Skip to content

Commit

Permalink
Refactor constraint construction (#1627)
Browse files Browse the repository at this point in the history
* start

* add FictitiousLoad

* shortTermStorageLevel

* flowDissociation

* bindingConstraintHour

* ghost

* this is not only about constraint builder

* pay attention to the time step

* specific issue

* bug free

* smooth green?

* M&M

* Max Pumping ok?

* Area Hydro Level (_-_)

* finally

* basic

* tiny

* clean code

* add {PMin,PMax}DispatchableGeneration

* clean code

* ConsistenceNODU ok

* NbUnitsOutageLessThanNbUnitsStop

* NbDispUnitsMinBoundSinceMinUpTime

* MinDownTime

* setup Access Control

* remove comments

* remove comments

* treat major code smells

* treat major code smells 2

* more on major code smells

* update after review

* about objects lifetime

* (does not compile) cut into small pieces

* Revert "(does not compile) cut into small pieces"

This reverts commit 5a047c0.

* aesthetic

* remove comment

* smart move

* **** move

* shallow

* customize error exception

* work on "group 1"

* fix

* update

* small

* group of constraint

* from free function to class (LinearProblemMatrixBuilder)

* update LinearProblemMatrixBuilder class

* fix

* continue to group

* implement week binding constraints group

* add HydroPowerGroup

* builder as ctor parameter

* builder as ctor parameter

* clean

* int is not a bool

* add Hydro Smoothing group

* MinMaxHydroPowerGroup

* rename

* new MaxPumpingGroup

* AreaHydroLevelGroup

* new FictitiousLoad

* New ShortTermStorageLevel

* New FlowDissociation

* NEw BindingConstraintHour

* delete copies

* New BindingConstraintDay

* about includes

* New BindingConstraintWeek

* includes...

* HydroPower

* include.......

* new HydroPowerSmoothingUsingVariationSum

* new HydroPowerSmoothingUsingVariationMaxDown

* new HydroPowerSmoothingUsingVariationMaxUP

* MinHydroPower

* MaxHydroPower

* MaxPumping

* new AreaHydroLevel

* setup FinalStockGroup

* fix

* shrink method: linear problem run

* decomposition

* remove duplicated includes

* update

* make FinalStockGroup is built

* merge conflict fix

* new P{Min, Max}DispatchableGeneration & PMinMaxDispatchableGenerationGroup

* renew StartUpCosts

* add NbUnitsOutageLessThanNbUnitsStopGroup

* minuptime

* remove copy error

* new LinearProblemMatrixStartUpCosts

* fix

* fix 2

* update CmakeLists.txt

* fix

* include errors

* fix read-write data

* add documentation

* add doc for StartUpCosts group of constraints

* remove deprecated

* work on CsrQuadraticProblem / CsrFlowDissociation

* missing include

* Update CsrFlowDissociation.h

* get rid of old code

* inline function

* CsrAreaBalance new way & rename

* fix : CsrAreaBalance = Group

* logic issue

* fix doubled NegativeUnsuppliedEnergy

* 🐍 CsrBindingConstraintHour 💥

* method call syntax

* remove old logs

* remove old code

* update QuadraticProblemMatrix

* remove copy error

* ;

* unused params

* add return type

* it's 🏃

* update

* fix

* remove old Style Constraint Builder

* ConstraintBuilder is the New ConstraintBuilder

* rename file

* rename classes

* keep renaming

* rename new_exportPaliers

* transform shared_ptr data to ref: first try

* FictitiousLoadData as ref

* shortTermStorageLevelData 💾

* FlowDissociationData

* BindingConstraintHourData

* bindingConstraintDayData

* BindingConstraintWeekData

* HydroPowerData

* Min/Max/HydroPowerData

* MaxPumpingData

* AreaHydroLevelData

* data as ctor parameter

* perf issue

* fix perf issue

* small change

* updates

* about FlowDissociationData

* optimized loop in bindingConstraintHour

* remove empty line

* continue refactor

* re-work binding Constraint Week Data

* move HydroPowerData to ctor

* set data once for {Min, Max}HydroPower

* skip windows & sonar

* same for MaxPumping

* we're ok AreaHydroLevelGroup

* ok FinalStockGroup

* fix

* update StartUpCosts Group

* fix constraint index

* changes

* CsrAreaBalance

* no shared_ptr of data anymore!

* test MinDownTime elsewhere

* test NbDispUnitsMinBoundSinceMinUpTime out of it's inner loop

* test NbUnitsOutageLessThanNbUnitsStop out of it's inner loop

* big one

* shared????

* reactivate w&s

* reshape constraint construction (#1815)

* rename method

* rename with respect to the default style

* remove default parameters

* fix

* update

* fix

* ShortTermStorageLevel specific case

* NTC fix

* .

* @guilpier-code's remark

* typo

* from PR

* move unrelated jobs from LinearProblemMatrix
  • Loading branch information
a-zakir authored Dec 15, 2023
1 parent 21a61b3 commit 6a4779a
Show file tree
Hide file tree
Showing 114 changed files with 2,381 additions and 1,275 deletions.
56 changes: 53 additions & 3 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ set(RTESOLVER_OPT
opt_numero_de_jour_du_pas_de_temps.cpp
opt_construction_variables_optimisees_quadratique.cpp
opt_decompte_variables_et_contraintes.cpp
opt_construction_matrice_des_contraintes_cas_quadratique.cpp
opt_construction_matrice_des_contraintes_cas_lineaire.cpp
opt_construction_matrice_des_contraintes_outils.cpp
opt_gestion_des_bornes_cas_lineaire.cpp
opt_verification_presence_reserve_jmoins1.cpp
Expand All @@ -29,7 +27,6 @@ set(RTESOLVER_OPT
opt_liberation_problemes_simplexe.cpp
opt_restaurer_les_donnees.cpp
opt_gestion_des_couts_cas_quadratique.cpp
opt_construction_contraintes_couts_demarrage.cpp
opt_construction_variables_couts_demarrages.cpp
opt_gestion_des_bornes_couts_demarrage.cpp
opt_gestion_des_couts_couts_demarrage.cpp
Expand Down Expand Up @@ -66,13 +63,22 @@ set(RTESOLVER_OPT
adequacy_patch_csr/csr_quadratic_problem.cpp
adequacy_patch_csr/count_constraints_variables.h
adequacy_patch_csr/count_constraints_variables.cpp
adequacy_patch_csr/constraints/CsrFlowDissociation.h
adequacy_patch_csr/constraints/CsrFlowDissociation.cpp
adequacy_patch_csr/constraints/CsrAreaBalance.h
adequacy_patch_csr/constraints/CsrAreaBalance.cpp
adequacy_patch_csr/constraints/CsrBindingConstraintHour.h
adequacy_patch_csr/constraints/CsrBindingConstraintHour.cpp

opt_period_string_generator_base.h
opt_rename_problem.h
opt_rename_problem.cpp


constraints/ConstraintBuilder.cpp
constraints/ConstraintBuilder.h
constraints/constraint_builder_utils.cpp
constraints/constraint_builder_utils.h
constraints/AreaBalance.h
constraints/AreaBalance.cpp
constraints/FictitiousLoad.h
Expand Down Expand Up @@ -120,6 +126,50 @@ set(RTESOLVER_OPT
constraints/MinDownTime.h
constraints/MinDownTime.cpp

ProblemMatrixEssential.h
ProblemMatrixEssential.cpp
LinearProblemMatrixStartUpCosts.h
LinearProblemMatrixStartUpCosts.cpp
LinearProblemMatrix.h
LinearProblemMatrix.cpp
QuadraticProblemMatrix.h
QuadraticProblemMatrix.cpp
constraints/ConstraintGroup.h
constraints/Group1.h
constraints/Group1.cpp
constraints/BindingConstraintDayGroup.h
constraints/BindingConstraintDayGroup.cpp
constraints/BindingConstraintWeekGroup.h
constraints/BindingConstraintWeekGroup.cpp
constraints/HydroPowerGroup.h
constraints/HydroPowerGroup.cpp
constraints/HydraulicSmoothingGroup.h
constraints/HydraulicSmoothingGroup.cpp
constraints/MinMaxHydroPowerGroup.h
constraints/MinMaxHydroPowerGroup.cpp
constraints/MaxPumpingGroup.h
constraints/MaxPumpingGroup.cpp
constraints/AreaHydroLevelGroup.h
constraints/AreaHydroLevelGroup.cpp
constraints/FinalStockGroup.h
constraints/FinalStockGroup.cpp
constraints/AbstractStartUpCostsGroup.h
constraints/AbstractStartUpCostsGroup.cpp
constraints/PMinMaxDispatchableGenerationGroup.h
constraints/PMinMaxDispatchableGenerationGroup.cpp
constraints/ConsistenceNumberOfDispatchableUnitsGroup.h
constraints/ConsistenceNumberOfDispatchableUnitsGroup.cpp
constraints/NbUnitsOutageLessThanNbUnitsStopGroup.h
constraints/NbUnitsOutageLessThanNbUnitsStopGroup.cpp
constraints/NbDispUnitsMinBoundSinceMinUpTimeGroup.h
constraints/NbDispUnitsMinBoundSinceMinUpTimeGroup.cpp
constraints/MinDownTimeGroup.h
constraints/MinDownTimeGroup.cpp
constraints/ExchangeBalance.h
constraints/ExchangeBalance.cpp
constraints/ExchangeBalanceGroup.h
constraints/ExchangeBalanceGroup.cpp

)


Expand Down
73 changes: 73 additions & 0 deletions src/solver/optimisation/LinearProblemMatrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
** Copyright 2007-2023 RTE
** Authors: Antares_Simulator Team
**
** This file is part of Antares_Simulator.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** There are special exceptions to the terms and conditions of the
** license as they are applied to this software. View the full text of
** the exceptions in file COPYING.txt in the directory of this software
** distribution
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/

#include "LinearProblemMatrix.h"
#include "opt_export_structure.h"
#include "antares/solver/utils/filename.h"
#include "opt_fonctions.h"
#include "LinearProblemMatrixStartUpCosts.h"

using namespace Antares::Data;

LinearProblemMatrix::LinearProblemMatrix(PROBLEME_HEBDO* problemeHebdo,
ConstraintBuilder& builder) :
ProblemMatrixEssential(problemeHebdo),
builder_(builder),
group1_(problemeHebdo, builder),
bindingConstraintDayGroup_(problemeHebdo, builder),
bindingConstraintWeekGroup_(problemeHebdo, builder),
hydroPowerGroup_(problemeHebdo, builder),
hydraulicSmoothingGroup_(problemeHebdo, builder),
minMaxHydroPowerGroup_(problemeHebdo, builder),
maxPumpingGroup_(problemeHebdo, builder),
areaHydroLevelGroup_(problemeHebdo, builder),
finalStockGroup_(problemeHebdo, builder)
{
constraintgroups_ = {&group1_,
&bindingConstraintDayGroup_,
&bindingConstraintWeekGroup_,
&hydroPowerGroup_,
&hydraulicSmoothingGroup_,
&minMaxHydroPowerGroup_,
&maxPumpingGroup_,
&areaHydroLevelGroup_,
&finalStockGroup_};
}

void LinearProblemMatrix::Run()
{
InitializeProblemAResoudreCounters();

ProblemMatrixEssential::Run();

if (problemeHebdo_->OptimisationAvecCoutsDeDemarrage)
{
LinearProblemMatrixStartUpCosts(problemeHebdo_, false, builder_).Run();
}

return;
}
63 changes: 63 additions & 0 deletions src/solver/optimisation/LinearProblemMatrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
** Copyright 2007-2023 RTE
** Authors: Antares_Simulator Team
**
** This file is part of Antares_Simulator.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** There are special exceptions to the terms and conditions of the
** license as they are applied to this software. View the full text of
** the exceptions in file COPYING.txt in the directory of this software
** distribution
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#pragma once
#include "opt_structure_probleme_a_resoudre.h"
#include "sim_structure_probleme_economique.h"
#include "ProblemMatrixEssential.h"
#include "constraints/ConstraintGroup.h"
#include "constraints/Group1.h"
#include "constraints/BindingConstraintDayGroup.h"
#include "constraints/BindingConstraintWeekGroup.h"
#include "constraints/HydroPowerGroup.h"
#include "constraints/HydraulicSmoothingGroup.h"
#include "constraints/MinMaxHydroPowerGroup.h"
#include "constraints/MaxPumpingGroup.h"
#include "constraints/AreaHydroLevelGroup.h"
#include "constraints/FinalStockGroup.h"

#include <antares/study/study.h>

using namespace Antares::Data;
class LinearProblemMatrix : public ProblemMatrixEssential
{
public:
explicit LinearProblemMatrix(PROBLEME_HEBDO* problemeHebdo, ConstraintBuilder& builder);

void Run() override;

private:
ConstraintBuilder& builder_;
Group1 group1_;
BindingConstraintDayGroup bindingConstraintDayGroup_;
BindingConstraintWeekGroup bindingConstraintWeekGroup_;
HydroPowerGroup hydroPowerGroup_;
HydraulicSmoothingGroup hydraulicSmoothingGroup_;
MinMaxHydroPowerGroup minMaxHydroPowerGroup_;
MaxPumpingGroup maxPumpingGroup_;
AreaHydroLevelGroup areaHydroLevelGroup_;
FinalStockGroup finalStockGroup_;
};
47 changes: 47 additions & 0 deletions src/solver/optimisation/LinearProblemMatrixStartUpCosts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
** Copyright 2007-2023 RTE
** Authors: Antares_Simulator Team
**
** This file is part of Antares_Simulator.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** There are special exceptions to the terms and conditions of the
** license as they are applied to this software. View the full text of
** the exceptions in file COPYING.txt in the directory of this software
** distribution
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#pragma once
#include "LinearProblemMatrixStartUpCosts.h"
using namespace Antares::Data;

LinearProblemMatrixStartUpCosts::LinearProblemMatrixStartUpCosts(PROBLEME_HEBDO* problemeHebdo,
bool Simulation,
ConstraintBuilder& builder) :
ProblemMatrixEssential(problemeHebdo),
simulation_(Simulation),
pMinMaxDispatchableGenerationGroup_(problemeHebdo, simulation_, builder),
consistenceNumberOfDispatchableUnitsGroup_(problemeHebdo, simulation_, builder),
nbUnitsOutageLessThanNbUnitsStopGroup_(problemeHebdo, simulation_, builder),
nbDispUnitsMinBoundSinceMinUpTimeGroup_(problemeHebdo, simulation_, builder),
minDownTimeGroup_(problemeHebdo, simulation_, builder)
{
constraintgroups_ = {&pMinMaxDispatchableGenerationGroup_,
&consistenceNumberOfDispatchableUnitsGroup_,
&nbUnitsOutageLessThanNbUnitsStopGroup_,
&nbDispUnitsMinBoundSinceMinUpTimeGroup_,
&minDownTimeGroup_};
}
58 changes: 58 additions & 0 deletions src/solver/optimisation/LinearProblemMatrixStartUpCosts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
** Copyright 2007-2023 RTE
** Authors: Antares_Simulator Team
**
** This file is part of Antares_Simulator.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** There are special exceptions to the terms and conditions of the
** license as they are applied to this software. View the full text of
** the exceptions in file COPYING.txt in the directory of this software
** distribution
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#pragma once
#include "opt_structure_probleme_a_resoudre.h"
#include "sim_structure_probleme_economique.h"
#include "constraints/ConstraintGroup.h"
#include "ProblemMatrixEssential.h"
#include "opt_structure_probleme_a_resoudre.h"

#include "constraints/PMinMaxDispatchableGenerationGroup.h"
#include "constraints/ConsistenceNumberOfDispatchableUnitsGroup.h"
#include "constraints/NbUnitsOutageLessThanNbUnitsStopGroup.h"
#include "constraints/NbDispUnitsMinBoundSinceMinUpTimeGroup.h"
#include "constraints/MinDownTimeGroup.h"

#include <antares/study/study.h>

using namespace Antares::Data;

class LinearProblemMatrixStartUpCosts : public ProblemMatrixEssential
{
public:
explicit LinearProblemMatrixStartUpCosts(PROBLEME_HEBDO* problemeHebdo,
bool Simulation,
ConstraintBuilder& builder);

private:
bool simulation_ = false;
PMinMaxDispatchableGenerationGroup pMinMaxDispatchableGenerationGroup_;
ConsistenceNumberOfDispatchableUnitsGroup consistenceNumberOfDispatchableUnitsGroup_;
NbUnitsOutageLessThanNbUnitsStopGroup nbUnitsOutageLessThanNbUnitsStopGroup_;
NbDispUnitsMinBoundSinceMinUpTimeGroup nbDispUnitsMinBoundSinceMinUpTimeGroup_;
MinDownTimeGroup minDownTimeGroup_;
};
47 changes: 47 additions & 0 deletions src/solver/optimisation/ProblemMatrixEssential.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
** Copyright 2007-2023 RTE
** Authors: Antares_Simulator Team
**
** This file is part of Antares_Simulator.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** There are special exceptions to the terms and conditions of the
** license as they are applied to this software. View the full text of
** the exceptions in file COPYING.txt in the directory of this software
** distribution
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#include "ProblemMatrixEssential.h"

ProblemMatrixEssential::ProblemMatrixEssential(PROBLEME_HEBDO* problemeHebdo) :
problemeHebdo_(problemeHebdo)
{
}

void ProblemMatrixEssential::Run()
{
for (auto& group : constraintgroups_)
{
group->BuildConstraints();
}
}

void ProblemMatrixEssential::InitializeProblemAResoudreCounters()
{
auto& ProblemeAResoudre = problemeHebdo_->ProblemeAResoudre;
ProblemeAResoudre->NombreDeContraintes = 0;
ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes = 0;
}
Loading

0 comments on commit 6a4779a

Please sign in to comment.