From 8dbf5c11e911adef6abd472a2c6c8b675a3bf8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Fri, 27 Sep 2024 13:20:36 +0200 Subject: [PATCH] Adequacy patch CSR - revamp output variables [ANT-1932] (#2421) Backport of #2306 --- .github/workflows/ubuntu.yml | 8 -- .github/workflows/windows-vcpkg.yml | 9 -- .../study/parameters/adq-patch-params.cpp | 2 +- .../study/parameters/adq-patch-params.h | 2 - src/solver/optimisation/CMakeLists.txt | 2 + .../adequacy_patch_csr/post_processing.cpp | 62 +++++++++++ .../adequacy_patch_csr/post_processing.h | 29 +++++ .../set_variable_boundaries.cpp | 3 +- .../optimisation/post_process_commands.cpp | 45 ++++---- .../simulation/sim_alloc_probleme_hebdo.cpp | 4 +- .../sim_structure_probleme_economique.h | 6 +- src/solver/variable/CMakeLists.txt | 3 +- src/solver/variable/economy/all.h | 36 +++---- ...dEnergyAfterCSR.h => unsupliedEnergyCsr.h} | 102 +++++++++--------- .../solver/optimisation/adequacy_patch.cpp | 74 +++++++++++++ 15 files changed, 262 insertions(+), 125 deletions(-) create mode 100644 src/solver/optimisation/adequacy_patch_csr/post_processing.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/post_processing.h rename src/solver/variable/economy/{spilledEnergyAfterCSR.h => unsupliedEnergyCsr.h} (72%) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 0321a79870..8b29e7cfb3 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -242,14 +242,6 @@ jobs: batch-name: valid-mps os: ${{ env.os }} - - name: Run tests for adequacy patch (CSR) - if: false - uses: ./.github/workflows/run-tests - with: - simtest-tag: ${{steps.simtest-version.outputs.prop}} - batch-name: adequacy-patch-CSR - os: ${{ env.os }} - - name: Run parallel tests if: ${{ env.RUN_EXTENDED_TESTS == 'true' }} uses: ./.github/workflows/run-tests diff --git a/.github/workflows/windows-vcpkg.yml b/.github/workflows/windows-vcpkg.yml index f66b2e1acf..14ec769c8e 100644 --- a/.github/workflows/windows-vcpkg.yml +++ b/.github/workflows/windows-vcpkg.yml @@ -195,15 +195,6 @@ jobs: name: MPS-diff path: ${{ github.workspace }}/src/tests/mps - - - name: Run tests for adequacy patch (CSR) - if: false - uses: ./.github/workflows/run-tests - with: - simtest-tag: ${{steps.simtest-version.outputs.prop}} - batch-name: adequacy-patch-CSR - os: ${{ env.test-platform }} - - name: Run tests about infinity on BCs RHS if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} uses: ./.github/workflows/run-tests diff --git a/src/libs/antares/study/parameters/adq-patch-params.cpp b/src/libs/antares/study/parameters/adq-patch-params.cpp index 00b0a6cf64..eedef3aaef 100644 --- a/src/libs/antares/study/parameters/adq-patch-params.cpp +++ b/src/libs/antares/study/parameters/adq-patch-params.cpp @@ -148,7 +148,7 @@ void AdqPatchParams::addExcludedVariables(std::vector& out) const { out.emplace_back("DENS"); out.emplace_back("LMR VIOL."); - out.emplace_back("SPIL. ENRG. CSR"); + out.emplace_back("UNSP. ENRG CSR"); out.emplace_back("DTG MRG CSR"); } } diff --git a/src/libs/antares/study/parameters/adq-patch-params.h b/src/libs/antares/study/parameters/adq-patch-params.h index 44791d3c0f..47ec5599c2 100644 --- a/src/libs/antares/study/parameters/adq-patch-params.h +++ b/src/libs/antares/study/parameters/adq-patch-params.h @@ -92,8 +92,6 @@ class CurtailmentSharing //! Check CSR cost function prior & after CSR optimization bool checkCsrCostFunction; - bool recomputeDTGMRG = false; - bool updateFromKeyValue(const Yuni::String& key, const Yuni::String& value); void addProperties(IniFile::Section* section) const; diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index 4ca7205048..f552b874f2 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -50,6 +50,8 @@ set(RTESOLVER_OPT adequacy_patch_csr/hourly_csr_problem.h adequacy_patch_csr/adq_patch_post_process_list.h adequacy_patch_csr/adq_patch_post_process_list.cpp + adequacy_patch_csr/post_processing.cpp + adequacy_patch_csr/post_processing.h adequacy_patch_local_matching/adq_patch_local_matching.h adequacy_patch_local_matching/adq_patch_local_matching.cpp adequacy_patch_csr/adq_patch_curtailment_sharing.h diff --git a/src/solver/optimisation/adequacy_patch_csr/post_processing.cpp b/src/solver/optimisation/adequacy_patch_csr/post_processing.cpp new file mode 100644 index 0000000000..725ec9c364 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/post_processing.cpp @@ -0,0 +1,62 @@ +/* +** Copyright 2007-2024, RTE (https://www.rte-france.com) +** See AUTHORS.txt +** SPDX-License-Identifier: MPL-2.0 +** This file is part of Antares-Simulator, +** Adequacy and Performance assessment for interconnected energy networks. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the Mozilla Public Licence 2.0 as published by +** the Mozilla Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** Mozilla Public Licence 2.0 for more details. +** +** You should have received a copy of the Mozilla Public Licence 2.0 +** along with Antares_Simulator. If not, see . +*/ +#include "post_processing.h" + +#include + +namespace Antares::Data::AdequacyPatch +{ +double recomputeDTG_MRG(bool triggered, double dtgMrg, double ens) +{ + if (triggered) + { + return std::max(0.0, dtgMrg - ens); + } + else + { + return dtgMrg; + } +} + +double recomputeENS_MRG(bool triggered, double dtgMrg, double ens) +{ + if (triggered) + { + return std::max(0.0, ens - dtgMrg); + } + else + { + return ens; + } +} + +double recomputeMRGPrice(double ensCsr, double originalCost, double unsuppliedEnergyCost) +{ + if (ensCsr > 0.5) + { + return -unsuppliedEnergyCost; + } + else + { + return originalCost; + } +} +} // namespace Antares::Data::AdequacyPatch diff --git a/src/solver/optimisation/adequacy_patch_csr/post_processing.h b/src/solver/optimisation/adequacy_patch_csr/post_processing.h new file mode 100644 index 0000000000..3ae5ee2d91 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/post_processing.h @@ -0,0 +1,29 @@ +/* +** Copyright 2007-2024, RTE (https://www.rte-france.com) +** See AUTHORS.txt +** SPDX-License-Identifier: MPL-2.0 +** This file is part of Antares-Simulator, +** Adequacy and Performance assessment for interconnected energy networks. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the Mozilla Public Licence 2.0 as published by +** the Mozilla Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** Mozilla Public Licence 2.0 for more details. +** +** You should have received a copy of the Mozilla Public Licence 2.0 +** along with Antares_Simulator. If not, see . +*/ + +#pragma once + +namespace Antares::Data::AdequacyPatch +{ +double recomputeDTG_MRG(bool triggered, double dtgMrg, double ens); +double recomputeENS_MRG(bool triggered, double dtgMrg, double ens); +double recomputeMRGPrice(double ensCsr, double originalCost, double unsuppliedEnergyCost); +} // namespace Antares::Data::AdequacyPatch diff --git a/src/solver/optimisation/adequacy_patch_csr/set_variable_boundaries.cpp b/src/solver/optimisation/adequacy_patch_csr/set_variable_boundaries.cpp index 0bb5d91925..7cb72b7b0d 100644 --- a/src/solver/optimisation/adequacy_patch_csr/set_variable_boundaries.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/set_variable_boundaries.cpp @@ -93,8 +93,7 @@ void HourlyCSRProblem::setBoundsOnSpilledEnergy() .ValeursHorairesDeDefaillanceNegative[triggeredHour]; double* AdresseDuResultat = &(problemeHebdo_->ResultatsHoraires[area] - .ValeursHorairesSpilledEnergyAfterCSR[triggeredHour]); - + .ValeursHorairesDeDefaillanceNegative[triggeredHour]); problemeAResoudre_.AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; diff --git a/src/solver/optimisation/post_process_commands.cpp b/src/solver/optimisation/post_process_commands.cpp index f864cc1c89..31e70626d3 100644 --- a/src/solver/optimisation/post_process_commands.cpp +++ b/src/solver/optimisation/post_process_commands.cpp @@ -23,6 +23,7 @@ #include "../simulation/common-eco-adq.h" #include "../simulation/adequacy_patch_runtime_data.h" #include "adequacy_patch_local_matching/adequacy_patch_weekly_optimization.h" +#include "adequacy_patch_csr/post_processing.h" #include "adequacy_patch_csr/adq_patch_curtailment_sharing.h" namespace Antares::Solver::Simulation @@ -141,28 +142,23 @@ void DTGmarginForAdqPatchPostProcessCmd::execute(const optRuntimeData&) for (uint hour = 0; hour < nbHoursInWeek; hour++) { - // define access to the required variables + auto& hourlyResults = problemeHebdo_->ResultatsHoraires[Area]; const auto& scratchpad = area_list_[Area]->scratchpad[thread_number_]; - double dtgMrg = scratchpad.dispatchableGenerationMargin[hour]; + const double dtgMrg = scratchpad.dispatchableGenerationMargin[hour]; + const double ens = hourlyResults.ValeursHorairesDeDefaillancePositive[hour]; + const bool triggered = problemeHebdo_->adequacyPatchRuntimeData + ->wasCSRTriggeredAtAreaHour(Area, hour); + hourlyResults.ValeursHorairesDtgMrgCsr[hour] = recomputeDTG_MRG(triggered, dtgMrg, ens); + hourlyResults.ValeursHorairesDeDefaillancePositiveCSR[hour] = recomputeENS_MRG( + triggered, + dtgMrg, + ens); - auto& hourlyResults = problemeHebdo_->ResultatsHoraires[Area]; - double& dtgMrgCsr = hourlyResults.ValeursHorairesDtgMrgCsr[hour]; - double& ens = hourlyResults.ValeursHorairesDeDefaillancePositive[hour]; - double& mrgCost = hourlyResults.CoutsMarginauxHoraires[hour]; - // calculate DTG MRG CSR and adjust ENS if neccessary - if (problemeHebdo_->adequacyPatchRuntimeData->wasCSRTriggeredAtAreaHour(Area, hour)) - { - if (adqPatchParams_.curtailmentSharing.recomputeDTGMRG) - { - dtgMrgCsr = std::max(0.0, dtgMrg - ens); - ens = std::max(0.0, ens - dtgMrg); - } - // set MRG PRICE to value of unsupplied energy cost, if LOLD=1.0 (ENS>0.5) - if (ens > 0.5) - mrgCost = -area_list_[Area]->thermal.unsuppliedEnergyCost; - } - else - dtgMrgCsr = dtgMrg; + const double unsuppliedEnergyCost = area_list_[Area]->thermal.unsuppliedEnergyCost; + hourlyResults.CoutsMarginauxHoraires[hour] = recomputeMRGPrice( + hourlyResults.ValeursHorairesDtgMrgCsr[hour], + hourlyResults.CoutsMarginauxHoraires[hour], + unsuppliedEnergyCost); } } } @@ -256,13 +252,8 @@ double CurtailmentSharingPostProcessCmd::calculateDensNewAndTotalLmrViolation() const auto& scratchpad = area_list_[Area]->scratchpad[thread_number_]; double dtgMrg = scratchpad.dispatchableGenerationMargin[hour]; // write down densNew values for all the hours - problemeHebdo_->ResultatsHoraires[Area].ValeursHorairesDENS[hour] = std::max( - 0.0, - densNew); - // copy spilled Energy values into spilled Energy values after CSR - problemeHebdo_->ResultatsHoraires[Area].ValeursHorairesSpilledEnergyAfterCSR[hour] - = problemeHebdo_->ResultatsHoraires[Area] - .ValeursHorairesDeDefaillanceNegative[hour]; + problemeHebdo_->ResultatsHoraires[Area].ValeursHorairesDENS[hour] + = std::max(0.0, densNew); // check LMR violations totalLmrViolation += LmrViolationAreaHour( problemeHebdo_, diff --git a/src/solver/simulation/sim_alloc_probleme_hebdo.cpp b/src/solver/simulation/sim_alloc_probleme_hebdo.cpp index 80c5ad5edb..5ee3b74e92 100644 --- a/src/solver/simulation/sim_alloc_probleme_hebdo.cpp +++ b/src/solver/simulation/sim_alloc_probleme_hebdo.cpp @@ -415,12 +415,12 @@ void SIM_AllocateAreas(PROBLEME_HEBDO& problem, problem.ResultatsHoraires[k].ValeursHorairesDeDefaillancePositive .assign(NombreDePasDeTemps, 0.); + problem.ResultatsHoraires[k].ValeursHorairesDeDefaillancePositiveCSR + .assign(NombreDePasDeTemps, 0.); problem.ResultatsHoraires[k].ValeursHorairesDENS .assign(NombreDePasDeTemps, 0.); // adq patch problem.ResultatsHoraires[k].ValeursHorairesLmrViolations .assign(NombreDePasDeTemps, 0); // adq patch - problem.ResultatsHoraires[k].ValeursHorairesSpilledEnergyAfterCSR - .assign(NombreDePasDeTemps, 0.); // adq patch problem.ResultatsHoraires[k].ValeursHorairesDtgMrgCsr .assign(NombreDePasDeTemps, 0.); // adq patch problem.ResultatsHoraires[k].ValeursHorairesDeDefaillancePositiveUp diff --git a/src/solver/simulation/sim_structure_probleme_economique.h b/src/solver/simulation/sim_structure_probleme_economique.h index a357f4f34c..7feea19585 100644 --- a/src/solver/simulation/sim_structure_probleme_economique.h +++ b/src/solver/simulation/sim_structure_probleme_economique.h @@ -429,9 +429,9 @@ struct PRODUCTION_THERMIQUE_OPTIMALE struct RESULTATS_HORAIRES { std::vector ValeursHorairesDeDefaillancePositive; - std::vector ValeursHorairesDENS; // adq patch domestic unsupplied energy - std::vector ValeursHorairesLmrViolations; // adq patch lmr violations - std::vector ValeursHorairesSpilledEnergyAfterCSR; // adq patch spillage after CSR + std::vector ValeursHorairesDeDefaillancePositiveCSR; + std::vector ValeursHorairesDENS; // adq patch domestic unsupplied energy + std::vector ValeursHorairesLmrViolations; // adq patch lmr violations std::vector ValeursHorairesDtgMrgCsr; // adq patch DTG MRG after CSR std::vector ValeursHorairesDeDefaillancePositiveUp; std::vector ValeursHorairesDeDefaillancePositiveDown; diff --git a/src/solver/variable/CMakeLists.txt b/src/solver/variable/CMakeLists.txt index df21955781..fea122e23c 100644 --- a/src/solver/variable/CMakeLists.txt +++ b/src/solver/variable/CMakeLists.txt @@ -109,9 +109,9 @@ set(SRC_VARIABLE_ECONOMY economy/STStorageLevelsByCluster.h economy/STStorageCashFlowByCluster.h economy/unsupliedEnergy.h + economy/unsupliedEnergyCsr.h economy/domesticUnsuppliedEnergy.h economy/localMatchingRuleViolations.h - economy/spilledEnergyAfterCSR.h economy/dtgMarginAfterCsr.h economy/spilledEnergy.h economy/dispatchableGeneration.h @@ -128,6 +128,7 @@ set(SRC_VARIABLE_ECONOMY economy/avail-dispatchable-generation.h economy/dispatchable-generation-margin.h + # Links economy/links/flowLinear.h economy/links/flowLinearAbs.h diff --git a/src/solver/variable/economy/all.h b/src/solver/variable/economy/all.h index b961c8dbf7..3527fcec6d 100644 --- a/src/solver/variable/economy/all.h +++ b/src/solver/variable/economy/all.h @@ -63,7 +63,6 @@ #include "unsupliedEnergy.h" #include "domesticUnsuppliedEnergy.h" #include "localMatchingRuleViolations.h" -#include "spilledEnergyAfterCSR.h" #include "dtgMarginAfterCsr.h" #include "spilledEnergy.h" @@ -73,6 +72,7 @@ #include "avail-dispatchable-generation.h" #include "dispatchable-generation-margin.h" +#include "unsupliedEnergyCsr.h" // By thermal plant #include "productionByDispatchablePlant.h" @@ -161,22 +161,24 @@ typedef // Prices >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> VariablesPerArea; /*! @@ -240,8 +242,6 @@ typedef // Prices LMRViolations, Common::SpatialAggregate< SpilledEnergy, - Common::SpatialAggregate< - SpilledEnergyAfterCSR, // LOLD Common::SpatialAggregate< LOLD, @@ -271,7 +271,7 @@ typedef // Prices // - // refs: // #55 - >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> VariablesPerSetOfAreas; typedef BindingConstMarginCost< // Marginal cost for a binding constraint diff --git a/src/solver/variable/economy/spilledEnergyAfterCSR.h b/src/solver/variable/economy/unsupliedEnergyCsr.h similarity index 72% rename from src/solver/variable/economy/spilledEnergyAfterCSR.h rename to src/solver/variable/economy/unsupliedEnergyCsr.h index c36ae1aee5..979977d972 100644 --- a/src/solver/variable/economy/spilledEnergyAfterCSR.h +++ b/src/solver/variable/economy/unsupliedEnergyCsr.h @@ -1,53 +1,53 @@ /* -** Copyright 2007-2023 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. +** Copyright 2007-2024, RTE (https://www.rte-france.com) +** See AUTHORS.txt +** SPDX-License-Identifier: MPL-2.0 +** This file is part of Antares-Simulator, +** Adequacy and Performance assessment for interconnected energy networks. ** ** 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 +** it under the terms of the Mozilla Public Licence 2.0 as published by +** the Mozilla Foundation, either version 2 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 . +** Mozilla Public Licence 2.0 for more details. ** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +** You should have received a copy of the Mozilla Public Licence 2.0 +** along with Antares_Simulator. If not, see . */ -#ifndef __SOLVER_VARIABLE_ECONOMY_SpilledEnergyAfterCSR_H__ -#define __SOLVER_VARIABLE_ECONOMY_SpilledEnergyAfterCSR_H__ +#pragma once #include "../variable.h" -namespace Antares::Solver::Variable::Economy +namespace Antares +{ +namespace Solver +{ +namespace Variable { -struct VCardSpilledEnergyAfterCSR +namespace Economy +{ +struct VCardUnsupliedEnergyCSR { //! Caption static std::string Caption() { - return "SPIL. ENRG. CSR"; + return "UNSP. ENRG CSR"; } + //! Unit static std::string Unit() { return "MWh"; } + //! The short description of the variable static std::string Description() { - return "Spilled Energy After CSR Optimization (generation that cannot be satisfied) " - "after CSR optimization"; + return "Unsuplied Energy after CSR (demand that cannot be satisfied)"; } //! The expecte results @@ -59,8 +59,7 @@ struct VCardSpilledEnergyAfterCSR ResultsType; //! The VCard to look for for calculating spatial aggregates - typedef VCardSpilledEnergyAfterCSR VCardForSpatialAggregate; - + typedef VCardUnsupliedEnergyCSR VCardForSpatialAggregate; enum { //! Data Level @@ -82,9 +81,8 @@ struct VCardSpilledEnergyAfterCSR //! Intermediate values hasIntermediateValues = 1, //! Can this variable be non applicable (0 : no, 1 : yes) - isPossiblyNonApplicable = 0, + isPossiblyNonApplicable = 0 }; - typedef IntermediateValues IntermediateValuesBaseType; typedef IntermediateValues* IntermediateValuesType; @@ -92,21 +90,17 @@ struct VCardSpilledEnergyAfterCSR }; // class VCard -/*! -** \brief C02 Average value of the overrall SpilledEnergyAfterCSR emissions expected from all -** the thermal dispatchable clusters -*/ template -class SpilledEnergyAfterCSR - : public Variable::IVariable, NextT, VCardSpilledEnergyAfterCSR> +class UnsupliedEnergyCSR + : public Variable::IVariable, NextT, VCardUnsupliedEnergyCSR> { public: //! Type of the next static variable typedef NextT NextType; //! VCard - typedef VCardSpilledEnergyAfterCSR VCardType; + typedef VCardUnsupliedEnergyCSR VCardType; //! Ancestor - typedef Variable::IVariable, NextT, VCardType> AncestorType; + typedef Variable::IVariable, NextT, VCardType> AncestorType; //! List of expected results typedef typename VCardType::ResultsType ResultsType; @@ -124,15 +118,16 @@ class SpilledEnergyAfterCSR { enum { - count - = ((VCardType::categoryDataLevel & CDataLevel && VCardType::categoryFileLevel & CFile) - ? (NextType::template Statistics::count - + VCardType::columnCount * ResultsType::count) - : NextType::template Statistics::count), + count = ((VCardType::categoryDataLevel & CDataLevel + && VCardType::categoryFileLevel & CFile) + ? (NextType::template Statistics::count + + VCardType::columnCount * ResultsType::count) + : NextType::template Statistics::count), }; }; - ~SpilledEnergyAfterCSR() +public: + ~UnsupliedEnergyCSR() { delete[] pValuesForTheCurrentYear; } @@ -146,7 +141,9 @@ class SpilledEnergyAfterCSR pValuesForTheCurrentYear = new VCardType::IntermediateValuesBaseType[pNbYearsParallel]; for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) + { pValuesForTheCurrentYear[numSpace].initializeFromStudy(study); + } // Next NextType::initializeFromStudy(study); @@ -173,7 +170,9 @@ class SpilledEnergyAfterCSR void simulationBegin() { for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) + { pValuesForTheCurrentYear[numSpace].reset(); + } // Next NextType::simulationBegin(); } @@ -192,10 +191,10 @@ class SpilledEnergyAfterCSR NextType::yearBegin(year, numSpace); } - void yearEndBuild(State& state, unsigned int year) + void yearEndBuild(State& state, unsigned int year, unsigned int numSpace) { // Next variable - NextType::yearEndBuild(state, year); + NextType::yearEndBuild(state, year, numSpace); } void yearEnd(unsigned int year, unsigned int numSpace) @@ -229,10 +228,8 @@ class SpilledEnergyAfterCSR void hourForEachArea(State& state, unsigned int numSpace) { - // Total SpilledEnergyAfterCSR emissions pValuesForTheCurrentYear[numSpace][state.hourInTheYear] - = state.hourlyResults->ValeursHorairesSpilledEnergyAfterCSR[state.hourInTheWeek]; - + = state.hourlyResults->ValeursHorairesDeDefaillancePositiveCSR[state.hourInTheWeek]; // Next variable NextType::hourForEachArea(state, numSpace); } @@ -257,8 +254,8 @@ class SpilledEnergyAfterCSR // Write the data for the current year results.variableCaption = VCardType::Caption(); results.variableUnit = VCardType::Unit(); - pValuesForTheCurrentYear[numSpace].template buildAnnualSurveyReport( - results, fileLevel, precision); + pValuesForTheCurrentYear[numSpace] + .template buildAnnualSurveyReport(results, fileLevel, precision); } } @@ -267,8 +264,9 @@ class SpilledEnergyAfterCSR typename VCardType::IntermediateValuesType pValuesForTheCurrentYear; unsigned int pNbYearsParallel; -}; // class SpilledEnergyAfterCSR - -} // namespace Antares::Solver::Variable::Economy +}; // class UnsupliedEnergyCSR -#endif // __SOLVER_VARIABLE_ECONOMY_SpilledEnergyAfterCSR_H__ +} // namespace Economy +} // namespace Variable +} // namespace Solver +} // namespace Antares diff --git a/src/tests/src/solver/optimisation/adequacy_patch.cpp b/src/tests/src/solver/optimisation/adequacy_patch.cpp index fd9e2f84e5..a8055e8634 100644 --- a/src/tests/src/solver/optimisation/adequacy_patch.cpp +++ b/src/tests/src/solver/optimisation/adequacy_patch.cpp @@ -8,6 +8,7 @@ #include "adequacy_patch_local_matching/adq_patch_local_matching.h" #include "adequacy_patch_csr/adq_patch_curtailment_sharing.h" #include +#include "adequacy_patch_csr/post_processing.h" #include "antares/study/parameters/adq-patch-params.h" #include #include @@ -19,6 +20,7 @@ static double origineExtremite = -1; static double extremiteOrigine = 5; using namespace Antares::Data::AdequacyPatch; +namespace tt = boost::test_tools; static const double flowArea0toArea1_positive = 10; static const double flowArea0toArea1_negative = -10; @@ -370,3 +372,75 @@ BOOST_AUTO_TEST_CASE(check_adq_param_wrong_hurdle_cost) auto p = createParams(); BOOST_CHECK_THROW(p.checkAdqPatchIncludeHurdleCost(false), Error::IncompatibleHurdleCostCSR); } + +BOOST_AUTO_TEST_SUITE(adq_patch_post_processing) + +BOOST_AUTO_TEST_CASE(dtg_mrg_triggered_low_ens) +{ + const bool triggered = true; + const double dtgMrg = 32.; + const double ens = 21.; + + BOOST_TEST(recomputeDTG_MRG(triggered, dtgMrg, ens) == 11., tt::tolerance(1.e-6)); + + BOOST_TEST(recomputeDTG_MRG(triggered, dtgMrg, ens) + recomputeENS_MRG(triggered, dtgMrg, ens) + == std::abs(dtgMrg - ens), + tt::tolerance(1.e-6)); +} + +BOOST_AUTO_TEST_CASE(dtg_mrg_triggered_high_ens) +{ + const bool triggered = true; + const double dtgMrg = 32.; + const double ens = 42.; + + BOOST_TEST(recomputeDTG_MRG(triggered, dtgMrg, ens) == 0., tt::tolerance(1.e-6)); + + BOOST_TEST(recomputeDTG_MRG(triggered, dtgMrg, ens) + recomputeENS_MRG(triggered, dtgMrg, ens) + == std::abs(dtgMrg - ens), + tt::tolerance(1.e-6)); +} + +BOOST_AUTO_TEST_CASE(dtg_mrg_not_triggered_low_ens) +{ + const bool triggered = false; + const double dtgMrg = 32.; + const double ens = 21.; + + BOOST_TEST(recomputeDTG_MRG(triggered, dtgMrg, ens) == dtgMrg, tt::tolerance(1.e-6)); + BOOST_TEST(recomputeDTG_MRG(triggered, dtgMrg, ens) + recomputeENS_MRG(triggered, dtgMrg, ens) + == dtgMrg + ens, + tt::tolerance(1.e-6)); +} + +BOOST_AUTO_TEST_CASE(dtg_mrg_not_triggered_high_ens) +{ + const bool triggered = false; + const double dtgMrg = 32.; + const double ens = 42.; + + BOOST_TEST(recomputeDTG_MRG(triggered, dtgMrg, ens) == dtgMrg, tt::tolerance(1.e-6)); + BOOST_TEST(recomputeDTG_MRG(triggered, dtgMrg, ens) + recomputeENS_MRG(triggered, dtgMrg, ens) + == dtgMrg + ens, + tt::tolerance(1.e-6)); +} + +BOOST_AUTO_TEST_CASE(mrgprice_high_enscsr) +{ + const double ensCsr = 21.; + const double originalCost = 3.; + const double unsuppliedEnergyCost = 1000.; + BOOST_TEST(recomputeMRGPrice(ensCsr, originalCost, unsuppliedEnergyCost) + == -unsuppliedEnergyCost, + tt::tolerance(1.e-6)); +} + +BOOST_AUTO_TEST_CASE(mrgprice_low_enscsr) +{ + const double ensCsr = 0.; + const double originalCost = 3.; + const double unsuppliedEnergyCost = 1000.; + BOOST_TEST(recomputeMRGPrice(ensCsr, originalCost, unsuppliedEnergyCost) == originalCost, + tt::tolerance(1.e-6)); +} +BOOST_AUTO_TEST_SUITE_END()