Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
bindConstraints.hxx
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#include <vector>
25
26#include "antares/study/binding_constraint/BindingConstraint.h"
27#include "antares/study/fwd.h"
28
29#include "bindConstraints.h"
30
31namespace Antares::Solver::Variable
32{
33template<class NextT>
34void 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
52template<class NextT>
53void 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
72template<class NextT>
73template<class PredicateT>
74inline void BindingConstraints<NextT>::RetrieveVariableList(PredicateT& predicate)
75{
76 NextType::RetrieveVariableList(predicate);
77}
78
79template<class NextT>
80template<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
101template<class NextT>
102void BindingConstraints<NextT>::simulationBegin()
103{
104 for (auto& bc: pBindConstraints)
105 {
106 bc.simulationBegin();
107 }
108}
109
110template<class NextT>
111void BindingConstraints<NextT>::simulationEnd()
112{
113 for (auto& bc: pBindConstraints)
114 {
115 bc.simulationEnd();
116 }
117}
118
119template<class NextT>
120void BindingConstraints<NextT>::yearEndBuild(State& /*state*/, uint /*year*/, uint /*numSpace*/)
121{
122}
123
124template<class NextT>
125void 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
170template<class NextT>
171void BindingConstraints<NextT>::computeSummary(std::map<unsigned int, unsigned int>& numSpaceToYear,
172 unsigned int nbYearsForCurrentSummary)
173{
174 for (uint i = 0; i != pBCcount; ++i)
175 {
176 // Broadcast to all constraints
177 pBindConstraints[i].computeSummary(numSpaceToYear, nbYearsForCurrentSummary);
178 }
179}
180
181template<class NextT>
182void BindingConstraints<NextT>::yearBegin(uint year, uint numSpace)
183{
184 // Broadcast to all binding constraints
185 for (uint i = 0; i != pBCcount; ++i)
186 {
187 pBindConstraints[i].yearBegin(year, numSpace);
188 }
189}
190
191template<class NextT>
192void BindingConstraints<NextT>::yearEnd(uint year, uint numSpace)
193{
194 // Broadcast to all binding constraints
195 for (uint i = 0; i != pBCcount; ++i)
196 {
197 pBindConstraints[i].yearEnd(year, numSpace);
198 }
199}
200
201template<class NextT>
202void BindingConstraints<NextT>::weekBegin(State& state)
203{
204 for (uint i = 0; i != pBCcount; ++i)
205 {
206 pBindConstraints[i].weekBegin(state);
207 }
208}
209
210template<class NextT>
211void BindingConstraints<NextT>::weekEnd(State& state)
212{
213 for (uint i = 0; i != pBCcount; ++i)
214 {
215 pBindConstraints[i].weekEnd(state);
216 }
217}
218
219template<class NextT>
220void BindingConstraints<NextT>::hourBegin(uint hourInTheYear)
221{
222 for (uint i = 0; i != pBCcount; ++i)
223 {
224 pBindConstraints[i].hourBegin(hourInTheYear);
225 }
226}
227
228template<class NextT>
229void BindingConstraints<NextT>::hourEnd(State& state, uint hourInTheYear)
230{
231 for (uint i = 0; i != pBCcount; ++i)
232 {
233 pBindConstraints[i].hourEnd(state, hourInTheYear);
234 }
235}
236
237template<class NextT>
238void BindingConstraints<NextT>::weekForEachArea(State& state, unsigned int numSpace)
239{
240 for (uint i = 0; i != pBCcount; ++i)
241 {
242 pBindConstraints[i].weekForEachArea(state, numSpace);
243 }
244}
245
246template<class NextT>
247void BindingConstraints<NextT>::hourForEachArea(State& state, unsigned int numSpace)
248{
249 for (uint i = 0; i != pBCcount; ++i)
250 {
251 pBindConstraints[i].hourForEachArea(state, numSpace);
252 }
253}
254
255template<class NextT>
256template<class VCardToFindT>
257inline void BindingConstraints<NextT>::retrieveResultsForArea(
258 typename Storage<VCardToFindT>::ResultsType** result,
259 const Data::Area* area)
260{
261 NextType::template retrieveResultsForArea<VCardToFindT>(result, area);
262}
263
264template<class NextT>
265void BindingConstraints<NextT>::buildDigest(SurveyResults& results,
266 int digestLevel,
267 int dataLevel) const
268{
269 for (uint i = 0; i != pBCcount; ++i)
270 {
271 pBindConstraints[i].buildDigest(results, digestLevel, dataLevel);
272 }
273}
274
275template<class NextT>
276template<class V>
277void BindingConstraints<NextT>::simulationEndSpatialAggregates(V& allVars)
278{
279 NextType::template simulationEndSpatialAggregates<V>(allVars);
280}
281
282template<class NextT>
283template<class V>
284void BindingConstraints<NextT>::computeSpatialAggregatesSummary(
285 V& allVars,
286 std::map<unsigned int, unsigned int>& numSpaceToYear,
287 unsigned int nbYearsForCurrentSummary)
288{
289 NextType::template computeSpatialAggregatesSummary<V>(allVars,
290 numSpaceToYear,
291 nbYearsForCurrentSummary);
292}
293
294template<class NextT>
295void BindingConstraints<NextT>::beforeYearByYearExport(uint year, uint numSpace)
296{
297 for (uint i = 0; i != pBCcount; ++i)
298 {
299 pBindConstraints[i].beforeYearByYearExport(year, numSpace);
300 }
301}
302
303template<class NextT>
304template<class SearchVCardT, class O>
305inline void BindingConstraints<NextT>::computeSpatialAggregateWith(O& out,
306 const Data::Area* area,
307 uint numSpace)
308{
309 NextType::template computeSpatialAggregateWith<SearchVCardT, O>(out, area, numSpace);
310}
311
312template<class NextT>
313template<class VCardToFindT>
314inline void BindingConstraints<NextT>::retrieveResultsForLink(
315 typename Storage<VCardToFindT>::ResultsType** result,
316 const Data::AreaLink* link)
317{
318 NextType::template retrieveResultsForLink<VCardToFindT>(result, link);
319}
320
321template<class NextT>
322template<class VCardToFindT>
323inline void BindingConstraints<NextT>::retrieveResultsForThermalCluster(
324 typename Storage<VCardToFindT>::ResultsType** result,
325 const Data::ThermalCluster* cluster)
326{
327 NextType::template retrieveResultsForThermalCluster<VCardToFindT>(result, cluster);
328}
329} // namespace Antares::Solver::Variable
Definition for a single area.
Definition area.h:52
Definition study.h:61
A single thermal cluster.
Definition cluster.h:78
Definition bindConstraints.h:72
static void RetrieveVariableList(PredicateT &predicate)
Retrieve the list of all individual variables.
Definition bindConstraints.hxx:74
Definition cbuilder.h:120
VariableAccessor< typenameVCardT::ResultsType, VCardT::columnCount >::Type ResultsType
The true type used for the results.
Definition info.h:764