Skip to content

Commit

Permalink
Better handling of variable bounds for BOOL variables
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes committed Jan 7, 2025
1 parent 69a5225 commit 072dc7b
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/solver/optim-model-filler/ComponentFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,33 @@ void ComponentFiller::addVariables(Solver::Modeler::Api::ILinearProblem& pb,
auto evaluator = std::make_unique<Solver::Visitors::EvalVisitor>(evaluationContext_);
for (const auto& variable: component_.getModel()->Variables() | std::views::values)
{
pb.addVariable(evaluator->dispatch(variable.LowerBound().RootNode()),
evaluator->dispatch(variable.UpperBound().RootNode()),
variable.Type() != Study::SystemModel::ValueType::FLOAT,
component_.Id() + "." + variable.Id());
const auto variableID = component_.Id() + "." + variable.Id();
switch (variable.Type())
{
case Study::SystemModel::ValueType::BOOL:
{
pb.addVariable(0., 1., true, variableID);
break;
}
case Study::SystemModel::ValueType::INTEGER:
{
pb.addVariable(evaluator->dispatch(variable.LowerBound().RootNode()),
evaluator->dispatch(variable.UpperBound().RootNode()),
true,
variableID);
break;
}
case Study::SystemModel::ValueType::CONTINUOUS:
{
pb.addVariable(evaluator->dispatch(variable.LowerBound().RootNode()),
evaluator->dispatch(variable.UpperBound().RootNode()),
false,
variableID);
break;
}
default:
throw std::invalid_argument("Invalid type for variable");
}
}
}

Expand Down

0 comments on commit 072dc7b

Please sign in to comment.