Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE - FOR EXECUTABLES ONLY RTEi #1190

Closed
wants to merge 14 commits into from
12 changes: 6 additions & 6 deletions .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ jobs:
path: 'simtest.json'
prop_path: 'version'

- name: Run tests for adequacy patch (CSR)
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{steps.simtest-version.outputs.prop}}
batch-name: adequacy-patch-CSR
os: ${{ matrix.test-platform }}
# - name: Run tests for adequacy patch (CSR)
# uses: ./.github/workflows/run-tests
# with:
# simtest-tag: ${{steps.simtest-version.outputs.prop}}
# batch-name: adequacy-patch-CSR
# os: ${{ matrix.test-platform }}

- name: Run tests about infinity on BCs RHS
uses: ./.github/workflows/run-tests
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(ANTARES_WEBSITE "https://antares-simulator.org/")
set(ANTARES_ONLINE_DOC "https://antares-simulator.readthedocs.io/")

# Beta release
set(ANTARES_BETA 0)
set(ANTARES_BETA 12) # adq-patch-beta-12 for Elia
set(ANTARES_RC 0)

# OR-Tools tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ std::tuple<double, double, double> calculateAreaFlowBalance(PROBLEME_HEBDO* prob
}

double ensInit
= problemeHebdo->ResultatsHoraires[Area]->ValeursHorairesDeDefaillancePositive[hour];
= problemeHebdo->ResultatsHoraires[Area]->ValeursHorairesDeDefaillancePositive[hour]; // this is still calculated properly!! From ENS value from the first and only optimization before CSR hourly run
if (includeFlowsOutsideAdqPatchToDensNew)
{
densNew = std::max(0.0, ensInit + netPositionInit + flowsNode1toNodeA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ double calculateQuadraticCost(const PROBLEME_HEBDO* problemeHebdo, int hour, int
else if (problemeHebdo->adqPatchParams->PriceTakingOrder
== Data::AdequacyPatch::AdqPatchPTO::isDens)
{
priceTakingOrders = problemeHebdo->ResultatsHoraires[area]->ValeursHorairesDENS[hour];
priceTakingOrders = problemeHebdo->ResultatsHoraires[area]->ValeursHorairesDENS[hour]; // densNew value taken! OK!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful, ValeursHorairesDENS[hour] = 0, see src/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.cpp.

Suggested change
priceTakingOrders = problemeHebdo->ResultatsHoraires[area]->ValeursHorairesDENS[hour]; // densNew value taken! OK!
priceTakingOrders = problemeHebdo->ResultatsHoraires[pays]->ValeursHorairesDeDefaillancePositive[hour];

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm positive we are good here. According to spec:
image
s0 PTO=DENS not PTO=ENS.
if ValeursHorairesDENS[hour] = 0 function calculateQuadraticCost will just return zero. It will not try to divide with zero.
If you meant that by this point in the code the column DENS is going to be all zeros, It is not the case. Zeros are overwritten for areas inside adq-patch in
src/solver/optimisation/post_process_commands.cpp line 231

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, LGTM

}

if (priceTakingOrders <= 0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void HourlyCSRProblem::setBoundsOnENS()
int var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[area];

problemeAResoudre_.Xmin[var] = -csrSolverRelaxation;
problemeAResoudre_.Xmax[var]
problemeAResoudre_.Xmax[var] // upper bound for ENS variable is still calculated DENS_new
= problemeHebdo_->ResultatsHoraires[area]->ValeursHorairesDENS[triggeredHour]
+ csrSolverRelaxation;

Expand Down
4 changes: 2 additions & 2 deletions src/solver/optimisation/adequacy_patch_csr/solve_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void storeOrDisregardInteriorPointResults(const PROBLEME_ANTARES_A_RESOUDRE& Pro
else if (checkCost && deltaCost >= 0.0)
logs.warning()
<< "[adq-patch] CSR optimization is providing solution with greater costs, optimum "
"solution is set as LMR . year: "
"solution is set as Normal Optimization . year: "
<< yearNb + 1 << ". hour: " << weekNb * hoursInWeek + hourlyCsrProblem.triggeredHour + 1;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ void handleInteriorPointError(const PROBLEME_POINT_INTERIEUR& Probleme,
{
const int hoursInWeek = 168;
logs.warning()
<< "No further optimization for CSR is possible, optimum solution is set as LMR . year: "
<< "No further optimization for CSR is possible, optimum solution is set as Normal Optimization . year: "
<< yearNb + 1 << ". hour: " << weekNb * hoursInWeek + hour + 1;

#ifndef NDEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,33 @@ AdequacyPatchOptimization::AdequacyPatchOptimization(PROBLEME_HEBDO* problemeHeb
}
void AdequacyPatchOptimization::solve(uint weekInTheYear, int hourInTheYear)
{
problemeHebdo_->adqPatchParams->AdequacyFirstStep = true;
OPT_OptimisationHebdomadaire(problemeHebdo_, thread_number_);
// problemeHebdo_->adqPatchParams->AdequacyFirstStep = true;
// OPT_OptimisationHebdomadaire(problemeHebdo_, thread_number_);

// never set AdequacyFirstStep to True and skip the islanding optimization
Comment on lines +48 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to change the definition of this class (revert all changes).

We made a nice factory method just for that, see file src/solver/optimisation/base_weekly_optimization.cpp. Just return std::make_unique<DefaultWeeklyOptimization> in all cases (adq patch enabled/disabled), it's much simpler.

Copy link
Collaborator Author

@Milos-RTEi Milos-RTEi Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I saw that. Nice. I agree it's a proper way to do it.
I just wanted to be sure that AdequacyFirstStep = false. Even though I think I overwritten all the code where AdequacyFirstStep is used.
Also for areas outside adq-patch we need to set zero values for DENS somewhere.
I agree DENS should be initialized to zero somewhere else if just defaultWeeklyOptimization is required.
On TODO list.

problemeHebdo_->adqPatchParams->AdequacyFirstStep = false;

for (int pays = 0; pays < problemeHebdo_->NombreDePays; ++pays)
{
if (problemeHebdo_->adequacyPatchRuntimeData->areaMode[pays]
== Data::AdequacyPatch::physicalAreaInsideAdqPatch)
memcpy(problemeHebdo_->ResultatsHoraires[pays]->ValeursHorairesDENS,
problemeHebdo_->ResultatsHoraires[pays]->ValeursHorairesDeDefaillancePositive,
problemeHebdo_->NombreDePasDeTemps * sizeof(double));
else
// if (problemeHebdo_->adequacyPatchRuntimeData->areaMode[pays]
// == Data::AdequacyPatch::physicalAreaInsideAdqPatch)
// memcpy(problemeHebdo_->ResultatsHoraires[pays]->ValeursHorairesDENS,
// problemeHebdo_->ResultatsHoraires[pays]->ValeursHorairesDeDefaillancePositive,
// problemeHebdo_->NombreDePasDeTemps * sizeof(double));
// else
memset(problemeHebdo_->ResultatsHoraires[pays]->ValeursHorairesDENS,
0,
problemeHebdo_->NombreDePasDeTemps * sizeof(double));
}

// no need to copy results/column ENS - > DENS, just set all DENS to zero

// TODO check if we need to cut SIM_RenseignementProblemeHebdo and just pick out the
// part that we need
::SIM_RenseignementProblemeHebdo(*problemeHebdo_, weekInTheYear, thread_number_, hourInTheYear);
OPT_OptimisationHebdomadaire(problemeHebdo_, thread_number_);
// ::SIM_RenseignementProblemeHebdo(*problemeHebdo_, weekInTheYear, thread_number_, hourInTheYear);
// no need to refresh anything now
// do normal optimization
OPT_OptimisationHebdomadaire(problemeHebdo_, thread_number_); // thread_number_is const and is = 0
}

} // namespace Antares::Solver::Optimization
Original file line number Diff line number Diff line change
Expand Up @@ -135,35 +135,37 @@ void setNTCbounds(double& Xmax,
Xmax = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco];
Xmin = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]);

// first step is never going to come to this point as True but just to be sure we can skip this

// set for adq patch first step
if (problemeHebdo->adqPatchParams && problemeHebdo->adqPatchParams->AdequacyFirstStep)
{
ntcToZeroStatusForAdqPatch = getNTCtoZeroStatus(problemeHebdo, Interco);
// if (problemeHebdo->adqPatchParams && problemeHebdo->adqPatchParams->AdequacyFirstStep)
// {
// ntcToZeroStatusForAdqPatch = getNTCtoZeroStatus(problemeHebdo, Interco);

switch (ntcToZeroStatusForAdqPatch)
{
case NtcSetToZeroStatus_AdqPatchStep1::setToZero:
{
Xmax = 0.;
Xmin = 0.;
break;
}
case NtcSetToZeroStatus_AdqPatchStep1::setOriginExtremityToZero:
{
Xmax = 0.;
Xmin = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]);
break;
}
case NtcSetToZeroStatus_AdqPatchStep1::setExtremityOriginToZero:
{
Xmax = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco];
Xmin = 0.;
break;
}
default:
return;
}
}
// switch (ntcToZeroStatusForAdqPatch)
// {
// case NtcSetToZeroStatus_AdqPatchStep1::setToZero:
// {
// Xmax = 0.;
// Xmin = 0.;
// break;
// }
// case NtcSetToZeroStatus_AdqPatchStep1::setOriginExtremityToZero:
// {
// Xmax = 0.;
// Xmin = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]);
// break;
// }
// case NtcSetToZeroStatus_AdqPatchStep1::setExtremityOriginToZero:
// {
// Xmax = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco];
// Xmin = 0.;
// break;
// }
// default:
// return;
// }
// }
}

} // namespace Antares::Data::AdequacyPatch
16 changes: 9 additions & 7 deletions src/solver/optimisation/opt_gestion_des_bornes_cas_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ void setBoundsForUnsuppliedEnergy(PROBLEME_HEBDO* problemeHebdo,
Xmax[var] = 0.;

// adq patch: update ENS <= DENS in 2nd run
if (problemeHebdo->adqPatchParams
&& problemeHebdo->adqPatchParams->AdequacyFirstStep == false
&& problemeHebdo->adequacyPatchRuntimeData->areaMode[Pays]
== Data::AdequacyPatch::physicalAreaInsideAdqPatch)
Xmax[var] = std::min(
Xmax[var], problemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDENS[PdtHebdo]);
// if (problemeHebdo->adqPatchParams
// && problemeHebdo->adqPatchParams->AdequacyFirstStep == false
// && problemeHebdo->adequacyPatchRuntimeData->areaMode[Pays]
// == Data::AdequacyPatch::physicalAreaInsideAdqPatch)
// Xmax[var] = std::min(
// Xmax[var], problemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDENS[PdtHebdo]);

// no need to adjust Xmax -> simulate ENS <= DENS in 2nd run when AdequacyFirstStep == false

problemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDeDefaillancePositive[PdtHebdo]
= 0.0;
Expand Down Expand Up @@ -220,7 +222,7 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* prob
var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco];
CoutDeTransport = problemeHebdo->CoutDeTransport[Interco];

AdequacyPatch::setNTCbounds(Xmax[var], Xmin[var], ValeursDeNTC, Interco, problemeHebdo);
AdequacyPatch::setNTCbounds(Xmax[var], Xmin[var], ValeursDeNTC, Interco, problemeHebdo); // since AdequacyFirstStep is always false bounds are set properly !!

if (Math::Infinite(Xmax[var]) == 1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/solver/optimisation/post_process_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ double CurtailmentSharingPostProcessCmd::calculateDensNewAndTotalLmrViolation()
+ ? flows (node 1 -> node A) - DTG.MRG(node A)] */
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]
// write down densNew values for all the hours - > this is still OK - before CSR optimization writing all DENS values above zero values for areas inside adq-patch
problemeHebdo_->ResultatsHoraires[Area]->ValeursHorairesDENS[hour]
= std::max(0.0, densNew - dtgMrg);
;
// copy spilled Energy values into spilled Energy values after CSR
Expand Down
Loading
Loading