Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
ConstraintBuilder.h
1/*
2** Copyright 2007-2024, 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#pragma once
22
23#include <utility>
24
25#include <antares/logs/logs.h>
26#include "antares/solver/optimisation/opt_structure_probleme_a_resoudre.h"
27#include "antares/solver/simulation/sim_structure_probleme_economique.h"
28
29#include "../opt_fonctions.h"
30#include "../opt_rename_problem.h"
31#include "../variables/VariableManagement.h"
32
33// TODO God struct should be decomposed
35{
36public:
37 std::vector<double>& Pi;
38 std::vector<int>& Colonne;
39 int& nombreDeContraintes;
40 int& nombreDeTermesDansLaMatriceDeContrainte;
41 std::vector<int>& IndicesDebutDeLigne;
42 SparseVector<double>& CoefficientsDeLaMatriceDesContraintes;
43 SparseVector<int>& IndicesColonnes;
44 std::vector<int>& NombreDeTermesDesLignes;
45 std::string& Sens;
46 int& IncrementDAllocationMatriceDesContraintes;
47 std::vector<CORRESPONDANCES_DES_VARIABLES>& CorrespondanceVarNativesVarOptim;
48 const int32_t& NombreDePasDeTempsPourUneOptimisation;
49 std::vector<int>& NumeroDeVariableStockFinal;
50 std::vector<std::vector<int>>& NumeroDeVariableDeTrancheDeStock;
51 std::vector<std::string>& NomDesContraintes;
52 const bool& NamedProblems;
53 const std::vector<const char*>& NomsDesPays;
54 const uint32_t& weekInTheYear;
55 const uint32_t& NombreDePasDeTemps;
56};
57
71{
72public:
73 ConstraintBuilder() = delete;
74
76 data(data),
77 variableManager_(data.CorrespondanceVarNativesVarOptim,
78 data.NumeroDeVariableStockFinal,
79 data.NumeroDeVariableDeTrancheDeStock,
80 data.NombreDePasDeTempsPourUneOptimisation)
81 {
82 }
83
84 ConstraintBuilder& updateHourWithinWeek(unsigned hour)
85 {
86 hourInWeek_ = hour;
87 return *this;
88 }
89
98 ConstraintBuilder& DispatchableProduction(unsigned int index,
99 double coeff,
100 int offset = 0,
101 int delta = 0);
102
103 ConstraintBuilder& NumberOfDispatchableUnits(unsigned int index, double coeff);
104
105 ConstraintBuilder& NumberStoppingDispatchableUnits(unsigned int index, double coeff);
106
107 ConstraintBuilder& NumberStartingDispatchableUnits(unsigned int index, double coeff);
108
109 ConstraintBuilder& NumberBreakingDownDispatchableUnits(unsigned int index, double coeff);
110
111 ConstraintBuilder& NTCDirect(unsigned int index, double coeff, int offset = 0, int delta = 0);
112
113 ConstraintBuilder& IntercoDirectCost(unsigned int index, double coeff);
114
115 ConstraintBuilder& IntercoIndirectCost(unsigned int index, double coeff);
116
117 ConstraintBuilder& ShortTermStorageInjection(unsigned int index,
118 double coeff,
119 int offset = 0,
120 int delta = 0);
121
122 ConstraintBuilder& ShortTermStorageWithdrawal(unsigned int index,
123 double coeff,
124 int offset = 0,
125 int delta = 0);
126
127 ConstraintBuilder& ShortTermStorageLevel(unsigned int index,
128 double coeff,
129 int offset = 0,
130 int delta = 0);
131 ConstraintBuilder& ShortTermCostVariationInjection(unsigned int index,
132 double coeff,
133 int offset = 0,
134 int delta = 0);
135 ConstraintBuilder& ShortTermCostVariationWithdrawal(unsigned int index,
136 double coeff,
137 int offset = 0,
138 int delta = 0);
139
140 ConstraintBuilder& HydProd(unsigned int index, double coeff);
141
142 ConstraintBuilder& HydProdDown(unsigned int index, double coeff);
143
144 ConstraintBuilder& HydProdUp(unsigned int index, double coeff);
145
146 ConstraintBuilder& Pumping(unsigned int index, double coeff);
147
148 ConstraintBuilder& HydroLevel(unsigned int index, double coeff);
149
150 ConstraintBuilder& Overflow(unsigned int index, double coeff);
151
152 ConstraintBuilder& FinalStorage(unsigned int index, double coeff);
153
154 ConstraintBuilder& PositiveUnsuppliedEnergy(unsigned int index, double coeff);
155
156 ConstraintBuilder& NegativeUnsuppliedEnergy(unsigned int index, double coeff);
157
158 ConstraintBuilder& LayerStorage(unsigned area, unsigned layer, double coeff);
159
161
162 class ConstraintBuilderInvalidOperator: public std::runtime_error
163 {
164 public:
165 using std::runtime_error::runtime_error;
166 };
167
174 {
175 if (op == '<' || op == '=' || op == '>')
176 {
177 operator_ = op;
178 }
179 else
180 {
181 throw ConstraintBuilderInvalidOperator(std::string("Invalid operator: ") + op);
182 }
183
184 return *this;
185 }
186
193 {
194 operator_ = '=';
195 return *this;
196 }
197
204 {
205 operator_ = '<';
206 return *this;
207 }
208
215 {
216 operator_ = '>';
217 return *this;
218 }
219
224 void build();
225
226 int NumberOfVariables() const
227 {
228 return nombreDeTermes_;
229 }
230
232
233private:
234 void OPT_ChargerLaContrainteDansLaMatriceDesContraintes();
235
236 unsigned int hourInWeek_ = 0;
237
238 char operator_ = '=';
239 int nombreDeTermes_ = 0;
240
241 void AddVariable(int index, double coeff);
242
250};
251
254{
255public:
256 ConstraintFactory() = delete;
257
258 explicit ConstraintFactory(ConstraintBuilder& builder):
259 builder(builder)
260 {
261 }
262
263 ConstraintBuilder& builder;
264};
265
266// Helper functions
267inline void ExportPaliers(const PALIERS_THERMIQUES& PaliersThermiquesDuPays,
268 ConstraintBuilder& newConstraintBuilder)
269{
270 for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
271 {
272 const int palier = PaliersThermiquesDuPays
273 .NumeroDuPalierDansLEnsembleDesPaliersThermiques[index];
274 newConstraintBuilder.DispatchableProduction(palier, -1.0);
275 }
276}
277
279{
280public:
281 const char& TypeDeContrainteCouplante;
282 const int& NombreDInterconnexionsDansLaContrainteCouplante;
283 const std::vector<int>& NumeroDeLInterconnexion;
284 const std::vector<double>& PoidsDeLInterconnexion;
285 const std::vector<int>& OffsetTemporelSurLInterco;
286 const int& NombreDePaliersDispatchDansLaContrainteCouplante;
287 const std::vector<int>& PaysDuPalierDispatch;
288 const std::vector<int>& NumeroDuPalierDispatch;
289 const std::vector<double>& PoidsDuPalierDispatch;
290 const std::vector<int>& OffsetTemporelSurLePalierDispatch;
291 const char& SensDeLaContrainteCouplante;
292 const char* const& NomDeLaContrainteCouplante;
293 const std::vector<PALIERS_THERMIQUES>& PaliersThermiquesDuPays;
294};
295
297{
298 const std::vector<PALIERS_THERMIQUES>& PaliersThermiquesDuPays;
299 bool Simulation;
300};
301
303{
304 std::vector<CORRESPONDANCES_DES_CONTRAINTES>& CorrespondanceCntNativesCntOptim;
305
306 const std::vector<::ShortTermStorage::AREA_INPUT>& ShortTermStorage;
307};
308
310{
311 CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires;
312};
Definition ConstraintBuilder.h:279
Definition ConstraintBuilder.h:35
Definition ConstraintBuilder.h:163
Definition ConstraintBuilder.h:71
ConstraintBuilder & lessThan()
set the sign of the constraint to '<', building a constraint less than rhs
Definition ConstraintBuilder.h:203
ConstraintBuilder & equalTo()
set the sign of the constraint to '=', building a constraint equal to rhs
Definition ConstraintBuilder.h:192
ConstraintBuilder & greaterThan()
set the sign of the constraint to '>', building a constraint greather than rhs
Definition ConstraintBuilder.h:214
void build()
add the constraint in the matrix
Definition ConstraintBuilder.cpp:24
ConstraintBuilder & SetOperator(char op)
set the operator of the constraint (sign)
Definition ConstraintBuilder.h:173
Definition ConstraintBuilder.h:254
Definition ShortTermStorageLevel.h:26
Definition SparseVector.hxx:5
Definition VariableManagement.h:12
Definition sim_structure_probleme_economique.h:112
Definition sim_structure_probleme_economique.h:267
Definition ConstraintBuilder.h:310
Definition ConstraintBuilder.h:303
Definition ConstraintBuilder.h:297