Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
solver_utils.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#ifndef __SOLVER_SIMULATION_SOLVER_UTILS_H__
22#define __SOLVER_SIMULATION_SOLVER_UTILS_H__
23
24#include <limits> // For std numeric_limits
25#include <map>
26#include <vector>
27
28#include <antares/study/fwd.h>
29#include <antares/writer/i_writer.h>
30
31namespace Antares::Solver::Simulation
32{
34{
35 // Un lot d'année à exécuter en parallèle.
36 // En fonction d'une éventuelle play-list, certaines seront jouées et d'autres non.
37
38public:
39 // Numeros des annees en parallele pour ce lot (certaines ne seront pas jouées en cas de
40 // play-list "trouée")
41 std::vector<unsigned int> yearsIndices;
42
43 // Une annee doit-elle être rejouée ?
44 std::map<uint, bool> yearFailed;
45
46 // Associe le numero d'une année jouée à l'indice de l'espace
47 std::map<unsigned int, unsigned int> performedYearToSpace;
48
49 // L'inverse : pour une année jouée, associe l'indice de l'espace au numero de l'année
50 std::map<unsigned int, unsigned int> spaceToPerformedYear;
51
52 // Pour chaque année, est-elle la première à devoir être jouée dans son lot d'années ?
53 std::map<unsigned int, bool> isFirstPerformedYearOfASet;
54
55 // Pour chaque année du lot, est-elle jouée ou non ?
56 std::map<unsigned int, bool> isYearPerformed;
57
58 // Nbre d'années en parallele vraiment jouées pour ce lot
59 unsigned int nbPerformedYears;
60
61 // Nbre d'années en parallele jouées ou non pour ce lot
62 unsigned int nbYears;
63
64 // Regenere-t-on des times series avant de jouer les annees du lot courant
65 bool regenerateTS;
66
67 // Annee a passer a la fonction "regenerateTimeSeries<false>(y)" (si regenerateTS is "true")
68 unsigned int yearForTSgeneration;
69};
70
72{
73public:
74 void setNbPerformedYears(uint n);
75 void addCost(const double cost);
76 void endStandardDeviation();
77
78 // System costs statistics
79 double costAverage = 0.;
80 double costStdDeviation = 0.;
81 double costMin = std::numeric_limits<double>::max();
82 double costMax = 0.;
83
84private:
85 // Total number of performed years in the study
86 uint nbPerformedYears = 0.;
87};
88
90{
91public:
92 // Costs
93 costStatistics systemCost;
94 costStatistics criterionCost1;
95 costStatistics criterionCost2;
96 costStatistics optimizationTime1;
97 costStatistics optimizationTime2;
98 costStatistics updateTime;
99
101 void setNbPerformedYears(uint n);
102 void endStandardDeviations();
103 void writeToOutput(IResultWriter& writer);
104
105private:
106 void writeSystemCostToOutput(IResultWriter& writer);
107 void writeCriterionCostsToOutput(IResultWriter& writer) const;
108 void writeUpdateTimes(IResultWriter& writer) const;
109 void writeOptimizationTimeToOutput(IResultWriter& writer) const;
110};
111
113{
114public:
116 {
117 pNbAreas = 0;
118 }
119
120 ~yearRandomNumbers() = default;
121
122 void setNbAreas(uint nbAreas)
123 {
124 pNbAreas = nbAreas;
125 }
126
127 void setPowerFluctuations(Data::PowerFluctuations powerFluctuations)
128 {
129 pPowerFluctuations = powerFluctuations;
130 }
131
132 void reset()
133 {
134 // Thermal noises
135 for (uint a = 0; a != pNbAreas; a++)
136 {
137 pThermalNoisesByArea[a].assign(pThermalNoisesByArea[a].size(), 0);
138 }
139
140 // General
141 pNbClustersByArea.assign(pNbAreas, 0);
142
143 // Reservoir levels, spilled and unsupplied energy costs
144 pReservoirLevels.assign(pNbAreas, 0);
145 pUnsuppliedEnergy.assign(pNbAreas, 0);
146 pSpilledEnergy.assign(pNbAreas, 0);
147
148 // Hydro costs noises
149 switch (pPowerFluctuations)
150 {
151 case Data::lssFreeModulations:
152 {
153 for (uint a = 0; a != pNbAreas; a++)
154 {
155 pHydroCostsByArea_freeMod[a].assign(8784, 0);
156 }
157 break;
158 }
159
160 case Data::lssMinimizeRamping:
161 case Data::lssMinimizeExcursions:
162 {
163 pHydroCosts_rampingOrExcursion.assign(pNbAreas, 0);
164 break;
165 }
166
167 case Data::lssUnknown:
168 break;
169 }
170 }
171
172 // General data
173 uint pNbAreas;
174 Data::PowerFluctuations pPowerFluctuations;
175
176 // Data for thermal noises
177 std::vector<std::vector<double>> pThermalNoisesByArea;
178 std::vector<size_t> pNbClustersByArea;
179
180 // Data for reservoir levels
181 std::vector<double> pReservoirLevels;
182
183 // Data for unsupplied and spilled energy costs
184 std::vector<double> pUnsuppliedEnergy;
185 std::vector<double> pSpilledEnergy;
186
187 // Hydro costs noises
188 std::vector<std::vector<double>> pHydroCostsByArea_freeMod;
189 std::vector<double> pHydroCosts_rampingOrExcursion;
190};
191
193{
194public:
195 randomNumbers(uint maxNbPerformedYearsInAset, Data::PowerFluctuations powerFluctuations):
196 pMaxNbPerformedYears(maxNbPerformedYearsInAset)
197 {
198 // Allocate a table of parallel years structures
199 pYears.resize(maxNbPerformedYearsInAset);
200
201 // Tells these structures their power fluctuations mode
202 for (uint y = 0; y < maxNbPerformedYearsInAset; ++y)
203 {
204 pYears[y].setPowerFluctuations(powerFluctuations);
205 }
206 }
207
208 ~randomNumbers() = default;
209
210 void reset()
211 {
212 for (uint i = 0; i < pMaxNbPerformedYears; i++)
213 {
214 pYears[i].reset();
215 }
216
217 yearNumberToIndex.clear();
218 }
219
220 uint pMaxNbPerformedYears;
221 std::vector<yearRandomNumbers> pYears;
222
223 // Associates :
224 // year number (0, ..., total nb of years to compute - 1) --> index of the year's space
225 //(0,
226 //..., max nb of parallel years - 1)
227 std::map<uint, uint> yearNumberToIndex;
228};
229
230// Class representing a hydro cost noise.
231// This class allows sorting hydro costs noises into increasing absolute values order
232// when instances are contained in a :
233// std::set<hydroCostNoise, compareHydroCostsNoises>
235{
236public:
237 hydroCostNoise(double v, uint i):
238 value(v),
239 index(i)
240 {
241 }
242
243 inline double getValue() const
244 {
245 return value;
246 }
247
248 inline uint getIndex() const
249 {
250 return index;
251 }
252
253 double value;
254 uint index;
255};
256
257// Used to sort the hydro costs noises into increasing absolute values order in a std::set
259{
260 inline bool operator()(const hydroCostNoise& hcnr1, const hydroCostNoise& hcnr2) const
261 {
262 return std::abs(hcnr1.getValue()) < std::abs(hcnr2.getValue());
263 }
264};
265} // namespace Antares::Solver::Simulation
266
267#endif // __SOLVER_SIMULATION_SOLVER_H__
Definition i_writer.h:34
Definition solver_utils.h:235
Definition solver_utils.h:193