From 383183e1a9b6acf31e3e10e7d276167a5ba583dd Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 27 Oct 2023 15:17:51 +0200 Subject: [PATCH 01/13] [DEV] directCapacities --- .../series/include/antares/series/series.h | 1 + src/libs/antares/series/series.cpp | 5 +++++ src/libs/antares/study/area/links.cpp | 19 ++++++++++--------- src/libs/antares/study/area/links.h | 3 ++- .../study/scenario-builder/applyToMatrix.hxx | 4 ++-- src/solver/simulation/common-eco-adq.cpp | 2 +- .../simulation/sim_calcul_economique.cpp | 8 ++++---- src/solver/simulation/timeseries-numbers.cpp | 6 +++--- .../economy/links/congestionProbability.h | 4 ++-- .../action/handler/antares-study/link/ntc.cpp | 2 +- .../datagrid/renderer/connection.cpp | 4 ++-- 11 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/libs/antares/series/include/antares/series/series.h b/src/libs/antares/series/include/antares/series/series.h index 48b7b7e4fd..03018a6f52 100644 --- a/src/libs/antares/series/include/antares/series/series.h +++ b/src/libs/antares/series/include/antares/series/series.h @@ -80,6 +80,7 @@ class TimeSeries void unloadFromMemory() const; void roundAllEntries(); void resize(uint32_t timeSeriesCount, uint32_t timestepCount); + void fill(double value); void averageTimeseries(); bool forceReload(bool reload = false) const; diff --git a/src/libs/antares/series/series.cpp b/src/libs/antares/series/series.cpp index 793ff4c9ff..a7f8d88514 100644 --- a/src/libs/antares/series/series.cpp +++ b/src/libs/antares/series/series.cpp @@ -107,6 +107,11 @@ void TimeSeries::resize(uint32_t timeSeriesCount, uint32_t timestepCount) timeSeries.resize(timeSeriesCount, timestepCount); } +void TimeSeries::fill(double value) +{ + timeSeries.fill(value); +} + void TimeSeries::roundAllEntries() { timeSeries.roundAllEntries(); diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index 678ed9350e..b1e1429052 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -64,7 +64,7 @@ AreaLink::AreaLink() : from(nullptr), with(nullptr), parameters(fhlMax, HOURS_PER_YEAR), - directCapacities(1, HOURS_PER_YEAR), + directCapacities(timeseriesNumbers), indirectCapacities(1, HOURS_PER_YEAR), useLoopFlow(false), usePST(false), @@ -80,6 +80,7 @@ AreaLink::AreaLink() : style(stPlain), linkWidth(1) { + directCapacities.reset(); } AreaLink::~AreaLink() @@ -131,7 +132,7 @@ bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& fol // Read link's direct capacities time series filename.clear() << capacitiesFolder << SEP << with->id << "_direct.txt"; - success = directCapacities.loadFromCSVFile(filename, 1, HOURS_PER_YEAR) && success; + success = directCapacities.timeSeries.loadFromCSVFile(filename, 1, HOURS_PER_YEAR) && success; // Read link's indirect capacities time series filename.clear() << capacitiesFolder << SEP << with->id << "_indirect.txt"; @@ -210,7 +211,7 @@ void AreaLink::detach() void AreaLink::resetToDefaultValues() { parameters.reset(fhlMax, HOURS_PER_YEAR, true); - directCapacities.reset(1, HOURS_PER_YEAR, true); + directCapacities.timeSeries.reset(1, HOURS_PER_YEAR, true); indirectCapacities.reset(1, HOURS_PER_YEAR, true); for (uint i = 0; i != HOURS_PER_YEAR; ++i) @@ -262,7 +263,7 @@ void AreaLink::reverse() indirectCapacities.forceReload(true); // invert NTC values - directCapacities.swap(indirectCapacities); + directCapacities.timeSeries.swap(indirectCapacities); directCapacities.markAsModified(); indirectCapacities.markAsModified(); @@ -482,7 +483,7 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const AnyStr if (study.usedByTheSolver) { // Short names for link's properties - const uint nbDirectTS = link.directCapacities.width; + const uint nbDirectTS = link.directCapacities.timeSeries.width; const uint nbIndirectTS = link.indirectCapacities.width; if (nbDirectTS != nbIndirectTS) { @@ -499,7 +500,7 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const AnyStr for (uint indexTS = 0; indexTS < nbDirectTS; ++indexTS) { - auto& directCapacities = link.directCapacities[indexTS]; + auto* directCapacities = link.directCapacities[indexTS]; auto& indirectCapacities = link.indirectCapacities[indexTS]; // Checks on direct capacities @@ -590,7 +591,7 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const AnyStr case Data::LocalTransmissionCapacities::null: { // Ignore transmission capacities - link.directCapacities.zero(); + link.directCapacities.timeSeries.zero(); link.indirectCapacities.zero(); break; } @@ -636,7 +637,7 @@ bool saveAreaLinksTimeSeriesToFolder(const Area* area, const char* const folder) // Save direct capacities time series filename.clear() << capacitiesFolder << SEP << link.with->id << "_direct.txt"; - success = link.directCapacities.saveToCSVFile(filename, 6, false, true) && success; + success = link.directCapacities.timeSeries.saveToCSVFile(filename, 6, false, true) && success; // Save indirect capacities time series @@ -726,7 +727,7 @@ uint64_t AreaLink::memoryUsage() const { uint64_t to_return = sizeof(AreaLink); to_return += parameters.valuesMemoryUsage(); - to_return += directCapacities.valuesMemoryUsage(); + to_return += directCapacities.memoryUsage(); to_return += indirectCapacities.valuesMemoryUsage(); return to_return; diff --git a/src/libs/antares/study/area/links.h b/src/libs/antares/study/area/links.h index b18d6e28cb..03cef5401f 100644 --- a/src/libs/antares/study/area/links.h +++ b/src/libs/antares/study/area/links.h @@ -32,6 +32,7 @@ #include #include "../fwd.h" #include +#include #include #include @@ -144,7 +145,7 @@ class AreaLink final : public Yuni::NonCopyable ** */ Matrix<> parameters; - Matrix<> directCapacities; + TimeSeries directCapacities; Matrix<> indirectCapacities; //! Monte-Carlo diff --git a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx index 2937c57a76..bb38afddcd 100644 --- a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx +++ b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx @@ -35,8 +35,8 @@ inline bool CheckValidity(uint value, { //Value = index of time series //Direct Capacities = all time series - //directCapacities.width = Number of time series - return value < data.directCapacities.width; + //directCapacities.timeSeries.width = Number of time series + return value < data.directCapacities.timeSeries.width; } template<> diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 4d8f4a1f11..d74727301e 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -72,7 +72,7 @@ static void RecalculDesEchangesMoyens(Data::Study& study, { auto* link = study.runtime->areaLink[j]; int ret = retrieveAverageNTC( - study, link->directCapacities, link->timeseriesNumbers, avgDirect); + study, link->directCapacities.timeSeries, link->timeseriesNumbers, avgDirect); ret = retrieveAverageNTC( study, link->indirectCapacities, link->timeseriesNumbers, avgIndirect) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 14133c06f1..c678a8e8e4 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -562,13 +562,13 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint k = 0; k != linkCount; ++k) { auto& lnk = *(studyruntime.areaLink[k]); - const int tsIndex = (lnk.directCapacities.width != 1) ? lnk.timeseriesNumbers[0][year] : 0; + const int tsIndex = (lnk.directCapacities.timeSeries.width != 1) ? lnk.timeseriesNumbers[0][year] : 0; - assert((uint)hourInYear < lnk.directCapacities.height); - assert((uint)tsIndex < lnk.directCapacities.width); + assert((uint)hourInYear < lnk.directCapacities.timeSeries.height); + assert((uint)tsIndex < lnk.directCapacities.timeSeries.width); assert((uint)tsIndex < lnk.indirectCapacities.width); - ntc.ValeurDeNTCOrigineVersExtremite[k] = lnk.directCapacities[tsIndex][hourInYear]; + ntc.ValeurDeNTCOrigineVersExtremite[k] = lnk.directCapacities.getCoefficient(year, hourInYear); ntc.ValeurDeNTCExtremiteVersOrigine[k] = lnk.indirectCapacities[tsIndex][hourInYear]; ntc.ValeurDeLoopFlowOrigineVersExtremite[k] = lnk.parameters[fhlLoopFlow][hourInYear]; } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index a85da87f83..477c2c47bd 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -249,7 +249,7 @@ class areaLinksTransCapaNumberOfTSretriever : public areaNumberOfTSretriever for (auto it = area.links.begin(); it != area.links.end(); ++it) { const auto& link = *(it->second); - to_return.push_back(link.directCapacities.width); + to_return.push_back(link.directCapacities.timeSeries.width); to_return.push_back(link.indirectCapacities.width); } return to_return; @@ -696,7 +696,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i for (auto it = area.links.begin(); it != area.links.end(); ++it) { auto& link = *(it->second); - const uint nbTimeSeries = link.directCapacities.width; + const uint nbTimeSeries = link.directCapacities.timeSeries.width; if (nbTimeSeries == 1) { // Random generator (mersenne-twister) must not be called here @@ -860,7 +860,7 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) [&years](const std::pair& it) { auto link = it.second; fixTSNumbersSingleAreaSingleMode( - link->timeseriesNumbers, link->directCapacities.width, years); + link->timeseriesNumbers, link->directCapacities.timeSeries.width, years); }); }); study.bindingConstraintsGroups.fixTSNumbersWhenWidthIsOne(); diff --git a/src/solver/variable/economy/links/congestionProbability.h b/src/solver/variable/economy/links/congestionProbability.h index 72f560d7b4..418076a630 100644 --- a/src/solver/variable/economy/links/congestionProbability.h +++ b/src/solver/variable/economy/links/congestionProbability.h @@ -278,10 +278,10 @@ class CongestionProbability assert(state.link != NULL); const auto& linkDirectCapa = state.link->directCapacities; const auto& linkIndirectCapa = state.link->indirectCapacities; - const int tsIndex = (linkDirectCapa.width != 1) ? state.link->timeseriesNumbers[0][state.year] : 0; + const int tsIndex = state.link->directCapacities.getSeriesIndex(state.year); // CONG. PROB + if (state.ntc.ValeurDuFlux[state.link->index] - > +linkDirectCapa.entry[tsIndex][state.hourInTheYear] - 10e-6) + > +linkDirectCapa.getCoefficient(state.year, state.hourInTheYear) - 10e-6) pValuesForTheCurrentYear[numSpace][0].hour[state.hourInTheYear] += 100.0 * ratio; // CONG. PROB - if (state.ntc.ValeurDuFlux[state.link->index] diff --git a/src/ui/action/handler/antares-study/link/ntc.cpp b/src/ui/action/handler/antares-study/link/ntc.cpp index 772f7eae6e..179439b00e 100644 --- a/src/ui/action/handler/antares-study/link/ntc.cpp +++ b/src/ui/action/handler/antares-study/link/ntc.cpp @@ -83,7 +83,7 @@ bool NTC::performWL(Context& ctx) // Direct capacities source->directCapacities.forceReload(true); ctx.link->directCapacities.forceReload(true); - ctx.link->directCapacities.pasteToColumn(0, source->directCapacities.entry[0]); + ctx.link->directCapacities.timeSeries.pasteToColumn(0, source->directCapacities.timeSeries.entry[0]); // Indirect capacities source->indirectCapacities.forceReload(true); diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/connection.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/connection.cpp index e9fc5595d1..50c1e2f4fe 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/connection.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/connection.cpp @@ -228,7 +228,7 @@ void connectionParameters::setMatrix(Data::AreaLink* link) { matrix(link ? &(link->parameters) : nullptr); - direct_ntc_ = link ? &(link->directCapacities) : nullptr; + direct_ntc_ = link ? &(link->directCapacities.timeSeries) : nullptr; indirect_ntc_ = link ? &(link->indirectCapacities) : nullptr; } @@ -274,7 +274,7 @@ connectionNTCdirect::connectionNTCdirect(wxWindow* parent, } void connectionNTCdirect::setMatrix(Data::AreaLink* link) { - matrix(link ? &(link->directCapacities) : nullptr); + matrix(link ? &(link->directCapacities.timeSeries) : nullptr); mLoopFlowData = link ? &(link->parameters[Data::fhlLoopFlow]) : nullptr; } From ebacd2ccf19b2f17e291b9d335d8d5137d09263c Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 27 Oct 2023 17:50:26 +0200 Subject: [PATCH 02/13] [DEV] indirectCapacities --- src/libs/antares/study/area/links.cpp | 19 ++++++++++--------- src/libs/antares/study/area/links.h | 2 +- src/solver/constraints-builder/cbuilder.cpp | 2 +- src/solver/simulation/common-eco-adq.cpp | 2 +- .../simulation/sim_calcul_economique.cpp | 6 +----- src/solver/simulation/timeseries-numbers.cpp | 2 +- .../economy/links/congestionProbability.h | 3 +-- .../action/handler/antares-study/link/ntc.cpp | 2 +- .../datagrid/renderer/connection.cpp | 4 ++-- 9 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index b1e1429052..87bd9134af 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -65,7 +65,7 @@ AreaLink::AreaLink() : with(nullptr), parameters(fhlMax, HOURS_PER_YEAR), directCapacities(timeseriesNumbers), - indirectCapacities(1, HOURS_PER_YEAR), + indirectCapacities(timeseriesNumbers), useLoopFlow(false), usePST(false), useHurdlesCost(false), @@ -81,6 +81,7 @@ AreaLink::AreaLink() : linkWidth(1) { directCapacities.reset(); + indirectCapacities.reset(); } AreaLink::~AreaLink() @@ -136,7 +137,7 @@ bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& fol // Read link's indirect capacities time series filename.clear() << capacitiesFolder << SEP << with->id << "_indirect.txt"; - success = indirectCapacities.loadFromCSVFile(filename, 1, HOURS_PER_YEAR) && success; + success = indirectCapacities.timeSeries.loadFromCSVFile(filename, 1, HOURS_PER_YEAR) && success; return success; } @@ -212,7 +213,7 @@ void AreaLink::resetToDefaultValues() { parameters.reset(fhlMax, HOURS_PER_YEAR, true); directCapacities.timeSeries.reset(1, HOURS_PER_YEAR, true); - indirectCapacities.reset(1, HOURS_PER_YEAR, true); + indirectCapacities.timeSeries.reset(1, HOURS_PER_YEAR, true); for (uint i = 0; i != HOURS_PER_YEAR; ++i) { @@ -263,7 +264,7 @@ void AreaLink::reverse() indirectCapacities.forceReload(true); // invert NTC values - directCapacities.timeSeries.swap(indirectCapacities); + directCapacities.timeSeries.swap(indirectCapacities.timeSeries); directCapacities.markAsModified(); indirectCapacities.markAsModified(); @@ -484,7 +485,7 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const AnyStr { // Short names for link's properties const uint nbDirectTS = link.directCapacities.timeSeries.width; - const uint nbIndirectTS = link.indirectCapacities.width; + const uint nbIndirectTS = link.indirectCapacities.timeSeries.width; if (nbDirectTS != nbIndirectTS) { logLinkDataCheckErrorDirectIndirect( @@ -501,7 +502,7 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const AnyStr for (uint indexTS = 0; indexTS < nbDirectTS; ++indexTS) { auto* directCapacities = link.directCapacities[indexTS]; - auto& indirectCapacities = link.indirectCapacities[indexTS]; + auto* indirectCapacities = link.indirectCapacities[indexTS]; // Checks on direct capacities for (int h = 0; h < HOURS_PER_YEAR; h++) @@ -592,7 +593,7 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const AnyStr { // Ignore transmission capacities link.directCapacities.timeSeries.zero(); - link.indirectCapacities.zero(); + link.indirectCapacities.timeSeries.zero(); break; } case Data::LocalTransmissionCapacities::infinite: @@ -642,7 +643,7 @@ bool saveAreaLinksTimeSeriesToFolder(const Area* area, const char* const folder) // Save indirect capacities time series filename.clear() << capacitiesFolder << SEP << link.with->id << "_indirect.txt"; - success = link.indirectCapacities.saveToCSVFile(filename, 6, false, true) && success; + success = link.indirectCapacities.timeSeries.saveToCSVFile(filename, 6, false, true) && success; } return success; @@ -728,7 +729,7 @@ uint64_t AreaLink::memoryUsage() const uint64_t to_return = sizeof(AreaLink); to_return += parameters.valuesMemoryUsage(); to_return += directCapacities.memoryUsage(); - to_return += indirectCapacities.valuesMemoryUsage(); + to_return += indirectCapacities.memoryUsage(); return to_return; } diff --git a/src/libs/antares/study/area/links.h b/src/libs/antares/study/area/links.h index 03cef5401f..b5d9559bcf 100644 --- a/src/libs/antares/study/area/links.h +++ b/src/libs/antares/study/area/links.h @@ -146,7 +146,7 @@ class AreaLink final : public Yuni::NonCopyable */ Matrix<> parameters; TimeSeries directCapacities; - Matrix<> indirectCapacities; + TimeSeries indirectCapacities; //! Monte-Carlo Matrix timeseriesNumbers; diff --git a/src/solver/constraints-builder/cbuilder.cpp b/src/solver/constraints-builder/cbuilder.cpp index eebca2d015..0756022618 100644 --- a/src/solver/constraints-builder/cbuilder.cpp +++ b/src/solver/constraints-builder/cbuilder.cpp @@ -84,7 +84,7 @@ bool CBuilder::checkValidityOfNodalLoopFlow(linkInfo* linkInfo, size_t hour) { Data::AreaLink* link = linkInfo->ptr; - for (uint tsIndex = 0; tsIndex < link->indirectCapacities.width; ++tsIndex) + for (uint tsIndex = 0; tsIndex < link->indirectCapacities.timeSeries.width; ++tsIndex) { if ((-1.0 * link->indirectCapacities[tsIndex][hour] > link->parameters[Data::fhlLoopFlow][hour]) diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index d74727301e..c550b05610 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -75,7 +75,7 @@ static void RecalculDesEchangesMoyens(Data::Study& study, study, link->directCapacities.timeSeries, link->timeseriesNumbers, avgDirect); ret = retrieveAverageNTC( - study, link->indirectCapacities, link->timeseriesNumbers, avgIndirect) + study, link->indirectCapacities.timeSeries, link->timeseriesNumbers, avgIndirect) && ret; if (!ret) { diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index c678a8e8e4..f41f12ce47 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -562,14 +562,10 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint k = 0; k != linkCount; ++k) { auto& lnk = *(studyruntime.areaLink[k]); - const int tsIndex = (lnk.directCapacities.timeSeries.width != 1) ? lnk.timeseriesNumbers[0][year] : 0; - assert((uint)hourInYear < lnk.directCapacities.timeSeries.height); - assert((uint)tsIndex < lnk.directCapacities.timeSeries.width); - assert((uint)tsIndex < lnk.indirectCapacities.width); ntc.ValeurDeNTCOrigineVersExtremite[k] = lnk.directCapacities.getCoefficient(year, hourInYear); - ntc.ValeurDeNTCExtremiteVersOrigine[k] = lnk.indirectCapacities[tsIndex][hourInYear]; + ntc.ValeurDeNTCExtremiteVersOrigine[k] = lnk.indirectCapacities.getCoefficient(year, hourInYear); ntc.ValeurDeLoopFlowOrigineVersExtremite[k] = lnk.parameters[fhlLoopFlow][hourInYear]; } } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 477c2c47bd..d3cd402ee9 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -250,7 +250,7 @@ class areaLinksTransCapaNumberOfTSretriever : public areaNumberOfTSretriever { const auto& link = *(it->second); to_return.push_back(link.directCapacities.timeSeries.width); - to_return.push_back(link.indirectCapacities.width); + to_return.push_back(link.indirectCapacities.timeSeries.width); } return to_return; } diff --git a/src/solver/variable/economy/links/congestionProbability.h b/src/solver/variable/economy/links/congestionProbability.h index 418076a630..ba4e6739db 100644 --- a/src/solver/variable/economy/links/congestionProbability.h +++ b/src/solver/variable/economy/links/congestionProbability.h @@ -278,14 +278,13 @@ class CongestionProbability assert(state.link != NULL); const auto& linkDirectCapa = state.link->directCapacities; const auto& linkIndirectCapa = state.link->indirectCapacities; - const int tsIndex = state.link->directCapacities.getSeriesIndex(state.year); // CONG. PROB + if (state.ntc.ValeurDuFlux[state.link->index] > +linkDirectCapa.getCoefficient(state.year, state.hourInTheYear) - 10e-6) pValuesForTheCurrentYear[numSpace][0].hour[state.hourInTheYear] += 100.0 * ratio; // CONG. PROB - if (state.ntc.ValeurDuFlux[state.link->index] - < -linkIndirectCapa.entry[tsIndex][state.hourInTheYear] + 10e-6) + < -linkIndirectCapa.getSeriesIndex(state.year) + 10e-6) pValuesForTheCurrentYear[numSpace][1].hour[state.hourInTheYear] += 100.0 * ratio; // Next item in the list diff --git a/src/ui/action/handler/antares-study/link/ntc.cpp b/src/ui/action/handler/antares-study/link/ntc.cpp index 179439b00e..5ee674d71b 100644 --- a/src/ui/action/handler/antares-study/link/ntc.cpp +++ b/src/ui/action/handler/antares-study/link/ntc.cpp @@ -88,7 +88,7 @@ bool NTC::performWL(Context& ctx) // Indirect capacities source->indirectCapacities.forceReload(true); ctx.link->indirectCapacities.forceReload(true); - ctx.link->indirectCapacities.pasteToColumn(0, source->indirectCapacities.entry[0]); + ctx.link->indirectCapacities.timeSeries.pasteToColumn(0, source->indirectCapacities.timeSeries.entry[0]); return true; } else diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/connection.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/connection.cpp index 50c1e2f4fe..e18885e28d 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/connection.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/connection.cpp @@ -229,7 +229,7 @@ void connectionParameters::setMatrix(Data::AreaLink* link) matrix(link ? &(link->parameters) : nullptr); direct_ntc_ = link ? &(link->directCapacities.timeSeries) : nullptr; - indirect_ntc_ = link ? &(link->indirectCapacities) : nullptr; + indirect_ntc_ = link ? &(link->indirectCapacities.timeSeries) : nullptr; } // =========================== @@ -294,7 +294,7 @@ connectionNTCindirect::connectionNTCindirect(wxWindow* parent, } void connectionNTCindirect::setMatrix(Data::AreaLink* link) { - matrix(link ? &(link->indirectCapacities) : nullptr); + matrix(link ? &(link->indirectCapacities.timeSeries) : nullptr); mLoopFlowData = link ? &(link->parameters[Data::fhlLoopFlow]) : nullptr; } From 0cbb4290af06afe5072b6a59423d91a5258b9d7c Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 30 Oct 2023 11:05:53 +0100 Subject: [PATCH 03/13] [FIX} Results --- src/solver/variable/economy/links/congestionProbability.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/variable/economy/links/congestionProbability.h b/src/solver/variable/economy/links/congestionProbability.h index ba4e6739db..69b8bb97eb 100644 --- a/src/solver/variable/economy/links/congestionProbability.h +++ b/src/solver/variable/economy/links/congestionProbability.h @@ -284,7 +284,7 @@ class CongestionProbability pValuesForTheCurrentYear[numSpace][0].hour[state.hourInTheYear] += 100.0 * ratio; // CONG. PROB - if (state.ntc.ValeurDuFlux[state.link->index] - < -linkIndirectCapa.getSeriesIndex(state.year) + 10e-6) + < -linkIndirectCapa.getCoefficient(state.year, state.hourInTheYear) + 10e-6) pValuesForTheCurrentYear[numSpace][1].hour[state.hourInTheYear] += 100.0 * ratio; // Next item in the list From e1ca0591e388ee5484d612b5ad9f7c9848b9d8da Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 30 Oct 2023 11:46:27 +0100 Subject: [PATCH 04/13] [DEV] code smell --- src/libs/antares/series/include/antares/series/series.h | 2 +- src/libs/antares/series/series.cpp | 4 ++-- src/libs/antares/study/area/links.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/antares/series/include/antares/series/series.h b/src/libs/antares/series/include/antares/series/series.h index 03018a6f52..14649b8c2d 100644 --- a/src/libs/antares/series/include/antares/series/series.h +++ b/src/libs/antares/series/include/antares/series/series.h @@ -90,7 +90,7 @@ class TimeSeries TS timeSeries; numbers& timeseriesNumbers; - static const double emptyColumn[HOURS_PER_YEAR]; + static const std::vector emptyColumn; }; } // namespace Antares::Data diff --git a/src/libs/antares/series/series.cpp b/src/libs/antares/series/series.cpp index a7f8d88514..a86ba14a4c 100644 --- a/src/libs/antares/series/series.cpp +++ b/src/libs/antares/series/series.cpp @@ -38,7 +38,7 @@ using namespace Yuni; namespace Antares::Data { -const double TimeSeries::emptyColumn[] = {0}; +const std::vector TimeSeries::emptyColumn(HOURS_PER_YEAR); TimeSeries::TimeSeries(numbers& tsNumbers) : timeseriesNumbers(tsNumbers) {} @@ -78,7 +78,7 @@ double TimeSeries::getCoefficient(uint32_t year, uint32_t timestep) const const double* TimeSeries::getColumn(uint32_t year) const { if (timeSeries.width == 0) - return emptyColumn; + return emptyColumn.data(); return timeSeries[getSeriesIndex(year)]; } diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index 87bd9134af..2bb9090cb7 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -501,8 +501,8 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const AnyStr for (uint indexTS = 0; indexTS < nbDirectTS; ++indexTS) { - auto* directCapacities = link.directCapacities[indexTS]; - auto* indirectCapacities = link.indirectCapacities[indexTS]; + const double* directCapacities = link.directCapacities[indexTS]; + const double* indirectCapacities = link.indirectCapacities[indexTS]; // Checks on direct capacities for (int h = 0; h < HOURS_PER_YEAR; h++) From 261e353fa5ea2f893043ce0fc286967dfbcc1931 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 31 Oct 2023 10:36:21 +0100 Subject: [PATCH 05/13] [DOC] Add doxygen comments --- .../series/include/antares/series/series.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/antares/series/include/antares/series/series.h b/src/libs/antares/series/include/antares/series/series.h index 14649b8c2d..1a015df204 100644 --- a/src/libs/antares/series/include/antares/series/series.h +++ b/src/libs/antares/series/include/antares/series/series.h @@ -31,16 +31,15 @@ namespace Antares::Data { +/*! + ** \brief This class is used to represent the generic time series + ** + ** The goal is to handle indexing with the time series numbers: getCoefficient() + ** and also providing a wrapper for all the Matrix<> functions such as resize() + */ class TimeSeries { - /*! - ** \brief This class is used to represent the generic time series - ** - ** The goal is to handle indexing with the time series numbers: getCoefficient() - ** and also providing a wrapper for all the Matrix<> functions such as resize() - */ - public: using numbers = Matrix; using TS = Matrix; @@ -59,7 +58,6 @@ class TimeSeries const bool average); /*! ** \brief Save time series to a file - ** \ingroup windseries ** ** \param areaID The ID of the area associated to the data series ** \param folder The target folder @@ -74,6 +72,8 @@ class TimeSeries const double* getColumn(uint32_t year) const; uint32_t getSeriesIndex(uint32_t year) const; + /// \brief overload operator to return a column + /// Unlike getColumn() it doesn't use timeseriesNumbers double* operator[](uint32_t index); void reset(); @@ -90,7 +90,7 @@ class TimeSeries TS timeSeries; numbers& timeseriesNumbers; - static const std::vector emptyColumn; + static const std::vector emptyColumn; ///< used in getColumn if timeSeries empty }; } // namespace Antares::Data From 1ebf14a87f2e9b68759cf8ec1ad991b4ecb48f88 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 2 Nov 2023 13:51:03 +0100 Subject: [PATCH 06/13] [DEV] Remove useless assert --- src/solver/simulation/sim_calcul_economique.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index f41f12ce47..e6b7d52099 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -562,7 +562,6 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint k = 0; k != linkCount; ++k) { auto& lnk = *(studyruntime.areaLink[k]); - assert((uint)hourInYear < lnk.directCapacities.timeSeries.height); ntc.ValeurDeNTCOrigineVersExtremite[k] = lnk.directCapacities.getCoefficient(year, hourInYear); ntc.ValeurDeNTCExtremiteVersOrigine[k] = lnk.indirectCapacities.getCoefficient(year, hourInYear); From 9912a0da96bfbc6dc534ddc4252c7e75ccd8071d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 3 Nov 2023 12:39:45 +0100 Subject: [PATCH 07/13] [DEV] Use loadFromFile, remove databuffer arg --- src/libs/antares/series/include/antares/series/series.h | 2 -- src/libs/antares/series/series.cpp | 2 +- src/libs/antares/study/area/links.cpp | 4 ++-- src/libs/antares/study/area/list.cpp | 6 +++--- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libs/antares/series/include/antares/series/series.h b/src/libs/antares/series/include/antares/series/series.h index 1a015df204..464323645a 100644 --- a/src/libs/antares/series/include/antares/series/series.h +++ b/src/libs/antares/series/include/antares/series/series.h @@ -49,12 +49,10 @@ class TimeSeries ** \brief Load series from a file ** ** \param path path of the file - ** \param dataBuffer yuni dependency to use loadFromCSV ** \param average used to average timeseries ** \return A non-zero value if the operation succeeded, 0 otherwise */ bool loadFromFile(const std::string& path, - Matrix<>::BufferType dataBuffer, const bool average); /*! ** \brief Save time series to a file diff --git a/src/libs/antares/series/series.cpp b/src/libs/antares/series/series.cpp index a86ba14a4c..fffac58607 100644 --- a/src/libs/antares/series/series.cpp +++ b/src/libs/antares/series/series.cpp @@ -44,10 +44,10 @@ TimeSeries::TimeSeries(numbers& tsNumbers) : timeseriesNumbers(tsNumbers) {} bool TimeSeries::loadFromFile(const std::string& path, - Matrix<>::BufferType dataBuffer, const bool average) { bool ret = true; + Matrix<>::BufferType dataBuffer; ret = timeSeries.loadFromCSVFile(path, 1, HOURS_PER_YEAR, &dataBuffer) && ret; if (average) diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index 2bb9090cb7..e33b6dd4c0 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -133,11 +133,11 @@ bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& fol // Read link's direct capacities time series filename.clear() << capacitiesFolder << SEP << with->id << "_direct.txt"; - success = directCapacities.timeSeries.loadFromCSVFile(filename, 1, HOURS_PER_YEAR) && success; + success = directCapacities.loadFromFile(filename, false) && success; // Read link's indirect capacities time series filename.clear() << capacitiesFolder << SEP << with->id << "_indirect.txt"; - success = indirectCapacities.timeSeries.loadFromCSVFile(filename, 1, HOURS_PER_YEAR) && success; + success = directCapacities.loadFromFile(filename, false) && success; return success; } diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 5ce8975540..9e6a324e26 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -854,7 +854,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, { buffer.clear() << study.folderInput << SEP << "load" << SEP << "series" << SEP << "load_" << area.id << ".txt"; - ret = area.load.series.loadFromFile(buffer.c_str(), study.dataBuffer, averageTs) + ret = area.load.series.loadFromFile(buffer.c_str(), averageTs) && ret; } @@ -875,7 +875,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, { buffer.clear() << study.folderInput << SEP << "solar" << SEP << "series" << SEP << "solar_" << area.id << ".txt"; - ret = area.solar.series.loadFromFile(buffer.c_str(), study.dataBuffer, averageTs) + ret = area.solar.series.loadFromFile(buffer.c_str(), averageTs) && ret; } @@ -920,7 +920,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, { buffer.clear() << study.folderInput << SEP << "wind" << SEP << "series" << SEP << "wind_" << area.id << ".txt"; - ret = area.wind.series.loadFromFile(buffer.c_str(), study.dataBuffer, averageTs) + ret = area.wind.series.loadFromFile(buffer.c_str(), averageTs) && ret; } From 1f453f111f76b4b0bf9e41042352eba8e99c9e57 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 3 Nov 2023 15:15:41 +0100 Subject: [PATCH 08/13] [FIX] typo --- src/libs/antares/study/area/links.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index e33b6dd4c0..8575f5ad23 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -137,7 +137,7 @@ bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& fol // Read link's indirect capacities time series filename.clear() << capacitiesFolder << SEP << with->id << "_indirect.txt"; - success = directCapacities.loadFromFile(filename, false) && success; + success = indirectCapacities.loadFromFile(filename, false) && success; return success; } From 951bbcf870c18eaf52ce0b25cc2fd8435febd59a Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 6 Nov 2023 10:22:42 +0100 Subject: [PATCH 09/13] [DEV] Add saveToFile function --- src/libs/antares/series/include/antares/series/series.h | 2 ++ src/libs/antares/series/series.cpp | 4 ++++ src/libs/antares/study/area/links.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libs/antares/series/include/antares/series/series.h b/src/libs/antares/series/include/antares/series/series.h index 464323645a..e80818445a 100644 --- a/src/libs/antares/series/include/antares/series/series.h +++ b/src/libs/antares/series/include/antares/series/series.h @@ -66,6 +66,8 @@ class TimeSeries const std::string& folder, const std::string& prefix) const; + int saveToFile(const std::string& filename, bool saveEvenIfAllZero) const; + double getCoefficient(uint32_t year, uint32_t timestep) const; const double* getColumn(uint32_t year) const; uint32_t getSeriesIndex(uint32_t year) const; diff --git a/src/libs/antares/series/series.cpp b/src/libs/antares/series/series.cpp index fffac58607..8a896e5902 100644 --- a/src/libs/antares/series/series.cpp +++ b/src/libs/antares/series/series.cpp @@ -67,6 +67,10 @@ int TimeSeries::saveToFolder(const AreaName& areaID, return timeSeries.saveToCSVFile(buffer, 0); } +int TimeSeries::saveToFile(const std::string& filename, bool saveEvenIfAllZero) const +{ + return timeSeries.saveToCSVFile(filename, 6, false, saveEvenIfAllZero); +} double TimeSeries::getCoefficient(uint32_t year, uint32_t timestep) const { diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index 8575f5ad23..7f5bf68dab 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -212,8 +212,8 @@ void AreaLink::detach() void AreaLink::resetToDefaultValues() { parameters.reset(fhlMax, HOURS_PER_YEAR, true); - directCapacities.timeSeries.reset(1, HOURS_PER_YEAR, true); - indirectCapacities.timeSeries.reset(1, HOURS_PER_YEAR, true); + directCapacities.reset(); + indirectCapacities.reset(); for (uint i = 0; i != HOURS_PER_YEAR; ++i) { @@ -638,12 +638,12 @@ bool saveAreaLinksTimeSeriesToFolder(const Area* area, const char* const folder) // Save direct capacities time series filename.clear() << capacitiesFolder << SEP << link.with->id << "_direct.txt"; - success = link.directCapacities.timeSeries.saveToCSVFile(filename, 6, false, true) && success; + success = link.directCapacities.saveToFile(filename, true) && success; // Save indirect capacities time series filename.clear() << capacitiesFolder << SEP << link.with->id << "_indirect.txt"; - success = link.indirectCapacities.timeSeries.saveToCSVFile(filename, 6, false, true) && success; + success = link.indirectCapacities.saveToFile(filename, true) && success; } return success; From f8883213ce943b8c5683d464bbaebb31734f778a Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 6 Nov 2023 17:23:30 +0100 Subject: [PATCH 10/13] [DOC] Add class to doxygen --- src/libs/antares/series/include/antares/series/series.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/series/include/antares/series/series.h b/src/libs/antares/series/include/antares/series/series.h index e80818445a..72caabaee8 100644 --- a/src/libs/antares/series/include/antares/series/series.h +++ b/src/libs/antares/series/include/antares/series/series.h @@ -32,12 +32,12 @@ namespace Antares::Data { /*! + ** \class TimeSeries ** \brief This class is used to represent the generic time series ** ** The goal is to handle indexing with the time series numbers: getCoefficient() ** and also providing a wrapper for all the Matrix<> functions such as resize() */ - class TimeSeries { public: From 479b87279f901a761df024cc90f53f2acf1240db Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 7 Nov 2023 10:24:15 +0100 Subject: [PATCH 11/13] [DOC] Small fix --- src/libs/antares/series/include/antares/series/series.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/series/include/antares/series/series.h b/src/libs/antares/series/include/antares/series/series.h index 72caabaee8..4442254a9b 100644 --- a/src/libs/antares/series/include/antares/series/series.h +++ b/src/libs/antares/series/include/antares/series/series.h @@ -73,7 +73,7 @@ class TimeSeries uint32_t getSeriesIndex(uint32_t year) const; /// \brief overload operator to return a column - /// Unlike getColumn() it doesn't use timeseriesNumbers + /// Unlike getColumn() it uses direct indexing and not timeseriesNumbers double* operator[](uint32_t index); void reset(); From 9f8be1f1aca40547e6a0b518619ba85465b7c205 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 15 Nov 2023 15:15:23 +0100 Subject: [PATCH 12/13] [DEV] Use getcolumn --- .../simulation/sim_calcul_economique.cpp | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index e6b7d52099..be4f67e0fb 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -554,20 +554,26 @@ void SIM_RenseignementProblemeHebdo(const Study& study, int hourInYear = PasDeTempsDebut; unsigned int year = problem.year; - for (unsigned hourInWeek = 0; hourInWeek < problem.NombreDePasDeTemps; ++hourInWeek, ++hourInYear) + uint linkCount = studyruntime.interconnectionsCount(); + for (uint k = 0; k != linkCount; ++k) { - VALEURS_DE_NTC_ET_RESISTANCES& ntc = problem.ValeursDeNTC[hourInWeek]; + auto& lnk = *(studyruntime.areaLink[k]); + const double* directCapacities = lnk.directCapacities.getColumn(year); + const double* indirectCapacities = lnk.indirectCapacities.getColumn(year); + for (unsigned hourInWeek = 0; hourInWeek < problem.NombreDePasDeTemps; ++hourInWeek, ++hourInYear) { - uint linkCount = studyruntime.interconnectionsCount(); - for (uint k = 0; k != linkCount; ++k) - { - auto& lnk = *(studyruntime.areaLink[k]); + VALEURS_DE_NTC_ET_RESISTANCES& ntc = problem.ValeursDeNTC[hourInWeek]; - ntc.ValeurDeNTCOrigineVersExtremite[k] = lnk.directCapacities.getCoefficient(year, hourInYear); - ntc.ValeurDeNTCExtremiteVersOrigine[k] = lnk.indirectCapacities.getCoefficient(year, hourInYear); - ntc.ValeurDeLoopFlowOrigineVersExtremite[k] = lnk.parameters[fhlLoopFlow][hourInYear]; - } + ntc.ValeurDeNTCOrigineVersExtremite[k] = directCapacities[hourInYear]; + ntc.ValeurDeNTCExtremiteVersOrigine[k] = indirectCapacities[hourInYear]; + ntc.ValeurDeLoopFlowOrigineVersExtremite[k] = lnk.parameters[fhlLoopFlow][hourInYear]; } + } + + hourInYear = PasDeTempsDebut; + for (unsigned hourInWeek = 0; hourInWeek < problem.NombreDePasDeTemps; ++hourInWeek, ++hourInYear) + { + preparerBindingConstraint(problem, PasDeTempsDebut, study.bindingConstraints, study.bindingConstraintsGroups, weekFirstDay, hourInWeek); From 7f2874eb21900a16a1eea54bb5540590238cf16e Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 15 Nov 2023 15:58:01 +0100 Subject: [PATCH 13/13] [FIX] hourInYear --- src/solver/simulation/sim_calcul_economique.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index be4f67e0fb..080acb109e 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -551,12 +551,12 @@ void SIM_RenseignementProblemeHebdo(const Study& study, } } - int hourInYear = PasDeTempsDebut; unsigned int year = problem.year; uint linkCount = studyruntime.interconnectionsCount(); for (uint k = 0; k != linkCount; ++k) { + int hourInYear = PasDeTempsDebut; auto& lnk = *(studyruntime.areaLink[k]); const double* directCapacities = lnk.directCapacities.getColumn(year); const double* indirectCapacities = lnk.indirectCapacities.getColumn(year); @@ -570,7 +570,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, } } - hourInYear = PasDeTempsDebut; + int hourInYear = PasDeTempsDebut; for (unsigned hourInWeek = 0; hourInWeek < problem.NombreDePasDeTemps; ++hourInWeek, ++hourInYear) {