Antares Simulator
Power System Simulator
hourly_csr_problem.h
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 
22 #pragma once
23 
24 // TODO[FOM] Remove this, it is only required for PROBLEME_HEBDO
25 // but this problem has nothing to do with PROBLEME_HEBDO
26 #include <set>
27 
28 #include <antares/logs/logs.h>
29 #include <antares/study/parameters/adq-patch-params.h>
30 #include "antares/solver/optimisation/opt_structure_probleme_a_resoudre.h"
31 
32 #include "../variables/VariableManagerUtils.h"
33 
35 {
36  LinkVariable():
37  directVar(-1),
38  indirectVar(-1)
39  {
40  }
41 
42  LinkVariable(int direct, int indirect):
43  directVar(direct),
44  indirectVar(indirect)
45  {
46  }
47 
48  inline bool check() const
49  {
50  if (directVar < 0)
51  {
52  Antares::logs.warning() << "directVar < 0 detected, this should not happen";
53  }
54  if (indirectVar < 0)
55  {
56  Antares::logs.warning() << "indirectVar < 0 detected, this should not happen";
57  }
58 
59  return (directVar >= 0) && (indirectVar >= 0);
60  }
61 
62  int directVar;
63  int indirectVar;
64 };
65 
66 struct PROBLEME_HEBDO;
67 
68 class HourlyCSRProblem final
69 {
71 
72 public:
73  explicit HourlyCSRProblem(const AdqPatchParams& adqPatchParams,
74  PROBLEME_HEBDO* p,
75  const Solver::Optimization::OptimizationOptions& solverOptions):
76  solverOptions_(solverOptions),
77  adqPatchParams_(adqPatchParams),
78  variableManager_(p->CorrespondanceVarNativesVarOptim,
79  p->NumeroDeVariableStockFinal,
80  p->NumeroDeVariableDeTrancheDeStock,
81  p->NombreDePasDeTempsPourUneOptimisation),
82  problemeHebdo_(p)
83  {
84  double temp = pow(10, -adqPatchParams.curtailmentSharing.thresholdVarBoundsRelaxation);
85  belowThisThresholdSetToZero = std::min(temp, 0.1);
86 
87  allocateProblem();
88  }
89 
90  HourlyCSRProblem(const HourlyCSRProblem&) = delete;
91  HourlyCSRProblem& operator=(const HourlyCSRProblem&) = delete;
92 
93  inline void setHour(int hour)
94  {
95  triggeredHour = hour;
96  }
97 
98  void run(unsigned int week, unsigned int year);
99 
100 private:
101  void calculateCsrParameters();
102 
103  void buildProblemVariables();
104  void setVariableBounds();
105  void buildProblemConstraintsLHS();
106  void buildProblemConstraintsRHS();
107  void setProblemCost();
108  void solveProblem(unsigned int week,
109  int year,
111  void allocateProblem();
112 
113  // variable construction
114  void constructVariableENS();
115  void constructVariableSpilledEnergy();
116  void constructVariableFlows();
117 
118  // variable bounds
119  void setBoundsOnENS();
120  void setBoundsOnSpilledEnergy();
121  void setBoundsOnFlows();
122 
123  // Constraints
124  void setRHSvalueOnFlows();
125  void setRHSnodeBalanceValue();
126  void setRHSbindingConstraintsValue();
127 
128  // Costs
129  void setQuadraticCost();
130  void setLinearCost();
131 
132  const Solver::Optimization::OptimizationOptions& solverOptions_;
133 
134 public:
135  // TODO [gp] : try to make these members private
136  double belowThisThresholdSetToZero;
137  std::map<int, int> numberOfConstraintCsrAreaBalance;
138  std::set<int> ensVariablesInsideAdqPatch; // place inside only ENS inside adq-patch
139  std::set<int> varToBeSetToZeroIfBelowThreshold; // place inside only ENS and Spillage variable
140  int triggeredHour;
141 
142  const AdqPatchParams& adqPatchParams_;
143  VariableManagement::VariableManager variableManager_;
144 
145  PROBLEME_HEBDO* problemeHebdo_;
146  PROBLEME_ANTARES_A_RESOUDRE problemeAResoudre_;
147 
148  std::map<int, int> numberOfConstraintCsrEns;
149  std::map<int, int> numberOfConstraintCsrFlowDissociation;
150  std::map<int, int> numberOfConstraintCsrHourlyBinding; // length is number of binding constraint
151  // contains interco 2-2
152 
153  std::map<int, double> rhsAreaBalanceValues;
154 
155  // links between two areas inside the adq-patch domain
156  std::map<int, LinkVariable> linkInsideAdqPatch;
157 };
int thresholdVarBoundsRelaxation
CSR Variables relaxation threshold.
Definition: adq-patch-params.h:98
Definition: hourly_csr_problem.h:69
Definition: opt_structure_probleme_a_resoudre.h:35
Definition: VariableManagement.h:12
Definition: adq-patch-params.h:114
Definition: hourly_csr_problem.h:35
Definition: sim_structure_probleme_economique.h:403