Skip to content

Commit

Permalink
Adequacy patch CSR - revamp output variables [ANT-1932] (#2421)
Browse files Browse the repository at this point in the history
Backport of #2306
  • Loading branch information
flomnes authored Sep 27, 2024
1 parent 0577520 commit 8dbf5c1
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 125 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/parameters/adq-patch-params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void AdqPatchParams::addExcludedVariables(std::vector<std::string>& 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");
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/libs/antares/study/parameters/adq-patch-params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions src/solver/optimisation/adequacy_patch_csr/post_processing.cpp
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/license/mpl-2-0/>.
*/
#include "post_processing.h"

#include <algorithm>

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
29 changes: 29 additions & 0 deletions src/solver/optimisation/adequacy_patch_csr/post_processing.h
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/license/mpl-2-0/>.
*/

#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
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ void HourlyCSRProblem::setBoundsOnSpilledEnergy()
.ValeursHorairesDeDefaillanceNegative[triggeredHour];

double* AdresseDuResultat = &(problemeHebdo_->ResultatsHoraires[area]
.ValeursHorairesSpilledEnergyAfterCSR[triggeredHour]);

.ValeursHorairesDeDefaillanceNegative[triggeredHour]);
problemeAResoudre_.AdresseOuPlacerLaValeurDesVariablesOptimisees[var]
= AdresseDuResultat;

Expand Down
45 changes: 18 additions & 27 deletions src/solver/optimisation/post_process_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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_,
Expand Down
4 changes: 2 additions & 2 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/solver/simulation/sim_structure_probleme_economique.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ struct PRODUCTION_THERMIQUE_OPTIMALE
struct RESULTATS_HORAIRES
{
std::vector<double> ValeursHorairesDeDefaillancePositive;
std::vector<double> ValeursHorairesDENS; // adq patch domestic unsupplied energy
std::vector<int> ValeursHorairesLmrViolations; // adq patch lmr violations
std::vector<double> ValeursHorairesSpilledEnergyAfterCSR; // adq patch spillage after CSR
std::vector<double> ValeursHorairesDeDefaillancePositiveCSR;
std::vector<double> ValeursHorairesDENS; // adq patch domestic unsupplied energy
std::vector<int> ValeursHorairesLmrViolations; // adq patch lmr violations
std::vector<double> ValeursHorairesDtgMrgCsr; // adq patch DTG MRG after CSR
std::vector<double> ValeursHorairesDeDefaillancePositiveUp;
std::vector<double> ValeursHorairesDeDefaillancePositiveDown;
Expand Down
3 changes: 2 additions & 1 deletion src/solver/variable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
36 changes: 18 additions & 18 deletions src/solver/variable/economy/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
#include "unsupliedEnergy.h"
#include "domesticUnsuppliedEnergy.h"
#include "localMatchingRuleViolations.h"
#include "spilledEnergyAfterCSR.h"
#include "dtgMarginAfterCsr.h"
#include "spilledEnergy.h"

Expand All @@ -73,6 +72,7 @@

#include "avail-dispatchable-generation.h"
#include "dispatchable-generation-margin.h"
#include "unsupliedEnergyCsr.h"

// By thermal plant
#include "productionByDispatchablePlant.h"
Expand Down Expand Up @@ -161,22 +161,24 @@ typedef // Prices
<DomesticUnsuppliedEnergy // Domestic Unsupplied Energy
<LMRViolations // LMR Violations
<SpilledEnergy // Spilled Energy
<SpilledEnergyAfterCSR // SpilledEnergyAfterCSR
<LOLD // LOLD
<LOLP // LOLP
<AvailableDispatchGen<DispatchableGenMargin<
DtgMarginCsr // DTG MRG CSR
<Marge<NonProportionalCost<
NonProportionalCostByDispatchablePlant // Startup cost + Fixed
// cost per thermal
// plant detail
<NbOfDispatchedUnits // Number of Units Dispatched
<NbOfDispatchedUnitsByPlant // Number of Units Dispatched by
// plant
<ProfitByPlant
// Links
<Variable::Economy::Links // All links
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<AvailableDispatchGen<DispatchableGenMargin<DtgMarginCsr< // DTG
// MRG
// CSR
UnsupliedEnergyCSR< // Unsupplied energy after CSR
Marge<NonProportionalCost<
NonProportionalCostByDispatchablePlant // Startup cost +
// Fixed cost per
// thermal plant
// detail
<NbOfDispatchedUnits // Number of Units Dispatched
<NbOfDispatchedUnitsByPlant // Number of Units Dispatched
// by plant
<ProfitByPlant
// Links
<Variable::Economy::Links // All links
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
VariablesPerArea;

/*!
Expand Down Expand Up @@ -240,8 +242,6 @@ typedef // Prices
LMRViolations,
Common::SpatialAggregate<
SpilledEnergy,
Common::SpatialAggregate<
SpilledEnergyAfterCSR,
// LOLD
Common::SpatialAggregate<
LOLD,
Expand Down Expand Up @@ -271,7 +271,7 @@ typedef // Prices
// -
// refs:
// #55
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
VariablesPerSetOfAreas;

typedef BindingConstMarginCost< // Marginal cost for a binding constraint
Expand Down
Loading

0 comments on commit 8dbf5c1

Please sign in to comment.