Skip to content

Commit

Permalink
implement week binding constraints group
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Sep 19, 2023
1 parent a653ada commit 8ed7085
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 63 deletions.
3 changes: 2 additions & 1 deletion src/solver/optimisation/BindingConstraintDayGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ std::shared_ptr<BindingConstraintDayData>

return std::make_shared<BindingConstraintDayData>(data);
}

void BindingConstraintDayGroup::Build()
{
std::shared_ptr<NewConstraintBuilder> builder(
Expand All @@ -36,7 +37,7 @@ void BindingConstraintDayGroup::Build()
for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo_->NombreDeContraintesCouplantes;
cntCouplante++)
{
bindingConstraintDay.add(cntCouplante,
bindingConstraintDay.add(cntCouplante,
GetBindingConstraintDayDataFromProblemHebdo(cntCouplante));
}
}
101 changes: 58 additions & 43 deletions src/solver/optimisation/BindingConstraintWeek.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,80 @@
#include "BindingConstraintWeek.h"

void BindingConstraintWeek::add(int cntCouplante)
void BindingConstraintWeek::add(int cntCouplante, std::shared_ptr<BindingConstraintWeekData> data)
{
const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes
= problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante];
int semaine = problemeHebdo->weekInTheYear;
CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires
= problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires;
if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE)
int semaine = builder->data->weekInTheYear;
if (data->TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE)
return;

const int nbInterco
= MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante;
const int nbClusters
= MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante;
const int nbInterco = data->NombreDInterconnexionsDansLaContrainteCouplante;
const int nbClusters = data->NombreDePaliersDispatchDansLaContrainteCouplante;

for (int index = 0; index < nbInterco; index++)
{
int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index];
double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index];
int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index];
for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++)
int interco = data->NumeroDeLInterconnexion[index];
double poids = data->PoidsDeLInterconnexion[index];
int offset = data->OffsetTemporelSurLInterco[index];
for (int pdt = 0; pdt < builder->data->NombreDePasDeTempsPourUneOptimisation; pdt++)
{
builder.updateHourWithinWeek(pdt).include(
Variable::NTCDirect(interco), poids, offset, true, problemeHebdo->NombreDePasDeTemps);
builder->updateHourWithinWeek(pdt);
int pdt1;
if (offset >= 0)
{
pdt1 = (pdt + offset) % builder->data->NombreDePasDeTempsPourUneOptimisation;
}
else
{
pdt1 = (pdt + offset + builder->data->NombreDePasDeTemps)
% builder->data->NombreDePasDeTempsPourUneOptimisation;
}
builder->updateHourWithinWeek(pdt1).include(
NewVariable::NTCDirect(interco), poids, 0, false, builder->data->NombreDePasDeTemps);
}
}

for (int index = 0; index < nbClusters; index++)
for (int index = 0; index < nbClusters; index++)
{
int pays = data->PaysDuPalierDispatch[index];
const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data->PaliersThermiquesDuPays[pays];
const int palier
= PaliersThermiquesDuPays
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[data->NumeroDuPalierDispatch[index]];
double poids = data->PoidsDuPalierDispatch[index];
int offset = data->OffsetTemporelSurLePalierDispatch[index];
for (int pdt = 0; pdt < builder->data->NombreDePasDeTempsPourUneOptimisation; pdt++)
{
int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index];
const PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];
const int palier
= PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques
[MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]];
double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index];
int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index];
for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++)
int pdt1;

builder->updateHourWithinWeek(pdt); // useless?
if (offset >= 0)
{
pdt1 = (pdt + offset) % builder->data->NombreDePasDeTempsPourUneOptimisation;
}
else
{
builder.updateHourWithinWeek(pdt).include(Variable::DispatchableProduction(palier),
poids,
offset,
true,
problemeHebdo->NombreDePasDeTemps);
pdt1 = (pdt + offset + builder->data->NombreDePasDeTemps)
% builder->data->NombreDePasDeTempsPourUneOptimisation;
}

builder->updateHourWithinWeek(pdt1).include(NewVariable::DispatchableProduction(palier),
poids,
offset,
false,
builder->data->NombreDePasDeTemps);
}
}

char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante;
builder.SetOperator(op);
char op = data->SensDeLaContrainteCouplante;
builder->operatorRHS(op);

CorrespondanceCntNativesCntOptimHebdomadaires
.NumeroDeContrainteDesContraintesCouplantes[cntCouplante]
= problemeHebdo->ProblemeAResoudre->NombreDeContraintes;
data->NumeroDeContrainteDesContraintesCouplantes[cntCouplante]
= builder->data->nombreDeContraintes;
// Name
{
ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes,
problemeHebdo->NamedProblems);
namer.UpdateTimeStep(semaine);
namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes,
MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante);
ConstraintNamer namer(builder->data->NomDesContraintes, builder->data->NamedProblems);
namer.UpdateTimeStep(semaine);
namer.BindingConstraintWeek(builder->data->nombreDeContraintes,
data->NomDeLaContrainteCouplante);
}
builder.build();
builder->build();
}
13 changes: 9 additions & 4 deletions src/solver/optimisation/BindingConstraintWeek.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#pragma once
#include "constraint_builder.h"
#include "new_constraint_builder.h"

class BindingConstraintWeek : private Constraint
struct BindingConstraintWeekData : public BindingConstraintData
{
std::vector<int>& NumeroDeContrainteDesContraintesCouplantes;
};

class BindingConstraintWeek : private NewConstraint
{
public:
using Constraint::Constraint;
void add(int cntCouplante);
using NewConstraint::NewConstraint;
void add(int cntCouplante, std::shared_ptr<BindingConstraintWeekData> data);
};
49 changes: 49 additions & 0 deletions src/solver/optimisation/BindingConstraintWeekGroup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "BindingConstraintWeekGroup.h"
#include "new_constraint_builder_utils.h"

std::shared_ptr<BindingConstraintWeekData>
BindingConstraintWeekGroup::GetBindingConstraintWeekDataFromProblemHebdo(int cntCouplante)
{
const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes
= problemeHebdo_->MatriceDesContraintesCouplantes[cntCouplante];

BindingConstraintWeekData data
= {MatriceDesContraintesCouplantes.TypeDeContrainteCouplante,
MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante,
MatriceDesContraintesCouplantes.NumeroDeLInterconnexion,
MatriceDesContraintesCouplantes.PoidsDeLInterconnexion,
MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco,
MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante,
MatriceDesContraintesCouplantes.PaysDuPalierDispatch,
MatriceDesContraintesCouplantes.NumeroDuPalierDispatch,
MatriceDesContraintesCouplantes.PoidsDuPalierDispatch,
MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch,
MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante,
MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante,
problemeHebdo_->PaliersThermiquesDuPays,
problemeHebdo_->CorrespondanceCntNativesCntOptimHebdomadaires
.NumeroDeContrainteDesContraintesCouplantes};

return std::make_shared<BindingConstraintWeekData>(data);
}

void BindingConstraintWeekGroup::Build()
{
std::shared_ptr<NewConstraintBuilder> builder(
NewGetConstraintBuilderFromProblemHebdo(problemeHebdo_));
BindingConstraintWeek bindingConstraintWeek(builder);

if (problemeHebdo_->NombreDePasDeTempsPourUneOptimisation
> problemeHebdo_->NombreDePasDeTempsDUneJournee)
{
CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires
= problemeHebdo_->CorrespondanceCntNativesCntOptimHebdomadaires;
for (uint32_t cntCouplante = 0;
cntCouplante < problemeHebdo_->NombreDeContraintesCouplantes;
cntCouplante++)
{
bindingConstraintWeek.add(cntCouplante,
GetBindingConstraintWeekDataFromProblemHebdo(cntCouplante));
}
}
}
16 changes: 16 additions & 0 deletions src/solver/optimisation/BindingConstraintWeekGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "ConstraintGroup.h"
#include "BindingConstraintWeek.h"

class BindingConstraintWeekGroup : public ConstraintGroup
{
public:
using ConstraintGroup::ConstraintGroup;

/*TODO Rename this*/
void Build() override;

private:
std::shared_ptr<BindingConstraintWeekData> GetBindingConstraintWeekDataFromProblemHebdo(
int cntCouplante);
};
2 changes: 2 additions & 0 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ set(RTESOLVER_OPT
Group1.cpp
BindingConstraintDayGroup.h
BindingConstraintDayGroup.cpp
BindingConstraintWeekGroup.h
BindingConstraintWeekGroup.cpp

)

Expand Down
13 changes: 0 additions & 13 deletions src/solver/optimisation/LinearProblemMatrixBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void LinearProblemMatrixBuilder::Run()
ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes,
problemeHebdo_->NamedProblems);

BindingConstraintWeek bindingConstraintWeek(problemeHebdo_);
HydroPower hydroPower(problemeHebdo_);
HydroPowerSmoothingUsingVariationSum hydroPowerSmoothingUsingVariationSum(problemeHebdo_);
HydroPowerSmoothingUsingVariationMaxDown hydroPowerSmoothingUsingVariationMaxDown(
Expand All @@ -90,18 +89,6 @@ void LinearProblemMatrixBuilder::Run()
group->Build();
}

if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee)
{
CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires
= problemeHebdo_->CorrespondanceCntNativesCntOptimHebdomadaires;
for (uint32_t cntCouplante = 0;
cntCouplante < problemeHebdo_->NombreDeContraintesCouplantes;
cntCouplante++)
{
bindingConstraintWeek.add(cntCouplante);
}
}

for (uint32_t pays = 0; pays < problemeHebdo_->NombreDePays; pays++)
{
hydroPower.add(pays);
Expand Down
7 changes: 5 additions & 2 deletions src/solver/optimisation/LinearProblemMatrixBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ConstraintGroup.h"
#include "Group1.h"
#include "BindingConstraintDayGroup.h"
#include "BindingConstraintWeekGroup.h"

#include <antares/study.h>

Expand All @@ -41,16 +42,18 @@ class LinearProblemMatrixBuilder
problemeHebdo_(problemeHebdo),
writer_(writer),
group1_(problemeHebdo),
bindingConstraintDayGroup_(problemeHebdo)
bindingConstraintDayGroup_(problemeHebdo),
bindingConstraintWeekGroup_(problemeHebdo)
{
constraintgroups_ = {&group1_, &bindingConstraintDayGroup_};
constraintgroups_ = {&group1_, &bindingConstraintDayGroup_, &bindingConstraintWeekGroup_};
}

void Run();

private:
Group1 group1_;
BindingConstraintDayGroup bindingConstraintDayGroup_;
BindingConstraintWeekGroup bindingConstraintWeekGroup_;
std::vector<ConstraintGroup*> constraintgroups_;
PROBLEME_HEBDO* problemeHebdo_;
Solver::IResultWriter& writer_;
Expand Down

0 comments on commit 8ed7085

Please sign in to comment.