From 6324724d404c146cc3c1adb13da5095fd8e8c06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20Mar=C3=A9chal?= <45510813+JasonMarechal25@users.noreply.github.com> Date: Tue, 8 Oct 2024 18:37:30 +0200 Subject: [PATCH] [ANT-2206] default value for time/scenario dependant (#2447) Co-authored-by: Vincent Payet Co-authored-by: payetvin <113102157+payetvin@users.noreply.github.com> Co-authored-by: guilpier-code <62292552+guilpier-code@users.noreply.github.com> Co-authored-by: Florian OMNES --- .../antares/solver/libObjectModel/valueType.h | 2 ++ src/solver/modelConverter/modelConverter.cpp | 2 +- src/solver/modelParser/encoders.hxx | 8 ++--- .../antares/solver/modelParser/Library.h | 10 +++--- .../solver/modelParser/testModelParser.cpp | 34 +++++++++++++++++-- .../modelParser/testModelTranslator.cpp | 24 ++++++++----- 6 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/solver/libModelObject/include/antares/solver/libObjectModel/valueType.h b/src/solver/libModelObject/include/antares/solver/libObjectModel/valueType.h index feeac17b1e..d8921fb7dc 100644 --- a/src/solver/libModelObject/include/antares/solver/libObjectModel/valueType.h +++ b/src/solver/libModelObject/include/antares/solver/libObjectModel/valueType.h @@ -19,6 +19,8 @@ ** along with Antares_Simulator. If not, see . */ #pragma once +#include +#include namespace Antares::Solver::ObjectModel { diff --git a/src/solver/modelConverter/modelConverter.cpp b/src/solver/modelConverter/modelConverter.cpp index 82cab77b92..a103c8fcd2 100644 --- a/src/solver/modelConverter/modelConverter.cpp +++ b/src/solver/modelConverter/modelConverter.cpp @@ -96,7 +96,7 @@ Antares::Solver::ObjectModel::ValueType convertType(Antares::Solver::ModelParser using namespace std::string_literals; switch (type) { - case Antares::Solver::ModelParser::ValueType::FLOAT: + case Antares::Solver::ModelParser::ValueType::CONTINUOUS: return Antares::Solver::ObjectModel::ValueType::FLOAT; case Antares::Solver::ModelParser::ValueType::INTEGER: return Antares::Solver::ObjectModel::ValueType::INTEGER; diff --git a/src/solver/modelParser/encoders.hxx b/src/solver/modelParser/encoders.hxx index 940cc9ac88..9d913b860a 100644 --- a/src/solver/modelParser/encoders.hxx +++ b/src/solver/modelParser/encoders.hxx @@ -39,8 +39,8 @@ struct convert return false; } rhs.id = node["id"].as(); - rhs.time_dependent = node["time-dependent"].as(); - rhs.scenario_dependent = node["scenario-dependent"].as(); + rhs.time_dependent = node["time-dependent"].as(true); + rhs.scenario_dependent = node["scenario-dependent"].as(true); return true; } }; @@ -56,7 +56,7 @@ struct convert } if (node.as() == "FLOAT") { - rhs = Antares::Solver::ModelParser::ValueType::FLOAT; + rhs = Antares::Solver::ModelParser::ValueType::CONTINUOUS; } else if (node.as() == "INTEGER") { @@ -87,7 +87,7 @@ struct convert rhs.lower_bound = node["lower-bound"].as(); rhs.upper_bound = node["upper-bound"].as(); rhs.variable_type = node["variable-type"].as( - Antares::Solver::ModelParser::ValueType::FLOAT); + Antares::Solver::ModelParser::ValueType::CONTINUOUS); return true; } }; diff --git a/src/solver/modelParser/include/antares/solver/modelParser/Library.h b/src/solver/modelParser/include/antares/solver/modelParser/Library.h index d806cb1c3f..77233a4a50 100644 --- a/src/solver/modelParser/include/antares/solver/modelParser/Library.h +++ b/src/solver/modelParser/include/antares/solver/modelParser/Library.h @@ -37,7 +37,7 @@ struct Parameter enum class ValueType { - FLOAT, + CONTINUOUS, INTEGER, BOOL }; @@ -47,8 +47,8 @@ inline std::string toString(const ValueType& value_type) using namespace std::string_literals; switch (value_type) { - case ValueType::FLOAT: - return "FLOAT"s; + case ValueType::CONTINUOUS: + return "CONTINUOUS"s; case ValueType::INTEGER: return "INTEGER"s; case ValueType::BOOL: @@ -63,8 +63,8 @@ inline std::ostream& operator<<(std::ostream& os, const ValueType& value_type) using namespace std::string_literals; switch (value_type) { - case ValueType::FLOAT: - os << "FLOAT"s; + case ValueType::CONTINUOUS: + os << "CONTINUOUS"s; break; case ValueType::INTEGER: os << "INTEGER"s; diff --git a/src/tests/src/solver/modelParser/testModelParser.cpp b/src/tests/src/solver/modelParser/testModelParser.cpp index 9e94dd2d52..ea59c9bbfa 100644 --- a/src/tests/src/solver/modelParser/testModelParser.cpp +++ b/src/tests/src/solver/modelParser/testModelParser.cpp @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE(parameters_properly_parsed) description: "model_description" parameters: - id: "param_name" - time-dependent: false + time-dependent: FALSE scenario-dependent: false variables: [] ports: [] @@ -252,6 +252,34 @@ BOOST_AUTO_TEST_CASE(model_can_contain_multiple_parameters) BOOST_CHECK_EQUAL(libraryObj.models[0].parameters[1].scenario_dependent, true); } +// Time dependent and scenario dependant default value are true +BOOST_AUTO_TEST_CASE(test_library_model_parameters_default_values) +{ + Antares::Solver::ModelParser::Parser parser; + auto library = R"( + library: + id: "lib_id" + description: "lib_description" + port-types: [] + models: + - id: "model_id" + description: "model_description" + parameters: + - id: "param_name" + variables: [] + ports: [] + port-field-definitions: [] + constraints: [] + objective: "objective" + )"s; + Antares::Solver::ModelParser::Library libraryObj = parser.parse(library); + BOOST_CHECK(libraryObj.models.size() == 1); + BOOST_CHECK(libraryObj.models[0].parameters.size() == 1); + BOOST_CHECK(libraryObj.models[0].parameters[0].id == "param_name"); + BOOST_CHECK(libraryObj.models[0].parameters[0].time_dependent == true); + BOOST_CHECK(libraryObj.models[0].parameters[0].scenario_dependent == true); +} + // Test library with one model containing variables BOOST_AUTO_TEST_CASE(variables_properly_parsed) { @@ -388,8 +416,8 @@ BOOST_AUTO_TEST_CASE(variable_types_can_be_integer_bool_float_default_to_float) auto& var4 = model.variables[3]; BOOST_CHECK_EQUAL(var1.variable_type, Antares::Solver::ModelParser::ValueType::BOOL); BOOST_CHECK_EQUAL(var2.variable_type, Antares::Solver::ModelParser::ValueType::INTEGER); - BOOST_CHECK_EQUAL(var3.variable_type, Antares::Solver::ModelParser::ValueType::FLOAT); - BOOST_CHECK_EQUAL(var4.variable_type, Antares::Solver::ModelParser::ValueType::FLOAT); + BOOST_CHECK_EQUAL(var3.variable_type, Antares::Solver::ModelParser::ValueType::CONTINUOUS); + BOOST_CHECK_EQUAL(var4.variable_type, Antares::Solver::ModelParser::ValueType::CONTINUOUS); } // Test library with one model containing ports diff --git a/src/tests/src/solver/modelParser/testModelTranslator.cpp b/src/tests/src/solver/modelParser/testModelTranslator.cpp index b8a3149997..bf203ae8ed 100644 --- a/src/tests/src/solver/modelParser/testModelTranslator.cpp +++ b/src/tests/src/solver/modelParser/testModelTranslator.cpp @@ -92,6 +92,13 @@ BOOST_AUTO_TEST_CASE(port_type_with_empty_fileds_properly_translated) BOOST_CHECK_EQUAL(lib.PortTypes().at("port2").Id(), "port2"); BOOST_CHECK_EQUAL(lib.PortTypes().at("port2").Description(), "impedance port"); BOOST_CHECK(lib.PortTypes().at("port2").Fields().empty()); + BOOST_REQUIRE_EQUAL(lib.PortTypes().size(), 2); + BOOST_CHECK_EQUAL(lib.PortTypes().at("port1").Id(), "port1"); + BOOST_CHECK_EQUAL(lib.PortTypes().at("port1").Description(), "flow port"); + BOOST_CHECK(lib.PortTypes().at("port1").Fields().empty()); + BOOST_CHECK_EQUAL(lib.PortTypes().at("port2").Id(), "port2"); + BOOST_CHECK_EQUAL(lib.PortTypes().at("port2").Description(), "impedance port"); + BOOST_CHECK(lib.PortTypes().at("port2").Fields().empty()); } // Test library with port types and fields @@ -240,14 +247,15 @@ BOOST_AUTO_TEST_CASE(model_constraints_properly_translated) BOOST_AUTO_TEST_CASE(multiple_models_properly_translated) { ModelParser::Library library; - ModelParser::Model model1{.id = "model1", - .description = "description", - .parameters = {{"param1", true, false}, {"param2", false, false}}, - .variables = {{"varP", "7", "pmin", ModelParser::ValueType::FLOAT}}, - .ports = {}, - .port_field_definitions = {}, - .constraints = {}, - .objective = "objectives"}; + ModelParser::Model model1{ + .id = "model1", + .description = "description", + .parameters = {{"param1", true, false}, {"param2", false, false}}, + .variables = {{"varP", "7", "pmin", ModelParser::ValueType::CONTINUOUS}}, + .ports = {}, + .port_field_definitions = {}, + .constraints = {}, + .objective = "objectives"}; ModelParser::Model model2{ .id = "model2", .description = "description",