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

Remove manual allocations for set of areas, simplify code #2588

Merged
merged 11 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,11 @@ class SetsOfAreas

public:
//! Area list
typedef std::vector<NextType*> SetOfAreasVector;
typedef std::vector<NextType> SetOfAreasVector;
//! Area list
SetOfAreasVector pSetsOfAreas;
//! Reference to the origina set
std::vector<const Data::Sets::SetAreasType*> pOriginalSets;
//! An iterator for the begining of the list
typename SetOfAreasVector::iterator pBegin;
//! An iterator to the end of the list
typename SetOfAreasVector::iterator pEnd;
//! The study
const Data::Study* pStudy;

Expand Down
71 changes: 27 additions & 44 deletions src/solver/variable/include/antares/solver/variable/setofareas.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@ namespace Solver
namespace Variable
{
template<class NextT>
inline SetsOfAreas<NextT>::SetsOfAreas()
{
// Do nothing
}
inline SetsOfAreas<NextT>::SetsOfAreas() = default;

template<class NextT>
inline SetsOfAreas<NextT>::~SetsOfAreas()
{
// Releasing the memory occupied by the areas
for (typename SetOfAreasVector::iterator i = pBegin; i != pEnd; ++i)
{
delete *i;
}
}
inline SetsOfAreas<NextT>::~SetsOfAreas() = default;

template<class NextT>
void SetsOfAreas<NextT>::initializeFromStudy(Data::Study& study)
Expand All @@ -53,7 +43,7 @@ void SetsOfAreas<NextT>::initializeFromStudy(Data::Study& study)
// alias to the set of sets of areas
auto& sets = study.setsOfAreas;
// Reserving the memory
pSetsOfAreas.reserve(sets.size());
pSetsOfAreas.resize(sets.size());
pOriginalSets.reserve(sets.size());

// For each set...
Expand All @@ -74,35 +64,28 @@ void SetsOfAreas<NextT>::initializeFromStudy(Data::Study& study)
continue;
}

// Instancing a new set of variables of the area
NextType* n = new NextType();
auto& n = pSetsOfAreas[setIndex];

// Initialize the variables
// From the study
n->initializeFromStudy(study);
n.initializeFromStudy(study);

// Making specific variables non applicable in following output reports :
// - annual district reports
// - over all years district statistics reports
n->broadcastNonApplicability(true);
n.broadcastNonApplicability(true);

// For each current set's variable, getting the print status, that is :
// is variable's column(s) printed in output (set of areas) reports ?
n->getPrintStatusFromStudy(study);
n.getPrintStatusFromStudy(study);

// Adding the variables for the area in the list
pSetsOfAreas.push_back(n);
auto* originalSet = &sets[setIndex];
assert(originalSet != NULL);
assert(!originalSet->empty());
pOriginalSets.push_back(originalSet);

pNames.push_back(setname);
}

// Initializing iterators
pBegin = pSetsOfAreas.begin();
pEnd = pSetsOfAreas.end();
}

template<class NextT>
Expand Down Expand Up @@ -216,10 +199,10 @@ inline void SetsOfAreas<NextT>::buildSurveyReport(SurveyResults& results,
bool setOfAreasDataLevel = dataLevel & Category::DataLevel::setOfAreas;
if (count_int && setOfAreasDataLevel)
{
pSetsOfAreas[results.data.setOfAreasIndex]->buildSurveyReport(results,
dataLevel,
fileLevel,
precision);
pSetsOfAreas[results.data.setOfAreasIndex].buildSurveyReport(results,
dataLevel,
fileLevel,
precision);
}
}

Expand All @@ -234,11 +217,11 @@ inline void SetsOfAreas<NextT>::buildAnnualSurveyReport(SurveyResults& results,
bool setOfAreasDataLevel = dataLevel & Category::DataLevel::setOfAreas;
if (count_int && setOfAreasDataLevel)
{
pSetsOfAreas[results.data.setOfAreasIndex]->buildAnnualSurveyReport(results,
dataLevel,
fileLevel,
precision,
numSpace);
pSetsOfAreas[results.data.setOfAreasIndex].buildAnnualSurveyReport(results,
dataLevel,
fileLevel,
precision,
numSpace);
}
}

Expand All @@ -255,12 +238,12 @@ void SetsOfAreas<NextT>::buildDigest(SurveyResults& results, int digestLevel, in
results.data.area = nullptr;
results.data.rowIndex = 0;

for (auto i = pBegin; i != pEnd; ++i)
for (auto& i: pSetsOfAreas)
{
results.data.columnIndex = 0;
results.data.rowCaptions[results.data.rowIndex].clear()
<< "@ " << pNames[results.data.rowIndex];
(*i)->buildDigest(results, digestLevel, dataLevel);
i.buildDigest(results, digestLevel, dataLevel);
++results.data.rowIndex;
}
}
Expand Down Expand Up @@ -295,10 +278,10 @@ void SetsOfAreas<NextT>::yearEndSpatialAggregates(V& allVars, uint year, uint nu
for (uint setindex = 0; setindex != pSetsOfAreas.size(); ++setindex)
{
assert(setindex < pOriginalSets.size());
pSetsOfAreas[setindex]->yearEndSpatialAggregates(allVars,
year,
*(pOriginalSets[setindex]),
numSpace);
pSetsOfAreas[setindex].yearEndSpatialAggregates(allVars,
year,
*(pOriginalSets[setindex]),
numSpace);
}
}

Expand All @@ -312,9 +295,9 @@ void SetsOfAreas<NextT>::computeSpatialAggregatesSummary(
for (uint setindex = 0; setindex != pSetsOfAreas.size(); ++setindex)
{
assert(setindex < pOriginalSets.size());
pSetsOfAreas[setindex]->computeSpatialAggregatesSummary(allVars,
numSpaceToYear,
nbYearsForCurrentSummary);
pSetsOfAreas[setindex].computeSpatialAggregatesSummary(allVars,
numSpaceToYear,
nbYearsForCurrentSummary);
}
}

Expand All @@ -324,7 +307,7 @@ void SetsOfAreas<NextT>::simulationEndSpatialAggregates(V& allVars)
{
for (uint i = 0; i != pSetsOfAreas.size(); ++i)
{
pSetsOfAreas[i]->simulationEndSpatialAggregates(allVars, *(pOriginalSets[i]));
pSetsOfAreas[i].simulationEndSpatialAggregates(allVars, *(pOriginalSets[i]));
}
}

Expand All @@ -333,7 +316,7 @@ void SetsOfAreas<NextT>::beforeYearByYearExport(uint year, uint numSpace)
{
for (uint i = 0; i != pSetsOfAreas.size(); ++i)
{
pSetsOfAreas[i]->beforeYearByYearExport(year, numSpace);
pSetsOfAreas[i].beforeYearByYearExport(year, numSpace);
}
}

Expand Down
Loading