Skip to content

Commit

Permalink
continue to group
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Sep 18, 2023
1 parent 84b7e0e commit a653ada
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 59 deletions.
101 changes: 56 additions & 45 deletions src/solver/optimisation/BindingConstraintDay.cpp
Original file line number Diff line number Diff line change
@@ -1,81 +1,92 @@
#include "BindingConstraintDay.h"

void BindingConstraintDay::add(int cntCouplante)
void BindingConstraintDay::add(int cntCouplante, std::shared_ptr<BindingConstraintDayData> data)
{
const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes
= problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante];
if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE)
if (data->TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE)
return;

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

const int NombreDePasDeTempsPourUneOptimisation
= problemeHebdo->NombreDePasDeTempsPourUneOptimisation; // TODO
const int NombreDePasDeTempsDUneJournee = problemeHebdo->NombreDePasDeTempsDUneJournee;
= builder->data->NombreDePasDeTempsPourUneOptimisation; // TODO
const int NombreDePasDeTempsDUneJournee = data->NombreDePasDeTempsDUneJournee;
int pdtDebut = 0;
while (pdtDebut < NombreDePasDeTempsPourUneOptimisation)
{
int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut];
CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& CorrespondanceCntNativesCntOptimJournalieres
= problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[jour];
int jour = data->NumeroDeJourDuPasDeTemps[pdtDebut];

for (int index = 0; index < nbInterco; index++)
{
int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index];
double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index];
int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index];
int interco = data->NumeroDeLInterconnexion[index];
double poids = data->PoidsDeLInterconnexion[index];
int offset = data->OffsetTemporelSurLInterco[index];

for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++)
{
builder.updateHourWithinWeek(pdt).include(Variable::NTCDirect(interco),
poids,
offset,
true,
problemeHebdo->NombreDePasDeTemps);
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++)
{
int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index];
const PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];
int pays = data->PaysDuPalierDispatch[index];
const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data->PaliersThermiquesDuPays[pays];
const int palier
= PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques
[MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]];
double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index];
int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index];
[data->NumeroDuPalierDispatch[index]];
double poids = data->PoidsDuPalierDispatch[index];
int offset = data->OffsetTemporelSurLePalierDispatch[index];

for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++)
{
builder.updateHourWithinWeek(pdt).include(Variable::DispatchableProduction(palier),
poids,
offset,
true,
problemeHebdo->NombreDePasDeTemps);
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::DispatchableProduction(palier),
poids,
0,
false,
builder->data->NombreDePasDeTemps);
}
}

CorrespondanceCntNativesCntOptimJournalieres
data->CorrespondanceCntNativesCntOptimJournalieres[jour]
.NumeroDeContrainteDesContraintesCouplantes[cntCouplante]
= problemeHebdo->ProblemeAResoudre->NombreDeContraintes;

std::vector<double*>& AdresseOuPlacerLaValeurDesCoutsMarginaux
= problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux;
= builder->data->nombreDeContraintes;

char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante;
builder.SetOperator(op);
char op = data->SensDeLaContrainteCouplante;
builder->operatorRHS(op);
{
ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes,
problemeHebdo->NamedProblems);
ConstraintNamer namer(builder->data->NomDesContraintes, builder->data->NamedProblems);
namer.UpdateTimeStep(jour);
namer.BindingConstraintDay(problemeHebdo->ProblemeAResoudre->NombreDeContraintes,
MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante);
namer.BindingConstraintDay(builder->data->nombreDeContraintes,
data->NomDeLaContrainteCouplante);
}
builder.build();
pdtDebut += problemeHebdo->NombreDePasDeTempsDUneJournee;
builder->build();
pdtDebut += data->NombreDePasDeTempsDUneJournee;
}
}
18 changes: 14 additions & 4 deletions src/solver/optimisation/BindingConstraintDay.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#pragma once
#include "constraint_builder.h"
#include "new_constraint_builder.h"

class BindingConstraintDay : private Constraint
struct BindingConstraintDayData : public BindingConstraintData
{
std::vector<CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES>&
CorrespondanceCntNativesCntOptimJournalieres;

const int32_t& NombreDePasDeTempsDUneJournee;

std::vector<int32_t>& NumeroDeJourDuPasDeTemps;
};

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

std::shared_ptr<BindingConstraintDayData>
BindingConstraintDayGroup::GetBindingConstraintDayDataFromProblemHebdo(int cntCouplante)
{
const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes
= problemeHebdo_->MatriceDesContraintesCouplantes[cntCouplante];

BindingConstraintDayData 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_->CorrespondanceCntNativesCntOptimJournalieres,
problemeHebdo_->NombreDePasDeTempsDUneJournee,
problemeHebdo_->NumeroDeJourDuPasDeTemps};

return std::make_shared<BindingConstraintDayData>(data);
}
void BindingConstraintDayGroup::Build()
{
std::shared_ptr<NewConstraintBuilder> builder(
NewGetConstraintBuilderFromProblemHebdo(problemeHebdo_));

BindingConstraintDay bindingConstraintDay(builder);
for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo_->NombreDeContraintesCouplantes;
cntCouplante++)
{
bindingConstraintDay.add(cntCouplante,
GetBindingConstraintDayDataFromProblemHebdo(cntCouplante));
}
}
16 changes: 16 additions & 0 deletions src/solver/optimisation/BindingConstraintDayGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "ConstraintGroup.h"
#include "BindingConstraintDay.h"

class BindingConstraintDayGroup : public ConstraintGroup
{
public:
using ConstraintGroup::ConstraintGroup;

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

private:
std::shared_ptr<BindingConstraintDayData> GetBindingConstraintDayDataFromProblemHebdo(
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 @@ -130,6 +130,8 @@ set(RTESOLVER_OPT
ConstraintGroup.h
Group1.h
Group1.cpp
BindingConstraintDayGroup.h
BindingConstraintDayGroup.cpp

)

Expand Down
8 changes: 0 additions & 8 deletions src/solver/optimisation/LinearProblemMatrixBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "ShortTermStorageLevel.h"
#include "FlowDissociation.h"
#include "BindingConstraintHour.h"
#include "BindingConstraintDay.h"
#include "BindingConstraintWeek.h"
#include "HydroPower.h"
#include "HydroPowerSmoothingUsingVariationSum.h"
Expand Down Expand Up @@ -69,7 +68,6 @@ void LinearProblemMatrixBuilder::Run()
ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes,
problemeHebdo_->NamedProblems);

BindingConstraintDay bindingConstraintDay(problemeHebdo_);
BindingConstraintWeek bindingConstraintWeek(problemeHebdo_);
HydroPower hydroPower(problemeHebdo_);
HydroPowerSmoothingUsingVariationSum hydroPowerSmoothingUsingVariationSum(problemeHebdo_);
Expand All @@ -92,12 +90,6 @@ void LinearProblemMatrixBuilder::Run()
group->Build();
}

for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo_->NombreDeContraintesCouplantes;
cntCouplante++)
{
bindingConstraintDay.add(cntCouplante);
}

if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee)
{
CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires
Expand Down
9 changes: 7 additions & 2 deletions src/solver/optimisation/LinearProblemMatrixBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "sim_structure_probleme_economique.h"
#include "ConstraintGroup.h"
#include "Group1.h"
#include "BindingConstraintDayGroup.h"

#include <antares/study.h>

Expand All @@ -37,15 +38,19 @@ class LinearProblemMatrixBuilder
public:
explicit LinearProblemMatrixBuilder(PROBLEME_HEBDO* problemeHebdo,
Solver::IResultWriter& writer) :
problemeHebdo_(problemeHebdo), writer_(writer), group1_(problemeHebdo)
problemeHebdo_(problemeHebdo),
writer_(writer),
group1_(problemeHebdo),
bindingConstraintDayGroup_(problemeHebdo)
{
constraintgroups_.push_back(&group1_);
constraintgroups_ = {&group1_, &bindingConstraintDayGroup_};
}

void Run();

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

0 comments on commit a653ada

Please sign in to comment.