Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes committed Jan 7, 2025
1 parent 941c2a8 commit 25ec760
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/solver/modelConverter/modelConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,42 @@ Antares::Study::SystemModel::ValueType convertType(Antares::Solver::ModelParser:
*/
std::vector<Antares::Study::SystemModel::Variable> convertVariables(const ModelParser::Model& model)
{
auto handleDefaultForEmptyBound =
[](const std::string& id,
const std::string& initialBound,
const std::string& defaultBound,
Antares::Solver::ModelParser::ValueType type) -> std::string
{
if (!initialBound.empty())
{
return initialBound;
}
if (type == Antares::Solver::ModelParser::ValueType::BOOL)
{
return defaultBound;
}
throw std::runtime_error("Bounds are required for variable " + id);
};

std::vector<Antares::Study::SystemModel::Variable> variables;
for (const auto& variable: model.variables)
{
Antares::Study::SystemModel::Expression lb(variable.lower_bound,
convertExpressionToNode(variable.lower_bound,
model));
Antares::Study::SystemModel::Expression ub(variable.upper_bound,
convertExpressionToNode(variable.upper_bound,
model));
std::string lb = handleDefaultForEmptyBound(variable.id,
variable.lower_bound,
"0",
variable.variable_type);
Antares::Study::SystemModel::Expression lbExpression(lb,
convertExpressionToNode(lb, model));

std::string ub = handleDefaultForEmptyBound(variable.id,
variable.upper_bound,
"1",
variable.variable_type);
Antares::Study::SystemModel::Expression ubExpression(ub,
convertExpressionToNode(ub, model));
variables.emplace_back(variable.id,
std::move(lb),
std::move(ub),
std::move(lbExpression),
std::move(ubExpression),
convertType(variable.variable_type));
}

Expand Down

0 comments on commit 25ec760

Please sign in to comment.