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

Districts : simplifying the code #2279

Merged
merged 42 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6015a25
sets byIndex
payetvin Jul 18, 2024
67ba855
sets namebyIndex
payetvin Jul 18, 2024
4bdf895
correlation montlhy
payetvin Jul 18, 2024
404c817
correlation annual
payetvin Jul 18, 2024
680cb2e
small refactor in correlation
payetvin Jul 18, 2024
2da0e70
atsp tmparray
payetvin Jul 18, 2024
05aaac0
scenario rules
payetvin Jul 19, 2024
065acfb
xcast in ts generator
payetvin Jul 19, 2024
7438946
Revert "xcast in ts generator"
payetvin Jul 19, 2024
fc5d298
use make_shared for sets
payetvin Jul 19, 2024
978f04b
Merge branch 'develop' into feature/remove-new
payetvin Jul 19, 2024
b9bf04a
link info in cbuilder
payetvin Jul 19, 2024
7b6310c
thermal cluster prepro
payetvin Jul 19, 2024
b103fd7
format
payetvin Jul 19, 2024
7673fe9
Use unique_ptr
JasonMarechal25 Jul 22, 2024
83ec498
Remove this
JasonMarechal25 Jul 22, 2024
b1cc714
Use unique_ptr
JasonMarechal25 Jul 22, 2024
ed80dae
Remove dynamic allocations (#2275)
JasonMarechal25 Jul 22, 2024
d1c32f4
Simplify districts : remove useless setsOfLinks.
guilpier-code Jul 22, 2024
98169b6
Use uniqie_ptr
JasonMarechal25 Jul 22, 2024
ec17e72
Fix build
JasonMarechal25 Jul 22, 2024
58de3f2
Fix potential access violation (#2278)
JasonMarechal25 Jul 22, 2024
48a2246
Simplify districts : remove useless templates of class Sets
guilpier-code Jul 22, 2024
597177c
Merge branch 'feature/remove-new' into fix/simplify-districts
JasonMarechal25 Jul 22, 2024
3b2e9c6
Simplify districts : move set handler were it belongs (from Study to …
guilpier-code Jul 23, 2024
faf1d72
Simplify districts : remove all trace of template in class Sets, not …
guilpier-code Jul 23, 2024
c3a2cb5
Simplify districts : formatting
guilpier-code Jul 23, 2024
c5820ab
Simplify districts : renaming + make an add(...) function more simple
guilpier-code Jul 24, 2024
f41f711
Simplify districts : several things (see commit message)
guilpier-code Jul 24, 2024
081f91a
Merge remote-tracking branch 'remotes/origin/develop' into fix/simpli…
guilpier-code Jul 24, 2024
308ea5e
Simplify districts : formatting
guilpier-code Jul 24, 2024
8977058
Simplify districts : removing useless "typename"s (now templates were…
guilpier-code Jul 30, 2024
0237365
Simplify districts : use more modern loops over STL containers
guilpier-code Jul 30, 2024
229e733
Simplify districts : make Sets::add(...) functions private + improve …
guilpier-code Jul 31, 2024
b99d7b7
Simplify districts : changes die to review
guilpier-code Jul 31, 2024
9189793
Merge branch 'develop' into fix/simplify-districts
JasonMarechal25 Aug 19, 2024
ca613bf
Simplify districts : just reorder class Sets' methods to look better …
guilpier-code Aug 21, 2024
14b0e7a
Simplify districts : apply clang format
guilpier-code Aug 21, 2024
ab3ac26
Merge remote-tracking branch 'remotes/origin/develop' into fix/simpli…
guilpier-code Aug 22, 2024
cf8fa43
Simplify districts : temporarily activate running of all tests + comp…
guilpier-code Aug 22, 2024
842d1d4
Simplify districts : replace push_back with emplace_back
guilpier-code Aug 23, 2024
a92a56f
Revert workflows
flomnes Aug 23, 2024
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
14 changes: 7 additions & 7 deletions src/analyzer/atsp/correlations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool ATSP::computeMonthlyCorrelations()
Matrix<> tmpNDP;
tmpNDP.reset(realAreaCount, realAreaCount);

double* tmpArray = new double[realAreaCount + 1];
std::vector<double> tmpArray(realAreaCount + 1);

// Initialize mapping, to skip areas which has been disabled
// the real number of items is `realAreaCount`
Expand Down Expand Up @@ -342,7 +342,7 @@ bool ATSP::computeMonthlyCorrelations()
resultNDP.entry,
ID.entry,
ID.width,
tmpArray);
tmpArray.data());
if (shrink < 1.)
{
if (shrink <= -1.)
Expand Down Expand Up @@ -381,7 +381,7 @@ bool ATSP::computeMonthlyCorrelations()
resultNDP.entry,
CORR_MNPZ.entry,
CORR_MNPZ.width,
tmpArray);
tmpArray.data());
if (shrink < 1.)
{
if (shrink <= -1.) // CORR_MNPZ is too close to sdp boundary, shrink CORR_MNP instead
Expand All @@ -393,7 +393,7 @@ bool ATSP::computeMonthlyCorrelations()
resultNDP.entry,
ID.entry,
ID.width,
tmpArray);
tmpArray.data());
if (shrink <= -1.)
{
logs.error() << "invalid data, can not be processed";
Expand Down Expand Up @@ -505,7 +505,7 @@ bool ATSP::computeMonthlyCorrelations()
resultNDP.entry,
ID.entry,
ID.width,
tmpArray);
tmpArray.data());
if (shrink < 1.)
{
if (shrink <= -1.)
Expand Down Expand Up @@ -542,7 +542,7 @@ bool ATSP::computeMonthlyCorrelations()
resultNDP.entry,
CORR_YNPZ.entry,
CORR_YNPZ.width,
tmpArray);
tmpArray.data());
if (shrink < 1.)
{
if (shrink <= -1.) // CORR_YNP is too close to sdp boundary, shrink CORR_YNP instead
Expand All @@ -554,7 +554,7 @@ bool ATSP::computeMonthlyCorrelations()
resultNDP.entry,
ID.entry,
ID.width,
tmpArray);
tmpArray.data());
if (shrink <= -1.)
{
logs.error() << "invalid data, can not be processed";
Expand Down
180 changes: 53 additions & 127 deletions src/libs/antares/correlation/correlation.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
** 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/>.
*/
* 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 "antares/correlation/correlation.h"

Expand Down Expand Up @@ -327,18 +327,10 @@ int InterAreaCorrelationSaveToFile(const Matrix<>* m, const AreaList* l, const c
}

Correlation::Correlation():
annual(nullptr),
monthly(nullptr),
pMode(modeNone)
{
}

Correlation::~Correlation()
{
delete annual;
delete[] monthly;
}

bool Correlation::loadFromFile(Study& study, const AnyString& filename, bool warnings)
{
#ifndef NDEBUG
Expand Down Expand Up @@ -397,16 +389,16 @@ void Correlation::internalSaveToINI(Study& study, IO::File::Stream& file) const
// mode
file << "[general]\nmode = " << ModeToCString(pMode) << "\n\n";

if (annual)
if (!annual.empty())
{
ExportCorrelationCoefficients(study, *annual, file, "annual");
ExportCorrelationCoefficients(study, annual, file, "annual");
}
else
{
logs.error() << correlationName << ": the annual correlation coefficients are missing";
}

if (monthly)
if (!monthly.empty())
{
for (int month = 0; month < 12; month++)
{
Expand All @@ -428,20 +420,20 @@ bool Correlation::internalLoadFromINITry(Study& study, const IniFile& ini, bool

if (JIT::usedFromGUI or pMode == modeAnnual)
{
annual = new Matrix<>();
annual->resize(study.areas.size(), study.areas.size());
annual->fillUnit();
annual.clear();
annual.resize(study.areas.size(), study.areas.size());
annual.fillUnit();

auto* section = ini.find("annual");
if (section) // the section might be missing
{
ReadCorrelationCoefficients(*this, study, *annual, ini, *section, warnings);
ReadCorrelationCoefficients(*this, study, annual, ini, *section, warnings);
}
}

if (JIT::usedFromGUI or pMode == modeMonthly)
{
monthly = new Matrix<>[12];
monthly.resize(12);
for (uint i = 0; i < 12; ++i)
{
monthly[i].resize(study.areas.size(), study.areas.size());
Expand Down Expand Up @@ -475,28 +467,18 @@ bool Correlation::internalLoadFromINITry(Study& study, const IniFile& ini, bool

void Correlation::reset(Study& study)
{
// Clean
if (annual)
{
delete annual;
annual = nullptr;
}
if (monthly)
{
delete[] monthly;
monthly = nullptr;
}
clear();

pMode = modeAnnual;
if (JIT::usedFromGUI)
{
// Reset
annual = new Matrix<>();
annual->resize(study.areas.size(), study.areas.size());
annual->fillUnit();
annual.clear();
annual.resize(study.areas.size(), study.areas.size());
annual.fillUnit();

// Preparing the monthly correlation matrices
monthly = new Matrix<>[12];
monthly.resize(12);
for (int i = 0; i < 12; ++i)
{
monthly[i].resize(study.areas.size(), study.areas.size());
Expand All @@ -505,69 +487,44 @@ void Correlation::reset(Study& study)
}
else
{
annual = new Matrix<>();
annual->resize(study.areas.size(), study.areas.size());
annual->fillUnit();
annual.clear();
annual.resize(study.areas.size(), study.areas.size());
annual.fillUnit();
}
}

void Correlation::clear()
{
// Clean
if (annual)
{
delete annual;
annual = nullptr;
}
if (monthly)
{
delete[] monthly;
monthly = nullptr;
}
annual.reset();
monthly.clear();
}

bool Correlation::internalLoadFromINI(Study& study, const IniFile& ini, bool warnings)
{
// Clean
if (annual)
{
delete annual;
annual = nullptr;
}
if (monthly)
{
delete[] monthly;
monthly = nullptr;
}
clear();

if (!internalLoadFromINITry(study, ini, warnings))
{
// The loading has failed - fallback
pMode = modeAnnual;
if (JIT::usedFromGUI)
{
// Reset
annual = new Matrix<>();
annual->resize(study.areas.size(), study.areas.size());
annual->fillUnit();

// Preparing the monthly correlation matrices
monthly = new Matrix<>[12];
monthly.resize(12);
for (int i = 0; i < 12; ++i)
{
monthly[i].resize(study.areas.size(), study.areas.size());
monthly[i].fillUnit();
}
}
else
{
annual = new Matrix<>();
annual->resize(study.areas.size(), study.areas.size());
annual->fillUnit();
}

annual.clear();
annual.resize(study.areas.size(), study.areas.size());
annual.fillUnit();

return false;
}

return true;
}

Expand Down Expand Up @@ -600,45 +557,14 @@ void Correlation::set(Matrix<>& m, const Area& from, const Area& to, double v)
m[to.index][from.index] = v;
}

void Correlation::retrieveMontlyMatrixArray(const Matrix<>* array[12]) const
{
switch (pMode)
{
case modeAnnual:
{
for (uint i = 0; i != 12; ++i)
{
array[i] = annual;
}
break;
}
case modeMonthly:
{
for (uint i = 0; i != 12; ++i)
{
array[i] = &(monthly[i]);
}
break;
}
default:
{
for (uint i = 0; i != 12; ++i)
{
array[i] = nullptr;
}
return;
}
}
}

uint64_t Correlation::memoryUsage() const
{
uint64_t r = sizeof(Correlation);
if (annual)
if (!annual.empty())
{
r += annual->memoryUsage();
r += annual.memoryUsage();
}
if (monthly)
if (!monthly.empty())
{
for (uint i = 0; i != 12; ++i)
{
Expand All @@ -651,9 +577,9 @@ uint64_t Correlation::memoryUsage() const
bool Correlation::forceReload(bool reload) const
{
bool ret = true;
if (annual)
if (!annual.empty())
{
ret = annual->forceReload(reload) and ret;
ret = annual.forceReload(reload) and ret;
}
for (uint i = 0; i != 12; ++i)
{
Expand All @@ -665,9 +591,9 @@ bool Correlation::forceReload(bool reload) const

void Correlation::markAsModified() const
{
if (annual)
if (!annual.empty())
{
annual->markAsModified();
annual.markAsModified();
}
for (uint i = 0; i != 12; ++i)
{
Expand Down Expand Up @@ -762,8 +688,8 @@ void Correlation::copyFrom(const Correlation& source,

// copying the annual correlation matrix
std::cout << "ANNUAL\n";
CopyFromSingleMatrix(*source.annual,
*annual,
CopyFromSingleMatrix(source.annual,
annual,
studySource,
areaSourceIndex,
areaTargetIndex,
Expand Down
Loading
Loading