diff --git a/src/solver/variable/economy/max-mrg-utils.cpp b/src/solver/variable/economy/max-mrg-utils.cpp index cff627a0ea..cf9ac9e469 100644 --- a/src/solver/variable/economy/max-mrg-utils.cpp +++ b/src/solver/variable/economy/max-mrg-utils.cpp @@ -35,35 +35,32 @@ const unsigned int nbHoursInWeek = 168; namespace Antares::Solver::Variable::Economy { -MaxMRGinput dataToComputeMaxMRG(const State& state, unsigned int numSpace) +MaxMrgDataFactory::MaxMrgDataFactory(const State &state, unsigned int numSpace) : + state_(state), + numSpace_(numSpace), + weeklyResults_(state.problemeHebdo->ResultatsHoraires[state.area->index]) { - auto& area = *state.area; - auto index = area.index; - auto& problem = *state.problemeHebdo; - auto& weeklyResults = problem.ResultatsHoraires[index]; - - MaxMRGinput maxMrGinput; + maxMRGinput_.hydroGeneration = weeklyResults_.TurbinageHoraire.data(); + maxMRGinput_.hydroMaxPower = state_.area->hydro.maxPower[Data::PartHydro::genMaxP]; + maxMRGinput_.dtgMargin = state_.area->scratchpad[numSpace].dispatchableGenerationMargin; + maxMRGinput_.hourInYear = state.hourInTheYear; + maxMRGinput_.calendar = &state.study.calendar; + maxMRGinput_.areaName = state_.area->name.c_str(); +} - // Spillage - if (state.simplexRunNeeded) +MaxMRGinput MaxMrgUsualDataFactory::data() +{ + if (state_.simplexRunNeeded) { - maxMrGinput.spillage = weeklyResults.ValeursHorairesDeDefaillanceNegative.data(); + maxMRGinput_.spillage = weeklyResults_.ValeursHorairesDeDefaillanceNegative.data(); } else { - maxMrGinput.spillage = state.resSpilled[index]; + maxMRGinput_.spillage = state_.resSpilled[state_.area->index]; } - maxMrGinput.dens = weeklyResults.ValeursHorairesDeDefaillancePositive.data(); - - maxMrGinput.hydroGeneration = weeklyResults.TurbinageHoraire.data(); - maxMrGinput.hydroMaxPower = area.hydro.maxPower[Data::PartHydro::genMaxP]; - maxMrGinput.dtgMargin = area.scratchpad[numSpace].dispatchableGenerationMargin; - maxMrGinput.hourInYear = state.hourInTheYear; - maxMrGinput.calendar = &state.study.calendar; - maxMrGinput.areaName = area.name.c_str(); - - return maxMrGinput; + maxMRGinput_.dens = weeklyResults_.ValeursHorairesDeDefaillancePositive.data(); + return maxMRGinput_; } void computeMaxMRG(double* opmrg, const MaxMRGinput& in) diff --git a/src/solver/variable/economy/max-mrg-utils.h b/src/solver/variable/economy/max-mrg-utils.h index da9538e0af..73814f352d 100644 --- a/src/solver/variable/economy/max-mrg-utils.h +++ b/src/solver/variable/economy/max-mrg-utils.h @@ -17,8 +17,28 @@ struct MaxMRGinput std::string areaName; }; -MaxMRGinput dataToComputeMaxMRG(const State &state, unsigned int numSpace); void computeMaxMRG(double *opmrg, const MaxMRGinput &in); +class MaxMrgDataFactory +{ +public: + MaxMrgDataFactory(const State &state, unsigned int numSpace); + virtual MaxMRGinput data() = 0; +protected: + // in data + const State& state_; + const unsigned int numSpace_ = 0; + RESULTATS_HORAIRES& weeklyResults_; + // data to be built + MaxMRGinput maxMRGinput_; +}; + +class MaxMrgUsualDataFactory : public MaxMrgDataFactory +{ + using MaxMrgDataFactory::MaxMrgDataFactory; +public: + virtual MaxMRGinput data() override; +}; + } // Antares::Solver::Variable::Economy diff --git a/src/solver/variable/economy/max-mrg.h b/src/solver/variable/economy/max-mrg.h index 4c0c89b8c2..6e060f6f9f 100644 --- a/src/solver/variable/economy/max-mrg.h +++ b/src/solver/variable/economy/max-mrg.h @@ -242,7 +242,8 @@ class Marge : public Variable::IVariable, NextT, VCardMARGE> double* rawhourly = Memory::RawPointer(pValuesForTheCurrentYear[numSpace].hour); // Getting data required to compute max margin - MaxMRGinput maxMRGinput = dataToComputeMaxMRG(state, numSpace); + MaxMrgUsualDataFactory maxMRGdataFactory(state, numSpace); + MaxMRGinput maxMRGinput = maxMRGdataFactory.data(); computeMaxMRG(rawhourly + state.hourInTheYear, maxMRGinput); // next