Antares Simulator
Power System Simulator
bindConstraints.hxx
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 #pragma once
22 
23 #include <utility>
24 #include <vector>
25 
26 #include "antares/study/binding_constraint/BindingConstraint.h"
27 #include "antares/study/fwd.h"
28 
29 #include "bindConstraints.h"
30 
31 namespace Antares::Solver::Variable
32 {
33 template<class NextT>
34 void BindingConstraints<NextT>::buildSurveyReport(SurveyResults& results,
35  int dataLevel,
36  int fileLevel,
37  int precision) const
38 {
39  if (bool bcDataLevel = dataLevel & Category::DataLevel::bindingConstraint; !bcDataLevel)
40  {
41  return;
42  }
43 
44  for (uint i = 0; i != pBCcount; ++i)
45  {
46  const NextType& bc = pBindConstraints[i];
47 
48  bc.buildSurveyReport(results, dataLevel, fileLevel, precision);
49  }
50 }
51 
52 template<class NextT>
53 void BindingConstraints<NextT>::buildAnnualSurveyReport(SurveyResults& results,
54  int dataLevel,
55  int fileLevel,
56  int precision,
57  uint numSpace) const
58 {
59  if (bool bcDataLevel = dataLevel & Category::DataLevel::bindingConstraint; !bcDataLevel)
60  {
61  return;
62  }
63 
64  for (uint i = 0; i != pBCcount; ++i)
65  {
66  const NextType& bc = pBindConstraints[i];
67 
68  bc.buildAnnualSurveyReport(results, dataLevel, fileLevel, precision, numSpace);
69  }
70 }
71 
72 template<class NextT>
73 template<class PredicateT>
74 inline void BindingConstraints<NextT>::RetrieveVariableList(PredicateT& predicate)
75 {
76  NextType::RetrieveVariableList(predicate);
77 }
78 
79 template<class NextT>
80 template<class I>
82 {
83  // Begining of the node
84  if (VCardType::nodeDepthForGUI)
85  {
86  infos.template beginNode<VCardType>();
87  // Next variable in the list
88  NextType::template provideInformations<I>(infos);
89  // End of the node
90  infos.endNode();
91  }
92  else
93  {
94  // Giving our VCard
95  infos.template addVCard<VCardType>();
96  // Next variable in the list
97  NextType::template provideInformations<I>(infos);
98  }
99 }
100 
101 template<class NextT>
102 void BindingConstraints<NextT>::simulationBegin()
103 {
104  for (auto& bc: pBindConstraints)
105  {
106  bc.simulationBegin();
107  }
108 }
109 
110 template<class NextT>
111 void BindingConstraints<NextT>::simulationEnd()
112 {
113  for (auto& bc: pBindConstraints)
114  {
115  bc.simulationEnd();
116  }
117 }
118 
119 template<class NextT>
120 void BindingConstraints<NextT>::yearEndBuild(State& /*state*/, uint /*year*/, uint /*numSpace*/)
121 {
122 }
123 
124 template<class NextT>
125 void BindingConstraints<NextT>::initializeFromStudy(Data::Study& study)
126 {
127  const std::vector<std::shared_ptr<Data::BindingConstraint>>
128  inequalityByPtr = study.bindingConstraints.getPtrForInequalityBindingConstraints();
129 
130  // The total number of inequality binding constraints count
131  // (we don't count BCs with equality sign)
132  pBCcount = (uint)inequalityByPtr.size();
133 
134  // Reserving the memory
135  if (pBCcount > 0)
136  {
137  pBindConstraints.resize(pBCcount);
138  }
139 
140  for (uint i = 0; i != pBCcount; ++i)
141  {
142  NextType& bc = pBindConstraints[i];
143 
144  bc.setAssociatedBindConstraint(inequalityByPtr[i]);
145  bc.initializeFromStudy(study);
146 
147  // Does user want to print output results related to the current binding constraint ?
148  bc.getPrintStatusFromStudy(study);
149  }
150 
151  // Here we supply the max number of columns to the variable print info collector
152  // This is a ugly hack (it's a work around).
153  // We should have a simple call to :
154  // NextType::supplyMaxNumberOfColumns(study);
155  // Instead, we have a few lines as a hack.
156  // What we have to do is add to the print info collector a single VariablePrintInfo
157  // that has a max columns size of : (nb of inequality BCs) x ResultsType::count
158  // But note that for now, BC output variables are chained statically (one output variable per
159  // inequality BC). The hack is to make the first BC output variable able to supply max columns
160  // size for all BC output variables with its method getMaxNumberColumns(). A solution would be
161  // to make BC output variables (like BindingConstMarginCost) some DYNAMIC variables.
162  if (pBCcount > 0)
163  {
164  NextType& bc = pBindConstraints[0];
165  bc.setBindConstraintsCount(pBCcount);
166  bc.supplyMaxNumberOfColumns(study);
167  }
168 }
169 
170 template<class NextT>
171 void BindingConstraints<NextT>::computeSummary(unsigned int year, unsigned int numSpace)
172 {
173  for (uint i = 0; i != pBCcount; ++i)
174  {
175  // Broadcast to all constraints
176  pBindConstraints[i].computeSummary(year, numSpace);
177  }
178 }
179 
180 template<class NextT>
181 void BindingConstraints<NextT>::yearBegin(uint year, uint numSpace)
182 {
183  // Broadcast to all binding constraints
184  for (uint i = 0; i != pBCcount; ++i)
185  {
186  pBindConstraints[i].yearBegin(year, numSpace);
187  }
188 }
189 
190 template<class NextT>
191 void BindingConstraints<NextT>::yearEnd(uint year, uint numSpace)
192 {
193  // Broadcast to all binding constraints
194  for (uint i = 0; i != pBCcount; ++i)
195  {
196  pBindConstraints[i].yearEnd(year, numSpace);
197  }
198 }
199 
200 template<class NextT>
201 void BindingConstraints<NextT>::weekBegin(State& state)
202 {
203  for (uint i = 0; i != pBCcount; ++i)
204  {
205  pBindConstraints[i].weekBegin(state);
206  }
207 }
208 
209 template<class NextT>
210 void BindingConstraints<NextT>::weekEnd(State& state)
211 {
212  for (uint i = 0; i != pBCcount; ++i)
213  {
214  pBindConstraints[i].weekEnd(state);
215  }
216 }
217 
218 template<class NextT>
219 void BindingConstraints<NextT>::hourBegin(uint hourInTheYear)
220 {
221  for (uint i = 0; i != pBCcount; ++i)
222  {
223  pBindConstraints[i].hourBegin(hourInTheYear);
224  }
225 }
226 
227 template<class NextT>
228 void BindingConstraints<NextT>::hourEnd(State& state, uint hourInTheYear)
229 {
230  for (uint i = 0; i != pBCcount; ++i)
231  {
232  pBindConstraints[i].hourEnd(state, hourInTheYear);
233  }
234 }
235 
236 template<class NextT>
237 void BindingConstraints<NextT>::weekForEachArea(State& state, unsigned int numSpace)
238 {
239  for (uint i = 0; i != pBCcount; ++i)
240  {
241  pBindConstraints[i].weekForEachArea(state, numSpace);
242  }
243 }
244 
245 template<class NextT>
246 void BindingConstraints<NextT>::hourForEachArea(State& state, unsigned int numSpace)
247 {
248  for (uint i = 0; i != pBCcount; ++i)
249  {
250  pBindConstraints[i].hourForEachArea(state, numSpace);
251  }
252 }
253 
254 template<class NextT>
255 template<class VCardToFindT>
256 inline void BindingConstraints<NextT>::retrieveResultsForArea(
257  typename Storage<VCardToFindT>::ResultsType** result,
258  const Data::Area* area)
259 {
260  NextType::template retrieveResultsForArea<VCardToFindT>(result, area);
261 }
262 
263 template<class NextT>
264 void BindingConstraints<NextT>::buildDigest(SurveyResults& results,
265  int digestLevel,
266  int dataLevel) const
267 {
268  for (uint i = 0; i != pBCcount; ++i)
269  {
270  pBindConstraints[i].buildDigest(results, digestLevel, dataLevel);
271  }
272 }
273 
274 template<class NextT>
275 template<class V>
276 void BindingConstraints<NextT>::simulationEndSpatialAggregates(V& allVars)
277 {
278  NextType::template simulationEndSpatialAggregates<V>(allVars);
279 }
280 
281 template<class NextT>
282 template<class V>
283 void BindingConstraints<NextT>::computeSpatialAggregatesSummary(V& allVars,
284  unsigned int year,
285  unsigned int numSpace)
286 {
287  NextType::template computeSpatialAggregatesSummary<V>(allVars, year, numSpace);
288 }
289 
290 template<class NextT>
291 void BindingConstraints<NextT>::beforeYearByYearExport(uint year, uint numSpace)
292 {
293  for (uint i = 0; i != pBCcount; ++i)
294  {
295  pBindConstraints[i].beforeYearByYearExport(year, numSpace);
296  }
297 }
298 
299 template<class NextT>
300 template<class SearchVCardT, class O>
301 inline void BindingConstraints<NextT>::computeSpatialAggregateWith(O& out,
302  const Data::Area* area,
303  uint numSpace)
304 {
305  NextType::template computeSpatialAggregateWith<SearchVCardT, O>(out, area, numSpace);
306 }
307 
308 template<class NextT>
309 template<class VCardToFindT>
310 inline void BindingConstraints<NextT>::retrieveResultsForLink(
311  typename Storage<VCardToFindT>::ResultsType** result,
312  const Data::AreaLink* link)
313 {
314  NextType::template retrieveResultsForLink<VCardToFindT>(result, link);
315 }
316 
317 template<class NextT>
318 template<class VCardToFindT>
319 inline void BindingConstraints<NextT>::retrieveResultsForThermalCluster(
320  typename Storage<VCardToFindT>::ResultsType** result,
321  const Data::ThermalCluster* cluster)
322 {
323  NextType::template retrieveResultsForThermalCluster<VCardToFindT>(result, cluster);
324 }
325 } // namespace Antares::Solver::Variable
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
A single thermal cluster.
Definition: cluster.h:76
Definition: bindConstraints.h:68
static void RetrieveVariableList(PredicateT &predicate)
Retrieve the list of all individual variables.
Definition: bindConstraints.hxx:74
Definition: cbuilder.h:120
VariableAccessor< typename VCardT::ResultsType, VCardT::columnCount >::Type ResultsType
The true type used for the results.
Definition: info.h:760