Skip to content

Commit

Permalink
Fix Variable::Join (#2116)
Browse files Browse the repository at this point in the history
Use `Join<A, Join<B, C>>` instead of `Join<A, B, C>`, see economy/all.h
and adequacy/all.h, where C is `BindingConstraint`.

This requires homogeneity in function signatures. Indeed, currently many
functions have mismatching signatures, __ie__ a missing `numSpace`
argument, etc. Some functions also do not exist. So the hardest part of
this work is to even out all of these functions.

---------

Co-authored-by: Abdoulbari Zakir <[email protected]>
  • Loading branch information
flomnes and a-zakir authored May 28, 2024
1 parent 3e89b2e commit fa8f497
Show file tree
Hide file tree
Showing 62 changed files with 391 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ typedef Variable::Join<
// Variables for each area / links attached to the areas
Variable::Areas<VariablesPerArea>,
// Variables for each set of areas
Variable::SetsOfAreas<VariablesPerSetOfAreas>,
// Variables for each binding constraint
Variable::BindingConstraints<VariablesPerBindingConstraints>>
Variable::Join<Variable::SetsOfAreas<VariablesPerSetOfAreas>,
// Variables for each binding constraint
Variable::BindingConstraints<VariablesPerBindingConstraints>>>
ItemList;

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ class OverallCost: public Variable::IVariable<OverallCost<NextT>, NextT, VCardOv
NextType::yearEndBuildForEachThermalCluster(state, 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ class SpilledEnergy: public Variable::IVariable<SpilledEnergy<NextT>, NextT, VCa
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,18 @@ class BindingConstraints
void computeSummary(std::map<unsigned int, unsigned int>& numSpaceToYear,
unsigned int nbYearsForCurrentSummary);

void simulationBegin();
void simulationEnd();

void yearBegin(uint year, uint numSpace);
void yearEnd(uint year, uint numSpace);

void yearEndBuild(State& state, uint year, uint numSpace);

void weekBegin(State& state);
void weekEnd(State& state);
void weekForEachArea(State&, unsigned int numSpace);
void hourForEachArea(State&, unsigned int numSpace);

void hourBegin(uint hourInTheYear);
void hourEnd(State& state, uint hourInTheYear);
Expand All @@ -146,9 +154,39 @@ class BindingConstraints

uint64_t memoryUsage() const;

template<class V>
void yearEndSpatialAggregates(V&, uint, uint)
{
// do nothing
}

template<class I>
static void provideInformations(I& infos);

template<class VCardToFindT>
void retrieveResultsForArea(typename Storage<VCardToFindT>::ResultsType** result,
const Data::Area* area);
void buildDigest(SurveyResults&, int digestLevel, int dataLevel) const;

template<class V>
void simulationEndSpatialAggregates(V& allVars);

template<class VCardToFindT>
void retrieveResultsForLink(typename Storage<VCardToFindT>::ResultsType** result,
const Data::AreaLink* link);

template<class VCardToFindT>
void retrieveResultsForThermalCluster(typename Storage<VCardToFindT>::ResultsType** result,
const Data::ThermalCluster* cluster);
template<class VCardSearchT, class O>
void computeSpatialAggregateWith(O& out, const Data::Area* area, uint numSpace);
template<class V>
void computeSpatialAggregatesSummary(V& allVars,
std::map<unsigned int, unsigned int>& numSpaceToYear,
unsigned int);

void beforeYearByYearExport(uint year, uint numSpace);

private:
// For each binding constraint, output variable static list associated.
std::vector<NextType> pBindConstraints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ inline void BindingConstraints<NextT>::provideInformations(I& infos)
}
}

template<class NextT>
void BindingConstraints<NextT>::simulationBegin()
{
for (auto& bc: pBindConstraints)
{
bc.simulationBegin();
}
}

template<class NextT>
void BindingConstraints<NextT>::simulationEnd()
{
for (auto& bc: pBindConstraints)
{
bc.simulationEnd();
}
}

template<class NextT>
void BindingConstraints<NextT>::yearEndBuild(State& /*state*/, uint /*year*/, uint /*numSpace*/)
{
}

template<class NextT>
void BindingConstraints<NextT>::initializeFromStudy(Data::Study& study)
{
Expand Down Expand Up @@ -184,6 +207,15 @@ void BindingConstraints<NextT>::weekBegin(State& state)
}
}

template<class NextT>
void BindingConstraints<NextT>::weekEnd(State& state)
{
for (uint i = 0; i != pBCcount; ++i)
{
pBindConstraints[i].weekEnd(state);
}
}

template<class NextT>
void BindingConstraints<NextT>::hourBegin(uint hourInTheYear)
{
Expand Down Expand Up @@ -214,4 +246,96 @@ uint64_t BindingConstraints<NextT>::memoryUsage() const
return result;
}

template<class NextT>
void BindingConstraints<NextT>::weekForEachArea(State& state, unsigned int numSpace)
{
for (uint i = 0; i != pBCcount; ++i)
{
pBindConstraints[i].weekForEachArea(state, numSpace);
}
}

template<class NextT>
void BindingConstraints<NextT>::hourForEachArea(State& state, unsigned int numSpace)
{
for (uint i = 0; i != pBCcount; ++i)
{
pBindConstraints[i].hourForEachArea(state, numSpace);
}
}

template<class NextT>
template<class VCardToFindT>
inline void BindingConstraints<NextT>::retrieveResultsForArea(
typename Storage<VCardToFindT>::ResultsType** result,
const Data::Area* area)
{
NextType::template retrieveResultsForArea<VCardToFindT>(result, area);
}

template<class NextT>
void BindingConstraints<NextT>::buildDigest(SurveyResults& results,
int digestLevel,
int dataLevel) const
{
for (uint i = 0; i != pBCcount; ++i)
{
pBindConstraints[i].buildDigest(results, digestLevel, dataLevel);
}
}

template<class NextT>
template<class V>
void BindingConstraints<NextT>::simulationEndSpatialAggregates(V& allVars)
{
NextType::template simulationEndSpatialAggregates<V>(allVars);
}

template<class NextT>
template<class V>
void BindingConstraints<NextT>::computeSpatialAggregatesSummary(
V& allVars,
std::map<unsigned int, unsigned int>& numSpaceToYear,
unsigned int nbYearsForCurrentSummary)
{
NextType::template computeSpatialAggregatesSummary<V>(allVars,
numSpaceToYear,
nbYearsForCurrentSummary);
}

template<class NextT>
void BindingConstraints<NextT>::beforeYearByYearExport(uint year, uint numSpace)
{
for (uint i = 0; i != pBCcount; ++i)
{
pBindConstraints[i].beforeYearByYearExport(year, numSpace);
}
}

template<class NextT>
template<class SearchVCardT, class O>
inline void BindingConstraints<NextT>::computeSpatialAggregateWith(O& out,
const Data::Area* area,
uint numSpace)
{
NextType::template computeSpatialAggregateWith<SearchVCardT, O>(out, area, numSpace);
}

template<class NextT>
template<class VCardToFindT>
inline void BindingConstraints<NextT>::retrieveResultsForLink(
typename Storage<VCardToFindT>::ResultsType** result,
const Data::AreaLink* link)
{
NextType::template retrieveResultsForLink<VCardToFindT>(result, link);
}

template<class NextT>
template<class VCardToFindT>
inline void BindingConstraints<NextT>::retrieveResultsForThermalCluster(
typename Storage<VCardToFindT>::ResultsType** result,
const Data::ThermalCluster* cluster)
{
NextType::template retrieveResultsForThermalCluster<VCardToFindT>(result, cluster);
}
} // namespace Antares::Solver::Variable
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ class TimeSeriesValuesHydro
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)
Expand Down
Loading

0 comments on commit fa8f497

Please sign in to comment.