diff --git a/CMakeLists.txt b/CMakeLists.txt index b0da5ec..da40299 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ option(CHECK_INCONSISTENCIES "Check inconsistencies at each step" OFF) option(ENABLE_API "oRatio API" OFF) add_library(oRatioLib src/solver.cpp src/graph.cpp src/flaw.cpp src/resolver.cpp src/smart_type.cpp src/flaws/atom_flaw.cpp src/flaws/bool_flaw.cpp src/flaws/disj_flaw.cpp src/flaws/disjunction_flaw.cpp src/flaws/enum_flaw.cpp src/types/agent.cpp src/types/state_variable.cpp src/types/consumable_resource.cpp src/types/reusable_resource.cpp $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/solver_api.cpp>) +add_dependencies(oRatioLib RiDDLe SeMiTONE) target_link_libraries(oRatioLib PUBLIC RiDDLe SeMiTONE) target_include_directories(oRatioLib PUBLIC $ $ $ $) @@ -70,9 +71,10 @@ if(ENABLE_API) target_compile_definitions(oRatioLib PRIVATE ENABLE_API) endif() -add_executable(oRatio src/main.cpp) +add_executable(oRatio src/main.cpp src/solver_api.cpp) +add_dependencies(oRatio oRatioLib) target_link_libraries(oRatio PRIVATE oRatioLib) -target_include_directories(oRatio PRIVATE $) +target_compile_definitions(oRatio PRIVATE ENABLE_API=1 COMPUTE_NAMES=1) if(BUILD_TESTING) add_subdirectory(tests) diff --git a/src/main.cpp b/src/main.cpp index 8f2b3d3..07873b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,55 @@ #include "solver.hpp" +#include "logging.hpp" +#include "solver_api.hpp" +#include +#include +#include int main(int argc, char const *argv[]) { + if (argc < 3) + { + LOG_FATAL("usage: oRatio [ ...] "); + return -1; + } + + // the problem files.. + std::vector prob_names; + for (int i = 1; i < argc - 1; i++) + prob_names.push_back(argv[i]); + + // the solution file.. + std::string sol_name = argv[argc - 1]; + + LOG_INFO("starting oRatio"); + auto start = std::chrono::high_resolution_clock::now(); + auto s = std::make_shared(); + s->init(); + try + { + s->read(prob_names); + + if (s->solve()) + { + LOG_INFO("hurray!! we have found a solution.."); + + std::ofstream sol_file; + sol_file.open(sol_name); + sol_file << to_json(*s).dump(); + sol_file.close(); + } + else + { + LOG_INFO("the problem is unsolvable.."); + } + auto dur = std::chrono::high_resolution_clock::now() - start; + LOG_INFO("running time: " + std::to_string(std::chrono::duration_cast(dur).count()) + " ms"); + } + catch (const std::exception &ex) + { + LOG_FATAL("exception: " + std::string(ex.what())); + return 1; + } + return 0; } diff --git a/tests/test_solver.cpp b/tests/test_solver.cpp index 934e42b..2077521 100644 --- a/tests/test_solver.cpp +++ b/tests/test_solver.cpp @@ -1,7 +1,7 @@ -#include -#include #include "solver.hpp" #include "logging.hpp" +#include +#include int main(int argc, char const *argv[]) {