diff --git a/src/solver/optim-model-filler/ComponentFiller.cpp b/src/solver/optim-model-filler/ComponentFiller.cpp index 1f7726e536..4399f09ba8 100644 --- a/src/solver/optim-model-filler/ComponentFiller.cpp +++ b/src/solver/optim-model-filler/ComponentFiller.cpp @@ -44,45 +44,37 @@ bool checkTimeSteps(Solver::Modeler::Api::FillContext& ctx) return ctx.getFirstTimeStep() <= ctx.getLastTimeStep(); } -void ComponentFiller::addVariables_(Solver::Modeler::Api::ILinearProblem& pb, - const std::unique_ptr& evaluator, - unsigned int nb_vars) const +void ComponentFiller::addVariables(Solver::Modeler::Api::ILinearProblem& pb, + Solver::Modeler::Api::LinearProblemData& data, + Solver::Modeler::Api::FillContext& ctx) { + if (!checkTimeSteps(ctx)) + { + // exception? + return; + } + + Solver::Visitors::EvalVisitor evaluator(evaluationContext_); for (const auto& variable: component_.getModel()->Variables() | std::views::values) { if (variable.isTimeDependent()) { - pb.addVariable(evaluator->dispatch(variable.LowerBound().RootNode()), - evaluator->dispatch(variable.UpperBound().RootNode()), + pb.addVariable(evaluator.dispatch(variable.LowerBound().RootNode()), + evaluator.dispatch(variable.UpperBound().RootNode()), variable.Type() != Study::SystemModel::ValueType::FLOAT, component_.Id() + "." + variable.Id(), - nb_vars); + ctx.getNumberOfTimestep()); } else { - pb.addVariable(evaluator->dispatch(variable.LowerBound().RootNode()), - evaluator->dispatch(variable.UpperBound().RootNode()), + pb.addVariable(evaluator.dispatch(variable.LowerBound().RootNode()), + evaluator.dispatch(variable.UpperBound().RootNode()), variable.Type() != Study::SystemModel::ValueType::FLOAT, component_.Id() + "." + variable.Id()); } } } -void ComponentFiller::addVariables(Solver::Modeler::Api::ILinearProblem& pb, - Solver::Modeler::Api::LinearProblemData& data, - Solver::Modeler::Api::FillContext& ctx) -{ - auto evaluator = std::make_unique(evaluationContext_); - if (checkTimeSteps(ctx)) - { - addVariables_(pb, evaluator, ctx.getNumberOfTimestep()); - } - else - { - // exception? - } -} - void ComponentFiller::addStaticConstraint(Solver::Modeler::Api::ILinearProblem& pb, const LinearConstraint& linear_constraint, const std::string& constraint_id) const diff --git a/src/solver/optim-model-filler/include/antares/solver/optim-model-filler/ComponentFiller.h b/src/solver/optim-model-filler/include/antares/solver/optim-model-filler/ComponentFiller.h index 99a9df14a7..23b8fe4c12 100644 --- a/src/solver/optim-model-filler/include/antares/solver/optim-model-filler/ComponentFiller.h +++ b/src/solver/optim-model-filler/include/antares/solver/optim-model-filler/ComponentFiller.h @@ -53,10 +53,6 @@ class ComponentFiller: public Solver::Modeler::Api::LinearProblemFiller /// Create a ComponentFiller for a Component explicit ComponentFiller(const Study::SystemModel::Component& component); - void addVariables_(Solver::Modeler::Api::ILinearProblem& pb, - const std::unique_ptr& evaluator, - unsigned int nb_vars) const; - void addVariables(Solver::Modeler::Api::ILinearProblem& pb, Solver::Modeler::Api::LinearProblemData& data, Solver::Modeler::Api::FillContext& ctx) override;