25 #include "antares/io/inputs/yml-model/Library.h"
27 #include "yaml-cpp/yaml.h"
44 inline T as_fallback_default(
const Node& n)
50 struct convert<Antares::IO::Inputs::YmlModel::Parameter>
58 rhs.id = node[
"id"].as<std::string>();
59 rhs.time_dependent = node[
"time-dependent"].as<
bool>(
true);
60 rhs.scenario_dependent = node[
"scenario-dependent"].as<
bool>(
true);
66 struct convert<Antares::IO::Inputs::YmlModel::ValueType>
68 static bool decode(
const Node& node, Antares::IO::Inputs::YmlModel::ValueType& rhs)
74 const auto value = node.as<std::string>();
75 if (value ==
"continuous")
77 rhs = Antares::IO::Inputs::YmlModel::ValueType::CONTINUOUS;
79 else if (value ==
"integer")
81 rhs = Antares::IO::Inputs::YmlModel::ValueType::INTEGER;
83 else if (value ==
"boolean")
85 rhs = Antares::IO::Inputs::YmlModel::ValueType::BOOL;
96 struct convert<Antares::IO::Inputs::YmlModel::Variable>
104 rhs.id = node[
"id"].as<std::string>();
105 rhs.lower_bound = node[
"lower-bound"].as<std::string>(
"");
106 rhs.upper_bound = node[
"upper-bound"].as<std::string>(
"");
107 rhs.variable_type = node[
"variable-type"].as<Antares::IO::Inputs::YmlModel::ValueType>(
108 Antares::IO::Inputs::YmlModel::ValueType::CONTINUOUS);
109 rhs.time_dependent = node[
"time-dependent"].as<
bool>(
true);
110 rhs.scenario_dependent = node[
"scenario-dependent"].as<
bool>(
true);
111 rhs.location = node[
"location"].as<std::string>(
"subproblems");
117 struct convert<Antares::IO::Inputs::YmlModel::Port>
125 rhs.id = node[
"id"].as<std::string>();
126 rhs.type = node[
"type"].as<std::string>();
132 struct convert<Antares::IO::Inputs::YmlModel::PortFieldDefinition>
141 rhs.port = node[
"port"].as<std::string>();
142 rhs.field = node[
"field"].as<std::string>();
143 rhs.definition = node[
"definition"].as<std::string>();
149 struct convert<Antares::IO::Inputs::YmlModel::Constraint>
157 rhs.id = node[
"id"].as<std::string>();
158 rhs.expression = node[
"expression"].as<std::string>();
159 rhs.location = node[
"location"].as<std::string>(
"subproblems");
165 struct convert<Antares::IO::Inputs::YmlModel::ExtraOutput>
173 rhs.id = node[
"id"].as<std::string>();
174 rhs.expression = node[
"expression"].as<std::string>();
180 struct convert<Antares::IO::Inputs::YmlModel::Objective>
188 rhs.id = node[
"id"].as<std::string>();
189 rhs.expression = node[
"expression"].as<std::string>();
190 rhs.location = node[
"location"].as<std::string>(
"subproblems");
196 struct convert<Antares::IO::Inputs::YmlModel::Model>
204 rhs.id = node[
"id"].as<std::string>();
205 rhs.description = node[
"description"].as<std::string>(
"");
206 rhs.parameters = as_fallback_default<std::vector<Antares::IO::Inputs::YmlModel::Parameter>>(
208 rhs.variables = as_fallback_default<std::vector<Antares::IO::Inputs::YmlModel::Variable>>(
210 rhs.ports = as_fallback_default<std::vector<Antares::IO::Inputs::YmlModel::Port>>(
212 rhs.port_field_definitions = as_fallback_default<
213 std::vector<Antares::IO::Inputs::YmlModel::PortFieldDefinition>>(
214 node[
"port-field-definitions"]);
215 rhs.constraints = as_fallback_default<
216 std::vector<Antares::IO::Inputs::YmlModel::Constraint>>(node[
"constraints"]);
217 rhs.binding_constraints = as_fallback_default<
218 std::vector<Antares::IO::Inputs::YmlModel::Constraint>>(node[
"binding-constraints"]);
219 rhs.objectives = as_fallback_default<std::vector<Antares::IO::Inputs::YmlModel::Objective>>(
220 node[
"objective-contributions"]);
221 rhs.extra_outputs = as_fallback_default<
222 std::vector<Antares::IO::Inputs::YmlModel::ExtraOutput>>(node[
"extra-outputs"]);
228 struct convert<Antares::IO::Inputs::YmlModel::PortType>
236 rhs.id = node[
"id"].as<std::string>();
237 rhs.description = node[
"description"].as<std::string>(
"");
238 for (
const auto& field: node[
"fields"])
240 rhs.fields.push_back(field[
"id"].as<std::string>());
242 if (node[
"area-connection"].IsDefined())
244 if (node[
"area-connection"].size() != 1)
249 for (
const auto& field: node[
"area-connection"])
251 rhs.area_connection_injection_field = field[
"injection-field"].as<std::string>(
"");
259 struct convert<Antares::IO::Inputs::YmlModel::Library>
263 rhs.id = node[
"id"].as<std::string>();
264 rhs.description = node[
"description"].as<std::string>(
"");
265 rhs.port_types = as_fallback_default<std::vector<Antares::IO::Inputs::YmlModel::PortType>>(
267 rhs.models = node[
"models"].as<std::vector<Antares::IO::Inputs::YmlModel::Model>>();