Antares Simulator
Power System Simulator
ComponentFiller.h
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 
22 #pragma once
23 
24 #include <antares/optimisation/linear-problem-api/linearProblemFiller.h>
25 #include <antares/study/system-model/component.h>
26 #include <antares/study/system-model/variable.h>
27 #include "antares/modeler-optimisation-container/OptimEntityContainer.h"
28 #include "antares/modeler-optimisation-container/scenarioGroupRepo.h"
29 #include "antares/solver/optim-model-filler/Dimensions.h"
30 
31 #include "ReadLinearConstraintVisitor.h"
32 
33 namespace Antares::Optimisation
34 {
35 
36 // Represents a variable shared by master and subproblems
38 {
39  std::string name;
40  unsigned indexInProblem;
41 };
42 
44 {
45 public:
46  BendersDecomposition() = default;
47  void setCurrentProblemId(std::string id);
48  void collectConnectionVariables(std::vector<std::string>&& varnames, unsigned varsCountInPb);
49 
50  const std::map<std::string, std::vector<ConnectionVariable>>& connections() const
51  {
52  return connectionVars_;
53  }
54 
55 private:
56  std::map<std::string, std::vector<ConnectionVariable>> connectionVars_;
57  std::string currentProblemId_ = "master";
58 };
59 
61 {
62 public:
64  void write(std::ostream& os) const;
65 
66 private:
67  const BendersDecomposition& bd_;
68 };
69 
76 {
77 public:
78  ComponentFiller() = delete;
79 
80  ComponentFiller(ComponentFiller& other) = delete;
81 
82  explicit ComponentFiller(const ModelerStudy::SystemModel::Component& component,
83  OptimEntityContainer& optimEntityContainer,
84  const ScenarioGroupRepository& scenarioGroupRepository,
85  Modeler::Config::Location targetLocation,
86  BendersDecomposition* bendersDecomposition = nullptr);
87 
88  void addVariables(const LinearProblemApi::FillContext& ctx) override;
89 
90  void addConstraints(const LinearProblemApi::FillContext& ctx) override;
91  void addObjectives(const LinearProblemApi::FillContext& ctx) override;
92 
93 private:
94  void addStaticConstraint(const LinearConstraint& linear_constraint,
95  const std::string& constraint_id) const;
96 
97  void addTimeDependentConstraints(const LinearConstraint& linear_constraints,
98  const std::string& constraint_id,
99  const LinearProblemApi::FillContext& ctx) const;
100 
101  void addStaticObjective(const Optimization::LinearExpression& expression) const;
102 
103  VariabilityType getVariability(const Nodes::Node* node,
104  const ModelerStudy::SystemModel::Component& component) const;
105 
106  const ModelerStudy::SystemModel::Component& component_;
107  OptimEntityContainer& optimEntityContainer_;
108  const ScenarioGroupRepository& scenarioGroupRepository_;
109  const Modeler::Config::Location targetLocation_;
110  BendersDecomposition* bendersDecomposition_ = nullptr;
111 
112  // Filter to keep only items compatible with the target location
113  auto locationFilter()
114  {
115  return std::views::filter(
116  [this](const auto& item)
117  { return AreLocationsCompatibleForFillers(item.location(), targetLocation_); });
118  }
119 };
120 } // namespace Antares::Optimisation
Base class for nodes in a syntax tree.
Definition: Node.h:30
Definition: ComponentFiller.h:44
Definition: ComponentFiller.h:76
Context for filling linear problem data. Contains temporal information.
Definition: ILinearProblemData.h:35
Definition: OptimEntityContainer.h:46
Definition: scenarioGroupRepo.h:12
Definition: LinearExpression.h:30
Definition: VariableNode.h:9
VariabilityType
Represents the time and scenario variation of a value.
Definition: variabilityType.h:29
Definition: ComponentFiller.h:38
Definition: ReadLinearConstraintVisitor.h:50