Antares Simulator
Power System Simulator
inmemory-modeler.h
1 // Copyright 2007-2025, RTE (https://www.rte-france.com)
2 // See AUTHORS.txt
3 // SPDX-License-Identifier: MPL-2.0
4 // This file is part of Antares-Simulator,
5 // Adequacy and Performance assessment for interconnected energy networks.
6 //
7 // Antares_Simulator is free software: you can redistribute it and/or modify
8 // it under the terms of the Mozilla Public Licence 2.0 as published by
9 // the Mozilla Foundation, either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // Antares_Simulator is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // Mozilla Public Licence 2.0 for more details.
16 //
17 // You should have received a copy of the Mozilla Public Licence 2.0
18 // along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
19 
20 #pragma once
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "antares/expressions/nodes/VariableNode.h"
27 #include "antares/modeler-optimisation-container/OptimEntityContainer.h"
28 #include "antares/modeler-optimisation-container/scenarioGroupRepo.h"
29 #include "antares/optimisation/linear-problem-data-impl/linearProblemData.h"
30 #include "antares/optimisation/linear-problem-mpsolver-impl/linearProblem.h"
31 #include "antares/solver/modeler/data.h"
32 #include "antares/solver/optim-model-filler/Dimensions.h"
33 #include "antares/study/system-model/component.h"
34 #include "antares/study/system-model/model.h"
35 
36 using namespace Antares::ModelerStudy::SystemModel;
37 using namespace Antares::Optimisation;
38 
39 namespace Test::Modeler
40 {
41 std::pair<std::string, ParameterTypeAndValue> build_context_parameter_with(
42  const std::string& id,
43  const std::string& value,
44  const VariabilityType& type = VariabilityType::CONSTANT_IN_TIME_AND_SCENARIO);
45 
47 {
48  std::string id;
49  ValueType type;
52  bool timeDependent = true;
53  bool scenarioDependent = true;
54 };
55 
57 {
58  std::string id;
60 };
61 
63 {
64  std::unordered_map<std::string, Model> models;
66  std::unique_ptr<Antares::Optimisation::LinearProblemApi::ILinearProblem> pb;
67  std::vector<Component> components;
69  Antares::Modeler::Data modelerData;
71  std::unique_ptr<Antares::Optimisation::OptimEntityContainer> optimEntityContainer;
72 
73  void createModel(const std::string& modelId,
74  const std::vector<std::string>& parameterIds,
75  const std::vector<VariableData>& variablesData,
76  const std::vector<ConstraintData>& constraintsData,
77  Antares::Expressions::Nodes::Node* objective = nullptr);
78 
79  void createModelWithSystemModelParameter(
80  const std::string& modelId,
81  std::vector<Parameter>,
82  const std::vector<VariableData>& variablesData,
83  const std::vector<ConstraintData>& constraintsData,
84  Antares::Expressions::Nodes::Node* objective = nullptr);
85 
86  void createModelWithMultipleObjectives(
87  const std::string& modelId,
88  std::vector<Parameter>,
89  const std::vector<VariableData>& variablesData,
90  const std::vector<ConstraintData>& constraintsData,
91  std::vector<Antares::Expressions::Nodes::Node*> objectives);
92 
93  void createModelWithOneFloatVar(const std::string& modelId,
94  const std::vector<std::string>& parameterIds,
95  const std::string& varId,
98  const std::vector<ConstraintData>& constraintsData,
99  Antares::Expressions::Nodes::Node* objective = nullptr,
100  bool time_dependent = false);
101 
102  void createComponent(const std::string& modelId,
103  const std::string& componentId,
104  std::map<std::string, ParameterTypeAndValue> parameterValues = {},
105  std::string scenarioGroupId = "");
106 
107  Antares::Expressions::Nodes::Node* literal(double value);
108 
110  const std::string& paramId,
112  VariabilityType::CONSTANT_IN_TIME_AND_SCENARIO);
113 
115  const std::string& varId,
116  unsigned int index,
118  VariabilityType::CONSTANT_IN_TIME_AND_SCENARIO);
119 
125 
127 
128  void buildLinearProblem(
131  std::vector<std::unique_ptr<Antares::Optimisation::LinearProblemApi::IScenario>>& scenarios);
132 
133  void buildLinearProblem(
135 
136  void buildLinearProblem();
137 
138  Antares::Modeler::Data& getModelerData()
139  {
140  SystemBuilder systemBuilder;
141  auto system = systemBuilder.withId("system").withComponents(std::move(components)).build();
142  modelerData.system = std::make_unique<System>(std::move(system));
143  modelerData.dataSeries = std::make_unique<
145  return modelerData;
146  }
147 
148 private:
149  int componentIndex_ = 0;
150 };
151 } // namespace Test::Modeler
Base class for nodes in a syntax tree.
Definition: Node.h:30
SystemBuilder & withId(std::string_view id)
Sets the ID of the system.
Definition: system.cpp:49
SystemBuilder & withComponents(std::vector< Component > &&components)
Sets the components of the system.
Definition: system.cpp:61
System build()
Builds and returns the System object.
Definition: system.cpp:72
Context for filling linear problem data. Contains temporal information.
Definition: ILinearProblemData.h:35
Definition: scenarioGroupRepo.h:12
Definition: VariableNode.h:9
VariabilityType
Represents the time and scenario variation of a value.
Definition: variabilityType.h:29
Definition: data.h:38
Definition: inmemory-modeler.h:57
Definition: inmemory-modeler.h:63
Definition: inmemory-modeler.h:47