Skip to content

Commit

Permalink
[ANT-2206] default value for time/scenario dependant (#2447)
Browse files Browse the repository at this point in the history
Co-authored-by: Vincent Payet <[email protected]>
Co-authored-by: payetvin <[email protected]>
Co-authored-by: guilpier-code <[email protected]>
Co-authored-by: Florian OMNES <[email protected]>
  • Loading branch information
5 people authored Oct 8, 2024
1 parent af9f559 commit 6324724
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/
#pragma once
#include <iostream>
#include <string>

namespace Antares::Solver::ObjectModel
{
Expand Down
2 changes: 1 addition & 1 deletion src/solver/modelConverter/modelConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/solver/modelParser/encoders.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct convert<Antares::Solver::ModelParser::Parameter>
return false;
}
rhs.id = node["id"].as<std::string>();
rhs.time_dependent = node["time-dependent"].as<bool>();
rhs.scenario_dependent = node["scenario-dependent"].as<bool>();
rhs.time_dependent = node["time-dependent"].as<bool>(true);
rhs.scenario_dependent = node["scenario-dependent"].as<bool>(true);
return true;
}
};
Expand All @@ -56,7 +56,7 @@ struct convert<Antares::Solver::ModelParser::ValueType>
}
if (node.as<std::string>() == "FLOAT")
{
rhs = Antares::Solver::ModelParser::ValueType::FLOAT;
rhs = Antares::Solver::ModelParser::ValueType::CONTINUOUS;
}
else if (node.as<std::string>() == "INTEGER")
{
Expand Down Expand Up @@ -87,7 +87,7 @@ struct convert<Antares::Solver::ModelParser::Variable>
rhs.lower_bound = node["lower-bound"].as<std::string>();
rhs.upper_bound = node["upper-bound"].as<std::string>();
rhs.variable_type = node["variable-type"].as<Antares::Solver::ModelParser::ValueType>(
Antares::Solver::ModelParser::ValueType::FLOAT);
Antares::Solver::ModelParser::ValueType::CONTINUOUS);
return true;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Parameter

enum class ValueType
{
FLOAT,
CONTINUOUS,
INTEGER,
BOOL
};
Expand All @@ -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:
Expand All @@ -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;
Expand Down
34 changes: 31 additions & 3 deletions src/tests/src/solver/modelParser/testModelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions src/tests/src/solver/modelParser/testModelTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 6324724

Please sign in to comment.