21 #ifndef __ANTARES_CONSTRAINTSBUILDER_BUILDER_CBUILDER_H__
22 #define __ANTARES_CONSTRAINTSBUILDER_BUILDER_CBUILDER_H__
24 #include <yuni/yuni.h>
25 #include <yuni/core/string.h>
27 #include <antares/study/study.h>
28 #include "antares/solver/constraints-builder/grid.h"
29 #include "antares/study/area/constants.h"
31 #define CB_PREFIX "@UTO_"
41 nodeName = area->name.to<std::string>();
59 Data::AreaLinkName name;
60 Antares::Data::AssetType type;
63 bool hasPShiftsEqual =
true;
65 uint nImpedanceChanges;
70 double getWeightWithImpedance()
const;
71 Yuni::String getName()
const;
81 return lhs->getWeightWithImpedance() < rhs->getWeightWithImpedance();
89 return lhs->getWeightWithImpedance() < rhs->getWeightWithImpedance();
95 double operator()(
double i,
const linkInfo* o)
const
97 return (o->getWeightWithImpedance() + i);
103 double operator()(
double i,
const linkInfo* o)
const
105 return (o->getWeightWithImpedance() + i);
109 bool operator<(
const linkInfo& other)
const
111 return getWeightWithImpedance() < other.getWeightWithImpedance()
113 : (getWeightWithImpedance() > other.getWeightWithImpedance()
115 : getName() < other.getName());
122 State(std::vector<double> impedancesList, uint time,
double infinite = 1000000):
123 secondMember(3, time),
124 impedances(impedancesList)
131 std::vector<double> impedances;
132 std::map<linkInfo*, double> WeightMap;
138 Cycle(
const std::vector<linkInfo*>& linkList,
double infinite = 1000000):
141 opType(Data::BindingConstraint::opEquality),
144 uint columnImpedance = (uint)Antares::Data::fhlImpedances;
146 std::vector<double> impedances;
148 double currentLineSign = 1;
149 for (
auto line = linkList.begin(); line != linkList.end(); line++)
151 if ((*line)->nImpedanceChanges > 0
152 || ((*line)->type == Antares::Data::atAC && (!(*line)->hasPShiftsEqual)))
154 opType = Data::BindingConstraint::opBoth;
156 impedances.push_back((*line)->ptr->parameters[columnImpedance][0]);
158 time = HOURS_PER_YEAR;
161 if (line == linkList.begin())
167 if (previousLine->
with == (*line)->ptr->from
168 || previousLine->
from
169 == (*line)->ptr->with)
172 else if (previousLine->
from == (*line)->ptr->from
173 || previousLine->
with == (*line)->ptr->with)
175 currentLineSign *= -1;
179 assert(0 and
"links of the loops do not connect or are not in the right order");
183 sign.push_back(currentLineSign);
184 previousLine = (*line)->ptr;
186 State state(impedances, time, pInfinite);
187 states.push_back(state);
190 State& getState(std::vector<double>& impedances)
192 std::vector<State>::iterator stIT = std::find_if(states.begin(),
194 [&impedances](
State& s) ->
bool
195 { return s.impedances == impedances; });
197 if (stIT == states.end())
199 State state(impedances, time, pInfinite);
200 states.push_back(state);
201 stIT = std::find_if(states.begin(),
203 [&impedances](
State& s) ->
bool
204 { return s.impedances == impedances; });
210 std::vector<double> sign;
211 const std::vector<linkInfo*>& loop;
212 std::vector<State> states;
213 Data::BindingConstraint::Operator opType;
220 typedef std::vector<linkInfo*> Vector;
221 typedef std::map<linkInfo*, double> WeightMap;
222 typedef std::map<linkInfo*, double> Pattern;
223 typedef std::vector<Pattern> VectorOfPatterns;
224 typedef std::map<uint, Pattern*> Map;
252 bool saveCBuilderToFile(
const String& filename =
"")
const;
253 bool completeCBuilderFromFile(
const std::string& filename =
"");
263 auto linkIT = std::find_if(pLink.begin(),
265 [&u, &v](std::shared_ptr<linkInfo> edgeP) ->
bool
267 if (edgeP->ptr->from->id == u && edgeP->ptr->with->id == v)
271 if (edgeP->ptr->from->id == v && edgeP->ptr->with->id == u)
280 if (linkIT != pLink.end())
282 return linkIT->get();
292 for (
auto& area: pStudy.
areas)
294 auto a = area.second;
295 std::for_each(pLink.begin(),
297 [&a,
this](std::shared_ptr<linkInfo> edgeP)
299 if (edgeP->ptr->from == a || edgeP->ptr->with == a)
301 this->areaToLinks[a].insert(edgeP.get());
309 if (i < pLink.size())
311 return pLink[i].get();
328 bool createConstraints(
const std::vector<Vector>&);
330 double setInfinite(
const long value)
332 return infiniteSecondMember = value;
335 bool setCheckNodalLoopFlow(
const bool value)
337 return checkNodalLoopFlow = value;
340 bool setLoopFlowInclusion(
const bool value)
342 return includeLoopFlow = value;
345 bool setPhaseShiftInclusion(
const bool value)
347 return includePhaseShift = value;
352 return infiniteSecondMember;
355 bool getCheckNodalLoopFlow()
357 return checkNodalLoopFlow;
360 bool getLoopFlowInclusion()
362 return includeLoopFlow;
365 bool getPhaseShiftInclusion()
367 return includePhaseShift;
370 bool setUpToDate(
const bool value)
372 return isUpToDate = value;
389 void setCalendarStart(
int start)
391 calendarStart = start;
394 void setCalendarEnd(
int end)
399 uint getCalendarStart()
401 return calendarStart;
404 uint getCalendarEnd()
413 std::shared_ptr<Antares::Data::BindingConstraint> addConstraint(
414 const Data::ConstraintName& name,
415 const Yuni::String& op,
416 const Yuni::String& type,
417 const WeightMap& weights,
418 const double& secondMember);
421 std::vector<std::shared_ptr<linkInfo>> pLink;
425 std::string pPrefixDelete;
427 bool includeLoopFlow =
true;
428 bool includePhaseShift =
true;
429 bool isUpToDate =
false;
430 bool checkNodalLoopFlow =
true;
431 double infiniteSecondMember = 1000000;
433 uint calendarStart = 1;
434 uint calendarEnd = 8760;
436 std::vector<std::vector<linkInfo*>> pMesh;
438 std::map<Data::Area*, std::set<linkInfo*>> areaToLinks;
Definition: cbuilder.h:218
linkInfo * findLinkInfoFromNodeNames(Data::AreaName &u, Data::AreaName &v)
find an edge from node names
Definition: cbuilder.h:261
~CBuilder()=default
Destructor.
bool completeFromStudy()
Complete the settings with the data from the study.
Definition: load.cpp:27
void buildAreaToLinkInfosMap()
build list of edges from area
Definition: cbuilder.h:289
int alreadyExistingNetworkConstraints(const Yuni::String &prefix) const
check if network constraints already exists in the study
Definition: cbuilder.cpp:460
CBuilder(Antares::Data::Study &)
Default constructor.
Definition: cbuilder.cpp:49
bool runConstraintsBuilder(bool standalone=false)
Independent function to run the constraint generator from a study.
Definition: cbuilder.cpp:283
bool deletePreviousConstraints()
Delete the network constraints.
Definition: cbuilder.cpp:304
Definition: cbuilder.h:136
Definition of a link between two areas (Interconnection)
Definition: links.h:58
Area * with
The other area | Hash ID: with->id.
Definition: links.h:135
Area * from
The orginal Area.
Definition: links.h:133
Definition for a single area.
Definition: area.h:51
AreaList areas
All available areas.
Definition: study.h:524
void fillColumn(uint x, const T &value)
Set a entire column with a given value.
Definition: matrix.hxx:491
Definition: cbuilder.h:120
Definition: cbuilder.h:36
Definition: cbuilder.h:55
Definition: cbuilder.h:102
Definition: cbuilder.h:94
Definition: cbuilder.h:86
Definition: cbuilder.h:78