-
Notifications
You must be signed in to change notification settings - Fork 29
[ANT-4033] Feat: Support setObjectiveOffset #3207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 34 commits
17fdbb2
6ce6190
ef1d0b6
7ac83b7
c22bec2
5dd8b88
3d802d0
44e4152
040366b
c48aeaf
0f188c0
579c9cb
1090878
fa98604
691baf2
e5df6ac
3c47266
3dd1b98
8246d0e
1926e89
eee5d5f
5a63ba5
a167d65
6596e2d
af51a70
01577d2
746626c
3786a08
cc34597
0ef6b40
89c51e5
fc7d6db
cd277d4
7edd830
a5f5db5
8c4feb6
9c34d75
86e30cc
7a7276f
14dc9cc
f50ad73
7385d07
9396db9
cfeedb7
477cbd5
256e535
bd9a060
4aafeaa
946b95d
aa95227
8368e33
3c7715b
480a4f5
d83a1ff
be9e7d7
f0e9b7f
4932b40
549192b
086e6df
d43e9ec
83136e0
49b1e19
4a5d655
a07e8ba
36b00a6
cd56ace
295c8af
05a1def
bcb1979
6b2def5
d49902c
01489fb
e9638d5
ae56b7f
2e4f083
9c994dc
1f642a1
9597205
9c89bf8
40e2cd3
335a8c9
55b03dc
9f38df6
07bfb75
b373401
f098b60
fc2003d
d6e0b98
25e22e8
7fdc23f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,10 @@ | |
| #include <antares/expressions/nodes/ExpressionsNodes.h> | ||
| #include <antares/expressions/visitors/EvalVisitor.h> | ||
| #include <antares/solver/optim-model-filler/ComponentFiller.h> | ||
| #include "antares/exception/InvalidArgumentError.hpp" | ||
| #include "antares/exception/RuntimeError.hpp" | ||
| #include "antares/expressions/visitors/TimeIndexVisitor.h" | ||
| #include "antares/logs/logs.h" | ||
|
|
||
| namespace | ||
| { | ||
|
|
@@ -284,12 +287,12 @@ void ComponentFiller::addVariables(const LinearProblemApi::FillContext& ctx) | |
| return; | ||
| } | ||
|
|
||
| Expressions::Visitors::EvalVisitor evaluator(optimEntityContainer_, ctx, component_); | ||
| Visitors::EvalVisitor evaluator(optimEntityContainer_, ctx, component_); | ||
| auto valueOrDefault = [&evaluator](const auto& node, double defaultValue) | ||
| { | ||
| if (node.Empty()) | ||
| { | ||
| return Expressions::Visitors::EvaluationResult(defaultValue); | ||
| return Visitors::EvaluationResult(defaultValue); | ||
| } | ||
| return evaluator.dispatch(node.RootNode()); | ||
| }; | ||
|
|
@@ -336,7 +339,7 @@ void ComponentFiller::addVariables(const LinearProblemApi::FillContext& ctx) | |
| } | ||
|
|
||
| void ComponentFiller::addStaticConstraint(const LinearConstraint& linear_constraint, | ||
| const std::string& constraint_id) | ||
| const std::string& constraint_id) const | ||
| { | ||
| auto* ct = optimEntityContainer_.Problem().addConstraint(linear_constraint.lb[0], | ||
| linear_constraint.ub[0], | ||
|
|
@@ -353,7 +356,7 @@ void ComponentFiller::addStaticConstraint(const LinearConstraint& linear_constra | |
|
|
||
| void ComponentFiller::addTimeDependentConstraints(const LinearConstraint& linear_constraints, | ||
| const std::string& constraint_id, | ||
| const LinearProblemApi::FillContext& ctx) | ||
| const LinearProblemApi::FillContext& ctx) const | ||
| { | ||
| auto& pb = optimEntityContainer_.Problem(); | ||
| const auto dims = getDimensions(ctx); | ||
|
|
@@ -409,6 +412,19 @@ void ComponentFiller::addConstraints(const LinearProblemApi::FillContext& ctx) | |
| } | ||
| } | ||
|
|
||
| namespace | ||
| { | ||
| /* | ||
| * Given objective ax + b, x being a time dependent variable and b a parameter. b is the offset. | ||
| * Problems are a_1*x_1+b + a_2*x_2+b + ... + a_n*x_n+b | ||
| * => offset = n*b | ||
| */ | ||
| double updateOffset(double initialValue, double offset) | ||
| { | ||
| return initialValue + offset; | ||
| } | ||
| } // namespace | ||
|
|
||
| void ComponentFiller::addObjectives(const LinearProblemApi::FillContext& ctx) | ||
| { | ||
| auto* model = component_.getModel(); | ||
|
|
@@ -420,27 +436,30 @@ void ComponentFiller::addObjectives(const LinearProblemApi::FillContext& ctx) | |
| [&](const auto& objective) | ||
| { return AreLocationsCompatible(objective.location(), targetLocation_); }); | ||
|
|
||
| auto& pb = optimEntityContainer_.Problem(); | ||
| for (const auto& objective: model->Objectives() | locationFilter) | ||
| { | ||
| const auto linearExpression = visitor.visitMergeDuplicates( | ||
| objective.expression().RootNode()); | ||
|
|
||
| auto& pb = optimEntityContainer_.Problem(); | ||
| double objectiveOffset = 0.0; | ||
| for (const auto& expr: linearExpression) | ||
| { | ||
| for (const auto& [index, value]: expr) | ||
| { | ||
| pb.setObjectiveCoefficient(solverVariables[static_cast<std::size_t>(index)].get(), | ||
guilpier-code marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| value); | ||
| } | ||
| objectiveOffset = updateOffset(objectiveOffset, expr.constant()); | ||
| } | ||
| pb.setObjectiveOffset(objectiveOffset); | ||
| } | ||
|
||
| } | ||
|
|
||
| TimeIndex ComponentFiller::getConstraintTimeIndex(const Nodes::Node* node, | ||
| const Component& component) const | ||
| { | ||
| Expressions::Visitors::TimeIndexVisitor timeIndexVisitor(optimEntityContainer_, component); | ||
| Visitors::TimeIndexVisitor timeIndexVisitor(optimEntityContainer_, component); | ||
| return timeIndexVisitor.dispatch(node); | ||
| } | ||
| } // namespace Antares::Optimisation | ||
Uh oh!
There was an error while loading. Please reload this page.