Skip to content

Commit

Permalink
Add option to build oRatio executable and conditionally include name …
Browse files Browse the repository at this point in the history
…in JSON output
  • Loading branch information
riccardodebenedictis committed Nov 11, 2024
1 parent f7fbb95 commit 86aa253
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ message(STATUS "Heuristic type: ${HEURISTIC_TYPE}")

option(CHECK_INCONSISTENCIES "Check inconsistencies at each step" OFF)
option(ENABLE_API "oRatio API" OFF)
option(BUILD_EXECUTABLE "Build oRatio executable" ON)

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 $<$<BOOL:${ENABLE_API}>:${CMAKE_CURRENT_SOURCE_DIR}/src/solver_api.cpp>)
add_dependencies(oRatioLib RiDDLe SeMiTONE)
Expand Down Expand Up @@ -71,10 +72,13 @@ if(ENABLE_API)
target_compile_definitions(oRatioLib PRIVATE ENABLE_API)
endif()

add_executable(oRatio src/main.cpp src/solver_api.cpp)
add_dependencies(oRatio oRatioLib)
target_link_libraries(oRatio PRIVATE oRatioLib)
target_compile_definitions(oRatio PRIVATE ENABLE_API=1 COMPUTE_NAMES=1)
message(STATUS "Build oRatio executable: ${BUILD_EXECUTABLE}")
if(BUILD_EXECUTABLE)
set(ENABLE_API ON CACHE BOOL "oRatio API" FORCE)
add_executable(oRatio src/main.cpp src/solver_api.cpp)
add_dependencies(oRatio oRatioLib)
target_link_libraries(oRatio PRIVATE oRatioLib)
endif()

if(BUILD_TESTING)
add_subdirectory(tests)
Expand Down
2 changes: 2 additions & 0 deletions src/flaws/enum_flaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ namespace ratio
json::json enum_flaw::choose_value::get_data() const noexcept
{
json::json j{{"type", "assignment"}, {"value", value(dynamic_cast<const riddle::item &>(val))}};
#ifdef COMPUTE_NAMES
auto name = get_flaw().get_solver().guess_name(dynamic_cast<const riddle::item &>(val));
if (!name.empty())
j["name"] = name;
#endif
return j;
}
#endif
Expand Down
5 changes: 4 additions & 1 deletion src/solver_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ namespace ratio

[[nodiscard]] json::json to_json(const riddle::item &itm) noexcept
{
json::json j_itm{{"id", get_id(itm)}, {"name", itm.get_type().get_scope().get_core().guess_name(itm)}};
json::json j_itm{{"id", get_id(itm)}};
#ifdef COMPUTE_NAMES
j_itm["name"] = itm.get_type().get_scope().get_core().guess_name(itm);
#endif
// we add the full name of the type of the item..
std::string tp_name = itm.get_type().get_name();
const auto *t = &itm.get_type();
Expand Down
5 changes: 4 additions & 1 deletion src/types/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ namespace ratio

for (const auto &[agnt, atms] : agnt_instances)
{
json::json tl{{"id", get_id(*agnt)}, {"type", AGENT_TYPE_NAME}, {"name", get_solver().guess_name(*agnt)}};
json::json tl{{"id", get_id(*agnt)}, {"type", AGENT_TYPE_NAME}};
#ifdef COMPUTE_NAMES
tl["name"] = get_solver().guess_name(*agnt);
#endif

// for each pulse, the atoms starting at that pulse..
std::map<utils::inf_rational, std::set<atom *>> starting_atoms;
Expand Down
5 changes: 4 additions & 1 deletion src/types/consumable_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ namespace ratio
for (const auto &[cres, atms] : cr_instances)
{
const auto c_initial_amount = get_solver().arithmetic_value(*std::static_pointer_cast<riddle::arith_item>(cres->get(CONSUMABLE_RESOURCE_INITIAL_AMOUNT_NAME)));
json::json tl{{"id", get_id(*cres)}, {"type", CONSUMABLE_RESOURCE_TYPE_NAME}, {"name", get_solver().guess_name(*cres)}, {CONSUMABLE_RESOURCE_CAPACITY_NAME, to_json(get_solver().arithmetic_value(*std::static_pointer_cast<riddle::arith_item>(cres->get(CONSUMABLE_RESOURCE_CAPACITY_NAME))))}, {CONSUMABLE_RESOURCE_INITIAL_AMOUNT_NAME, to_json(c_initial_amount)}};
json::json tl{{"id", get_id(*cres)}, {"type", CONSUMABLE_RESOURCE_TYPE_NAME}, {CONSUMABLE_RESOURCE_CAPACITY_NAME, to_json(get_solver().arithmetic_value(*std::static_pointer_cast<riddle::arith_item>(cres->get(CONSUMABLE_RESOURCE_CAPACITY_NAME))))}, {CONSUMABLE_RESOURCE_INITIAL_AMOUNT_NAME, to_json(c_initial_amount)}};
#ifdef COMPUTE_NAMES
tl["name"] = get_solver().guess_name(*cres);
#endif

// for each pulse, the atoms starting at that pulse..
std::map<utils::inf_rational, std::set<atom *>> starting_atoms;
Expand Down
5 changes: 4 additions & 1 deletion src/types/state_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ namespace ratio

for (const auto &[sv, atms] : sv_instances)
{
json::json tl{{"id", get_id(*sv)}, {"type", STATE_VARIABLE_TYPE_NAME}, {"name", get_solver().guess_name(*sv)}};
json::json tl{{"id", get_id(*sv)}, {"type", STATE_VARIABLE_TYPE_NAME}};
#ifdef COMPUTE_NAMES
tl["name"] = get_solver().guess_name(*sv);
#endif

// for each pulse, the atoms starting at that pulse..
std::map<utils::inf_rational, std::set<atom *>> starting_atoms;
Expand Down

0 comments on commit 86aa253

Please sign in to comment.