diff --git a/src/solver/modeler/CMakeLists.txt b/src/solver/modeler/CMakeLists.txt index 3c631240ac..74378f6f7f 100644 --- a/src/solver/modeler/CMakeLists.txt +++ b/src/solver/modeler/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(api) add_subdirectory(ortoolsImpl) +add_subdirectory(parameters) diff --git a/src/solver/modeler/parameters/CMakeLists.txt b/src/solver/modeler/parameters/CMakeLists.txt new file mode 100644 index 0000000000..63610bd34e --- /dev/null +++ b/src/solver/modeler/parameters/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(modeler-parameters + include/antares/solver/modeler/parameters/modelerParameters.h + include/antares/solver/modeler/parameters/parseModelerParameters.h + parseModelerParameters.cpp + encoder.hxx +) + +target_link_libraries(modeler-parameters + PRIVATE + yaml-cpp) + +target_include_directories(modeler-parameters + PUBLIC + $ +) diff --git a/src/solver/modeler/parameters/encoder.hxx b/src/solver/modeler/parameters/encoder.hxx new file mode 100644 index 0000000000..82a3bdc00f --- /dev/null +++ b/src/solver/modeler/parameters/encoder.hxx @@ -0,0 +1,19 @@ +#include + +#include "yaml-cpp/yaml.h" + +namespace YAML +{ +template<> +struct convert +{ + static bool decode(const Node& node, Antares::Solver::ModelerParameters& rhs) + { + rhs.solver = node["solver"].as(); + rhs.solverLogs = node["description"].as(false); + rhs.solverParameters = node["solver-parameters"].as(); + rhs.noOutput = node["no-output"].as(false); + return true; + } +}; +} // namespace YAML diff --git a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/modelerParameters.h b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/modelerParameters.h new file mode 100644 index 0000000000..c6977a748b --- /dev/null +++ b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/modelerParameters.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace Antares::Solver +{ +struct ModelerParameters +{ + // OR-Tools solver to be used for the simulation + std::string solver; + // Display solver logs ON/OFF + bool solverLogs = false; + // Specific solver parameters + std::string solverParameters; + // Write output results + bool noOutput = false; +}; +} // namespace Antares::Solver diff --git a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h new file mode 100644 index 0000000000..c943b7a90c --- /dev/null +++ b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +namespace Antares::Solver +{ + +ModelerParameters parseModelerParameters(const std::filesystem::path& path); +} // namespace Antares::Solver diff --git a/src/solver/modeler/parameters/parseModelerParameters.cpp b/src/solver/modeler/parameters/parseModelerParameters.cpp new file mode 100644 index 0000000000..a0d1abbc70 --- /dev/null +++ b/src/solver/modeler/parameters/parseModelerParameters.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include "encoder.hxx" + +namespace Antares::Solver +{ +static std::string loadFileToString(const std::filesystem::path& filePath) +{ + return std::string(std::istreambuf_iterator(std::ifstream(filePath).rdbuf()), + std::istreambuf_iterator()); +} + +ModelerParameters parseModelerParameters(const std::filesystem::path& path) +{ + auto contents = loadFileToString(path); + YAML::Node root = YAML::Load(contents); + return root.as(); +} +} // namespace Antares::Solver