Skip to content

Commit

Permalink
Merge branch 'develop' into fix/coverage-short
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes authored Jul 25, 2024
2 parents c1fda8c + cb270ed commit 16b73c9
Show file tree
Hide file tree
Showing 23 changed files with 376 additions and 505 deletions.
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

0 comments on commit 16b73c9

Please sign in to comment.