From 29e115c7625bb6ff3ff1417174855e2f11bb12b2 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zaher <32519851+a-zakir@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:53:01 +0200 Subject: [PATCH 01/10] clean code (#2190) --- src/solver/optimisation/CMakeLists.txt | 1 - .../solver/optimisation/opt_fonctions.h | 5 -- ...ruction_matrice_des_contraintes_outils.cpp | 53 ------------------- 3 files changed, 59 deletions(-) delete mode 100644 src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index 2e3f257932..cbf8f33fc3 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -20,7 +20,6 @@ set(RTESOLVER_OPT opt_construction_variables_optimisees_quadratique.cpp opt_decompte_variables_et_contraintes.cpp opt_decompte_variables_et_contraintes.cpp - opt_construction_matrice_des_contraintes_outils.cpp opt_gestion_des_bornes_cas_lineaire.cpp opt_verification_presence_reserve_jmoins1.cpp opt_init_contraintes_hydrauliques.cpp diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h index 8aad20d799..9d13015286 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h @@ -94,11 +94,6 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO*); void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO*); double OPT_CalculerAireMaxPminJour(int, int, int, int, std::vector&, std::vector&); -void OPT_ChargerLaContrainteDansLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOUDRE*, - std::vector&, - std::vector&, - int, - char); void OPT_ChainagesDesIntercoPartantDUnNoeud(PROBLEME_HEBDO*); void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, diff --git a/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp b/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp deleted file mode 100644 index 80ef6f809c..0000000000 --- a/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp +++ /dev/null @@ -1,53 +0,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 . -*/ - -#include "antares/solver/optimisation/opt_fonctions.h" -#include "antares/solver/optimisation/opt_structure_probleme_a_resoudre.h" -#include "antares/solver/simulation/sim_structure_donnees.h" - -void OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, - std::vector& Pi, - std::vector& Colonne, - int NombreDeTermesDeLaContrainte, - char SensContrainte) -{ - int& nombreDeTermes = ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes; - int& nombreDeContraintes = ProblemeAResoudre->NombreDeContraintes; - - ProblemeAResoudre->IndicesDebutDeLigne[nombreDeContraintes] = nombreDeTermes; - for (int i = 0; i < NombreDeTermesDeLaContrainte; i++) - { - ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes[nombreDeTermes] = Pi[i]; - ProblemeAResoudre->IndicesColonnes[nombreDeTermes] = Colonne[i]; - nombreDeTermes++; - if (nombreDeTermes == ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes) - { - OPT_AugmenterLaTailleDeLaMatriceDesContraintes(ProblemeAResoudre); - } - } - ProblemeAResoudre->NombreDeTermesDesLignes[nombreDeContraintes] = NombreDeTermesDeLaContrainte; - - ProblemeAResoudre->Sens[nombreDeContraintes] = SensContrainte; - nombreDeContraintes++; - - return; -} From 56d0f0aa8031e4b8f814eefab9f7ffbec3c102be Mon Sep 17 00:00:00 2001 From: Abdoulbari Zaher <32519851+a-zakir@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:57:47 +0200 Subject: [PATCH 02/10] =?UTF-8?q?rm=20undefined=20OPT=5FFreeOptimizationDa?= =?UTF-8?q?ta(PROBLEME=5FANTARES=5FA=5FRESOUDRE*=20Pr=E2=80=A6=20(#2191)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …oblemeAResoudre); --- .../include/antares/solver/optimisation/opt_fonctions.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h index 9d13015286..1a52f7e331 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h @@ -98,7 +98,6 @@ void OPT_ChainagesDesIntercoPartantDUnNoeud(PROBLEME_HEBDO*); void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, int); -void OPT_FreeOptimizationData(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre); void OPT_AllocDuProblemeAOptimiser(PROBLEME_HEBDO*); int OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO*); void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOUDRE*); From b6c0185be6d3ac78356ea29c8cbf918aff12b999 Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:45:45 +0200 Subject: [PATCH 03/10] Separation of loading and validation for header [ANT-1213] (#2179) --- src/libs/antares/study/header.cpp | 13 ++----------- .../antares/study/include/antares/study/header.h | 4 ++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/libs/antares/study/header.cpp b/src/libs/antares/study/header.cpp index 4b751d75c7..ae44e94ad5 100644 --- a/src/libs/antares/study/header.cpp +++ b/src/libs/antares/study/header.cpp @@ -166,18 +166,8 @@ bool StudyHeader::internalLoadFromINIFile(const IniFile& ini, bool warnings) } } - if (version >= StudyVersion(7, 0)) + if (version.isSupported(true)) { - if (version > Data::StudyVersion::latest()) - { - if (warnings) - { - logs.error() << "Header: This version is not supported (version found:" - << version.toString() - << ", expected: <=" << Data::StudyVersion::latest().toString() << ')'; - } - return false; - } return true; } @@ -185,6 +175,7 @@ bool StudyHeader::internalLoadFromINIFile(const IniFile& ini, bool warnings) { logs.error() << "Study header: Invalid format"; } + return false; } diff --git a/src/libs/antares/study/include/antares/study/header.h b/src/libs/antares/study/include/antares/study/header.h index ec513143ec..aea7e0f35c 100644 --- a/src/libs/antares/study/include/antares/study/header.h +++ b/src/libs/antares/study/include/antares/study/header.h @@ -55,7 +55,6 @@ class StudyHeader final */ static bool readVersionFromFile(const std::filesystem::path& filename, std::string& version); -public: //! \name Constructor & Destructor //@{ /*! @@ -109,7 +108,8 @@ class StudyHeader final */ static StudyVersion tryToFindTheVersion(const std::string& folder); -public: + bool validateVersion(); + //! Caption of the study Yuni::String caption; From 3ca9107d14a94f4d898c0df2acea9e049870bde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Wed, 26 Jun 2024 11:19:28 +0200 Subject: [PATCH 04/10] Check formatting as part of the CI (#2193) Succeed if all source files are well formated. Fail otherwise, and display ill-formatted files. --------- Co-authored-by: Abdoulbari Zaher <32519851+a-zakir@users.noreply.github.com> --- .github/workflows/clang-format.yml | 36 + .../antlr-interface/ExprBaseVisitor.cpp | 3 - .../antares/antlr-interface/ExprBaseVisitor.h | 144 +- .../antares/antlr-interface/ExprLexer.cpp | 323 ++-- src/libs/antares/antlr-interface/ExprLexer.h | 67 +- .../antares/antlr-interface/ExprParser.cpp | 1590 ++++++++++------- src/libs/antares/antlr-interface/ExprParser.h | 392 ++-- .../antares/antlr-interface/ExprVisitor.cpp | 3 - .../antares/antlr-interface/ExprVisitor.h | 48 +- .../antares/checks/checkLoadedInputData.h | 1 - .../antares/exception/LoadingError.hpp | 7 +- .../FileTreeStudyLoader.h | 1 + .../include/antares/inifile/inifile.hxx | 3 +- src/libs/antares/inifile/inifile.cpp | 12 +- src/libs/antares/io/file.cpp | 2 +- src/libs/antares/io/include/antares/io/file.h | 4 +- .../antares/study-loader/IStudyLoader.h | 1 + src/libs/antares/study/area/area.cpp | 7 +- src/libs/antares/study/area/links.cpp | 27 +- src/libs/antares/study/area/list.cpp | 21 +- .../BindingConstraintGroupRepository.cpp | 18 +- .../antares/study/cleaner/cleaner-v20.cpp | 1 - .../study/include/antares/study/parameters.h | 3 +- .../antares/study/parts/hydro/container.h | 5 +- .../study/scenario-builder/hydroLevelsData.h | 3 +- .../study/include/antares/study/sets.hxx | 4 +- src/libs/antares/study/parameters.cpp | 17 +- .../study/parts/common/cluster_list.cpp | 5 +- .../antares/study/parts/hydro/allocation.cpp | 32 +- .../antares/study/parts/hydro/container.cpp | 256 +-- .../study/parts/hydro/finalLevelValidator.cpp | 46 +- src/libs/antares/study/parts/hydro/prepro.cpp | 8 +- src/libs/antares/study/parts/hydro/series.cpp | 2 +- .../study/parts/renewable/cluster_list.cpp | 2 +- .../parts/short-term-storage/container.cpp | 24 +- .../study/parts/thermal/cluster_list.cpp | 45 +- src/libs/antares/study/runtime/runtime.cpp | 6 +- .../BindingConstraintsTSNumbersData.cpp | 10 +- .../scenario-builder/hydroLevelsData.cpp | 6 +- .../antares/study/scenario-builder/rules.cpp | 5 +- src/libs/antares/study/study.cpp | 21 +- src/libs/antares/study/study.importprepro.cpp | 10 +- src/libs/antares/study/xcast/xcast.cpp | 3 +- src/libs/antares/writer/in_memory_writer.cpp | 2 +- src/libs/antares/writer/zip_writer.cpp | 1 - src/solver/application/application.cpp | 6 +- src/solver/constraints-builder/cbuilder.cpp | 3 +- .../solver/hydro/management/management.h | 3 +- src/solver/hydro/management/daily.cpp | 6 +- src/solver/hydro/management/management.cpp | 38 +- src/solver/hydro/management/monthly.cpp | 30 +- .../include/antares/solver/misc/options.h | 2 +- src/solver/misc/options.cpp | 2 +- src/solver/simulation/adequacy.cpp | 5 +- src/solver/simulation/common-eco-adq.cpp | 22 +- src/solver/simulation/common-hydro-levels.cpp | 22 +- src/solver/simulation/common-hydro-remix.cpp | 3 +- src/solver/simulation/economy.cpp | 5 +- .../hydro-final-reservoir-level-functions.cpp | 62 +- .../antares/solver/simulation/solver.hxx | 64 +- .../simulation/sim_calcul_economique.cpp | 10 +- src/solver/simulation/timeseries-numbers.cpp | 3 +- src/solver/ts-generator/availability.cpp | 22 +- src/solver/ts-generator/xcast/xcast.cpp | 3 +- src/solver/utils/ortools_utils.cpp | 8 +- .../antares/solver/variable/economy/all.h | 4 +- .../bindingConstraintsMarginalCost.h | 7 +- .../antares/solver/variable/endoflist.h | 1 - .../end-to-end/simple_study/simple-study.cpp | 2 +- src/tests/end-to-end/utils/utils.cpp | 3 +- src/tests/end-to-end/utils/utils.h | 3 + .../antlr4-interface/test_antlr_interface.cpp | 8 +- .../test-sc-builder-file-read-line.cpp | 80 +- .../test-sc-builder-file-save.cpp | 4 +- src/tests/src/libs/antares/test_utils.cpp | 9 +- .../antares/yaml-parser/test_yaml_parser.cpp | 16 +- ...-hydro-final-reservoir-level-functions.cpp | 18 +- 77 files changed, 2117 insertions(+), 1584 deletions(-) create mode 100644 .github/workflows/clang-format.yml diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 0000000000..9e00892851 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,36 @@ +name: Check cpp formatting + +on: + push: + branches: + - develop + - feature/* + - features/* + - fix/* + +jobs: + build: + name: clang-format + + runs-on: ubuntu-24.04 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Print version + run: clang-format --version + + - name: clang-format + run: cd src && ./format-code.sh + + - name: git diff + run: | + DIFF=`git status --porcelain` + if [[ $DIFF ]]; then + echo "The following files are not well formatted" + echo "$DIFF" + exit 1 + else + echo "Code is well formatted, congrats !" + fi diff --git a/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp b/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp index 42d6fef5d3..ec45c3a47e 100644 --- a/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp +++ b/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp @@ -1,7 +1,4 @@ // Generated from Expr.g4 by ANTLR 4.13.1 - #include "ExprBaseVisitor.h" - - diff --git a/src/libs/antares/antlr-interface/ExprBaseVisitor.h b/src/libs/antares/antlr-interface/ExprBaseVisitor.h index a8af3c573f..7ff7be623d 100644 --- a/src/libs/antares/antlr-interface/ExprBaseVisitor.h +++ b/src/libs/antares/antlr-interface/ExprBaseVisitor.h @@ -3,78 +3,88 @@ #pragma once - -#include "antlr4-runtime.h" #include "ExprVisitor.h" - +#include "antlr4-runtime.h" /** * This class provides an empty implementation of ExprVisitor, which can be * extended to create a visitor which only needs to handle a subset of the available methods. */ -class ExprBaseVisitor : public ExprVisitor { +class ExprBaseVisitor: public ExprVisitor +{ public: - - virtual std::any visitFullexpr(ExprParser::FullexprContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitShift(ExprParser::ShiftContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitIdentifier(ExprParser::IdentifierContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitNegation(ExprParser::NegationContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitExpression(ExprParser::ExpressionContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitComparison(ExprParser::ComparisonContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitAddsub(ExprParser::AddsubContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitPortField(ExprParser::PortFieldContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitMuldiv(ExprParser::MuldivContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitNumber(ExprParser::NumberContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitTimeIndex(ExprParser::TimeIndexContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitTimeShift(ExprParser::TimeShiftContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitFunction(ExprParser::FunctionContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext *ctx) override { - return visitChildren(ctx); - } - - virtual std::any visitTimeRange(ExprParser::TimeRangeContext *ctx) override { - return visitChildren(ctx); - } - - + virtual std::any visitFullexpr(ExprParser::FullexprContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitShift(ExprParser::ShiftContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitIdentifier(ExprParser::IdentifierContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitNegation(ExprParser::NegationContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitExpression(ExprParser::ExpressionContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitComparison(ExprParser::ComparisonContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitAddsub(ExprParser::AddsubContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitPortField(ExprParser::PortFieldContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitMuldiv(ExprParser::MuldivContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitNumber(ExprParser::NumberContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitTimeIndex(ExprParser::TimeIndexContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitTimeShift(ExprParser::TimeShiftContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitFunction(ExprParser::FunctionContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext* ctx) override + { + return visitChildren(ctx); + } + + virtual std::any visitTimeRange(ExprParser::TimeRangeContext* ctx) override + { + return visitChildren(ctx); + } }; - diff --git a/src/libs/antares/antlr-interface/ExprLexer.cpp b/src/libs/antares/antlr-interface/ExprLexer.cpp index a645fcddd0..9250294cf8 100644 --- a/src/libs/antares/antlr-interface/ExprLexer.cpp +++ b/src/libs/antares/antlr-interface/ExprLexer.cpp @@ -1,177 +1,238 @@ // Generated from Expr.g4 by ANTLR 4.13.1 - #include "ExprLexer.h" - using namespace antlr4; - - using namespace antlr4; -namespace { - -struct ExprLexerStaticData final { - ExprLexerStaticData(std::vector ruleNames, - std::vector channelNames, - std::vector modeNames, - std::vector literalNames, - std::vector symbolicNames) - : ruleNames(std::move(ruleNames)), channelNames(std::move(channelNames)), - modeNames(std::move(modeNames)), literalNames(std::move(literalNames)), +namespace +{ + +struct ExprLexerStaticData final +{ + ExprLexerStaticData(std::vector ruleNames, + std::vector channelNames, + std::vector modeNames, + std::vector literalNames, + std::vector symbolicNames): + ruleNames(std::move(ruleNames)), + channelNames(std::move(channelNames)), + modeNames(std::move(modeNames)), + literalNames(std::move(literalNames)), symbolicNames(std::move(symbolicNames)), - vocabulary(this->literalNames, this->symbolicNames) {} - - ExprLexerStaticData(const ExprLexerStaticData&) = delete; - ExprLexerStaticData(ExprLexerStaticData&&) = delete; - ExprLexerStaticData& operator=(const ExprLexerStaticData&) = delete; - ExprLexerStaticData& operator=(ExprLexerStaticData&&) = delete; - - std::vector decisionToDFA; - antlr4::atn::PredictionContextCache sharedContextCache; - const std::vector ruleNames; - const std::vector channelNames; - const std::vector modeNames; - const std::vector literalNames; - const std::vector symbolicNames; - const antlr4::dfa::Vocabulary vocabulary; - antlr4::atn::SerializedATNView serializedATN; - std::unique_ptr atn; + vocabulary(this->literalNames, this->symbolicNames) + { + } + + ExprLexerStaticData(const ExprLexerStaticData&) = delete; + ExprLexerStaticData(ExprLexerStaticData&&) = delete; + ExprLexerStaticData& operator=(const ExprLexerStaticData&) = delete; + ExprLexerStaticData& operator=(ExprLexerStaticData&&) = delete; + + std::vector decisionToDFA; + antlr4::atn::PredictionContextCache sharedContextCache; + const std::vector ruleNames; + const std::vector channelNames; + const std::vector modeNames; + const std::vector literalNames; + const std::vector symbolicNames; + const antlr4::dfa::Vocabulary vocabulary; + antlr4::atn::SerializedATNView serializedATN; + std::unique_ptr atn; }; ::antlr4::internal::OnceFlag exprlexerLexerOnceFlag; #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif -ExprLexerStaticData *exprlexerLexerStaticData = nullptr; + ExprLexerStaticData* exprlexerLexerStaticData + = nullptr; -void exprlexerLexerInitialize() { +void exprlexerLexerInitialize() +{ #if ANTLR4_USE_THREAD_LOCAL_CACHE - if (exprlexerLexerStaticData != nullptr) { - return; - } + if (exprlexerLexerStaticData != nullptr) + { + return; + } #else - assert(exprlexerLexerStaticData == nullptr); + assert(exprlexerLexerStaticData == nullptr); #endif - auto staticData = std::make_unique( - std::vector{ - "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", - "DIGIT", "CHAR", "CHAR_OR_DIGIT", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" - }, - std::vector{ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - }, - std::vector{ - "DEFAULT_MODE" - }, - std::vector{ - "", "'+'", "'-'", "'/'", "'*'", "'.'", "'('", "')'", "','", "'..'", - "", "'t'", "", "", "", "", "'['", "']'" - }, - std::vector{ - "", "", "", "", "", "", "", "", "", "", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" + auto staticData = std::make_unique( + std::vector{"T__0", "T__1", "T__2", "T__3", "T__4", + "T__5", "T__6", "T__7", "T__8", "DIGIT", + "CHAR", "CHAR_OR_DIGIT", "NUMBER", "TIME", "IDENTIFIER", + "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", + "WS"}, + std::vector{"DEFAULT_TOKEN_CHANNEL", "HIDDEN"}, + std::vector{"DEFAULT_MODE"}, + std::vector{"", + "'+'", + "'-'", + "'/'", + "'*'", + "'.'", + "'('", + "')'", + "','", + "'..'", + "", + "'t'", + "", + "", + "", + "", + "'['", + "']'"}, + std::vector{"", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "NUMBER", + "TIME", + "IDENTIFIER", + "COMPARISON", + "ADDSUB", + "MULDIV", + "LBRACKET", + "RBRACKET", + "WS"}); + static const int32_t serializedATNSegment[] = { + 4, 0, 18, 111, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, + 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, + 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, + 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, + 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 1, 0, 1, 0, 1, + 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, + 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, + 10, 1, 10, 1, 11, 1, 11, 3, 11, 69, 8, 11, 1, 12, 4, 12, 72, 8, 12, + 11, 12, 12, 12, 73, 1, 12, 1, 12, 4, 12, 78, 8, 12, 11, 12, 12, 12, 79, + 3, 12, 82, 8, 12, 1, 13, 1, 13, 1, 14, 1, 14, 5, 14, 88, 8, 14, 10, + 14, 12, 14, 91, 9, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 98, + 8, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, + 20, 1, 20, 1, 20, 1, 20, 0, 0, 21, 1, 1, 3, 2, 5, 3, 7, 4, 9, + 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 0, 21, 0, 23, 0, 25, 10, 27, 11, + 29, 12, 31, 13, 33, 14, 35, 15, 37, 16, 39, 17, 41, 18, 1, 0, 5, 1, 0, + 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 2, 0, 43, 43, 45, 45, 2, 0, 42, + 42, 47, 47, 3, 0, 9, 10, 13, 13, 32, 32, 114, 0, 1, 1, 0, 0, 0, 0, + 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, + 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, + 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, + 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, + 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, + 0, 41, 1, 0, 0, 0, 1, 43, 1, 0, 0, 0, 3, 45, 1, 0, 0, 0, 5, + 47, 1, 0, 0, 0, 7, 49, 1, 0, 0, 0, 9, 51, 1, 0, 0, 0, 11, 53, + 1, 0, 0, 0, 13, 55, 1, 0, 0, 0, 15, 57, 1, 0, 0, 0, 17, 59, 1, + 0, 0, 0, 19, 62, 1, 0, 0, 0, 21, 64, 1, 0, 0, 0, 23, 68, 1, 0, + 0, 0, 25, 71, 1, 0, 0, 0, 27, 83, 1, 0, 0, 0, 29, 85, 1, 0, 0, + 0, 31, 97, 1, 0, 0, 0, 33, 99, 1, 0, 0, 0, 35, 101, 1, 0, 0, 0, + 37, 103, 1, 0, 0, 0, 39, 105, 1, 0, 0, 0, 41, 107, 1, 0, 0, 0, 43, + 44, 5, 43, 0, 0, 44, 2, 1, 0, 0, 0, 45, 46, 5, 45, 0, 0, 46, 4, + 1, 0, 0, 0, 47, 48, 5, 47, 0, 0, 48, 6, 1, 0, 0, 0, 49, 50, 5, + 42, 0, 0, 50, 8, 1, 0, 0, 0, 51, 52, 5, 46, 0, 0, 52, 10, 1, 0, + 0, 0, 53, 54, 5, 40, 0, 0, 54, 12, 1, 0, 0, 0, 55, 56, 5, 41, 0, + 0, 56, 14, 1, 0, 0, 0, 57, 58, 5, 44, 0, 0, 58, 16, 1, 0, 0, 0, + 59, 60, 5, 46, 0, 0, 60, 61, 5, 46, 0, 0, 61, 18, 1, 0, 0, 0, 62, + 63, 7, 0, 0, 0, 63, 20, 1, 0, 0, 0, 64, 65, 7, 1, 0, 0, 65, 22, + 1, 0, 0, 0, 66, 69, 3, 21, 10, 0, 67, 69, 3, 19, 9, 0, 68, 66, 1, + 0, 0, 0, 68, 67, 1, 0, 0, 0, 69, 24, 1, 0, 0, 0, 70, 72, 3, 19, + 9, 0, 71, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 71, 1, 0, 0, + 0, 73, 74, 1, 0, 0, 0, 74, 81, 1, 0, 0, 0, 75, 77, 5, 46, 0, 0, + 76, 78, 3, 19, 9, 0, 77, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, + 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 82, 1, 0, 0, 0, 81, 75, + 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 26, 1, 0, 0, 0, 83, 84, 5, + 116, 0, 0, 84, 28, 1, 0, 0, 0, 85, 89, 3, 21, 10, 0, 86, 88, 3, 23, + 11, 0, 87, 86, 1, 0, 0, 0, 88, 91, 1, 0, 0, 0, 89, 87, 1, 0, 0, + 0, 89, 90, 1, 0, 0, 0, 90, 30, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, + 92, 98, 5, 61, 0, 0, 93, 94, 5, 62, 0, 0, 94, 98, 5, 61, 0, 0, 95, + 96, 5, 60, 0, 0, 96, 98, 5, 61, 0, 0, 97, 92, 1, 0, 0, 0, 97, 93, + 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 98, 32, 1, 0, 0, 0, 99, 100, 7, + 2, 0, 0, 100, 34, 1, 0, 0, 0, 101, 102, 7, 3, 0, 0, 102, 36, 1, 0, + 0, 0, 103, 104, 5, 91, 0, 0, 104, 38, 1, 0, 0, 0, 105, 106, 5, 93, 0, + 0, 106, 40, 1, 0, 0, 0, 107, 108, 7, 4, 0, 0, 108, 109, 1, 0, 0, 0, + 109, 110, 6, 20, 0, 0, 110, 42, 1, 0, 0, 0, 7, 0, 68, 73, 79, 81, 89, + 97, 1, 6, 0, 0}; + staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, + sizeof(serializedATNSegment) + / sizeof(serializedATNSegment[0])); + + antlr4::atn::ATNDeserializer deserializer; + staticData->atn = deserializer.deserialize(staticData->serializedATN); + + const size_t count = staticData->atn->getNumberOfDecisions(); + staticData->decisionToDFA.reserve(count); + for (size_t i = 0; i < count; i++) + { + staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); } - ); - static const int32_t serializedATNSegment[] = { - 4,0,18,111,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, - 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, - 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,1,0, - 1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,8,1,8,1, - 8,1,9,1,9,1,10,1,10,1,11,1,11,3,11,69,8,11,1,12,4,12,72,8,12,11,12,12, - 12,73,1,12,1,12,4,12,78,8,12,11,12,12,12,79,3,12,82,8,12,1,13,1,13,1, - 14,1,14,5,14,88,8,14,10,14,12,14,91,9,14,1,15,1,15,1,15,1,15,1,15,3,15, - 98,8,15,1,16,1,16,1,17,1,17,1,18,1,18,1,19,1,19,1,20,1,20,1,20,1,20,0, - 0,21,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,0,21,0,23,0,25,10,27, - 11,29,12,31,13,33,14,35,15,37,16,39,17,41,18,1,0,5,1,0,48,57,3,0,65,90, - 95,95,97,122,2,0,43,43,45,45,2,0,42,42,47,47,3,0,9,10,13,13,32,32,114, - 0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0, - 0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0, - 0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39, - 1,0,0,0,0,41,1,0,0,0,1,43,1,0,0,0,3,45,1,0,0,0,5,47,1,0,0,0,7,49,1,0, - 0,0,9,51,1,0,0,0,11,53,1,0,0,0,13,55,1,0,0,0,15,57,1,0,0,0,17,59,1,0, - 0,0,19,62,1,0,0,0,21,64,1,0,0,0,23,68,1,0,0,0,25,71,1,0,0,0,27,83,1,0, - 0,0,29,85,1,0,0,0,31,97,1,0,0,0,33,99,1,0,0,0,35,101,1,0,0,0,37,103,1, - 0,0,0,39,105,1,0,0,0,41,107,1,0,0,0,43,44,5,43,0,0,44,2,1,0,0,0,45,46, - 5,45,0,0,46,4,1,0,0,0,47,48,5,47,0,0,48,6,1,0,0,0,49,50,5,42,0,0,50,8, - 1,0,0,0,51,52,5,46,0,0,52,10,1,0,0,0,53,54,5,40,0,0,54,12,1,0,0,0,55, - 56,5,41,0,0,56,14,1,0,0,0,57,58,5,44,0,0,58,16,1,0,0,0,59,60,5,46,0,0, - 60,61,5,46,0,0,61,18,1,0,0,0,62,63,7,0,0,0,63,20,1,0,0,0,64,65,7,1,0, - 0,65,22,1,0,0,0,66,69,3,21,10,0,67,69,3,19,9,0,68,66,1,0,0,0,68,67,1, - 0,0,0,69,24,1,0,0,0,70,72,3,19,9,0,71,70,1,0,0,0,72,73,1,0,0,0,73,71, - 1,0,0,0,73,74,1,0,0,0,74,81,1,0,0,0,75,77,5,46,0,0,76,78,3,19,9,0,77, - 76,1,0,0,0,78,79,1,0,0,0,79,77,1,0,0,0,79,80,1,0,0,0,80,82,1,0,0,0,81, - 75,1,0,0,0,81,82,1,0,0,0,82,26,1,0,0,0,83,84,5,116,0,0,84,28,1,0,0,0, - 85,89,3,21,10,0,86,88,3,23,11,0,87,86,1,0,0,0,88,91,1,0,0,0,89,87,1,0, - 0,0,89,90,1,0,0,0,90,30,1,0,0,0,91,89,1,0,0,0,92,98,5,61,0,0,93,94,5, - 62,0,0,94,98,5,61,0,0,95,96,5,60,0,0,96,98,5,61,0,0,97,92,1,0,0,0,97, - 93,1,0,0,0,97,95,1,0,0,0,98,32,1,0,0,0,99,100,7,2,0,0,100,34,1,0,0,0, - 101,102,7,3,0,0,102,36,1,0,0,0,103,104,5,91,0,0,104,38,1,0,0,0,105,106, - 5,93,0,0,106,40,1,0,0,0,107,108,7,4,0,0,108,109,1,0,0,0,109,110,6,20, - 0,0,110,42,1,0,0,0,7,0,68,73,79,81,89,97,1,6,0,0 - }; - staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); - - antlr4::atn::ATNDeserializer deserializer; - staticData->atn = deserializer.deserialize(staticData->serializedATN); - - const size_t count = staticData->atn->getNumberOfDecisions(); - staticData->decisionToDFA.reserve(count); - for (size_t i = 0; i < count; i++) { - staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); - } - exprlexerLexerStaticData = staticData.release(); + exprlexerLexerStaticData = staticData.release(); } -} +} // namespace -ExprLexer::ExprLexer(CharStream *input) : Lexer(input) { - ExprLexer::initialize(); - _interpreter = new atn::LexerATNSimulator(this, *exprlexerLexerStaticData->atn, exprlexerLexerStaticData->decisionToDFA, exprlexerLexerStaticData->sharedContextCache); +ExprLexer::ExprLexer(CharStream* input): + Lexer(input) +{ + ExprLexer::initialize(); + _interpreter = new atn::LexerATNSimulator(this, + *exprlexerLexerStaticData->atn, + exprlexerLexerStaticData->decisionToDFA, + exprlexerLexerStaticData->sharedContextCache); } -ExprLexer::~ExprLexer() { - delete _interpreter; +ExprLexer::~ExprLexer() +{ + delete _interpreter; } -std::string ExprLexer::getGrammarFileName() const { - return "Expr.g4"; +std::string ExprLexer::getGrammarFileName() const +{ + return "Expr.g4"; } -const std::vector& ExprLexer::getRuleNames() const { - return exprlexerLexerStaticData->ruleNames; +const std::vector& ExprLexer::getRuleNames() const +{ + return exprlexerLexerStaticData->ruleNames; } -const std::vector& ExprLexer::getChannelNames() const { - return exprlexerLexerStaticData->channelNames; +const std::vector& ExprLexer::getChannelNames() const +{ + return exprlexerLexerStaticData->channelNames; } -const std::vector& ExprLexer::getModeNames() const { - return exprlexerLexerStaticData->modeNames; +const std::vector& ExprLexer::getModeNames() const +{ + return exprlexerLexerStaticData->modeNames; } -const dfa::Vocabulary& ExprLexer::getVocabulary() const { - return exprlexerLexerStaticData->vocabulary; +const dfa::Vocabulary& ExprLexer::getVocabulary() const +{ + return exprlexerLexerStaticData->vocabulary; } -antlr4::atn::SerializedATNView ExprLexer::getSerializedATN() const { - return exprlexerLexerStaticData->serializedATN; +antlr4::atn::SerializedATNView ExprLexer::getSerializedATN() const +{ + return exprlexerLexerStaticData->serializedATN; } -const atn::ATN& ExprLexer::getATN() const { - return *exprlexerLexerStaticData->atn; +const atn::ATN& ExprLexer::getATN() const +{ + return *exprlexerLexerStaticData->atn; } - - - -void ExprLexer::initialize() { +void ExprLexer::initialize() +{ #if ANTLR4_USE_THREAD_LOCAL_CACHE - exprlexerLexerInitialize(); + exprlexerLexerInitialize(); #else - ::antlr4::internal::call_once(exprlexerLexerOnceFlag, exprlexerLexerInitialize); + ::antlr4::internal::call_once(exprlexerLexerOnceFlag, exprlexerLexerInitialize); #endif } diff --git a/src/libs/antares/antlr-interface/ExprLexer.h b/src/libs/antares/antlr-interface/ExprLexer.h index c7db2c5f77..a569ec8d21 100644 --- a/src/libs/antares/antlr-interface/ExprLexer.h +++ b/src/libs/antares/antlr-interface/ExprLexer.h @@ -3,49 +3,58 @@ #pragma once - #include "antlr4-runtime.h" - - - -class ExprLexer : public antlr4::Lexer { +class ExprLexer: public antlr4::Lexer +{ public: - enum { - T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, - T__7 = 8, T__8 = 9, NUMBER = 10, TIME = 11, IDENTIFIER = 12, COMPARISON = 13, - ADDSUB = 14, MULDIV = 15, LBRACKET = 16, RBRACKET = 17, WS = 18 - }; + enum + { + T__0 = 1, + T__1 = 2, + T__2 = 3, + T__3 = 4, + T__4 = 5, + T__5 = 6, + T__6 = 7, + T__7 = 8, + T__8 = 9, + NUMBER = 10, + TIME = 11, + IDENTIFIER = 12, + COMPARISON = 13, + ADDSUB = 14, + MULDIV = 15, + LBRACKET = 16, + RBRACKET = 17, + WS = 18 + }; - explicit ExprLexer(antlr4::CharStream *input); + explicit ExprLexer(antlr4::CharStream* input); - ~ExprLexer() override; + ~ExprLexer() override; + std::string getGrammarFileName() const override; - std::string getGrammarFileName() const override; + const std::vector& getRuleNames() const override; - const std::vector& getRuleNames() const override; + const std::vector& getChannelNames() const override; - const std::vector& getChannelNames() const override; + const std::vector& getModeNames() const override; - const std::vector& getModeNames() const override; + const antlr4::dfa::Vocabulary& getVocabulary() const override; - const antlr4::dfa::Vocabulary& getVocabulary() const override; + antlr4::atn::SerializedATNView getSerializedATN() const override; - antlr4::atn::SerializedATNView getSerializedATN() const override; + const antlr4::atn::ATN& getATN() const override; - const antlr4::atn::ATN& getATN() const override; - - // By default the static state used to implement the lexer is lazily initialized during the first - // call to the constructor. You can call this function if you wish to initialize the static state - // ahead of time. - static void initialize(); + // By default the static state used to implement the lexer is lazily initialized during the + // first call to the constructor. You can call this function if you wish to initialize the + // static state ahead of time. + static void initialize(); private: + // Individual action functions triggered by action() above. - // Individual action functions triggered by action() above. - - // Individual semantic predicate functions triggered by sempred() above. - + // Individual semantic predicate functions triggered by sempred() above. }; - diff --git a/src/libs/antares/antlr-interface/ExprParser.cpp b/src/libs/antares/antlr-interface/ExprParser.cpp index 3c688d96d3..64335f4d82 100644 --- a/src/libs/antares/antlr-interface/ExprParser.cpp +++ b/src/libs/antares/antlr-interface/ExprParser.cpp @@ -1,884 +1,1176 @@ // Generated from Expr.g4 by ANTLR 4.13.1 - -#include "ExprVisitor.h" - #include "ExprParser.h" +#include "ExprVisitor.h" using namespace antlrcpp; using namespace antlr4; -namespace { +namespace +{ -struct ExprParserStaticData final { - ExprParserStaticData(std::vector ruleNames, - std::vector literalNames, - std::vector symbolicNames) - : ruleNames(std::move(ruleNames)), literalNames(std::move(literalNames)), +struct ExprParserStaticData final +{ + ExprParserStaticData(std::vector ruleNames, + std::vector literalNames, + std::vector symbolicNames): + ruleNames(std::move(ruleNames)), + literalNames(std::move(literalNames)), symbolicNames(std::move(symbolicNames)), - vocabulary(this->literalNames, this->symbolicNames) {} - - ExprParserStaticData(const ExprParserStaticData&) = delete; - ExprParserStaticData(ExprParserStaticData&&) = delete; - ExprParserStaticData& operator=(const ExprParserStaticData&) = delete; - ExprParserStaticData& operator=(ExprParserStaticData&&) = delete; - - std::vector decisionToDFA; - antlr4::atn::PredictionContextCache sharedContextCache; - const std::vector ruleNames; - const std::vector literalNames; - const std::vector symbolicNames; - const antlr4::dfa::Vocabulary vocabulary; - antlr4::atn::SerializedATNView serializedATN; - std::unique_ptr atn; + vocabulary(this->literalNames, this->symbolicNames) + { + } + + ExprParserStaticData(const ExprParserStaticData&) = delete; + ExprParserStaticData(ExprParserStaticData&&) = delete; + ExprParserStaticData& operator=(const ExprParserStaticData&) = delete; + ExprParserStaticData& operator=(ExprParserStaticData&&) = delete; + + std::vector decisionToDFA; + antlr4::atn::PredictionContextCache sharedContextCache; + const std::vector ruleNames; + const std::vector literalNames; + const std::vector symbolicNames; + const antlr4::dfa::Vocabulary vocabulary; + antlr4::atn::SerializedATNView serializedATN; + std::unique_ptr atn; }; ::antlr4::internal::OnceFlag exprParserOnceFlag; #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif -ExprParserStaticData *exprParserStaticData = nullptr; + ExprParserStaticData* exprParserStaticData + = nullptr; -void exprParserInitialize() { +void exprParserInitialize() +{ #if ANTLR4_USE_THREAD_LOCAL_CACHE - if (exprParserStaticData != nullptr) { - return; - } + if (exprParserStaticData != nullptr) + { + return; + } #else - assert(exprParserStaticData == nullptr); + assert(exprParserStaticData == nullptr); #endif - auto staticData = std::make_unique( - std::vector{ - "fullexpr", "shift", "expr" - }, - std::vector{ - "", "'+'", "'-'", "'/'", "'*'", "'.'", "'('", "')'", "','", "'..'", - "", "'t'", "", "", "", "", "'['", "']'" - }, - std::vector{ - "", "", "", "", "", "", "", "", "", "", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" + auto staticData = std::make_unique(std::vector{"fullexpr", + "shift", + "expr"}, + std::vector{"", + "'+'", + "'-'", + "'/'", + "'*'", + "'.'", + "'('", + "')'", + "','", + "'..'", + "", + "'t'", + "", + "", + "", + "", + "'['", + "']'"}, + std::vector{"", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "NUMBER", + "TIME", + "IDENTIFIER", + "COMPARISON", + "ADDSUB", + "MULDIV", + "LBRACKET", + "RBRACKET", + "WS"}); + static const int32_t serializedATNSegment[] = { + 4, 1, 18, 86, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, 0, 1, 1, + 1, 1, 1, 1, 3, 1, 13, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 5, 2, 37, 8, 2, 10, 2, 12, 2, 40, 9, 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 5, 2, 49, 8, 2, 10, 2, 12, 2, 52, 9, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 3, 2, 70, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 5, 2, 81, 8, 2, 10, 2, 12, 2, 84, 9, 2, 1, 2, 0, 1, 4, 3, 0, 2, 4, 0, + 2, 1, 0, 1, 2, 1, 0, 3, 4, 97, 0, 6, 1, 0, 0, 0, 2, 9, 1, 0, 0, 0, 4, 69, + 1, 0, 0, 0, 6, 7, 3, 4, 2, 0, 7, 8, 5, 0, 0, 1, 8, 1, 1, 0, 0, 0, 9, 12, + 5, 11, 0, 0, 10, 11, 7, 0, 0, 0, 11, 13, 3, 4, 2, 0, 12, 10, 1, 0, 0, 0, 12, 13, + 1, 0, 0, 0, 13, 3, 1, 0, 0, 0, 14, 15, 6, 2, -1, 0, 15, 16, 5, 2, 0, 0, 16, 70, + 3, 4, 2, 13, 17, 70, 5, 12, 0, 0, 18, 19, 5, 12, 0, 0, 19, 20, 5, 5, 0, 0, 20, 70, + 5, 12, 0, 0, 21, 70, 5, 10, 0, 0, 22, 23, 5, 6, 0, 0, 23, 24, 3, 4, 2, 0, 24, 25, + 5, 7, 0, 0, 25, 70, 1, 0, 0, 0, 26, 27, 5, 12, 0, 0, 27, 28, 5, 6, 0, 0, 28, 29, + 3, 4, 2, 0, 29, 30, 5, 7, 0, 0, 30, 70, 1, 0, 0, 0, 31, 32, 5, 12, 0, 0, 32, 33, + 5, 16, 0, 0, 33, 38, 3, 2, 1, 0, 34, 35, 5, 8, 0, 0, 35, 37, 3, 2, 1, 0, 36, 34, + 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, + 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 42, 5, 17, 0, 0, 42, 70, 1, 0, 0, 0, 43, 44, + 5, 12, 0, 0, 44, 45, 5, 16, 0, 0, 45, 50, 3, 4, 2, 0, 46, 47, 5, 8, 0, 0, 47, 49, + 3, 4, 2, 0, 48, 46, 1, 0, 0, 0, 49, 52, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, + 1, 0, 0, 0, 51, 53, 1, 0, 0, 0, 52, 50, 1, 0, 0, 0, 53, 54, 5, 17, 0, 0, 54, 70, + 1, 0, 0, 0, 55, 56, 5, 12, 0, 0, 56, 57, 5, 16, 0, 0, 57, 58, 3, 2, 1, 0, 58, 59, + 5, 9, 0, 0, 59, 60, 3, 2, 1, 0, 60, 61, 5, 17, 0, 0, 61, 70, 1, 0, 0, 0, 62, 63, + 5, 12, 0, 0, 63, 64, 5, 16, 0, 0, 64, 65, 3, 4, 2, 0, 65, 66, 5, 9, 0, 0, 66, 67, + 3, 4, 2, 0, 67, 68, 5, 17, 0, 0, 68, 70, 1, 0, 0, 0, 69, 14, 1, 0, 0, 0, 69, 17, + 1, 0, 0, 0, 69, 18, 1, 0, 0, 0, 69, 21, 1, 0, 0, 0, 69, 22, 1, 0, 0, 0, 69, 26, + 1, 0, 0, 0, 69, 31, 1, 0, 0, 0, 69, 43, 1, 0, 0, 0, 69, 55, 1, 0, 0, 0, 69, 62, + 1, 0, 0, 0, 70, 82, 1, 0, 0, 0, 71, 72, 10, 12, 0, 0, 72, 73, 7, 1, 0, 0, 73, 81, + 3, 4, 2, 13, 74, 75, 10, 11, 0, 0, 75, 76, 7, 0, 0, 0, 76, 81, 3, 4, 2, 12, 77, 78, + 10, 10, 0, 0, 78, 79, 5, 13, 0, 0, 79, 81, 3, 4, 2, 11, 80, 71, 1, 0, 0, 0, 80, 74, + 1, 0, 0, 0, 80, 77, 1, 0, 0, 0, 81, 84, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, + 1, 0, 0, 0, 83, 5, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 6, 12, 38, 50, 69, 80, 82}; + staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, + sizeof(serializedATNSegment) + / sizeof(serializedATNSegment[0])); + + antlr4::atn::ATNDeserializer deserializer; + staticData->atn = deserializer.deserialize(staticData->serializedATN); + + const size_t count = staticData->atn->getNumberOfDecisions(); + staticData->decisionToDFA.reserve(count); + for (size_t i = 0; i < count; i++) + { + staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); } - ); - static const int32_t serializedATNSegment[] = { - 4,1,18,86,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,1,1,1,1,1,1,3,1,13,8,1, - 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,5,2,37,8,2,10,2,12,2,40,9,2,1,2,1,2,1,2,1,2,1,2,1,2, - 1,2,5,2,49,8,2,10,2,12,2,52,9,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,3,2,70,8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, - 1,2,5,2,81,8,2,10,2,12,2,84,9,2,1,2,0,1,4,3,0,2,4,0,2,1,0,1,2,1,0,3,4, - 97,0,6,1,0,0,0,2,9,1,0,0,0,4,69,1,0,0,0,6,7,3,4,2,0,7,8,5,0,0,1,8,1,1, - 0,0,0,9,12,5,11,0,0,10,11,7,0,0,0,11,13,3,4,2,0,12,10,1,0,0,0,12,13,1, - 0,0,0,13,3,1,0,0,0,14,15,6,2,-1,0,15,16,5,2,0,0,16,70,3,4,2,13,17,70, - 5,12,0,0,18,19,5,12,0,0,19,20,5,5,0,0,20,70,5,12,0,0,21,70,5,10,0,0,22, - 23,5,6,0,0,23,24,3,4,2,0,24,25,5,7,0,0,25,70,1,0,0,0,26,27,5,12,0,0,27, - 28,5,6,0,0,28,29,3,4,2,0,29,30,5,7,0,0,30,70,1,0,0,0,31,32,5,12,0,0,32, - 33,5,16,0,0,33,38,3,2,1,0,34,35,5,8,0,0,35,37,3,2,1,0,36,34,1,0,0,0,37, - 40,1,0,0,0,38,36,1,0,0,0,38,39,1,0,0,0,39,41,1,0,0,0,40,38,1,0,0,0,41, - 42,5,17,0,0,42,70,1,0,0,0,43,44,5,12,0,0,44,45,5,16,0,0,45,50,3,4,2,0, - 46,47,5,8,0,0,47,49,3,4,2,0,48,46,1,0,0,0,49,52,1,0,0,0,50,48,1,0,0,0, - 50,51,1,0,0,0,51,53,1,0,0,0,52,50,1,0,0,0,53,54,5,17,0,0,54,70,1,0,0, - 0,55,56,5,12,0,0,56,57,5,16,0,0,57,58,3,2,1,0,58,59,5,9,0,0,59,60,3,2, - 1,0,60,61,5,17,0,0,61,70,1,0,0,0,62,63,5,12,0,0,63,64,5,16,0,0,64,65, - 3,4,2,0,65,66,5,9,0,0,66,67,3,4,2,0,67,68,5,17,0,0,68,70,1,0,0,0,69,14, - 1,0,0,0,69,17,1,0,0,0,69,18,1,0,0,0,69,21,1,0,0,0,69,22,1,0,0,0,69,26, - 1,0,0,0,69,31,1,0,0,0,69,43,1,0,0,0,69,55,1,0,0,0,69,62,1,0,0,0,70,82, - 1,0,0,0,71,72,10,12,0,0,72,73,7,1,0,0,73,81,3,4,2,13,74,75,10,11,0,0, - 75,76,7,0,0,0,76,81,3,4,2,12,77,78,10,10,0,0,78,79,5,13,0,0,79,81,3,4, - 2,11,80,71,1,0,0,0,80,74,1,0,0,0,80,77,1,0,0,0,81,84,1,0,0,0,82,80,1, - 0,0,0,82,83,1,0,0,0,83,5,1,0,0,0,84,82,1,0,0,0,6,12,38,50,69,80,82 - }; - staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); - - antlr4::atn::ATNDeserializer deserializer; - staticData->atn = deserializer.deserialize(staticData->serializedATN); - - const size_t count = staticData->atn->getNumberOfDecisions(); - staticData->decisionToDFA.reserve(count); - for (size_t i = 0; i < count; i++) { - staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); - } - exprParserStaticData = staticData.release(); -} - + exprParserStaticData = staticData.release(); } -ExprParser::ExprParser(TokenStream *input) : ExprParser(input, antlr4::atn::ParserATNSimulatorOptions()) {} +} // namespace -ExprParser::ExprParser(TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options) : Parser(input) { - ExprParser::initialize(); - _interpreter = new atn::ParserATNSimulator(this, *exprParserStaticData->atn, exprParserStaticData->decisionToDFA, exprParserStaticData->sharedContextCache, options); +ExprParser::ExprParser(TokenStream* input): + ExprParser(input, antlr4::atn::ParserATNSimulatorOptions()) +{ } -ExprParser::~ExprParser() { - delete _interpreter; +ExprParser::ExprParser(TokenStream* input, const antlr4::atn::ParserATNSimulatorOptions& options): + Parser(input) +{ + ExprParser::initialize(); + _interpreter = new atn::ParserATNSimulator(this, + *exprParserStaticData->atn, + exprParserStaticData->decisionToDFA, + exprParserStaticData->sharedContextCache, + options); } -const atn::ATN& ExprParser::getATN() const { - return *exprParserStaticData->atn; +ExprParser::~ExprParser() +{ + delete _interpreter; } -std::string ExprParser::getGrammarFileName() const { - return "Expr.g4"; +const atn::ATN& ExprParser::getATN() const +{ + return *exprParserStaticData->atn; } -const std::vector& ExprParser::getRuleNames() const { - return exprParserStaticData->ruleNames; +std::string ExprParser::getGrammarFileName() const +{ + return "Expr.g4"; } -const dfa::Vocabulary& ExprParser::getVocabulary() const { - return exprParserStaticData->vocabulary; +const std::vector& ExprParser::getRuleNames() const +{ + return exprParserStaticData->ruleNames; } -antlr4::atn::SerializedATNView ExprParser::getSerializedATN() const { - return exprParserStaticData->serializedATN; +const dfa::Vocabulary& ExprParser::getVocabulary() const +{ + return exprParserStaticData->vocabulary; } +antlr4::atn::SerializedATNView ExprParser::getSerializedATN() const +{ + return exprParserStaticData->serializedATN; +} -//----------------- FullexprContext ------------------------------------------------------------------ +//----------------- FullexprContext +//------------------------------------------------------------------ -ExprParser::FullexprContext::FullexprContext(ParserRuleContext *parent, size_t invokingState) - : ParserRuleContext(parent, invokingState) { +ExprParser::FullexprContext::FullexprContext(ParserRuleContext* parent, size_t invokingState): + ParserRuleContext(parent, invokingState) +{ } -ExprParser::ExprContext* ExprParser::FullexprContext::expr() { - return getRuleContext(0); +ExprParser::ExprContext* ExprParser::FullexprContext::expr() +{ + return getRuleContext(0); } -tree::TerminalNode* ExprParser::FullexprContext::EOF() { - return getToken(ExprParser::EOF, 0); +tree::TerminalNode* ExprParser::FullexprContext::EOF() +{ + return getToken(ExprParser::EOF, 0); } - -size_t ExprParser::FullexprContext::getRuleIndex() const { - return ExprParser::RuleFullexpr; +size_t ExprParser::FullexprContext::getRuleIndex() const +{ + return ExprParser::RuleFullexpr; } - -std::any ExprParser::FullexprContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitFullexpr(this); - else - return visitor->visitChildren(this); +std::any ExprParser::FullexprContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitFullexpr(this); + } + else + { + return visitor->visitChildren(this); + } } -ExprParser::FullexprContext* ExprParser::fullexpr() { - FullexprContext *_localctx = _tracker.createInstance(_ctx, getState()); - enterRule(_localctx, 0, ExprParser::RuleFullexpr); +ExprParser::FullexprContext* ExprParser::fullexpr() +{ + FullexprContext* _localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 0, ExprParser::RuleFullexpr); #if __cplusplus > 201703L - auto onExit = finally([=, this] { + auto onExit = finally( + [=, this] + { #else - auto onExit = finally([=] { + auto onExit = finally( + [=] + { #endif - exitRule(); - }); - try { - enterOuterAlt(_localctx, 1); - setState(6); - expr(0); - setState(7); - match(ExprParser::EOF); - - } - catch (RecognitionException &e) { - _errHandler->reportError(this, e); - _localctx->exception = std::current_exception(); - _errHandler->recover(this, _localctx->exception); - } - - return _localctx; + exitRule(); + }); + try + { + enterOuterAlt(_localctx, 1); + setState(6); + expr(0); + setState(7); + match(ExprParser::EOF); + } + catch (RecognitionException& e) + { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; } //----------------- ShiftContext ------------------------------------------------------------------ -ExprParser::ShiftContext::ShiftContext(ParserRuleContext *parent, size_t invokingState) - : ParserRuleContext(parent, invokingState) { +ExprParser::ShiftContext::ShiftContext(ParserRuleContext* parent, size_t invokingState): + ParserRuleContext(parent, invokingState) +{ } -tree::TerminalNode* ExprParser::ShiftContext::TIME() { - return getToken(ExprParser::TIME, 0); +tree::TerminalNode* ExprParser::ShiftContext::TIME() +{ + return getToken(ExprParser::TIME, 0); } -ExprParser::ExprContext* ExprParser::ShiftContext::expr() { - return getRuleContext(0); +ExprParser::ExprContext* ExprParser::ShiftContext::expr() +{ + return getRuleContext(0); } - -size_t ExprParser::ShiftContext::getRuleIndex() const { - return ExprParser::RuleShift; +size_t ExprParser::ShiftContext::getRuleIndex() const +{ + return ExprParser::RuleShift; } - -std::any ExprParser::ShiftContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitShift(this); - else - return visitor->visitChildren(this); +std::any ExprParser::ShiftContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitShift(this); + } + else + { + return visitor->visitChildren(this); + } } -ExprParser::ShiftContext* ExprParser::shift() { - ShiftContext *_localctx = _tracker.createInstance(_ctx, getState()); - enterRule(_localctx, 2, ExprParser::RuleShift); - size_t _la = 0; +ExprParser::ShiftContext* ExprParser::shift() +{ + ShiftContext* _localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 2, ExprParser::RuleShift); + size_t _la = 0; #if __cplusplus > 201703L - auto onExit = finally([=, this] { + auto onExit = finally( + [=, this] + { #else - auto onExit = finally([=] { + auto onExit = finally( + [=] + { #endif - exitRule(); - }); - try { - enterOuterAlt(_localctx, 1); - setState(9); - match(ExprParser::TIME); - setState(12); - _errHandler->sync(this); - - _la = _input->LA(1); - if (_la == ExprParser::T__0 - - || _la == ExprParser::T__1) { - setState(10); - antlrcpp::downCast(_localctx)->op = _input->LT(1); - _la = _input->LA(1); - if (!(_la == ExprParser::T__0 - - || _la == ExprParser::T__1)) { - antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); - } - else { - _errHandler->reportMatch(this); - consume(); - } - setState(11); - expr(0); - } - - } - catch (RecognitionException &e) { - _errHandler->reportError(this, e); - _localctx->exception = std::current_exception(); - _errHandler->recover(this, _localctx->exception); - } - - return _localctx; + exitRule(); + }); + try + { + enterOuterAlt(_localctx, 1); + setState(9); + match(ExprParser::TIME); + setState(12); + _errHandler->sync(this); + + _la = _input->LA(1); + if (_la == ExprParser::T__0 + + || _la == ExprParser::T__1) + { + setState(10); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__0 + + || _la == ExprParser::T__1)) + { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else + { + _errHandler->reportMatch(this); + consume(); + } + setState(11); + expr(0); + } + } + catch (RecognitionException& e) + { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; } //----------------- ExprContext ------------------------------------------------------------------ -ExprParser::ExprContext::ExprContext(ParserRuleContext *parent, size_t invokingState) - : ParserRuleContext(parent, invokingState) { +ExprParser::ExprContext::ExprContext(ParserRuleContext* parent, size_t invokingState): + ParserRuleContext(parent, invokingState) +{ } - -size_t ExprParser::ExprContext::getRuleIndex() const { - return ExprParser::RuleExpr; +size_t ExprParser::ExprContext::getRuleIndex() const +{ + return ExprParser::RuleExpr; } -void ExprParser::ExprContext::copyFrom(ExprContext *ctx) { - ParserRuleContext::copyFrom(ctx); +void ExprParser::ExprContext::copyFrom(ExprContext* ctx) +{ + ParserRuleContext::copyFrom(ctx); } -//----------------- IdentifierContext ------------------------------------------------------------------ +//----------------- IdentifierContext +//------------------------------------------------------------------ + +tree::TerminalNode* ExprParser::IdentifierContext::IDENTIFIER() +{ + return getToken(ExprParser::IDENTIFIER, 0); +} -tree::TerminalNode* ExprParser::IdentifierContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); +ExprParser::IdentifierContext::IdentifierContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::IdentifierContext::IdentifierContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::IdentifierContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitIdentifier(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- NegationContext +//------------------------------------------------------------------ -std::any ExprParser::IdentifierContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitIdentifier(this); - else - return visitor->visitChildren(this); +ExprParser::ExprContext* ExprParser::NegationContext::expr() +{ + return getRuleContext(0); } -//----------------- NegationContext ------------------------------------------------------------------ -ExprParser::ExprContext* ExprParser::NegationContext::expr() { - return getRuleContext(0); +ExprParser::NegationContext::NegationContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::NegationContext::NegationContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::NegationContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitNegation(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- ExpressionContext +//------------------------------------------------------------------ -std::any ExprParser::NegationContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitNegation(this); - else - return visitor->visitChildren(this); +ExprParser::ExprContext* ExprParser::ExpressionContext::expr() +{ + return getRuleContext(0); } -//----------------- ExpressionContext ------------------------------------------------------------------ -ExprParser::ExprContext* ExprParser::ExpressionContext::expr() { - return getRuleContext(0); +ExprParser::ExpressionContext::ExpressionContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::ExpressionContext::ExpressionContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::ExpressionContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitExpression(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- ComparisonContext +//------------------------------------------------------------------ -std::any ExprParser::ExpressionContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitExpression(this); - else - return visitor->visitChildren(this); +std::vector ExprParser::ComparisonContext::expr() +{ + return getRuleContexts(); } -//----------------- ComparisonContext ------------------------------------------------------------------ -std::vector ExprParser::ComparisonContext::expr() { - return getRuleContexts(); +ExprParser::ExprContext* ExprParser::ComparisonContext::expr(size_t i) +{ + return getRuleContext(i); } -ExprParser::ExprContext* ExprParser::ComparisonContext::expr(size_t i) { - return getRuleContext(i); +tree::TerminalNode* ExprParser::ComparisonContext::COMPARISON() +{ + return getToken(ExprParser::COMPARISON, 0); } -tree::TerminalNode* ExprParser::ComparisonContext::COMPARISON() { - return getToken(ExprParser::COMPARISON, 0); +ExprParser::ComparisonContext::ComparisonContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::ComparisonContext::ComparisonContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::ComparisonContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitComparison(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- AddsubContext ------------------------------------------------------------------ -std::any ExprParser::ComparisonContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitComparison(this); - else - return visitor->visitChildren(this); +std::vector ExprParser::AddsubContext::expr() +{ + return getRuleContexts(); } -//----------------- AddsubContext ------------------------------------------------------------------ -std::vector ExprParser::AddsubContext::expr() { - return getRuleContexts(); +ExprParser::ExprContext* ExprParser::AddsubContext::expr(size_t i) +{ + return getRuleContext(i); } -ExprParser::ExprContext* ExprParser::AddsubContext::expr(size_t i) { - return getRuleContext(i); +ExprParser::AddsubContext::AddsubContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::AddsubContext::AddsubContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::AddsubContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitAddsub(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- PortFieldContext +//------------------------------------------------------------------ -std::any ExprParser::AddsubContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitAddsub(this); - else - return visitor->visitChildren(this); +std::vector ExprParser::PortFieldContext::IDENTIFIER() +{ + return getTokens(ExprParser::IDENTIFIER); } -//----------------- PortFieldContext ------------------------------------------------------------------ -std::vector ExprParser::PortFieldContext::IDENTIFIER() { - return getTokens(ExprParser::IDENTIFIER); +tree::TerminalNode* ExprParser::PortFieldContext::IDENTIFIER(size_t i) +{ + return getToken(ExprParser::IDENTIFIER, i); } -tree::TerminalNode* ExprParser::PortFieldContext::IDENTIFIER(size_t i) { - return getToken(ExprParser::IDENTIFIER, i); +ExprParser::PortFieldContext::PortFieldContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::PortFieldContext::PortFieldContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::PortFieldContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitPortField(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- MuldivContext ------------------------------------------------------------------ -std::any ExprParser::PortFieldContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitPortField(this); - else - return visitor->visitChildren(this); +std::vector ExprParser::MuldivContext::expr() +{ + return getRuleContexts(); } -//----------------- MuldivContext ------------------------------------------------------------------ -std::vector ExprParser::MuldivContext::expr() { - return getRuleContexts(); +ExprParser::ExprContext* ExprParser::MuldivContext::expr(size_t i) +{ + return getRuleContext(i); } -ExprParser::ExprContext* ExprParser::MuldivContext::expr(size_t i) { - return getRuleContext(i); +ExprParser::MuldivContext::MuldivContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::MuldivContext::MuldivContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::MuldivContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitMuldiv(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- NumberContext ------------------------------------------------------------------ -std::any ExprParser::MuldivContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitMuldiv(this); - else - return visitor->visitChildren(this); +tree::TerminalNode* ExprParser::NumberContext::NUMBER() +{ + return getToken(ExprParser::NUMBER, 0); } -//----------------- NumberContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::NumberContext::NUMBER() { - return getToken(ExprParser::NUMBER, 0); +ExprParser::NumberContext::NumberContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::NumberContext::NumberContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::NumberContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitNumber(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- TimeIndexContext +//------------------------------------------------------------------ -std::any ExprParser::NumberContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitNumber(this); - else - return visitor->visitChildren(this); +tree::TerminalNode* ExprParser::TimeIndexContext::IDENTIFIER() +{ + return getToken(ExprParser::IDENTIFIER, 0); } -//----------------- TimeIndexContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::TimeIndexContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); +tree::TerminalNode* ExprParser::TimeIndexContext::LBRACKET() +{ + return getToken(ExprParser::LBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeIndexContext::LBRACKET() { - return getToken(ExprParser::LBRACKET, 0); +std::vector ExprParser::TimeIndexContext::expr() +{ + return getRuleContexts(); } -std::vector ExprParser::TimeIndexContext::expr() { - return getRuleContexts(); +ExprParser::ExprContext* ExprParser::TimeIndexContext::expr(size_t i) +{ + return getRuleContext(i); } -ExprParser::ExprContext* ExprParser::TimeIndexContext::expr(size_t i) { - return getRuleContext(i); +tree::TerminalNode* ExprParser::TimeIndexContext::RBRACKET() +{ + return getToken(ExprParser::RBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeIndexContext::RBRACKET() { - return getToken(ExprParser::RBRACKET, 0); +ExprParser::TimeIndexContext::TimeIndexContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::TimeIndexContext::TimeIndexContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::TimeIndexContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitTimeIndex(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- TimeShiftContext +//------------------------------------------------------------------ -std::any ExprParser::TimeIndexContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitTimeIndex(this); - else - return visitor->visitChildren(this); +tree::TerminalNode* ExprParser::TimeShiftContext::IDENTIFIER() +{ + return getToken(ExprParser::IDENTIFIER, 0); } -//----------------- TimeShiftContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::TimeShiftContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); +tree::TerminalNode* ExprParser::TimeShiftContext::LBRACKET() +{ + return getToken(ExprParser::LBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeShiftContext::LBRACKET() { - return getToken(ExprParser::LBRACKET, 0); +std::vector ExprParser::TimeShiftContext::shift() +{ + return getRuleContexts(); } -std::vector ExprParser::TimeShiftContext::shift() { - return getRuleContexts(); +ExprParser::ShiftContext* ExprParser::TimeShiftContext::shift(size_t i) +{ + return getRuleContext(i); } -ExprParser::ShiftContext* ExprParser::TimeShiftContext::shift(size_t i) { - return getRuleContext(i); +tree::TerminalNode* ExprParser::TimeShiftContext::RBRACKET() +{ + return getToken(ExprParser::RBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeShiftContext::RBRACKET() { - return getToken(ExprParser::RBRACKET, 0); +ExprParser::TimeShiftContext::TimeShiftContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::TimeShiftContext::TimeShiftContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::TimeShiftContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitTimeShift(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- FunctionContext +//------------------------------------------------------------------ -std::any ExprParser::TimeShiftContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitTimeShift(this); - else - return visitor->visitChildren(this); +tree::TerminalNode* ExprParser::FunctionContext::IDENTIFIER() +{ + return getToken(ExprParser::IDENTIFIER, 0); } -//----------------- FunctionContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::FunctionContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); +ExprParser::ExprContext* ExprParser::FunctionContext::expr() +{ + return getRuleContext(0); } -ExprParser::ExprContext* ExprParser::FunctionContext::expr() { - return getRuleContext(0); +ExprParser::FunctionContext::FunctionContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::FunctionContext::FunctionContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::FunctionContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitFunction(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- TimeShiftRangeContext +//------------------------------------------------------------------ -std::any ExprParser::FunctionContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitFunction(this); - else - return visitor->visitChildren(this); +tree::TerminalNode* ExprParser::TimeShiftRangeContext::IDENTIFIER() +{ + return getToken(ExprParser::IDENTIFIER, 0); } -//----------------- TimeShiftRangeContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::TimeShiftRangeContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); +tree::TerminalNode* ExprParser::TimeShiftRangeContext::LBRACKET() +{ + return getToken(ExprParser::LBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeShiftRangeContext::LBRACKET() { - return getToken(ExprParser::LBRACKET, 0); +tree::TerminalNode* ExprParser::TimeShiftRangeContext::RBRACKET() +{ + return getToken(ExprParser::RBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeShiftRangeContext::RBRACKET() { - return getToken(ExprParser::RBRACKET, 0); +std::vector ExprParser::TimeShiftRangeContext::shift() +{ + return getRuleContexts(); } -std::vector ExprParser::TimeShiftRangeContext::shift() { - return getRuleContexts(); +ExprParser::ShiftContext* ExprParser::TimeShiftRangeContext::shift(size_t i) +{ + return getRuleContext(i); } -ExprParser::ShiftContext* ExprParser::TimeShiftRangeContext::shift(size_t i) { - return getRuleContext(i); +ExprParser::TimeShiftRangeContext::TimeShiftRangeContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::TimeShiftRangeContext::TimeShiftRangeContext(ExprContext *ctx) { copyFrom(ctx); } +std::any ExprParser::TimeShiftRangeContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitTimeShiftRange(this); + } + else + { + return visitor->visitChildren(this); + } +} +//----------------- TimeRangeContext +//------------------------------------------------------------------ -std::any ExprParser::TimeShiftRangeContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitTimeShiftRange(this); - else - return visitor->visitChildren(this); +tree::TerminalNode* ExprParser::TimeRangeContext::IDENTIFIER() +{ + return getToken(ExprParser::IDENTIFIER, 0); } -//----------------- TimeRangeContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::TimeRangeContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); +tree::TerminalNode* ExprParser::TimeRangeContext::LBRACKET() +{ + return getToken(ExprParser::LBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeRangeContext::LBRACKET() { - return getToken(ExprParser::LBRACKET, 0); +std::vector ExprParser::TimeRangeContext::expr() +{ + return getRuleContexts(); } -std::vector ExprParser::TimeRangeContext::expr() { - return getRuleContexts(); +ExprParser::ExprContext* ExprParser::TimeRangeContext::expr(size_t i) +{ + return getRuleContext(i); } -ExprParser::ExprContext* ExprParser::TimeRangeContext::expr(size_t i) { - return getRuleContext(i); +tree::TerminalNode* ExprParser::TimeRangeContext::RBRACKET() +{ + return getToken(ExprParser::RBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeRangeContext::RBRACKET() { - return getToken(ExprParser::RBRACKET, 0); +ExprParser::TimeRangeContext::TimeRangeContext(ExprContext* ctx) +{ + copyFrom(ctx); } -ExprParser::TimeRangeContext::TimeRangeContext(ExprContext *ctx) { copyFrom(ctx); } - - -std::any ExprParser::TimeRangeContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitTimeRange(this); - else - return visitor->visitChildren(this); +std::any ExprParser::TimeRangeContext::accept(tree::ParseTreeVisitor* visitor) +{ + if (auto parserVisitor = dynamic_cast(visitor)) + { + return parserVisitor->visitTimeRange(this); + } + else + { + return visitor->visitChildren(this); + } } -ExprParser::ExprContext* ExprParser::expr() { - return expr(0); +ExprParser::ExprContext* ExprParser::expr() +{ + return expr(0); } -ExprParser::ExprContext* ExprParser::expr(int precedence) { - ParserRuleContext *parentContext = _ctx; - size_t parentState = getState(); - ExprParser::ExprContext *_localctx = _tracker.createInstance(_ctx, parentState); - ExprParser::ExprContext *previousContext = _localctx; - (void)previousContext; // Silence compiler, in case the context is not used by generated code. - size_t startState = 4; - enterRecursionRule(_localctx, 4, ExprParser::RuleExpr, precedence); +ExprParser::ExprContext* ExprParser::expr(int precedence) +{ + ParserRuleContext* parentContext = _ctx; + size_t parentState = getState(); + ExprParser::ExprContext* _localctx = _tracker.createInstance(_ctx, parentState); + ExprParser::ExprContext* previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 4; + enterRecursionRule(_localctx, 4, ExprParser::RuleExpr, precedence); size_t _la = 0; #if __cplusplus > 201703L - auto onExit = finally([=, this] { + auto onExit = finally( + [=, this] + { #else - auto onExit = finally([=] { + auto onExit = finally( + [=] + { #endif - unrollRecursionContexts(parentContext); - }); - try { - size_t alt; - enterOuterAlt(_localctx, 1); - setState(69); - _errHandler->sync(this); - switch (getInterpreter()->adaptivePredict(_input, 3, _ctx)) { - case 1: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - - setState(15); - match(ExprParser::T__1); - setState(16); - expr(13); - break; - } - - case 2: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(17); - match(ExprParser::IDENTIFIER); - break; - } - - case 3: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(18); - match(ExprParser::IDENTIFIER); - setState(19); - match(ExprParser::T__4); - setState(20); - match(ExprParser::IDENTIFIER); - break; - } - - case 4: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(21); - match(ExprParser::NUMBER); - break; - } - - case 5: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(22); - match(ExprParser::T__5); - setState(23); - expr(0); - setState(24); - match(ExprParser::T__6); - break; - } - - case 6: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(26); - match(ExprParser::IDENTIFIER); - setState(27); - match(ExprParser::T__5); - setState(28); - expr(0); - setState(29); - match(ExprParser::T__6); - break; - } - - case 7: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(31); - match(ExprParser::IDENTIFIER); - setState(32); - match(ExprParser::LBRACKET); - setState(33); - shift(); - setState(38); - _errHandler->sync(this); - _la = _input->LA(1); - while (_la == ExprParser::T__7) { - setState(34); - match(ExprParser::T__7); - setState(35); - shift(); - setState(40); - _errHandler->sync(this); - _la = _input->LA(1); - } - setState(41); - match(ExprParser::RBRACKET); - break; - } - - case 8: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(43); - match(ExprParser::IDENTIFIER); - setState(44); - match(ExprParser::LBRACKET); - setState(45); - expr(0); - setState(50); - _errHandler->sync(this); - _la = _input->LA(1); - while (_la == ExprParser::T__7) { - setState(46); - match(ExprParser::T__7); - setState(47); - expr(0); - setState(52); + unrollRecursionContexts(parentContext); + }); + try + { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(69); _errHandler->sync(this); - _la = _input->LA(1); - } - setState(53); - match(ExprParser::RBRACKET); - break; - } - - case 9: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(55); - match(ExprParser::IDENTIFIER); - setState(56); - match(ExprParser::LBRACKET); - setState(57); - antlrcpp::downCast(_localctx)->shift1 = shift(); - setState(58); - match(ExprParser::T__8); - setState(59); - antlrcpp::downCast(_localctx)->shift2 = shift(); - setState(60); - match(ExprParser::RBRACKET); - break; - } - - case 10: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(62); - match(ExprParser::IDENTIFIER); - setState(63); - match(ExprParser::LBRACKET); - setState(64); - expr(0); - setState(65); - match(ExprParser::T__8); - setState(66); - expr(0); - setState(67); - match(ExprParser::RBRACKET); - break; - } + switch (getInterpreter()->adaptivePredict(_input, 3, _ctx)) + { + case 1: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + + setState(15); + match(ExprParser::T__1); + setState(16); + expr(13); + break; + } - default: - break; - } - _ctx->stop = _input->LT(-1); - setState(82); - _errHandler->sync(this); - alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); - while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { - if (alt == 1) { - if (!_parseListeners.empty()) - triggerExitRuleEvent(); - previousContext = _localctx; - setState(80); - _errHandler->sync(this); - switch (getInterpreter()->adaptivePredict(_input, 4, _ctx)) { - case 1: { - auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); - _localctx = newContext; - pushNewRecursionContext(newContext, startState, RuleExpr); - setState(71); - - if (!(precpred(_ctx, 12))) throw FailedPredicateException(this, "precpred(_ctx, 12)"); - setState(72); - antlrcpp::downCast(_localctx)->op = _input->LT(1); - _la = _input->LA(1); - if (!(_la == ExprParser::T__2 - - || _la == ExprParser::T__3)) { - antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); - } - else { - _errHandler->reportMatch(this); - consume(); - } - setState(73); - expr(13); - break; + case 2: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(17); + match(ExprParser::IDENTIFIER); + break; } - case 2: { - auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); - _localctx = newContext; - pushNewRecursionContext(newContext, startState, RuleExpr); - setState(74); - - if (!(precpred(_ctx, 11))) throw FailedPredicateException(this, "precpred(_ctx, 11)"); - setState(75); - antlrcpp::downCast(_localctx)->op = _input->LT(1); - _la = _input->LA(1); - if (!(_la == ExprParser::T__0 - - || _la == ExprParser::T__1)) { - antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); - } - else { - _errHandler->reportMatch(this); - consume(); - } - setState(76); - expr(12); - break; + case 3: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(18); + match(ExprParser::IDENTIFIER); + setState(19); + match(ExprParser::T__4); + setState(20); + match(ExprParser::IDENTIFIER); + break; } - case 3: { - auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); - _localctx = newContext; - pushNewRecursionContext(newContext, startState, RuleExpr); - setState(77); - - if (!(precpred(_ctx, 10))) throw FailedPredicateException(this, "precpred(_ctx, 10)"); - setState(78); - match(ExprParser::COMPARISON); - setState(79); - expr(11); - break; + case 4: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(21); + match(ExprParser::NUMBER); + break; + } + + case 5: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(22); + match(ExprParser::T__5); + setState(23); + expr(0); + setState(24); + match(ExprParser::T__6); + break; + } + + case 6: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(26); + match(ExprParser::IDENTIFIER); + setState(27); + match(ExprParser::T__5); + setState(28); + expr(0); + setState(29); + match(ExprParser::T__6); + break; + } + + case 7: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(31); + match(ExprParser::IDENTIFIER); + setState(32); + match(ExprParser::LBRACKET); + setState(33); + shift(); + setState(38); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == ExprParser::T__7) + { + setState(34); + match(ExprParser::T__7); + setState(35); + shift(); + setState(40); + _errHandler->sync(this); + _la = _input->LA(1); + } + setState(41); + match(ExprParser::RBRACKET); + break; + } + + case 8: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(43); + match(ExprParser::IDENTIFIER); + setState(44); + match(ExprParser::LBRACKET); + setState(45); + expr(0); + setState(50); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == ExprParser::T__7) + { + setState(46); + match(ExprParser::T__7); + setState(47); + expr(0); + setState(52); + _errHandler->sync(this); + _la = _input->LA(1); + } + setState(53); + match(ExprParser::RBRACKET); + break; + } + + case 9: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(55); + match(ExprParser::IDENTIFIER); + setState(56); + match(ExprParser::LBRACKET); + setState(57); + antlrcpp::downCast(_localctx)->shift1 = shift(); + setState(58); + match(ExprParser::T__8); + setState(59); + antlrcpp::downCast(_localctx)->shift2 = shift(); + setState(60); + match(ExprParser::RBRACKET); + break; + } + + case 10: + { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(62); + match(ExprParser::IDENTIFIER); + setState(63); + match(ExprParser::LBRACKET); + setState(64); + expr(0); + setState(65); + match(ExprParser::T__8); + setState(66); + expr(0); + setState(67); + match(ExprParser::RBRACKET); + break; } default: - break; - } - } - setState(84); - _errHandler->sync(this); - alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); + break; + } + _ctx->stop = _input->LT(-1); + setState(82); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) + { + if (alt == 1) + { + if (!_parseListeners.empty()) + { + triggerExitRuleEvent(); + } + previousContext = _localctx; + setState(80); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 4, _ctx)) + { + case 1: + { + auto newContext = _tracker.createInstance( + _tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleExpr); + setState(71); + + if (!(precpred(_ctx, 12))) + { + throw FailedPredicateException(this, "precpred(_ctx, 12)"); + } + setState(72); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__2 + + || _la == ExprParser::T__3)) + { + antlrcpp::downCast(_localctx)->op = _errHandler + ->recoverInline(this); + } + else + { + _errHandler->reportMatch(this); + consume(); + } + setState(73); + expr(13); + break; + } + + case 2: + { + auto newContext = _tracker.createInstance( + _tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleExpr); + setState(74); + + if (!(precpred(_ctx, 11))) + { + throw FailedPredicateException(this, "precpred(_ctx, 11)"); + } + setState(75); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__0 + + || _la == ExprParser::T__1)) + { + antlrcpp::downCast(_localctx)->op = _errHandler + ->recoverInline(this); + } + else + { + _errHandler->reportMatch(this); + consume(); + } + setState(76); + expr(12); + break; + } + + case 3: + { + auto newContext = _tracker.createInstance( + _tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleExpr); + setState(77); + + if (!(precpred(_ctx, 10))) + { + throw FailedPredicateException(this, "precpred(_ctx, 10)"); + } + setState(78); + match(ExprParser::COMPARISON); + setState(79); + expr(11); + break; + } + + default: + break; + } + } + setState(84); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); + } + } + catch (RecognitionException& e) + { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); } - } - catch (RecognitionException &e) { - _errHandler->reportError(this, e); - _localctx->exception = std::current_exception(); - _errHandler->recover(this, _localctx->exception); - } - return _localctx; + return _localctx; } -bool ExprParser::sempred(RuleContext *context, size_t ruleIndex, size_t predicateIndex) { - switch (ruleIndex) { - case 2: return exprSempred(antlrcpp::downCast(context), predicateIndex); +bool ExprParser::sempred(RuleContext* context, size_t ruleIndex, size_t predicateIndex) +{ + switch (ruleIndex) + { + case 2: + return exprSempred(antlrcpp::downCast(context), predicateIndex); - default: - break; - } - return true; + default: + break; + } + return true; } -bool ExprParser::exprSempred(ExprContext *_localctx, size_t predicateIndex) { - switch (predicateIndex) { - case 0: return precpred(_ctx, 12); - case 1: return precpred(_ctx, 11); - case 2: return precpred(_ctx, 10); +bool ExprParser::exprSempred(ExprContext* _localctx, size_t predicateIndex) +{ + switch (predicateIndex) + { + case 0: + return precpred(_ctx, 12); + case 1: + return precpred(_ctx, 11); + case 2: + return precpred(_ctx, 10); - default: - break; - } - return true; + default: + break; + } + return true; } -void ExprParser::initialize() { +void ExprParser::initialize() +{ #if ANTLR4_USE_THREAD_LOCAL_CACHE - exprParserInitialize(); + exprParserInitialize(); #else - ::antlr4::internal::call_once(exprParserOnceFlag, exprParserInitialize); + ::antlr4::internal::call_once(exprParserOnceFlag, exprParserInitialize); #endif } diff --git a/src/libs/antares/antlr-interface/ExprParser.h b/src/libs/antares/antlr-interface/ExprParser.h index aa1c8b6f09..6573ea2b2d 100644 --- a/src/libs/antares/antlr-interface/ExprParser.h +++ b/src/libs/antares/antlr-interface/ExprParser.h @@ -3,242 +3,266 @@ #pragma once - #include "antlr4-runtime.h" - - - -class ExprParser : public antlr4::Parser { +class ExprParser: public antlr4::Parser +{ public: - enum { - T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, - T__7 = 8, T__8 = 9, NUMBER = 10, TIME = 11, IDENTIFIER = 12, COMPARISON = 13, - ADDSUB = 14, MULDIV = 15, LBRACKET = 16, RBRACKET = 17, WS = 18 - }; - - enum { - RuleFullexpr = 0, RuleShift = 1, RuleExpr = 2 - }; - - explicit ExprParser(antlr4::TokenStream *input); - - ExprParser(antlr4::TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options); - - ~ExprParser() override; - - std::string getGrammarFileName() const override; - - const antlr4::atn::ATN& getATN() const override; - - const std::vector& getRuleNames() const override; + enum + { + T__0 = 1, + T__1 = 2, + T__2 = 3, + T__3 = 4, + T__4 = 5, + T__5 = 6, + T__6 = 7, + T__7 = 8, + T__8 = 9, + NUMBER = 10, + TIME = 11, + IDENTIFIER = 12, + COMPARISON = 13, + ADDSUB = 14, + MULDIV = 15, + LBRACKET = 16, + RBRACKET = 17, + WS = 18 + }; + + enum + { + RuleFullexpr = 0, + RuleShift = 1, + RuleExpr = 2 + }; + + explicit ExprParser(antlr4::TokenStream* input); - const antlr4::dfa::Vocabulary& getVocabulary() const override; + ExprParser(antlr4::TokenStream* input, const antlr4::atn::ParserATNSimulatorOptions& options); + + ~ExprParser() override; - antlr4::atn::SerializedATNView getSerializedATN() const override; + std::string getGrammarFileName() const override; + + const antlr4::atn::ATN& getATN() const override; + const std::vector& getRuleNames() const override; + + const antlr4::dfa::Vocabulary& getVocabulary() const override; - class FullexprContext; - class ShiftContext; - class ExprContext; + antlr4::atn::SerializedATNView getSerializedATN() const override; + + class FullexprContext; + class ShiftContext; + class ExprContext; + + class FullexprContext: public antlr4::ParserRuleContext + { + public: + FullexprContext(antlr4::ParserRuleContext* parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + ExprContext* expr(); + antlr4::tree::TerminalNode* EOF(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; + + FullexprContext* fullexpr(); - class FullexprContext : public antlr4::ParserRuleContext { - public: - FullexprContext(antlr4::ParserRuleContext *parent, size_t invokingState); - virtual size_t getRuleIndex() const override; - ExprContext *expr(); - antlr4::tree::TerminalNode *EOF(); + class ShiftContext: public antlr4::ParserRuleContext + { + public: + antlr4::Token* op = nullptr; + ShiftContext(antlr4::ParserRuleContext* parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode* TIME(); + ExprContext* expr(); + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - - }; + ShiftContext* shift(); - FullexprContext* fullexpr(); + class ExprContext: public antlr4::ParserRuleContext + { + public: + ExprContext(antlr4::ParserRuleContext* parent, size_t invokingState); - class ShiftContext : public antlr4::ParserRuleContext { - public: - antlr4::Token *op = nullptr; - ShiftContext(antlr4::ParserRuleContext *parent, size_t invokingState); - virtual size_t getRuleIndex() const override; - antlr4::tree::TerminalNode *TIME(); - ExprContext *expr(); + ExprContext() = default; + void copyFrom(ExprContext* context); + using antlr4::ParserRuleContext::copyFrom; + + virtual size_t getRuleIndex() const override; + }; + + class IdentifierContext: public ExprContext + { + public: + IdentifierContext(ExprContext* ctx); + + antlr4::tree::TerminalNode* IDENTIFIER(); + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; + + class NegationContext: public ExprContext + { + public: + NegationContext(ExprContext* ctx); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - - }; + ExprContext* expr(); - ShiftContext* shift(); + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class ExprContext : public antlr4::ParserRuleContext { - public: - ExprContext(antlr4::ParserRuleContext *parent, size_t invokingState); - - ExprContext() = default; - void copyFrom(ExprContext *context); - using antlr4::ParserRuleContext::copyFrom; + class ExpressionContext: public ExprContext + { + public: + ExpressionContext(ExprContext* ctx); - virtual size_t getRuleIndex() const override; + ExprContext* expr(); - - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class IdentifierContext : public ExprContext { - public: - IdentifierContext(ExprContext *ctx); + class ComparisonContext: public ExprContext + { + public: + ComparisonContext(ExprContext* ctx); - antlr4::tree::TerminalNode *IDENTIFIER(); + std::vector expr(); + ExprContext* expr(size_t i); + antlr4::tree::TerminalNode* COMPARISON(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class NegationContext : public ExprContext { - public: - NegationContext(ExprContext *ctx); + class AddsubContext: public ExprContext + { + public: + AddsubContext(ExprContext* ctx); - ExprContext *expr(); + antlr4::Token* op = nullptr; + std::vector expr(); + ExprContext* expr(size_t i); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class ExpressionContext : public ExprContext { - public: - ExpressionContext(ExprContext *ctx); + class PortFieldContext: public ExprContext + { + public: + PortFieldContext(ExprContext* ctx); - ExprContext *expr(); + std::vector IDENTIFIER(); + antlr4::tree::TerminalNode* IDENTIFIER(size_t i); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class ComparisonContext : public ExprContext { - public: - ComparisonContext(ExprContext *ctx); + class MuldivContext: public ExprContext + { + public: + MuldivContext(ExprContext* ctx); - std::vector expr(); - ExprContext* expr(size_t i); - antlr4::tree::TerminalNode *COMPARISON(); + antlr4::Token* op = nullptr; + std::vector expr(); + ExprContext* expr(size_t i); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class AddsubContext : public ExprContext { - public: - AddsubContext(ExprContext *ctx); + class NumberContext: public ExprContext + { + public: + NumberContext(ExprContext* ctx); - antlr4::Token *op = nullptr; - std::vector expr(); - ExprContext* expr(size_t i); + antlr4::tree::TerminalNode* NUMBER(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class PortFieldContext : public ExprContext { - public: - PortFieldContext(ExprContext *ctx); + class TimeIndexContext: public ExprContext + { + public: + TimeIndexContext(ExprContext* ctx); - std::vector IDENTIFIER(); - antlr4::tree::TerminalNode* IDENTIFIER(size_t i); + antlr4::tree::TerminalNode* IDENTIFIER(); + antlr4::tree::TerminalNode* LBRACKET(); + std::vector expr(); + ExprContext* expr(size_t i); + antlr4::tree::TerminalNode* RBRACKET(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class MuldivContext : public ExprContext { - public: - MuldivContext(ExprContext *ctx); + class TimeShiftContext: public ExprContext + { + public: + TimeShiftContext(ExprContext* ctx); - antlr4::Token *op = nullptr; - std::vector expr(); - ExprContext* expr(size_t i); + antlr4::tree::TerminalNode* IDENTIFIER(); + antlr4::tree::TerminalNode* LBRACKET(); + std::vector shift(); + ShiftContext* shift(size_t i); + antlr4::tree::TerminalNode* RBRACKET(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class NumberContext : public ExprContext { - public: - NumberContext(ExprContext *ctx); + class FunctionContext: public ExprContext + { + public: + FunctionContext(ExprContext* ctx); - antlr4::tree::TerminalNode *NUMBER(); + antlr4::tree::TerminalNode* IDENTIFIER(); + ExprContext* expr(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class TimeIndexContext : public ExprContext { - public: - TimeIndexContext(ExprContext *ctx); + class TimeShiftRangeContext: public ExprContext + { + public: + TimeShiftRangeContext(ExprContext* ctx); - antlr4::tree::TerminalNode *IDENTIFIER(); - antlr4::tree::TerminalNode *LBRACKET(); - std::vector expr(); - ExprContext* expr(size_t i); - antlr4::tree::TerminalNode *RBRACKET(); + ExprParser::ShiftContext* shift1 = nullptr; + ExprParser::ShiftContext* shift2 = nullptr; + antlr4::tree::TerminalNode* IDENTIFIER(); + antlr4::tree::TerminalNode* LBRACKET(); + antlr4::tree::TerminalNode* RBRACKET(); + std::vector shift(); + ShiftContext* shift(size_t i); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class TimeShiftContext : public ExprContext { - public: - TimeShiftContext(ExprContext *ctx); + class TimeRangeContext: public ExprContext + { + public: + TimeRangeContext(ExprContext* ctx); - antlr4::tree::TerminalNode *IDENTIFIER(); - antlr4::tree::TerminalNode *LBRACKET(); - std::vector shift(); - ShiftContext* shift(size_t i); - antlr4::tree::TerminalNode *RBRACKET(); + antlr4::tree::TerminalNode* IDENTIFIER(); + antlr4::tree::TerminalNode* LBRACKET(); + std::vector expr(); + ExprContext* expr(size_t i); + antlr4::tree::TerminalNode* RBRACKET(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; + }; - class FunctionContext : public ExprContext { - public: - FunctionContext(ExprContext *ctx); + ExprContext* expr(); + ExprContext* expr(int precedence); - antlr4::tree::TerminalNode *IDENTIFIER(); - ExprContext *expr(); + bool sempred(antlr4::RuleContext* _localctx, size_t ruleIndex, size_t predicateIndex) override; - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; + bool exprSempred(ExprContext* _localctx, size_t predicateIndex); - class TimeShiftRangeContext : public ExprContext { - public: - TimeShiftRangeContext(ExprContext *ctx); - - ExprParser::ShiftContext *shift1 = nullptr; - ExprParser::ShiftContext *shift2 = nullptr; - antlr4::tree::TerminalNode *IDENTIFIER(); - antlr4::tree::TerminalNode *LBRACKET(); - antlr4::tree::TerminalNode *RBRACKET(); - std::vector shift(); - ShiftContext* shift(size_t i); - - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; - - class TimeRangeContext : public ExprContext { - public: - TimeRangeContext(ExprContext *ctx); - - antlr4::tree::TerminalNode *IDENTIFIER(); - antlr4::tree::TerminalNode *LBRACKET(); - std::vector expr(); - ExprContext* expr(size_t i); - antlr4::tree::TerminalNode *RBRACKET(); - - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - }; - - ExprContext* expr(); - ExprContext* expr(int precedence); - - bool sempred(antlr4::RuleContext *_localctx, size_t ruleIndex, size_t predicateIndex) override; - - bool exprSempred(ExprContext *_localctx, size_t predicateIndex); - - // By default the static state used to implement the parser is lazily initialized during the first - // call to the constructor. You can call this function if you wish to initialize the static state - // ahead of time. - static void initialize(); + // By default the static state used to implement the parser is lazily initialized during the + // first call to the constructor. You can call this function if you wish to initialize the + // static state ahead of time. + static void initialize(); private: }; - diff --git a/src/libs/antares/antlr-interface/ExprVisitor.cpp b/src/libs/antares/antlr-interface/ExprVisitor.cpp index c214f0f76f..bf0de76765 100644 --- a/src/libs/antares/antlr-interface/ExprVisitor.cpp +++ b/src/libs/antares/antlr-interface/ExprVisitor.cpp @@ -1,7 +1,4 @@ // Generated from Expr.g4 by ANTLR 4.13.1 - #include "ExprVisitor.h" - - diff --git a/src/libs/antares/antlr-interface/ExprVisitor.h b/src/libs/antares/antlr-interface/ExprVisitor.h index c064d6d54a..6caed416f5 100644 --- a/src/libs/antares/antlr-interface/ExprVisitor.h +++ b/src/libs/antares/antlr-interface/ExprVisitor.h @@ -3,52 +3,46 @@ #pragma once - -#include "antlr4-runtime.h" #include "ExprParser.h" - - +#include "antlr4-runtime.h" /** * This class defines an abstract visitor for a parse tree * produced by ExprParser. */ -class ExprVisitor : public antlr4::tree::AbstractParseTreeVisitor { +class ExprVisitor: public antlr4::tree::AbstractParseTreeVisitor +{ public: + /** + * Visit parse trees produced by ExprParser. + */ + virtual std::any visitFullexpr(ExprParser::FullexprContext* context) = 0; - /** - * Visit parse trees produced by ExprParser. - */ - virtual std::any visitFullexpr(ExprParser::FullexprContext *context) = 0; + virtual std::any visitShift(ExprParser::ShiftContext* context) = 0; - virtual std::any visitShift(ExprParser::ShiftContext *context) = 0; + virtual std::any visitIdentifier(ExprParser::IdentifierContext* context) = 0; - virtual std::any visitIdentifier(ExprParser::IdentifierContext *context) = 0; + virtual std::any visitNegation(ExprParser::NegationContext* context) = 0; - virtual std::any visitNegation(ExprParser::NegationContext *context) = 0; + virtual std::any visitExpression(ExprParser::ExpressionContext* context) = 0; - virtual std::any visitExpression(ExprParser::ExpressionContext *context) = 0; + virtual std::any visitComparison(ExprParser::ComparisonContext* context) = 0; - virtual std::any visitComparison(ExprParser::ComparisonContext *context) = 0; + virtual std::any visitAddsub(ExprParser::AddsubContext* context) = 0; - virtual std::any visitAddsub(ExprParser::AddsubContext *context) = 0; + virtual std::any visitPortField(ExprParser::PortFieldContext* context) = 0; - virtual std::any visitPortField(ExprParser::PortFieldContext *context) = 0; + virtual std::any visitMuldiv(ExprParser::MuldivContext* context) = 0; - virtual std::any visitMuldiv(ExprParser::MuldivContext *context) = 0; + virtual std::any visitNumber(ExprParser::NumberContext* context) = 0; - virtual std::any visitNumber(ExprParser::NumberContext *context) = 0; + virtual std::any visitTimeIndex(ExprParser::TimeIndexContext* context) = 0; - virtual std::any visitTimeIndex(ExprParser::TimeIndexContext *context) = 0; + virtual std::any visitTimeShift(ExprParser::TimeShiftContext* context) = 0; - virtual std::any visitTimeShift(ExprParser::TimeShiftContext *context) = 0; - - virtual std::any visitFunction(ExprParser::FunctionContext *context) = 0; - - virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext *context) = 0; - - virtual std::any visitTimeRange(ExprParser::TimeRangeContext *context) = 0; + virtual std::any visitFunction(ExprParser::FunctionContext* context) = 0; + virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext* context) = 0; + virtual std::any visitTimeRange(ExprParser::TimeRangeContext* context) = 0; }; - diff --git a/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h b/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h index 113451410f..62352390bc 100644 --- a/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h +++ b/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h @@ -28,7 +28,6 @@ void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode, bool ortoolsUsed, const std::string& solverName); - void checkStudyVersion(const AnyString& optStudyFolder); void checkSimplexRangeHydroPricing(Antares::Data::SimplexOptimization optRange, diff --git a/src/libs/antares/exception/include/antares/exception/LoadingError.hpp b/src/libs/antares/exception/include/antares/exception/LoadingError.hpp index ab1ae664d8..c79b1a791e 100644 --- a/src/libs/antares/exception/include/antares/exception/LoadingError.hpp +++ b/src/libs/antares/exception/include/antares/exception/LoadingError.hpp @@ -130,13 +130,14 @@ class InvalidSolver: public LoadingError explicit InvalidSolver(const std::string& solver, const std::string& availableSolverList); }; -class InvalidSolverSpecificParameters : public LoadingError +class InvalidSolverSpecificParameters: public LoadingError { public: - explicit InvalidSolverSpecificParameters(const std::string& solver, const std::string& specificParameters); + explicit InvalidSolverSpecificParameters(const std::string& solver, + const std::string& specificParameters); }; -class InvalidStudy : public LoadingError +class InvalidStudy: public LoadingError { public: explicit InvalidStudy(const Yuni::String& study); diff --git a/src/libs/antares/file-tree-study-loader/include/antares/file-tree-study-loader/FileTreeStudyLoader.h b/src/libs/antares/file-tree-study-loader/include/antares/file-tree-study-loader/FileTreeStudyLoader.h index 687afa12ae..7b46a95c3a 100644 --- a/src/libs/antares/file-tree-study-loader/include/antares/file-tree-study-loader/FileTreeStudyLoader.h +++ b/src/libs/antares/file-tree-study-loader/include/antares/file-tree-study-loader/FileTreeStudyLoader.h @@ -31,6 +31,7 @@ namespace Data { class Study; } + /** * @class FileTreeStudyLoader * @brief A class to load studies from the file tree. diff --git a/src/libs/antares/inifile/include/antares/inifile/inifile.hxx b/src/libs/antares/inifile/include/antares/inifile/inifile.hxx index 64785d1ece..20498c3ee2 100644 --- a/src/libs/antares/inifile/include/antares/inifile/inifile.hxx +++ b/src/libs/antares/inifile/include/antares/inifile/inifile.hxx @@ -32,7 +32,8 @@ inline bool IniFile::empty() const return not firstSection; } -inline IniFile::Section::Section(const AnyString& name): name(name) +inline IniFile::Section::Section(const AnyString& name): + name(name) { } diff --git a/src/libs/antares/inifile/inifile.cpp b/src/libs/antares/inifile/inifile.cpp index 67190a0654..8cfa6b9607 100644 --- a/src/libs/antares/inifile/inifile.cpp +++ b/src/libs/antares/inifile/inifile.cpp @@ -65,9 +65,8 @@ void IniFile::Section::saveToStream(std::ostream& stream_out, uint64_t& written) stream_out << '[' << name << "]\n"; written += 4 /* []\n\n */ + name.size(); - each([&stream_out, &written](const IniFile::Property& p) { - p.saveToStream(stream_out, written); - }); + each([&stream_out, &written](const IniFile::Property& p) + { p.saveToStream(stream_out, written); }); stream_out << '\n'; } @@ -249,7 +248,7 @@ bool IniFile::open(const fs::path& filename, bool warnings) if (std::ifstream file(filename); file.is_open()) { - if (! readStream(file)) + if (!readStream(file)) { logs.error() << "Invalid INI file : " << filename; return false; @@ -266,9 +265,8 @@ bool IniFile::open(const fs::path& filename, bool warnings) void IniFile::saveToStream(std::ostream& stream_out, uint64_t& written) const { - each([&stream_out, &written](const IniFile::Section& s) { - s.saveToStream(stream_out, written); - }); + each([&stream_out, &written](const IniFile::Section& s) + { s.saveToStream(stream_out, written); }); if (written != 0) { diff --git a/src/libs/antares/io/file.cpp b/src/libs/antares/io/file.cpp index 10bf5b30b9..8ef66b3a3d 100644 --- a/src/libs/antares/io/file.cpp +++ b/src/libs/antares/io/file.cpp @@ -27,13 +27,13 @@ #ifdef YUNI_OS_WINDOWS #include + #include #else #include #include #endif #include - #include #include diff --git a/src/libs/antares/io/include/antares/io/file.h b/src/libs/antares/io/include/antares/io/file.h index e9fd0e91dc..b401b1cece 100644 --- a/src/libs/antares/io/include/antares/io/file.h +++ b/src/libs/antares/io/include/antares/io/file.h @@ -21,10 +21,10 @@ #ifndef __LIBS_ANTARES_IO_FILE_H__ #define __LIBS_ANTARES_IO_FILE_H__ -#include - #include +#include + namespace Antares::IO { /*! diff --git a/src/libs/antares/study-loader/include/antares/study-loader/IStudyLoader.h b/src/libs/antares/study-loader/include/antares/study-loader/IStudyLoader.h index 9b4c710ed4..7d6f25373b 100644 --- a/src/libs/antares/study-loader/include/antares/study-loader/IStudyLoader.h +++ b/src/libs/antares/study-loader/include/antares/study-loader/IStudyLoader.h @@ -29,6 +29,7 @@ namespace Data { class Study; } + /** * @class IStudyLoader * @brief The IStudyLoader class is an interface for loading studies. diff --git a/src/libs/antares/study/area/area.cpp b/src/libs/antares/study/area/area.cpp index da99f973ae..fe2b2b7b75 100644 --- a/src/libs/antares/study/area/area.cpp +++ b/src/libs/antares/study/area/area.cpp @@ -52,19 +52,20 @@ Area::Area(): internalInitialize(); } -Area::Area(const AnyString& name) : Area() +Area::Area(const AnyString& name): + Area() { internalInitialize(); this->name = name; this->id = Antares::transformNameIntoID(this->name); } -Area::Area(const AnyString& name, const AnyString& id) : Area() +Area::Area(const AnyString& name, const AnyString& id): + Area() { internalInitialize(); this->name = name; this->id = Antares::transformNameIntoID(id); - } Area::~Area() diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index 40da9df149..3523643328 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -142,8 +142,8 @@ bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& fol bool AreaLink::loadTSGenTimeSeries(const fs::path& folder) { const std::string idprepro = std::string(from->id) + "/" + std::string(with->id); - tsGeneration.prepro = - std::make_unique(idprepro, tsGeneration.unitCount); + tsGeneration.prepro = std::make_unique(idprepro, + tsGeneration.unitCount); bool anyFileWasLoaded = false; @@ -157,10 +157,10 @@ bool AreaLink::loadTSGenTimeSeries(const fs::path& folder) { anyFileWasLoaded = true; tsGeneration.valid = tsGeneration.prepro->data.loadFromCSVFile( - filepath.string(), - Antares::Data::PreproAvailability::preproAvailabilityMax, - DAYS_PER_YEAR) - && tsGeneration.prepro->validate(); + filepath.string(), + Antares::Data::PreproAvailability::preproAvailabilityMax, + DAYS_PER_YEAR) + && tsGeneration.prepro->validate(); } // Modulation @@ -170,7 +170,7 @@ bool AreaLink::loadTSGenTimeSeries(const fs::path& folder) { anyFileWasLoaded = true; tsGeneration.valid &= tsGeneration.modulationCapacityDirect - .loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR); + .loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR); } filepath = preproFile; @@ -179,7 +179,7 @@ bool AreaLink::loadTSGenTimeSeries(const fs::path& folder) { anyFileWasLoaded = true; tsGeneration.valid &= tsGeneration.modulationCapacityIndirect - .loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR); + .loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR); } if (anyFileWasLoaded) @@ -506,11 +506,8 @@ bool handleKey(Data::AreaLink& link, const String& key, const String& value) return false; } -bool handleTSGenKey(Data::LinkTsGeneration& out, - const std::string& key, - const String& value) +bool handleTSGenKey(Data::LinkTsGeneration& out, const std::string& key, const String& value) { - if (key == "unitcount") { return value.to(out.unitCount); @@ -572,7 +569,11 @@ bool AreaLinksInternalLoadFromProperty(AreaLink& link, const String& key, const } } // anonymous namespace -bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const fs::path& folder, bool loadTSGen) +bool AreaLinksLoadFromFolder(Study& study, + AreaList* l, + Area* area, + const fs::path& folder, + bool loadTSGen) { // Assert assert(area); diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index f76afb5686..181159933b 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -968,8 +968,9 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = hydroSeries->LoadMaxPower(area.id, buffer) && ret; } - hydroSeries->resizeTSinDeratedMode( - study.parameters.derated, studyVersion, study.usedByTheSolver); + hydroSeries->resizeTSinDeratedMode(study.parameters.derated, + studyVersion, + study.usedByTheSolver); } // Wind @@ -1278,7 +1279,7 @@ Area* AreaList::findFromPosition(const int x, const int y) const { auto lastArea = i->second; if (lastArea->ui && std::abs(lastArea->ui->x - x) < nearestDistance - && std::abs(lastArea->ui->y - y) < nearestDistance) + && std::abs(lastArea->ui->y - y) < nearestDistance) { nearestItem = lastArea; } @@ -1326,12 +1327,14 @@ void AreaListEnsureDataLoadPrepro(AreaList* l) /* Asserts */ assert(l); - l->each([](Data::Area& area) { - if (!area.load.prepro) - { - area.load.prepro = new Antares::Data::Load::Prepro(); - } - }); + l->each( + [](Data::Area& area) + { + if (!area.load.prepro) + { + area.load.prepro = new Antares::Data::Load::Prepro(); + } + }); } void AreaListEnsureDataSolarPrepro(AreaList* l) diff --git a/src/libs/antares/study/binding_constraint/BindingConstraintGroupRepository.cpp b/src/libs/antares/study/binding_constraint/BindingConstraintGroupRepository.cpp index ff181e7ed8..b29ad4fba2 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraintGroupRepository.cpp +++ b/src/libs/antares/study/binding_constraint/BindingConstraintGroupRepository.cpp @@ -60,7 +60,9 @@ bool BindingConstraintGroupRepository::buildFrom(const BindingConstraintsReposit bool BindingConstraintGroupRepository::timeSeriesWidthConsistentInGroups() const { - bool allConsistent = !std::ranges::any_of(groups_, [](const auto& group) + bool allConsistent = !std::ranges::any_of( + groups_, + [](const auto& group) { const auto& constraints = group->constraints(); if (constraints.empty()) @@ -68,7 +70,8 @@ bool BindingConstraintGroupRepository::timeSeriesWidthConsistentInGroups() const return false; } auto width = (*constraints.begin())->RHSTimeSeries().width; - bool isConsistent = std::ranges::all_of(constraints, + bool isConsistent = std::ranges::all_of( + constraints, [&width](const std::shared_ptr& bc) { bool sameWidth = bc->RHSTimeSeries().width == width; @@ -89,15 +92,16 @@ bool BindingConstraintGroupRepository::timeSeriesWidthConsistentInGroups() const void BindingConstraintGroupRepository::resizeAllTimeseriesNumbers(unsigned int nb_years) { - std::ranges::for_each(groups_, [&nb_years](auto& group) - { group->timeseriesNumbers.reset(nb_years); }); + std::ranges::for_each(groups_, + [&nb_years](auto& group) { group->timeseriesNumbers.reset(nb_years); }); } BindingConstraintGroup* BindingConstraintGroupRepository::operator[](const std::string& name) const { - if (auto group = std::ranges::find_if(groups_, [&name](auto& group_of_constraint) - { return group_of_constraint->name() == name; }); - group != groups_.end()) + if (auto group = std::ranges::find_if(groups_, + [&name](auto& group_of_constraint) + { return group_of_constraint->name() == name; }); + group != groups_.end()) { return group->get(); } diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 7d1aadf58e..3fa46cf4b5 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -391,7 +391,6 @@ bool listOfFilesAnDirectoriesToKeep(StudyCleaningInfos* infos) buffer.clear() << infos->folder << "/input/bindingconstraints/bindingconstraints.ini"; if (ini.open(buffer)) { - ini.each( [&e](const IniFile::Section& section) { diff --git a/src/libs/antares/study/include/antares/study/parameters.h b/src/libs/antares/study/include/antares/study/parameters.h index 791e20f865..1eacc026bb 100644 --- a/src/libs/antares/study/include/antares/study/parameters.h +++ b/src/libs/antares/study/include/antares/study/parameters.h @@ -504,8 +504,7 @@ class Parameters final private: //! Load data from an INI file - bool loadFromINI(const IniFile& ini, - const StudyVersion& version); + bool loadFromINI(const IniFile& ini, const StudyVersion& version); void resetPlayedYears(uint nbOfYears); diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/container.h b/src/libs/antares/study/include/antares/study/parts/hydro/container.h index e09970b79c..9d80ce4369 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/include/antares/study/parts/hydro/container.h @@ -22,6 +22,7 @@ #define __ANTARES_LIBS_STUDY_PARTS_HYDRO_CONTAINER_H__ #include + #include "../../fwd.h" #include "allocation.h" #include "prepro.h" @@ -178,9 +179,7 @@ class PartHydro // As this function can be called a lot of times, we pass working variables and returned variables // as arguments, so that we don't have to create them locally (as in a classical function) each // time. -double getWaterValue(const double& level, - const Matrix& waterValues, - const uint day); +double getWaterValue(const double& level, const Matrix& waterValues, const uint day); // Interpolates a rate from the credit modulation table according to a level double getWeeklyModulation(const double& level /* format : in % of reservoir capacity */, diff --git a/src/libs/antares/study/include/antares/study/scenario-builder/hydroLevelsData.h b/src/libs/antares/study/include/antares/study/scenario-builder/hydroLevelsData.h index 42aff6336a..b5cb21073d 100644 --- a/src/libs/antares/study/include/antares/study/scenario-builder/hydroLevelsData.h +++ b/src/libs/antares/study/include/antares/study/scenario-builder/hydroLevelsData.h @@ -21,9 +21,10 @@ #ifndef __LIBS_STUDY_SCENARIO_BUILDER_DATA_HYDRO_LEVELS_H__ #define __LIBS_STUDY_SCENARIO_BUILDER_DATA_HYDRO_LEVELS_H__ -#include "scBuilderDataInterface.h" #include +#include "scBuilderDataInterface.h" + namespace Antares { namespace Data diff --git a/src/libs/antares/study/include/antares/study/sets.hxx b/src/libs/antares/study/include/antares/study/sets.hxx index d2976252cc..df1f9cff93 100644 --- a/src/libs/antares/study/include/antares/study/sets.hxx +++ b/src/libs/antares/study/include/antares/study/sets.hxx @@ -288,8 +288,8 @@ bool Sets::loadFromFile(const std::filesystem::path& filename) continue; } - logs.warning() << "sets: `" << filename << "`: Invalid property `" - << p->key << '\''; + logs.warning() << "sets: `" << filename << "`: Invalid property `" << p->key + << '\''; } // Add the new group diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index 7337b9c8b0..2f4c0b30b1 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -1109,10 +1109,16 @@ static bool SGDIntLoadFamily_Legacy(Parameters& d, if (key == "initial-reservoir-levels") // ignored since 9.2 { - if (version >= StudyVersion(9,2)) - logs.warning() << "Option initial-reservoir-levels is deprecated, please remove it from the study"; + if (version >= StudyVersion(9, 2)) + { + logs.warning() + << "Option initial-reservoir-levels is deprecated, please remove it from the study"; + } else if (value == "hot start") - logs.warning() << "Hydro hot start not supported with this solver, please use a version < 9.2"; + { + logs.warning() + << "Hydro hot start not supported with this solver, please use a version < 9.2"; + } return true; } @@ -1125,8 +1131,7 @@ bool firstKeyLetterIsValid(const String& name) return (firstLetter >= 'a' && firstLetter <= 'z'); } -bool Parameters::loadFromINI(const IniFile& ini, - const StudyVersion& version) +bool Parameters::loadFromINI(const IniFile& ini, const StudyVersion& version) { // Reset inner data reset(); @@ -1292,7 +1297,9 @@ void Parameters::fixBadValues() } if (simulationDays.first == 0) + { simulationDays.first = 1; + } else { simulationDays.first = std::clamp(simulationDays.first, 1u, 365u); diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 9be5c2ca57..9c39ca7c8b 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -263,8 +263,9 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons template bool ClusterList::loadDataSeriesFromFolder(Study& s, const AnyString& folder) { - return std::ranges::all_of(allClusters_, [&s, &folder](auto c) - { return c->loadDataSeriesFromFolder(s, folder); }); + return std::ranges::all_of(allClusters_, + [&s, &folder](auto c) + { return c->loadDataSeriesFromFolder(s, folder); }); } template diff --git a/src/libs/antares/study/parts/hydro/allocation.cpp b/src/libs/antares/study/parts/hydro/allocation.cpp index 597264cf20..052bc3411d 100644 --- a/src/libs/antares/study/parts/hydro/allocation.cpp +++ b/src/libs/antares/study/parts/hydro/allocation.cpp @@ -164,8 +164,7 @@ void HydroAllocation::clear() #endif } -bool HydroAllocation::loadFromFile(const AreaName& referencearea, - const fs::path& filename) +bool HydroAllocation::loadFromFile(const AreaName& referencearea, const fs::path& filename) { clear(); @@ -177,21 +176,24 @@ bool HydroAllocation::loadFromFile(const AreaName& referencearea, } if (ini.empty()) + { return true; + } - ini.each([this](const IniFile::Section& section) - { - for (auto* p = section.firstProperty; p; p = p->next) - { - double coeff = p->value.to(); - if (!Utils::isZero(coeff)) - { - AreaName areaname = p->key; - areaname.toLower(); - pValues[areaname] = coeff; - } - } - }); + ini.each( + [this](const IniFile::Section& section) + { + for (auto* p = section.firstProperty; p; p = p->next) + { + double coeff = p->value.to(); + if (!Utils::isZero(coeff)) + { + AreaName areaname = p->key; + areaname.toLower(); + pValues[areaname] = coeff; + } + } + }); return true; } diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index c9dc476de5..e98d94bee4 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -32,7 +32,7 @@ using namespace Yuni; namespace Antares::Data { -PartHydro::PartHydro(const Data::Area& area) : +PartHydro::PartHydro(const Data::Area& area): interDailyBreakdown(0.), intraDailyModulation(2.), intermonthlyBreakdown(0), @@ -113,7 +113,9 @@ static bool loadProperties(Study& study, T PartHydro::*ptr) { if (!property) + { return false; + } bool ret = true; @@ -242,52 +244,74 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) if (IniFile::Section* section = ini.find("inter-daily-breakdown")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::interDailyBreakdown) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::interDailyBreakdown) + && ret; } if (IniFile::Section* section = ini.find("intra-daily-modulation")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::intraDailyModulation) && ret; + ret = loadProperties(study, + section->firstProperty, + buffer, + &PartHydro::intraDailyModulation) + && ret; } if (IniFile::Section* section = ini.find("reservoir")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirManagement) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirManagement) + && ret; } if (IniFile::Section* section = ini.find("reservoir capacity")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirCapacity) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirCapacity) + && ret; } if (IniFile::Section* section = ini.find("follow load")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::followLoadModulations) && ret; + ret = loadProperties(study, + section->firstProperty, + buffer, + &PartHydro::followLoadModulations) + && ret; } if (IniFile::Section* section = ini.find("use water")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useWaterValue) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useWaterValue) + && ret; } if (IniFile::Section* section = ini.find("hard bounds")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::hardBoundsOnRuleCurves) && ret; + ret = loadProperties(study, + section->firstProperty, + buffer, + &PartHydro::hardBoundsOnRuleCurves) + && ret; } if (IniFile::Section* section = ini.find("use heuristic")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useHeuristicTarget) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useHeuristicTarget) + && ret; } if (IniFile::Section* section = ini.find("power to level")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::powerToLevel) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::powerToLevel) + && ret; } if (IniFile::Section* section = ini.find("initialize reservoir date")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::initializeReservoirLevelDate) && ret; + ret = loadProperties(study, + section->firstProperty, + buffer, + &PartHydro::initializeReservoirLevelDate) + && ret; } if (IniFile::Section* section = ini.find("use leeway")) @@ -297,17 +321,20 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) if (IniFile::Section* section = ini.find("leeway low")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayLowerBound) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayLowerBound) + && ret; } if (IniFile::Section* section = ini.find("leeway up")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayUpperBound) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayUpperBound) + && ret; } if (IniFile::Section* section = ini.find("pumping efficiency")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::pumpingEfficiency) && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::pumpingEfficiency) + && ret; } return ret; @@ -317,10 +344,12 @@ bool PartHydro::checkReservoirLevels(const Study& study) { bool ret = true; - for (const auto& [areaName, area] : study.areas) + for (const auto& [areaName, area]: study.areas) { if (!study.usedByTheSolver) + { return true; + } auto& col = area->hydro.inflowPattern[0]; bool errorInflow = false; @@ -340,8 +369,8 @@ bool PartHydro::checkReservoirLevels(const Study& study) for (unsigned int day = 0; day < DAYS_PER_YEAR; day++) { if (!errorLevels - && (colMin[day] < 0 || colAvg[day] < 0 || colMin[day] > colMax[day] - || colAvg[day] > 100 || colMax[day] > 100)) + && (colMin[day] < 0 || colAvg[day] < 0 || colMin[day] > colMax[day] + || colAvg[day] > 100 || colMax[day] > 100)) { logs.error() << areaName << ": invalid reservoir level value"; errorLevels = true; @@ -352,7 +381,7 @@ bool PartHydro::checkReservoirLevels(const Study& study) for (int i = 0; i < 101; i++) { if ((area->hydro.creditModulation[i][0] < 0) - || (area->hydro.creditModulation[i][1] < 0)) + || (area->hydro.creditModulation[i][1] < 0)) { logs.error() << areaName << ": invalid credit modulation value"; ret = false; @@ -372,75 +401,73 @@ bool PartHydro::checkProperties(Study& study) // the study, because they are too small (< 1e-6). We cannot have reservoir management = yes and // capacity = 0 because of further division by capacity. reservoir management = no and capacity // = 0 is possible (no use of capacity further) - study.areas.each([&ret](Data::Area& area) - { - if (area.hydro.reservoirCapacity < 1e-3 && area.hydro.reservoirManagement) - { - logs.error() << area.name - << ": reservoir capacity not defined. Impossible to manage."; - ret = false; - } + study.areas.each( + [&ret](Data::Area& area) + { + if (area.hydro.reservoirCapacity < 1e-3 && area.hydro.reservoirManagement) + { + logs.error() << area.name + << ": reservoir capacity not defined. Impossible to manage."; + ret = false; + } - if (!area.hydro.useHeuristicTarget && !area.hydro.useWaterValue) - { - logs.error() << area.name - << " : use water value = no conflicts with use heuristic target = no"; - ret = false; - } + if (!area.hydro.useHeuristicTarget && !area.hydro.useWaterValue) + { + logs.error() << area.name + << " : use water value = no conflicts with use heuristic target = no"; + ret = false; + } - if (area.hydro.intraDailyModulation < 1.) - { - logs.error() - << area.id << ": Invalid intra-daily modulation. It must be >= 1.0, Got " - << area.hydro.intraDailyModulation << " (truncated to 1)"; - area.hydro.intraDailyModulation = 1.; - } + if (area.hydro.intraDailyModulation < 1.) + { + logs.error() << area.id << ": Invalid intra-daily modulation. It must be >= 1.0, Got " + << area.hydro.intraDailyModulation << " (truncated to 1)"; + area.hydro.intraDailyModulation = 1.; + } - if (area.hydro.reservoirCapacity < 0) - { - logs.error() << area.id << ": Invalid reservoir capacity."; - area.hydro.reservoirCapacity = 0.; - } + if (area.hydro.reservoirCapacity < 0) + { + logs.error() << area.id << ": Invalid reservoir capacity."; + area.hydro.reservoirCapacity = 0.; + } - if (area.hydro.intermonthlyBreakdown < 0) - { - logs.error() << area.id << ": Invalid intermonthly breakdown"; - area.hydro.intermonthlyBreakdown = 0.; - } + if (area.hydro.intermonthlyBreakdown < 0) + { + logs.error() << area.id << ": Invalid intermonthly breakdown"; + area.hydro.intermonthlyBreakdown = 0.; + } - if (area.hydro.initializeReservoirLevelDate < 0) - { - logs.error() << area.id << ": Invalid initialize reservoir date"; - area.hydro.initializeReservoirLevelDate = 0; - } + if (area.hydro.initializeReservoirLevelDate < 0) + { + logs.error() << area.id << ": Invalid initialize reservoir date"; + area.hydro.initializeReservoirLevelDate = 0; + } - if (area.hydro.leewayLowerBound < 0.) - { - logs.error() - << area.id << ": Invalid leeway lower bound. It must be >= 0.0, Got " - << area.hydro.leewayLowerBound; - area.hydro.leewayLowerBound = 0.; - } + if (area.hydro.leewayLowerBound < 0.) + { + logs.error() << area.id << ": Invalid leeway lower bound. It must be >= 0.0, Got " + << area.hydro.leewayLowerBound; + area.hydro.leewayLowerBound = 0.; + } - if (area.hydro.leewayUpperBound < 0.) - { - logs.error() - << area.id << ": Invalid leeway upper bound. It must be >= 0.0, Got " - << area.hydro.leewayUpperBound; - area.hydro.leewayUpperBound = 0.; - } + if (area.hydro.leewayUpperBound < 0.) + { + logs.error() << area.id << ": Invalid leeway upper bound. It must be >= 0.0, Got " + << area.hydro.leewayUpperBound; + area.hydro.leewayUpperBound = 0.; + } - if (area.hydro.leewayLowerBound > area.hydro.leewayUpperBound) - { + if (area.hydro.leewayLowerBound > area.hydro.leewayUpperBound) + { logs.error() << area.id << ": Leeway lower bound greater than leeway upper bound."; - } + } - if (area.hydro.pumpingEfficiency < 0) - { - logs.error() << area.id << ": Invalid pumping efficiency"; - area.hydro.pumpingEfficiency = 0.; - } - }); + if (area.hydro.pumpingEfficiency < 0) + { + logs.error() << area.id << ": Invalid pumping efficiency"; + area.hydro.pumpingEfficiency = 0.; + } + }); return ret; } @@ -465,40 +492,40 @@ bool PartHydro::SaveToFolder(const AreaList& areas, const AnyString& folder) struct AllSections { - IniFile::Section* s; - IniFile::Section* smod; - IniFile::Section* sIMB; - IniFile::Section* sreservoir; - IniFile::Section* sreservoirCapacity; - IniFile::Section* sFollowLoad; - IniFile::Section* sUseWater; - IniFile::Section* sHardBounds; - IniFile::Section* sInitializeReservoirDate; - IniFile::Section* sUseHeuristic; - IniFile::Section* sUseLeeway; - IniFile::Section* sPowerToLevel; - IniFile::Section* sLeewayLow; - IniFile::Section* sLeewayUp; - IniFile::Section* spumpingEfficiency; - - AllSections(IniFile& ini) : - s(ini.addSection("inter-daily-breakdown")), - smod(ini.addSection("intra-daily-modulation")), - sIMB(ini.addSection("inter-monthly-breakdown")), - sreservoir(ini.addSection("reservoir")), - sreservoirCapacity(ini.addSection("reservoir capacity")), - sFollowLoad(ini.addSection("follow load")), - sUseWater(ini.addSection("use water")), - sHardBounds(ini.addSection("hard bounds")), - sInitializeReservoirDate(ini.addSection("initialize reservoir date")), - sUseHeuristic(ini.addSection("use heuristic")), - sUseLeeway(ini.addSection("use leeway")), - sPowerToLevel(ini.addSection("power to level")), - sLeewayLow(ini.addSection("leeway low")), - sLeewayUp(ini.addSection("leeway up")), - spumpingEfficiency(ini.addSection("pumping efficiency")) + IniFile::Section* s; + IniFile::Section* smod; + IniFile::Section* sIMB; + IniFile::Section* sreservoir; + IniFile::Section* sreservoirCapacity; + IniFile::Section* sFollowLoad; + IniFile::Section* sUseWater; + IniFile::Section* sHardBounds; + IniFile::Section* sInitializeReservoirDate; + IniFile::Section* sUseHeuristic; + IniFile::Section* sUseLeeway; + IniFile::Section* sPowerToLevel; + IniFile::Section* sLeewayLow; + IniFile::Section* sLeewayUp; + IniFile::Section* spumpingEfficiency; + + AllSections(IniFile& ini): + s(ini.addSection("inter-daily-breakdown")), + smod(ini.addSection("intra-daily-modulation")), + sIMB(ini.addSection("inter-monthly-breakdown")), + sreservoir(ini.addSection("reservoir")), + sreservoirCapacity(ini.addSection("reservoir capacity")), + sFollowLoad(ini.addSection("follow load")), + sUseWater(ini.addSection("use water")), + sHardBounds(ini.addSection("hard bounds")), + sInitializeReservoirDate(ini.addSection("initialize reservoir date")), + sUseHeuristic(ini.addSection("use heuristic")), + sUseLeeway(ini.addSection("use leeway")), + sPowerToLevel(ini.addSection("power to level")), + sLeewayLow(ini.addSection("leeway low")), + sLeewayUp(ini.addSection("leeway up")), + spumpingEfficiency(ini.addSection("pumping efficiency")) { - } + } }; // Init @@ -515,7 +542,8 @@ bool PartHydro::SaveToFolder(const AreaList& areas, const AnyString& folder) allSections.s->add(area.id, area.hydro.interDailyBreakdown); allSections.smod->add(area.id, area.hydro.intraDailyModulation); allSections.sIMB->add(area.id, area.hydro.intermonthlyBreakdown); - allSections.sInitializeReservoirDate->add(area.id, area.hydro.initializeReservoirLevelDate); + allSections.sInitializeReservoirDate->add(area.id, + area.hydro.initializeReservoirLevelDate); allSections.sLeewayLow->add(area.id, area.hydro.leewayLowerBound); allSections.sLeewayUp->add(area.id, area.hydro.leewayUpperBound); allSections.spumpingEfficiency->add(area.id, area.hydro.pumpingEfficiency); @@ -740,8 +768,8 @@ bool PartHydro::CheckDailyMaxEnergy(const AnyString& areaName) } double getWaterValue(const double& level /* format : in % of reservoir capacity */, - const Matrix& waterValues, - const uint day) + const Matrix& waterValues, + const uint day) { assert((level >= 0. && level <= 100.) && "getWaterValue function : invalid level"); double levelUp = ceil(level); @@ -752,7 +780,7 @@ double getWaterValue(const double& level /* format : in % of reservoir capacity return waterValues[(int)(levelUp)][day]; } return waterValues[(int)(levelUp)][day] * (level - levelDown) - + waterValues[(int)(levelDown)][day] * (levelUp - level); + + waterValues[(int)(levelDown)][day] * (levelUp - level); } double getWeeklyModulation(const double& level /* format : in % of reservoir capacity */, diff --git a/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp b/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp index 2229f75f97..5aa233fedb 100644 --- a/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp +++ b/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp @@ -37,8 +37,8 @@ FinalLevelValidator::FinalLevelValidator(PartHydro& hydro, double finalLevel, const unsigned int year, const unsigned int lastSimulationDay, - const unsigned int firstMonthOfSimulation) - : hydro_(hydro), + const unsigned int firstMonthOfSimulation): + hydro_(hydro), areaName_(areaName), areaIndex_(areaIndex), initialLevel_(initialLevel), @@ -52,36 +52,46 @@ FinalLevelValidator::FinalLevelValidator(PartHydro& hydro, bool FinalLevelValidator::check() { if (skippingFinalLevelUse()) + { return true; - if (! checkForInfeasibility()) + } + if (!checkForInfeasibility()) + { return false; + } finalLevelFineForUse_ = true; return true; } bool FinalLevelValidator::skippingFinalLevelUse() { - if(! wasSetInScenarioBuilder()) + if (!wasSetInScenarioBuilder()) + { return true; - if (! compatibleWithReservoirProperties()) + } + if (!compatibleWithReservoirProperties()) + { return true; + } return false; } bool FinalLevelValidator::wasSetInScenarioBuilder() { - return ! isnan(finalLevel_); + return !isnan(finalLevel_); } bool FinalLevelValidator::compatibleWithReservoirProperties() { if (hydro_.reservoirManagement && !hydro_.useWaterValue) + { return true; + } - logs.warning() << "Final reservoir level not applicable! Year:" << year_ + 1 - << ", Area:" << areaName_ - << ". Check: Reservoir management = Yes, Use water values = No and proper initial " - "reservoir level is provided "; + logs.warning() + << "Final reservoir level not applicable! Year:" << year_ + 1 << ", Area:" << areaName_ + << ". Check: Reservoir management = Yes, Use water values = No and proper initial " + "reservoir level is provided "; return false; } @@ -98,10 +108,12 @@ bool FinalLevelValidator::hydroAllocationStartMatchesSimulation() const { int initReservoirLvlMonth = hydro_.initializeReservoirLevelDate; // month [0-11] if (lastSimulationDay_ == DAYS_PER_YEAR && initReservoirLvlMonth == firstMonthOfSimulation_) + { return true; + } - logs.error() << "Year " << year_ + 1 << ", area '" << areaName_ << "' : " - << "Hydro allocation must start on the 1st simulation month and " + logs.error() << "Year " << year_ + 1 << ", area '" << areaName_ + << "' : " << "Hydro allocation must start on the 1st simulation month and " << "simulation last a whole year"; return false; } @@ -115,8 +127,8 @@ bool FinalLevelValidator::isFinalLevelReachable() const { logs.error() << "Year: " << year_ + 1 << ". Area: " << areaName_ << ". Incompatible total inflows: " << totalYearInflows - << " with initial: " << initialLevel_ - << " and final: " << finalLevel_ << " reservoir levels."; + << " with initial: " << initialLevel_ << " and final: " << finalLevel_ + << " reservoir levels."; return false; } return true; @@ -125,17 +137,19 @@ bool FinalLevelValidator::isFinalLevelReachable() const double FinalLevelValidator::calculateTotalInflows() const { // calculate yearly inflows - auto const& srcinflows = hydro_.series->storage.getColumn(year_); + const auto& srcinflows = hydro_.series->storage.getColumn(year_); double totalYearInflows = 0.0; for (unsigned int day = 0; day < DAYS_PER_YEAR; ++day) + { totalYearInflows += srcinflows[day]; + } return totalYearInflows; } bool FinalLevelValidator::isBetweenRuleCurves() const { - double lowLevelLastDay = hydro_.reservoirLevel[Data::PartHydro::minimum][DAYS_PER_YEAR - 1]; + double lowLevelLastDay = hydro_.reservoirLevel[Data::PartHydro::minimum][DAYS_PER_YEAR - 1]; double highLevelLastDay = hydro_.reservoirLevel[Data::PartHydro::maximum][DAYS_PER_YEAR - 1]; if (finalLevel_ < lowLevelLastDay || finalLevel_ > highLevelLastDay) diff --git a/src/libs/antares/study/parts/hydro/prepro.cpp b/src/libs/antares/study/parts/hydro/prepro.cpp index 9370c562fa..13711759f4 100644 --- a/src/libs/antares/study/parts/hydro/prepro.cpp +++ b/src/libs/antares/study/parts/hydro/prepro.cpp @@ -151,6 +151,7 @@ bool PreproHydro::loadFromFolder(Study& s, const AreaName& areaID, const std::st { mtrxOption = Matrix<>::optFixedSize | Matrix<>::optImmediate, }; + constexpr int maxNbOfLineToLoad = 12; data.resize(hydroPreproMax, 12, true); @@ -160,7 +161,8 @@ bool PreproHydro::loadFromFolder(Study& s, const AreaName& areaID, const std::st bool ret = PreproHydroLoadSettings(this, buffer); buffer.clear() << folder << SEP << areaID << SEP << "energy.txt"; - ret = data.loadFromCSVFile(buffer, hydroPreproMax, maxNbOfLineToLoad, mtrxOption, &s.dataBuffer) && ret; + ret = data.loadFromCSVFile(buffer, hydroPreproMax, maxNbOfLineToLoad, mtrxOption, &s.dataBuffer) + && ret; return ret; } @@ -203,8 +205,8 @@ bool PreproHydro::validate(const std::string& areaID) { ret = false; logs.error() << "Hydro: Prepro: `" << areaID - << "`: minimum energy: At least one value is negative (line: " - << (i + 1) << ')'; + << "`: minimum energy: At least one value is negative (line: " << (i + 1) + << ')'; continue; } if (colMin[i] > colMax[i]) diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 3eda6d5fc3..8c73772565 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -54,7 +54,7 @@ static void ConvertDailyTSintoHourlyTS(const Matrix::ColumnType& dailyCo { uint hour = 0; uint day = 0; - + while (hour < HOURS_PER_YEAR && day < DAYS_PER_YEAR) { for (uint i = 0; i < HOURS_PER_DAY; ++i) diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index 62db61a900..aa1c915a75 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -223,7 +223,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) bool RenewableClusterList::validateClusters() const { bool ret = true; - for (const auto& cluster : allClusters_) + for (const auto& cluster: allClusters_) { ret = cluster->integrityCheck() && ret; } diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index 749613a14b..9a27233064 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -37,8 +37,7 @@ namespace Antares::Data::ShortTermStorage { bool STStorageInput::validate() const { - return std::ranges::all_of(storagesByIndex, [](auto& cluster) - { return cluster.validate(); }); + return std::ranges::all_of(storagesByIndex, [](auto& cluster) { return cluster.validate(); }); } bool STStorageInput::createSTStorageClustersFromIniFile(const fs::path& path) @@ -68,8 +67,9 @@ bool STStorageInput::createSTStorageClustersFromIniFile(const fs::path& path) storagesByIndex.push_back(cluster); } - std::ranges::sort(storagesByIndex, [](const auto& a, const auto& b) - { return a.properties.name < b.properties.name; }); + std::ranges::sort(storagesByIndex, + [](const auto& a, const auto& b) + { return a.properties.name < b.properties.name; }); return true; } @@ -100,8 +100,8 @@ bool STStorageInput::saveToFolder(const std::string& folder) const IniFile ini; logs.debug() << "saving file " << pathIni; - std::ranges::for_each(storagesByIndex, [&ini](auto& storage) - { return storage.saveProperties(ini); }); + std::ranges::for_each(storagesByIndex, + [&ini](auto& storage) { return storage.saveProperties(ini); }); return ini.save(pathIni); } @@ -109,20 +109,20 @@ bool STStorageInput::saveToFolder(const std::string& folder) const bool STStorageInput::saveDataSeriesToFolder(const std::string& folder) const { Yuni::IO::Directory::Create(folder); - return std::ranges::all_of(storagesByIndex, [&folder](auto& storage) - { return storage.saveSeries(folder + SEP + storage.id); }); + return std::ranges::all_of(storagesByIndex, + [&folder](auto& storage) + { return storage.saveSeries(folder + SEP + storage.id); }); } std::size_t STStorageInput::count() const { - return std::ranges::count_if(storagesByIndex, [](const STStorageCluster& st) - { return st.properties.enabled; }); + return std::ranges::count_if(storagesByIndex, + [](const STStorageCluster& st) { return st.properties.enabled; }); } uint STStorageInput::removeDisabledClusters() { - return std::erase_if(storagesByIndex, [](const auto& c) - { return !c.enabled(); }); + return std::erase_if(storagesByIndex, [](const auto& c) { return !c.enabled(); }); } } // namespace Antares::Data::ShortTermStorage diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 4bf2e042c2..8435870d0a 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -162,7 +162,8 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A ret = cluster->modulation.loadFromCSVFile(modulationFile, thermalModulationMax, HOURS_PER_YEAR, - options) && ret; + options) + && ret; // Check the data integrity of the cluster addToCompleteList(cluster); @@ -174,12 +175,11 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A return ret; } - bool ThermalClusterList::validateClusters(const Parameters& parameters) const { bool ret = true; - for (const auto& cluster : allClusters_) + for (const auto& cluster: allClusters_) { cluster->minUpTime = std::clamp(cluster->minUpTime, 1u, 168u); cluster->minDownTime = std::clamp(cluster->minDownTime, 1u, 168u); @@ -206,7 +206,6 @@ bool ThermalClusterList::validateClusters(const Parameters& parameters) const cluster->nominalCapacityWithSpinning = cluster->nominalCapacity; ret = cluster->integrityCheck() && ret; - } return ret; @@ -377,7 +376,7 @@ void ThermalClusterList::reverseCalculationOfSpinning() void ThermalClusterList::enableMustrunForEveryone() { - for (const auto& c : allClusters_) + for (const auto& c: allClusters_) { c->mustrun = true; } @@ -541,7 +540,6 @@ bool ThermalClusterList::saveToFolder(const AnyString& folder) const { ret = false; } - } // Write the ini file @@ -598,27 +596,32 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, const AnyString& fol return std::ranges::all_of(allClusters_ | std::views::filter(hasPrepro), loadPrepro); } -bool ThermalClusterList::validatePrepro(const Study& study) { +bool ThermalClusterList::validatePrepro(const Study& study) +{ auto hasPrepro = [](auto c) { return (bool)c->prepro; }; - const bool globalThermalTSgeneration = - study.parameters.timeSeriesToGenerate & timeSeriesThermal; + const bool globalThermalTSgeneration = study.parameters.timeSeriesToGenerate + & timeSeriesThermal; if (!study.usedByTheSolver) + { return true; + } - return std::ranges::all_of( - allClusters_ | std::views::filter(hasPrepro), - [&globalThermalTSgeneration](auto& c) { - if (globalThermalTSgeneration && !c->prepro->validate()) { - return false; - } - - if (c->doWeGenerateTS(globalThermalTSgeneration)) { - return c->prepro->normalizeAndCheckNPO(); - } - return true; - }); + return std::ranges::all_of(allClusters_ | std::views::filter(hasPrepro), + [&globalThermalTSgeneration](auto& c) + { + if (globalThermalTSgeneration && !c->prepro->validate()) + { + return false; + } + + if (c->doWeGenerateTS(globalThermalTSgeneration)) + { + return c->prepro->normalizeAndCheckNPO(); + } + return true; + }); } bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder) diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 035faf86ac..c094450243 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -213,8 +213,7 @@ void StudyRuntimeInfos::initializeRangeLimits(const Study& study, StudyRangeLimi } else { - simulationDaysPerMonth[ca.month] = study.calendar.months[ca.month].days - - ca.dayMonth; + simulationDaysPerMonth[ca.month] = study.calendar.months[ca.month].days - ca.dayMonth; simulationDaysPerMonth[cb.month] = cb.dayMonth + 1; for (uint i = ca.month + 1; i < cb.month; ++i) { @@ -441,7 +440,8 @@ void StudyRangeLimits::checkIntegrity() const void StudyRuntimeInfos::disableAllFilters(Study& study) { - study.areas.each([](Data::Area& area) + study.areas.each( + [](Data::Area& area) { area.filterSynthesis = filterAll; area.filterYearByYear = filterAll; diff --git a/src/libs/antares/study/scenario-builder/BindingConstraintsTSNumbersData.cpp b/src/libs/antares/study/scenario-builder/BindingConstraintsTSNumbersData.cpp index 46a0694a58..5ffef13e98 100644 --- a/src/libs/antares/study/scenario-builder/BindingConstraintsTSNumbersData.cpp +++ b/src/libs/antares/study/scenario-builder/BindingConstraintsTSNumbersData.cpp @@ -81,11 +81,11 @@ bool BindingConstraintsTSNumberData::reset(const Study& study) { const uint nbYears = study.parameters.nbYears; std::ranges::for_each(study.bindingConstraintsGroups, - [this, &nbYears](const auto& group) - { - auto& ts_numbers = rules_[group->name()]; - ts_numbers.reset(1, nbYears); - }); + [this, &nbYears](const auto& group) + { + auto& ts_numbers = rules_[group->name()]; + ts_numbers.reset(1, nbYears); + }); return true; } diff --git a/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp b/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp index 3295df4503..8d0575b96a 100644 --- a/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp +++ b/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp @@ -29,9 +29,9 @@ namespace Antares::Data::ScenarioBuilder { hydroLevelsData::hydroLevelsData(const std::string& iniFilePrefix, - std::function applyToTarget) : - addToPrefix_(iniFilePrefix), - applyToTarget_(applyToTarget) + std::function applyToTarget): + addToPrefix_(iniFilePrefix), + applyToTarget_(applyToTarget) { } diff --git a/src/libs/antares/study/scenario-builder/rules.cpp b/src/libs/antares/study/scenario-builder/rules.cpp index fd79f07f7c..2037eede6b 100644 --- a/src/libs/antares/study/scenario-builder/rules.cpp +++ b/src/libs/antares/study/scenario-builder/rules.cpp @@ -288,7 +288,9 @@ bool Rules::readFinalHydroLevels(const AreaName::Vector& splitKey, String value, const Data::Area* area = getArea(areaname, updaterMode); if (!area) + { return false; + } double finalLevel = fromStringToHydroLevel(value, 1.); hydroFinalLevels.setTSnumber(area->index, year, finalLevel); @@ -450,8 +452,7 @@ bool Rules::apply() void Rules::sendWarningsForDisabledClusters() { - for (auto it = disabledClustersOnRuleActive.begin(); - it != disabledClustersOnRuleActive.end(); + for (auto it = disabledClustersOnRuleActive.begin(); it != disabledClustersOnRuleActive.end(); it++) { std::vector& scenariiForCurrentCluster = it->second; diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 511e61a592..5b1dde8c5f 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -856,7 +856,8 @@ void Study::areaDelete(Area::Vector& arealist) << area.name; // Updating all hydro allocation - areas.each([&area](Data::Area& areait) { areait.hydro.allocation.remove(area.id); }); + areas.each([&area](Data::Area& areait) + { areait.hydro.allocation.remove(area.id); }); // Remove all binding constraints attached to the area bindingConstraints.remove(*i); @@ -956,7 +957,7 @@ bool Study::areaRename(Area* area, AreaName newName) // Updating all hydro allocation areas.each([&oldid, &newid](Data::Area& areait) - { areait.hydro.allocation.rename(oldid, newid); }); + { areait.hydro.allocation.rename(oldid, newid); }); ScenarioBuilderUpdater updaterSB(*this); bool ret = true; @@ -1109,13 +1110,14 @@ void Study::destroyAllWindTSGeneratorData() void Study::destroyAllThermalTSGeneratorData() { - areas.each([](const Data::Area& area) - { - for (const auto& cluster: area.thermal.list.each_enabled_and_not_mustrun()) - { - FreeAndNil(cluster->prepro); - } - }); + areas.each( + [](const Data::Area& area) + { + for (const auto& cluster: area.thermal.list.each_enabled_and_not_mustrun()) + { + FreeAndNil(cluster->prepro); + } + }); } void Study::ensureDataAreLoadedForAllBindingConstraints() @@ -1358,7 +1360,6 @@ bool Study::checkForFilenameLimits(bool output, const String& chfolder) const areas.each( [&output, &linkname, &areaname](const Area& area) { - if (areaname.size() < area.id.size()) { areaname = area.id; diff --git a/src/libs/antares/study/study.importprepro.cpp b/src/libs/antares/study/study.importprepro.cpp index 3b8263eadf..f7c8082050 100644 --- a/src/libs/antares/study/study.importprepro.cpp +++ b/src/libs/antares/study/study.importprepro.cpp @@ -50,7 +50,7 @@ bool Study::importTimeseriesIntoInput() if (parameters.haveToImport(timeSeriesLoad)) { logs.info() << "Importing load timeseries..."; - for (const auto& [areaName, area] : areas) + for (const auto& [areaName, area]: areas) { logs.info() << "Importing load timeseries : " << areaName; buffer.clear() << folderInput << SEP << "load" << SEP << "series"; @@ -63,7 +63,7 @@ bool Study::importTimeseriesIntoInput() if (parameters.haveToImport(timeSeriesSolar)) { logs.info() << "Importing solar timeseries..."; - for (const auto& [areaName, area] : areas) + for (const auto& [areaName, area]: areas) { logs.info() << "Importing solar timeseries : " << areaName; buffer.clear() << folderInput << SEP << "solar" << SEP << "series"; @@ -76,7 +76,7 @@ bool Study::importTimeseriesIntoInput() if (parameters.haveToImport(timeSeriesHydro)) { logs.info() << "Importing hydro timeseries..."; - for (const auto& [areaName, area] : areas) + for (const auto& [areaName, area]: areas) { logs.info() << "Importing hydro timeseries : " << areaName; buffer.clear() << folderInput << SEP << "hydro" << SEP << "series"; @@ -89,7 +89,7 @@ bool Study::importTimeseriesIntoInput() if (parameters.haveToImport(timeSeriesWind)) { logs.info() << "Importing wind timeseries..."; - for (const auto& [areaName, area] : areas) + for (const auto& [areaName, area]: areas) { logs.info() << "Importing wind timeseries : " << areaName; buffer.clear() << folderInput << SEP << "wind" << SEP << "series"; @@ -104,7 +104,7 @@ bool Study::importTimeseriesIntoInput() logs.info() << "Importing thermal timeseries..."; String msg; - for (const auto& [areaName, area] : areas) + for (const auto& [areaName, area]: areas) { msg.clear() << "Importing thermal timeseries : " << areaName; diff --git a/src/libs/antares/study/xcast/xcast.cpp b/src/libs/antares/study/xcast/xcast.cpp index 51ed1624b0..0f2e05956b 100644 --- a/src/libs/antares/study/xcast/xcast.cpp +++ b/src/libs/antares/study/xcast/xcast.cpp @@ -207,7 +207,8 @@ bool XCast::loadFromFolder(const AnyString& folder) // For each property if (section.name == "general") { - for (const IniFile::Property* p = section.firstProperty; p != nullptr; p = p->next) + for (const IniFile::Property* p = section.firstProperty; p != nullptr; + p = p->next) { CString<30, false> key = p->key; key.toLower(); diff --git a/src/libs/antares/writer/in_memory_writer.cpp b/src/libs/antares/writer/in_memory_writer.cpp index e3e643a74f..182fee1927 100644 --- a/src/libs/antares/writer/in_memory_writer.cpp +++ b/src/libs/antares/writer/in_memory_writer.cpp @@ -24,9 +24,9 @@ #include #include +#include #include #include -#include namespace fs = std::filesystem; diff --git a/src/libs/antares/writer/zip_writer.cpp b/src/libs/antares/writer/zip_writer.cpp index 362d0e730e..6359460f8a 100644 --- a/src/libs/antares/writer/zip_writer.cpp +++ b/src/libs/antares/writer/zip_writer.cpp @@ -51,7 +51,6 @@ static void logErrorAndThrow [[noreturn]] (const std::string& errorMessage) throw std::runtime_error(errorMessage); } - // Class ZipWriteJob template ZipWriteJob::ZipWriteJob(ZipWriter& writer, diff --git a/src/solver/application/application.cpp b/src/solver/application/application.cpp index d222ad88c0..9ec3ce3e14 100644 --- a/src/solver/application/application.cpp +++ b/src/solver/application/application.cpp @@ -337,10 +337,14 @@ void Application::prepare(int argc, char* argv[]) // don't de-allocate these. if (!parseCommandLine(options)) // --help + { return; + } if (!handleOptions(options)) // --version, --list-solvers - return; + { + return; + } // Perform some checks checkAndCorrectSettingsAndOptions(pSettings, options); diff --git a/src/solver/constraints-builder/cbuilder.cpp b/src/solver/constraints-builder/cbuilder.cpp index a49806ff16..0b37556347 100644 --- a/src/solver/constraints-builder/cbuilder.cpp +++ b/src/solver/constraints-builder/cbuilder.cpp @@ -364,8 +364,7 @@ bool CBuilder::saveCBuilderToFile(const String& filename) const if (filename == "") { - fs::path path = fs::path(pStudy.folder.c_str()) / "settings" - / "constraintbuilder.ini"; + fs::path path = fs::path(pStudy.folder.c_str()) / "settings" / "constraintbuilder.ini"; return ini.save(path.string()); } diff --git a/src/solver/hydro/include/antares/solver/hydro/management/management.h b/src/solver/hydro/include/antares/solver/hydro/management/management.h index b642e441c2..30528d92d2 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/management.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/management.h @@ -152,8 +152,7 @@ class HydroManagement final // \return The total inflow for the whole year double prepareMonthlyTargetGenerations(Data::Area& area, TmpDataByArea& data); - void prepareDailyOptimalGenerations(uint y, - Antares::Data::Area::ScratchMap& scratchmap); + void prepareDailyOptimalGenerations(uint y, Antares::Data::Area::ScratchMap& scratchmap); void prepareDailyOptimalGenerations(Data::Area& area, uint y, diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index f7e4665159..d9651a1197 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -219,9 +219,9 @@ struct DebugData }; inline void HydroManagement::prepareDailyOptimalGenerations( - Data::Area& area, - uint y, - Antares::Data::Area::ScratchMap& scratchmap) + Data::Area& area, + uint y, + Antares::Data::Area::ScratchMap& scratchmap) { const auto srcinflows = area.hydro.series->storage.getColumn(y); diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 703235fc61..a863668f64 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -385,23 +385,31 @@ bool HydroManagement::checkMinGeneration(uint year) const void HydroManagement::changeInflowsToAccommodateFinalLevels(uint year) { - areas_.each([this, &year](Data::Area& area) - { - auto& data = tmpDataByArea_[&area]; - - if (!area.hydro.deltaBetweenFinalAndInitialLevels[year].has_value()) - return; - - // Must be done before prepareMonthlyTargetGenerations - double delta = area.hydro.deltaBetweenFinalAndInitialLevels[year].value(); - if (delta < 0) - data.inflows[0] -= delta; - else if (delta > 0) - data.inflows[11] -= delta; - }); + areas_.each( + [this, &year](Data::Area& area) + { + auto& data = tmpDataByArea_[&area]; + + if (!area.hydro.deltaBetweenFinalAndInitialLevels[year].has_value()) + { + return; + } + + // Must be done before prepareMonthlyTargetGenerations + double delta = area.hydro.deltaBetweenFinalAndInitialLevels[year].value(); + if (delta < 0) + { + data.inflows[0] -= delta; + } + else if (delta > 0) + { + data.inflows[11] -= delta; + } + }); } -void HydroManagement::prepareNetDemand(uint year, Data::SimulationMode mode, +void HydroManagement::prepareNetDemand(uint year, + Data::SimulationMode mode, const Antares::Data::Area::ScratchMap& scratchmap) { areas_.each( diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index aa10b7c10e..37c2085e3c 100644 --- a/src/solver/hydro/management/monthly.cpp +++ b/src/solver/hydro/management/monthly.cpp @@ -290,22 +290,22 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ auto monthName = calendar_.text.months[simulationMonth].name; - buffer << monthName[0] << monthName[1] << monthName[2] << '\t'; - buffer << '\t'; - buffer << data.inflows[realmonth] << '\t'; - buffer << data.MTG[realmonth] << '\t'; - buffer << data.MOG[realmonth] / area.hydro.reservoirCapacity << '\t'; - buffer << data.MOL[realmonth] << '\t'; - buffer << minLvl[firstDay] << '\t'; - buffer << maxLvl[firstDay] << '\t'; - buffer << '\n'; - } - auto content = buffer.str(); - resultWriter_.addEntryFromBuffer(path.str(), content); - } + buffer << monthName[0] << monthName[1] << monthName[2] << '\t'; + buffer << '\t'; + buffer << data.inflows[realmonth] << '\t'; + buffer << data.MTG[realmonth] << '\t'; + buffer << data.MOG[realmonth] / area.hydro.reservoirCapacity << '\t'; + buffer << data.MOL[realmonth] << '\t'; + buffer << minLvl[firstDay] << '\t'; + buffer << maxLvl[firstDay] << '\t'; + buffer << '\n'; + } + auto content = buffer.str(); + resultWriter_.addEntryFromBuffer(path.str(), content); + } - indexArea++; - }); + indexArea++; + }); } } // namespace Antares diff --git a/src/solver/misc/include/antares/solver/misc/options.h b/src/solver/misc/include/antares/solver/misc/options.h index 2560a74d1c..00daf5aec7 100644 --- a/src/solver/misc/include/antares/solver/misc/options.h +++ b/src/solver/misc/include/antares/solver/misc/options.h @@ -27,8 +27,8 @@ #include #include -#include #include +#include /*! ** \brief Command line settings for launching the simulation diff --git a/src/solver/misc/options.cpp b/src/solver/misc/options.cpp index 9429b50e79..458ae2fa06 100644 --- a/src/solver/misc/options.cpp +++ b/src/solver/misc/options.cpp @@ -22,8 +22,8 @@ #include "antares/solver/misc/options.h" #include -#include #include +#include #include #include diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index 2b03f7bcdc..fa4a292902 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -68,7 +68,10 @@ bool Adequacy::simulationBegin() pProblemesHebdo.resize(pNbMaxPerformedYearsInParallel); for (uint numSpace = 0; numSpace < pNbMaxPerformedYearsInParallel; numSpace++) { - SIM_InitialisationProblemeHebdo(study, pProblemesHebdo[numSpace], nbHoursInAWeek, numSpace); + SIM_InitialisationProblemeHebdo(study, + pProblemesHebdo[numSpace], + nbHoursInAWeek, + numSpace); } } diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 1f56235499..8095cc85bb 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -395,21 +395,23 @@ void PrepareRandomNumbers(Data::Study& study, }); } - void SetInitialHydroLevel(Data::Study& study, PROBLEME_HEBDO& problem, const HYDRO_VENTILATION_RESULTS& hydroVentilationResults) { uint firstDaySimu = study.parameters.simulationDays.first; - study.areas.each([&problem, &firstDaySimu, &hydroVentilationResults](const Data::Area& area) - { - if (area.hydro.reservoirManagement) - { - double capacity = area.hydro.reservoirCapacity; - problem.previousSimulationFinalLevel[area.index] = - hydroVentilationResults[area.index].NiveauxReservoirsDebutJours[firstDaySimu] * capacity; - } - }); + study.areas.each( + [&problem, &firstDaySimu, &hydroVentilationResults](const Data::Area& area) + { + if (area.hydro.reservoirManagement) + { + double capacity = area.hydro.reservoirCapacity; + problem.previousSimulationFinalLevel[area.index] = hydroVentilationResults[area.index] + .NiveauxReservoirsDebutJours + [firstDaySimu] + * capacity; + } + }); } void BuildThermalPartOfWeeklyProblem(Data::Study& study, diff --git a/src/solver/simulation/common-hydro-levels.cpp b/src/solver/simulation/common-hydro-levels.cpp index 81602073a1..b0ba258b0e 100644 --- a/src/solver/simulation/common-hydro-levels.cpp +++ b/src/solver/simulation/common-hydro-levels.cpp @@ -33,7 +33,7 @@ void computingHydroLevels(const Data::AreaList& areas, bool remixWasRun, bool computeAnyway) { - for (const auto& [_, area] : areas) + for (const auto& [_, area]: areas) { if (!area->hydro.reservoirManagement) { @@ -50,7 +50,7 @@ void computingHydroLevels(const Data::AreaList& areas, double reservoirCapacity = area->hydro.reservoirCapacity; std::vector& inflows = problem.CaracteristiquesHydrauliques[index] - .ApportNaturelHoraire; + .ApportNaturelHoraire; RESULTATS_HORAIRES& weeklyResults = problem.ResultatsHoraires[index]; @@ -65,7 +65,7 @@ void computingHydroLevels(const Data::AreaList& areas, std::vector& ovf = weeklyResults.debordementsHoraires; computeTimeStepLevel - computeLvlObj(nivInit, inflows, ovf, turb, pumpingRatio, pump, reservoirCapacity); + computeLvlObj(nivInit, inflows, ovf, turb, pumpingRatio, pump, reservoirCapacity); for (uint h = 0; h < nbHoursInAWeek - 1; h++) { @@ -94,7 +94,7 @@ void interpolateWaterValue(const Data::AreaList& areas, daysOfWeek[d] = weekFirstDay + d; } - for (const auto& [_, area] : areas) + for (const auto& [_, area]: areas) { uint index = area->index; @@ -118,22 +118,22 @@ void interpolateWaterValue(const Data::AreaList& areas, std::vector& niv = weeklyResults.niveauxHoraires; waterVal[0] = Data::getWaterValue(problem.previousSimulationFinalLevel[index] * 100 - / reservoirCapacity, - area->hydro.waterValues, - weekFirstDay); + / reservoirCapacity, + area->hydro.waterValues, + weekFirstDay); for (uint h = 1; h < nbHoursInAWeek; h++) { waterVal[h] = Data::getWaterValue(niv[h - 1], - area->hydro.waterValues, - daysOfWeek[h / 24]); + area->hydro.waterValues, + daysOfWeek[h / 24]); } } } void updatingWeeklyFinalHydroLevel(const Data::AreaList& areas, PROBLEME_HEBDO& problem) { - for (const auto& [_, area] : areas) + for (const auto& [_, area]: areas) { if (!area->hydro.reservoirManagement) { @@ -149,7 +149,7 @@ void updatingWeeklyFinalHydroLevel(const Data::AreaList& areas, PROBLEME_HEBDO& std::vector& niv = weeklyResults.niveauxHoraires; problem.previousSimulationFinalLevel[index] = niv[nbHoursInAWeek - 1] * reservoirCapacity - / 100; + / 100; } } diff --git a/src/solver/simulation/common-hydro-remix.cpp b/src/solver/simulation/common-hydro-remix.cpp index dcf39052ce..de8e3f5328 100644 --- a/src/solver/simulation/common-hydro-remix.cpp +++ b/src/solver/simulation/common-hydro-remix.cpp @@ -51,8 +51,7 @@ static bool Remix(const Data::AreaList& areas, bool status = true; areas.each( - [&HE, &DE, &remix, &G, &status, &problem, &numSpace, &hourInYear] - (const Data::Area& area) + [&HE, &DE, &remix, &G, &status, &problem, &numSpace, &hourInYear](const Data::Area& area) { auto index = area.index; diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index 934ebc4c2c..ac40117b2c 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -73,7 +73,10 @@ bool Economy::simulationBegin() for (uint numSpace = 0; numSpace < pNbMaxPerformedYearsInParallel; numSpace++) { - SIM_InitialisationProblemeHebdo(study, pProblemesHebdo[numSpace], nbHoursInAWeek, numSpace); + SIM_InitialisationProblemeHebdo(study, + pProblemesHebdo[numSpace], + nbHoursInAWeek, + numSpace); auto options = createOptimizationOptions(study); weeklyOptProblems_[numSpace] = Antares::Solver::Optimization::WeeklyOptimization:: diff --git a/src/solver/simulation/hydro-final-reservoir-level-functions.cpp b/src/solver/simulation/hydro-final-reservoir-level-functions.cpp index 32f2d4dfa2..225a0e2be9 100644 --- a/src/solver/simulation/hydro-final-reservoir-level-functions.cpp +++ b/src/solver/simulation/hydro-final-reservoir-level-functions.cpp @@ -26,43 +26,47 @@ */ #include "antares/solver/simulation/hydro-final-reservoir-level-functions.h" -#include "antares/study/parts/hydro/finalLevelValidator.h" + #include +#include "antares/study/parts/hydro/finalLevelValidator.h" namespace Antares::Solver { void CheckFinalReservoirLevelsConfiguration(const Data::Study& study) { - study.areas.each([&study](Data::Area &area) - { - uint nbYears = study.parameters.nbYears; - for (uint year = 0; year != nbYears; ++year) - { - if (! study.parameters.yearsFilter.at(year)) - continue; + study.areas.each( + [&study](Data::Area& area) + { + uint nbYears = study.parameters.nbYears; + for (uint year = 0; year != nbYears; ++year) + { + if (!study.parameters.yearsFilter.at(year)) + { + continue; + } - double initialLevel = study.scenarioInitialHydroLevels.entry[area.index][year]; - double finalLevel = study.scenarioFinalHydroLevels.entry[area.index][year]; + double initialLevel = study.scenarioInitialHydroLevels.entry[area.index][year]; + double finalLevel = study.scenarioFinalHydroLevels.entry[area.index][year]; - Data::FinalLevelValidator validator(area.hydro, - area.index, - area.name, - initialLevel, - finalLevel, - year, - study.parameters.simulationDays.end, - study.parameters.firstMonthInYear); - if (! validator.check()) - { - throw FatalError("hydro final level : infeasibility"); - } - if (validator.finalLevelFineForUse()) - { - area.hydro.deltaBetweenFinalAndInitialLevels[year] = finalLevel - initialLevel; - } - } - }); + Data::FinalLevelValidator validator(area.hydro, + area.index, + area.name, + initialLevel, + finalLevel, + year, + study.parameters.simulationDays.end, + study.parameters.firstMonthInYear); + if (!validator.check()) + { + throw FatalError("hydro final level : infeasibility"); + } + if (validator.finalLevelFineForUse()) + { + area.hydro.deltaBetweenFinalAndInitialLevels[year] = finalLevel - initialLevel; + } + } + }); } // End function CheckFinalReservoirLevelsConfiguration -} // namespace Antares::Solver \ No newline at end of file +} // namespace Antares::Solver diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index 232fa520fc..cd6bcb5f62 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -39,7 +39,6 @@ #include "antares/solver/simulation/timeseries-numbers.h" #include "antares/solver/ts-generator/generator.h" - #include "hydro-final-reservoir-level-functions.h" namespace Antares::Solver::Simulation @@ -75,10 +74,7 @@ public: yearByYear(pYearByYear), pDurationCollector(durationCollector), pResultWriter(resultWriter), - hydroManagement(study.areas, - study.parameters, - study.calendar, - resultWriter) + hydroManagement(study.areas, study.parameters, study.calendar, resultWriter) { scratchmap = study.areas.buildScratchMap(numSpace); } @@ -162,11 +158,8 @@ public: simulation_->prepareClustersInMustRunMode(scratchmap, y); // 4 - Hydraulic ventilation - pDurationCollector("hydro_ventilation") << [this, &randomReservoirLevel] { - hydroManagement.makeVentilation(randomReservoirLevel, - y, - scratchmap); - }; + pDurationCollector("hydro_ventilation") << [this, &randomReservoirLevel] + { hydroManagement.makeVentilation(randomReservoirLevel, y, scratchmap); }; // Updating the state state.year = y; @@ -748,15 +741,15 @@ void ISimulation::computeRandomNumbers( max[firstDayOfMonth], randomHydroGenerator); - // Possibly update the intial level from scenario builder - if (study.parameters.useCustomScenario) - { - double levelFromScenarioBuilder = study.scenarioInitialHydroLevels[areaIndex][y]; - if (levelFromScenarioBuilder >= 0.) - { - randomLevel = levelFromScenarioBuilder; - } - } + // Possibly update the intial level from scenario builder + if (study.parameters.useCustomScenario) + { + double levelFromScenarioBuilder = study.scenarioInitialHydroLevels[areaIndex][y]; + if (levelFromScenarioBuilder >= 0.) + { + randomLevel = levelFromScenarioBuilder; + } + } // Current area's hydro starting (or initial) level computation // (no matter if the year is performed or not, we always draw a random initial @@ -780,7 +773,12 @@ void ISimulation::computeRandomNumbers( bool SpilledEnergySeedIsDefault = (currentSpilledEnergySeed == defaultSpilledEnergySeed); areaIndex = 0; study.areas.each( - [&isPerformed, &areaIndex, &randomUnsupplied, &randomSpilled, &randomForYears, &indexYear, + [&isPerformed, + &areaIndex, + &randomUnsupplied, + &randomSpilled, + &randomForYears, + &indexYear, &SpilledEnergySeedIsDefault](Data::Area& area) { (void)area; // Avoiding warnings at compilation (unused variable) on linux @@ -1030,19 +1028,19 @@ void ISimulation::loopThroughYears(uint firstYear, // continue; auto task = std::make_shared>( - this, - y, - set_it->yearFailed, - set_it->isFirstPerformedYearOfASet, - pFirstSetParallelWithAPerformedYearWasRun, - numSpace, - randomForParallelYears, - performCalculations, - study, - state[numSpace], - pYearByYear, - pDurationCollector, - pResultWriter); + this, + y, + set_it->yearFailed, + set_it->isFirstPerformedYearOfASet, + pFirstSetParallelWithAPerformedYearWasRun, + numSpace, + randomForParallelYears, + performCalculations, + study, + state[numSpace], + pYearByYear, + pDurationCollector, + pResultWriter); results.add(Concurrency::AddTask(*pQueueService, task)); } // End loop over years of the current set of parallel years diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index ed13d54fe1..7fb3336599 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -513,11 +513,11 @@ void SIM_RenseignementProblemeHebdo(const Study& study, if (area.hydro.useWaterValue) { - problem.CaracteristiquesHydrauliques[k].WeeklyWaterValueStateRegular = - getWaterValue( - problem.previousSimulationFinalLevel[k] * 100 / area.hydro.reservoirCapacity, - area.hydro.waterValues, - weekFirstDay); + problem.CaracteristiquesHydrauliques[k].WeeklyWaterValueStateRegular + = getWaterValue(problem.previousSimulationFinalLevel[k] * 100 + / area.hydro.reservoirCapacity, + area.hydro.waterValues, + weekFirstDay); } if (problem.CaracteristiquesHydrauliques[k].PresenceDHydrauliqueModulable > 0) diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 52b1213ada..446a0efa08 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -329,8 +329,7 @@ bool checkInterModalConsistencyForArea(const Area& area, { logs.error() << "Inter-modal correlation: time-series numbers of inter-modal modes in area '" - << area.name << "'" - << " are not identical"; + << area.name << "'" << " are not identical"; return false; } diff --git a/src/solver/ts-generator/availability.cpp b/src/solver/ts-generator/availability.cpp index 69f62a10a1..dfb2d8c1f4 100644 --- a/src/solver/ts-generator/availability.cpp +++ b/src/solver/ts-generator/availability.cpp @@ -99,7 +99,9 @@ class GeneratorTempData final const T& duration) const; }; -GeneratorTempData::GeneratorTempData(Data::Study& study, unsigned nbOfSeriesToGen, MersenneTwister& rndGenerator): +GeneratorTempData::GeneratorTempData(Data::Study& study, + unsigned nbOfSeriesToGen, + MersenneTwister& rndGenerator): derated(study.parameters.derated), nbOfSeriesToGen_(nbOfSeriesToGen), rndgenerator(rndGenerator) @@ -616,10 +618,13 @@ listOfLinks getAllLinksToGen(Data::AreaList& areas) areas.each( [&links](const Data::Area& area) { - std::ranges::for_each(area.links, [&links](auto& l) + std::ranges::for_each(area.links, + [&links](auto& l) { if (!l.second->tsGeneration.forceNoGeneration) + { links.push_back(l.second); + } }); }); @@ -698,7 +703,10 @@ bool generateLinkTimeSeries(Data::Study& study, } // DIRECT - AvailabilityTSGeneratorData tsConfigDataDirect(tsGenStruct, ts, tsGenStruct.modulationCapacityDirect, link->with->name); + AvailabilityTSGeneratorData tsConfigDataDirect(tsGenStruct, + ts, + tsGenStruct.modulationCapacityDirect, + link->with->name); generator.generateTS(*link->from, tsConfigDataDirect); @@ -707,12 +715,14 @@ bool generateLinkTimeSeries(Data::Study& study, writeResultsToDisk(study, writer, ts.timeSeries, filePath); // INDIRECT - AvailabilityTSGeneratorData tsConfigDataIndirect(tsGenStruct, ts, tsGenStruct.modulationCapacityIndirect, link->with->name); + AvailabilityTSGeneratorData tsConfigDataIndirect(tsGenStruct, + ts, + tsGenStruct.modulationCapacityIndirect, + link->with->name); generator.generateTS(*link->from, tsConfigDataIndirect); - filePath = savePath + SEP + link->from->id + SEP + link->with->id.c_str() - + "_indirect.txt"; + filePath = savePath + SEP + link->from->id + SEP + link->with->id.c_str() + "_indirect.txt"; writeResultsToDisk(study, writer, ts.timeSeries, filePath); } diff --git a/src/solver/ts-generator/xcast/xcast.cpp b/src/solver/ts-generator/xcast/xcast.cpp index ca0c96087a..56f7234119 100644 --- a/src/solver/ts-generator/xcast/xcast.cpp +++ b/src/solver/ts-generator/xcast/xcast.cpp @@ -593,7 +593,8 @@ bool XCast::runWithPredicate(PredicateT& predicate, Progression::Task& progressi if (study.parameters.derated) { - study.areas.each([&predicate](Data::Area& area) { predicate.matrix(area).averageTimeseries(); }); + study.areas.each([&predicate](Data::Area& area) + { predicate.matrix(area).averageTimeseries(); }); } if (study.parameters.timeSeriesToArchive & timeSeriesType) diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index 1f2f5e4169..2cc81b80fa 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -56,10 +56,9 @@ static void checkSetSolverSpecificParameters(bool status, } } -static void TuneSolverSpecificOptions( - MPSolver* solver, - const std::string& solverName, - const std::string& solverParameters) +static void TuneSolverSpecificOptions(MPSolver* solver, + const std::string& solverName, + const std::string& solverParameters) { if (!solver) { @@ -135,7 +134,6 @@ MPSolver* ProblemSimplexeNommeConverter::Convert() return solver; } - void ProblemSimplexeNommeConverter::CopyMatrix(const MPSolver* solver) const { auto variables = solver->variables(); diff --git a/src/solver/variable/include/antares/solver/variable/economy/all.h b/src/solver/variable/include/antares/solver/variable/economy/all.h index a3c637c43f..b7a62eb6bf 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/all.h +++ b/src/solver/variable/include/antares/solver/variable/economy/all.h @@ -248,8 +248,8 @@ typedef Variable::Join< Variable::Areas, // Variables for each set of areas Variable::Join, - // Variables for each binding constraint - Variable::BindingConstraints>> + // Variables for each binding constraint + Variable::BindingConstraints>> ItemList; /*! diff --git a/src/solver/variable/include/antares/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h b/src/solver/variable/include/antares/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h index 6d7e02fa3e..8a1f97676f 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h +++ b/src/solver/variable/include/antares/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h @@ -147,7 +147,6 @@ class BindingConstMarginCost NextType::simulationEnd(); } - void initializeFromStudy(Data::Study& study) { pNbYearsParallel = study.maxNbYearsInParallel; @@ -257,8 +256,8 @@ class BindingConstMarginCost for (int dayInTheWeek = 0; dayInTheWeek < 7; dayInTheWeek++) { pValuesForTheCurrentYear[numSpace].day[dayInTheYear] - -= state.problemeHebdo - ->ResultatsContraintesCouplantes[associatedBC_][dayInTheWeek]; + -= state.problemeHebdo + ->ResultatsContraintesCouplantes[associatedBC_][dayInTheWeek]; dayInTheYear++; } @@ -270,7 +269,7 @@ class BindingConstMarginCost { uint weekInTheYear = state.weekInTheYear; double weeklyValue = -state.problemeHebdo - ->ResultatsContraintesCouplantes[associatedBC_][0]; + ->ResultatsContraintesCouplantes[associatedBC_][0]; pValuesForTheCurrentYear[numSpace].week[weekInTheYear] = weeklyValue; diff --git a/src/solver/variable/include/antares/solver/variable/endoflist.h b/src/solver/variable/include/antares/solver/variable/endoflist.h index 7c32c32ecb..d8cb5dd69d 100644 --- a/src/solver/variable/include/antares/solver/variable/endoflist.h +++ b/src/solver/variable/include/antares/solver/variable/endoflist.h @@ -254,7 +254,6 @@ class EndOfList static void computeSpatialAggregateWith(O&, const Data::Area*, uint numSpace) { UNUSED_VARIABLE(numSpace); - assert(false); } template diff --git a/src/tests/end-to-end/simple_study/simple-study.cpp b/src/tests/end-to-end/simple_study/simple-study.cpp index bfad50326f..96a66aef3e 100644 --- a/src/tests/end-to-end/simple_study/simple-study.cpp +++ b/src/tests/end-to-end/simple_study/simple-study.cpp @@ -82,7 +82,7 @@ HydroMaxPowerStudy::HydroMaxPowerStudy() area = addAreaToStudy("Area"); area->thermal.unsuppliedEnergyCost = 1; - setNumberMCyears(1); + setNumberMCyears(1); TimeSeriesConfigurer loadTSconfig(area->load.series.timeSeries); loadTSconfig.setColumnCount(1).fillColumnWith(0, loadInArea); diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index a42891ea45..fdba99c007 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -219,7 +219,8 @@ void StudyBuilder::setNumberMCyears(unsigned int nbYears) { study->parameters.resetPlaylist(nbYears); study->areas.resizeAllTimeseriesNumbers(nbYears); - study->areas.each([&](Data::Area& area) { area.hydro.deltaBetweenFinalAndInitialLevels.resize(nbYears); }); + study->areas.each([&](Data::Area& area) + { area.hydro.deltaBetweenFinalAndInitialLevels.resize(nbYears); }); } void StudyBuilder::playOnlyYear(unsigned int year) diff --git a/src/tests/end-to-end/utils/utils.h b/src/tests/end-to-end/utils/utils.h index 1fa55efbff..84362bf2e0 100644 --- a/src/tests/end-to-end/utils/utils.h +++ b/src/tests/end-to-end/utils/utils.h @@ -164,14 +164,17 @@ class ScenarioBuilderRule { return rules_->load; } + BindingConstraintsTSNumberData& bcGroup() { return rules_->binding_constraints; } + hydroTSNumberData& hydro() { return rules_->hydro; } + private: Rules::Ptr rules_; }; diff --git a/src/tests/src/libs/antares/antlr4-interface/test_antlr_interface.cpp b/src/tests/src/libs/antares/antlr4-interface/test_antlr_interface.cpp index e97f4e3524..04d1c7be9f 100644 --- a/src/tests/src/libs/antares/antlr4-interface/test_antlr_interface.cpp +++ b/src/tests/src/libs/antares/antlr4-interface/test_antlr_interface.cpp @@ -19,15 +19,17 @@ ** along with Antares_Simulator. If not, see . */ #define BOOST_TEST_MODULE antlr_interface tests -#include -#include -#include "antlr4-runtime.h" #include +#include +#include + #include "ExprLexer.h" #include "ExprParser.h" +#include "antlr4-runtime.h" using namespace antlr4; + BOOST_AUTO_TEST_CASE(test_antlr_interface) { const std::string my_input = "y = b + a*x"; diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 7879559fb0..de09d007d1 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -355,10 +355,12 @@ BOOST_FIXTURE_TEST_CASE(on_area1_and_on_year_17__hydro_level_0_123_is_chosen__re AreaName::Vector splitKey = {"hl", "area 1", yearNumber}; my_rule.readLine(splitKey, level); - BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_1->index), level.to()); + BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_1->index), + level.to()); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_1->index][yearNumber.to()], level.to()); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_1->index][yearNumber.to()], + level.to()); } BOOST_FIXTURE_TEST_CASE( @@ -370,10 +372,11 @@ BOOST_FIXTURE_TEST_CASE( AreaName::Vector splitKey = {"hl", "area 2", yearNumber}; BOOST_CHECK(my_rule.readLine(splitKey, level)); - BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_2->index), 1.); + BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_2->index), + 1.); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_2->index][yearNumber.to()], 1.); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_2->index][yearNumber.to()], 1.); } BOOST_FIXTURE_TEST_CASE( @@ -385,10 +388,11 @@ BOOST_FIXTURE_TEST_CASE( AreaName::Vector splitKey = {"hl", "area 3", yearNumber}; BOOST_CHECK(my_rule.readLine(splitKey, level)); - BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_3->index), 0.); + BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_3->index), + 0.); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_3->index][yearNumber.to()], 0.); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_3->index][yearNumber.to()], 0.); } // ======================== @@ -396,47 +400,47 @@ BOOST_FIXTURE_TEST_CASE( // ======================== BOOST_FIXTURE_TEST_CASE(on_area1_and_on_year_8__hydro_level_0_342_is_chosen__reading_OK, Fixture) { - AreaName yearNumber = "8"; - String level = "0.342"; - AreaName::Vector splitKey = {"hfl", "area 1", yearNumber}; - my_rule.readLine(splitKey, level, false); + AreaName yearNumber = "8"; + String level = "0.342"; + AreaName::Vector splitKey = {"hfl", "area 1", yearNumber}; + my_rule.readLine(splitKey, level, false); - BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_1->index), - level.to()); + BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_1->index), + level.to()); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_1->index][yearNumber.to()], - level.to()); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_1->index][yearNumber.to()], + level.to()); } -BOOST_FIXTURE_TEST_CASE(on_area2_and_on_year_1__hydro_level_2_4_is_chosen_level_lowered_to_1__reading_OK, Fixture) +BOOST_FIXTURE_TEST_CASE( + on_area2_and_on_year_1__hydro_level_2_4_is_chosen_level_lowered_to_1__reading_OK, + Fixture) { - AreaName yearNumber = "1"; - String level = "2.4"; - AreaName::Vector splitKey = {"hfl", "area 2", yearNumber}; - BOOST_CHECK(my_rule.readLine(splitKey, level, false)); + AreaName yearNumber = "1"; + String level = "2.4"; + AreaName::Vector splitKey = {"hfl", "area 2", yearNumber}; + BOOST_CHECK(my_rule.readLine(splitKey, level, false)); - BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_2->index), - 1.); + BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_2->index), 1.); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_2->index][yearNumber.to()], - 1.); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_2->index][yearNumber.to()], 1.); } -BOOST_FIXTURE_TEST_CASE(on_area3_and_on_year_3__hydro_level_neg_5_2_is_chosen__level_raised_to_0__reading_OK, Fixture) +BOOST_FIXTURE_TEST_CASE( + on_area3_and_on_year_3__hydro_level_neg_5_2_is_chosen__level_raised_to_0__reading_OK, + Fixture) { - AreaName yearNumber = "3"; - String level = "-5.2"; - AreaName::Vector splitKey = {"hfl", "area 3", yearNumber}; - BOOST_CHECK(my_rule.readLine(splitKey, level, false)); + AreaName yearNumber = "3"; + String level = "-5.2"; + AreaName::Vector splitKey = {"hfl", "area 3", yearNumber}; + BOOST_CHECK(my_rule.readLine(splitKey, level, false)); - BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_3->index), - 0.); + BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_3->index), 0.); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_3->index][yearNumber.to()], - 0.); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_3->index][yearNumber.to()], 0.); } // ====================== diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 13d5a38b48..64813637fc 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -436,7 +436,9 @@ BOOST_FIXTURE_TEST_CASE( // ======================== // Tests on Hydro final levels // ======================== -BOOST_FIXTURE_TEST_CASE(HYDRO_FINAL_LEVEL__TS_number_for_many_areas_and_years__generated_and_ref_sc_buider_files_are_identical, saveFixture) +BOOST_FIXTURE_TEST_CASE( + HYDRO_FINAL_LEVEL__TS_number_for_many_areas_and_years__generated_and_ref_sc_buider_files_are_identical, + saveFixture) { my_rule->hydroFinalLevels.setTSnumber(area_1->index, 4, 8); my_rule->hydroFinalLevels.setTSnumber(area_2->index, 11, 3); diff --git a/src/tests/src/libs/antares/test_utils.cpp b/src/tests/src/libs/antares/test_utils.cpp index ad7e97d833..5cb05e27c4 100644 --- a/src/tests/src/libs/antares/test_utils.cpp +++ b/src/tests/src/libs/antares/test_utils.cpp @@ -19,14 +19,14 @@ * along with Antares_Simulator. If not, see . */ #define BOOST_TEST_MODULE test utils +#include #include #include -#include - #include -#include + +#include namespace fs = std::filesystem; @@ -99,7 +99,8 @@ BOOST_AUTO_TEST_CASE(yuni_normalize_vs_std_lexically_normal) { Yuni::String yuniNorm; Yuni::IO::Normalize(yuniNorm, path.string()); - BOOST_CHECK_MESSAGE(path.lexically_normal().string() == yuniNorm, std::string("Check failed for ") + path.string()); + BOOST_CHECK_MESSAGE(path.lexically_normal().string() == yuniNorm, + std::string("Check failed for ") + path.string()); }; helper(fs::path("a/./b/..")); helper(fs::path("a/.///b/../")); diff --git a/src/tests/src/libs/antares/yaml-parser/test_yaml_parser.cpp b/src/tests/src/libs/antares/yaml-parser/test_yaml_parser.cpp index ebfbc4bba8..87978fbcaa 100644 --- a/src/tests/src/libs/antares/yaml-parser/test_yaml_parser.cpp +++ b/src/tests/src/libs/antares/yaml-parser/test_yaml_parser.cpp @@ -19,19 +19,22 @@ ** along with Antares_Simulator. If not, see . */ #define BOOST_TEST_MODULE yamlcpp tests -#include -#include -#include "yaml-cpp/yaml.h" -#include #include +#include #include #include +#include +#include + +#include "yaml-cpp/yaml.h" + // our data types struct Vec3 { float x, y, z; }; + struct Power { std::string name; @@ -44,6 +47,7 @@ struct Monster Vec3 position; std::vector powers; }; + namespace YAML { template<> @@ -71,6 +75,7 @@ struct convert return true; } }; + template<> struct convert { @@ -89,6 +94,7 @@ struct convert return true; } }; + template<> struct convert { @@ -108,7 +114,7 @@ struct convert rhs.name = node["name"].as(); rhs.position = node["position"].as(); const YAML::Node& powers = node["powers"]; - for (const auto power : powers) + for (const auto power: powers) { rhs.powers.push_back(power.as()); } diff --git a/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp b/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp index d4a6c3512b..a38d7ea12c 100644 --- a/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp +++ b/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp @@ -6,23 +6,24 @@ #define WIN32_LEAN_AND_MEAN #include +#include + #include "include/antares/solver/simulation/hydro-final-reservoir-level-functions.h" #include "include/antares/study/parts/hydro/finalLevelValidator.h" -#include using namespace Antares::Solver; using namespace Antares::Data; - struct Fixture { Fixture(const Fixture& f) = delete; Fixture(const Fixture&& f) = delete; Fixture& operator=(const Fixture& f) = delete; Fixture& operator=(const Fixture&& f) = delete; + Fixture() { - // Simulation last day must be 365 so that final level checks succeeds + // Simulation last day must be 365 so that final level checks succeeds study->parameters.simulationDays.end = 365; study->parameters.firstMonthInYear = january; uint nbYears = study->parameters.nbYears = 2; @@ -56,7 +57,6 @@ struct Fixture area_1->hydro.deltaBetweenFinalAndInitialLevels.resize(nbYears); area_2->hydro.deltaBetweenFinalAndInitialLevels.resize(nbYears); - // Scenario builder for initial and final reservoir levels // ------------------------------------------------------- uint areasCount = study->areas.size(); @@ -96,7 +96,7 @@ struct Fixture // ... Area 2 : Inflows time series area_2->hydro.series->storage.resize(nbInflowTS, 365); area_2->hydro.series->storage.timeSeries.fill(300.); - area_2->hydro.series->storage[0][0] = 300. + 1.; //DAYS_PER_YEAR + area_2->hydro.series->storage[0][0] = 300. + 1.; // DAYS_PER_YEAR area_2->hydro.series->storage[0][DAYS_PER_YEAR - 1] = 300. + 2.; } @@ -178,7 +178,8 @@ BOOST_AUTO_TEST_CASE(final_level_not_set_by_user____check_succeeds_but_final_lev BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); } -BOOST_AUTO_TEST_CASE(initial_level_month_and_simulation_first_month_different___check_fails_and_final_level_not_usable) +BOOST_AUTO_TEST_CASE( + initial_level_month_and_simulation_first_month_different___check_fails_and_final_level_not_usable) { uint year = 0; area_1->hydro.initializeReservoirLevelDate = 3; // initialize reservoir level != January @@ -233,7 +234,8 @@ BOOST_AUTO_TEST_CASE(final_level_out_of_rule_curves___check_fails_and_final_leve BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); } -BOOST_AUTO_TEST_CASE(final_level_unreachable_because_of_too_few_inflows___check_fails_and_final_level_not_usable) +BOOST_AUTO_TEST_CASE( + final_level_unreachable_because_of_too_few_inflows___check_fails_and_final_level_not_usable) { area_1->hydro.reservoirCapacity = 185000; uint year = 0; @@ -272,4 +274,4 @@ BOOST_AUTO_TEST_CASE(check_all_areas_final_levels_when_config_is_ok___all_checks BOOST_CHECK_EQUAL(area_2->hydro.deltaBetweenFinalAndInitialLevels[1].value(), 4.3 - 2.4); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END() From 41b3f457422a38e9b26bb5d6a063b805a29357ed Mon Sep 17 00:00:00 2001 From: Abdoulbari Zaher <32519851+a-zakir@users.noreply.github.com> Date: Wed, 26 Jun 2024 11:24:13 +0200 Subject: [PATCH 05/10] Revert "Check formatting as part of the CI" (#2196) Reverts AntaresSimulatorTeam/Antares_Simulator#2193 --- .github/workflows/clang-format.yml | 36 - .../antlr-interface/ExprBaseVisitor.cpp | 3 + .../antares/antlr-interface/ExprBaseVisitor.h | 144 +- .../antares/antlr-interface/ExprLexer.cpp | 323 ++-- src/libs/antares/antlr-interface/ExprLexer.h | 67 +- .../antares/antlr-interface/ExprParser.cpp | 1590 +++++++---------- src/libs/antares/antlr-interface/ExprParser.h | 392 ++-- .../antares/antlr-interface/ExprVisitor.cpp | 3 + .../antares/antlr-interface/ExprVisitor.h | 48 +- .../antares/checks/checkLoadedInputData.h | 1 + .../antares/exception/LoadingError.hpp | 7 +- .../FileTreeStudyLoader.h | 1 - .../include/antares/inifile/inifile.hxx | 3 +- src/libs/antares/inifile/inifile.cpp | 12 +- src/libs/antares/io/file.cpp | 2 +- src/libs/antares/io/include/antares/io/file.h | 4 +- .../antares/study-loader/IStudyLoader.h | 1 - src/libs/antares/study/area/area.cpp | 7 +- src/libs/antares/study/area/links.cpp | 27 +- src/libs/antares/study/area/list.cpp | 21 +- .../BindingConstraintGroupRepository.cpp | 18 +- .../antares/study/cleaner/cleaner-v20.cpp | 1 + .../study/include/antares/study/parameters.h | 3 +- .../antares/study/parts/hydro/container.h | 5 +- .../study/scenario-builder/hydroLevelsData.h | 3 +- .../study/include/antares/study/sets.hxx | 4 +- src/libs/antares/study/parameters.cpp | 17 +- .../study/parts/common/cluster_list.cpp | 5 +- .../antares/study/parts/hydro/allocation.cpp | 32 +- .../antares/study/parts/hydro/container.cpp | 256 ++- .../study/parts/hydro/finalLevelValidator.cpp | 46 +- src/libs/antares/study/parts/hydro/prepro.cpp | 8 +- src/libs/antares/study/parts/hydro/series.cpp | 2 +- .../study/parts/renewable/cluster_list.cpp | 2 +- .../parts/short-term-storage/container.cpp | 24 +- .../study/parts/thermal/cluster_list.cpp | 45 +- src/libs/antares/study/runtime/runtime.cpp | 6 +- .../BindingConstraintsTSNumbersData.cpp | 10 +- .../scenario-builder/hydroLevelsData.cpp | 6 +- .../antares/study/scenario-builder/rules.cpp | 5 +- src/libs/antares/study/study.cpp | 21 +- src/libs/antares/study/study.importprepro.cpp | 10 +- src/libs/antares/study/xcast/xcast.cpp | 3 +- src/libs/antares/writer/in_memory_writer.cpp | 2 +- src/libs/antares/writer/zip_writer.cpp | 1 + src/solver/application/application.cpp | 6 +- src/solver/constraints-builder/cbuilder.cpp | 3 +- .../solver/hydro/management/management.h | 3 +- src/solver/hydro/management/daily.cpp | 6 +- src/solver/hydro/management/management.cpp | 38 +- src/solver/hydro/management/monthly.cpp | 30 +- .../include/antares/solver/misc/options.h | 2 +- src/solver/misc/options.cpp | 2 +- src/solver/simulation/adequacy.cpp | 5 +- src/solver/simulation/common-eco-adq.cpp | 22 +- src/solver/simulation/common-hydro-levels.cpp | 22 +- src/solver/simulation/common-hydro-remix.cpp | 3 +- src/solver/simulation/economy.cpp | 5 +- .../hydro-final-reservoir-level-functions.cpp | 62 +- .../antares/solver/simulation/solver.hxx | 64 +- .../simulation/sim_calcul_economique.cpp | 10 +- src/solver/simulation/timeseries-numbers.cpp | 3 +- src/solver/ts-generator/availability.cpp | 22 +- src/solver/ts-generator/xcast/xcast.cpp | 3 +- src/solver/utils/ortools_utils.cpp | 8 +- .../antares/solver/variable/economy/all.h | 4 +- .../bindingConstraintsMarginalCost.h | 7 +- .../antares/solver/variable/endoflist.h | 1 + .../end-to-end/simple_study/simple-study.cpp | 2 +- src/tests/end-to-end/utils/utils.cpp | 3 +- src/tests/end-to-end/utils/utils.h | 3 - .../antlr4-interface/test_antlr_interface.cpp | 8 +- .../test-sc-builder-file-read-line.cpp | 80 +- .../test-sc-builder-file-save.cpp | 4 +- src/tests/src/libs/antares/test_utils.cpp | 9 +- .../antares/yaml-parser/test_yaml_parser.cpp | 16 +- ...-hydro-final-reservoir-level-functions.cpp | 18 +- 77 files changed, 1584 insertions(+), 2117 deletions(-) delete mode 100644 .github/workflows/clang-format.yml diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml deleted file mode 100644 index 9e00892851..0000000000 --- a/.github/workflows/clang-format.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Check cpp formatting - -on: - push: - branches: - - develop - - feature/* - - features/* - - fix/* - -jobs: - build: - name: clang-format - - runs-on: ubuntu-24.04 - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Print version - run: clang-format --version - - - name: clang-format - run: cd src && ./format-code.sh - - - name: git diff - run: | - DIFF=`git status --porcelain` - if [[ $DIFF ]]; then - echo "The following files are not well formatted" - echo "$DIFF" - exit 1 - else - echo "Code is well formatted, congrats !" - fi diff --git a/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp b/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp index ec45c3a47e..42d6fef5d3 100644 --- a/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp +++ b/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp @@ -1,4 +1,7 @@ // Generated from Expr.g4 by ANTLR 4.13.1 + #include "ExprBaseVisitor.h" + + diff --git a/src/libs/antares/antlr-interface/ExprBaseVisitor.h b/src/libs/antares/antlr-interface/ExprBaseVisitor.h index 7ff7be623d..a8af3c573f 100644 --- a/src/libs/antares/antlr-interface/ExprBaseVisitor.h +++ b/src/libs/antares/antlr-interface/ExprBaseVisitor.h @@ -3,88 +3,78 @@ #pragma once -#include "ExprVisitor.h" + #include "antlr4-runtime.h" +#include "ExprVisitor.h" + /** * This class provides an empty implementation of ExprVisitor, which can be * extended to create a visitor which only needs to handle a subset of the available methods. */ -class ExprBaseVisitor: public ExprVisitor -{ +class ExprBaseVisitor : public ExprVisitor { public: - virtual std::any visitFullexpr(ExprParser::FullexprContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitShift(ExprParser::ShiftContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitIdentifier(ExprParser::IdentifierContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitNegation(ExprParser::NegationContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitExpression(ExprParser::ExpressionContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitComparison(ExprParser::ComparisonContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitAddsub(ExprParser::AddsubContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitPortField(ExprParser::PortFieldContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitMuldiv(ExprParser::MuldivContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitNumber(ExprParser::NumberContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitTimeIndex(ExprParser::TimeIndexContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitTimeShift(ExprParser::TimeShiftContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitFunction(ExprParser::FunctionContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext* ctx) override - { - return visitChildren(ctx); - } - - virtual std::any visitTimeRange(ExprParser::TimeRangeContext* ctx) override - { - return visitChildren(ctx); - } + + virtual std::any visitFullexpr(ExprParser::FullexprContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitShift(ExprParser::ShiftContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitIdentifier(ExprParser::IdentifierContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitNegation(ExprParser::NegationContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitExpression(ExprParser::ExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitComparison(ExprParser::ComparisonContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitAddsub(ExprParser::AddsubContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitPortField(ExprParser::PortFieldContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitMuldiv(ExprParser::MuldivContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitNumber(ExprParser::NumberContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitTimeIndex(ExprParser::TimeIndexContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitTimeShift(ExprParser::TimeShiftContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitFunction(ExprParser::FunctionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitTimeRange(ExprParser::TimeRangeContext *ctx) override { + return visitChildren(ctx); + } + + }; + diff --git a/src/libs/antares/antlr-interface/ExprLexer.cpp b/src/libs/antares/antlr-interface/ExprLexer.cpp index 9250294cf8..a645fcddd0 100644 --- a/src/libs/antares/antlr-interface/ExprLexer.cpp +++ b/src/libs/antares/antlr-interface/ExprLexer.cpp @@ -1,238 +1,177 @@ // Generated from Expr.g4 by ANTLR 4.13.1 + #include "ExprLexer.h" + using namespace antlr4; + + using namespace antlr4; -namespace -{ - -struct ExprLexerStaticData final -{ - ExprLexerStaticData(std::vector ruleNames, - std::vector channelNames, - std::vector modeNames, - std::vector literalNames, - std::vector symbolicNames): - ruleNames(std::move(ruleNames)), - channelNames(std::move(channelNames)), - modeNames(std::move(modeNames)), - literalNames(std::move(literalNames)), - symbolicNames(std::move(symbolicNames)), - vocabulary(this->literalNames, this->symbolicNames) - { - } +namespace { - ExprLexerStaticData(const ExprLexerStaticData&) = delete; - ExprLexerStaticData(ExprLexerStaticData&&) = delete; - ExprLexerStaticData& operator=(const ExprLexerStaticData&) = delete; - ExprLexerStaticData& operator=(ExprLexerStaticData&&) = delete; - - std::vector decisionToDFA; - antlr4::atn::PredictionContextCache sharedContextCache; - const std::vector ruleNames; - const std::vector channelNames; - const std::vector modeNames; - const std::vector literalNames; - const std::vector symbolicNames; - const antlr4::dfa::Vocabulary vocabulary; - antlr4::atn::SerializedATNView serializedATN; - std::unique_ptr atn; +struct ExprLexerStaticData final { + ExprLexerStaticData(std::vector ruleNames, + std::vector channelNames, + std::vector modeNames, + std::vector literalNames, + std::vector symbolicNames) + : ruleNames(std::move(ruleNames)), channelNames(std::move(channelNames)), + modeNames(std::move(modeNames)), literalNames(std::move(literalNames)), + symbolicNames(std::move(symbolicNames)), + vocabulary(this->literalNames, this->symbolicNames) {} + + ExprLexerStaticData(const ExprLexerStaticData&) = delete; + ExprLexerStaticData(ExprLexerStaticData&&) = delete; + ExprLexerStaticData& operator=(const ExprLexerStaticData&) = delete; + ExprLexerStaticData& operator=(ExprLexerStaticData&&) = delete; + + std::vector decisionToDFA; + antlr4::atn::PredictionContextCache sharedContextCache; + const std::vector ruleNames; + const std::vector channelNames; + const std::vector modeNames; + const std::vector literalNames; + const std::vector symbolicNames; + const antlr4::dfa::Vocabulary vocabulary; + antlr4::atn::SerializedATNView serializedATN; + std::unique_ptr atn; }; ::antlr4::internal::OnceFlag exprlexerLexerOnceFlag; #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif - ExprLexerStaticData* exprlexerLexerStaticData - = nullptr; +ExprLexerStaticData *exprlexerLexerStaticData = nullptr; -void exprlexerLexerInitialize() -{ +void exprlexerLexerInitialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE - if (exprlexerLexerStaticData != nullptr) - { - return; - } + if (exprlexerLexerStaticData != nullptr) { + return; + } #else - assert(exprlexerLexerStaticData == nullptr); + assert(exprlexerLexerStaticData == nullptr); #endif - auto staticData = std::make_unique( - std::vector{"T__0", "T__1", "T__2", "T__3", "T__4", - "T__5", "T__6", "T__7", "T__8", "DIGIT", - "CHAR", "CHAR_OR_DIGIT", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", - "WS"}, - std::vector{"DEFAULT_TOKEN_CHANNEL", "HIDDEN"}, - std::vector{"DEFAULT_MODE"}, - std::vector{"", - "'+'", - "'-'", - "'/'", - "'*'", - "'.'", - "'('", - "')'", - "','", - "'..'", - "", - "'t'", - "", - "", - "", - "", - "'['", - "']'"}, - std::vector{"", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "NUMBER", - "TIME", - "IDENTIFIER", - "COMPARISON", - "ADDSUB", - "MULDIV", - "LBRACKET", - "RBRACKET", - "WS"}); - static const int32_t serializedATNSegment[] = { - 4, 0, 18, 111, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, - 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, - 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, - 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, - 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 1, 0, 1, 0, 1, - 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, - 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, - 10, 1, 10, 1, 11, 1, 11, 3, 11, 69, 8, 11, 1, 12, 4, 12, 72, 8, 12, - 11, 12, 12, 12, 73, 1, 12, 1, 12, 4, 12, 78, 8, 12, 11, 12, 12, 12, 79, - 3, 12, 82, 8, 12, 1, 13, 1, 13, 1, 14, 1, 14, 5, 14, 88, 8, 14, 10, - 14, 12, 14, 91, 9, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 98, - 8, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, - 20, 1, 20, 1, 20, 1, 20, 0, 0, 21, 1, 1, 3, 2, 5, 3, 7, 4, 9, - 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 0, 21, 0, 23, 0, 25, 10, 27, 11, - 29, 12, 31, 13, 33, 14, 35, 15, 37, 16, 39, 17, 41, 18, 1, 0, 5, 1, 0, - 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 2, 0, 43, 43, 45, 45, 2, 0, 42, - 42, 47, 47, 3, 0, 9, 10, 13, 13, 32, 32, 114, 0, 1, 1, 0, 0, 0, 0, - 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, - 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, - 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, - 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, - 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, - 0, 41, 1, 0, 0, 0, 1, 43, 1, 0, 0, 0, 3, 45, 1, 0, 0, 0, 5, - 47, 1, 0, 0, 0, 7, 49, 1, 0, 0, 0, 9, 51, 1, 0, 0, 0, 11, 53, - 1, 0, 0, 0, 13, 55, 1, 0, 0, 0, 15, 57, 1, 0, 0, 0, 17, 59, 1, - 0, 0, 0, 19, 62, 1, 0, 0, 0, 21, 64, 1, 0, 0, 0, 23, 68, 1, 0, - 0, 0, 25, 71, 1, 0, 0, 0, 27, 83, 1, 0, 0, 0, 29, 85, 1, 0, 0, - 0, 31, 97, 1, 0, 0, 0, 33, 99, 1, 0, 0, 0, 35, 101, 1, 0, 0, 0, - 37, 103, 1, 0, 0, 0, 39, 105, 1, 0, 0, 0, 41, 107, 1, 0, 0, 0, 43, - 44, 5, 43, 0, 0, 44, 2, 1, 0, 0, 0, 45, 46, 5, 45, 0, 0, 46, 4, - 1, 0, 0, 0, 47, 48, 5, 47, 0, 0, 48, 6, 1, 0, 0, 0, 49, 50, 5, - 42, 0, 0, 50, 8, 1, 0, 0, 0, 51, 52, 5, 46, 0, 0, 52, 10, 1, 0, - 0, 0, 53, 54, 5, 40, 0, 0, 54, 12, 1, 0, 0, 0, 55, 56, 5, 41, 0, - 0, 56, 14, 1, 0, 0, 0, 57, 58, 5, 44, 0, 0, 58, 16, 1, 0, 0, 0, - 59, 60, 5, 46, 0, 0, 60, 61, 5, 46, 0, 0, 61, 18, 1, 0, 0, 0, 62, - 63, 7, 0, 0, 0, 63, 20, 1, 0, 0, 0, 64, 65, 7, 1, 0, 0, 65, 22, - 1, 0, 0, 0, 66, 69, 3, 21, 10, 0, 67, 69, 3, 19, 9, 0, 68, 66, 1, - 0, 0, 0, 68, 67, 1, 0, 0, 0, 69, 24, 1, 0, 0, 0, 70, 72, 3, 19, - 9, 0, 71, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 71, 1, 0, 0, - 0, 73, 74, 1, 0, 0, 0, 74, 81, 1, 0, 0, 0, 75, 77, 5, 46, 0, 0, - 76, 78, 3, 19, 9, 0, 77, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, - 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 82, 1, 0, 0, 0, 81, 75, - 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 26, 1, 0, 0, 0, 83, 84, 5, - 116, 0, 0, 84, 28, 1, 0, 0, 0, 85, 89, 3, 21, 10, 0, 86, 88, 3, 23, - 11, 0, 87, 86, 1, 0, 0, 0, 88, 91, 1, 0, 0, 0, 89, 87, 1, 0, 0, - 0, 89, 90, 1, 0, 0, 0, 90, 30, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, - 92, 98, 5, 61, 0, 0, 93, 94, 5, 62, 0, 0, 94, 98, 5, 61, 0, 0, 95, - 96, 5, 60, 0, 0, 96, 98, 5, 61, 0, 0, 97, 92, 1, 0, 0, 0, 97, 93, - 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 98, 32, 1, 0, 0, 0, 99, 100, 7, - 2, 0, 0, 100, 34, 1, 0, 0, 0, 101, 102, 7, 3, 0, 0, 102, 36, 1, 0, - 0, 0, 103, 104, 5, 91, 0, 0, 104, 38, 1, 0, 0, 0, 105, 106, 5, 93, 0, - 0, 106, 40, 1, 0, 0, 0, 107, 108, 7, 4, 0, 0, 108, 109, 1, 0, 0, 0, - 109, 110, 6, 20, 0, 0, 110, 42, 1, 0, 0, 0, 7, 0, 68, 73, 79, 81, 89, - 97, 1, 6, 0, 0}; - staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, - sizeof(serializedATNSegment) - / sizeof(serializedATNSegment[0])); - - antlr4::atn::ATNDeserializer deserializer; - staticData->atn = deserializer.deserialize(staticData->serializedATN); - - const size_t count = staticData->atn->getNumberOfDecisions(); - staticData->decisionToDFA.reserve(count); - for (size_t i = 0; i < count; i++) - { - staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); + auto staticData = std::make_unique( + std::vector{ + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "DIGIT", "CHAR", "CHAR_OR_DIGIT", "NUMBER", "TIME", "IDENTIFIER", + "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" + }, + std::vector{ + "DEFAULT_TOKEN_CHANNEL", "HIDDEN" + }, + std::vector{ + "DEFAULT_MODE" + }, + std::vector{ + "", "'+'", "'-'", "'/'", "'*'", "'.'", "'('", "')'", "','", "'..'", + "", "'t'", "", "", "", "", "'['", "']'" + }, + std::vector{ + "", "", "", "", "", "", "", "", "", "", "NUMBER", "TIME", "IDENTIFIER", + "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" } - exprlexerLexerStaticData = staticData.release(); + ); + static const int32_t serializedATNSegment[] = { + 4,0,18,111,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, + 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,1,0, + 1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,8,1,8,1, + 8,1,9,1,9,1,10,1,10,1,11,1,11,3,11,69,8,11,1,12,4,12,72,8,12,11,12,12, + 12,73,1,12,1,12,4,12,78,8,12,11,12,12,12,79,3,12,82,8,12,1,13,1,13,1, + 14,1,14,5,14,88,8,14,10,14,12,14,91,9,14,1,15,1,15,1,15,1,15,1,15,3,15, + 98,8,15,1,16,1,16,1,17,1,17,1,18,1,18,1,19,1,19,1,20,1,20,1,20,1,20,0, + 0,21,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,0,21,0,23,0,25,10,27, + 11,29,12,31,13,33,14,35,15,37,16,39,17,41,18,1,0,5,1,0,48,57,3,0,65,90, + 95,95,97,122,2,0,43,43,45,45,2,0,42,42,47,47,3,0,9,10,13,13,32,32,114, + 0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0, + 0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0, + 0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39, + 1,0,0,0,0,41,1,0,0,0,1,43,1,0,0,0,3,45,1,0,0,0,5,47,1,0,0,0,7,49,1,0, + 0,0,9,51,1,0,0,0,11,53,1,0,0,0,13,55,1,0,0,0,15,57,1,0,0,0,17,59,1,0, + 0,0,19,62,1,0,0,0,21,64,1,0,0,0,23,68,1,0,0,0,25,71,1,0,0,0,27,83,1,0, + 0,0,29,85,1,0,0,0,31,97,1,0,0,0,33,99,1,0,0,0,35,101,1,0,0,0,37,103,1, + 0,0,0,39,105,1,0,0,0,41,107,1,0,0,0,43,44,5,43,0,0,44,2,1,0,0,0,45,46, + 5,45,0,0,46,4,1,0,0,0,47,48,5,47,0,0,48,6,1,0,0,0,49,50,5,42,0,0,50,8, + 1,0,0,0,51,52,5,46,0,0,52,10,1,0,0,0,53,54,5,40,0,0,54,12,1,0,0,0,55, + 56,5,41,0,0,56,14,1,0,0,0,57,58,5,44,0,0,58,16,1,0,0,0,59,60,5,46,0,0, + 60,61,5,46,0,0,61,18,1,0,0,0,62,63,7,0,0,0,63,20,1,0,0,0,64,65,7,1,0, + 0,65,22,1,0,0,0,66,69,3,21,10,0,67,69,3,19,9,0,68,66,1,0,0,0,68,67,1, + 0,0,0,69,24,1,0,0,0,70,72,3,19,9,0,71,70,1,0,0,0,72,73,1,0,0,0,73,71, + 1,0,0,0,73,74,1,0,0,0,74,81,1,0,0,0,75,77,5,46,0,0,76,78,3,19,9,0,77, + 76,1,0,0,0,78,79,1,0,0,0,79,77,1,0,0,0,79,80,1,0,0,0,80,82,1,0,0,0,81, + 75,1,0,0,0,81,82,1,0,0,0,82,26,1,0,0,0,83,84,5,116,0,0,84,28,1,0,0,0, + 85,89,3,21,10,0,86,88,3,23,11,0,87,86,1,0,0,0,88,91,1,0,0,0,89,87,1,0, + 0,0,89,90,1,0,0,0,90,30,1,0,0,0,91,89,1,0,0,0,92,98,5,61,0,0,93,94,5, + 62,0,0,94,98,5,61,0,0,95,96,5,60,0,0,96,98,5,61,0,0,97,92,1,0,0,0,97, + 93,1,0,0,0,97,95,1,0,0,0,98,32,1,0,0,0,99,100,7,2,0,0,100,34,1,0,0,0, + 101,102,7,3,0,0,102,36,1,0,0,0,103,104,5,91,0,0,104,38,1,0,0,0,105,106, + 5,93,0,0,106,40,1,0,0,0,107,108,7,4,0,0,108,109,1,0,0,0,109,110,6,20, + 0,0,110,42,1,0,0,0,7,0,68,73,79,81,89,97,1,6,0,0 + }; + staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); + + antlr4::atn::ATNDeserializer deserializer; + staticData->atn = deserializer.deserialize(staticData->serializedATN); + + const size_t count = staticData->atn->getNumberOfDecisions(); + staticData->decisionToDFA.reserve(count); + for (size_t i = 0; i < count; i++) { + staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); + } + exprlexerLexerStaticData = staticData.release(); } -} // namespace +} -ExprLexer::ExprLexer(CharStream* input): - Lexer(input) -{ - ExprLexer::initialize(); - _interpreter = new atn::LexerATNSimulator(this, - *exprlexerLexerStaticData->atn, - exprlexerLexerStaticData->decisionToDFA, - exprlexerLexerStaticData->sharedContextCache); +ExprLexer::ExprLexer(CharStream *input) : Lexer(input) { + ExprLexer::initialize(); + _interpreter = new atn::LexerATNSimulator(this, *exprlexerLexerStaticData->atn, exprlexerLexerStaticData->decisionToDFA, exprlexerLexerStaticData->sharedContextCache); } -ExprLexer::~ExprLexer() -{ - delete _interpreter; +ExprLexer::~ExprLexer() { + delete _interpreter; } -std::string ExprLexer::getGrammarFileName() const -{ - return "Expr.g4"; +std::string ExprLexer::getGrammarFileName() const { + return "Expr.g4"; } -const std::vector& ExprLexer::getRuleNames() const -{ - return exprlexerLexerStaticData->ruleNames; +const std::vector& ExprLexer::getRuleNames() const { + return exprlexerLexerStaticData->ruleNames; } -const std::vector& ExprLexer::getChannelNames() const -{ - return exprlexerLexerStaticData->channelNames; +const std::vector& ExprLexer::getChannelNames() const { + return exprlexerLexerStaticData->channelNames; } -const std::vector& ExprLexer::getModeNames() const -{ - return exprlexerLexerStaticData->modeNames; +const std::vector& ExprLexer::getModeNames() const { + return exprlexerLexerStaticData->modeNames; } -const dfa::Vocabulary& ExprLexer::getVocabulary() const -{ - return exprlexerLexerStaticData->vocabulary; +const dfa::Vocabulary& ExprLexer::getVocabulary() const { + return exprlexerLexerStaticData->vocabulary; } -antlr4::atn::SerializedATNView ExprLexer::getSerializedATN() const -{ - return exprlexerLexerStaticData->serializedATN; +antlr4::atn::SerializedATNView ExprLexer::getSerializedATN() const { + return exprlexerLexerStaticData->serializedATN; } -const atn::ATN& ExprLexer::getATN() const -{ - return *exprlexerLexerStaticData->atn; +const atn::ATN& ExprLexer::getATN() const { + return *exprlexerLexerStaticData->atn; } -void ExprLexer::initialize() -{ + + + +void ExprLexer::initialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE - exprlexerLexerInitialize(); + exprlexerLexerInitialize(); #else - ::antlr4::internal::call_once(exprlexerLexerOnceFlag, exprlexerLexerInitialize); + ::antlr4::internal::call_once(exprlexerLexerOnceFlag, exprlexerLexerInitialize); #endif } diff --git a/src/libs/antares/antlr-interface/ExprLexer.h b/src/libs/antares/antlr-interface/ExprLexer.h index a569ec8d21..c7db2c5f77 100644 --- a/src/libs/antares/antlr-interface/ExprLexer.h +++ b/src/libs/antares/antlr-interface/ExprLexer.h @@ -3,58 +3,49 @@ #pragma once + #include "antlr4-runtime.h" -class ExprLexer: public antlr4::Lexer -{ + + + +class ExprLexer : public antlr4::Lexer { public: - enum - { - T__0 = 1, - T__1 = 2, - T__2 = 3, - T__3 = 4, - T__4 = 5, - T__5 = 6, - T__6 = 7, - T__7 = 8, - T__8 = 9, - NUMBER = 10, - TIME = 11, - IDENTIFIER = 12, - COMPARISON = 13, - ADDSUB = 14, - MULDIV = 15, - LBRACKET = 16, - RBRACKET = 17, - WS = 18 - }; + enum { + T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, + T__7 = 8, T__8 = 9, NUMBER = 10, TIME = 11, IDENTIFIER = 12, COMPARISON = 13, + ADDSUB = 14, MULDIV = 15, LBRACKET = 16, RBRACKET = 17, WS = 18 + }; - explicit ExprLexer(antlr4::CharStream* input); + explicit ExprLexer(antlr4::CharStream *input); - ~ExprLexer() override; + ~ExprLexer() override; - std::string getGrammarFileName() const override; - const std::vector& getRuleNames() const override; + std::string getGrammarFileName() const override; - const std::vector& getChannelNames() const override; + const std::vector& getRuleNames() const override; - const std::vector& getModeNames() const override; + const std::vector& getChannelNames() const override; - const antlr4::dfa::Vocabulary& getVocabulary() const override; + const std::vector& getModeNames() const override; - antlr4::atn::SerializedATNView getSerializedATN() const override; + const antlr4::dfa::Vocabulary& getVocabulary() const override; - const antlr4::atn::ATN& getATN() const override; + antlr4::atn::SerializedATNView getSerializedATN() const override; - // By default the static state used to implement the lexer is lazily initialized during the - // first call to the constructor. You can call this function if you wish to initialize the - // static state ahead of time. - static void initialize(); + const antlr4::atn::ATN& getATN() const override; + + // By default the static state used to implement the lexer is lazily initialized during the first + // call to the constructor. You can call this function if you wish to initialize the static state + // ahead of time. + static void initialize(); private: - // Individual action functions triggered by action() above. - // Individual semantic predicate functions triggered by sempred() above. + // Individual action functions triggered by action() above. + + // Individual semantic predicate functions triggered by sempred() above. + }; + diff --git a/src/libs/antares/antlr-interface/ExprParser.cpp b/src/libs/antares/antlr-interface/ExprParser.cpp index 64335f4d82..3c688d96d3 100644 --- a/src/libs/antares/antlr-interface/ExprParser.cpp +++ b/src/libs/antares/antlr-interface/ExprParser.cpp @@ -1,1176 +1,884 @@ // Generated from Expr.g4 by ANTLR 4.13.1 -#include "ExprParser.h" #include "ExprVisitor.h" +#include "ExprParser.h" + + using namespace antlrcpp; using namespace antlr4; -namespace -{ +namespace { -struct ExprParserStaticData final -{ - ExprParserStaticData(std::vector ruleNames, - std::vector literalNames, - std::vector symbolicNames): - ruleNames(std::move(ruleNames)), - literalNames(std::move(literalNames)), +struct ExprParserStaticData final { + ExprParserStaticData(std::vector ruleNames, + std::vector literalNames, + std::vector symbolicNames) + : ruleNames(std::move(ruleNames)), literalNames(std::move(literalNames)), symbolicNames(std::move(symbolicNames)), - vocabulary(this->literalNames, this->symbolicNames) - { - } - - ExprParserStaticData(const ExprParserStaticData&) = delete; - ExprParserStaticData(ExprParserStaticData&&) = delete; - ExprParserStaticData& operator=(const ExprParserStaticData&) = delete; - ExprParserStaticData& operator=(ExprParserStaticData&&) = delete; - - std::vector decisionToDFA; - antlr4::atn::PredictionContextCache sharedContextCache; - const std::vector ruleNames; - const std::vector literalNames; - const std::vector symbolicNames; - const antlr4::dfa::Vocabulary vocabulary; - antlr4::atn::SerializedATNView serializedATN; - std::unique_ptr atn; + vocabulary(this->literalNames, this->symbolicNames) {} + + ExprParserStaticData(const ExprParserStaticData&) = delete; + ExprParserStaticData(ExprParserStaticData&&) = delete; + ExprParserStaticData& operator=(const ExprParserStaticData&) = delete; + ExprParserStaticData& operator=(ExprParserStaticData&&) = delete; + + std::vector decisionToDFA; + antlr4::atn::PredictionContextCache sharedContextCache; + const std::vector ruleNames; + const std::vector literalNames; + const std::vector symbolicNames; + const antlr4::dfa::Vocabulary vocabulary; + antlr4::atn::SerializedATNView serializedATN; + std::unique_ptr atn; }; ::antlr4::internal::OnceFlag exprParserOnceFlag; #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif - ExprParserStaticData* exprParserStaticData - = nullptr; +ExprParserStaticData *exprParserStaticData = nullptr; -void exprParserInitialize() -{ +void exprParserInitialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE - if (exprParserStaticData != nullptr) - { - return; - } + if (exprParserStaticData != nullptr) { + return; + } #else - assert(exprParserStaticData == nullptr); + assert(exprParserStaticData == nullptr); #endif - auto staticData = std::make_unique(std::vector{"fullexpr", - "shift", - "expr"}, - std::vector{"", - "'+'", - "'-'", - "'/'", - "'*'", - "'.'", - "'('", - "')'", - "','", - "'..'", - "", - "'t'", - "", - "", - "", - "", - "'['", - "']'"}, - std::vector{"", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "NUMBER", - "TIME", - "IDENTIFIER", - "COMPARISON", - "ADDSUB", - "MULDIV", - "LBRACKET", - "RBRACKET", - "WS"}); - static const int32_t serializedATNSegment[] = { - 4, 1, 18, 86, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, 0, 1, 1, - 1, 1, 1, 1, 3, 1, 13, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, - 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, - 2, 1, 2, 1, 2, 5, 2, 37, 8, 2, 10, 2, 12, 2, 40, 9, 2, 1, 2, 1, 2, 1, 2, 1, - 2, 1, 2, 1, 2, 1, 2, 5, 2, 49, 8, 2, 10, 2, 12, 2, 52, 9, 2, 1, 2, 1, 2, 1, - 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, - 2, 1, 2, 3, 2, 70, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, - 1, 2, 5, 2, 81, 8, 2, 10, 2, 12, 2, 84, 9, 2, 1, 2, 0, 1, 4, 3, 0, 2, 4, 0, - 2, 1, 0, 1, 2, 1, 0, 3, 4, 97, 0, 6, 1, 0, 0, 0, 2, 9, 1, 0, 0, 0, 4, 69, - 1, 0, 0, 0, 6, 7, 3, 4, 2, 0, 7, 8, 5, 0, 0, 1, 8, 1, 1, 0, 0, 0, 9, 12, - 5, 11, 0, 0, 10, 11, 7, 0, 0, 0, 11, 13, 3, 4, 2, 0, 12, 10, 1, 0, 0, 0, 12, 13, - 1, 0, 0, 0, 13, 3, 1, 0, 0, 0, 14, 15, 6, 2, -1, 0, 15, 16, 5, 2, 0, 0, 16, 70, - 3, 4, 2, 13, 17, 70, 5, 12, 0, 0, 18, 19, 5, 12, 0, 0, 19, 20, 5, 5, 0, 0, 20, 70, - 5, 12, 0, 0, 21, 70, 5, 10, 0, 0, 22, 23, 5, 6, 0, 0, 23, 24, 3, 4, 2, 0, 24, 25, - 5, 7, 0, 0, 25, 70, 1, 0, 0, 0, 26, 27, 5, 12, 0, 0, 27, 28, 5, 6, 0, 0, 28, 29, - 3, 4, 2, 0, 29, 30, 5, 7, 0, 0, 30, 70, 1, 0, 0, 0, 31, 32, 5, 12, 0, 0, 32, 33, - 5, 16, 0, 0, 33, 38, 3, 2, 1, 0, 34, 35, 5, 8, 0, 0, 35, 37, 3, 2, 1, 0, 36, 34, - 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, - 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 42, 5, 17, 0, 0, 42, 70, 1, 0, 0, 0, 43, 44, - 5, 12, 0, 0, 44, 45, 5, 16, 0, 0, 45, 50, 3, 4, 2, 0, 46, 47, 5, 8, 0, 0, 47, 49, - 3, 4, 2, 0, 48, 46, 1, 0, 0, 0, 49, 52, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, - 1, 0, 0, 0, 51, 53, 1, 0, 0, 0, 52, 50, 1, 0, 0, 0, 53, 54, 5, 17, 0, 0, 54, 70, - 1, 0, 0, 0, 55, 56, 5, 12, 0, 0, 56, 57, 5, 16, 0, 0, 57, 58, 3, 2, 1, 0, 58, 59, - 5, 9, 0, 0, 59, 60, 3, 2, 1, 0, 60, 61, 5, 17, 0, 0, 61, 70, 1, 0, 0, 0, 62, 63, - 5, 12, 0, 0, 63, 64, 5, 16, 0, 0, 64, 65, 3, 4, 2, 0, 65, 66, 5, 9, 0, 0, 66, 67, - 3, 4, 2, 0, 67, 68, 5, 17, 0, 0, 68, 70, 1, 0, 0, 0, 69, 14, 1, 0, 0, 0, 69, 17, - 1, 0, 0, 0, 69, 18, 1, 0, 0, 0, 69, 21, 1, 0, 0, 0, 69, 22, 1, 0, 0, 0, 69, 26, - 1, 0, 0, 0, 69, 31, 1, 0, 0, 0, 69, 43, 1, 0, 0, 0, 69, 55, 1, 0, 0, 0, 69, 62, - 1, 0, 0, 0, 70, 82, 1, 0, 0, 0, 71, 72, 10, 12, 0, 0, 72, 73, 7, 1, 0, 0, 73, 81, - 3, 4, 2, 13, 74, 75, 10, 11, 0, 0, 75, 76, 7, 0, 0, 0, 76, 81, 3, 4, 2, 12, 77, 78, - 10, 10, 0, 0, 78, 79, 5, 13, 0, 0, 79, 81, 3, 4, 2, 11, 80, 71, 1, 0, 0, 0, 80, 74, - 1, 0, 0, 0, 80, 77, 1, 0, 0, 0, 81, 84, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, - 1, 0, 0, 0, 83, 5, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 6, 12, 38, 50, 69, 80, 82}; - staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, - sizeof(serializedATNSegment) - / sizeof(serializedATNSegment[0])); - - antlr4::atn::ATNDeserializer deserializer; - staticData->atn = deserializer.deserialize(staticData->serializedATN); - - const size_t count = staticData->atn->getNumberOfDecisions(); - staticData->decisionToDFA.reserve(count); - for (size_t i = 0; i < count; i++) - { - staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); + auto staticData = std::make_unique( + std::vector{ + "fullexpr", "shift", "expr" + }, + std::vector{ + "", "'+'", "'-'", "'/'", "'*'", "'.'", "'('", "')'", "','", "'..'", + "", "'t'", "", "", "", "", "'['", "']'" + }, + std::vector{ + "", "", "", "", "", "", "", "", "", "", "NUMBER", "TIME", "IDENTIFIER", + "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" } - exprParserStaticData = staticData.release(); -} + ); + static const int32_t serializedATNSegment[] = { + 4,1,18,86,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,1,1,1,1,1,1,3,1,13,8,1, + 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,5,2,37,8,2,10,2,12,2,40,9,2,1,2,1,2,1,2,1,2,1,2,1,2, + 1,2,5,2,49,8,2,10,2,12,2,52,9,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,3,2,70,8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, + 1,2,5,2,81,8,2,10,2,12,2,84,9,2,1,2,0,1,4,3,0,2,4,0,2,1,0,1,2,1,0,3,4, + 97,0,6,1,0,0,0,2,9,1,0,0,0,4,69,1,0,0,0,6,7,3,4,2,0,7,8,5,0,0,1,8,1,1, + 0,0,0,9,12,5,11,0,0,10,11,7,0,0,0,11,13,3,4,2,0,12,10,1,0,0,0,12,13,1, + 0,0,0,13,3,1,0,0,0,14,15,6,2,-1,0,15,16,5,2,0,0,16,70,3,4,2,13,17,70, + 5,12,0,0,18,19,5,12,0,0,19,20,5,5,0,0,20,70,5,12,0,0,21,70,5,10,0,0,22, + 23,5,6,0,0,23,24,3,4,2,0,24,25,5,7,0,0,25,70,1,0,0,0,26,27,5,12,0,0,27, + 28,5,6,0,0,28,29,3,4,2,0,29,30,5,7,0,0,30,70,1,0,0,0,31,32,5,12,0,0,32, + 33,5,16,0,0,33,38,3,2,1,0,34,35,5,8,0,0,35,37,3,2,1,0,36,34,1,0,0,0,37, + 40,1,0,0,0,38,36,1,0,0,0,38,39,1,0,0,0,39,41,1,0,0,0,40,38,1,0,0,0,41, + 42,5,17,0,0,42,70,1,0,0,0,43,44,5,12,0,0,44,45,5,16,0,0,45,50,3,4,2,0, + 46,47,5,8,0,0,47,49,3,4,2,0,48,46,1,0,0,0,49,52,1,0,0,0,50,48,1,0,0,0, + 50,51,1,0,0,0,51,53,1,0,0,0,52,50,1,0,0,0,53,54,5,17,0,0,54,70,1,0,0, + 0,55,56,5,12,0,0,56,57,5,16,0,0,57,58,3,2,1,0,58,59,5,9,0,0,59,60,3,2, + 1,0,60,61,5,17,0,0,61,70,1,0,0,0,62,63,5,12,0,0,63,64,5,16,0,0,64,65, + 3,4,2,0,65,66,5,9,0,0,66,67,3,4,2,0,67,68,5,17,0,0,68,70,1,0,0,0,69,14, + 1,0,0,0,69,17,1,0,0,0,69,18,1,0,0,0,69,21,1,0,0,0,69,22,1,0,0,0,69,26, + 1,0,0,0,69,31,1,0,0,0,69,43,1,0,0,0,69,55,1,0,0,0,69,62,1,0,0,0,70,82, + 1,0,0,0,71,72,10,12,0,0,72,73,7,1,0,0,73,81,3,4,2,13,74,75,10,11,0,0, + 75,76,7,0,0,0,76,81,3,4,2,12,77,78,10,10,0,0,78,79,5,13,0,0,79,81,3,4, + 2,11,80,71,1,0,0,0,80,74,1,0,0,0,80,77,1,0,0,0,81,84,1,0,0,0,82,80,1, + 0,0,0,82,83,1,0,0,0,83,5,1,0,0,0,84,82,1,0,0,0,6,12,38,50,69,80,82 + }; + staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); + + antlr4::atn::ATNDeserializer deserializer; + staticData->atn = deserializer.deserialize(staticData->serializedATN); -} // namespace + const size_t count = staticData->atn->getNumberOfDecisions(); + staticData->decisionToDFA.reserve(count); + for (size_t i = 0; i < count; i++) { + staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); + } + exprParserStaticData = staticData.release(); +} -ExprParser::ExprParser(TokenStream* input): - ExprParser(input, antlr4::atn::ParserATNSimulatorOptions()) -{ } -ExprParser::ExprParser(TokenStream* input, const antlr4::atn::ParserATNSimulatorOptions& options): - Parser(input) -{ - ExprParser::initialize(); - _interpreter = new atn::ParserATNSimulator(this, - *exprParserStaticData->atn, - exprParserStaticData->decisionToDFA, - exprParserStaticData->sharedContextCache, - options); +ExprParser::ExprParser(TokenStream *input) : ExprParser(input, antlr4::atn::ParserATNSimulatorOptions()) {} + +ExprParser::ExprParser(TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options) : Parser(input) { + ExprParser::initialize(); + _interpreter = new atn::ParserATNSimulator(this, *exprParserStaticData->atn, exprParserStaticData->decisionToDFA, exprParserStaticData->sharedContextCache, options); } -ExprParser::~ExprParser() -{ - delete _interpreter; +ExprParser::~ExprParser() { + delete _interpreter; } -const atn::ATN& ExprParser::getATN() const -{ - return *exprParserStaticData->atn; +const atn::ATN& ExprParser::getATN() const { + return *exprParserStaticData->atn; } -std::string ExprParser::getGrammarFileName() const -{ - return "Expr.g4"; +std::string ExprParser::getGrammarFileName() const { + return "Expr.g4"; } -const std::vector& ExprParser::getRuleNames() const -{ - return exprParserStaticData->ruleNames; +const std::vector& ExprParser::getRuleNames() const { + return exprParserStaticData->ruleNames; } -const dfa::Vocabulary& ExprParser::getVocabulary() const -{ - return exprParserStaticData->vocabulary; +const dfa::Vocabulary& ExprParser::getVocabulary() const { + return exprParserStaticData->vocabulary; } -antlr4::atn::SerializedATNView ExprParser::getSerializedATN() const -{ - return exprParserStaticData->serializedATN; +antlr4::atn::SerializedATNView ExprParser::getSerializedATN() const { + return exprParserStaticData->serializedATN; } -//----------------- FullexprContext -//------------------------------------------------------------------ -ExprParser::FullexprContext::FullexprContext(ParserRuleContext* parent, size_t invokingState): - ParserRuleContext(parent, invokingState) -{ +//----------------- FullexprContext ------------------------------------------------------------------ + +ExprParser::FullexprContext::FullexprContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { } -ExprParser::ExprContext* ExprParser::FullexprContext::expr() -{ - return getRuleContext(0); +ExprParser::ExprContext* ExprParser::FullexprContext::expr() { + return getRuleContext(0); } -tree::TerminalNode* ExprParser::FullexprContext::EOF() -{ - return getToken(ExprParser::EOF, 0); +tree::TerminalNode* ExprParser::FullexprContext::EOF() { + return getToken(ExprParser::EOF, 0); } -size_t ExprParser::FullexprContext::getRuleIndex() const -{ - return ExprParser::RuleFullexpr; + +size_t ExprParser::FullexprContext::getRuleIndex() const { + return ExprParser::RuleFullexpr; } -std::any ExprParser::FullexprContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitFullexpr(this); - } - else - { - return visitor->visitChildren(this); - } + +std::any ExprParser::FullexprContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitFullexpr(this); + else + return visitor->visitChildren(this); } -ExprParser::FullexprContext* ExprParser::fullexpr() -{ - FullexprContext* _localctx = _tracker.createInstance(_ctx, getState()); - enterRule(_localctx, 0, ExprParser::RuleFullexpr); +ExprParser::FullexprContext* ExprParser::fullexpr() { + FullexprContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 0, ExprParser::RuleFullexpr); #if __cplusplus > 201703L - auto onExit = finally( - [=, this] - { + auto onExit = finally([=, this] { #else - auto onExit = finally( - [=] - { + auto onExit = finally([=] { #endif - exitRule(); - }); - try - { - enterOuterAlt(_localctx, 1); - setState(6); - expr(0); - setState(7); - match(ExprParser::EOF); - } - catch (RecognitionException& e) - { - _errHandler->reportError(this, e); - _localctx->exception = std::current_exception(); - _errHandler->recover(this, _localctx->exception); - } - - return _localctx; + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(6); + expr(0); + setState(7); + match(ExprParser::EOF); + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; } //----------------- ShiftContext ------------------------------------------------------------------ -ExprParser::ShiftContext::ShiftContext(ParserRuleContext* parent, size_t invokingState): - ParserRuleContext(parent, invokingState) -{ +ExprParser::ShiftContext::ShiftContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { } -tree::TerminalNode* ExprParser::ShiftContext::TIME() -{ - return getToken(ExprParser::TIME, 0); +tree::TerminalNode* ExprParser::ShiftContext::TIME() { + return getToken(ExprParser::TIME, 0); } -ExprParser::ExprContext* ExprParser::ShiftContext::expr() -{ - return getRuleContext(0); +ExprParser::ExprContext* ExprParser::ShiftContext::expr() { + return getRuleContext(0); } -size_t ExprParser::ShiftContext::getRuleIndex() const -{ - return ExprParser::RuleShift; + +size_t ExprParser::ShiftContext::getRuleIndex() const { + return ExprParser::RuleShift; } -std::any ExprParser::ShiftContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitShift(this); - } - else - { - return visitor->visitChildren(this); - } + +std::any ExprParser::ShiftContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitShift(this); + else + return visitor->visitChildren(this); } -ExprParser::ShiftContext* ExprParser::shift() -{ - ShiftContext* _localctx = _tracker.createInstance(_ctx, getState()); - enterRule(_localctx, 2, ExprParser::RuleShift); - size_t _la = 0; +ExprParser::ShiftContext* ExprParser::shift() { + ShiftContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 2, ExprParser::RuleShift); + size_t _la = 0; #if __cplusplus > 201703L - auto onExit = finally( - [=, this] - { + auto onExit = finally([=, this] { #else - auto onExit = finally( - [=] - { + auto onExit = finally([=] { #endif - exitRule(); - }); - try - { - enterOuterAlt(_localctx, 1); - setState(9); - match(ExprParser::TIME); - setState(12); - _errHandler->sync(this); - - _la = _input->LA(1); - if (_la == ExprParser::T__0 - - || _la == ExprParser::T__1) - { - setState(10); - antlrcpp::downCast(_localctx)->op = _input->LT(1); - _la = _input->LA(1); - if (!(_la == ExprParser::T__0 - - || _la == ExprParser::T__1)) - { - antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); - } - else - { - _errHandler->reportMatch(this); - consume(); - } - setState(11); - expr(0); - } - } - catch (RecognitionException& e) - { - _errHandler->reportError(this, e); - _localctx->exception = std::current_exception(); - _errHandler->recover(this, _localctx->exception); - } - - return _localctx; + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(9); + match(ExprParser::TIME); + setState(12); + _errHandler->sync(this); + + _la = _input->LA(1); + if (_la == ExprParser::T__0 + + || _la == ExprParser::T__1) { + setState(10); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__0 + + || _la == ExprParser::T__1)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(11); + expr(0); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; } //----------------- ExprContext ------------------------------------------------------------------ -ExprParser::ExprContext::ExprContext(ParserRuleContext* parent, size_t invokingState): - ParserRuleContext(parent, invokingState) -{ +ExprParser::ExprContext::ExprContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { } -size_t ExprParser::ExprContext::getRuleIndex() const -{ - return ExprParser::RuleExpr; -} -void ExprParser::ExprContext::copyFrom(ExprContext* ctx) -{ - ParserRuleContext::copyFrom(ctx); +size_t ExprParser::ExprContext::getRuleIndex() const { + return ExprParser::RuleExpr; } -//----------------- IdentifierContext -//------------------------------------------------------------------ - -tree::TerminalNode* ExprParser::IdentifierContext::IDENTIFIER() -{ - return getToken(ExprParser::IDENTIFIER, 0); +void ExprParser::ExprContext::copyFrom(ExprContext *ctx) { + ParserRuleContext::copyFrom(ctx); } -ExprParser::IdentifierContext::IdentifierContext(ExprContext* ctx) -{ - copyFrom(ctx); -} +//----------------- IdentifierContext ------------------------------------------------------------------ -std::any ExprParser::IdentifierContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitIdentifier(this); - } - else - { - return visitor->visitChildren(this); - } +tree::TerminalNode* ExprParser::IdentifierContext::IDENTIFIER() { + return getToken(ExprParser::IDENTIFIER, 0); } -//----------------- NegationContext -//------------------------------------------------------------------ +ExprParser::IdentifierContext::IdentifierContext(ExprContext *ctx) { copyFrom(ctx); } -ExprParser::ExprContext* ExprParser::NegationContext::expr() -{ - return getRuleContext(0); -} -ExprParser::NegationContext::NegationContext(ExprContext* ctx) -{ - copyFrom(ctx); +std::any ExprParser::IdentifierContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitIdentifier(this); + else + return visitor->visitChildren(this); } +//----------------- NegationContext ------------------------------------------------------------------ -std::any ExprParser::NegationContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitNegation(this); - } - else - { - return visitor->visitChildren(this); - } +ExprParser::ExprContext* ExprParser::NegationContext::expr() { + return getRuleContext(0); } -//----------------- ExpressionContext -//------------------------------------------------------------------ +ExprParser::NegationContext::NegationContext(ExprContext *ctx) { copyFrom(ctx); } -ExprParser::ExprContext* ExprParser::ExpressionContext::expr() -{ - return getRuleContext(0); -} -ExprParser::ExpressionContext::ExpressionContext(ExprContext* ctx) -{ - copyFrom(ctx); +std::any ExprParser::NegationContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitNegation(this); + else + return visitor->visitChildren(this); } +//----------------- ExpressionContext ------------------------------------------------------------------ -std::any ExprParser::ExpressionContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitExpression(this); - } - else - { - return visitor->visitChildren(this); - } +ExprParser::ExprContext* ExprParser::ExpressionContext::expr() { + return getRuleContext(0); } -//----------------- ComparisonContext -//------------------------------------------------------------------ +ExprParser::ExpressionContext::ExpressionContext(ExprContext *ctx) { copyFrom(ctx); } -std::vector ExprParser::ComparisonContext::expr() -{ - return getRuleContexts(); -} -ExprParser::ExprContext* ExprParser::ComparisonContext::expr(size_t i) -{ - return getRuleContext(i); +std::any ExprParser::ExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitExpression(this); + else + return visitor->visitChildren(this); } +//----------------- ComparisonContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::ComparisonContext::COMPARISON() -{ - return getToken(ExprParser::COMPARISON, 0); +std::vector ExprParser::ComparisonContext::expr() { + return getRuleContexts(); } -ExprParser::ComparisonContext::ComparisonContext(ExprContext* ctx) -{ - copyFrom(ctx); +ExprParser::ExprContext* ExprParser::ComparisonContext::expr(size_t i) { + return getRuleContext(i); } -std::any ExprParser::ComparisonContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitComparison(this); - } - else - { - return visitor->visitChildren(this); - } +tree::TerminalNode* ExprParser::ComparisonContext::COMPARISON() { + return getToken(ExprParser::COMPARISON, 0); } -//----------------- AddsubContext ------------------------------------------------------------------ +ExprParser::ComparisonContext::ComparisonContext(ExprContext *ctx) { copyFrom(ctx); } -std::vector ExprParser::AddsubContext::expr() -{ - return getRuleContexts(); -} -ExprParser::ExprContext* ExprParser::AddsubContext::expr(size_t i) -{ - return getRuleContext(i); +std::any ExprParser::ComparisonContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitComparison(this); + else + return visitor->visitChildren(this); } +//----------------- AddsubContext ------------------------------------------------------------------ -ExprParser::AddsubContext::AddsubContext(ExprContext* ctx) -{ - copyFrom(ctx); +std::vector ExprParser::AddsubContext::expr() { + return getRuleContexts(); } -std::any ExprParser::AddsubContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitAddsub(this); - } - else - { - return visitor->visitChildren(this); - } +ExprParser::ExprContext* ExprParser::AddsubContext::expr(size_t i) { + return getRuleContext(i); } -//----------------- PortFieldContext -//------------------------------------------------------------------ +ExprParser::AddsubContext::AddsubContext(ExprContext *ctx) { copyFrom(ctx); } -std::vector ExprParser::PortFieldContext::IDENTIFIER() -{ - return getTokens(ExprParser::IDENTIFIER); -} -tree::TerminalNode* ExprParser::PortFieldContext::IDENTIFIER(size_t i) -{ - return getToken(ExprParser::IDENTIFIER, i); +std::any ExprParser::AddsubContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitAddsub(this); + else + return visitor->visitChildren(this); } +//----------------- PortFieldContext ------------------------------------------------------------------ -ExprParser::PortFieldContext::PortFieldContext(ExprContext* ctx) -{ - copyFrom(ctx); +std::vector ExprParser::PortFieldContext::IDENTIFIER() { + return getTokens(ExprParser::IDENTIFIER); } -std::any ExprParser::PortFieldContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitPortField(this); - } - else - { - return visitor->visitChildren(this); - } +tree::TerminalNode* ExprParser::PortFieldContext::IDENTIFIER(size_t i) { + return getToken(ExprParser::IDENTIFIER, i); } -//----------------- MuldivContext ------------------------------------------------------------------ +ExprParser::PortFieldContext::PortFieldContext(ExprContext *ctx) { copyFrom(ctx); } -std::vector ExprParser::MuldivContext::expr() -{ - return getRuleContexts(); -} -ExprParser::ExprContext* ExprParser::MuldivContext::expr(size_t i) -{ - return getRuleContext(i); +std::any ExprParser::PortFieldContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitPortField(this); + else + return visitor->visitChildren(this); } +//----------------- MuldivContext ------------------------------------------------------------------ -ExprParser::MuldivContext::MuldivContext(ExprContext* ctx) -{ - copyFrom(ctx); +std::vector ExprParser::MuldivContext::expr() { + return getRuleContexts(); } -std::any ExprParser::MuldivContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitMuldiv(this); - } - else - { - return visitor->visitChildren(this); - } +ExprParser::ExprContext* ExprParser::MuldivContext::expr(size_t i) { + return getRuleContext(i); } -//----------------- NumberContext ------------------------------------------------------------------ +ExprParser::MuldivContext::MuldivContext(ExprContext *ctx) { copyFrom(ctx); } -tree::TerminalNode* ExprParser::NumberContext::NUMBER() -{ - return getToken(ExprParser::NUMBER, 0); -} -ExprParser::NumberContext::NumberContext(ExprContext* ctx) -{ - copyFrom(ctx); +std::any ExprParser::MuldivContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitMuldiv(this); + else + return visitor->visitChildren(this); } +//----------------- NumberContext ------------------------------------------------------------------ -std::any ExprParser::NumberContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitNumber(this); - } - else - { - return visitor->visitChildren(this); - } +tree::TerminalNode* ExprParser::NumberContext::NUMBER() { + return getToken(ExprParser::NUMBER, 0); } -//----------------- TimeIndexContext -//------------------------------------------------------------------ +ExprParser::NumberContext::NumberContext(ExprContext *ctx) { copyFrom(ctx); } -tree::TerminalNode* ExprParser::TimeIndexContext::IDENTIFIER() -{ - return getToken(ExprParser::IDENTIFIER, 0); -} -tree::TerminalNode* ExprParser::TimeIndexContext::LBRACKET() -{ - return getToken(ExprParser::LBRACKET, 0); +std::any ExprParser::NumberContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitNumber(this); + else + return visitor->visitChildren(this); } +//----------------- TimeIndexContext ------------------------------------------------------------------ -std::vector ExprParser::TimeIndexContext::expr() -{ - return getRuleContexts(); +tree::TerminalNode* ExprParser::TimeIndexContext::IDENTIFIER() { + return getToken(ExprParser::IDENTIFIER, 0); } -ExprParser::ExprContext* ExprParser::TimeIndexContext::expr(size_t i) -{ - return getRuleContext(i); +tree::TerminalNode* ExprParser::TimeIndexContext::LBRACKET() { + return getToken(ExprParser::LBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeIndexContext::RBRACKET() -{ - return getToken(ExprParser::RBRACKET, 0); +std::vector ExprParser::TimeIndexContext::expr() { + return getRuleContexts(); } -ExprParser::TimeIndexContext::TimeIndexContext(ExprContext* ctx) -{ - copyFrom(ctx); +ExprParser::ExprContext* ExprParser::TimeIndexContext::expr(size_t i) { + return getRuleContext(i); } -std::any ExprParser::TimeIndexContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitTimeIndex(this); - } - else - { - return visitor->visitChildren(this); - } +tree::TerminalNode* ExprParser::TimeIndexContext::RBRACKET() { + return getToken(ExprParser::RBRACKET, 0); } -//----------------- TimeShiftContext -//------------------------------------------------------------------ +ExprParser::TimeIndexContext::TimeIndexContext(ExprContext *ctx) { copyFrom(ctx); } -tree::TerminalNode* ExprParser::TimeShiftContext::IDENTIFIER() -{ - return getToken(ExprParser::IDENTIFIER, 0); -} -tree::TerminalNode* ExprParser::TimeShiftContext::LBRACKET() -{ - return getToken(ExprParser::LBRACKET, 0); +std::any ExprParser::TimeIndexContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitTimeIndex(this); + else + return visitor->visitChildren(this); } +//----------------- TimeShiftContext ------------------------------------------------------------------ -std::vector ExprParser::TimeShiftContext::shift() -{ - return getRuleContexts(); +tree::TerminalNode* ExprParser::TimeShiftContext::IDENTIFIER() { + return getToken(ExprParser::IDENTIFIER, 0); } -ExprParser::ShiftContext* ExprParser::TimeShiftContext::shift(size_t i) -{ - return getRuleContext(i); +tree::TerminalNode* ExprParser::TimeShiftContext::LBRACKET() { + return getToken(ExprParser::LBRACKET, 0); } -tree::TerminalNode* ExprParser::TimeShiftContext::RBRACKET() -{ - return getToken(ExprParser::RBRACKET, 0); +std::vector ExprParser::TimeShiftContext::shift() { + return getRuleContexts(); } -ExprParser::TimeShiftContext::TimeShiftContext(ExprContext* ctx) -{ - copyFrom(ctx); +ExprParser::ShiftContext* ExprParser::TimeShiftContext::shift(size_t i) { + return getRuleContext(i); } -std::any ExprParser::TimeShiftContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitTimeShift(this); - } - else - { - return visitor->visitChildren(this); - } +tree::TerminalNode* ExprParser::TimeShiftContext::RBRACKET() { + return getToken(ExprParser::RBRACKET, 0); } -//----------------- FunctionContext -//------------------------------------------------------------------ +ExprParser::TimeShiftContext::TimeShiftContext(ExprContext *ctx) { copyFrom(ctx); } -tree::TerminalNode* ExprParser::FunctionContext::IDENTIFIER() -{ - return getToken(ExprParser::IDENTIFIER, 0); -} -ExprParser::ExprContext* ExprParser::FunctionContext::expr() -{ - return getRuleContext(0); +std::any ExprParser::TimeShiftContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitTimeShift(this); + else + return visitor->visitChildren(this); } +//----------------- FunctionContext ------------------------------------------------------------------ -ExprParser::FunctionContext::FunctionContext(ExprContext* ctx) -{ - copyFrom(ctx); +tree::TerminalNode* ExprParser::FunctionContext::IDENTIFIER() { + return getToken(ExprParser::IDENTIFIER, 0); } -std::any ExprParser::FunctionContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitFunction(this); - } - else - { - return visitor->visitChildren(this); - } +ExprParser::ExprContext* ExprParser::FunctionContext::expr() { + return getRuleContext(0); } -//----------------- TimeShiftRangeContext -//------------------------------------------------------------------ +ExprParser::FunctionContext::FunctionContext(ExprContext *ctx) { copyFrom(ctx); } -tree::TerminalNode* ExprParser::TimeShiftRangeContext::IDENTIFIER() -{ - return getToken(ExprParser::IDENTIFIER, 0); -} -tree::TerminalNode* ExprParser::TimeShiftRangeContext::LBRACKET() -{ - return getToken(ExprParser::LBRACKET, 0); +std::any ExprParser::FunctionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitFunction(this); + else + return visitor->visitChildren(this); } +//----------------- TimeShiftRangeContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::TimeShiftRangeContext::RBRACKET() -{ - return getToken(ExprParser::RBRACKET, 0); +tree::TerminalNode* ExprParser::TimeShiftRangeContext::IDENTIFIER() { + return getToken(ExprParser::IDENTIFIER, 0); } -std::vector ExprParser::TimeShiftRangeContext::shift() -{ - return getRuleContexts(); +tree::TerminalNode* ExprParser::TimeShiftRangeContext::LBRACKET() { + return getToken(ExprParser::LBRACKET, 0); } -ExprParser::ShiftContext* ExprParser::TimeShiftRangeContext::shift(size_t i) -{ - return getRuleContext(i); +tree::TerminalNode* ExprParser::TimeShiftRangeContext::RBRACKET() { + return getToken(ExprParser::RBRACKET, 0); } -ExprParser::TimeShiftRangeContext::TimeShiftRangeContext(ExprContext* ctx) -{ - copyFrom(ctx); +std::vector ExprParser::TimeShiftRangeContext::shift() { + return getRuleContexts(); } -std::any ExprParser::TimeShiftRangeContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitTimeShiftRange(this); - } - else - { - return visitor->visitChildren(this); - } +ExprParser::ShiftContext* ExprParser::TimeShiftRangeContext::shift(size_t i) { + return getRuleContext(i); } -//----------------- TimeRangeContext -//------------------------------------------------------------------ +ExprParser::TimeShiftRangeContext::TimeShiftRangeContext(ExprContext *ctx) { copyFrom(ctx); } -tree::TerminalNode* ExprParser::TimeRangeContext::IDENTIFIER() -{ - return getToken(ExprParser::IDENTIFIER, 0); + +std::any ExprParser::TimeShiftRangeContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitTimeShiftRange(this); + else + return visitor->visitChildren(this); } +//----------------- TimeRangeContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::TimeRangeContext::LBRACKET() -{ - return getToken(ExprParser::LBRACKET, 0); +tree::TerminalNode* ExprParser::TimeRangeContext::IDENTIFIER() { + return getToken(ExprParser::IDENTIFIER, 0); } -std::vector ExprParser::TimeRangeContext::expr() -{ - return getRuleContexts(); +tree::TerminalNode* ExprParser::TimeRangeContext::LBRACKET() { + return getToken(ExprParser::LBRACKET, 0); } -ExprParser::ExprContext* ExprParser::TimeRangeContext::expr(size_t i) -{ - return getRuleContext(i); +std::vector ExprParser::TimeRangeContext::expr() { + return getRuleContexts(); } -tree::TerminalNode* ExprParser::TimeRangeContext::RBRACKET() -{ - return getToken(ExprParser::RBRACKET, 0); +ExprParser::ExprContext* ExprParser::TimeRangeContext::expr(size_t i) { + return getRuleContext(i); } -ExprParser::TimeRangeContext::TimeRangeContext(ExprContext* ctx) -{ - copyFrom(ctx); +tree::TerminalNode* ExprParser::TimeRangeContext::RBRACKET() { + return getToken(ExprParser::RBRACKET, 0); } -std::any ExprParser::TimeRangeContext::accept(tree::ParseTreeVisitor* visitor) -{ - if (auto parserVisitor = dynamic_cast(visitor)) - { - return parserVisitor->visitTimeRange(this); - } - else - { - return visitor->visitChildren(this); - } +ExprParser::TimeRangeContext::TimeRangeContext(ExprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::TimeRangeContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitTimeRange(this); + else + return visitor->visitChildren(this); } -ExprParser::ExprContext* ExprParser::expr() -{ - return expr(0); +ExprParser::ExprContext* ExprParser::expr() { + return expr(0); } -ExprParser::ExprContext* ExprParser::expr(int precedence) -{ - ParserRuleContext* parentContext = _ctx; - size_t parentState = getState(); - ExprParser::ExprContext* _localctx = _tracker.createInstance(_ctx, parentState); - ExprParser::ExprContext* previousContext = _localctx; - (void)previousContext; // Silence compiler, in case the context is not used by generated code. - size_t startState = 4; - enterRecursionRule(_localctx, 4, ExprParser::RuleExpr, precedence); +ExprParser::ExprContext* ExprParser::expr(int precedence) { + ParserRuleContext *parentContext = _ctx; + size_t parentState = getState(); + ExprParser::ExprContext *_localctx = _tracker.createInstance(_ctx, parentState); + ExprParser::ExprContext *previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 4; + enterRecursionRule(_localctx, 4, ExprParser::RuleExpr, precedence); size_t _la = 0; #if __cplusplus > 201703L - auto onExit = finally( - [=, this] - { + auto onExit = finally([=, this] { #else - auto onExit = finally( - [=] - { + auto onExit = finally([=] { #endif - unrollRecursionContexts(parentContext); - }); - try - { - size_t alt; - enterOuterAlt(_localctx, 1); - setState(69); + unrollRecursionContexts(parentContext); + }); + try { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(69); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 3, _ctx)) { + case 1: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + + setState(15); + match(ExprParser::T__1); + setState(16); + expr(13); + break; + } + + case 2: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(17); + match(ExprParser::IDENTIFIER); + break; + } + + case 3: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(18); + match(ExprParser::IDENTIFIER); + setState(19); + match(ExprParser::T__4); + setState(20); + match(ExprParser::IDENTIFIER); + break; + } + + case 4: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(21); + match(ExprParser::NUMBER); + break; + } + + case 5: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(22); + match(ExprParser::T__5); + setState(23); + expr(0); + setState(24); + match(ExprParser::T__6); + break; + } + + case 6: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(26); + match(ExprParser::IDENTIFIER); + setState(27); + match(ExprParser::T__5); + setState(28); + expr(0); + setState(29); + match(ExprParser::T__6); + break; + } + + case 7: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(31); + match(ExprParser::IDENTIFIER); + setState(32); + match(ExprParser::LBRACKET); + setState(33); + shift(); + setState(38); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == ExprParser::T__7) { + setState(34); + match(ExprParser::T__7); + setState(35); + shift(); + setState(40); _errHandler->sync(this); - switch (getInterpreter()->adaptivePredict(_input, 3, _ctx)) - { - case 1: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - - setState(15); - match(ExprParser::T__1); - setState(16); - expr(13); - break; - } - - case 2: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(17); - match(ExprParser::IDENTIFIER); - break; - } - - case 3: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(18); - match(ExprParser::IDENTIFIER); - setState(19); - match(ExprParser::T__4); - setState(20); - match(ExprParser::IDENTIFIER); - break; - } - - case 4: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(21); - match(ExprParser::NUMBER); - break; - } - - case 5: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(22); - match(ExprParser::T__5); - setState(23); - expr(0); - setState(24); - match(ExprParser::T__6); - break; - } - - case 6: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(26); - match(ExprParser::IDENTIFIER); - setState(27); - match(ExprParser::T__5); - setState(28); - expr(0); - setState(29); - match(ExprParser::T__6); - break; - } - - case 7: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(31); - match(ExprParser::IDENTIFIER); - setState(32); - match(ExprParser::LBRACKET); - setState(33); - shift(); - setState(38); - _errHandler->sync(this); - _la = _input->LA(1); - while (_la == ExprParser::T__7) - { - setState(34); - match(ExprParser::T__7); - setState(35); - shift(); - setState(40); - _errHandler->sync(this); - _la = _input->LA(1); - } - setState(41); - match(ExprParser::RBRACKET); - break; - } + _la = _input->LA(1); + } + setState(41); + match(ExprParser::RBRACKET); + break; + } + + case 8: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(43); + match(ExprParser::IDENTIFIER); + setState(44); + match(ExprParser::LBRACKET); + setState(45); + expr(0); + setState(50); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == ExprParser::T__7) { + setState(46); + match(ExprParser::T__7); + setState(47); + expr(0); + setState(52); + _errHandler->sync(this); + _la = _input->LA(1); + } + setState(53); + match(ExprParser::RBRACKET); + break; + } + + case 9: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(55); + match(ExprParser::IDENTIFIER); + setState(56); + match(ExprParser::LBRACKET); + setState(57); + antlrcpp::downCast(_localctx)->shift1 = shift(); + setState(58); + match(ExprParser::T__8); + setState(59); + antlrcpp::downCast(_localctx)->shift2 = shift(); + setState(60); + match(ExprParser::RBRACKET); + break; + } + + case 10: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(62); + match(ExprParser::IDENTIFIER); + setState(63); + match(ExprParser::LBRACKET); + setState(64); + expr(0); + setState(65); + match(ExprParser::T__8); + setState(66); + expr(0); + setState(67); + match(ExprParser::RBRACKET); + break; + } - case 8: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(43); - match(ExprParser::IDENTIFIER); - setState(44); - match(ExprParser::LBRACKET); - setState(45); - expr(0); - setState(50); - _errHandler->sync(this); - _la = _input->LA(1); - while (_la == ExprParser::T__7) - { - setState(46); - match(ExprParser::T__7); - setState(47); - expr(0); - setState(52); - _errHandler->sync(this); - _la = _input->LA(1); - } - setState(53); - match(ExprParser::RBRACKET); - break; + default: + break; + } + _ctx->stop = _input->LT(-1); + setState(82); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { + if (alt == 1) { + if (!_parseListeners.empty()) + triggerExitRuleEvent(); + previousContext = _localctx; + setState(80); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 4, _ctx)) { + case 1: { + auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleExpr); + setState(71); + + if (!(precpred(_ctx, 12))) throw FailedPredicateException(this, "precpred(_ctx, 12)"); + setState(72); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__2 + + || _la == ExprParser::T__3)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(73); + expr(13); + break; } - case 9: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(55); - match(ExprParser::IDENTIFIER); - setState(56); - match(ExprParser::LBRACKET); - setState(57); - antlrcpp::downCast(_localctx)->shift1 = shift(); - setState(58); - match(ExprParser::T__8); - setState(59); - antlrcpp::downCast(_localctx)->shift2 = shift(); - setState(60); - match(ExprParser::RBRACKET); - break; + case 2: { + auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleExpr); + setState(74); + + if (!(precpred(_ctx, 11))) throw FailedPredicateException(this, "precpred(_ctx, 11)"); + setState(75); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__0 + + || _la == ExprParser::T__1)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(76); + expr(12); + break; } - case 10: - { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; - setState(62); - match(ExprParser::IDENTIFIER); - setState(63); - match(ExprParser::LBRACKET); - setState(64); - expr(0); - setState(65); - match(ExprParser::T__8); - setState(66); - expr(0); - setState(67); - match(ExprParser::RBRACKET); - break; + case 3: { + auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleExpr); + setState(77); + + if (!(precpred(_ctx, 10))) throw FailedPredicateException(this, "precpred(_ctx, 10)"); + setState(78); + match(ExprParser::COMPARISON); + setState(79); + expr(11); + break; } default: - break; - } - _ctx->stop = _input->LT(-1); - setState(82); - _errHandler->sync(this); - alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); - while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) - { - if (alt == 1) - { - if (!_parseListeners.empty()) - { - triggerExitRuleEvent(); - } - previousContext = _localctx; - setState(80); - _errHandler->sync(this); - switch (getInterpreter()->adaptivePredict(_input, 4, _ctx)) - { - case 1: - { - auto newContext = _tracker.createInstance( - _tracker.createInstance(parentContext, parentState)); - _localctx = newContext; - pushNewRecursionContext(newContext, startState, RuleExpr); - setState(71); - - if (!(precpred(_ctx, 12))) - { - throw FailedPredicateException(this, "precpred(_ctx, 12)"); - } - setState(72); - antlrcpp::downCast(_localctx)->op = _input->LT(1); - _la = _input->LA(1); - if (!(_la == ExprParser::T__2 - - || _la == ExprParser::T__3)) - { - antlrcpp::downCast(_localctx)->op = _errHandler - ->recoverInline(this); - } - else - { - _errHandler->reportMatch(this); - consume(); - } - setState(73); - expr(13); - break; - } - - case 2: - { - auto newContext = _tracker.createInstance( - _tracker.createInstance(parentContext, parentState)); - _localctx = newContext; - pushNewRecursionContext(newContext, startState, RuleExpr); - setState(74); - - if (!(precpred(_ctx, 11))) - { - throw FailedPredicateException(this, "precpred(_ctx, 11)"); - } - setState(75); - antlrcpp::downCast(_localctx)->op = _input->LT(1); - _la = _input->LA(1); - if (!(_la == ExprParser::T__0 - - || _la == ExprParser::T__1)) - { - antlrcpp::downCast(_localctx)->op = _errHandler - ->recoverInline(this); - } - else - { - _errHandler->reportMatch(this); - consume(); - } - setState(76); - expr(12); - break; - } - - case 3: - { - auto newContext = _tracker.createInstance( - _tracker.createInstance(parentContext, parentState)); - _localctx = newContext; - pushNewRecursionContext(newContext, startState, RuleExpr); - setState(77); - - if (!(precpred(_ctx, 10))) - { - throw FailedPredicateException(this, "precpred(_ctx, 10)"); - } - setState(78); - match(ExprParser::COMPARISON); - setState(79); - expr(11); - break; - } - - default: - break; - } - } - setState(84); - _errHandler->sync(this); - alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); - } - } - catch (RecognitionException& e) - { - _errHandler->reportError(this, e); - _localctx->exception = std::current_exception(); - _errHandler->recover(this, _localctx->exception); + break; + } + } + setState(84); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); } - return _localctx; + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + return _localctx; } -bool ExprParser::sempred(RuleContext* context, size_t ruleIndex, size_t predicateIndex) -{ - switch (ruleIndex) - { - case 2: - return exprSempred(antlrcpp::downCast(context), predicateIndex); +bool ExprParser::sempred(RuleContext *context, size_t ruleIndex, size_t predicateIndex) { + switch (ruleIndex) { + case 2: return exprSempred(antlrcpp::downCast(context), predicateIndex); - default: - break; - } - return true; + default: + break; + } + return true; } -bool ExprParser::exprSempred(ExprContext* _localctx, size_t predicateIndex) -{ - switch (predicateIndex) - { - case 0: - return precpred(_ctx, 12); - case 1: - return precpred(_ctx, 11); - case 2: - return precpred(_ctx, 10); +bool ExprParser::exprSempred(ExprContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 0: return precpred(_ctx, 12); + case 1: return precpred(_ctx, 11); + case 2: return precpred(_ctx, 10); - default: - break; - } - return true; + default: + break; + } + return true; } -void ExprParser::initialize() -{ +void ExprParser::initialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE - exprParserInitialize(); + exprParserInitialize(); #else - ::antlr4::internal::call_once(exprParserOnceFlag, exprParserInitialize); + ::antlr4::internal::call_once(exprParserOnceFlag, exprParserInitialize); #endif } diff --git a/src/libs/antares/antlr-interface/ExprParser.h b/src/libs/antares/antlr-interface/ExprParser.h index 6573ea2b2d..aa1c8b6f09 100644 --- a/src/libs/antares/antlr-interface/ExprParser.h +++ b/src/libs/antares/antlr-interface/ExprParser.h @@ -3,266 +3,242 @@ #pragma once + #include "antlr4-runtime.h" -class ExprParser: public antlr4::Parser -{ + + + +class ExprParser : public antlr4::Parser { public: - enum - { - T__0 = 1, - T__1 = 2, - T__2 = 3, - T__3 = 4, - T__4 = 5, - T__5 = 6, - T__6 = 7, - T__7 = 8, - T__8 = 9, - NUMBER = 10, - TIME = 11, - IDENTIFIER = 12, - COMPARISON = 13, - ADDSUB = 14, - MULDIV = 15, - LBRACKET = 16, - RBRACKET = 17, - WS = 18 - }; - - enum - { - RuleFullexpr = 0, - RuleShift = 1, - RuleExpr = 2 - }; - - explicit ExprParser(antlr4::TokenStream* input); + enum { + T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, + T__7 = 8, T__8 = 9, NUMBER = 10, TIME = 11, IDENTIFIER = 12, COMPARISON = 13, + ADDSUB = 14, MULDIV = 15, LBRACKET = 16, RBRACKET = 17, WS = 18 + }; + + enum { + RuleFullexpr = 0, RuleShift = 1, RuleExpr = 2 + }; + + explicit ExprParser(antlr4::TokenStream *input); + + ExprParser(antlr4::TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options); + + ~ExprParser() override; + + std::string getGrammarFileName() const override; + + const antlr4::atn::ATN& getATN() const override; + + const std::vector& getRuleNames() const override; - ExprParser(antlr4::TokenStream* input, const antlr4::atn::ParserATNSimulatorOptions& options); - - ~ExprParser() override; + const antlr4::dfa::Vocabulary& getVocabulary() const override; - std::string getGrammarFileName() const override; - - const antlr4::atn::ATN& getATN() const override; + antlr4::atn::SerializedATNView getSerializedATN() const override; - const std::vector& getRuleNames() const override; - - const antlr4::dfa::Vocabulary& getVocabulary() const override; - antlr4::atn::SerializedATNView getSerializedATN() const override; - - class FullexprContext; - class ShiftContext; - class ExprContext; - - class FullexprContext: public antlr4::ParserRuleContext - { - public: - FullexprContext(antlr4::ParserRuleContext* parent, size_t invokingState); - virtual size_t getRuleIndex() const override; - ExprContext* expr(); - antlr4::tree::TerminalNode* EOF(); - - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; - - FullexprContext* fullexpr(); + class FullexprContext; + class ShiftContext; + class ExprContext; - class ShiftContext: public antlr4::ParserRuleContext - { - public: - antlr4::Token* op = nullptr; - ShiftContext(antlr4::ParserRuleContext* parent, size_t invokingState); - virtual size_t getRuleIndex() const override; - antlr4::tree::TerminalNode* TIME(); - ExprContext* expr(); + class FullexprContext : public antlr4::ParserRuleContext { + public: + FullexprContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + ExprContext *expr(); + antlr4::tree::TerminalNode *EOF(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; - ShiftContext* shift(); + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; - class ExprContext: public antlr4::ParserRuleContext - { - public: - ExprContext(antlr4::ParserRuleContext* parent, size_t invokingState); + FullexprContext* fullexpr(); - ExprContext() = default; - void copyFrom(ExprContext* context); - using antlr4::ParserRuleContext::copyFrom; - - virtual size_t getRuleIndex() const override; - }; - - class IdentifierContext: public ExprContext - { - public: - IdentifierContext(ExprContext* ctx); - - antlr4::tree::TerminalNode* IDENTIFIER(); + class ShiftContext : public antlr4::ParserRuleContext { + public: + antlr4::Token *op = nullptr; + ShiftContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *TIME(); + ExprContext *expr(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; - - class NegationContext: public ExprContext - { - public: - NegationContext(ExprContext* ctx); - ExprContext* expr(); + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + ShiftContext* shift(); - class ExpressionContext: public ExprContext - { - public: - ExpressionContext(ExprContext* ctx); + class ExprContext : public antlr4::ParserRuleContext { + public: + ExprContext(antlr4::ParserRuleContext *parent, size_t invokingState); + + ExprContext() = default; + void copyFrom(ExprContext *context); + using antlr4::ParserRuleContext::copyFrom; - ExprContext* expr(); + virtual size_t getRuleIndex() const override; - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + + }; - class ComparisonContext: public ExprContext - { - public: - ComparisonContext(ExprContext* ctx); + class IdentifierContext : public ExprContext { + public: + IdentifierContext(ExprContext *ctx); - std::vector expr(); - ExprContext* expr(size_t i); - antlr4::tree::TerminalNode* COMPARISON(); + antlr4::tree::TerminalNode *IDENTIFIER(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class AddsubContext: public ExprContext - { - public: - AddsubContext(ExprContext* ctx); + class NegationContext : public ExprContext { + public: + NegationContext(ExprContext *ctx); - antlr4::Token* op = nullptr; - std::vector expr(); - ExprContext* expr(size_t i); + ExprContext *expr(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class PortFieldContext: public ExprContext - { - public: - PortFieldContext(ExprContext* ctx); + class ExpressionContext : public ExprContext { + public: + ExpressionContext(ExprContext *ctx); - std::vector IDENTIFIER(); - antlr4::tree::TerminalNode* IDENTIFIER(size_t i); + ExprContext *expr(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class MuldivContext: public ExprContext - { - public: - MuldivContext(ExprContext* ctx); + class ComparisonContext : public ExprContext { + public: + ComparisonContext(ExprContext *ctx); - antlr4::Token* op = nullptr; - std::vector expr(); - ExprContext* expr(size_t i); + std::vector expr(); + ExprContext* expr(size_t i); + antlr4::tree::TerminalNode *COMPARISON(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class NumberContext: public ExprContext - { - public: - NumberContext(ExprContext* ctx); + class AddsubContext : public ExprContext { + public: + AddsubContext(ExprContext *ctx); - antlr4::tree::TerminalNode* NUMBER(); + antlr4::Token *op = nullptr; + std::vector expr(); + ExprContext* expr(size_t i); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class TimeIndexContext: public ExprContext - { - public: - TimeIndexContext(ExprContext* ctx); + class PortFieldContext : public ExprContext { + public: + PortFieldContext(ExprContext *ctx); - antlr4::tree::TerminalNode* IDENTIFIER(); - antlr4::tree::TerminalNode* LBRACKET(); - std::vector expr(); - ExprContext* expr(size_t i); - antlr4::tree::TerminalNode* RBRACKET(); + std::vector IDENTIFIER(); + antlr4::tree::TerminalNode* IDENTIFIER(size_t i); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class TimeShiftContext: public ExprContext - { - public: - TimeShiftContext(ExprContext* ctx); + class MuldivContext : public ExprContext { + public: + MuldivContext(ExprContext *ctx); - antlr4::tree::TerminalNode* IDENTIFIER(); - antlr4::tree::TerminalNode* LBRACKET(); - std::vector shift(); - ShiftContext* shift(size_t i); - antlr4::tree::TerminalNode* RBRACKET(); + antlr4::Token *op = nullptr; + std::vector expr(); + ExprContext* expr(size_t i); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class FunctionContext: public ExprContext - { - public: - FunctionContext(ExprContext* ctx); + class NumberContext : public ExprContext { + public: + NumberContext(ExprContext *ctx); - antlr4::tree::TerminalNode* IDENTIFIER(); - ExprContext* expr(); + antlr4::tree::TerminalNode *NUMBER(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class TimeShiftRangeContext: public ExprContext - { - public: - TimeShiftRangeContext(ExprContext* ctx); + class TimeIndexContext : public ExprContext { + public: + TimeIndexContext(ExprContext *ctx); - ExprParser::ShiftContext* shift1 = nullptr; - ExprParser::ShiftContext* shift2 = nullptr; - antlr4::tree::TerminalNode* IDENTIFIER(); - antlr4::tree::TerminalNode* LBRACKET(); - antlr4::tree::TerminalNode* RBRACKET(); - std::vector shift(); - ShiftContext* shift(size_t i); + antlr4::tree::TerminalNode *IDENTIFIER(); + antlr4::tree::TerminalNode *LBRACKET(); + std::vector expr(); + ExprContext* expr(size_t i); + antlr4::tree::TerminalNode *RBRACKET(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class TimeRangeContext: public ExprContext - { - public: - TimeRangeContext(ExprContext* ctx); + class TimeShiftContext : public ExprContext { + public: + TimeShiftContext(ExprContext *ctx); - antlr4::tree::TerminalNode* IDENTIFIER(); - antlr4::tree::TerminalNode* LBRACKET(); - std::vector expr(); - ExprContext* expr(size_t i); - antlr4::tree::TerminalNode* RBRACKET(); + antlr4::tree::TerminalNode *IDENTIFIER(); + antlr4::tree::TerminalNode *LBRACKET(); + std::vector shift(); + ShiftContext* shift(size_t i); + antlr4::tree::TerminalNode *RBRACKET(); - virtual std::any accept(antlr4::tree::ParseTreeVisitor* visitor) override; - }; + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - ExprContext* expr(); - ExprContext* expr(int precedence); + class FunctionContext : public ExprContext { + public: + FunctionContext(ExprContext *ctx); - bool sempred(antlr4::RuleContext* _localctx, size_t ruleIndex, size_t predicateIndex) override; + antlr4::tree::TerminalNode *IDENTIFIER(); + ExprContext *expr(); - bool exprSempred(ExprContext* _localctx, size_t predicateIndex); + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - // By default the static state used to implement the parser is lazily initialized during the - // first call to the constructor. You can call this function if you wish to initialize the - // static state ahead of time. - static void initialize(); + class TimeShiftRangeContext : public ExprContext { + public: + TimeShiftRangeContext(ExprContext *ctx); + + ExprParser::ShiftContext *shift1 = nullptr; + ExprParser::ShiftContext *shift2 = nullptr; + antlr4::tree::TerminalNode *IDENTIFIER(); + antlr4::tree::TerminalNode *LBRACKET(); + antlr4::tree::TerminalNode *RBRACKET(); + std::vector shift(); + ShiftContext* shift(size_t i); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + + class TimeRangeContext : public ExprContext { + public: + TimeRangeContext(ExprContext *ctx); + + antlr4::tree::TerminalNode *IDENTIFIER(); + antlr4::tree::TerminalNode *LBRACKET(); + std::vector expr(); + ExprContext* expr(size_t i); + antlr4::tree::TerminalNode *RBRACKET(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + + ExprContext* expr(); + ExprContext* expr(int precedence); + + bool sempred(antlr4::RuleContext *_localctx, size_t ruleIndex, size_t predicateIndex) override; + + bool exprSempred(ExprContext *_localctx, size_t predicateIndex); + + // By default the static state used to implement the parser is lazily initialized during the first + // call to the constructor. You can call this function if you wish to initialize the static state + // ahead of time. + static void initialize(); private: }; + diff --git a/src/libs/antares/antlr-interface/ExprVisitor.cpp b/src/libs/antares/antlr-interface/ExprVisitor.cpp index bf0de76765..c214f0f76f 100644 --- a/src/libs/antares/antlr-interface/ExprVisitor.cpp +++ b/src/libs/antares/antlr-interface/ExprVisitor.cpp @@ -1,4 +1,7 @@ // Generated from Expr.g4 by ANTLR 4.13.1 + #include "ExprVisitor.h" + + diff --git a/src/libs/antares/antlr-interface/ExprVisitor.h b/src/libs/antares/antlr-interface/ExprVisitor.h index 6caed416f5..c064d6d54a 100644 --- a/src/libs/antares/antlr-interface/ExprVisitor.h +++ b/src/libs/antares/antlr-interface/ExprVisitor.h @@ -3,46 +3,52 @@ #pragma once -#include "ExprParser.h" + #include "antlr4-runtime.h" +#include "ExprParser.h" + + /** * This class defines an abstract visitor for a parse tree * produced by ExprParser. */ -class ExprVisitor: public antlr4::tree::AbstractParseTreeVisitor -{ +class ExprVisitor : public antlr4::tree::AbstractParseTreeVisitor { public: - /** - * Visit parse trees produced by ExprParser. - */ - virtual std::any visitFullexpr(ExprParser::FullexprContext* context) = 0; - virtual std::any visitShift(ExprParser::ShiftContext* context) = 0; + /** + * Visit parse trees produced by ExprParser. + */ + virtual std::any visitFullexpr(ExprParser::FullexprContext *context) = 0; - virtual std::any visitIdentifier(ExprParser::IdentifierContext* context) = 0; + virtual std::any visitShift(ExprParser::ShiftContext *context) = 0; - virtual std::any visitNegation(ExprParser::NegationContext* context) = 0; + virtual std::any visitIdentifier(ExprParser::IdentifierContext *context) = 0; - virtual std::any visitExpression(ExprParser::ExpressionContext* context) = 0; + virtual std::any visitNegation(ExprParser::NegationContext *context) = 0; - virtual std::any visitComparison(ExprParser::ComparisonContext* context) = 0; + virtual std::any visitExpression(ExprParser::ExpressionContext *context) = 0; - virtual std::any visitAddsub(ExprParser::AddsubContext* context) = 0; + virtual std::any visitComparison(ExprParser::ComparisonContext *context) = 0; - virtual std::any visitPortField(ExprParser::PortFieldContext* context) = 0; + virtual std::any visitAddsub(ExprParser::AddsubContext *context) = 0; - virtual std::any visitMuldiv(ExprParser::MuldivContext* context) = 0; + virtual std::any visitPortField(ExprParser::PortFieldContext *context) = 0; - virtual std::any visitNumber(ExprParser::NumberContext* context) = 0; + virtual std::any visitMuldiv(ExprParser::MuldivContext *context) = 0; - virtual std::any visitTimeIndex(ExprParser::TimeIndexContext* context) = 0; + virtual std::any visitNumber(ExprParser::NumberContext *context) = 0; - virtual std::any visitTimeShift(ExprParser::TimeShiftContext* context) = 0; + virtual std::any visitTimeIndex(ExprParser::TimeIndexContext *context) = 0; - virtual std::any visitFunction(ExprParser::FunctionContext* context) = 0; + virtual std::any visitTimeShift(ExprParser::TimeShiftContext *context) = 0; + + virtual std::any visitFunction(ExprParser::FunctionContext *context) = 0; + + virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext *context) = 0; + + virtual std::any visitTimeRange(ExprParser::TimeRangeContext *context) = 0; - virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext* context) = 0; - virtual std::any visitTimeRange(ExprParser::TimeRangeContext* context) = 0; }; + diff --git a/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h b/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h index 62352390bc..113451410f 100644 --- a/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h +++ b/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h @@ -28,6 +28,7 @@ void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode, bool ortoolsUsed, const std::string& solverName); + void checkStudyVersion(const AnyString& optStudyFolder); void checkSimplexRangeHydroPricing(Antares::Data::SimplexOptimization optRange, diff --git a/src/libs/antares/exception/include/antares/exception/LoadingError.hpp b/src/libs/antares/exception/include/antares/exception/LoadingError.hpp index c79b1a791e..ab1ae664d8 100644 --- a/src/libs/antares/exception/include/antares/exception/LoadingError.hpp +++ b/src/libs/antares/exception/include/antares/exception/LoadingError.hpp @@ -130,14 +130,13 @@ class InvalidSolver: public LoadingError explicit InvalidSolver(const std::string& solver, const std::string& availableSolverList); }; -class InvalidSolverSpecificParameters: public LoadingError +class InvalidSolverSpecificParameters : public LoadingError { public: - explicit InvalidSolverSpecificParameters(const std::string& solver, - const std::string& specificParameters); + explicit InvalidSolverSpecificParameters(const std::string& solver, const std::string& specificParameters); }; -class InvalidStudy: public LoadingError +class InvalidStudy : public LoadingError { public: explicit InvalidStudy(const Yuni::String& study); diff --git a/src/libs/antares/file-tree-study-loader/include/antares/file-tree-study-loader/FileTreeStudyLoader.h b/src/libs/antares/file-tree-study-loader/include/antares/file-tree-study-loader/FileTreeStudyLoader.h index 7b46a95c3a..687afa12ae 100644 --- a/src/libs/antares/file-tree-study-loader/include/antares/file-tree-study-loader/FileTreeStudyLoader.h +++ b/src/libs/antares/file-tree-study-loader/include/antares/file-tree-study-loader/FileTreeStudyLoader.h @@ -31,7 +31,6 @@ namespace Data { class Study; } - /** * @class FileTreeStudyLoader * @brief A class to load studies from the file tree. diff --git a/src/libs/antares/inifile/include/antares/inifile/inifile.hxx b/src/libs/antares/inifile/include/antares/inifile/inifile.hxx index 20498c3ee2..64785d1ece 100644 --- a/src/libs/antares/inifile/include/antares/inifile/inifile.hxx +++ b/src/libs/antares/inifile/include/antares/inifile/inifile.hxx @@ -32,8 +32,7 @@ inline bool IniFile::empty() const return not firstSection; } -inline IniFile::Section::Section(const AnyString& name): - name(name) +inline IniFile::Section::Section(const AnyString& name): name(name) { } diff --git a/src/libs/antares/inifile/inifile.cpp b/src/libs/antares/inifile/inifile.cpp index 8cfa6b9607..67190a0654 100644 --- a/src/libs/antares/inifile/inifile.cpp +++ b/src/libs/antares/inifile/inifile.cpp @@ -65,8 +65,9 @@ void IniFile::Section::saveToStream(std::ostream& stream_out, uint64_t& written) stream_out << '[' << name << "]\n"; written += 4 /* []\n\n */ + name.size(); - each([&stream_out, &written](const IniFile::Property& p) - { p.saveToStream(stream_out, written); }); + each([&stream_out, &written](const IniFile::Property& p) { + p.saveToStream(stream_out, written); + }); stream_out << '\n'; } @@ -248,7 +249,7 @@ bool IniFile::open(const fs::path& filename, bool warnings) if (std::ifstream file(filename); file.is_open()) { - if (!readStream(file)) + if (! readStream(file)) { logs.error() << "Invalid INI file : " << filename; return false; @@ -265,8 +266,9 @@ bool IniFile::open(const fs::path& filename, bool warnings) void IniFile::saveToStream(std::ostream& stream_out, uint64_t& written) const { - each([&stream_out, &written](const IniFile::Section& s) - { s.saveToStream(stream_out, written); }); + each([&stream_out, &written](const IniFile::Section& s) { + s.saveToStream(stream_out, written); + }); if (written != 0) { diff --git a/src/libs/antares/io/file.cpp b/src/libs/antares/io/file.cpp index 8ef66b3a3d..10bf5b30b9 100644 --- a/src/libs/antares/io/file.cpp +++ b/src/libs/antares/io/file.cpp @@ -27,13 +27,13 @@ #ifdef YUNI_OS_WINDOWS #include - #include #else #include #include #endif #include + #include #include diff --git a/src/libs/antares/io/include/antares/io/file.h b/src/libs/antares/io/include/antares/io/file.h index b401b1cece..e9fd0e91dc 100644 --- a/src/libs/antares/io/include/antares/io/file.h +++ b/src/libs/antares/io/include/antares/io/file.h @@ -21,10 +21,10 @@ #ifndef __LIBS_ANTARES_IO_FILE_H__ #define __LIBS_ANTARES_IO_FILE_H__ -#include - #include +#include + namespace Antares::IO { /*! diff --git a/src/libs/antares/study-loader/include/antares/study-loader/IStudyLoader.h b/src/libs/antares/study-loader/include/antares/study-loader/IStudyLoader.h index 7d6f25373b..9b4c710ed4 100644 --- a/src/libs/antares/study-loader/include/antares/study-loader/IStudyLoader.h +++ b/src/libs/antares/study-loader/include/antares/study-loader/IStudyLoader.h @@ -29,7 +29,6 @@ namespace Data { class Study; } - /** * @class IStudyLoader * @brief The IStudyLoader class is an interface for loading studies. diff --git a/src/libs/antares/study/area/area.cpp b/src/libs/antares/study/area/area.cpp index fe2b2b7b75..da99f973ae 100644 --- a/src/libs/antares/study/area/area.cpp +++ b/src/libs/antares/study/area/area.cpp @@ -52,20 +52,19 @@ Area::Area(): internalInitialize(); } -Area::Area(const AnyString& name): - Area() +Area::Area(const AnyString& name) : Area() { internalInitialize(); this->name = name; this->id = Antares::transformNameIntoID(this->name); } -Area::Area(const AnyString& name, const AnyString& id): - Area() +Area::Area(const AnyString& name, const AnyString& id) : Area() { internalInitialize(); this->name = name; this->id = Antares::transformNameIntoID(id); + } Area::~Area() diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index 3523643328..40da9df149 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -142,8 +142,8 @@ bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& fol bool AreaLink::loadTSGenTimeSeries(const fs::path& folder) { const std::string idprepro = std::string(from->id) + "/" + std::string(with->id); - tsGeneration.prepro = std::make_unique(idprepro, - tsGeneration.unitCount); + tsGeneration.prepro = + std::make_unique(idprepro, tsGeneration.unitCount); bool anyFileWasLoaded = false; @@ -157,10 +157,10 @@ bool AreaLink::loadTSGenTimeSeries(const fs::path& folder) { anyFileWasLoaded = true; tsGeneration.valid = tsGeneration.prepro->data.loadFromCSVFile( - filepath.string(), - Antares::Data::PreproAvailability::preproAvailabilityMax, - DAYS_PER_YEAR) - && tsGeneration.prepro->validate(); + filepath.string(), + Antares::Data::PreproAvailability::preproAvailabilityMax, + DAYS_PER_YEAR) + && tsGeneration.prepro->validate(); } // Modulation @@ -170,7 +170,7 @@ bool AreaLink::loadTSGenTimeSeries(const fs::path& folder) { anyFileWasLoaded = true; tsGeneration.valid &= tsGeneration.modulationCapacityDirect - .loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR); + .loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR); } filepath = preproFile; @@ -179,7 +179,7 @@ bool AreaLink::loadTSGenTimeSeries(const fs::path& folder) { anyFileWasLoaded = true; tsGeneration.valid &= tsGeneration.modulationCapacityIndirect - .loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR); + .loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR); } if (anyFileWasLoaded) @@ -506,8 +506,11 @@ bool handleKey(Data::AreaLink& link, const String& key, const String& value) return false; } -bool handleTSGenKey(Data::LinkTsGeneration& out, const std::string& key, const String& value) +bool handleTSGenKey(Data::LinkTsGeneration& out, + const std::string& key, + const String& value) { + if (key == "unitcount") { return value.to(out.unitCount); @@ -569,11 +572,7 @@ bool AreaLinksInternalLoadFromProperty(AreaLink& link, const String& key, const } } // anonymous namespace -bool AreaLinksLoadFromFolder(Study& study, - AreaList* l, - Area* area, - const fs::path& folder, - bool loadTSGen) +bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const fs::path& folder, bool loadTSGen) { // Assert assert(area); diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 181159933b..f76afb5686 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -968,9 +968,8 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = hydroSeries->LoadMaxPower(area.id, buffer) && ret; } - hydroSeries->resizeTSinDeratedMode(study.parameters.derated, - studyVersion, - study.usedByTheSolver); + hydroSeries->resizeTSinDeratedMode( + study.parameters.derated, studyVersion, study.usedByTheSolver); } // Wind @@ -1279,7 +1278,7 @@ Area* AreaList::findFromPosition(const int x, const int y) const { auto lastArea = i->second; if (lastArea->ui && std::abs(lastArea->ui->x - x) < nearestDistance - && std::abs(lastArea->ui->y - y) < nearestDistance) + && std::abs(lastArea->ui->y - y) < nearestDistance) { nearestItem = lastArea; } @@ -1327,14 +1326,12 @@ void AreaListEnsureDataLoadPrepro(AreaList* l) /* Asserts */ assert(l); - l->each( - [](Data::Area& area) - { - if (!area.load.prepro) - { - area.load.prepro = new Antares::Data::Load::Prepro(); - } - }); + l->each([](Data::Area& area) { + if (!area.load.prepro) + { + area.load.prepro = new Antares::Data::Load::Prepro(); + } + }); } void AreaListEnsureDataSolarPrepro(AreaList* l) diff --git a/src/libs/antares/study/binding_constraint/BindingConstraintGroupRepository.cpp b/src/libs/antares/study/binding_constraint/BindingConstraintGroupRepository.cpp index b29ad4fba2..ff181e7ed8 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraintGroupRepository.cpp +++ b/src/libs/antares/study/binding_constraint/BindingConstraintGroupRepository.cpp @@ -60,9 +60,7 @@ bool BindingConstraintGroupRepository::buildFrom(const BindingConstraintsReposit bool BindingConstraintGroupRepository::timeSeriesWidthConsistentInGroups() const { - bool allConsistent = !std::ranges::any_of( - groups_, - [](const auto& group) + bool allConsistent = !std::ranges::any_of(groups_, [](const auto& group) { const auto& constraints = group->constraints(); if (constraints.empty()) @@ -70,8 +68,7 @@ bool BindingConstraintGroupRepository::timeSeriesWidthConsistentInGroups() const return false; } auto width = (*constraints.begin())->RHSTimeSeries().width; - bool isConsistent = std::ranges::all_of( - constraints, + bool isConsistent = std::ranges::all_of(constraints, [&width](const std::shared_ptr& bc) { bool sameWidth = bc->RHSTimeSeries().width == width; @@ -92,16 +89,15 @@ bool BindingConstraintGroupRepository::timeSeriesWidthConsistentInGroups() const void BindingConstraintGroupRepository::resizeAllTimeseriesNumbers(unsigned int nb_years) { - std::ranges::for_each(groups_, - [&nb_years](auto& group) { group->timeseriesNumbers.reset(nb_years); }); + std::ranges::for_each(groups_, [&nb_years](auto& group) + { group->timeseriesNumbers.reset(nb_years); }); } BindingConstraintGroup* BindingConstraintGroupRepository::operator[](const std::string& name) const { - if (auto group = std::ranges::find_if(groups_, - [&name](auto& group_of_constraint) - { return group_of_constraint->name() == name; }); - group != groups_.end()) + if (auto group = std::ranges::find_if(groups_, [&name](auto& group_of_constraint) + { return group_of_constraint->name() == name; }); + group != groups_.end()) { return group->get(); } diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 3fa46cf4b5..7d1aadf58e 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -391,6 +391,7 @@ bool listOfFilesAnDirectoriesToKeep(StudyCleaningInfos* infos) buffer.clear() << infos->folder << "/input/bindingconstraints/bindingconstraints.ini"; if (ini.open(buffer)) { + ini.each( [&e](const IniFile::Section& section) { diff --git a/src/libs/antares/study/include/antares/study/parameters.h b/src/libs/antares/study/include/antares/study/parameters.h index 1eacc026bb..791e20f865 100644 --- a/src/libs/antares/study/include/antares/study/parameters.h +++ b/src/libs/antares/study/include/antares/study/parameters.h @@ -504,7 +504,8 @@ class Parameters final private: //! Load data from an INI file - bool loadFromINI(const IniFile& ini, const StudyVersion& version); + bool loadFromINI(const IniFile& ini, + const StudyVersion& version); void resetPlayedYears(uint nbOfYears); diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/container.h b/src/libs/antares/study/include/antares/study/parts/hydro/container.h index 9d80ce4369..e09970b79c 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/include/antares/study/parts/hydro/container.h @@ -22,7 +22,6 @@ #define __ANTARES_LIBS_STUDY_PARTS_HYDRO_CONTAINER_H__ #include - #include "../../fwd.h" #include "allocation.h" #include "prepro.h" @@ -179,7 +178,9 @@ class PartHydro // As this function can be called a lot of times, we pass working variables and returned variables // as arguments, so that we don't have to create them locally (as in a classical function) each // time. -double getWaterValue(const double& level, const Matrix& waterValues, const uint day); +double getWaterValue(const double& level, + const Matrix& waterValues, + const uint day); // Interpolates a rate from the credit modulation table according to a level double getWeeklyModulation(const double& level /* format : in % of reservoir capacity */, diff --git a/src/libs/antares/study/include/antares/study/scenario-builder/hydroLevelsData.h b/src/libs/antares/study/include/antares/study/scenario-builder/hydroLevelsData.h index b5cb21073d..42aff6336a 100644 --- a/src/libs/antares/study/include/antares/study/scenario-builder/hydroLevelsData.h +++ b/src/libs/antares/study/include/antares/study/scenario-builder/hydroLevelsData.h @@ -21,9 +21,8 @@ #ifndef __LIBS_STUDY_SCENARIO_BUILDER_DATA_HYDRO_LEVELS_H__ #define __LIBS_STUDY_SCENARIO_BUILDER_DATA_HYDRO_LEVELS_H__ -#include - #include "scBuilderDataInterface.h" +#include namespace Antares { diff --git a/src/libs/antares/study/include/antares/study/sets.hxx b/src/libs/antares/study/include/antares/study/sets.hxx index df1f9cff93..d2976252cc 100644 --- a/src/libs/antares/study/include/antares/study/sets.hxx +++ b/src/libs/antares/study/include/antares/study/sets.hxx @@ -288,8 +288,8 @@ bool Sets::loadFromFile(const std::filesystem::path& filename) continue; } - logs.warning() << "sets: `" << filename << "`: Invalid property `" << p->key - << '\''; + logs.warning() << "sets: `" << filename << "`: Invalid property `" + << p->key << '\''; } // Add the new group diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index 2f4c0b30b1..7337b9c8b0 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -1109,16 +1109,10 @@ static bool SGDIntLoadFamily_Legacy(Parameters& d, if (key == "initial-reservoir-levels") // ignored since 9.2 { - if (version >= StudyVersion(9, 2)) - { - logs.warning() - << "Option initial-reservoir-levels is deprecated, please remove it from the study"; - } + if (version >= StudyVersion(9,2)) + logs.warning() << "Option initial-reservoir-levels is deprecated, please remove it from the study"; else if (value == "hot start") - { - logs.warning() - << "Hydro hot start not supported with this solver, please use a version < 9.2"; - } + logs.warning() << "Hydro hot start not supported with this solver, please use a version < 9.2"; return true; } @@ -1131,7 +1125,8 @@ bool firstKeyLetterIsValid(const String& name) return (firstLetter >= 'a' && firstLetter <= 'z'); } -bool Parameters::loadFromINI(const IniFile& ini, const StudyVersion& version) +bool Parameters::loadFromINI(const IniFile& ini, + const StudyVersion& version) { // Reset inner data reset(); @@ -1297,9 +1292,7 @@ void Parameters::fixBadValues() } if (simulationDays.first == 0) - { simulationDays.first = 1; - } else { simulationDays.first = std::clamp(simulationDays.first, 1u, 365u); diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 9c39ca7c8b..9be5c2ca57 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -263,9 +263,8 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons template bool ClusterList::loadDataSeriesFromFolder(Study& s, const AnyString& folder) { - return std::ranges::all_of(allClusters_, - [&s, &folder](auto c) - { return c->loadDataSeriesFromFolder(s, folder); }); + return std::ranges::all_of(allClusters_, [&s, &folder](auto c) + { return c->loadDataSeriesFromFolder(s, folder); }); } template diff --git a/src/libs/antares/study/parts/hydro/allocation.cpp b/src/libs/antares/study/parts/hydro/allocation.cpp index 052bc3411d..597264cf20 100644 --- a/src/libs/antares/study/parts/hydro/allocation.cpp +++ b/src/libs/antares/study/parts/hydro/allocation.cpp @@ -164,7 +164,8 @@ void HydroAllocation::clear() #endif } -bool HydroAllocation::loadFromFile(const AreaName& referencearea, const fs::path& filename) +bool HydroAllocation::loadFromFile(const AreaName& referencearea, + const fs::path& filename) { clear(); @@ -176,24 +177,21 @@ bool HydroAllocation::loadFromFile(const AreaName& referencearea, const fs::path } if (ini.empty()) - { return true; - } - ini.each( - [this](const IniFile::Section& section) - { - for (auto* p = section.firstProperty; p; p = p->next) - { - double coeff = p->value.to(); - if (!Utils::isZero(coeff)) - { - AreaName areaname = p->key; - areaname.toLower(); - pValues[areaname] = coeff; - } - } - }); + ini.each([this](const IniFile::Section& section) + { + for (auto* p = section.firstProperty; p; p = p->next) + { + double coeff = p->value.to(); + if (!Utils::isZero(coeff)) + { + AreaName areaname = p->key; + areaname.toLower(); + pValues[areaname] = coeff; + } + } + }); return true; } diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index e98d94bee4..c9dc476de5 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -32,7 +32,7 @@ using namespace Yuni; namespace Antares::Data { -PartHydro::PartHydro(const Data::Area& area): +PartHydro::PartHydro(const Data::Area& area) : interDailyBreakdown(0.), intraDailyModulation(2.), intermonthlyBreakdown(0), @@ -113,9 +113,7 @@ static bool loadProperties(Study& study, T PartHydro::*ptr) { if (!property) - { return false; - } bool ret = true; @@ -244,74 +242,52 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) if (IniFile::Section* section = ini.find("inter-daily-breakdown")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::interDailyBreakdown) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::interDailyBreakdown) && ret; } if (IniFile::Section* section = ini.find("intra-daily-modulation")) { - ret = loadProperties(study, - section->firstProperty, - buffer, - &PartHydro::intraDailyModulation) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::intraDailyModulation) && ret; } if (IniFile::Section* section = ini.find("reservoir")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirManagement) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirManagement) && ret; } if (IniFile::Section* section = ini.find("reservoir capacity")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirCapacity) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirCapacity) && ret; } if (IniFile::Section* section = ini.find("follow load")) { - ret = loadProperties(study, - section->firstProperty, - buffer, - &PartHydro::followLoadModulations) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::followLoadModulations) && ret; } if (IniFile::Section* section = ini.find("use water")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useWaterValue) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useWaterValue) && ret; } if (IniFile::Section* section = ini.find("hard bounds")) { - ret = loadProperties(study, - section->firstProperty, - buffer, - &PartHydro::hardBoundsOnRuleCurves) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::hardBoundsOnRuleCurves) && ret; } if (IniFile::Section* section = ini.find("use heuristic")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useHeuristicTarget) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useHeuristicTarget) && ret; } if (IniFile::Section* section = ini.find("power to level")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::powerToLevel) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::powerToLevel) && ret; } if (IniFile::Section* section = ini.find("initialize reservoir date")) { - ret = loadProperties(study, - section->firstProperty, - buffer, - &PartHydro::initializeReservoirLevelDate) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::initializeReservoirLevelDate) && ret; } if (IniFile::Section* section = ini.find("use leeway")) @@ -321,20 +297,17 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) if (IniFile::Section* section = ini.find("leeway low")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayLowerBound) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayLowerBound) && ret; } if (IniFile::Section* section = ini.find("leeway up")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayUpperBound) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayUpperBound) && ret; } if (IniFile::Section* section = ini.find("pumping efficiency")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::pumpingEfficiency) - && ret; + ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::pumpingEfficiency) && ret; } return ret; @@ -344,12 +317,10 @@ bool PartHydro::checkReservoirLevels(const Study& study) { bool ret = true; - for (const auto& [areaName, area]: study.areas) + for (const auto& [areaName, area] : study.areas) { if (!study.usedByTheSolver) - { return true; - } auto& col = area->hydro.inflowPattern[0]; bool errorInflow = false; @@ -369,8 +340,8 @@ bool PartHydro::checkReservoirLevels(const Study& study) for (unsigned int day = 0; day < DAYS_PER_YEAR; day++) { if (!errorLevels - && (colMin[day] < 0 || colAvg[day] < 0 || colMin[day] > colMax[day] - || colAvg[day] > 100 || colMax[day] > 100)) + && (colMin[day] < 0 || colAvg[day] < 0 || colMin[day] > colMax[day] + || colAvg[day] > 100 || colMax[day] > 100)) { logs.error() << areaName << ": invalid reservoir level value"; errorLevels = true; @@ -381,7 +352,7 @@ bool PartHydro::checkReservoirLevels(const Study& study) for (int i = 0; i < 101; i++) { if ((area->hydro.creditModulation[i][0] < 0) - || (area->hydro.creditModulation[i][1] < 0)) + || (area->hydro.creditModulation[i][1] < 0)) { logs.error() << areaName << ": invalid credit modulation value"; ret = false; @@ -401,73 +372,75 @@ bool PartHydro::checkProperties(Study& study) // the study, because they are too small (< 1e-6). We cannot have reservoir management = yes and // capacity = 0 because of further division by capacity. reservoir management = no and capacity // = 0 is possible (no use of capacity further) - study.areas.each( - [&ret](Data::Area& area) - { - if (area.hydro.reservoirCapacity < 1e-3 && area.hydro.reservoirManagement) - { - logs.error() << area.name - << ": reservoir capacity not defined. Impossible to manage."; - ret = false; - } + study.areas.each([&ret](Data::Area& area) + { + if (area.hydro.reservoirCapacity < 1e-3 && area.hydro.reservoirManagement) + { + logs.error() << area.name + << ": reservoir capacity not defined. Impossible to manage."; + ret = false; + } - if (!area.hydro.useHeuristicTarget && !area.hydro.useWaterValue) - { - logs.error() << area.name - << " : use water value = no conflicts with use heuristic target = no"; - ret = false; - } + if (!area.hydro.useHeuristicTarget && !area.hydro.useWaterValue) + { + logs.error() << area.name + << " : use water value = no conflicts with use heuristic target = no"; + ret = false; + } - if (area.hydro.intraDailyModulation < 1.) - { - logs.error() << area.id << ": Invalid intra-daily modulation. It must be >= 1.0, Got " - << area.hydro.intraDailyModulation << " (truncated to 1)"; - area.hydro.intraDailyModulation = 1.; - } + if (area.hydro.intraDailyModulation < 1.) + { + logs.error() + << area.id << ": Invalid intra-daily modulation. It must be >= 1.0, Got " + << area.hydro.intraDailyModulation << " (truncated to 1)"; + area.hydro.intraDailyModulation = 1.; + } - if (area.hydro.reservoirCapacity < 0) - { - logs.error() << area.id << ": Invalid reservoir capacity."; - area.hydro.reservoirCapacity = 0.; - } + if (area.hydro.reservoirCapacity < 0) + { + logs.error() << area.id << ": Invalid reservoir capacity."; + area.hydro.reservoirCapacity = 0.; + } - if (area.hydro.intermonthlyBreakdown < 0) - { - logs.error() << area.id << ": Invalid intermonthly breakdown"; - area.hydro.intermonthlyBreakdown = 0.; - } + if (area.hydro.intermonthlyBreakdown < 0) + { + logs.error() << area.id << ": Invalid intermonthly breakdown"; + area.hydro.intermonthlyBreakdown = 0.; + } - if (area.hydro.initializeReservoirLevelDate < 0) - { - logs.error() << area.id << ": Invalid initialize reservoir date"; - area.hydro.initializeReservoirLevelDate = 0; - } + if (area.hydro.initializeReservoirLevelDate < 0) + { + logs.error() << area.id << ": Invalid initialize reservoir date"; + area.hydro.initializeReservoirLevelDate = 0; + } - if (area.hydro.leewayLowerBound < 0.) - { - logs.error() << area.id << ": Invalid leeway lower bound. It must be >= 0.0, Got " - << area.hydro.leewayLowerBound; - area.hydro.leewayLowerBound = 0.; - } + if (area.hydro.leewayLowerBound < 0.) + { + logs.error() + << area.id << ": Invalid leeway lower bound. It must be >= 0.0, Got " + << area.hydro.leewayLowerBound; + area.hydro.leewayLowerBound = 0.; + } - if (area.hydro.leewayUpperBound < 0.) - { - logs.error() << area.id << ": Invalid leeway upper bound. It must be >= 0.0, Got " - << area.hydro.leewayUpperBound; - area.hydro.leewayUpperBound = 0.; - } + if (area.hydro.leewayUpperBound < 0.) + { + logs.error() + << area.id << ": Invalid leeway upper bound. It must be >= 0.0, Got " + << area.hydro.leewayUpperBound; + area.hydro.leewayUpperBound = 0.; + } - if (area.hydro.leewayLowerBound > area.hydro.leewayUpperBound) - { + if (area.hydro.leewayLowerBound > area.hydro.leewayUpperBound) + { logs.error() << area.id << ": Leeway lower bound greater than leeway upper bound."; - } + } - if (area.hydro.pumpingEfficiency < 0) - { - logs.error() << area.id << ": Invalid pumping efficiency"; - area.hydro.pumpingEfficiency = 0.; - } - }); + if (area.hydro.pumpingEfficiency < 0) + { + logs.error() << area.id << ": Invalid pumping efficiency"; + area.hydro.pumpingEfficiency = 0.; + } + }); return ret; } @@ -492,40 +465,40 @@ bool PartHydro::SaveToFolder(const AreaList& areas, const AnyString& folder) struct AllSections { - IniFile::Section* s; - IniFile::Section* smod; - IniFile::Section* sIMB; - IniFile::Section* sreservoir; - IniFile::Section* sreservoirCapacity; - IniFile::Section* sFollowLoad; - IniFile::Section* sUseWater; - IniFile::Section* sHardBounds; - IniFile::Section* sInitializeReservoirDate; - IniFile::Section* sUseHeuristic; - IniFile::Section* sUseLeeway; - IniFile::Section* sPowerToLevel; - IniFile::Section* sLeewayLow; - IniFile::Section* sLeewayUp; - IniFile::Section* spumpingEfficiency; - - AllSections(IniFile& ini): - s(ini.addSection("inter-daily-breakdown")), - smod(ini.addSection("intra-daily-modulation")), - sIMB(ini.addSection("inter-monthly-breakdown")), - sreservoir(ini.addSection("reservoir")), - sreservoirCapacity(ini.addSection("reservoir capacity")), - sFollowLoad(ini.addSection("follow load")), - sUseWater(ini.addSection("use water")), - sHardBounds(ini.addSection("hard bounds")), - sInitializeReservoirDate(ini.addSection("initialize reservoir date")), - sUseHeuristic(ini.addSection("use heuristic")), - sUseLeeway(ini.addSection("use leeway")), - sPowerToLevel(ini.addSection("power to level")), - sLeewayLow(ini.addSection("leeway low")), - sLeewayUp(ini.addSection("leeway up")), - spumpingEfficiency(ini.addSection("pumping efficiency")) + IniFile::Section* s; + IniFile::Section* smod; + IniFile::Section* sIMB; + IniFile::Section* sreservoir; + IniFile::Section* sreservoirCapacity; + IniFile::Section* sFollowLoad; + IniFile::Section* sUseWater; + IniFile::Section* sHardBounds; + IniFile::Section* sInitializeReservoirDate; + IniFile::Section* sUseHeuristic; + IniFile::Section* sUseLeeway; + IniFile::Section* sPowerToLevel; + IniFile::Section* sLeewayLow; + IniFile::Section* sLeewayUp; + IniFile::Section* spumpingEfficiency; + + AllSections(IniFile& ini) : + s(ini.addSection("inter-daily-breakdown")), + smod(ini.addSection("intra-daily-modulation")), + sIMB(ini.addSection("inter-monthly-breakdown")), + sreservoir(ini.addSection("reservoir")), + sreservoirCapacity(ini.addSection("reservoir capacity")), + sFollowLoad(ini.addSection("follow load")), + sUseWater(ini.addSection("use water")), + sHardBounds(ini.addSection("hard bounds")), + sInitializeReservoirDate(ini.addSection("initialize reservoir date")), + sUseHeuristic(ini.addSection("use heuristic")), + sUseLeeway(ini.addSection("use leeway")), + sPowerToLevel(ini.addSection("power to level")), + sLeewayLow(ini.addSection("leeway low")), + sLeewayUp(ini.addSection("leeway up")), + spumpingEfficiency(ini.addSection("pumping efficiency")) { - } + } }; // Init @@ -542,8 +515,7 @@ bool PartHydro::SaveToFolder(const AreaList& areas, const AnyString& folder) allSections.s->add(area.id, area.hydro.interDailyBreakdown); allSections.smod->add(area.id, area.hydro.intraDailyModulation); allSections.sIMB->add(area.id, area.hydro.intermonthlyBreakdown); - allSections.sInitializeReservoirDate->add(area.id, - area.hydro.initializeReservoirLevelDate); + allSections.sInitializeReservoirDate->add(area.id, area.hydro.initializeReservoirLevelDate); allSections.sLeewayLow->add(area.id, area.hydro.leewayLowerBound); allSections.sLeewayUp->add(area.id, area.hydro.leewayUpperBound); allSections.spumpingEfficiency->add(area.id, area.hydro.pumpingEfficiency); @@ -768,8 +740,8 @@ bool PartHydro::CheckDailyMaxEnergy(const AnyString& areaName) } double getWaterValue(const double& level /* format : in % of reservoir capacity */, - const Matrix& waterValues, - const uint day) + const Matrix& waterValues, + const uint day) { assert((level >= 0. && level <= 100.) && "getWaterValue function : invalid level"); double levelUp = ceil(level); @@ -780,7 +752,7 @@ double getWaterValue(const double& level /* format : in % of reservoir capacity return waterValues[(int)(levelUp)][day]; } return waterValues[(int)(levelUp)][day] * (level - levelDown) - + waterValues[(int)(levelDown)][day] * (levelUp - level); + + waterValues[(int)(levelDown)][day] * (levelUp - level); } double getWeeklyModulation(const double& level /* format : in % of reservoir capacity */, diff --git a/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp b/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp index 5aa233fedb..2229f75f97 100644 --- a/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp +++ b/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp @@ -37,8 +37,8 @@ FinalLevelValidator::FinalLevelValidator(PartHydro& hydro, double finalLevel, const unsigned int year, const unsigned int lastSimulationDay, - const unsigned int firstMonthOfSimulation): - hydro_(hydro), + const unsigned int firstMonthOfSimulation) + : hydro_(hydro), areaName_(areaName), areaIndex_(areaIndex), initialLevel_(initialLevel), @@ -52,46 +52,36 @@ FinalLevelValidator::FinalLevelValidator(PartHydro& hydro, bool FinalLevelValidator::check() { if (skippingFinalLevelUse()) - { return true; - } - if (!checkForInfeasibility()) - { + if (! checkForInfeasibility()) return false; - } finalLevelFineForUse_ = true; return true; } bool FinalLevelValidator::skippingFinalLevelUse() { - if (!wasSetInScenarioBuilder()) - { + if(! wasSetInScenarioBuilder()) return true; - } - if (!compatibleWithReservoirProperties()) - { + if (! compatibleWithReservoirProperties()) return true; - } return false; } bool FinalLevelValidator::wasSetInScenarioBuilder() { - return !isnan(finalLevel_); + return ! isnan(finalLevel_); } bool FinalLevelValidator::compatibleWithReservoirProperties() { if (hydro_.reservoirManagement && !hydro_.useWaterValue) - { return true; - } - logs.warning() - << "Final reservoir level not applicable! Year:" << year_ + 1 << ", Area:" << areaName_ - << ". Check: Reservoir management = Yes, Use water values = No and proper initial " - "reservoir level is provided "; + logs.warning() << "Final reservoir level not applicable! Year:" << year_ + 1 + << ", Area:" << areaName_ + << ". Check: Reservoir management = Yes, Use water values = No and proper initial " + "reservoir level is provided "; return false; } @@ -108,12 +98,10 @@ bool FinalLevelValidator::hydroAllocationStartMatchesSimulation() const { int initReservoirLvlMonth = hydro_.initializeReservoirLevelDate; // month [0-11] if (lastSimulationDay_ == DAYS_PER_YEAR && initReservoirLvlMonth == firstMonthOfSimulation_) - { return true; - } - logs.error() << "Year " << year_ + 1 << ", area '" << areaName_ - << "' : " << "Hydro allocation must start on the 1st simulation month and " + logs.error() << "Year " << year_ + 1 << ", area '" << areaName_ << "' : " + << "Hydro allocation must start on the 1st simulation month and " << "simulation last a whole year"; return false; } @@ -127,8 +115,8 @@ bool FinalLevelValidator::isFinalLevelReachable() const { logs.error() << "Year: " << year_ + 1 << ". Area: " << areaName_ << ". Incompatible total inflows: " << totalYearInflows - << " with initial: " << initialLevel_ << " and final: " << finalLevel_ - << " reservoir levels."; + << " with initial: " << initialLevel_ + << " and final: " << finalLevel_ << " reservoir levels."; return false; } return true; @@ -137,19 +125,17 @@ bool FinalLevelValidator::isFinalLevelReachable() const double FinalLevelValidator::calculateTotalInflows() const { // calculate yearly inflows - const auto& srcinflows = hydro_.series->storage.getColumn(year_); + auto const& srcinflows = hydro_.series->storage.getColumn(year_); double totalYearInflows = 0.0; for (unsigned int day = 0; day < DAYS_PER_YEAR; ++day) - { totalYearInflows += srcinflows[day]; - } return totalYearInflows; } bool FinalLevelValidator::isBetweenRuleCurves() const { - double lowLevelLastDay = hydro_.reservoirLevel[Data::PartHydro::minimum][DAYS_PER_YEAR - 1]; + double lowLevelLastDay = hydro_.reservoirLevel[Data::PartHydro::minimum][DAYS_PER_YEAR - 1]; double highLevelLastDay = hydro_.reservoirLevel[Data::PartHydro::maximum][DAYS_PER_YEAR - 1]; if (finalLevel_ < lowLevelLastDay || finalLevel_ > highLevelLastDay) diff --git a/src/libs/antares/study/parts/hydro/prepro.cpp b/src/libs/antares/study/parts/hydro/prepro.cpp index 13711759f4..9370c562fa 100644 --- a/src/libs/antares/study/parts/hydro/prepro.cpp +++ b/src/libs/antares/study/parts/hydro/prepro.cpp @@ -151,7 +151,6 @@ bool PreproHydro::loadFromFolder(Study& s, const AreaName& areaID, const std::st { mtrxOption = Matrix<>::optFixedSize | Matrix<>::optImmediate, }; - constexpr int maxNbOfLineToLoad = 12; data.resize(hydroPreproMax, 12, true); @@ -161,8 +160,7 @@ bool PreproHydro::loadFromFolder(Study& s, const AreaName& areaID, const std::st bool ret = PreproHydroLoadSettings(this, buffer); buffer.clear() << folder << SEP << areaID << SEP << "energy.txt"; - ret = data.loadFromCSVFile(buffer, hydroPreproMax, maxNbOfLineToLoad, mtrxOption, &s.dataBuffer) - && ret; + ret = data.loadFromCSVFile(buffer, hydroPreproMax, maxNbOfLineToLoad, mtrxOption, &s.dataBuffer) && ret; return ret; } @@ -205,8 +203,8 @@ bool PreproHydro::validate(const std::string& areaID) { ret = false; logs.error() << "Hydro: Prepro: `" << areaID - << "`: minimum energy: At least one value is negative (line: " << (i + 1) - << ')'; + << "`: minimum energy: At least one value is negative (line: " + << (i + 1) << ')'; continue; } if (colMin[i] > colMax[i]) diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 8c73772565..3eda6d5fc3 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -54,7 +54,7 @@ static void ConvertDailyTSintoHourlyTS(const Matrix::ColumnType& dailyCo { uint hour = 0; uint day = 0; - + while (hour < HOURS_PER_YEAR && day < DAYS_PER_YEAR) { for (uint i = 0; i < HOURS_PER_DAY; ++i) diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index aa1c915a75..62db61a900 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -223,7 +223,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) bool RenewableClusterList::validateClusters() const { bool ret = true; - for (const auto& cluster: allClusters_) + for (const auto& cluster : allClusters_) { ret = cluster->integrityCheck() && ret; } diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index 9a27233064..749613a14b 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -37,7 +37,8 @@ namespace Antares::Data::ShortTermStorage { bool STStorageInput::validate() const { - return std::ranges::all_of(storagesByIndex, [](auto& cluster) { return cluster.validate(); }); + return std::ranges::all_of(storagesByIndex, [](auto& cluster) + { return cluster.validate(); }); } bool STStorageInput::createSTStorageClustersFromIniFile(const fs::path& path) @@ -67,9 +68,8 @@ bool STStorageInput::createSTStorageClustersFromIniFile(const fs::path& path) storagesByIndex.push_back(cluster); } - std::ranges::sort(storagesByIndex, - [](const auto& a, const auto& b) - { return a.properties.name < b.properties.name; }); + std::ranges::sort(storagesByIndex, [](const auto& a, const auto& b) + { return a.properties.name < b.properties.name; }); return true; } @@ -100,8 +100,8 @@ bool STStorageInput::saveToFolder(const std::string& folder) const IniFile ini; logs.debug() << "saving file " << pathIni; - std::ranges::for_each(storagesByIndex, - [&ini](auto& storage) { return storage.saveProperties(ini); }); + std::ranges::for_each(storagesByIndex, [&ini](auto& storage) + { return storage.saveProperties(ini); }); return ini.save(pathIni); } @@ -109,20 +109,20 @@ bool STStorageInput::saveToFolder(const std::string& folder) const bool STStorageInput::saveDataSeriesToFolder(const std::string& folder) const { Yuni::IO::Directory::Create(folder); - return std::ranges::all_of(storagesByIndex, - [&folder](auto& storage) - { return storage.saveSeries(folder + SEP + storage.id); }); + return std::ranges::all_of(storagesByIndex, [&folder](auto& storage) + { return storage.saveSeries(folder + SEP + storage.id); }); } std::size_t STStorageInput::count() const { - return std::ranges::count_if(storagesByIndex, - [](const STStorageCluster& st) { return st.properties.enabled; }); + return std::ranges::count_if(storagesByIndex, [](const STStorageCluster& st) + { return st.properties.enabled; }); } uint STStorageInput::removeDisabledClusters() { - return std::erase_if(storagesByIndex, [](const auto& c) { return !c.enabled(); }); + return std::erase_if(storagesByIndex, [](const auto& c) + { return !c.enabled(); }); } } // namespace Antares::Data::ShortTermStorage diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 8435870d0a..4bf2e042c2 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -162,8 +162,7 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A ret = cluster->modulation.loadFromCSVFile(modulationFile, thermalModulationMax, HOURS_PER_YEAR, - options) - && ret; + options) && ret; // Check the data integrity of the cluster addToCompleteList(cluster); @@ -175,11 +174,12 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A return ret; } + bool ThermalClusterList::validateClusters(const Parameters& parameters) const { bool ret = true; - for (const auto& cluster: allClusters_) + for (const auto& cluster : allClusters_) { cluster->minUpTime = std::clamp(cluster->minUpTime, 1u, 168u); cluster->minDownTime = std::clamp(cluster->minDownTime, 1u, 168u); @@ -206,6 +206,7 @@ bool ThermalClusterList::validateClusters(const Parameters& parameters) const cluster->nominalCapacityWithSpinning = cluster->nominalCapacity; ret = cluster->integrityCheck() && ret; + } return ret; @@ -376,7 +377,7 @@ void ThermalClusterList::reverseCalculationOfSpinning() void ThermalClusterList::enableMustrunForEveryone() { - for (const auto& c: allClusters_) + for (const auto& c : allClusters_) { c->mustrun = true; } @@ -540,6 +541,7 @@ bool ThermalClusterList::saveToFolder(const AnyString& folder) const { ret = false; } + } // Write the ini file @@ -596,32 +598,27 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, const AnyString& fol return std::ranges::all_of(allClusters_ | std::views::filter(hasPrepro), loadPrepro); } -bool ThermalClusterList::validatePrepro(const Study& study) -{ +bool ThermalClusterList::validatePrepro(const Study& study) { auto hasPrepro = [](auto c) { return (bool)c->prepro; }; - const bool globalThermalTSgeneration = study.parameters.timeSeriesToGenerate - & timeSeriesThermal; + const bool globalThermalTSgeneration = + study.parameters.timeSeriesToGenerate & timeSeriesThermal; if (!study.usedByTheSolver) - { return true; - } - return std::ranges::all_of(allClusters_ | std::views::filter(hasPrepro), - [&globalThermalTSgeneration](auto& c) - { - if (globalThermalTSgeneration && !c->prepro->validate()) - { - return false; - } - - if (c->doWeGenerateTS(globalThermalTSgeneration)) - { - return c->prepro->normalizeAndCheckNPO(); - } - return true; - }); + return std::ranges::all_of( + allClusters_ | std::views::filter(hasPrepro), + [&globalThermalTSgeneration](auto& c) { + if (globalThermalTSgeneration && !c->prepro->validate()) { + return false; + } + + if (c->doWeGenerateTS(globalThermalTSgeneration)) { + return c->prepro->normalizeAndCheckNPO(); + } + return true; + }); } bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder) diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index c094450243..035faf86ac 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -213,7 +213,8 @@ void StudyRuntimeInfos::initializeRangeLimits(const Study& study, StudyRangeLimi } else { - simulationDaysPerMonth[ca.month] = study.calendar.months[ca.month].days - ca.dayMonth; + simulationDaysPerMonth[ca.month] = study.calendar.months[ca.month].days + - ca.dayMonth; simulationDaysPerMonth[cb.month] = cb.dayMonth + 1; for (uint i = ca.month + 1; i < cb.month; ++i) { @@ -440,8 +441,7 @@ void StudyRangeLimits::checkIntegrity() const void StudyRuntimeInfos::disableAllFilters(Study& study) { - study.areas.each( - [](Data::Area& area) + study.areas.each([](Data::Area& area) { area.filterSynthesis = filterAll; area.filterYearByYear = filterAll; diff --git a/src/libs/antares/study/scenario-builder/BindingConstraintsTSNumbersData.cpp b/src/libs/antares/study/scenario-builder/BindingConstraintsTSNumbersData.cpp index 5ffef13e98..46a0694a58 100644 --- a/src/libs/antares/study/scenario-builder/BindingConstraintsTSNumbersData.cpp +++ b/src/libs/antares/study/scenario-builder/BindingConstraintsTSNumbersData.cpp @@ -81,11 +81,11 @@ bool BindingConstraintsTSNumberData::reset(const Study& study) { const uint nbYears = study.parameters.nbYears; std::ranges::for_each(study.bindingConstraintsGroups, - [this, &nbYears](const auto& group) - { - auto& ts_numbers = rules_[group->name()]; - ts_numbers.reset(1, nbYears); - }); + [this, &nbYears](const auto& group) + { + auto& ts_numbers = rules_[group->name()]; + ts_numbers.reset(1, nbYears); + }); return true; } diff --git a/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp b/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp index 8d0575b96a..3295df4503 100644 --- a/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp +++ b/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp @@ -29,9 +29,9 @@ namespace Antares::Data::ScenarioBuilder { hydroLevelsData::hydroLevelsData(const std::string& iniFilePrefix, - std::function applyToTarget): - addToPrefix_(iniFilePrefix), - applyToTarget_(applyToTarget) + std::function applyToTarget) : + addToPrefix_(iniFilePrefix), + applyToTarget_(applyToTarget) { } diff --git a/src/libs/antares/study/scenario-builder/rules.cpp b/src/libs/antares/study/scenario-builder/rules.cpp index 2037eede6b..fd79f07f7c 100644 --- a/src/libs/antares/study/scenario-builder/rules.cpp +++ b/src/libs/antares/study/scenario-builder/rules.cpp @@ -288,9 +288,7 @@ bool Rules::readFinalHydroLevels(const AreaName::Vector& splitKey, String value, const Data::Area* area = getArea(areaname, updaterMode); if (!area) - { return false; - } double finalLevel = fromStringToHydroLevel(value, 1.); hydroFinalLevels.setTSnumber(area->index, year, finalLevel); @@ -452,7 +450,8 @@ bool Rules::apply() void Rules::sendWarningsForDisabledClusters() { - for (auto it = disabledClustersOnRuleActive.begin(); it != disabledClustersOnRuleActive.end(); + for (auto it = disabledClustersOnRuleActive.begin(); + it != disabledClustersOnRuleActive.end(); it++) { std::vector& scenariiForCurrentCluster = it->second; diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 5b1dde8c5f..511e61a592 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -856,8 +856,7 @@ void Study::areaDelete(Area::Vector& arealist) << area.name; // Updating all hydro allocation - areas.each([&area](Data::Area& areait) - { areait.hydro.allocation.remove(area.id); }); + areas.each([&area](Data::Area& areait) { areait.hydro.allocation.remove(area.id); }); // Remove all binding constraints attached to the area bindingConstraints.remove(*i); @@ -957,7 +956,7 @@ bool Study::areaRename(Area* area, AreaName newName) // Updating all hydro allocation areas.each([&oldid, &newid](Data::Area& areait) - { areait.hydro.allocation.rename(oldid, newid); }); + { areait.hydro.allocation.rename(oldid, newid); }); ScenarioBuilderUpdater updaterSB(*this); bool ret = true; @@ -1110,14 +1109,13 @@ void Study::destroyAllWindTSGeneratorData() void Study::destroyAllThermalTSGeneratorData() { - areas.each( - [](const Data::Area& area) - { - for (const auto& cluster: area.thermal.list.each_enabled_and_not_mustrun()) - { - FreeAndNil(cluster->prepro); - } - }); + areas.each([](const Data::Area& area) + { + for (const auto& cluster: area.thermal.list.each_enabled_and_not_mustrun()) + { + FreeAndNil(cluster->prepro); + } + }); } void Study::ensureDataAreLoadedForAllBindingConstraints() @@ -1360,6 +1358,7 @@ bool Study::checkForFilenameLimits(bool output, const String& chfolder) const areas.each( [&output, &linkname, &areaname](const Area& area) { + if (areaname.size() < area.id.size()) { areaname = area.id; diff --git a/src/libs/antares/study/study.importprepro.cpp b/src/libs/antares/study/study.importprepro.cpp index f7c8082050..3b8263eadf 100644 --- a/src/libs/antares/study/study.importprepro.cpp +++ b/src/libs/antares/study/study.importprepro.cpp @@ -50,7 +50,7 @@ bool Study::importTimeseriesIntoInput() if (parameters.haveToImport(timeSeriesLoad)) { logs.info() << "Importing load timeseries..."; - for (const auto& [areaName, area]: areas) + for (const auto& [areaName, area] : areas) { logs.info() << "Importing load timeseries : " << areaName; buffer.clear() << folderInput << SEP << "load" << SEP << "series"; @@ -63,7 +63,7 @@ bool Study::importTimeseriesIntoInput() if (parameters.haveToImport(timeSeriesSolar)) { logs.info() << "Importing solar timeseries..."; - for (const auto& [areaName, area]: areas) + for (const auto& [areaName, area] : areas) { logs.info() << "Importing solar timeseries : " << areaName; buffer.clear() << folderInput << SEP << "solar" << SEP << "series"; @@ -76,7 +76,7 @@ bool Study::importTimeseriesIntoInput() if (parameters.haveToImport(timeSeriesHydro)) { logs.info() << "Importing hydro timeseries..."; - for (const auto& [areaName, area]: areas) + for (const auto& [areaName, area] : areas) { logs.info() << "Importing hydro timeseries : " << areaName; buffer.clear() << folderInput << SEP << "hydro" << SEP << "series"; @@ -89,7 +89,7 @@ bool Study::importTimeseriesIntoInput() if (parameters.haveToImport(timeSeriesWind)) { logs.info() << "Importing wind timeseries..."; - for (const auto& [areaName, area]: areas) + for (const auto& [areaName, area] : areas) { logs.info() << "Importing wind timeseries : " << areaName; buffer.clear() << folderInput << SEP << "wind" << SEP << "series"; @@ -104,7 +104,7 @@ bool Study::importTimeseriesIntoInput() logs.info() << "Importing thermal timeseries..."; String msg; - for (const auto& [areaName, area]: areas) + for (const auto& [areaName, area] : areas) { msg.clear() << "Importing thermal timeseries : " << areaName; diff --git a/src/libs/antares/study/xcast/xcast.cpp b/src/libs/antares/study/xcast/xcast.cpp index 0f2e05956b..51ed1624b0 100644 --- a/src/libs/antares/study/xcast/xcast.cpp +++ b/src/libs/antares/study/xcast/xcast.cpp @@ -207,8 +207,7 @@ bool XCast::loadFromFolder(const AnyString& folder) // For each property if (section.name == "general") { - for (const IniFile::Property* p = section.firstProperty; p != nullptr; - p = p->next) + for (const IniFile::Property* p = section.firstProperty; p != nullptr; p = p->next) { CString<30, false> key = p->key; key.toLower(); diff --git a/src/libs/antares/writer/in_memory_writer.cpp b/src/libs/antares/writer/in_memory_writer.cpp index 182fee1927..e3e643a74f 100644 --- a/src/libs/antares/writer/in_memory_writer.cpp +++ b/src/libs/antares/writer/in_memory_writer.cpp @@ -24,9 +24,9 @@ #include #include -#include #include #include +#include namespace fs = std::filesystem; diff --git a/src/libs/antares/writer/zip_writer.cpp b/src/libs/antares/writer/zip_writer.cpp index 6359460f8a..362d0e730e 100644 --- a/src/libs/antares/writer/zip_writer.cpp +++ b/src/libs/antares/writer/zip_writer.cpp @@ -51,6 +51,7 @@ static void logErrorAndThrow [[noreturn]] (const std::string& errorMessage) throw std::runtime_error(errorMessage); } + // Class ZipWriteJob template ZipWriteJob::ZipWriteJob(ZipWriter& writer, diff --git a/src/solver/application/application.cpp b/src/solver/application/application.cpp index 9ec3ce3e14..d222ad88c0 100644 --- a/src/solver/application/application.cpp +++ b/src/solver/application/application.cpp @@ -337,14 +337,10 @@ void Application::prepare(int argc, char* argv[]) // don't de-allocate these. if (!parseCommandLine(options)) // --help - { return; - } if (!handleOptions(options)) // --version, --list-solvers - { - return; - } + return; // Perform some checks checkAndCorrectSettingsAndOptions(pSettings, options); diff --git a/src/solver/constraints-builder/cbuilder.cpp b/src/solver/constraints-builder/cbuilder.cpp index 0b37556347..a49806ff16 100644 --- a/src/solver/constraints-builder/cbuilder.cpp +++ b/src/solver/constraints-builder/cbuilder.cpp @@ -364,7 +364,8 @@ bool CBuilder::saveCBuilderToFile(const String& filename) const if (filename == "") { - fs::path path = fs::path(pStudy.folder.c_str()) / "settings" / "constraintbuilder.ini"; + fs::path path = fs::path(pStudy.folder.c_str()) / "settings" + / "constraintbuilder.ini"; return ini.save(path.string()); } diff --git a/src/solver/hydro/include/antares/solver/hydro/management/management.h b/src/solver/hydro/include/antares/solver/hydro/management/management.h index 30528d92d2..b642e441c2 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/management.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/management.h @@ -152,7 +152,8 @@ class HydroManagement final // \return The total inflow for the whole year double prepareMonthlyTargetGenerations(Data::Area& area, TmpDataByArea& data); - void prepareDailyOptimalGenerations(uint y, Antares::Data::Area::ScratchMap& scratchmap); + void prepareDailyOptimalGenerations(uint y, + Antares::Data::Area::ScratchMap& scratchmap); void prepareDailyOptimalGenerations(Data::Area& area, uint y, diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index d9651a1197..f7e4665159 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -219,9 +219,9 @@ struct DebugData }; inline void HydroManagement::prepareDailyOptimalGenerations( - Data::Area& area, - uint y, - Antares::Data::Area::ScratchMap& scratchmap) + Data::Area& area, + uint y, + Antares::Data::Area::ScratchMap& scratchmap) { const auto srcinflows = area.hydro.series->storage.getColumn(y); diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index a863668f64..703235fc61 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -385,31 +385,23 @@ bool HydroManagement::checkMinGeneration(uint year) const void HydroManagement::changeInflowsToAccommodateFinalLevels(uint year) { - areas_.each( - [this, &year](Data::Area& area) - { - auto& data = tmpDataByArea_[&area]; - - if (!area.hydro.deltaBetweenFinalAndInitialLevels[year].has_value()) - { - return; - } - - // Must be done before prepareMonthlyTargetGenerations - double delta = area.hydro.deltaBetweenFinalAndInitialLevels[year].value(); - if (delta < 0) - { - data.inflows[0] -= delta; - } - else if (delta > 0) - { - data.inflows[11] -= delta; - } - }); + areas_.each([this, &year](Data::Area& area) + { + auto& data = tmpDataByArea_[&area]; + + if (!area.hydro.deltaBetweenFinalAndInitialLevels[year].has_value()) + return; + + // Must be done before prepareMonthlyTargetGenerations + double delta = area.hydro.deltaBetweenFinalAndInitialLevels[year].value(); + if (delta < 0) + data.inflows[0] -= delta; + else if (delta > 0) + data.inflows[11] -= delta; + }); } -void HydroManagement::prepareNetDemand(uint year, - Data::SimulationMode mode, +void HydroManagement::prepareNetDemand(uint year, Data::SimulationMode mode, const Antares::Data::Area::ScratchMap& scratchmap) { areas_.each( diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index 37c2085e3c..aa10b7c10e 100644 --- a/src/solver/hydro/management/monthly.cpp +++ b/src/solver/hydro/management/monthly.cpp @@ -290,22 +290,22 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ auto monthName = calendar_.text.months[simulationMonth].name; - buffer << monthName[0] << monthName[1] << monthName[2] << '\t'; - buffer << '\t'; - buffer << data.inflows[realmonth] << '\t'; - buffer << data.MTG[realmonth] << '\t'; - buffer << data.MOG[realmonth] / area.hydro.reservoirCapacity << '\t'; - buffer << data.MOL[realmonth] << '\t'; - buffer << minLvl[firstDay] << '\t'; - buffer << maxLvl[firstDay] << '\t'; - buffer << '\n'; - } - auto content = buffer.str(); - resultWriter_.addEntryFromBuffer(path.str(), content); - } + buffer << monthName[0] << monthName[1] << monthName[2] << '\t'; + buffer << '\t'; + buffer << data.inflows[realmonth] << '\t'; + buffer << data.MTG[realmonth] << '\t'; + buffer << data.MOG[realmonth] / area.hydro.reservoirCapacity << '\t'; + buffer << data.MOL[realmonth] << '\t'; + buffer << minLvl[firstDay] << '\t'; + buffer << maxLvl[firstDay] << '\t'; + buffer << '\n'; + } + auto content = buffer.str(); + resultWriter_.addEntryFromBuffer(path.str(), content); + } - indexArea++; - }); + indexArea++; + }); } } // namespace Antares diff --git a/src/solver/misc/include/antares/solver/misc/options.h b/src/solver/misc/include/antares/solver/misc/options.h index 00daf5aec7..2560a74d1c 100644 --- a/src/solver/misc/include/antares/solver/misc/options.h +++ b/src/solver/misc/include/antares/solver/misc/options.h @@ -27,8 +27,8 @@ #include #include -#include #include +#include /*! ** \brief Command line settings for launching the simulation diff --git a/src/solver/misc/options.cpp b/src/solver/misc/options.cpp index 458ae2fa06..9429b50e79 100644 --- a/src/solver/misc/options.cpp +++ b/src/solver/misc/options.cpp @@ -22,8 +22,8 @@ #include "antares/solver/misc/options.h" #include -#include #include +#include #include #include diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index fa4a292902..2b03f7bcdc 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -68,10 +68,7 @@ bool Adequacy::simulationBegin() pProblemesHebdo.resize(pNbMaxPerformedYearsInParallel); for (uint numSpace = 0; numSpace < pNbMaxPerformedYearsInParallel; numSpace++) { - SIM_InitialisationProblemeHebdo(study, - pProblemesHebdo[numSpace], - nbHoursInAWeek, - numSpace); + SIM_InitialisationProblemeHebdo(study, pProblemesHebdo[numSpace], nbHoursInAWeek, numSpace); } } diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 8095cc85bb..1f56235499 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -395,23 +395,21 @@ void PrepareRandomNumbers(Data::Study& study, }); } + void SetInitialHydroLevel(Data::Study& study, PROBLEME_HEBDO& problem, const HYDRO_VENTILATION_RESULTS& hydroVentilationResults) { uint firstDaySimu = study.parameters.simulationDays.first; - study.areas.each( - [&problem, &firstDaySimu, &hydroVentilationResults](const Data::Area& area) - { - if (area.hydro.reservoirManagement) - { - double capacity = area.hydro.reservoirCapacity; - problem.previousSimulationFinalLevel[area.index] = hydroVentilationResults[area.index] - .NiveauxReservoirsDebutJours - [firstDaySimu] - * capacity; - } - }); + study.areas.each([&problem, &firstDaySimu, &hydroVentilationResults](const Data::Area& area) + { + if (area.hydro.reservoirManagement) + { + double capacity = area.hydro.reservoirCapacity; + problem.previousSimulationFinalLevel[area.index] = + hydroVentilationResults[area.index].NiveauxReservoirsDebutJours[firstDaySimu] * capacity; + } + }); } void BuildThermalPartOfWeeklyProblem(Data::Study& study, diff --git a/src/solver/simulation/common-hydro-levels.cpp b/src/solver/simulation/common-hydro-levels.cpp index b0ba258b0e..81602073a1 100644 --- a/src/solver/simulation/common-hydro-levels.cpp +++ b/src/solver/simulation/common-hydro-levels.cpp @@ -33,7 +33,7 @@ void computingHydroLevels(const Data::AreaList& areas, bool remixWasRun, bool computeAnyway) { - for (const auto& [_, area]: areas) + for (const auto& [_, area] : areas) { if (!area->hydro.reservoirManagement) { @@ -50,7 +50,7 @@ void computingHydroLevels(const Data::AreaList& areas, double reservoirCapacity = area->hydro.reservoirCapacity; std::vector& inflows = problem.CaracteristiquesHydrauliques[index] - .ApportNaturelHoraire; + .ApportNaturelHoraire; RESULTATS_HORAIRES& weeklyResults = problem.ResultatsHoraires[index]; @@ -65,7 +65,7 @@ void computingHydroLevels(const Data::AreaList& areas, std::vector& ovf = weeklyResults.debordementsHoraires; computeTimeStepLevel - computeLvlObj(nivInit, inflows, ovf, turb, pumpingRatio, pump, reservoirCapacity); + computeLvlObj(nivInit, inflows, ovf, turb, pumpingRatio, pump, reservoirCapacity); for (uint h = 0; h < nbHoursInAWeek - 1; h++) { @@ -94,7 +94,7 @@ void interpolateWaterValue(const Data::AreaList& areas, daysOfWeek[d] = weekFirstDay + d; } - for (const auto& [_, area]: areas) + for (const auto& [_, area] : areas) { uint index = area->index; @@ -118,22 +118,22 @@ void interpolateWaterValue(const Data::AreaList& areas, std::vector& niv = weeklyResults.niveauxHoraires; waterVal[0] = Data::getWaterValue(problem.previousSimulationFinalLevel[index] * 100 - / reservoirCapacity, - area->hydro.waterValues, - weekFirstDay); + / reservoirCapacity, + area->hydro.waterValues, + weekFirstDay); for (uint h = 1; h < nbHoursInAWeek; h++) { waterVal[h] = Data::getWaterValue(niv[h - 1], - area->hydro.waterValues, - daysOfWeek[h / 24]); + area->hydro.waterValues, + daysOfWeek[h / 24]); } } } void updatingWeeklyFinalHydroLevel(const Data::AreaList& areas, PROBLEME_HEBDO& problem) { - for (const auto& [_, area]: areas) + for (const auto& [_, area] : areas) { if (!area->hydro.reservoirManagement) { @@ -149,7 +149,7 @@ void updatingWeeklyFinalHydroLevel(const Data::AreaList& areas, PROBLEME_HEBDO& std::vector& niv = weeklyResults.niveauxHoraires; problem.previousSimulationFinalLevel[index] = niv[nbHoursInAWeek - 1] * reservoirCapacity - / 100; + / 100; } } diff --git a/src/solver/simulation/common-hydro-remix.cpp b/src/solver/simulation/common-hydro-remix.cpp index de8e3f5328..dcf39052ce 100644 --- a/src/solver/simulation/common-hydro-remix.cpp +++ b/src/solver/simulation/common-hydro-remix.cpp @@ -51,7 +51,8 @@ static bool Remix(const Data::AreaList& areas, bool status = true; areas.each( - [&HE, &DE, &remix, &G, &status, &problem, &numSpace, &hourInYear](const Data::Area& area) + [&HE, &DE, &remix, &G, &status, &problem, &numSpace, &hourInYear] + (const Data::Area& area) { auto index = area.index; diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index ac40117b2c..934ebc4c2c 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -73,10 +73,7 @@ bool Economy::simulationBegin() for (uint numSpace = 0; numSpace < pNbMaxPerformedYearsInParallel; numSpace++) { - SIM_InitialisationProblemeHebdo(study, - pProblemesHebdo[numSpace], - nbHoursInAWeek, - numSpace); + SIM_InitialisationProblemeHebdo(study, pProblemesHebdo[numSpace], nbHoursInAWeek, numSpace); auto options = createOptimizationOptions(study); weeklyOptProblems_[numSpace] = Antares::Solver::Optimization::WeeklyOptimization:: diff --git a/src/solver/simulation/hydro-final-reservoir-level-functions.cpp b/src/solver/simulation/hydro-final-reservoir-level-functions.cpp index 225a0e2be9..32f2d4dfa2 100644 --- a/src/solver/simulation/hydro-final-reservoir-level-functions.cpp +++ b/src/solver/simulation/hydro-final-reservoir-level-functions.cpp @@ -26,47 +26,43 @@ */ #include "antares/solver/simulation/hydro-final-reservoir-level-functions.h" - -#include #include "antares/study/parts/hydro/finalLevelValidator.h" +#include namespace Antares::Solver { void CheckFinalReservoirLevelsConfiguration(const Data::Study& study) { - study.areas.each( - [&study](Data::Area& area) - { - uint nbYears = study.parameters.nbYears; - for (uint year = 0; year != nbYears; ++year) - { - if (!study.parameters.yearsFilter.at(year)) - { - continue; - } + study.areas.each([&study](Data::Area &area) + { + uint nbYears = study.parameters.nbYears; + for (uint year = 0; year != nbYears; ++year) + { + if (! study.parameters.yearsFilter.at(year)) + continue; - double initialLevel = study.scenarioInitialHydroLevels.entry[area.index][year]; - double finalLevel = study.scenarioFinalHydroLevels.entry[area.index][year]; + double initialLevel = study.scenarioInitialHydroLevels.entry[area.index][year]; + double finalLevel = study.scenarioFinalHydroLevels.entry[area.index][year]; - Data::FinalLevelValidator validator(area.hydro, - area.index, - area.name, - initialLevel, - finalLevel, - year, - study.parameters.simulationDays.end, - study.parameters.firstMonthInYear); - if (!validator.check()) - { - throw FatalError("hydro final level : infeasibility"); - } - if (validator.finalLevelFineForUse()) - { - area.hydro.deltaBetweenFinalAndInitialLevels[year] = finalLevel - initialLevel; - } - } - }); + Data::FinalLevelValidator validator(area.hydro, + area.index, + area.name, + initialLevel, + finalLevel, + year, + study.parameters.simulationDays.end, + study.parameters.firstMonthInYear); + if (! validator.check()) + { + throw FatalError("hydro final level : infeasibility"); + } + if (validator.finalLevelFineForUse()) + { + area.hydro.deltaBetweenFinalAndInitialLevels[year] = finalLevel - initialLevel; + } + } + }); } // End function CheckFinalReservoirLevelsConfiguration -} // namespace Antares::Solver +} // namespace Antares::Solver \ No newline at end of file diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index cd6bcb5f62..232fa520fc 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -39,6 +39,7 @@ #include "antares/solver/simulation/timeseries-numbers.h" #include "antares/solver/ts-generator/generator.h" + #include "hydro-final-reservoir-level-functions.h" namespace Antares::Solver::Simulation @@ -74,7 +75,10 @@ public: yearByYear(pYearByYear), pDurationCollector(durationCollector), pResultWriter(resultWriter), - hydroManagement(study.areas, study.parameters, study.calendar, resultWriter) + hydroManagement(study.areas, + study.parameters, + study.calendar, + resultWriter) { scratchmap = study.areas.buildScratchMap(numSpace); } @@ -158,8 +162,11 @@ public: simulation_->prepareClustersInMustRunMode(scratchmap, y); // 4 - Hydraulic ventilation - pDurationCollector("hydro_ventilation") << [this, &randomReservoirLevel] - { hydroManagement.makeVentilation(randomReservoirLevel, y, scratchmap); }; + pDurationCollector("hydro_ventilation") << [this, &randomReservoirLevel] { + hydroManagement.makeVentilation(randomReservoirLevel, + y, + scratchmap); + }; // Updating the state state.year = y; @@ -741,15 +748,15 @@ void ISimulation::computeRandomNumbers( max[firstDayOfMonth], randomHydroGenerator); - // Possibly update the intial level from scenario builder - if (study.parameters.useCustomScenario) - { - double levelFromScenarioBuilder = study.scenarioInitialHydroLevels[areaIndex][y]; - if (levelFromScenarioBuilder >= 0.) - { - randomLevel = levelFromScenarioBuilder; - } - } + // Possibly update the intial level from scenario builder + if (study.parameters.useCustomScenario) + { + double levelFromScenarioBuilder = study.scenarioInitialHydroLevels[areaIndex][y]; + if (levelFromScenarioBuilder >= 0.) + { + randomLevel = levelFromScenarioBuilder; + } + } // Current area's hydro starting (or initial) level computation // (no matter if the year is performed or not, we always draw a random initial @@ -773,12 +780,7 @@ void ISimulation::computeRandomNumbers( bool SpilledEnergySeedIsDefault = (currentSpilledEnergySeed == defaultSpilledEnergySeed); areaIndex = 0; study.areas.each( - [&isPerformed, - &areaIndex, - &randomUnsupplied, - &randomSpilled, - &randomForYears, - &indexYear, + [&isPerformed, &areaIndex, &randomUnsupplied, &randomSpilled, &randomForYears, &indexYear, &SpilledEnergySeedIsDefault](Data::Area& area) { (void)area; // Avoiding warnings at compilation (unused variable) on linux @@ -1028,19 +1030,19 @@ void ISimulation::loopThroughYears(uint firstYear, // continue; auto task = std::make_shared>( - this, - y, - set_it->yearFailed, - set_it->isFirstPerformedYearOfASet, - pFirstSetParallelWithAPerformedYearWasRun, - numSpace, - randomForParallelYears, - performCalculations, - study, - state[numSpace], - pYearByYear, - pDurationCollector, - pResultWriter); + this, + y, + set_it->yearFailed, + set_it->isFirstPerformedYearOfASet, + pFirstSetParallelWithAPerformedYearWasRun, + numSpace, + randomForParallelYears, + performCalculations, + study, + state[numSpace], + pYearByYear, + pDurationCollector, + pResultWriter); results.add(Concurrency::AddTask(*pQueueService, task)); } // End loop over years of the current set of parallel years diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 7fb3336599..ed13d54fe1 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -513,11 +513,11 @@ void SIM_RenseignementProblemeHebdo(const Study& study, if (area.hydro.useWaterValue) { - problem.CaracteristiquesHydrauliques[k].WeeklyWaterValueStateRegular - = getWaterValue(problem.previousSimulationFinalLevel[k] * 100 - / area.hydro.reservoirCapacity, - area.hydro.waterValues, - weekFirstDay); + problem.CaracteristiquesHydrauliques[k].WeeklyWaterValueStateRegular = + getWaterValue( + problem.previousSimulationFinalLevel[k] * 100 / area.hydro.reservoirCapacity, + area.hydro.waterValues, + weekFirstDay); } if (problem.CaracteristiquesHydrauliques[k].PresenceDHydrauliqueModulable > 0) diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 446a0efa08..52b1213ada 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -329,7 +329,8 @@ bool checkInterModalConsistencyForArea(const Area& area, { logs.error() << "Inter-modal correlation: time-series numbers of inter-modal modes in area '" - << area.name << "'" << " are not identical"; + << area.name << "'" + << " are not identical"; return false; } diff --git a/src/solver/ts-generator/availability.cpp b/src/solver/ts-generator/availability.cpp index dfb2d8c1f4..69f62a10a1 100644 --- a/src/solver/ts-generator/availability.cpp +++ b/src/solver/ts-generator/availability.cpp @@ -99,9 +99,7 @@ class GeneratorTempData final const T& duration) const; }; -GeneratorTempData::GeneratorTempData(Data::Study& study, - unsigned nbOfSeriesToGen, - MersenneTwister& rndGenerator): +GeneratorTempData::GeneratorTempData(Data::Study& study, unsigned nbOfSeriesToGen, MersenneTwister& rndGenerator): derated(study.parameters.derated), nbOfSeriesToGen_(nbOfSeriesToGen), rndgenerator(rndGenerator) @@ -618,13 +616,10 @@ listOfLinks getAllLinksToGen(Data::AreaList& areas) areas.each( [&links](const Data::Area& area) { - std::ranges::for_each(area.links, - [&links](auto& l) + std::ranges::for_each(area.links, [&links](auto& l) { if (!l.second->tsGeneration.forceNoGeneration) - { links.push_back(l.second); - } }); }); @@ -703,10 +698,7 @@ bool generateLinkTimeSeries(Data::Study& study, } // DIRECT - AvailabilityTSGeneratorData tsConfigDataDirect(tsGenStruct, - ts, - tsGenStruct.modulationCapacityDirect, - link->with->name); + AvailabilityTSGeneratorData tsConfigDataDirect(tsGenStruct, ts, tsGenStruct.modulationCapacityDirect, link->with->name); generator.generateTS(*link->from, tsConfigDataDirect); @@ -715,14 +707,12 @@ bool generateLinkTimeSeries(Data::Study& study, writeResultsToDisk(study, writer, ts.timeSeries, filePath); // INDIRECT - AvailabilityTSGeneratorData tsConfigDataIndirect(tsGenStruct, - ts, - tsGenStruct.modulationCapacityIndirect, - link->with->name); + AvailabilityTSGeneratorData tsConfigDataIndirect(tsGenStruct, ts, tsGenStruct.modulationCapacityIndirect, link->with->name); generator.generateTS(*link->from, tsConfigDataIndirect); - filePath = savePath + SEP + link->from->id + SEP + link->with->id.c_str() + "_indirect.txt"; + filePath = savePath + SEP + link->from->id + SEP + link->with->id.c_str() + + "_indirect.txt"; writeResultsToDisk(study, writer, ts.timeSeries, filePath); } diff --git a/src/solver/ts-generator/xcast/xcast.cpp b/src/solver/ts-generator/xcast/xcast.cpp index 56f7234119..ca0c96087a 100644 --- a/src/solver/ts-generator/xcast/xcast.cpp +++ b/src/solver/ts-generator/xcast/xcast.cpp @@ -593,8 +593,7 @@ bool XCast::runWithPredicate(PredicateT& predicate, Progression::Task& progressi if (study.parameters.derated) { - study.areas.each([&predicate](Data::Area& area) - { predicate.matrix(area).averageTimeseries(); }); + study.areas.each([&predicate](Data::Area& area) { predicate.matrix(area).averageTimeseries(); }); } if (study.parameters.timeSeriesToArchive & timeSeriesType) diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index 2cc81b80fa..1f2f5e4169 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -56,9 +56,10 @@ static void checkSetSolverSpecificParameters(bool status, } } -static void TuneSolverSpecificOptions(MPSolver* solver, - const std::string& solverName, - const std::string& solverParameters) +static void TuneSolverSpecificOptions( + MPSolver* solver, + const std::string& solverName, + const std::string& solverParameters) { if (!solver) { @@ -134,6 +135,7 @@ MPSolver* ProblemSimplexeNommeConverter::Convert() return solver; } + void ProblemSimplexeNommeConverter::CopyMatrix(const MPSolver* solver) const { auto variables = solver->variables(); diff --git a/src/solver/variable/include/antares/solver/variable/economy/all.h b/src/solver/variable/include/antares/solver/variable/economy/all.h index b7a62eb6bf..a3c637c43f 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/all.h +++ b/src/solver/variable/include/antares/solver/variable/economy/all.h @@ -248,8 +248,8 @@ typedef Variable::Join< Variable::Areas, // Variables for each set of areas Variable::Join, - // Variables for each binding constraint - Variable::BindingConstraints>> + // Variables for each binding constraint + Variable::BindingConstraints>> ItemList; /*! diff --git a/src/solver/variable/include/antares/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h b/src/solver/variable/include/antares/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h index 8a1f97676f..6d7e02fa3e 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h +++ b/src/solver/variable/include/antares/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h @@ -147,6 +147,7 @@ class BindingConstMarginCost NextType::simulationEnd(); } + void initializeFromStudy(Data::Study& study) { pNbYearsParallel = study.maxNbYearsInParallel; @@ -256,8 +257,8 @@ class BindingConstMarginCost for (int dayInTheWeek = 0; dayInTheWeek < 7; dayInTheWeek++) { pValuesForTheCurrentYear[numSpace].day[dayInTheYear] - -= state.problemeHebdo - ->ResultatsContraintesCouplantes[associatedBC_][dayInTheWeek]; + -= state.problemeHebdo + ->ResultatsContraintesCouplantes[associatedBC_][dayInTheWeek]; dayInTheYear++; } @@ -269,7 +270,7 @@ class BindingConstMarginCost { uint weekInTheYear = state.weekInTheYear; double weeklyValue = -state.problemeHebdo - ->ResultatsContraintesCouplantes[associatedBC_][0]; + ->ResultatsContraintesCouplantes[associatedBC_][0]; pValuesForTheCurrentYear[numSpace].week[weekInTheYear] = weeklyValue; diff --git a/src/solver/variable/include/antares/solver/variable/endoflist.h b/src/solver/variable/include/antares/solver/variable/endoflist.h index d8cb5dd69d..7c32c32ecb 100644 --- a/src/solver/variable/include/antares/solver/variable/endoflist.h +++ b/src/solver/variable/include/antares/solver/variable/endoflist.h @@ -254,6 +254,7 @@ class EndOfList static void computeSpatialAggregateWith(O&, const Data::Area*, uint numSpace) { UNUSED_VARIABLE(numSpace); + assert(false); } template diff --git a/src/tests/end-to-end/simple_study/simple-study.cpp b/src/tests/end-to-end/simple_study/simple-study.cpp index 96a66aef3e..bfad50326f 100644 --- a/src/tests/end-to-end/simple_study/simple-study.cpp +++ b/src/tests/end-to-end/simple_study/simple-study.cpp @@ -82,7 +82,7 @@ HydroMaxPowerStudy::HydroMaxPowerStudy() area = addAreaToStudy("Area"); area->thermal.unsuppliedEnergyCost = 1; - setNumberMCyears(1); + setNumberMCyears(1); TimeSeriesConfigurer loadTSconfig(area->load.series.timeSeries); loadTSconfig.setColumnCount(1).fillColumnWith(0, loadInArea); diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index fdba99c007..a42891ea45 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -219,8 +219,7 @@ void StudyBuilder::setNumberMCyears(unsigned int nbYears) { study->parameters.resetPlaylist(nbYears); study->areas.resizeAllTimeseriesNumbers(nbYears); - study->areas.each([&](Data::Area& area) - { area.hydro.deltaBetweenFinalAndInitialLevels.resize(nbYears); }); + study->areas.each([&](Data::Area& area) { area.hydro.deltaBetweenFinalAndInitialLevels.resize(nbYears); }); } void StudyBuilder::playOnlyYear(unsigned int year) diff --git a/src/tests/end-to-end/utils/utils.h b/src/tests/end-to-end/utils/utils.h index 84362bf2e0..1fa55efbff 100644 --- a/src/tests/end-to-end/utils/utils.h +++ b/src/tests/end-to-end/utils/utils.h @@ -164,17 +164,14 @@ class ScenarioBuilderRule { return rules_->load; } - BindingConstraintsTSNumberData& bcGroup() { return rules_->binding_constraints; } - hydroTSNumberData& hydro() { return rules_->hydro; } - private: Rules::Ptr rules_; }; diff --git a/src/tests/src/libs/antares/antlr4-interface/test_antlr_interface.cpp b/src/tests/src/libs/antares/antlr4-interface/test_antlr_interface.cpp index 04d1c7be9f..e97f4e3524 100644 --- a/src/tests/src/libs/antares/antlr4-interface/test_antlr_interface.cpp +++ b/src/tests/src/libs/antares/antlr4-interface/test_antlr_interface.cpp @@ -19,17 +19,15 @@ ** along with Antares_Simulator. If not, see . */ #define BOOST_TEST_MODULE antlr_interface tests -#include - -#include #include +#include +#include "antlr4-runtime.h" +#include #include "ExprLexer.h" #include "ExprParser.h" -#include "antlr4-runtime.h" using namespace antlr4; - BOOST_AUTO_TEST_CASE(test_antlr_interface) { const std::string my_input = "y = b + a*x"; diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index de09d007d1..7879559fb0 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -355,12 +355,10 @@ BOOST_FIXTURE_TEST_CASE(on_area1_and_on_year_17__hydro_level_0_123_is_chosen__re AreaName::Vector splitKey = {"hl", "area 1", yearNumber}; my_rule.readLine(splitKey, level); - BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_1->index), - level.to()); + BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_1->index), level.to()); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_1->index][yearNumber.to()], - level.to()); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_1->index][yearNumber.to()], level.to()); } BOOST_FIXTURE_TEST_CASE( @@ -372,11 +370,10 @@ BOOST_FIXTURE_TEST_CASE( AreaName::Vector splitKey = {"hl", "area 2", yearNumber}; BOOST_CHECK(my_rule.readLine(splitKey, level)); - BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_2->index), - 1.); + BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_2->index), 1.); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_2->index][yearNumber.to()], 1.); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_2->index][yearNumber.to()], 1.); } BOOST_FIXTURE_TEST_CASE( @@ -388,11 +385,10 @@ BOOST_FIXTURE_TEST_CASE( AreaName::Vector splitKey = {"hl", "area 3", yearNumber}; BOOST_CHECK(my_rule.readLine(splitKey, level)); - BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_3->index), - 0.); + BOOST_CHECK_EQUAL(my_rule.hydroInitialLevels.get_value(yearNumber.to(), area_3->index), 0.); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_3->index][yearNumber.to()], 0.); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioInitialHydroLevels[area_3->index][yearNumber.to()], 0.); } // ======================== @@ -400,47 +396,47 @@ BOOST_FIXTURE_TEST_CASE( // ======================== BOOST_FIXTURE_TEST_CASE(on_area1_and_on_year_8__hydro_level_0_342_is_chosen__reading_OK, Fixture) { - AreaName yearNumber = "8"; - String level = "0.342"; - AreaName::Vector splitKey = {"hfl", "area 1", yearNumber}; - my_rule.readLine(splitKey, level, false); + AreaName yearNumber = "8"; + String level = "0.342"; + AreaName::Vector splitKey = {"hfl", "area 1", yearNumber}; + my_rule.readLine(splitKey, level, false); - BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_1->index), - level.to()); + BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_1->index), + level.to()); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_1->index][yearNumber.to()], - level.to()); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_1->index][yearNumber.to()], + level.to()); } -BOOST_FIXTURE_TEST_CASE( - on_area2_and_on_year_1__hydro_level_2_4_is_chosen_level_lowered_to_1__reading_OK, - Fixture) +BOOST_FIXTURE_TEST_CASE(on_area2_and_on_year_1__hydro_level_2_4_is_chosen_level_lowered_to_1__reading_OK, Fixture) { - AreaName yearNumber = "1"; - String level = "2.4"; - AreaName::Vector splitKey = {"hfl", "area 2", yearNumber}; - BOOST_CHECK(my_rule.readLine(splitKey, level, false)); + AreaName yearNumber = "1"; + String level = "2.4"; + AreaName::Vector splitKey = {"hfl", "area 2", yearNumber}; + BOOST_CHECK(my_rule.readLine(splitKey, level, false)); - BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_2->index), 1.); + BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_2->index), + 1.); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_2->index][yearNumber.to()], 1.); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_2->index][yearNumber.to()], + 1.); } -BOOST_FIXTURE_TEST_CASE( - on_area3_and_on_year_3__hydro_level_neg_5_2_is_chosen__level_raised_to_0__reading_OK, - Fixture) +BOOST_FIXTURE_TEST_CASE(on_area3_and_on_year_3__hydro_level_neg_5_2_is_chosen__level_raised_to_0__reading_OK, Fixture) { - AreaName yearNumber = "3"; - String level = "-5.2"; - AreaName::Vector splitKey = {"hfl", "area 3", yearNumber}; - BOOST_CHECK(my_rule.readLine(splitKey, level, false)); + AreaName yearNumber = "3"; + String level = "-5.2"; + AreaName::Vector splitKey = {"hfl", "area 3", yearNumber}; + BOOST_CHECK(my_rule.readLine(splitKey, level, false)); - BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_3->index), 0.); + BOOST_CHECK_EQUAL(my_rule.hydroFinalLevels.get_value(yearNumber.to(), area_3->index), + 0.); - BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_3->index][yearNumber.to()], 0.); + BOOST_CHECK(my_rule.apply()); + BOOST_CHECK_EQUAL(study->scenarioFinalHydroLevels[area_3->index][yearNumber.to()], + 0.); } // ====================== diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 64813637fc..13d5a38b48 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -436,9 +436,7 @@ BOOST_FIXTURE_TEST_CASE( // ======================== // Tests on Hydro final levels // ======================== -BOOST_FIXTURE_TEST_CASE( - HYDRO_FINAL_LEVEL__TS_number_for_many_areas_and_years__generated_and_ref_sc_buider_files_are_identical, - saveFixture) +BOOST_FIXTURE_TEST_CASE(HYDRO_FINAL_LEVEL__TS_number_for_many_areas_and_years__generated_and_ref_sc_buider_files_are_identical, saveFixture) { my_rule->hydroFinalLevels.setTSnumber(area_1->index, 4, 8); my_rule->hydroFinalLevels.setTSnumber(area_2->index, 11, 3); diff --git a/src/tests/src/libs/antares/test_utils.cpp b/src/tests/src/libs/antares/test_utils.cpp index 5cb05e27c4..ad7e97d833 100644 --- a/src/tests/src/libs/antares/test_utils.cpp +++ b/src/tests/src/libs/antares/test_utils.cpp @@ -19,15 +19,15 @@ * along with Antares_Simulator. If not, see . */ #define BOOST_TEST_MODULE test utils -#include #include #include -#include - #include +#include +#include + namespace fs = std::filesystem; namespace @@ -99,8 +99,7 @@ BOOST_AUTO_TEST_CASE(yuni_normalize_vs_std_lexically_normal) { Yuni::String yuniNorm; Yuni::IO::Normalize(yuniNorm, path.string()); - BOOST_CHECK_MESSAGE(path.lexically_normal().string() == yuniNorm, - std::string("Check failed for ") + path.string()); + BOOST_CHECK_MESSAGE(path.lexically_normal().string() == yuniNorm, std::string("Check failed for ") + path.string()); }; helper(fs::path("a/./b/..")); helper(fs::path("a/.///b/../")); diff --git a/src/tests/src/libs/antares/yaml-parser/test_yaml_parser.cpp b/src/tests/src/libs/antares/yaml-parser/test_yaml_parser.cpp index 87978fbcaa..ebfbc4bba8 100644 --- a/src/tests/src/libs/antares/yaml-parser/test_yaml_parser.cpp +++ b/src/tests/src/libs/antares/yaml-parser/test_yaml_parser.cpp @@ -19,22 +19,19 @@ ** along with Antares_Simulator. If not, see . */ #define BOOST_TEST_MODULE yamlcpp tests -#include +#include +#include +#include "yaml-cpp/yaml.h" #include +#include #include #include -#include -#include - -#include "yaml-cpp/yaml.h" - // our data types struct Vec3 { float x, y, z; }; - struct Power { std::string name; @@ -47,7 +44,6 @@ struct Monster Vec3 position; std::vector powers; }; - namespace YAML { template<> @@ -75,7 +71,6 @@ struct convert return true; } }; - template<> struct convert { @@ -94,7 +89,6 @@ struct convert return true; } }; - template<> struct convert { @@ -114,7 +108,7 @@ struct convert rhs.name = node["name"].as(); rhs.position = node["position"].as(); const YAML::Node& powers = node["powers"]; - for (const auto power: powers) + for (const auto power : powers) { rhs.powers.push_back(power.as()); } diff --git a/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp b/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp index a38d7ea12c..d4a6c3512b 100644 --- a/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp +++ b/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp @@ -6,24 +6,23 @@ #define WIN32_LEAN_AND_MEAN #include -#include - #include "include/antares/solver/simulation/hydro-final-reservoir-level-functions.h" #include "include/antares/study/parts/hydro/finalLevelValidator.h" +#include using namespace Antares::Solver; using namespace Antares::Data; + struct Fixture { Fixture(const Fixture& f) = delete; Fixture(const Fixture&& f) = delete; Fixture& operator=(const Fixture& f) = delete; Fixture& operator=(const Fixture&& f) = delete; - Fixture() { - // Simulation last day must be 365 so that final level checks succeeds + // Simulation last day must be 365 so that final level checks succeeds study->parameters.simulationDays.end = 365; study->parameters.firstMonthInYear = january; uint nbYears = study->parameters.nbYears = 2; @@ -57,6 +56,7 @@ struct Fixture area_1->hydro.deltaBetweenFinalAndInitialLevels.resize(nbYears); area_2->hydro.deltaBetweenFinalAndInitialLevels.resize(nbYears); + // Scenario builder for initial and final reservoir levels // ------------------------------------------------------- uint areasCount = study->areas.size(); @@ -96,7 +96,7 @@ struct Fixture // ... Area 2 : Inflows time series area_2->hydro.series->storage.resize(nbInflowTS, 365); area_2->hydro.series->storage.timeSeries.fill(300.); - area_2->hydro.series->storage[0][0] = 300. + 1.; // DAYS_PER_YEAR + area_2->hydro.series->storage[0][0] = 300. + 1.; //DAYS_PER_YEAR area_2->hydro.series->storage[0][DAYS_PER_YEAR - 1] = 300. + 2.; } @@ -178,8 +178,7 @@ BOOST_AUTO_TEST_CASE(final_level_not_set_by_user____check_succeeds_but_final_lev BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); } -BOOST_AUTO_TEST_CASE( - initial_level_month_and_simulation_first_month_different___check_fails_and_final_level_not_usable) +BOOST_AUTO_TEST_CASE(initial_level_month_and_simulation_first_month_different___check_fails_and_final_level_not_usable) { uint year = 0; area_1->hydro.initializeReservoirLevelDate = 3; // initialize reservoir level != January @@ -234,8 +233,7 @@ BOOST_AUTO_TEST_CASE(final_level_out_of_rule_curves___check_fails_and_final_leve BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); } -BOOST_AUTO_TEST_CASE( - final_level_unreachable_because_of_too_few_inflows___check_fails_and_final_level_not_usable) +BOOST_AUTO_TEST_CASE(final_level_unreachable_because_of_too_few_inflows___check_fails_and_final_level_not_usable) { area_1->hydro.reservoirCapacity = 185000; uint year = 0; @@ -274,4 +272,4 @@ BOOST_AUTO_TEST_CASE(check_all_areas_final_levels_when_config_is_ok___all_checks BOOST_CHECK_EQUAL(area_2->hydro.deltaBetweenFinalAndInitialLevels[1].value(), 4.3 - 2.4); } -BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From fc04d70d459050a4385302b6b40b1c5c8693409b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Wed, 26 Jun 2024 11:43:50 +0200 Subject: [PATCH 06/10] Check formatting as part of the CI (workflow only) (#2198) --- .github/workflows/clang-format.yml | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/clang-format.yml diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 0000000000..9e00892851 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,36 @@ +name: Check cpp formatting + +on: + push: + branches: + - develop + - feature/* + - features/* + - fix/* + +jobs: + build: + name: clang-format + + runs-on: ubuntu-24.04 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Print version + run: clang-format --version + + - name: clang-format + run: cd src && ./format-code.sh + + - name: git diff + run: | + DIFF=`git status --porcelain` + if [[ $DIFF ]]; then + echo "The following files are not well formatted" + echo "$DIFF" + exit 1 + else + echo "Code is well formatted, congrats !" + fi From 03481750724aa75f662f29ee5a4c428a2b64383f Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Thu, 27 Jun 2024 00:16:20 +0200 Subject: [PATCH 07/10] Remove some compile warnings (#2199) --- src/libs/antares/study/area/area.cpp | 3 +-- .../study/include/antares/study/parameters.h | 3 +-- .../antares/study/parts/hydro/container.h | 2 +- src/libs/antares/study/load.cpp | 2 +- src/libs/antares/study/parameters.cpp | 3 +-- src/libs/antares/study/parts/hydro/container.cpp | 2 +- .../study/parts/hydro/finalLevelValidator.cpp | 16 ++++++++-------- .../study/parameters/parameters-tests.cpp | 4 ++-- 8 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/libs/antares/study/area/area.cpp b/src/libs/antares/study/area/area.cpp index da99f973ae..929e8653c2 100644 --- a/src/libs/antares/study/area/area.cpp +++ b/src/libs/antares/study/area/area.cpp @@ -46,8 +46,7 @@ void Area::internalInitialize() Area::Area(): reserves(fhrMax, HOURS_PER_YEAR), - miscGen(fhhMax, HOURS_PER_YEAR), - hydro(*this) + miscGen(fhhMax, HOURS_PER_YEAR) { internalInitialize(); } diff --git a/src/libs/antares/study/include/antares/study/parameters.h b/src/libs/antares/study/include/antares/study/parameters.h index 791e20f865..73ba5b5f77 100644 --- a/src/libs/antares/study/include/antares/study/parameters.h +++ b/src/libs/antares/study/include/antares/study/parameters.h @@ -76,8 +76,7 @@ class Parameters final ** \return True if the settings have been loaded, false if at least one error has occured */ bool loadFromFile(const AnyString& filename, - const StudyVersion& version, - const StudyLoadOptions& options); + const StudyVersion& version); /*! ** \brief Prepare all settings for a simulation diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/container.h b/src/libs/antares/study/include/antares/study/parts/hydro/container.h index e09970b79c..6748c830e7 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/include/antares/study/parts/hydro/container.h @@ -81,7 +81,7 @@ class PartHydro /*! ** \brief Default Constructor */ - PartHydro(const Data::Area& area); + PartHydro(); //! Destructor ~PartHydro(); diff --git a/src/libs/antares/study/load.cpp b/src/libs/antares/study/load.cpp index 4175bc2305..749d0d81ff 100644 --- a/src/libs/antares/study/load.cpp +++ b/src/libs/antares/study/load.cpp @@ -83,7 +83,7 @@ bool Study::internalLoadIni(const String& path, const StudyLoadOptions& options) } // Load the general data buffer.clear() << folderSettings << SEP << "generaldata.ini"; - bool errorWhileLoading = !parameters.loadFromFile(buffer, header.version, options); + bool errorWhileLoading = !parameters.loadFromFile(buffer, header.version); parameters.validateOptions(options); diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index 7337b9c8b0..dbfb7f81e2 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -1958,8 +1958,7 @@ void Parameters::saveToINI(IniFile& ini) const } bool Parameters::loadFromFile(const AnyString& filename, - const StudyVersion& version, - const StudyLoadOptions& options) + const StudyVersion& version) { // Loading the INI file IniFile ini; diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index c9dc476de5..e09ae5a8fb 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -32,7 +32,7 @@ using namespace Yuni; namespace Antares::Data { -PartHydro::PartHydro(const Data::Area& area) : +PartHydro::PartHydro() : interDailyBreakdown(0.), intraDailyModulation(2.), intermonthlyBreakdown(0), diff --git a/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp b/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp index 2229f75f97..c3ea96ca08 100644 --- a/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp +++ b/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp @@ -37,15 +37,15 @@ FinalLevelValidator::FinalLevelValidator(PartHydro& hydro, double finalLevel, const unsigned int year, const unsigned int lastSimulationDay, - const unsigned int firstMonthOfSimulation) - : hydro_(hydro), - areaName_(areaName), - areaIndex_(areaIndex), - initialLevel_(initialLevel), - finalLevel_(finalLevel), + const unsigned int firstMonthOfSimulation) : year_(year), lastSimulationDay_(lastSimulationDay), - firstMonthOfSimulation_(firstMonthOfSimulation) + firstMonthOfSimulation_(firstMonthOfSimulation), + hydro_(hydro), + areaIndex_(areaIndex), + areaName_(areaName), + initialLevel_(initialLevel), + finalLevel_(finalLevel) { } @@ -96,7 +96,7 @@ bool FinalLevelValidator::checkForInfeasibility() bool FinalLevelValidator::hydroAllocationStartMatchesSimulation() const { - int initReservoirLvlMonth = hydro_.initializeReservoirLevelDate; // month [0-11] + unsigned initReservoirLvlMonth = hydro_.initializeReservoirLevelDate; // month [0-11] if (lastSimulationDay_ == DAYS_PER_YEAR && initReservoirLvlMonth == firstMonthOfSimulation_) return true; diff --git a/src/tests/src/libs/antares/study/parameters/parameters-tests.cpp b/src/tests/src/libs/antares/study/parameters/parameters-tests.cpp index 07c8e7fa1d..5e0da57a10 100644 --- a/src/tests/src/libs/antares/study/parameters/parameters-tests.cpp +++ b/src/tests/src/libs/antares/study/parameters/parameters-tests.cpp @@ -69,7 +69,7 @@ BOOST_FIXTURE_TEST_CASE(loadValid, Fixture) options.optOptions.ortoolsSolver = "xpress"; writeValidFile(); - p.loadFromFile(path.string(), version, options); + p.loadFromFile(path.string(), version); p.validateOptions(options); p.fixBadValues(); @@ -94,7 +94,7 @@ BOOST_FIXTURE_TEST_CASE(fixBadValue, Fixture) BOOST_FIXTURE_TEST_CASE(invalidValues, Fixture) { writeInvalidFile(); - BOOST_CHECK(p.loadFromFile(path.string(), version, options)); + BOOST_CHECK(p.loadFromFile(path.string(), version)); p.validateOptions(options); p.fixBadValues(); From b8f1849561a9f0f5281d0643d49d7b97060bcf06 Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Thu, 27 Jun 2024 00:23:08 +0200 Subject: [PATCH 08/10] Remove Antares::Memory::Array (#2187) --- .../array/include/antares/array/matrix.h | 9 - .../array/include/antares/array/matrix.hxx | 25 --- .../memory/include/antares/memory/memory.h | 48 ----- .../memory/include/antares/memory/memory.hxx | 48 ----- .../solver/variable/storage/minmax-data.h | 44 ++--- .../antares/solver/variable/storage/minmax.h | 20 +- .../solver/variable/storage/minmax.hxx | 1 - src/solver/variable/storage/minmax-data.cpp | 179 ++++-------------- 8 files changed, 54 insertions(+), 320 deletions(-) diff --git a/src/libs/antares/array/include/antares/array/matrix.h b/src/libs/antares/array/include/antares/array/matrix.h index f1d65c5a43..48eb27dd6f 100644 --- a/src/libs/antares/array/include/antares/array/matrix.h +++ b/src/libs/antares/array/include/antares/array/matrix.h @@ -339,15 +339,6 @@ class Matrix template void pasteToColumn(uint x, const U* data); - /*! - ** \brief Copy values into a given column in the matrix - ** - ** \param x The column index (zero-based) - ** \param data The data to copy - */ - template - void pasteToColumn(uint x, const Antares::Memory::Array& data); - /*! ** \brief Set a entire column with a given value ** diff --git a/src/libs/antares/array/include/antares/array/matrix.hxx b/src/libs/antares/array/include/antares/array/matrix.hxx index 7fabacba02..78fef9186a 100644 --- a/src/libs/antares/array/include/antares/array/matrix.hxx +++ b/src/libs/antares/array/include/antares/array/matrix.hxx @@ -488,31 +488,6 @@ void Matrix::pasteToColumn(uint x, const U* data) markAsModified(); } -template -template -void Matrix::pasteToColumn(uint x, const Antares::Memory::Array& data) -{ - assert(x < width and "Invalid column index (bigger than `this->width`)"); - ColumnType& column = entry[x]; - - // if the two types are strictly equal, we can perform some major - // optimisations - if (Yuni::Static::Type::StrictlyEqual::Yes) - { - (void)::memcpy(column, data, sizeof(T) * height); - } - else - { - // ...otherwise we have to copy each item by hand in any cases - for (uint y = 0; y != height; ++y) - { - column[y] = (T)data[y]; - } - } - - markAsModified(); -} - template void Matrix::fillColumn(uint x, const T& value) { diff --git a/src/libs/antares/memory/include/antares/memory/memory.h b/src/libs/antares/memory/include/antares/memory/memory.h index 89eb4815f4..42515c5fce 100644 --- a/src/libs/antares/memory/include/antares/memory/memory.h +++ b/src/libs/antares/memory/include/antares/memory/memory.h @@ -33,52 +33,6 @@ namespace Antares class Memory final: public Yuni::Policy::ObjectLevelLockable { public: - template - class Array final - { - public: - //! \name Constructors - //@{ - /*! - ** \brief Default constructor - */ - Array() = default; - - /*! - ** \brief Constructor from null - */ - explicit Array(const Yuni::NullPtr&); - - /*! - ** \brief Constructor with an initial allocation size - */ - explicit Array(size_t size); - - //! Copy constructor (must be empty) - Array(const Array& copy); - - template - Array(const Array&); - - /*! - ** \brief Destructor - */ - ~Array(); - //@} - - /*! - ** \brief - */ - void allocate(size_t size); - - T& operator[](uint i); - const T& operator[](uint i) const; - - private: - T* pPointer = nullptr; - - }; // class Array - template struct Stored final { @@ -101,7 +55,6 @@ class Memory final: public Yuni::Policy::ObjectLevelLockable template static void Assign(uint count, U* array, const U& value); -public: template static void Allocate(T*& out, size_t size); @@ -117,7 +70,6 @@ class Memory final: public Yuni::Policy::ObjectLevelLockable template static void Release(T*& pointer); -public: //! \name Constructor & Destructor //@{ /*! diff --git a/src/libs/antares/memory/include/antares/memory/memory.hxx b/src/libs/antares/memory/include/antares/memory/memory.hxx index 1b575150a5..aeb99b413d 100644 --- a/src/libs/antares/memory/include/antares/memory/memory.hxx +++ b/src/libs/antares/memory/include/antares/memory/memory.hxx @@ -28,54 +28,6 @@ inline uint64_t Memory::processID() const return pProcessID; } -template -Memory::Array::Array(const Yuni::NullPtr&) -{ -} - -template -Memory::Array::Array(const Memory::Array&) -{ -} - -template -template -Memory::Array::Array(const Memory::Array&) -{ -} - -template -inline Memory::Array::Array(size_t size) -{ - allocate(size); -} - -template -inline Memory::Array::~Array() -{ - delete[] pPointer; - pPointer = nullptr; -} - -template -void Memory::Array::allocate(size_t size) -{ - delete[] pPointer; - pPointer = new T[size]; -} - -template -T& Memory::Array::operator[](uint i) -{ - return (T&)pPointer[i]; -} - -template -const T& Memory::Array::operator[](uint i) const -{ - return (const T&)pPointer[i]; -} - template inline void Memory::Release(T*& pointer) { diff --git a/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h b/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h index c444ca73c9..156f53fec2 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h +++ b/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h @@ -21,19 +21,11 @@ #ifndef __SOLVER_VARIABLE_STORAGE_MINMAX_DATA_H__ #define __SOLVER_VARIABLE_STORAGE_MINMAX_DATA_H__ -#include -#include +#include + #include "antares/solver/variable/storage/intermediate.h" -namespace Antares -{ -namespace Solver -{ -namespace Variable -{ -namespace R -{ -namespace AllYears +namespace Antares::Solver::Variable::R::AllYears { class MinMaxData { @@ -44,17 +36,8 @@ class MinMaxData uint32_t indice; }; -public: - //! \name Constructor & Destructor - //@{ - /*! - ** \brief Default constructor - */ - MinMaxData(); - //! Destructor - ~MinMaxData(); - - void initialize(); + MinMaxData() = default; + ~MinMaxData() = default; void resetInf(); void resetSup(); @@ -62,19 +45,14 @@ class MinMaxData void mergeInf(uint year, const IntermediateValues& rhs); void mergeSup(uint year, const IntermediateValues& rhs); -public: - Data annual; - Data monthly[maxMonths]; - Data weekly[maxWeeksInAYear]; - Data daily[maxDaysInAYear]; - Antares::Memory::Stored::Type hourly; + std::vector annual{1}; + std::vector monthly{maxMonths}; + std::vector weekly{maxWeeksInAYear}; + std::vector daily{maxDaysInAYear}; + std::vector hourly{maxHoursInAYear}; }; // class MinMaxData -} // namespace AllYears -} // namespace R -} // namespace Variable -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Variable::R::AllYears #endif // __SOLVER_VARIABLE_STORAGE_MINMAX_DATA_H__ diff --git a/src/solver/variable/include/antares/solver/variable/storage/minmax.h b/src/solver/variable/include/antares/solver/variable/storage/minmax.h index b9aaba7bc3..8e9603fa16 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/minmax.h +++ b/src/solver/variable/include/antares/solver/variable/storage/minmax.h @@ -84,20 +84,20 @@ struct MinMaxBase: public NextT { case Category::hourly: InternalExportIndices(report, - Memory::RawPointer(minmax.hourly), + Memory::RawPointer(minmax.hourly.data()), fileLevel); break; case Category::daily: - InternalExportIndices(report, minmax.daily, fileLevel); + InternalExportIndices(report, minmax.daily.data(), fileLevel); break; case Category::weekly: - InternalExportIndices(report, minmax.weekly, fileLevel); + InternalExportIndices(report, minmax.weekly.data(), fileLevel); break; case Category::monthly: - InternalExportIndices(report, minmax.monthly, fileLevel); + InternalExportIndices(report, minmax.monthly.data(), fileLevel); break; case Category::annual: - InternalExportIndices<1, VCardT>(report, &minmax.annual, fileLevel); + InternalExportIndices<1, VCardT>(report, minmax.annual.data(), fileLevel); break; } } @@ -107,19 +107,19 @@ struct MinMaxBase: public NextT { case Category::hourly: InternalExportValues(report, - Memory::RawPointer(minmax.hourly)); + Memory::RawPointer(minmax.hourly.data())); break; case Category::daily: - InternalExportValues(report, minmax.daily); + InternalExportValues(report, minmax.daily.data()); break; case Category::weekly: - InternalExportValues(report, minmax.weekly); + InternalExportValues(report, minmax.weekly.data()); break; case Category::monthly: - InternalExportValues(report, minmax.monthly); + InternalExportValues(report, minmax.monthly.data()); break; case Category::annual: - InternalExportValues<1, VCardT>(report, &minmax.annual); + InternalExportValues<1, VCardT>(report, minmax.annual.data()); break; } } diff --git a/src/solver/variable/include/antares/solver/variable/storage/minmax.hxx b/src/solver/variable/include/antares/solver/variable/storage/minmax.hxx index de94f1d571..741e56cbba 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/minmax.hxx +++ b/src/solver/variable/include/antares/solver/variable/storage/minmax.hxx @@ -36,7 +36,6 @@ namespace AllYears template inline void MinMaxBase::initializeFromStudy(Data::Study& study) { - minmax.initialize(); // Next NextType::initializeFromStudy(study); } diff --git a/src/solver/variable/storage/minmax-data.cpp b/src/solver/variable/storage/minmax-data.cpp index 7d6e3f0565..6d25480806 100644 --- a/src/solver/variable/storage/minmax-data.cpp +++ b/src/solver/variable/storage/minmax-data.cpp @@ -21,135 +21,40 @@ #include "antares/solver/variable/storage/minmax-data.h" -#include - -#include - #include "antares/solver/variable/storage/intermediate.h" -using namespace Yuni; - namespace Antares::Solver::Variable::R::AllYears { -namespace // anonymous -{ constexpr double eps = 1.e-7; -template -struct ArrayInitializer +static void initArray(bool opInferior, std::vector& array) { - static void Init(Antares::Memory::Array& array) - { - for (uint i = 0; i != Size; ++i) - { - MinMaxData::Data& data = array[i]; - data.value = DBL_MAX; // +inf - data.indice = (uint32_t)(-1); // invalid indice - } - } - - static void Init(MinMaxData::Data* array) + for (auto& data : array) { - for (uint i = 0; i != Size; ++i) - { - MinMaxData::Data& data = array[i]; - data.value = DBL_MAX; // +inf - data.indice = (uint32_t)(-1); // invalid indice - } + data.value = opInferior ? DBL_MAX : -DBL_MAX; // +inf or -inf + data.indice = (uint32_t)(-1); // invalid indice } +} -}; // class ArrayInitializer - -template -struct ArrayInitializer +static void mergeArray(bool opInferior, + unsigned year, + std::vector& results, + const double* values) { - static void Init(Antares::Memory::Array& array) - { - for (uint i = 0; i != Size; ++i) - { - // Contrary to what we could guess, DBL_MIN is not the smallest number - // you can hold in a double, but the smallest positive number you can - // hold in a double - MinMaxData::Data& data = array[i]; - data.value = -DBL_MAX; // -inf - data.indice = (uint32_t)(-1); // invalid indice - } - } - - static void Init(MinMaxData::Data* array) + for (unsigned i = 0; i != results.size(); ++i) { - for (uint i = 0; i != Size; ++i) - { - // Contrary to what we could guess, DBL_MIN is not the smallest number - // you can hold in a double, but the smallest positive number you can - // hold in a double - MinMaxData::Data& data = array[i]; - data.value = -DBL_MAX; // -inf - data.indice = (uint32_t)(-1); // invalid indice - } - } + MinMaxData::Data& data = results[i]; -}; // class ArrayInitializer - -template -struct MergeArray -{ - template - static void Do(const uint year, - Antares::Memory::Array& results, - const U& values) - { - for (uint i = 0; i != Size; ++i) + if (opInferior) { - MinMaxData::Data& data = results[i]; if (values[i] < data.value - eps) { data.value = values[i]; data.indice = year + 1; // The year is zero-based } } - } - - template - static void Do(const uint year, MinMaxData::Data* results, const U& values) - { - for (uint i = 0; i != Size; ++i) - { - if (values[i] < results[i].value - eps) - { - results[i].value = values[i]; - results[i].indice = year + 1; // The year is zero-based - } - } - } - -}; // class MergeArray - -template -struct MergeArray<0, Size> -{ - template - static void Do(const uint year, - Antares::Memory::Array& results, - const U& values) - { - for (uint i = 0; i != Size; ++i) - { - MinMaxData::Data& data = results[i]; - if (values[i] > data.value + eps) - { - data.value = values[i]; - data.indice = year + 1; // The year is zero-based - } - } - } - - template - static void Do(const uint year, MinMaxData::Data* results, const U& values) - { - for (uint i = 0; i != Size; ++i) + else { - MinMaxData::Data& data = results[i]; if (values[i] > data.value + eps) { data.value = values[i]; @@ -157,60 +62,42 @@ struct MergeArray<0, Size> } } } - -}; // class MergeArray - -} // anonymous namespace - -MinMaxData::MinMaxData(): - hourly(nullptr) -{ -} - -MinMaxData::~MinMaxData() -{ - Antares::Memory::Release(hourly); } void MinMaxData::resetInf() { - ArrayInitializer<1, true>::Init(&annual); - ArrayInitializer::Init(monthly); - ArrayInitializer::Init(weekly); - ArrayInitializer::Init(daily); - ArrayInitializer::Init(hourly); + initArray(true, annual); + initArray(true, monthly); + initArray(true, weekly); + initArray(true, daily); + initArray(true, hourly); } void MinMaxData::resetSup() { - ArrayInitializer<1, false>::Init(&annual); - ArrayInitializer::Init(monthly); - ArrayInitializer::Init(weekly); - ArrayInitializer::Init(daily); - ArrayInitializer::Init(hourly); -} - -void MinMaxData::initialize() -{ - Antares::Memory::Allocate(hourly, maxHoursInAYear); + initArray(false, annual); + initArray(false, monthly); + initArray(false, weekly); + initArray(false, daily); + initArray(false, hourly); } void MinMaxData::mergeInf(uint year, const IntermediateValues& rhs) { - MergeArray::Do(year, monthly, rhs.month); - MergeArray::Do(year, weekly, rhs.week); - MergeArray::Do(year, daily, rhs.day); - MergeArray::Do(year, hourly, rhs.hour); - MergeArray::Do(year, &annual, &rhs.year); + mergeArray(true, year, monthly, rhs.month); + mergeArray(true, year, weekly, rhs.week); + mergeArray(true, year, daily, rhs.day); + mergeArray(true, year, hourly, rhs.hour); + mergeArray(true, year, annual, &rhs.year); } void MinMaxData::mergeSup(uint year, const IntermediateValues& rhs) { - MergeArray::Do(year, monthly, rhs.month); - MergeArray::Do(year, weekly, rhs.week); - MergeArray::Do(year, daily, rhs.day); - MergeArray::Do(year, hourly, rhs.hour); - MergeArray::Do(year, &annual, &rhs.year); + mergeArray(false, year, monthly, rhs.month); + mergeArray(false, year, weekly, rhs.week); + mergeArray(false, year, daily, rhs.day); + mergeArray(false, year, hourly, rhs.hour); + mergeArray(false, year, annual, &rhs.year); } } // namespace Antares::Solver::Variable::R::AllYears From ea815a1f1a015b5228abb841891838b5cf0f4d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Thu, 27 Jun 2024 10:26:50 +0200 Subject: [PATCH 09/10] Simplify functions prepareClustersInMustRunMode (#2168) Spin-off from https://github.com/AntaresSimulatorTeam/Antares_Simulator/pull/2128 Credits @guilpier-code --------- Co-authored-by: Vincent Payet Co-authored-by: payetvin <113102157+payetvin@users.noreply.github.com> --- .../include/antares/study/area/scratchpad.h | 4 +- src/solver/simulation/adequacy.cpp | 30 +++++++++- src/solver/simulation/common-eco-adq.cpp | 59 ------------------- src/solver/simulation/economy.cpp | 18 +++++- .../solver/simulation/common-eco-adq.h | 7 --- 5 files changed, 47 insertions(+), 71 deletions(-) diff --git a/src/libs/antares/study/include/antares/study/area/scratchpad.h b/src/libs/antares/study/include/antares/study/area/scratchpad.h index 3258b7423d..864d50a155 100644 --- a/src/libs/antares/study/include/antares/study/area/scratchpad.h +++ b/src/libs/antares/study/include/antares/study/area/scratchpad.h @@ -66,11 +66,11 @@ class AreaScratchpad final //! Sum of all 'must-run' clusters // This variable is initialized every MC-year - double mustrunSum[HOURS_PER_YEAR]; + std::array mustrunSum; //! Sum of all original 'must-run' clusters (adequacy only) // This variable is initialized every MC-year - double originalMustrunSum[HOURS_PER_YEAR]; + std::array originalMustrunSum; /*! ** \brief Dispatchable Generation Margin diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index 2b03f7bcdc..c2ac21dbea 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -402,7 +402,33 @@ void Adequacy::simulationEnd() void Adequacy::prepareClustersInMustRunMode(Data::Area::ScratchMap& scratchmap, uint year) { - PrepareDataFromClustersInMustrunMode(study, scratchmap, year); -} + for (uint i = 0; i < study.areas.size(); ++i) + { + auto &area = *study.areas[i]; + auto &scratchpad = scratchmap.at(&area); + + std::ranges::fill(scratchpad.mustrunSum, 0); + std::ranges::fill(scratchpad.originalMustrunSum, 0); + + auto& mrs = scratchpad.mustrunSum; + auto& adq = scratchpad.originalMustrunSum; + + for (const auto &cluster: area.thermal.list.each_mustrun_and_enabled()) + { + const auto &availableProduction = cluster->series.getColumn(year); + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + mrs[h] += availableProduction[h]; + } + if (cluster->mustrunOrigin) + { + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + adq[h] += 2 * availableProduction[h]; // Why do we add the available production twice ? + } + } + } + } +} } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 1f56235499..bc63e19708 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -113,65 +113,6 @@ static void RecalculDesEchangesMoyens(Data::Study& study, } } -void PrepareDataFromClustersInMustrunMode(Data::Study& study, - Data::Area::ScratchMap& scratchmap, - uint year) -{ - bool inAdequacy = (study.parameters.mode == Data::SimulationMode::Adequacy); - - for (uint i = 0; i < study.areas.size(); ++i) - { - auto& area = *study.areas[i]; - auto& scratchpad = scratchmap.at(&area); - - memset(scratchpad.mustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); - if (inAdequacy) - { - memset(scratchpad.originalMustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); - } - - double* mrs = scratchpad.mustrunSum; - double* adq = scratchpad.originalMustrunSum; - - for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) - { - const auto& availableProduction = cluster->series.getColumn(year); - if (inAdequacy && cluster->mustrunOrigin) - { - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - mrs[h] += availableProduction[h]; - adq[h] += availableProduction[h]; - } - } - else - { - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - mrs[h] += availableProduction[h]; - } - } - } - - if (inAdequacy) - { - for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) - { - if (!cluster->mustrunOrigin) - { - continue; - } - - const auto& availableProduction = cluster->series.getColumn(year); - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - adq[h] += availableProduction[h]; - } - } - } - } -} - bool ShouldUseQuadraticOptimisation(const Data::Study& study) { const bool flowQuadEnabled = study.parameters.variablesPrintInfo.isPrinted("FLOW QUAD."); diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index 934ebc4c2c..4baef3d5b4 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -265,7 +265,23 @@ void Economy::simulationEnd() void Economy::prepareClustersInMustRunMode(Data::Area::ScratchMap& scratchmap, uint year) { - PrepareDataFromClustersInMustrunMode(study, scratchmap, year); + for (uint i = 0; i < study.areas.size(); ++i) + { + auto& area = *study.areas[i]; + auto& scratchpad = scratchmap.at(&area); + + std::ranges::fill(scratchpad.mustrunSum, 0); + + auto& mrs = scratchpad.mustrunSum; + for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) + { + const auto& availableProduction = cluster->series.getColumn(year); + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + mrs[h] += availableProduction[h]; + } + } + } } } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h b/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h index 6ea4a9e003..0bf24cd71d 100644 --- a/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h +++ b/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h @@ -66,13 +66,6 @@ void BuildThermalPartOfWeeklyProblem(Data::Study& study, double** thermalNoises, unsigned int year); -/*! -** \brief Prepare data from clusters in mustrun mode (eco+adq) -*/ -void PrepareDataFromClustersInMustrunMode(Data::Study& study, - Data::Area::ScratchMap& scratchmap, - uint year); - /*! ** \brief Get if the quadratic optimization should be used according ** to the input data (eco+adq) From 60977f667965ec4614a56feb0dcb9032ca3e98fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20Mar=C3=A9chal?= <45510813+JasonMarechal25@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:38:21 +0200 Subject: [PATCH 10/10] Expose API [ANT-1158] (#1993) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expose Antares Solver in a library. the library and target are called AntaresAPI. This API expose one entry point to run a simulation on a study. The return value of this is a data structure with the path to the simulation and the weekly problems. - New component API - Create a new project "api_client" and corresponding tests to detect API lib install regressions - rename "utils" project in tests as "in-memory-study" - promote this project at top level in tests. This allow in-memory-study to be used for any tests - create SimulationObserver. Object passed throughout all "frames" of the simulation. --------- Co-authored-by: Florian Omnès Co-authored-by: Florian OMNES <26088210+flomnes@users.noreply.github.com> --- .../workflows/install-cmake-328/action.yml | 4 +- .github/workflows/ubuntu.yml | 19 +- .../Expose_cpp_API.md | 10 +- .../separate_install_exe_api.md | 25 +++ src/CMakeLists.txt | 3 +- src/api/API.cpp | 116 +++++++++++ src/api/CMakeLists.txt | 42 ++++ src/api/SimulationObserver.cpp | 73 +++++++ src/api/SimulationResults.cpp | 22 ++ .../include/antares/api/SimulationResults.h | 62 ++++++ src/api/include/antares/api/solver.h | 35 ++++ src/api/private/API.h | 56 ++++++ src/api/private/SimulationObserver.h | 61 ++++++ src/api/solver.cpp | 46 +++++ src/api_client_example/CMakeLists.txt | 12 ++ src/api_client_example/README.md | 3 + src/api_client_example/src/API_client.cpp | 30 +++ src/api_client_example/src/API_client.h | 28 +++ src/api_client_example/src/CMakeLists.txt | 14 ++ src/api_client_example/tests/CMakeLists.txt | 17 ++ src/api_client_example/tests/test.cpp | 37 ++++ .../FileTreeStudyLoader.cpp | 14 +- src/libs/antares/inifile/CMakeLists.txt | 4 +- src/libs/antares/study/CMakeLists.txt | 1 - .../study/parts/short-term-storage/cluster.h | 38 ++-- src/packaging/CMakeLists.txt | 3 + src/packaging/Config.cmake.in | 6 +- src/solver/CMakeLists.txt | 1 + src/solver/application/application.cpp | 9 +- src/solver/lps/CMakeLists.txt | 24 +++ src/solver/lps/LpsFromAntares.cpp | 56 ++++++ .../antares/solver/lps/LpsFromAntares.h | 149 ++++++++++++++ src/solver/main/economy.cpp | 47 ----- src/solver/misc/options.cpp | 40 ++-- src/solver/optimisation/CMakeLists.txt | 4 +- .../HebdoProblemToLpsTranslator.cpp | 109 ++++++++++ .../adequacy_patch_weekly_optimization.cpp | 49 ++--- .../optimisation/base_weekly_optimization.cpp | 55 ++--- .../HebdoProblemToLpsTranslator.h | 81 ++++++++ .../adequacy_patch_weekly_optimization.h | 5 +- .../optimisation/base_weekly_optimization.h | 48 +++-- .../constraints/constraint_builder_utils.h | 1 + .../optimisation/opt_export_structure.h | 58 ++---- .../solver/optimisation/opt_fonctions.h | 62 +++--- .../solver/optimisation/weekly_optimization.h | 44 ++-- .../optimisation/opt_optimisation_hebdo.cpp | 45 +++-- .../opt_optimisation_lineaire.cpp | 71 ++++--- .../opt_pilotage_optimisation_lineaire.cpp | 44 ++-- .../optimisation/opt_rename_problem.cpp | 1 + .../optimisation/weekly_optimization.cpp | 43 ++-- src/solver/simulation/CMakeLists.txt | 55 ++--- src/solver/simulation/adequacy.cpp | 51 ++--- src/solver/simulation/adequacy_mode.cpp | 63 +++--- src/solver/simulation/common-eco-adq.cpp | 42 ++-- src/solver/simulation/economy.cpp | 48 +++-- src/solver/simulation/economy_mode.cpp | 64 +++--- .../solver/simulation/ISimulationObserver.h | 65 ++++++ .../antares/solver/simulation/adequacy.h | 48 ++--- .../antares/solver/simulation/adequacy_mode.h | 4 +- .../antares/solver/simulation/economy.h | 43 ++-- .../antares/solver/simulation/economy_mode.h | 5 +- .../antares/solver/simulation/solver.h | 45 +++-- .../antares/solver/simulation/solver.hxx | 23 ++- .../antares/solver/utils/name_translator.h | 38 ++-- src/tests/CMakeLists.txt | 1 + src/tests/end-to-end/CMakeLists.txt | 1 - .../binding_constraints/CMakeLists.txt | 3 +- .../test_binding_constraints.cpp | 2 +- .../end-to-end/simple_study/CMakeLists.txt | 3 +- .../end-to-end/simple_study/simple-study.cpp | 2 +- src/tests/end-to-end/utils/CMakeLists.txt | 20 -- src/tests/inmemory-study/CMakeLists.txt | 25 +++ .../in-memory-study.cpp} | 51 ++--- .../include/in-memory-study.h} | 43 ++-- src/tests/src/CMakeLists.txt | 2 + src/tests/src/api_internal/CMakeLists.txt | 27 +++ src/tests/src/api_internal/test_api.cpp | 96 +++++++++ src/tests/src/api_lib/CMakeLists.txt | 20 ++ src/tests/src/api_lib/test_api.cpp | 35 ++++ src/tests/src/libs/CMakeLists.txt | 2 +- src/tests/src/solver/CMakeLists.txt | 1 + .../test-unfeasible-problem-analyzer.cpp | 5 +- src/tests/src/solver/lps/CMakeLists.txt | 20 ++ src/tests/src/solver/lps/test_lps.cpp | 77 +++++++ .../src/solver/optimisation/CMakeLists.txt | 26 +-- .../adequacy_patch/CMakeLists.txt | 24 +++ .../{ => adequacy_patch}/adequacy_patch.cpp | 0 .../optimisation/translator/CMakeLists.txt | 20 ++ .../translator/test_translator.cpp | 189 ++++++++++++++++++ .../renderer/scenario-builder-ntc-renderer.h | 38 ++-- src/vcpkg.json | 2 +- 91 files changed, 2427 insertions(+), 729 deletions(-) create mode 100644 docs/Architecture_Decision_Records/separate_install_exe_api.md create mode 100644 src/api/API.cpp create mode 100644 src/api/CMakeLists.txt create mode 100644 src/api/SimulationObserver.cpp create mode 100644 src/api/SimulationResults.cpp create mode 100644 src/api/include/antares/api/SimulationResults.h create mode 100644 src/api/include/antares/api/solver.h create mode 100644 src/api/private/API.h create mode 100644 src/api/private/SimulationObserver.h create mode 100644 src/api/solver.cpp create mode 100644 src/api_client_example/CMakeLists.txt create mode 100644 src/api_client_example/README.md create mode 100644 src/api_client_example/src/API_client.cpp create mode 100644 src/api_client_example/src/API_client.h create mode 100644 src/api_client_example/src/CMakeLists.txt create mode 100644 src/api_client_example/tests/CMakeLists.txt create mode 100644 src/api_client_example/tests/test.cpp create mode 100644 src/solver/lps/CMakeLists.txt create mode 100644 src/solver/lps/LpsFromAntares.cpp create mode 100644 src/solver/lps/include/antares/solver/lps/LpsFromAntares.h delete mode 100644 src/solver/main/economy.cpp create mode 100644 src/solver/optimisation/HebdoProblemToLpsTranslator.cpp create mode 100644 src/solver/optimisation/include/antares/solver/optimisation/HebdoProblemToLpsTranslator.h create mode 100644 src/solver/simulation/include/antares/solver/simulation/ISimulationObserver.h delete mode 100644 src/tests/end-to-end/utils/CMakeLists.txt create mode 100644 src/tests/inmemory-study/CMakeLists.txt rename src/tests/{end-to-end/utils/utils.cpp => inmemory-study/in-memory-study.cpp} (88%) rename src/tests/{end-to-end/utils/utils.h => inmemory-study/include/in-memory-study.h} (86%) create mode 100644 src/tests/src/api_internal/CMakeLists.txt create mode 100644 src/tests/src/api_internal/test_api.cpp create mode 100644 src/tests/src/api_lib/CMakeLists.txt create mode 100644 src/tests/src/api_lib/test_api.cpp create mode 100644 src/tests/src/solver/lps/CMakeLists.txt create mode 100644 src/tests/src/solver/lps/test_lps.cpp create mode 100644 src/tests/src/solver/optimisation/adequacy_patch/CMakeLists.txt rename src/tests/src/solver/optimisation/{ => adequacy_patch}/adequacy_patch.cpp (100%) create mode 100644 src/tests/src/solver/optimisation/translator/CMakeLists.txt create mode 100644 src/tests/src/solver/optimisation/translator/test_translator.cpp diff --git a/.github/workflows/install-cmake-328/action.yml b/.github/workflows/install-cmake-328/action.yml index a6f111746c..1cf045dbee 100644 --- a/.github/workflows/install-cmake-328/action.yml +++ b/.github/workflows/install-cmake-328/action.yml @@ -1,4 +1,4 @@ -name: "Install cmake 3.28 using devtoolset 10" +name: "Install cmake 3.28 using devtoolset 10 if possible" description: "Download and install system wide cmake 3.28" runs: @@ -7,7 +7,7 @@ runs: - name: Build cmake shell: bash run: | - source /opt/rh/devtoolset-10/enable + source /opt/rh/devtoolset-10/enable || true # Ignore error if devtoolset-10 is not available yum -y install openssl-devel wget https://github.com/Kitware/CMake/releases/download/v3.28.2/cmake-3.28.2.tar.gz tar -xvf cmake-3.28.2.tar.gz diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 85713eeb70..88fc65ceac 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -29,7 +29,6 @@ env: RUN_EXTENDED_TESTS: ${{ github.event_name == 'schedule' || inputs.run-tests == 'true' }} REF: ${{ inputs.target_branch =='' && github.ref || inputs.target_branch}} VCPKG_ROOT: ${{ github.workspace }}/vcpkg - vcpkgPackages: yaml-cpp antlr4 boost-test triplet: x64-linux WX_CONFIG: /usr/bin/wx-config @@ -115,6 +114,24 @@ jobs: run: | cmake --build _build -j$(nproc) + - name: Run API tests + run: | + cmake --install _build --prefix antares_install + cd src/api_client_example + cmake -B _build -S . \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TESTING=ON \ + -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/vcpkg/scripts/buildsystems/vcpkg.cmake \ + -DVCPKG_TARGET_TRIPLET=x64-linux-release \ + -DCMAKE_PREFIX_PATH="${{github.workspace}}/rte-antares-deps-Release;${{github.workspace}}/install;${{ env.ORTOOLS_DIR }}/install;${{github.workspace}}/antares_install;${{github.workspace}}/rte-antares-deps-Release;${{github.workspace}}/_build/vcpkg_installed/x64-linux-release" + cmake --build _build -j$(nproc) + cd _build + ctest -C Release --output-on-failure + # simtest - name: Read simtest version id: simtest-version diff --git a/docs/Architecture_Decision_Records/Expose_cpp_API.md b/docs/Architecture_Decision_Records/Expose_cpp_API.md index bae68cd5b4..fcc11c8a93 100644 --- a/docs/Architecture_Decision_Records/Expose_cpp_API.md +++ b/docs/Architecture_Decision_Records/Expose_cpp_API.md @@ -4,11 +4,11 @@ ## Context -Some clients (e.g. Xpansion) would prefer to use a library than a CLI tool. Exposing a library require exposing a public API. -The API can be exposed either as pure C or as C++. -A C API can always be developped as a facade on top of a C++ API. -C++ API will not have to care about ABI compatibility because Simulator lib will be provided as static, meaning a client -upgrading would need to be recompiled and relink with the new lib version. +Several clients, such as Xpansion, express a preference for utilizing a library over a command-line interface (CLI) tool. Exposing a library necessitates the exposure of a public API. + +This API can be presented in either pure C or C++. It's worth noting that a C API can always serve as a facade atop a C++ API. + +In the case of a C++ API, concerns regarding ABI compatibility are alleviated, as the Simulator library is provided in a static form. Consequently, when a client upgrades, they would simply need to recompile and relink with the new version of the library. ## Decision diff --git a/docs/Architecture_Decision_Records/separate_install_exe_api.md b/docs/Architecture_Decision_Records/separate_install_exe_api.md new file mode 100644 index 0000000000..3a9662ec1d --- /dev/null +++ b/docs/Architecture_Decision_Records/separate_install_exe_api.md @@ -0,0 +1,25 @@ +# Expose public C++ API + +## Status: Rejected [2024/04/11] + +## Context + +Originally, there exists a single install target designated to deploy the diverse Antares executables, predominantly packaged within the release assets. However, there's a rationale behind avoiding the creation of a unified package containing both executables and libraries, given that they cater to distinct user demographics. This mirrors the flexibility offered by package managers such as apt, where users can opt to install binary packages and separate development (devel) packages according to their requirements. + +## Decision + +Split installation into two targets + +Produce different assets/packages for each install targets. + + +## Consequences + +* Mutltiplication of assets +* Two install targets to manage +* Users of executable not "polluted" by libraries + +## Reason for rejection + +The decision was rejected because it was deemed unnecessary to split the installation targets. It adds +some difficulties for few benefits at the moment \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 862c7fdbc8..44715f0650 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -233,7 +233,7 @@ message(STATUS "OR-Tools tag ${ORTOOLS_TAG}") FetchContent_MakeAvailable(ortools) endif() -find_package(minizip-ng) +find_package(minizip-ng QUIET) if (minizip-ng_FOUND) add_library(MINIZIP::minizip ALIAS MINIZIP::minizip-ng) else () @@ -267,6 +267,7 @@ add_subdirectory("ext/yuni/src") OMESSAGE("") # empty line # Sub Directories +add_subdirectory(api) add_subdirectory(libs) #antares-core fswalker if(BUILD_UI) diff --git a/src/api/API.cpp b/src/api/API.cpp new file mode 100644 index 0000000000..38e9778eab --- /dev/null +++ b/src/api/API.cpp @@ -0,0 +1,116 @@ +/* + * 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 . + */ + +#include "API.h" +#include "antares/solver/simulation/economy_mode.h" +#include "antares/solver/simulation/adequacy_mode.h" +#include "antares/solver/misc/options.h" +#include "antares/infoCollection/StudyInfoCollector.h" +#include "antares/benchmarking/DurationCollector.h" +#include "antares/exception/LoadingError.hpp" +#include +#include + +namespace Antares::API +{ +SimulationResults APIInternal::run(const IStudyLoader& study_loader) +{ + try { + study_ = study_loader.load(); + } catch (const ::Antares::Error::StudyFolderDoesNotExist& e) { + Antares::API::Error err{.reason = e.what()}; + return { + .simulationPath = "", + .antares_problems = {}, + .error = err + }; + } + return execute(); +} + +/** + * @brief The execute method is used to execute the simulation. + * @return SimulationResults object which contains the results of the simulation. + * + * This method is initialy a copy of Application::execute with some modifications hence the apparent dupllication + */ +SimulationResults APIInternal::execute() const +{ + // study_ == nullptr e.g when the -h flag is given + if (!study_) + { + using namespace std::string_literals; + Antares::API::Error err{.reason = "Couldn't create study"s}; + return {.simulationPath{}, .antares_problems{}, .error = err}; + } + + study_->computePThetaInfForThermalClusters(); + + // Only those two fields are used un simulation + Settings settings; + settings.tsGeneratorsOnly = false; + settings.noOutput = false; + + Benchmarking::DurationCollector durationCollector; + Benchmarking::OptimizationInfo optimizationInfo; + auto ioQueueService = std::make_shared(); + ioQueueService->maximumThreadCount(1); + ioQueueService->start(); + auto resultWriter = Solver::resultWriterFactory( + study_->parameters.resultFormat, study_->folderOutput, ioQueueService, durationCollector); + SimulationObserver simulationObserver; + // Run the simulation + switch (study_->runtime->mode) + { + case Data::SimulationMode::Economy: + case Data::SimulationMode::Expansion: + Solver::runSimulationInEconomicMode(*study_, + settings, + durationCollector, + *resultWriter, + optimizationInfo, + simulationObserver); + break; + case Data::SimulationMode::Adequacy: + Solver::runSimulationInAdequacyMode(*study_, + settings, + durationCollector, + *resultWriter, + optimizationInfo, + simulationObserver); + break; + default: + break; + } + + // Importing Time-Series if asked + study_->importTimeseriesIntoInput(); + + // Stop the display of the progression + study_->progression.stop(); + return + { + .simulationPath = study_->folderOutput.c_str(), + .antares_problems = simulationObserver.acquireLps(), + .error{} + }; +} +} // namespace Antares::API \ No newline at end of file diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt new file mode 100644 index 0000000000..109c640578 --- /dev/null +++ b/src/api/CMakeLists.txt @@ -0,0 +1,42 @@ +add_library(solver_api) +add_library(Antares::solver_api ALIAS solver_api) + +set(PUBLIC_HEADERS + include/antares/api/SimulationResults.h + include/antares/api/solver.h +) + +set(PRIVATE_HEADERS + private/API.h + private/SimulationObserver.h +) + +target_sources(solver_api + PRIVATE + solver.cpp + API.cpp + SimulationObserver.cpp + SimulationResults.cpp + ${PUBLIC_HEADERS} + ${PRIVATE_HEADERS} +) + +target_include_directories(solver_api + PUBLIC + $ + PRIVATE + $ +) + +target_link_libraries(solver_api + PRIVATE + Antares::study + Antares::study-loader + Antares::file-tree-study-loader + antares-solver-simulation + PUBLIC + Antares::lps +) +install(DIRECTORY include/antares + DESTINATION "include" +) \ No newline at end of file diff --git a/src/api/SimulationObserver.cpp b/src/api/SimulationObserver.cpp new file mode 100644 index 0000000000..7842ce8099 --- /dev/null +++ b/src/api/SimulationObserver.cpp @@ -0,0 +1,73 @@ + +/* + * 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 . + */ + +#include "SimulationObserver.h" + +#include "antares/solver/optimisation/HebdoProblemToLpsTranslator.h" + +namespace Antares::API +{ +namespace +{ +auto translate(const PROBLEME_HEBDO& problemeHebdo, + std::string_view name, + const Solver::HebdoProblemToLpsTranslator& translator, + const unsigned int year, + const unsigned int week) +{ + auto weekly_data = translator.translate(problemeHebdo.ProblemeAResoudre.get(), name); + Solver::ConstantDataFromAntares common_data; + if (year == 1 && week == 1) + { + common_data = translator.commonProblemData(problemeHebdo.ProblemeAResoudre.get()); + } + return std::make_pair(common_data, weekly_data); +} +} // namespace + +void SimulationObserver::notifyHebdoProblem(const PROBLEME_HEBDO& problemeHebdo, + int optimizationNumber, + std::string_view name) +{ + if (optimizationNumber != 1) + { + return; // We only care about first optimization + } + Solver::HebdoProblemToLpsTranslator translator; + const unsigned int year = problemeHebdo.year + 1; + const unsigned int week = problemeHebdo.weekInTheYear + 1; + // common_data and weekly_data computed before the mutex lock to prevent blocking the thread + auto [common_data, weekly_data] = translate(problemeHebdo, name, translator, year, week); + std::lock_guard lock(mutex_); + if (year == 1 && week == 1) + { + lps_.setConstantData(common_data); + } + lps_.addWeeklyData({year, week}, weekly_data); +} + +Solver::LpsFromAntares&& SimulationObserver::acquireLps() noexcept +{ + std::lock_guard lock(mutex_); + return std::move(lps_); +} +} // namespace Antares::API diff --git a/src/api/SimulationResults.cpp b/src/api/SimulationResults.cpp new file mode 100644 index 0000000000..63c5127a49 --- /dev/null +++ b/src/api/SimulationResults.cpp @@ -0,0 +1,22 @@ +/* + * 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 . + */ + +#include "antares/api/SimulationResults.h" diff --git a/src/api/include/antares/api/SimulationResults.h b/src/api/include/antares/api/SimulationResults.h new file mode 100644 index 0000000000..5a5e93982a --- /dev/null +++ b/src/api/include/antares/api/SimulationResults.h @@ -0,0 +1,62 @@ +/* + * 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 . + */ + +#pragma once +#include +#include +#include +#include "antares/solver/lps/LpsFromAntares.h" + +namespace Antares::API +{ +/** + * @struct Error + * @brief The Error structure is used to represent an error that occurred during the simulation. + */ +struct Error { + /** + * @brief The reason for the error. + */ + std::string reason; +}; + +/** + * @struct SimulationResults + * @brief The SimulationResults structure is used to represent the results of a simulation. + * @details It contains the path to the simulation, weekly problems, and an optional error. + */ +struct [[nodiscard("Contains results and potential error")]] SimulationResults +{ + /** + * @brief The path to the simulation (output). + */ + std::filesystem::path simulationPath; + /** + * @brief weekly problems + */ + Antares::Solver::LpsFromAntares antares_problems; + /** + * @brief An optional error that occurred during the simulation. + */ + std::optional error; +}; + +} \ No newline at end of file diff --git a/src/api/include/antares/api/solver.h b/src/api/include/antares/api/solver.h new file mode 100644 index 0000000000..d016a9a08a --- /dev/null +++ b/src/api/include/antares/api/solver.h @@ -0,0 +1,35 @@ + +/* + * 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 . + */ + +#pragma once +#include "SimulationResults.h" + +namespace Antares::API +{ +/** + * @brief The PerformSimulation function is used to perform a simulation. + * @param study_path The path to the study to be simulated. + * @return SimulationResults object which contains the results of the simulation. + * @exception noexcept This function does not throw exceptions. + */ +SimulationResults PerformSimulation(const std::filesystem::path& study_path) noexcept; +} // namespace Antares::API diff --git a/src/api/private/API.h b/src/api/private/API.h new file mode 100644 index 0000000000..91f8a4e2d3 --- /dev/null +++ b/src/api/private/API.h @@ -0,0 +1,56 @@ +/* + * 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 . + */ + +#pragma once +#include + +#include +#include "antares/api/SimulationResults.h" + +namespace Antares::Data +{ +class Study; +} + +namespace Antares::API +{ + +/** + * @class APIInternal + * @brief The APIInternal class is used to run simulations. + */ +class APIInternal +{ +public: + /** + * @brief The run method is used to run the simulation. + * @param study_loader A pointer to an IStudyLoader object. The IStudyLoader object is used to + * load the study that will be simulated. + * @return SimulationResults object which contains the results of the simulation. + */ + SimulationResults run(const IStudyLoader& study_loader); + +private: + std::shared_ptr study_; + SimulationResults execute() const; +}; + +} // namespace Antares::API diff --git a/src/api/private/SimulationObserver.h b/src/api/private/SimulationObserver.h new file mode 100644 index 0000000000..f2d78fc4eb --- /dev/null +++ b/src/api/private/SimulationObserver.h @@ -0,0 +1,61 @@ +/* + * 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 . + */ + +#pragma once +#include +#include + +namespace Antares::API +{ + +/** + * @class SimulationObserver + * @brief The SimulationObserver class is used to observe the simulation. + * @details It inherits from the ISimulationObserver interface and overrides the notifyHebdoProblem + * method. + */ +class SimulationObserver: public Solver::Simulation::ISimulationObserver +{ +public: + /** + * @brief Used to notify of a solver HEBDO_PROBLEM. + * HEBDO_PROBLEM is assumed to be properly constructed and valid in order to build + * LpsFromAntares properly + * @param problemeHebdo A pointer to a PROBLEME_HEBDO object representing the problem. + * @param optimizationNumber The number of the optimization. + * @param name The name of the problem. + */ + void notifyHebdoProblem(const PROBLEME_HEBDO& problemeHebdo, + int optimizationNumber, + std::string_view name) override; + + /** + * @brief The acquireLps method is used to take ownership of Antares problems. + * @return An LpsFromAntares object containing the linear programming problems. + */ + Solver::LpsFromAntares&& acquireLps() noexcept; + +private: + Solver::LpsFromAntares lps_; + std::mutex mutex_; +}; + +} // namespace Antares::API diff --git a/src/api/solver.cpp b/src/api/solver.cpp new file mode 100644 index 0000000000..6e2f7068ea --- /dev/null +++ b/src/api/solver.cpp @@ -0,0 +1,46 @@ +/* + * 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 . + */ + +#include +#include "antares/file-tree-study-loader/FileTreeStudyLoader.h" +#include "antares/study-loader/IStudyLoader.h" + +#include "private/API.h" + +namespace Antares::API +{ + +SimulationResults PerformSimulation(const std::filesystem::path& study_path) noexcept +{ + try + { + APIInternal api; + FileTreeStudyLoader study_loader(study_path); + return api.run(study_loader); + } + catch (const std::exception& e) + { + Antares::API::Error err{.reason = e.what()}; + return SimulationResults{.simulationPath = study_path, .antares_problems{}, .error = err}; + } +} + +} // namespace Antares::API diff --git a/src/api_client_example/CMakeLists.txt b/src/api_client_example/CMakeLists.txt new file mode 100644 index 0000000000..570ee9341b --- /dev/null +++ b/src/api_client_example/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.5) + +PROJECT(API_client) + +set(CMAKE_CXX_STANDARD 20) + +add_subdirectory(src) + +include(CTest) +if (BUILD_TESTING) + add_subdirectory(tests) +endif () \ No newline at end of file diff --git a/src/api_client_example/README.md b/src/api_client_example/README.md new file mode 100644 index 0000000000..151b1d346b --- /dev/null +++ b/src/api_client_example/README.md @@ -0,0 +1,3 @@ +Client for antares solver API + +To demonstrate as much capabilities as possible this client should stay stand alone this mean not added as a sub_directory for cmake diff --git a/src/api_client_example/src/API_client.cpp b/src/api_client_example/src/API_client.cpp new file mode 100644 index 0000000000..6489806c51 --- /dev/null +++ b/src/api_client_example/src/API_client.cpp @@ -0,0 +1,30 @@ +/* + * 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 . + */ + + +#include "API_client.h" + +#include + +Antares::API::SimulationResults solve(std::filesystem::path study_path) { + return Antares::API::PerformSimulation(std::move(study_path)); +} + diff --git a/src/api_client_example/src/API_client.h b/src/api_client_example/src/API_client.h new file mode 100644 index 0000000000..5d8500649e --- /dev/null +++ b/src/api_client_example/src/API_client.h @@ -0,0 +1,28 @@ + +/* + * 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 . + */ + +#pragma once + +#include +#include + +Antares::API::SimulationResults solve(std::filesystem::path study_path); diff --git a/src/api_client_example/src/CMakeLists.txt b/src/api_client_example/src/CMakeLists.txt new file mode 100644 index 0000000000..55ebb33579 --- /dev/null +++ b/src/api_client_example/src/CMakeLists.txt @@ -0,0 +1,14 @@ +add_library(API_client) + +target_sources(API_client + PRIVATE + API_client.cpp + API_client.h +) + +find_package(Antares REQUIRED) +target_link_libraries(API_client PUBLIC Antares::solver_api) +target_include_directories(API_client + PUBLIC + $ +) \ No newline at end of file diff --git a/src/api_client_example/tests/CMakeLists.txt b/src/api_client_example/tests/CMakeLists.txt new file mode 100644 index 0000000000..1fc9c3cc89 --- /dev/null +++ b/src/api_client_example/tests/CMakeLists.txt @@ -0,0 +1,17 @@ +find_package(Boost COMPONENTS unit_test_framework REQUIRED) + +add_executable(test_client) + +target_sources(test_client + PRIVATE + test.cpp +) + +target_link_libraries(test_client + PRIVATE + API_client + Boost::unit_test_framework +) + +add_test(NAME testclient COMMAND test_client) +set_property(TEST testclient PROPERTY LABELS integ) \ No newline at end of file diff --git a/src/api_client_example/tests/test.cpp b/src/api_client_example/tests/test.cpp new file mode 100644 index 0000000000..4adee7bfd6 --- /dev/null +++ b/src/api_client_example/tests/test.cpp @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +#define BOOST_TEST_MODULE test_client_api + +#include +#include "API_client.h" + +BOOST_AUTO_TEST_CASE(test_run) { + auto results = solve("dummy_study_test_client_api"); + BOOST_CHECK(results.error); + BOOST_CHECK(!results.error->reason.empty()); + auto c = results.error->reason; + std::cout << c << std::endl; + BOOST_CHECK(results.error->reason.find("Study") != std::string::npos); + BOOST_CHECK(results.error->reason.find("folder") != std::string::npos); + BOOST_CHECK(results.error->reason.find("not") != std::string::npos); + BOOST_CHECK(results.error->reason.find("exist") != std::string::npos); +} \ No newline at end of file diff --git a/src/libs/antares/file-tree-study-loader/FileTreeStudyLoader.cpp b/src/libs/antares/file-tree-study-loader/FileTreeStudyLoader.cpp index 5302c19263..8ff1c2730d 100644 --- a/src/libs/antares/file-tree-study-loader/FileTreeStudyLoader.cpp +++ b/src/libs/antares/file-tree-study-loader/FileTreeStudyLoader.cpp @@ -49,15 +49,10 @@ namespace * @param study_path A string_view representing the study path. * @return std::vector A vector of strings containing the prepared arguments. */ -[[nodiscard]] std::vector prepareArgs(std::span argv, - std::string_view study_path) +void prepareArgs(std::array& argv, std::span data) { - using namespace std::literals::string_literals; - std::string arg0{""s}; - std::string arg1{study_path}; - argv[0] = arg0.data(); - argv[1] = arg1.data(); - return {std::move(arg0), std::move(arg1)}; + argv[0] = data[0].data(); + argv[1] = data[1].data(); } } // namespace @@ -66,8 +61,9 @@ std::unique_ptr FileTreeStudyLoader::load() const using namespace std::literals::string_literals; Antares::Solver::Application application; constexpr unsigned int argc = 2; + std::array keep_alive{""s, study_path_.string()}; std::array argv; - auto keep_alive = prepareArgs(argv, study_path_.string()); + prepareArgs(argv, keep_alive); application.prepare(argc, argv.data()); return application.acquireStudy(); diff --git a/src/libs/antares/inifile/CMakeLists.txt b/src/libs/antares/inifile/CMakeLists.txt index a68b3f2786..089591f002 100644 --- a/src/libs/antares/inifile/CMakeLists.txt +++ b/src/libs/antares/inifile/CMakeLists.txt @@ -17,11 +17,11 @@ target_link_libraries(inifile PRIVATE io logs - Boost::boost + Boost::headers ) target_include_directories(inifile - PUBLIC + PUBLIC $ ) diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt index c90d543fff..65ad5398a6 100644 --- a/src/libs/antares/study/CMakeLists.txt +++ b/src/libs/antares/study/CMakeLists.txt @@ -285,7 +285,6 @@ add_library(Antares::study ALIAS study) target_link_libraries(study PUBLIC - Boost::boost yuni-static-core Antares::date #parameters Antares::inifile #parameters diff --git a/src/libs/antares/study/include/antares/study/parts/short-term-storage/cluster.h b/src/libs/antares/study/include/antares/study/parts/short-term-storage/cluster.h index afe2e1976f..cc9af74015 100644 --- a/src/libs/antares/study/include/antares/study/parts/short-term-storage/cluster.h +++ b/src/libs/antares/study/include/antares/study/parts/short-term-storage/cluster.h @@ -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 . -*/ + * 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 . + */ #pragma once #include diff --git a/src/packaging/CMakeLists.txt b/src/packaging/CMakeLists.txt index 6d68ec5e38..868cd7a8ec 100644 --- a/src/packaging/CMakeLists.txt +++ b/src/packaging/CMakeLists.txt @@ -10,6 +10,8 @@ set(TARGET_LIBS #No alias #not dependency is present since once a dependency is in the export set #it is available for everything + solver_api #What we want to export + #solver_api study study-loader @@ -33,6 +35,7 @@ set(TARGET_LIBS #No alias exception benchmarking antares-solver-variable + lps #study-loader #nothing diff --git a/src/packaging/Config.cmake.in b/src/packaging/Config.cmake.in index 2cbf63a275..c9bcb039e1 100644 --- a/src/packaging/Config.cmake.in +++ b/src/packaging/Config.cmake.in @@ -1,8 +1,8 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) -find_dependency(ortools REQUIRED) -find_dependency(minizip-ng) +find_dependency(Boost REQUIRED) +find_package(minizip-ng QUIET) #Optional, don't use find_dependency it forces return in case of dep not found if (minizip-ng_FOUND) add_library(MINIZIP::minizip ALIAS MINIZIP::minizip-ng) else () @@ -11,6 +11,8 @@ else () message (FATAL_ERROR "Minizip dependency (minizip or minizip-ng) not found.") endif () endif () +find_dependency(ortools REQUIRED) +find_dependency(sirius_solver REQUIRED) include("${CMAKE_CURRENT_LIST_DIR}/AntaresTargets.cmake") diff --git a/src/solver/CMakeLists.txt b/src/solver/CMakeLists.txt index aeb17fb3a0..13ab3bfa6c 100644 --- a/src/solver/CMakeLists.txt +++ b/src/solver/CMakeLists.txt @@ -11,6 +11,7 @@ add_subdirectory(application) add_subdirectory(constraints-builder) add_subdirectory(hydro) add_subdirectory(infeasible-problem-analysis) +add_subdirectory(lps) add_subdirectory(misc) add_subdirectory(optimisation) add_subdirectory(signal-handling) diff --git a/src/solver/application/application.cpp b/src/solver/application/application.cpp index d222ad88c0..90d5e559c5 100644 --- a/src/solver/application/application.cpp +++ b/src/solver/application/application.cpp @@ -34,7 +34,6 @@ #include #include "antares/antares/version.h" #include "antares/config/config.h" -#include "antares/file-tree-study-loader/FileTreeStudyLoader.h" #include "antares/signal-handling/public.h" #include "antares/solver/misc/system-memory.h" #include "antares/solver/misc/write-command-line.h" @@ -410,20 +409,24 @@ void Application::execute() void Application::runSimulationInEconomicMode() { + Simulation::NullSimulationObserver observer; Solver::runSimulationInEconomicMode(*pStudy, pSettings, pDurationCollector, *resultWriter, - pOptimizationInfo); + pOptimizationInfo, + observer); } void Application::runSimulationInAdequacyMode() { + Simulation::NullSimulationObserver observer; Solver::runSimulationInAdequacyMode(*pStudy, pSettings, pDurationCollector, *resultWriter, - pOptimizationInfo); + pOptimizationInfo, + observer); } static std::string timeToString() diff --git a/src/solver/lps/CMakeLists.txt b/src/solver/lps/CMakeLists.txt new file mode 100644 index 0000000000..8c3e48cab0 --- /dev/null +++ b/src/solver/lps/CMakeLists.txt @@ -0,0 +1,24 @@ +set(PROJ lps) +set(HEADERS + include/antares/solver/lps/LpsFromAntares.h +) +set(SRC_PROJ + ${HEADERS} + LpsFromAntares.cpp +) +source_group("solver\\lps" FILES ${SRC_PROJ}) + +add_library(${PROJ}) +target_sources(${PROJ} PRIVATE + ${SRC_PROJ} +) +add_library(Antares::${PROJ} ALIAS ${PROJ}) + +target_include_directories(${PROJ} + PUBLIC + $ +) + +install(DIRECTORY include/antares + DESTINATION "include" +) \ No newline at end of file diff --git a/src/solver/lps/LpsFromAntares.cpp b/src/solver/lps/LpsFromAntares.cpp new file mode 100644 index 0000000000..a32484038d --- /dev/null +++ b/src/solver/lps/LpsFromAntares.cpp @@ -0,0 +1,56 @@ +/* + * 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 . + */ + +#include "antares/solver/lps/LpsFromAntares.h" + +namespace Antares::Solver +{ +bool LpsFromAntares::empty() const +{ + return constantProblemData.VariablesCount == 0 || weeklyProblems.empty(); +} + +void LpsFromAntares::setConstantData(const ConstantDataFromAntares& data) +{ + constantProblemData = data; +} + +void LpsFromAntares::addWeeklyData(WeeklyProblemId id, const WeeklyDataFromAntares& data) +{ + weeklyProblems.emplace(id, data); +} + +const WeeklyDataFromAntares& LpsFromAntares::weeklyData(WeeklyProblemId id) const +{ + auto it = weeklyProblems.find(id); + if (it == weeklyProblems.end()) + { + return WeeklyDataFromAntares(); // TODO Better error handling + } + return it->second; +} + +size_t LpsFromAntares::weekCount() const noexcept +{ + return weeklyProblems.size(); +} + +} // namespace Antares::Solver diff --git a/src/solver/lps/include/antares/solver/lps/LpsFromAntares.h b/src/solver/lps/include/antares/solver/lps/LpsFromAntares.h new file mode 100644 index 0000000000..f85d99b060 --- /dev/null +++ b/src/solver/lps/include/antares/solver/lps/LpsFromAntares.h @@ -0,0 +1,149 @@ + +/* + * 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 . + */ + +#pragma once +#include +#include +#include +#include +#include + +namespace Antares::Solver +{ + +/** + * @struct WeeklyProblemId + * @brief The WeeklyProblemId struct is used to identify a weekly problem by year and week. + */ +struct WeeklyProblemId +{ + unsigned int year = 0; + unsigned int week = 0; + // Order of comparison is order of member declaration + auto operator<=>(const WeeklyProblemId& other) const = default; +}; + +// Type de données inutile car les matrices de tous les pbs Weekly sont +// identiques. Cela pourra changer à l'avenir si des coefficients de contraintes +// couplantes peuvent varier au cours du temps (ex: rendement d'une pompe à +// chaleur qui varie selon la température, FlowBased ?, etc) +/** + * @class ConstantDataFromAntares + * @brief The ConstantDataFromAntares class is used to store constant data across all weeks + * of Antares problems. + */ +struct ConstantDataFromAntares +{ + unsigned VariablesCount = 0; // Mathématiquement : Nb colonnes de la matrice, + // Informatiquement = TypeDeVariable.size() + unsigned ConstraintesCount = 0; // Mathématiqument : Nb lignes de la matrice, + // Informatiquement = Mdeb.size() + unsigned CoeffCount = 0; // Mathématiquement : Nb coeffs non nuls de la + // matrice, Informatiquement = Nbterm.size() = + // IndicesColonnes.size()= + // CoefficientsDeLaMatriceDesContraintes.size() + + std::vector VariablesType; // Variables entières ou biniaires + std::vector Mdeb; // Indique dans les indices dans le vecteur IndicesColonnes qui + // correspondent au début de chaque ligne. Ex : Mdeb[3] = 8 et + // Mdeb[4] = 13 -> Les termes IndicesColonnes[8] à + // IndicesColonnes[12] correspondent à des Id de colonnes de la + // ligne 3 de la matrice (en supposant que les lignes sont indexées + // à partir de 0) + std::vector NotNullTermCount; // Nombre de termes non nuls sur chaque ligne. + // Inutile car NbTerm[i] = Mdeb[i+1] - Mdeb[i] + std::vector ColumnIndexes; // Id des colonnes des termes de + // CoefficientsDeLaMatriceDesContraintes : Ex + // IndicesColonnes[3] = 8 -> + // CoefficientsDeLaMatriceDesContraintes[8] donne la + // valeur du terme de la colonne 8, et de la ligne i où + // i est tel que Mdeb[i] <= 3 < Mdeb[i+1] + std::vector ConstraintsMatrixCoeff; // Coefficients de la matrice + + std::vector VariablesMeaning; + std::vector ConstraintsMeaning; + + auto operator<=>(const ConstantDataFromAntares& other) const = default; +}; + +/** + * @class WeeklyDataFromAntares + * @brief The WeeklyDataFromAntares class is used to store weekly data for an Antares Problem. + */ +struct WeeklyDataFromAntares +{ + std::vector Direction; // Sens de la contrainte : < ou > ou =, taille = + // NombreDeContraintes + std::vector Xmax; // Borne max des variables de la semaine + // considérée, taille = NombreDeVariables + std::vector Xmin; // Borne min des variables de la semaine + // considérée, taille = NombreDeVariables + std::vector LinearCost; // Coefficients du vecteur de coût de la fonction objectif, + // taille = NombreDeVariables + std::vector RHS; // Vecteur des second membre des contraintes, taille = + // NombreDeContraintes + std::string name; + + std::vector variables; + std::vector constraints; + + auto operator<=>(const WeeklyDataFromAntares& other) const = default; +}; + +using WeeklyDataByYearWeek = std::map; + +/** + * @class LpsFromAntares + * @brief The LpsFromAntares class is used to manage the constant and weekly data for Antares + * problems. + */ +class LpsFromAntares +{ +public: + /* + * @brief Checks if the LpsFromAntares object is empty. + * Emptiness is defined by either the constant data or the weekly data being empty. + */ + bool empty() const; + /* + * @brief Replaces the constant data in the LpsFromAntares object. + * Copy happens + */ + void setConstantData(const ConstantDataFromAntares& data); + /* + * @brief Adds weekly data to the LpsFromAntares object. + */ + void addWeeklyData(WeeklyProblemId id, const WeeklyDataFromAntares& data); + /* + * @brief Retrieves weekly data from the LpsFromAntares object. + */ + const WeeklyDataFromAntares& weeklyData(WeeklyProblemId id) const; + /* + * @brief Retrieves the number of weeks in the LpsFromAntares object. + */ + [[nodiscard]] size_t weekCount() const noexcept; + + ConstantDataFromAntares constantProblemData; + WeeklyDataByYearWeek weeklyProblems; +}; + +} // namespace Antares::Solver diff --git a/src/solver/main/economy.cpp b/src/solver/main/economy.cpp deleted file mode 100644 index f4fc8ba907..0000000000 --- a/src/solver/main/economy.cpp +++ /dev/null @@ -1,47 +0,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 . -*/ - -#include "antares/solver/simulation/economy.h" - -#include -#include -#include "antares/application/application.h" -#include "antares/solver/simulation/solver.h" - -namespace Antares::Solver -{ -void Application::runSimulationInEconomicMode() -{ - // Type of the simulation - typedef Solver::Simulation::ISimulation SimulationType; - SimulationType simulation(*pStudy, pSettings, pDurationCollector, *resultWriter); - simulation.checkWriter(); - simulation.run(); - - if (!(pSettings.noOutput || pSettings.tsGeneratorsOnly)) - { - pDurationCollector("synthesis_export") - << [&simulation] { simulation.writeResults(/*synthesis:*/ true); }; - - this->pOptimizationInfo = simulation.getOptimizationInfo(); - } -} -} // namespace Antares::Solver diff --git a/src/solver/misc/options.cpp b/src/solver/misc/options.cpp index 9429b50e79..a09b83e17d 100644 --- a/src/solver/misc/options.cpp +++ b/src/solver/misc/options.cpp @@ -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 . -*/ + * 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 . + */ #include "antares/solver/misc/options.h" @@ -45,7 +45,7 @@ std::unique_ptr CreateParser(Settings& settings, StudyLoad { settings.reset(); - auto parser = std::unique_ptr(new Yuni::GetOpt::Parser()); + auto parser = std::make_unique(); parser->addParagraph(Yuni::String() << "Antares Solver v" << ANTARES_VERSION_PUB_STR << "\n"); diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index cbf8f33fc3..a6c6f01e66 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -172,7 +172,8 @@ set(RTESOLVER_OPT variables/VariableManagement.cpp variables/VariableManagerUtils.h variables/VariableManagerUtils.cpp - + include/antares/solver/optimisation/HebdoProblemToLpsTranslator.h + HebdoProblemToLpsTranslator.cpp ) @@ -196,6 +197,7 @@ target_link_libraries(model_antares antares-solver-simulation Antares::benchmarking Antares::optimization-options + Antares::lps PRIVATE infeasible_problem_analysis ) diff --git a/src/solver/optimisation/HebdoProblemToLpsTranslator.cpp b/src/solver/optimisation/HebdoProblemToLpsTranslator.cpp new file mode 100644 index 0000000000..1109e9c780 --- /dev/null +++ b/src/solver/optimisation/HebdoProblemToLpsTranslator.cpp @@ -0,0 +1,109 @@ + +/* + * 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 . + */ + +#include "antares/solver/optimisation/HebdoProblemToLpsTranslator.h" +#include "antares/solver/utils/filename.h" + +namespace Antares::Solver +{ + +namespace +{ +/** + * @brief Copies elements from one container to another. + * + * This function takes two containers as arguments. It copies elements from the first container to the second one. + * + * @param in The container from which to copy elements. + * @param out The container to which to copy elements. + */ +template +void copy(const T& in, U& out) +{ + std::ranges::copy(in, std::back_inserter(out)); +} +} + +WeeklyDataFromAntares HebdoProblemToLpsTranslator::translate( + const PROBLEME_ANTARES_A_RESOUDRE* problem, + std::string_view name) const +{ + if (problem == nullptr) + return {}; + auto ret = WeeklyDataFromAntares(); + + copy(problem->CoutLineaire, ret.LinearCost); + copy(problem->Xmax, ret.Xmax); + copy(problem->Xmin, ret.Xmin); + copy(problem->NomDesVariables, ret.variables); + copy(problem->NomDesContraintes, ret.constraints); + copy(problem->SecondMembre, ret.RHS); + copy(problem->Sens, ret.Direction); + + copy(name, ret.name); + + return ret; +} + +ConstantDataFromAntares HebdoProblemToLpsTranslator::commonProblemData(const PROBLEME_ANTARES_A_RESOUDRE* problem) const { + if (problem == nullptr) + return ConstantDataFromAntares(); + + if (problem->NombreDeVariables <= 0) { + throw WeeklyProblemTranslationException("VariablesCount must be strictly positive"); + } + if (problem->NombreDeContraintes <= 0) { + throw WeeklyProblemTranslationException("ConstraintesCount must be strictly positive"); + } + + if (problem->NombreDeContraintes > problem->IndicesDebutDeLigne.size()) { + throw WeeklyProblemTranslationException("ConstraintesCount exceed IndicesDebutDeLigne size"); + } + + if (problem->NombreDeContraintes > problem->NombreDeTermesDesLignes.size()) { + throw WeeklyProblemTranslationException("ConstraintesCount exceed NombreDeTermesDesLignes size"); + } + + ConstantDataFromAntares ret; + + ret.VariablesCount = problem->NombreDeVariables; + ret.ConstraintesCount = problem->NombreDeContraintes; + + ret.CoeffCount = problem->IndicesDebutDeLigne[problem->NombreDeContraintes - 1] + + problem->NombreDeTermesDesLignes[problem->NombreDeContraintes - 1]; + + copy(problem->TypeDeVariable, ret.VariablesType); + + copy(problem->CoefficientsDeLaMatriceDesContraintes, + ret.ConstraintsMatrixCoeff); + copy(problem->IndicesColonnes, ret.ColumnIndexes); + + copy(problem->IndicesDebutDeLigne, ret.Mdeb); + return ret; +} + +WeeklyProblemTranslationException::WeeklyProblemTranslationException( + const std::string& string) noexcept +: std::runtime_error{string} +{ +} +} // namespace Antares::Solver \ No newline at end of file diff --git a/src/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.cpp b/src/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.cpp index 577cfa55b7..174d32564d 100644 --- a/src/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.cpp +++ b/src/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.cpp @@ -1,28 +1,29 @@ /* -** 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 . -*/ + * 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 . + */ #include "antares/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.h" #include "antares/solver/optimisation/opt_fonctions.h" #include "antares/solver/simulation/adequacy_patch_runtime_data.h" +#include "antares/solver/simulation/ISimulationObserver.h" #include "antares/study/fwd.h" using namespace Antares::Data::AdequacyPatch; @@ -35,16 +36,18 @@ AdequacyPatchOptimization::AdequacyPatchOptimization(const Antares::Data::Study& PROBLEME_HEBDO* problemeHebdo, AdqPatchParams& adqPatchParams, uint thread_number, - IResultWriter& writer): - WeeklyOptimization(options, problemeHebdo, adqPatchParams, thread_number, writer), + IResultWriter& writer, + Simulation::ISimulationObserver& observer): + WeeklyOptimization(options, problemeHebdo, adqPatchParams, thread_number, writer, observer), study_(study) { } void AdequacyPatchOptimization::solve() { + Simulation::NullSimulationObserver nullSimulationObserver; problemeHebdo_->adequacyPatchRuntimeData->AdequacyFirstStep = true; - OPT_OptimisationHebdomadaire(options_, problemeHebdo_, adqPatchParams_, writer_); + OPT_OptimisationHebdomadaire(options_, problemeHebdo_, adqPatchParams_, writer_, nullSimulationObserver); problemeHebdo_->adequacyPatchRuntimeData->AdequacyFirstStep = false; for (uint32_t pays = 0; pays < problemeHebdo_->NombreDePays; ++pays) @@ -61,7 +64,7 @@ void AdequacyPatchOptimization::solve() } } - OPT_OptimisationHebdomadaire(options_, problemeHebdo_, adqPatchParams_, writer_); + OPT_OptimisationHebdomadaire(options_, problemeHebdo_, adqPatchParams_, writer_, nullSimulationObserver); } } // namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/base_weekly_optimization.cpp b/src/solver/optimisation/base_weekly_optimization.cpp index d4da2a1167..80efece4b9 100644 --- a/src/solver/optimisation/base_weekly_optimization.cpp +++ b/src/solver/optimisation/base_weekly_optimization.cpp @@ -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 . -*/ + * 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 . + */ #include "antares/solver/optimisation/base_weekly_optimization.h" @@ -34,12 +34,15 @@ WeeklyOptimization::WeeklyOptimization(const OptimizationOptions& options, PROBLEME_HEBDO* problemesHebdo, AdqPatchParams& adqPatchParams, uint thread_number, - IResultWriter& writer): + IResultWriter& writer, + Simulation::ISimulationObserver& simulationObserver + ) : options_(options), problemeHebdo_(problemesHebdo), adqPatchParams_(adqPatchParams), thread_number_(thread_number), - writer_(writer) + writer_(writer), + simulationObserver_(simulationObserver) { } @@ -48,7 +51,9 @@ std::unique_ptr WeeklyOptimization::create(const Antares::Da AdqPatchParams& adqPatchParams, PROBLEME_HEBDO* problemeHebdo, uint thread_number, - IResultWriter& writer) + IResultWriter& writer, + Simulation::ISimulationObserver& simulationObserver + ) { if (adqPatchParams.enabled && adqPatchParams.localMatching.enabled) { @@ -57,7 +62,8 @@ std::unique_ptr WeeklyOptimization::create(const Antares::Da problemeHebdo, adqPatchParams, thread_number, - writer); + writer, + simulationObserver); } else { @@ -65,7 +71,8 @@ std::unique_ptr WeeklyOptimization::create(const Antares::Da problemeHebdo, adqPatchParams, thread_number, - writer); + writer, + simulationObserver); } } diff --git a/src/solver/optimisation/include/antares/solver/optimisation/HebdoProblemToLpsTranslator.h b/src/solver/optimisation/include/antares/solver/optimisation/HebdoProblemToLpsTranslator.h new file mode 100644 index 0000000000..7deb23a0ca --- /dev/null +++ b/src/solver/optimisation/include/antares/solver/optimisation/HebdoProblemToLpsTranslator.h @@ -0,0 +1,81 @@ + +/* + * 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 . + */ + +#pragma once + +#include "antares/solver/lps/LpsFromAntares.h" +#include "antares/solver/simulation/sim_structure_probleme_economique.h" + +namespace Antares::Solver +{ + +/** + * @class WeeklyProblemTranslationException + * @brief Exception class for errors during the translation of a weekly problem. + * + * This class is a custom exception class that is thrown when an error occurs during the translation + * of a weekly problem. + */ +class WeeklyProblemTranslationException: public std::runtime_error +{ +public: + explicit WeeklyProblemTranslationException(const std::string& string) noexcept; +}; + +/** + * @class HebdoProblemToLpsTranslator + * @brief Class for translating a weekly problem to a linear programming problem. + * + * This class is responsible for translating a weekly problem to a linear programming problem. + */ +class HebdoProblemToLpsTranslator +{ +public: + /** + * @brief Translates a weekly problem to a linear programming problem. + * + * This function takes a pointer to a PROBLEME_ANTARES_A_RESOUDRE object and a string_view + * representing the name of the problem. It translates the weekly problem to a linear + * programming problem and returns a WeeklyDataFromAntaresPtr to the translated problem. Datas + * from the PROBLEME_ANTARES_A_RESOUDRE are copied to the WeeklyDataFromAntaresPtr. + * + * @param problem A pointer to the weekly problem to be translated. + * @param name The name of the problem. + * @return WeeklyDataFromAntaresPtr A WeeklyDataFromAntaresPtr to the translated problem. + */ + [[nodiscard]] WeeklyDataFromAntares translate(const PROBLEME_ANTARES_A_RESOUDRE* problem, + std::string_view name) const; + + /** + * @brief Retrieves common problem data, the part common to every weekly problems + * + * This function takes a pointer to a PROBLEME_ANTARES_A_RESOUDRE object and retrieves the + * common problem data. It returns a ConstantDataFromAntaresPtr to the common problem data. + * + * @param problem A pointer to the problem from which to retrieve the common data. + * @return ConstantDataFromAntaresPtr A ConstantDataFromAntaresPtr to the common problem data. + */ + [[nodiscard]] ConstantDataFromAntares commonProblemData( + const PROBLEME_ANTARES_A_RESOUDRE* problem) const; +}; + +} // namespace Antares::Solver diff --git a/src/solver/optimisation/include/antares/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.h b/src/solver/optimisation/include/antares/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.h index 2585fc8053..b11bdc817a 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/adequacy_patch_local_matching/adequacy_patch_weekly_optimization.h @@ -37,9 +37,10 @@ class AdequacyPatchOptimization: public WeeklyOptimization explicit AdequacyPatchOptimization(const Antares::Data::Study& study, const OptimizationOptions& options, PROBLEME_HEBDO* problemeHebdo, - Antares::Data::AdequacyPatch::AdqPatchParams&, + Data::AdequacyPatch::AdqPatchParams&, uint numSpace, - IResultWriter& writer); + IResultWriter& writer, + Simulation::ISimulationObserver& observer); ~AdequacyPatchOptimization() override = default; void solve() override; diff --git a/src/solver/optimisation/include/antares/solver/optimisation/base_weekly_optimization.h b/src/solver/optimisation/include/antares/solver/optimisation/base_weekly_optimization.h index 7f4b755bb5..e25ffca086 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/base_weekly_optimization.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/base_weekly_optimization.h @@ -1,29 +1,30 @@ /* -** 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 . -*/ + * 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 . + */ #pragma once #include // for "uint" definition #include +#include "antares/solver/simulation/ISimulationObserver.h" #include "antares/solver/simulation/sim_structure_donnees.h" #include "antares/solver/simulation/sim_structure_probleme_economique.h" @@ -40,18 +41,23 @@ class WeeklyOptimization Antares::Data::AdequacyPatch::AdqPatchParams& adqPatchParams, PROBLEME_HEBDO* problemesHebdo, uint numSpace, - IResultWriter& writer); + IResultWriter& writer, + Simulation::ISimulationObserver& simulationObserver + ); protected: explicit WeeklyOptimization(const OptimizationOptions& options, PROBLEME_HEBDO* problemesHebdo, Antares::Data::AdequacyPatch::AdqPatchParams&, uint numSpace, - IResultWriter& writer); + IResultWriter& writer, + Simulation::ISimulationObserver& simulationObserver + ); Antares::Solver::Optimization::OptimizationOptions options_; PROBLEME_HEBDO* const problemeHebdo_ = nullptr; Antares::Data::AdequacyPatch::AdqPatchParams& adqPatchParams_; const uint thread_number_ = 0; IResultWriter& writer_; + std::reference_wrapper simulationObserver_; }; } // namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/include/antares/solver/optimisation/constraints/constraint_builder_utils.h b/src/solver/optimisation/include/antares/solver/optimisation/constraints/constraint_builder_utils.h index 9e4981700e..9e940aa200 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/constraints/constraint_builder_utils.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/constraints/constraint_builder_utils.h @@ -22,6 +22,7 @@ #include #include "ConstraintBuilder.h" +struct PROBLEME_HEBDO; ConstraintBuilderData NewGetConstraintBuilderFromProblemHebdoAndProblemAResoudre( PROBLEME_HEBDO* problemeHebdo, diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_export_structure.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_export_structure.h index 4d69d8711e..47aa3838e1 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_export_structure.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_export_structure.h @@ -1,50 +1,32 @@ /* -** 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 . -*/ -#ifndef __EXPORT_STRUCTURE__ -#define __EXPORT_STRUCTURE__ + * 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 . + */ +#pragma once -#include -#include #include -#include - -#include #include "antares/antares/Enum.hpp" #include "antares/writer/i_writer.h" - -namespace Antares -{ -namespace Data -{ - -class Study; -} // namespace Data -} // namespace Antares - struct PROBLEME_HEBDO; void OPT_ExportInterco(Antares::Solver::IResultWriter& writer, PROBLEME_HEBDO* problemeHebdo); void OPT_ExportAreaName(Antares::Solver::IResultWriter& writer, const std::vector& areaNames); void OPT_ExportStructures(PROBLEME_HEBDO* problemeHebdo, Antares::Solver::IResultWriter& writer); - -#endif diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h index 1a52f7e331..2150ea991a 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h @@ -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 . -*/ + * 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 . + */ #ifndef __SOLVER_OPTIMISATION_FUNCTIONS_H__ #define __SOLVER_OPTIMISATION_FUNCTIONS_H__ @@ -26,6 +26,7 @@ #include #include "antares/config/config.h" #include "antares/solver/optimisation/opt_structure_probleme_a_resoudre.h" +#include "antares/solver/simulation/ISimulationObserver.h" #include "antares/study/parameters/adq-patch-params.h" #include "adequacy_patch_csr/hourly_csr_problem.h" @@ -34,9 +35,10 @@ using AdqPatchParams = Antares::Data::AdequacyPatch::AdqPatchParams; using OptimizationOptions = Antares::Solver::Optimization::OptimizationOptions; void OPT_OptimisationHebdomadaire(const OptimizationOptions& options, - PROBLEME_HEBDO*, - const AdqPatchParams&, - Antares::Solver::IResultWriter& writer); + PROBLEME_HEBDO* pProblemeHebdo, + const AdqPatchParams& adqPatchParams, + Solver::IResultWriter& writer, + Solver::Simulation::ISimulationObserver& simulationObserver); void OPT_NumeroDeJourDuPasDeTemps(PROBLEME_HEBDO*); void OPT_NumeroDIntervalleOptimiseDuPasDeTemps(PROBLEME_HEBDO*); void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBDO*); @@ -65,9 +67,11 @@ bool ADQ_PATCH_CSR(PROBLEME_ANTARES_A_RESOUDRE&, int year); bool OPT_PilotageOptimisationLineaire(const OptimizationOptions& options, - PROBLEME_HEBDO*, - const AdqPatchParams&, - Antares::Solver::IResultWriter& writer); + PROBLEME_HEBDO* problemeHebdo, + const AdqPatchParams& adqPatchParams, + Solver::IResultWriter& writer, + Solver::Simulation::ISimulationObserver& simulationObserver + ); void OPT_VerifierPresenceReserveJmoins1(PROBLEME_HEBDO*); bool OPT_PilotageOptimisationQuadratique(PROBLEME_HEBDO*); @@ -85,9 +89,11 @@ bool OPT_AppelDuSimplexe(const OptimizationOptions& options, void OPT_LiberationProblemesSimplexe(const OptimizationOptions& options, const PROBLEME_HEBDO*); bool OPT_OptimisationLineaire(const OptimizationOptions& options, - PROBLEME_HEBDO*, - const AdqPatchParams&, - Antares::Solver::IResultWriter& writer); + PROBLEME_HEBDO* problemeHebdo, + const AdqPatchParams& adqPatchParams, + Solver::IResultWriter& writer, + Solver::Simulation::ISimulationObserver& simulationObserver + ); void OPT_RestaurerLesDonnees(PROBLEME_HEBDO*); /*------------------------------*/ diff --git a/src/solver/optimisation/include/antares/solver/optimisation/weekly_optimization.h b/src/solver/optimisation/include/antares/solver/optimisation/weekly_optimization.h index 1f9ae23137..d0f33adb39 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/weekly_optimization.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/weekly_optimization.h @@ -1,27 +1,29 @@ /* -** 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 . -*/ + * 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 . + */ #pragma once #include "antares/solver/simulation/sim_structure_probleme_economique.h" +#include "antares/solver/simulation/ISimulationObserver.h" + #include "base_weekly_optimization.h" @@ -34,7 +36,9 @@ class DefaultWeeklyOptimization: public WeeklyOptimization PROBLEME_HEBDO* problemeHebdo, Antares::Data::AdequacyPatch::AdqPatchParams&, uint numSpace, - IResultWriter& writer); + IResultWriter& writer, + Simulation::ISimulationObserver& simulationObserver + ); ~DefaultWeeklyOptimization() override = default; void solve() override; }; diff --git a/src/solver/optimisation/opt_optimisation_hebdo.cpp b/src/solver/optimisation/opt_optimisation_hebdo.cpp index 89c59ec57a..6883089378 100644 --- a/src/solver/optimisation/opt_optimisation_hebdo.cpp +++ b/src/solver/optimisation/opt_optimisation_hebdo.cpp @@ -1,29 +1,30 @@ /* -** 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 . -*/ + * 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 . + */ #include #include #include #include "antares/solver/optimisation/opt_fonctions.h" #include "antares/solver/optimisation/opt_structure_probleme_a_resoudre.h" +#include "antares/solver/simulation/ISimulationObserver.h" #include "antares/solver/simulation/sim_extern_variables_globales.h" extern "C" @@ -39,11 +40,13 @@ using Antares::Solver::Optimization::OptimizationOptions; void OPT_OptimisationHebdomadaire(const OptimizationOptions& options, PROBLEME_HEBDO* pProblemeHebdo, const AdqPatchParams& adqPatchParams, - Solver::IResultWriter& writer) + Solver::IResultWriter& writer, + Solver::Simulation::ISimulationObserver& simulationObserver) { if (pProblemeHebdo->TypeDOptimisation == OPTIMISATION_LINEAIRE) { - if (!OPT_PilotageOptimisationLineaire(options, pProblemeHebdo, adqPatchParams, writer)) + if (!OPT_PilotageOptimisationLineaire( + options, pProblemeHebdo, adqPatchParams, writer, simulationObserver)) { logs.error() << "Linear optimization failed"; throw UnfeasibleProblemError("Linear optimization failed"); diff --git a/src/solver/optimisation/opt_optimisation_lineaire.cpp b/src/solver/optimisation/opt_optimisation_lineaire.cpp index 67c475e396..d3635ff326 100644 --- a/src/solver/optimisation/opt_optimisation_lineaire.cpp +++ b/src/solver/optimisation/opt_optimisation_lineaire.cpp @@ -1,29 +1,32 @@ /* -** 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 . -*/ + * 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 . + */ #include +#include "antares/solver/lps/LpsFromAntares.h" +#include "antares/solver/optimisation/HebdoProblemToLpsTranslator.h" #include "antares/solver/optimisation/LinearProblemMatrix.h" #include "antares/solver/optimisation/constraints/constraint_builder_utils.h" #include "antares/solver/optimisation/opt_export_structure.h" #include "antares/solver/optimisation/opt_fonctions.h" +#include "antares/solver/simulation/ISimulationObserver.h" #include "antares/solver/simulation/sim_structure_probleme_economique.h" #include "antares/solver/utils/filename.h" using namespace Antares; @@ -61,11 +64,27 @@ void OPT_EcrireResultatFonctionObjectiveAuFormatTXT( writer.addEntryFromBuffer(filename, buffer); } +namespace +{ +void notifyProblemHebdo(const PROBLEME_HEBDO* problemeHebdo, + int optimizationNumber, + Solver::Simulation::ISimulationObserver& simulationObserver, + const OptPeriodStringGenerator* optPeriodStringGenerator) +{ + simulationObserver.notifyHebdoProblem(*problemeHebdo, + optimizationNumber, + createMPSfilename(*optPeriodStringGenerator, + optimizationNumber)); +} +} + bool runWeeklyOptimization(const OptimizationOptions& options, PROBLEME_HEBDO* problemeHebdo, const AdqPatchParams& adqPatchParams, Solver::IResultWriter& writer, - int optimizationNumber) + int optimizationNumber, + Solver::Simulation::ISimulationObserver& simulationObserver + ) { const int NombreDePasDeTempsPourUneOptimisation = problemeHebdo ->NombreDePasDeTempsPourUneOptimisation; @@ -102,6 +121,8 @@ bool runWeeklyOptimization(const OptimizationOptions& options, problemeHebdo->weekInTheYear, problemeHebdo->year); + notifyProblemHebdo(problemeHebdo, optimizationNumber, simulationObserver, optPeriodStringGenerator.get()); + if (!OPT_AppelDuSimplexe(options, problemeHebdo, numeroDeLIntervalle, @@ -142,7 +163,9 @@ void runThermalHeuristic(PROBLEME_HEBDO* problemeHebdo) bool OPT_OptimisationLineaire(const OptimizationOptions& options, PROBLEME_HEBDO* problemeHebdo, const AdqPatchParams& adqPatchParams, - Solver::IResultWriter& writer) + Solver::IResultWriter& writer, + Solver::Simulation::ISimulationObserver& simulationObserver + ) { if (!problemeHebdo->OptimisationAuPasHebdomadaire) { @@ -175,7 +198,8 @@ bool OPT_OptimisationLineaire(const OptimizationOptions& options, problemeHebdo, adqPatchParams, writer, - PREMIERE_OPTIMISATION); + PREMIERE_OPTIMISATION, + simulationObserver); // We only need the 2nd optimization when NOT solving with integer variables // We also skip the 2nd optimization in the hidden 'Expansion' mode @@ -188,7 +212,8 @@ bool OPT_OptimisationLineaire(const OptimizationOptions& options, problemeHebdo, adqPatchParams, writer, - DEUXIEME_OPTIMISATION); + DEUXIEME_OPTIMISATION, + simulationObserver); } return ret; } diff --git a/src/solver/optimisation/opt_pilotage_optimisation_lineaire.cpp b/src/solver/optimisation/opt_pilotage_optimisation_lineaire.cpp index 79ce32f0cb..2ca9c71d56 100644 --- a/src/solver/optimisation/opt_pilotage_optimisation_lineaire.cpp +++ b/src/solver/optimisation/opt_pilotage_optimisation_lineaire.cpp @@ -1,27 +1,28 @@ /* -** 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 . -*/ + * 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 . + */ #include "antares/optimization-options/options.h" #include "antares/solver/optimisation/opt_fonctions.h" #include "antares/solver/optimisation/opt_structure_probleme_a_resoudre.h" +#include "antares/solver/simulation/ISimulationObserver.h" #include "antares/solver/simulation/sim_extern_variables_globales.h" using Antares::Solver::Optimization::OptimizationOptions; @@ -29,7 +30,8 @@ using Antares::Solver::Optimization::OptimizationOptions; bool OPT_PilotageOptimisationLineaire(const OptimizationOptions& options, PROBLEME_HEBDO* problemeHebdo, const AdqPatchParams& adqPatchParams, - Solver::IResultWriter& writer) + Solver::IResultWriter& writer, + Solver::Simulation::ISimulationObserver& simulationObserver) { if (!problemeHebdo->LeProblemeADejaEteInstancie) { @@ -75,5 +77,5 @@ bool OPT_PilotageOptimisationLineaire(const OptimizationOptions& options, OPT_InitialiserNombreMinEtMaxDeGroupesCoutsDeDemarrage(problemeHebdo); } - return OPT_OptimisationLineaire(options, problemeHebdo, adqPatchParams, writer); + return OPT_OptimisationLineaire(options, problemeHebdo, adqPatchParams, writer, simulationObserver); } diff --git a/src/solver/optimisation/opt_rename_problem.cpp b/src/solver/optimisation/opt_rename_problem.cpp index 7a7553a59a..85edf581b8 100644 --- a/src/solver/optimisation/opt_rename_problem.cpp +++ b/src/solver/optimisation/opt_rename_problem.cpp @@ -21,6 +21,7 @@ #include "antares/solver/optimisation/opt_rename_problem.h" +#include #include const std::string HOUR("hour"); diff --git a/src/solver/optimisation/weekly_optimization.cpp b/src/solver/optimisation/weekly_optimization.cpp index 164cabf32f..cf943b2125 100644 --- a/src/solver/optimisation/weekly_optimization.cpp +++ b/src/solver/optimisation/weekly_optimization.cpp @@ -1,22 +1,22 @@ /* -** 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 . + * 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 . */ #include "antares/solver/optimisation/weekly_optimization.h" @@ -29,14 +29,15 @@ DefaultWeeklyOptimization::DefaultWeeklyOptimization(const OptimizationOptions& PROBLEME_HEBDO* problemeHebdo, AdqPatchParams& adqPatchParams, uint thread_number, - IResultWriter& writer): - WeeklyOptimization(options, problemeHebdo, adqPatchParams, thread_number, writer) + IResultWriter& writer, + Simulation::ISimulationObserver& simulationObserver) : + WeeklyOptimization(options, problemeHebdo, adqPatchParams, thread_number, writer, simulationObserver) { } void DefaultWeeklyOptimization::solve() { - OPT_OptimisationHebdomadaire(options_, problemeHebdo_, adqPatchParams_, writer_); + OPT_OptimisationHebdomadaire(options_, problemeHebdo_, adqPatchParams_, writer_, simulationObserver_.get()); } } // namespace Antares::Solver::Optimization diff --git a/src/solver/simulation/CMakeLists.txt b/src/solver/simulation/CMakeLists.txt index 0d2bc666eb..6a5355ea56 100644 --- a/src/solver/simulation/CMakeLists.txt +++ b/src/solver/simulation/CMakeLists.txt @@ -22,36 +22,37 @@ set(SRC_SIMULATION apply-scenario.cpp - # Solver - include/antares/solver/simulation/solver_utils.h - solver_utils.cpp - include/antares/solver/simulation/solver.h - include/antares/solver/simulation/solver.hxx - include/antares/solver/simulation/solver.data.h - solver.data.cpp - include/antares/solver/simulation/common-eco-adq.h - common-eco-adq.cpp - common-hydro-remix.cpp - common-hydro-levels.cpp - include/antares/solver/simulation/adequacy.h - adequacy.cpp - include/antares/solver/simulation/economy.h - economy.cpp - include/antares/solver/simulation/base_post_process.h - base_post_process.cpp - include/antares/solver/simulation/opt_time_writer.h - opt_time_writer.cpp - include/antares/solver/simulation/adequacy_patch_runtime_data.h - adequacy_patch_runtime_data.cpp - include/antares/solver/simulation/ITimeSeriesNumbersWriter.h + # Solver + include/antares/solver/simulation/solver_utils.h + solver_utils.cpp + include/antares/solver/simulation/solver.h + include/antares/solver/simulation/solver.hxx + include/antares/solver/simulation/solver.data.h + solver.data.cpp + include/antares/solver/simulation/common-eco-adq.h + common-eco-adq.cpp + common-hydro-remix.cpp + common-hydro-levels.cpp + include/antares/solver/simulation/adequacy.h + adequacy.cpp + include/antares/solver/simulation/economy.h + economy.cpp + include/antares/solver/simulation/base_post_process.h + base_post_process.cpp + include/antares/solver/simulation/opt_time_writer.h + opt_time_writer.cpp + include/antares/solver/simulation/adequacy_patch_runtime_data.h + adequacy_patch_runtime_data.cpp + include/antares/solver/simulation/ITimeSeriesNumbersWriter.h include/antares/solver/simulation/hydro-final-reservoir-level-functions.h hydro-final-reservoir-level-functions.cpp - TimeSeriesNumbersWriter.cpp + TimeSeriesNumbersWriter.cpp include/antares/solver/simulation/BindingConstraintsTimeSeriesNumbersWriter.h - economy_mode.cpp - adequacy_mode.cpp - include/antares/solver/simulation/economy_mode.h - include/antares/solver/simulation/adequacy_mode.h + include/antares/solver/simulation/ISimulationObserver.h + economy_mode.cpp + adequacy_mode.cpp + include/antares/solver/simulation/economy_mode.h + include/antares/solver/simulation/adequacy_mode.h ) source_group("simulation" FILES ${SRC_SIMULATION}) diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index c2ac21dbea..8ba97fde33 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -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 . -*/ + * 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 . + */ #include "antares/solver/simulation/adequacy.h" @@ -29,10 +29,10 @@ using Antares::Constants::nbHoursInAWeek; namespace Antares::Solver::Simulation { -Adequacy::Adequacy(Data::Study& study, IResultWriter& resultWriter): - study(study), - preproOnly(false), - resultWriter(resultWriter) +Adequacy::Adequacy(Data::Study& study, + IResultWriter& resultWriter, + Simulation::ISimulationObserver& simulationObserver) : + study(study), resultWriter(resultWriter), simulationObserver_(simulationObserver) { } @@ -207,7 +207,8 @@ bool Adequacy::year(Progression::Task& progression, OPT_OptimisationHebdomadaire(createOptimizationOptions(study), ¤tProblem, study.parameters.adqPatchParams, - resultWriter); + resultWriter, + simulationObserver_.get()); computingHydroLevels(study.areas, currentProblem, false); @@ -367,7 +368,7 @@ bool Adequacy::year(Progression::Task& progression, return true; } -void Adequacy::incrementProgression(Progression::Task& progression) +void Adequacy::incrementProgression(Progression::Task& progression) const { for (uint w = 0; w < pNbWeeks; ++w) { diff --git a/src/solver/simulation/adequacy_mode.cpp b/src/solver/simulation/adequacy_mode.cpp index 59048ddf7b..86435743ce 100644 --- a/src/solver/simulation/adequacy_mode.cpp +++ b/src/solver/simulation/adequacy_mode.cpp @@ -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 . - */ +* 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 . +*/ #include "antares/solver/simulation/adequacy_mode.h" @@ -27,23 +27,24 @@ namespace Antares::Solver { void runSimulationInAdequacyMode(Antares::Data::Study& study, - const Settings& settings, + const Settings& settings, Benchmarking::DurationCollector& durationCollector, - IResultWriter& resultWriter, - Benchmarking::OptimizationInfo& info) + IResultWriter& resultWriter, + Benchmarking::OptimizationInfo& info, + Simulation::ISimulationObserver& simulationObserver) { - // Type of the simulation - typedef Solver::Simulation::ISimulation SimulationType; - SimulationType simulation(study, settings, durationCollector, resultWriter); - simulation.checkWriter(); - simulation.run(); + // Type of the simulation + typedef Solver::Simulation::ISimulation SimulationType; + SimulationType simulation(study, settings, durationCollector, resultWriter, simulationObserver); + simulation.checkWriter(); + simulation.run(); - if (!(settings.noOutput || settings.tsGeneratorsOnly)) - { + if (!(settings.noOutput || settings.tsGeneratorsOnly)) + { durationCollector("synthesis_export") << [&simulation] { simulation.writeResults(/*synthesis:*/ true); }; - info = simulation.getOptimizationInfo(); - } + info = simulation.getOptimizationInfo(); + } } } // namespace Antares::Solver diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index bc63e19708..4917e76f09 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -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 . -*/ + * 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 . + */ #include "antares/solver/simulation/common-eco-adq.h" @@ -91,10 +91,12 @@ static void RecalculDesEchangesMoyens(Data::Study& study, try { NullResultWriter resultWriter; + NullSimulationObserver simulationObserver; OPT_OptimisationHebdomadaire(createOptimizationOptions(study), &problem, study.parameters.adqPatchParams, - resultWriter); + resultWriter, + simulationObserver); } catch (Data::UnfeasibleProblemError&) { diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index 4baef3d5b4..1fa0b63625 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -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 . -*/ + * 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 . + */ #include "antares/solver/simulation/economy.h" @@ -33,10 +33,13 @@ using Antares::Constants::nbHoursInAWeek; namespace Antares::Solver::Simulation { -Economy::Economy(Data::Study& study, IResultWriter& resultWriter): +Economy::Economy(Data::Study& study, + IResultWriter& resultWriter, + Simulation::ISimulationObserver& simulationObserver) : study(study), preproOnly(false), - resultWriter(resultWriter) + resultWriter(resultWriter), + simulationObserver_(simulationObserver) { } @@ -82,7 +85,8 @@ bool Economy::simulationBegin() study.parameters.adqPatchParams, &pProblemesHebdo[numSpace], numSpace, - resultWriter); + resultWriter, + simulationObserver_.get()); postProcessesList_[numSpace] = interfacePostProcessList::create( study.parameters.adqPatchParams, &pProblemesHebdo[numSpace], diff --git a/src/solver/simulation/economy_mode.cpp b/src/solver/simulation/economy_mode.cpp index e79d7a1363..816eb1a212 100644 --- a/src/solver/simulation/economy_mode.cpp +++ b/src/solver/simulation/economy_mode.cpp @@ -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 . - */ +* 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 . +*/ #include "antares/solver/simulation/economy_mode.h" @@ -27,23 +27,25 @@ namespace Antares::Solver { void runSimulationInEconomicMode(Antares::Data::Study& study, - const Settings& settings, + const Settings& settings, Benchmarking::DurationCollector& durationCollector, - IResultWriter& resultWriter, - Benchmarking::OptimizationInfo& info) + IResultWriter& resultWriter, + Benchmarking::OptimizationInfo& info, + Simulation::ISimulationObserver& simulationObserver +) { - // Type of the simulation - typedef Solver::Simulation::ISimulation SimulationType; - SimulationType simulation(study, settings, durationCollector, resultWriter); - simulation.checkWriter(); - simulation.run(); + // Type of the simulation + typedef Solver::Simulation::ISimulation SimulationType; + SimulationType simulation(study, settings, durationCollector, resultWriter, simulationObserver); + simulation.checkWriter(); + simulation.run(); - if (!(settings.noOutput || settings.tsGeneratorsOnly)) - { + if (!(settings.noOutput || settings.tsGeneratorsOnly)) + { durationCollector("synthesis_export") << [&simulation] { simulation.writeResults(/*synthesis:*/ true); }; - info = simulation.getOptimizationInfo(); - } + info = simulation.getOptimizationInfo(); + } } } // namespace Antares::Solver diff --git a/src/solver/simulation/include/antares/solver/simulation/ISimulationObserver.h b/src/solver/simulation/include/antares/solver/simulation/ISimulationObserver.h new file mode 100644 index 0000000000..414695a580 --- /dev/null +++ b/src/solver/simulation/include/antares/solver/simulation/ISimulationObserver.h @@ -0,0 +1,65 @@ + +/* + * 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 . + */ + +#pragma once + +#include "sim_structure_probleme_economique.h" + +namespace Antares::Solver::Simulation +{ + +/** + * @class ISimulationObserver + * @brief The ISimulationObserver class is an interface for observing the simulation. + * @details It declares the notifyHebdoProblem method. + */ +class ISimulationObserver +{ +public: + virtual ~ISimulationObserver() = default; + /** + * @brief The notifyHebdoProblem method is used to notify of a problem during the simulation. + * @param problemeHebdo A pointer to a PROBLEME_HEBDO object representing the problem. + * @param optimizationNumber The number of the optimization. + * @param name The name of the problem. + */ + virtual void notifyHebdoProblem(const PROBLEME_HEBDO& problemeHebdo, + int optimizationNumber, + std::string_view name) + = 0; +}; + +/** + * @class NullSimulationObserver + * @brief The NullSimulationObserver class is a null object for the ISimulationObserver interface. + * @details It overrides the notifyHebdoProblem method with an empty implementation. + */ +class NullSimulationObserver : public ISimulationObserver +{ +public: + ~NullSimulationObserver() override = default; + void notifyHebdoProblem(const PROBLEME_HEBDO&, int, std::string_view) override + { + //null object pattern + } +}; +} // namespace Antares::Solver::Simulation \ No newline at end of file diff --git a/src/solver/simulation/include/antares/solver/simulation/adequacy.h b/src/solver/simulation/include/antares/solver/simulation/adequacy.h index 6d659103c3..130f3c18f5 100644 --- a/src/solver/simulation/include/antares/solver/simulation/adequacy.h +++ b/src/solver/simulation/include/antares/solver/simulation/adequacy.h @@ -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 . -*/ + * 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 . + */ #ifndef __SOLVER_SIMULATION_ADEQUACY_H__ #define __SOLVER_SIMULATION_ADEQUACY_H__ @@ -41,7 +41,6 @@ class Adequacy return "adequacy"; } -public: //! \name Constructor & Destructor //@{ /*! @@ -49,20 +48,20 @@ class Adequacy ** ** \param study The current study */ - Adequacy(Data::Study& study, IResultWriter& resultWriter); + Adequacy(Data::Study& study, IResultWriter& resultWriter, + Simulation::ISimulationObserver& simulationObserver); //! Destructor ~Adequacy() = default; //@} Benchmarking::OptimizationInfo getOptimizationInfo() const; -public: //! Current study Data::Study& study; //! All variables Solver::Variable::Adequacy::AllVariables variables; //! Prepro only - bool preproOnly; + bool preproOnly = false; protected: void setNbPerformedYearsInParallel(uint nbMaxPerformedYearsInParallel); @@ -79,7 +78,7 @@ class Adequacy OptimizationStatisticsWriter& optWriter, const Antares::Data::Area::ScratchMap& scratchmap); - void incrementProgression(Progression::Task& progression); + void incrementProgression(Progression::Task& progression) const; void simulationEnd(); @@ -102,6 +101,7 @@ class Adequacy Matrix<> pRES; IResultWriter& resultWriter; + std::reference_wrapper simulationObserver_; }; // class Adequacy } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/include/antares/solver/simulation/adequacy_mode.h b/src/solver/simulation/include/antares/solver/simulation/adequacy_mode.h index 260ba2c92f..66734027b9 100644 --- a/src/solver/simulation/include/antares/solver/simulation/adequacy_mode.h +++ b/src/solver/simulation/include/antares/solver/simulation/adequacy_mode.h @@ -24,6 +24,7 @@ #include "antares/infoCollection/StudyInfoCollector.h" #include "antares/solver/misc/options.h" +#include "antares/solver/simulation/ISimulationObserver.h" #include "antares/writer/i_writer.h" namespace Antares::Solver @@ -32,5 +33,6 @@ void runSimulationInAdequacyMode(Antares::Data::Study& study, const Settings& settings, Benchmarking::DurationCollector& durationCollector, IResultWriter& resultWriter, - Benchmarking::OptimizationInfo& info); + Benchmarking::OptimizationInfo& info, + Simulation::ISimulationObserver& simulationObserver); } diff --git a/src/solver/simulation/include/antares/solver/simulation/economy.h b/src/solver/simulation/include/antares/solver/simulation/economy.h index b7661c3f11..592fac59f8 100644 --- a/src/solver/simulation/include/antares/solver/simulation/economy.h +++ b/src/solver/simulation/include/antares/solver/simulation/economy.h @@ -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 . -*/ + * 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 . + */ #ifndef __SOLVER_SIMULATION_ECONOMY_H__ #define __SOLVER_SIMULATION_ECONOMY_H__ @@ -50,7 +50,9 @@ class Economy ** ** \param study The current study */ - Economy(Data::Study& study, IResultWriter& resultWriter); + Economy(Data::Study& study, + IResultWriter& resultWriter, + Simulation::ISimulationObserver& simulationObserver); //! Destructor ~Economy() = default; //@} @@ -100,6 +102,7 @@ class Economy weeklyOptProblems_; std::vector> postProcessesList_; IResultWriter& resultWriter; + std::reference_wrapper simulationObserver_; }; // class Economy } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/include/antares/solver/simulation/economy_mode.h b/src/solver/simulation/include/antares/solver/simulation/economy_mode.h index 5e1f454884..7437d39cf1 100644 --- a/src/solver/simulation/include/antares/solver/simulation/economy_mode.h +++ b/src/solver/simulation/include/antares/solver/simulation/economy_mode.h @@ -24,6 +24,7 @@ #include "antares/infoCollection/StudyInfoCollector.h" #include "antares/solver/misc/options.h" +#include "antares/solver/simulation/ISimulationObserver.h" #include "antares/writer/i_writer.h" namespace Antares::Solver @@ -32,5 +33,7 @@ void runSimulationInEconomicMode(Antares::Data::Study& study, const Settings& settings, Benchmarking::DurationCollector& durationCollector, IResultWriter& resultWriter, - Benchmarking::OptimizationInfo& info); + Benchmarking::OptimizationInfo& info, + Simulation::ISimulationObserver& simulationObserver +); } diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.h b/src/solver/simulation/include/antares/solver/simulation/solver.h index fe16b660b9..cd2abfa366 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.h +++ b/src/solver/simulation/include/antares/solver/simulation/solver.h @@ -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 . -*/ + * 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 . + */ #ifndef __SOLVER_SIMULATION_SOLVER_H__ #define __SOLVER_SIMULATION_SOLVER_H__ @@ -26,6 +26,7 @@ #include #include +#include #include #include #include "antares/solver/hydro/management/management.h" @@ -54,7 +55,8 @@ class ISimulation: public Impl ISimulation(Data::Study& study, const ::Settings& settings, Benchmarking::DurationCollector& duration_collector, - IResultWriter& resultWriter); + IResultWriter& resultWriter, + Simulation::ISimulationObserver& simulationObserver); //! Destructor ~ISimulation(); //@} @@ -76,7 +78,6 @@ class ISimulation: public Impl */ void writeResults(bool synthesis, uint year = 0, uint numSpace = 9999); -public: //! Reference to the current study Data::Study& study; //! The global settings @@ -136,7 +137,6 @@ class ISimulation: public Impl */ void loopThroughYears(uint firstYear, uint endYear, std::vector& state); -private: //! Some temporary to avoid performing useless complex checks Solver::Private::Simulation::CacheData pData; //! @@ -160,6 +160,7 @@ class ISimulation: public Impl //! Result writer Antares::Solver::IResultWriter& pResultWriter; + std::reference_wrapper simulationObserver_; }; // class ISimulation } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index 232fa520fc..57dff06fd9 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -31,8 +31,8 @@ #include #include #include "antares/concurrency/concurrency.h" -#include "antares/solver//variable/constants.h" -#include "antares/solver//variable/print.h" +#include "antares/solver/variable/constants.h" +#include "antares/solver/variable/print.h" #include "antares/solver/hydro/management/management.h" // Added for use of randomReservoirLevel(...) #include "antares/solver/simulation/apply-scenario.h" #include "antares/solver/simulation/opt_time_writer.h" @@ -61,7 +61,8 @@ public: Variable::State& pState, bool pYearByYear, Benchmarking::DurationCollector& durationCollector, - IResultWriter& resultWriter): + IResultWriter& resultWriter, + ISimulationObserver& simulationObserver): simulation_(simulation), y(pY), yearFailed(pYearFailed), @@ -75,6 +76,7 @@ public: yearByYear(pYearByYear), pDurationCollector(durationCollector), pResultWriter(resultWriter), + simulationObserver_(simulationObserver), hydroManagement(study.areas, study.parameters, study.calendar, @@ -101,6 +103,7 @@ private: bool yearByYear; Benchmarking::DurationCollector& pDurationCollector; IResultWriter& pResultWriter; + std::reference_wrapper simulationObserver_; HydroManagement hydroManagement; Antares::Data::Area::ScratchMap scratchmap; @@ -235,8 +238,9 @@ inline ISimulation::ISimulation( Data::Study& study, const ::Settings& settings, Benchmarking::DurationCollector& duration_collector, - IResultWriter& resultWriter): - ImplementationType(study, resultWriter), + IResultWriter& resultWriter, + Simulation::ISimulationObserver& simulationObserver): + ImplementationType(study, resultWriter, simulationObserver), study(study), settings(settings), pNbYearsReallyPerformed(0), @@ -245,7 +249,8 @@ inline ISimulation::ISimulation( pFirstSetParallelWithAPerformedYearWasRun(false), pDurationCollector(duration_collector), pQueueService(study.pQueueService), - pResultWriter(resultWriter) + pResultWriter(resultWriter), + simulationObserver_(simulationObserver) { // Ask to the interface to show the messages logs.info(); @@ -300,9 +305,6 @@ void ISimulation::run() // Determine if we have to use the preprocessors at least one time. pData.initialize(study.parameters); - // Prepro only ? - ImplementationType::preproOnly = settings.tsGeneratorsOnly; - ImplementationType::setNbPerformedYearsInParallel(pNbMaxPerformedYearsInParallel); TSGenerator::ResizeGeneratedTimeSeries(study.areas, study.parameters); @@ -1042,7 +1044,8 @@ void ISimulation::loopThroughYears(uint firstYear, state[numSpace], pYearByYear, pDurationCollector, - pResultWriter); + pResultWriter, + simulationObserver_.get()); results.add(Concurrency::AddTask(*pQueueService, task)); } // End loop over years of the current set of parallel years diff --git a/src/solver/utils/include/antares/solver/utils/name_translator.h b/src/solver/utils/include/antares/solver/utils/name_translator.h index e7a54b3614..5612e30c76 100644 --- a/src/solver/utils/include/antares/solver/utils/name_translator.h +++ b/src/solver/utils/include/antares/solver/utils/name_translator.h @@ -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 . -*/ + * 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 . + */ #pragma once #include diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index a771c25503..fcbc5cd6b2 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -34,6 +34,7 @@ if (${RECENT_BOOST}) add_subdirectory(end-to-end) add_subdirectory(src) add_subdirectory(kirchhoff-cbuilder) + add_subdirectory(inmemory-study) else() message(STATUS "Boost >= 1.60.0 is required for end-to-end tests, found ${Boost_VERSION}. Skipping") endif() diff --git a/src/tests/end-to-end/CMakeLists.txt b/src/tests/end-to-end/CMakeLists.txt index 9830013131..6c2031e372 100644 --- a/src/tests/end-to-end/CMakeLists.txt +++ b/src/tests/end-to-end/CMakeLists.txt @@ -1,3 +1,2 @@ -add_subdirectory(utils) add_subdirectory(simple_study) add_subdirectory(binding_constraints) \ No newline at end of file diff --git a/src/tests/end-to-end/binding_constraints/CMakeLists.txt b/src/tests/end-to-end/binding_constraints/CMakeLists.txt index 1b7cf52e86..72e2e46f62 100644 --- a/src/tests/end-to-end/binding_constraints/CMakeLists.txt +++ b/src/tests/end-to-end/binding_constraints/CMakeLists.txt @@ -12,18 +12,17 @@ add_executable(tests-binding_constraints target_link_libraries(tests-binding_constraints PRIVATE - test_utils Boost::unit_test_framework model_antares antares-solver-simulation antares-solver-hydro antares-solver-ts-generator + Antares::tests::in-memory-study ) target_include_directories(tests-binding_constraints PRIVATE ${CMAKE_SOURCE_DIR}/solver - ${CMAKE_CURRENT_SOURCE_DIR}/../utils ) add_test(NAME end-to-end-binding_constraints COMMAND tests-binding_constraints) diff --git a/src/tests/end-to-end/binding_constraints/test_binding_constraints.cpp b/src/tests/end-to-end/binding_constraints/test_binding_constraints.cpp index c1b875378f..10f91f2a40 100644 --- a/src/tests/end-to-end/binding_constraints/test_binding_constraints.cpp +++ b/src/tests/end-to-end/binding_constraints/test_binding_constraints.cpp @@ -23,7 +23,7 @@ #include #include -#include "utils.h" +#include "in-memory-study.h" namespace utf = boost::unit_test; namespace tt = boost::test_tools; diff --git a/src/tests/end-to-end/simple_study/CMakeLists.txt b/src/tests/end-to-end/simple_study/CMakeLists.txt index 670cb16187..cc5c93b410 100644 --- a/src/tests/end-to-end/simple_study/CMakeLists.txt +++ b/src/tests/end-to-end/simple_study/CMakeLists.txt @@ -12,19 +12,18 @@ add_executable(tests-simple-study target_link_libraries(tests-simple-study PRIVATE - test_utils antares-solver-hydro antares-solver-variable antares-solver-simulation antares-solver-ts-generator model_antares ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} + Antares::tests::in-memory-study ) target_include_directories(tests-simple-study PRIVATE ${CMAKE_SOURCE_DIR}/solver - ${CMAKE_CURRENT_SOURCE_DIR}/../utils ) add_test(NAME end-to-end-simple-study COMMAND tests-simple-study) diff --git a/src/tests/end-to-end/simple_study/simple-study.cpp b/src/tests/end-to-end/simple_study/simple-study.cpp index bfad50326f..7992165af2 100644 --- a/src/tests/end-to-end/simple_study/simple-study.cpp +++ b/src/tests/end-to-end/simple_study/simple-study.cpp @@ -22,7 +22,7 @@ #include #include -#include "utils.h" +#include "in-memory-study.h" namespace utf = boost::unit_test; namespace tt = boost::test_tools; diff --git a/src/tests/end-to-end/utils/CMakeLists.txt b/src/tests/end-to-end/utils/CMakeLists.txt deleted file mode 100644 index 166e083bc0..0000000000 --- a/src/tests/end-to-end/utils/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -add_library(test_utils - utils.cpp - utils.h - ) - -target_link_libraries(test_utils - PUBLIC - ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} - Antares::infoCollection - antares-solver-simulation - ) - -target_include_directories(test_utils - PRIVATE - ${CMAKE_SOURCE_DIR}/solver - ) - -set_target_properties(test_utils PROPERTIES FOLDER Unit-tests/end_to_end) - -target_include_directories(test_utils PUBLIC ${Boost_INCLUDE_DIRS}) diff --git a/src/tests/inmemory-study/CMakeLists.txt b/src/tests/inmemory-study/CMakeLists.txt new file mode 100644 index 0000000000..36c757f717 --- /dev/null +++ b/src/tests/inmemory-study/CMakeLists.txt @@ -0,0 +1,25 @@ +add_library(in-memory-study) +add_library(Antares::tests::in-memory-study ALIAS in-memory-study) + +target_sources(in-memory-study + PRIVATE + in-memory-study.cpp + include/in-memory-study.h +) + +target_link_libraries(in-memory-study + PUBLIC + ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} + antares-solver-simulation + PRIVATE + Antares::infoCollection +) + +target_include_directories(in-memory-study + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include +) + +set_target_properties(in-memory-study PROPERTIES FOLDER Unit-tests) + +target_include_directories(in-memory-study PUBLIC ${Boost_INCLUDE_DIRS}) diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/inmemory-study/in-memory-study.cpp similarity index 88% rename from src/tests/end-to-end/utils/utils.cpp rename to src/tests/inmemory-study/in-memory-study.cpp index a42891ea45..77b984fb45 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/inmemory-study/in-memory-study.cpp @@ -1,27 +1,28 @@ /* -** 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 . -*/ + * 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 . + */ #define WIN32_LEAN_AND_MEAN -#include "utils.h" +#include "in-memory-study.h" -void initializeStudy(Study::Ptr study) + +void initializeStudy(Study* study) { study->parameters.reset(); } @@ -187,11 +188,11 @@ void SimulationHandler::create() { study_.initializeRuntimeInfos(); addScratchpadToEachArea(study_); - simulation_ = std::make_shared>(study_, settings_, durationCollector_, - resultWriter_); + resultWriter_, + observer_); SIM_AllocationTableaux(study_); } @@ -203,10 +204,10 @@ StudyBuilder::StudyBuilder() // Make logs shrink to errors (and higher) only logs.verbosityLevel = Logs::Verbosity::Error::level; - study = std::make_shared(); + study = std::make_unique(true); simulation = std::make_shared(*study); - initializeStudy(study); + initializeStudy(study.get()); } void StudyBuilder::simulationBetweenDays(const unsigned int firstDay, const unsigned int lastDay) diff --git a/src/tests/end-to-end/utils/utils.h b/src/tests/inmemory-study/include/in-memory-study.h similarity index 86% rename from src/tests/end-to-end/utils/utils.h rename to src/tests/inmemory-study/include/in-memory-study.h index 1fa55efbff..101b6b47ab 100644 --- a/src/tests/end-to-end/utils/utils.h +++ b/src/tests/inmemory-study/include/in-memory-study.h @@ -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 . -*/ + * 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 . + */ #pragma once #define WIN32_LEAN_AND_MEAN #include "antares/solver/simulation/economy.h" @@ -30,7 +30,7 @@ using namespace Antares::Solver; using namespace Antares::Solver::Simulation; using namespace Antares::Data::ScenarioBuilder; -void initializeStudy(Study::Ptr study); +void initializeStudy(Study* study); void configureLinkCapacities(AreaLink* link); class TimeSeriesConfigurer @@ -207,6 +207,7 @@ class SimulationHandler Settings settings_; Study& study_; NullResultWriter resultWriter_; + NullSimulationObserver observer_; }; // ========================= @@ -224,7 +225,7 @@ struct StudyBuilder void giveWeightToYear(float weight, unsigned int year); // Data members - std::shared_ptr study; + std::unique_ptr study; std::shared_ptr simulation; }; diff --git a/src/tests/src/CMakeLists.txt b/src/tests/src/CMakeLists.txt index f6275f8386..14c9929f56 100644 --- a/src/tests/src/CMakeLists.txt +++ b/src/tests/src/CMakeLists.txt @@ -1,3 +1,5 @@ +add_subdirectory(api_internal) +add_subdirectory(api_lib) add_subdirectory(utils) add_subdirectory(libs) diff --git a/src/tests/src/api_internal/CMakeLists.txt b/src/tests/src/api_internal/CMakeLists.txt new file mode 100644 index 0000000000..2186dc6f4b --- /dev/null +++ b/src/tests/src/api_internal/CMakeLists.txt @@ -0,0 +1,27 @@ +set(EXECUTABLE_NAME test-api) +add_executable(${EXECUTABLE_NAME}) + +target_sources(${EXECUTABLE_NAME} + PRIVATE + test_api.cpp +) + +target_link_libraries(${EXECUTABLE_NAME} + PRIVATE + Boost::unit_test_framework + Antares::solver_api + Antares::tests::in-memory-study +) + +target_include_directories(${EXECUTABLE_NAME} + PRIVATE + #Allow to use the private headers + $ +) + +# Storing tests-ts-numbers under the folder Unit-tests in the IDE +set_target_properties(${EXECUTABLE_NAME} PROPERTIES FOLDER Unit-tests) + +add_test(NAME test-api COMMAND ${EXECUTABLE_NAME}) + +set_property(TEST test-api PROPERTY LABELS unit) diff --git a/src/tests/src/api_internal/test_api.cpp b/src/tests/src/api_internal/test_api.cpp new file mode 100644 index 0000000000..d60f6315d5 --- /dev/null +++ b/src/tests/src/api_internal/test_api.cpp @@ -0,0 +1,96 @@ +/* + * 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 . + */ + +#define BOOST_TEST_MODULE test_api +#define WIN32_LEAN_AND_MEAN + +#include + +#include + +#include "API.h" +#include "in-memory-study.h" + +class InMemoryStudyLoader: public Antares::IStudyLoader +{ +public: + explicit InMemoryStudyLoader(bool success = true): + success_(success){}; + + [[nodiscard]] std::unique_ptr load() const override + { + if (!success_) + { + return nullptr; + } + StudyBuilder builder; + builder.addAreaToStudy("area1"); + builder.addAreaToStudy("area2"); + builder.setNumberMCyears(1); + builder.study->initializeRuntimeInfos(); + builder.study->parameters.resultFormat = ResultFormat::inMemory; + builder.study->prepareOutput(); + return std::move(builder.study); + } + + bool success_ = true; +}; + +BOOST_AUTO_TEST_CASE(simulation_path_points_to_results) +{ + Antares::API::APIInternal api; + auto study_loader = std::make_unique(); + auto results = api.run(*study_loader.get()); + BOOST_CHECK_EQUAL(results.simulationPath, std::filesystem::path{"no_output"}); + // Testing for "no_output" is a bit weird, but it's the only way to test this without actually + // running the simulation +} + +BOOST_AUTO_TEST_CASE(api_run_contains_antares_problem) +{ + Antares::API::APIInternal api; + auto study_loader = std::make_unique(); + auto results = api.run(*study_loader.get()); + + BOOST_CHECK(!results.antares_problems.empty()); + BOOST_CHECK(!results.error); +} + +BOOST_AUTO_TEST_CASE(result_failure_when_study_is_null) +{ + Antares::API::APIInternal api; + auto study_loader = std::make_unique(false); + auto results = api.run(*study_loader.get()); + + BOOST_CHECK(results.error); +} + +// Test where data in problems are consistant with data in study +BOOST_AUTO_TEST_CASE(result_contains_problems) +{ + Antares::API::APIInternal api; + auto study_loader = std::make_unique(); + auto results = api.run(*study_loader.get()); + + BOOST_CHECK(!results.antares_problems.empty()); + BOOST_CHECK(!results.error); + BOOST_CHECK_EQUAL(results.antares_problems.weeklyProblems.size(), 52); +} diff --git a/src/tests/src/api_lib/CMakeLists.txt b/src/tests/src/api_lib/CMakeLists.txt new file mode 100644 index 0000000000..b5ce633955 --- /dev/null +++ b/src/tests/src/api_lib/CMakeLists.txt @@ -0,0 +1,20 @@ +set(EXECUTABLE_NAME test-client-api) +add_executable(${EXECUTABLE_NAME}) + +target_sources(${EXECUTABLE_NAME} + PRIVATE + test_api.cpp +) + +target_link_libraries(${EXECUTABLE_NAME} + PRIVATE + Boost::unit_test_framework + Antares::solver_api +) + +# Storing tests-ts-numbers under the folder Unit-tests in the IDE +set_target_properties(${EXECUTABLE_NAME} PROPERTIES FOLDER Unit-tests) + +add_test(NAME test-client-api COMMAND ${EXECUTABLE_NAME}) + +set_property(TEST test-client-api PROPERTY LABELS unit) diff --git a/src/tests/src/api_lib/test_api.cpp b/src/tests/src/api_lib/test_api.cpp new file mode 100644 index 0000000000..0dbddfae7f --- /dev/null +++ b/src/tests/src/api_lib/test_api.cpp @@ -0,0 +1,35 @@ +/* + * 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 . + */ + +#define BOOST_TEST_MODULE test_api +#define WIN32_LEAN_AND_MEAN + +#include + +#include "antares/api/solver.h" + +BOOST_AUTO_TEST_CASE(result_failure_when_study_path_invalid) +{ + using namespace std::string_literals; + auto results = Antares::API::PerformSimulation("dummy"s); + BOOST_CHECK(results.error); + BOOST_CHECK(!results.error->reason.empty()); +} diff --git a/src/tests/src/libs/CMakeLists.txt b/src/tests/src/libs/CMakeLists.txt index b97a7df1bc..81b6173280 100644 --- a/src/tests/src/libs/CMakeLists.txt +++ b/src/tests/src/libs/CMakeLists.txt @@ -1,2 +1,2 @@ -add_subdirectory(antares) \ No newline at end of file +add_subdirectory(antares) diff --git a/src/tests/src/solver/CMakeLists.txt b/src/tests/src/solver/CMakeLists.txt index 690cf4fa68..e301a13a77 100644 --- a/src/tests/src/solver/CMakeLists.txt +++ b/src/tests/src/solver/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(simulation) add_subdirectory(optimisation) add_subdirectory(utils) add_subdirectory(infeasible-problem-analysis) +add_subdirectory(lps) diff --git a/src/tests/src/solver/infeasible-problem-analysis/test-unfeasible-problem-analyzer.cpp b/src/tests/src/solver/infeasible-problem-analysis/test-unfeasible-problem-analyzer.cpp index d333f5104c..5f10a75879 100644 --- a/src/tests/src/solver/infeasible-problem-analysis/test-unfeasible-problem-analyzer.cpp +++ b/src/tests/src/solver/infeasible-problem-analysis/test-unfeasible-problem-analyzer.cpp @@ -24,16 +24,15 @@ #include #include #include +#include #include "antares/solver/infeasible-problem-analysis/constraint-slack-analysis.h" #include "antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h" #include "antares/solver/infeasible-problem-analysis/variables-bounds-consistency.h" -#include "ortools/linear_solver/linear_solver.h" - namespace bdata = boost::unit_test::data; -using operations_research::MPSolver; +using namespace operations_research; using Antares::Optimization::ConstraintSlackAnalysis; using Antares::Optimization::UnfeasibilityAnalysis; diff --git a/src/tests/src/solver/lps/CMakeLists.txt b/src/tests/src/solver/lps/CMakeLists.txt new file mode 100644 index 0000000000..89121152ba --- /dev/null +++ b/src/tests/src/solver/lps/CMakeLists.txt @@ -0,0 +1,20 @@ +set(EXECUTABLE_NAME test-lps) +add_executable(${EXECUTABLE_NAME}) + +target_sources(${EXECUTABLE_NAME} + PRIVATE + test_lps.cpp +) + +target_link_libraries(${EXECUTABLE_NAME} + PRIVATE + Boost::unit_test_framework + antares-solver-simulation +) + +# Storing tests-ts-numbers under the folder Unit-tests in the IDE +set_target_properties(${EXECUTABLE_NAME} PROPERTIES FOLDER Unit-tests) + +add_test(NAME test-lps COMMAND ${EXECUTABLE_NAME}) + +set_property(TEST test-lps PROPERTY LABELS unit) diff --git a/src/tests/src/solver/lps/test_lps.cpp b/src/tests/src/solver/lps/test_lps.cpp new file mode 100644 index 0000000000..3a0bf4aa34 --- /dev/null +++ b/src/tests/src/solver/lps/test_lps.cpp @@ -0,0 +1,77 @@ +/* + * 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 . + */ + +#define BOOST_TEST_MODULE test_translator +#define WIN32_LEAN_AND_MEAN + +#include + +#include + +using namespace Antares::Solver; + +BOOST_AUTO_TEST_CASE(new_lps_is_empty) +{ + LpsFromAntares lps; + BOOST_CHECK(lps.empty()); +} + +BOOST_AUTO_TEST_CASE(lps_with_only_constant_data_is_empty) +{ + LpsFromAntares lps; + lps.setConstantData(ConstantDataFromAntares()); + BOOST_CHECK(lps.empty()); +} + +BOOST_AUTO_TEST_CASE(lps_with_no_variabled_is_empty) +{ + LpsFromAntares lps; + lps.constantProblemData.VariablesCount = 0; + lps.addWeeklyData({0, 0}, WeeklyDataFromAntares()); + BOOST_CHECK(lps.empty()); +} + +BOOST_AUTO_TEST_CASE(lps_with_both_constant_and_weekly_data_is_not_empty) +{ + LpsFromAntares lps; + lps.constantProblemData.VariablesCount = 65; + lps.addWeeklyData({0, 0}, WeeklyDataFromAntares()); + BOOST_CHECK(!lps.empty()); +} + +BOOST_AUTO_TEST_CASE(replace_const_data) +{ + LpsFromAntares lps; + ConstantDataFromAntares var; + var.VariablesCount = 42; + lps.setConstantData(var); + BOOST_CHECK(lps.constantProblemData.VariablesCount == 42); +} + +// Add weekly data for week 1 year 1 +BOOST_AUTO_TEST_CASE(add_weekly_data_for_week_1_year_1) +{ + LpsFromAntares lps; + WeeklyDataFromAntares w; + w.RHS.push_back(43); + lps.addWeeklyData({1, 1}, w); + BOOST_CHECK(lps.weeklyData({1, 1}).RHS.size() != WeeklyDataFromAntares().RHS.size()); +} diff --git a/src/tests/src/solver/optimisation/CMakeLists.txt b/src/tests/src/solver/optimisation/CMakeLists.txt index 72d92448a3..d3b9a9a82e 100644 --- a/src/tests/src/solver/optimisation/CMakeLists.txt +++ b/src/tests/src/solver/optimisation/CMakeLists.txt @@ -1,24 +1,2 @@ -# Useful variables definitions -set(src_solver_optimisation "${CMAKE_SOURCE_DIR}/solver/optimisation") - -set(EXECUTABLE_NAME tests-adq-patch) -add_executable(${EXECUTABLE_NAME} adequacy_patch.cpp) - -target_include_directories(${EXECUTABLE_NAME} - PRIVATE - "${src_solver_optimisation}" -) - -target_link_libraries(${EXECUTABLE_NAME} - PRIVATE - Boost::unit_test_framework - model_antares - array -) - -# Storing tests-ts-numbers under the folder Unit-tests in the IDE -set_target_properties(${EXECUTABLE_NAME} PROPERTIES FOLDER Unit-tests) - -add_test(NAME test-adq-patch COMMAND ${EXECUTABLE_NAME}) - -set_property(TEST test-adq-patch PROPERTY LABELS unit) +add_subdirectory(adequacy_patch) +add_subdirectory(translator) \ No newline at end of file diff --git a/src/tests/src/solver/optimisation/adequacy_patch/CMakeLists.txt b/src/tests/src/solver/optimisation/adequacy_patch/CMakeLists.txt new file mode 100644 index 0000000000..bb28a99864 --- /dev/null +++ b/src/tests/src/solver/optimisation/adequacy_patch/CMakeLists.txt @@ -0,0 +1,24 @@ +# Useful variables definitions +set(src_solver_optimisation "${CMAKE_SOURCE_DIR}/solver/optimisation") + +set(EXECUTABLE_NAME tests-adq-patch) +add_executable(${EXECUTABLE_NAME} adequacy_patch.cpp) + +target_include_directories(${EXECUTABLE_NAME} + PRIVATE + "${src_solver_optimisation}" +) + +target_link_libraries(${EXECUTABLE_NAME} + PRIVATE + Boost::unit_test_framework + model_antares + array +) + +# Storing tests-ts-numbers under the folder Unit-tests in the IDE +set_target_properties(${EXECUTABLE_NAME} PROPERTIES FOLDER Unit-tests) + +add_test(NAME test-adq-patch COMMAND ${EXECUTABLE_NAME}) + +set_property(TEST test-adq-patch PROPERTY LABELS unit) diff --git a/src/tests/src/solver/optimisation/adequacy_patch.cpp b/src/tests/src/solver/optimisation/adequacy_patch/adequacy_patch.cpp similarity index 100% rename from src/tests/src/solver/optimisation/adequacy_patch.cpp rename to src/tests/src/solver/optimisation/adequacy_patch/adequacy_patch.cpp diff --git a/src/tests/src/solver/optimisation/translator/CMakeLists.txt b/src/tests/src/solver/optimisation/translator/CMakeLists.txt new file mode 100644 index 0000000000..87f3d5a0cb --- /dev/null +++ b/src/tests/src/solver/optimisation/translator/CMakeLists.txt @@ -0,0 +1,20 @@ +set(EXECUTABLE_NAME test-translator) +add_executable(${EXECUTABLE_NAME}) + +target_sources(${EXECUTABLE_NAME} + PRIVATE + test_translator.cpp +) + +target_link_libraries(${EXECUTABLE_NAME} + PRIVATE + Boost::unit_test_framework + model_antares +) + +# Storing tests-ts-numbers under the folder Unit-tests in the IDE +set_target_properties(${EXECUTABLE_NAME} PROPERTIES FOLDER Unit-tests) + +add_test(NAME test-translator COMMAND ${EXECUTABLE_NAME}) + +set_property(TEST test-translator PROPERTY LABELS unit) diff --git a/src/tests/src/solver/optimisation/translator/test_translator.cpp b/src/tests/src/solver/optimisation/translator/test_translator.cpp new file mode 100644 index 0000000000..6fdc32c8fd --- /dev/null +++ b/src/tests/src/solver/optimisation/translator/test_translator.cpp @@ -0,0 +1,189 @@ +/* + * 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 . + */ + +#define BOOST_TEST_MODULE test_translator +#define WIN32_LEAN_AND_MEAN + +#include + +#include + +#include +#include "antares/solver/utils/opt_period_string_generator.h" + +using namespace Antares::Solver; + +class StubOptPeriodStringGenerator: public OptPeriodStringGenerator +{ +public: + std::string to_string() const override + { + return "Plop"; + } +}; + +BOOST_AUTO_TEST_CASE(null_hebdo_is_empty_lps) +{ + HebdoProblemToLpsTranslator translator; + auto ret = translator.translate(nullptr, std::string()); + BOOST_CHECK(ret == WeeklyDataFromAntares()); +} + +BOOST_AUTO_TEST_CASE(non_null_hebdo_returns_non_empty_lps) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.CoutLineaire.push_back(45); + auto ret = translator.translate(&problemHebdo, std::string()); + BOOST_CHECK(ret != WeeklyDataFromAntares()); +} + +BOOST_AUTO_TEST_CASE(Data_properly_copied) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.CoutLineaire = {0, 1, 2}; + problemHebdo.Xmax = {10, 11, 12}; + problemHebdo.Xmin = {20, 21, 22}; + problemHebdo.NomDesVariables = {"a", "b", "c"}; + problemHebdo.NomDesContraintes = {"d", "e", "f"}; + problemHebdo.SecondMembre = {30, 31, 32}; + + auto ret = translator.translate(&problemHebdo, std::string()); + BOOST_CHECK(ret.LinearCost == problemHebdo.CoutLineaire); + BOOST_CHECK(ret.Xmax == problemHebdo.Xmax); + BOOST_CHECK(ret.Xmin == problemHebdo.Xmin); + BOOST_CHECK(ret.RHS == problemHebdo.SecondMembre); + + BOOST_CHECK(ret.variables == problemHebdo.NomDesVariables); + BOOST_CHECK(ret.constraints == problemHebdo.NomDesContraintes); +} + +BOOST_AUTO_TEST_CASE(translate_sens) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.Sens = "<=>"; + + auto ret = translator.translate(&problemHebdo, std::string()); + BOOST_CHECK(ret.Direction == std::vector({'<', '=', '>'})); +} + +BOOST_AUTO_TEST_CASE(translate_name_is_filled) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + + auto ret = translator.translate(&problemHebdo, "dummy"); + BOOST_CHECK(!ret.name.empty()); +} + +BOOST_AUTO_TEST_CASE(translate_name_is_properly_filled) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + + auto ret = translator.translate(&problemHebdo, "problem-Plop--optim-nb-1.mps"); + BOOST_CHECK_EQUAL(ret.name, "problem-Plop--optim-nb-1.mps"); +} + +BOOST_AUTO_TEST_CASE(empty_problem_empty_const_data) +{ + HebdoProblemToLpsTranslator translator; + auto ret = translator.commonProblemData(nullptr); + BOOST_CHECK(ret == ConstantDataFromAntares()); +} + +BOOST_AUTO_TEST_CASE(common_data_properly_copied) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.NombreDeVariables = 1; + problemHebdo.NombreDeContraintes = 2; + problemHebdo.TypeDeVariable = {0, 1, 2}; + problemHebdo.IndicesDebutDeLigne = {0, 3}; + problemHebdo.NombreDeTermesDesLignes = {3, 3}; + problemHebdo.CoefficientsDeLaMatriceDesContraintes = {0, 1, 2, 3, 4, 5}; + problemHebdo.IndicesColonnes = {0, 1, 2, 3, 4, 5}; + + auto ret = translator.commonProblemData(&problemHebdo); + BOOST_CHECK_EQUAL(ret.VariablesCount, problemHebdo.NombreDeVariables); + BOOST_CHECK_EQUAL(ret.ConstraintesCount, problemHebdo.NombreDeContraintes); + BOOST_CHECK(std::ranges::equal(ret.VariablesType, problemHebdo.TypeDeVariable)); + BOOST_CHECK(ret.ConstraintsMatrixCoeff == problemHebdo.CoefficientsDeLaMatriceDesContraintes); + BOOST_CHECK(std::ranges::equal(ret.ColumnIndexes, problemHebdo.IndicesColonnes)); + BOOST_CHECK(std::ranges::equal(ret.Mdeb, problemHebdo.IndicesDebutDeLigne)); +} + +// throw exception if NombreDeVariables is 0 +BOOST_AUTO_TEST_CASE(throw_exception_if_NombreDeVariables_is_0) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.NombreDeVariables = 0; + BOOST_CHECK_THROW(translator.commonProblemData(&problemHebdo), std::runtime_error); +} + +BOOST_AUTO_TEST_CASE(throw_exception_if_NombreDeContraintes_is_0) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.NombreDeContraintes = 0; + BOOST_CHECK_THROW(translator.commonProblemData(&problemHebdo), std::runtime_error); +} + +BOOST_AUTO_TEST_CASE(throw_exception_if_IndicesDebutDeLigne_out_of_bound) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.NombreDeVariables = 1; + problemHebdo.NombreDeContraintes = 3; + problemHebdo.IndicesDebutDeLigne = {0, 3}; + problemHebdo.NombreDeTermesDesLignes = {0, 3, 6, 7, 8}; + BOOST_CHECK_THROW(translator.commonProblemData(&problemHebdo), std::runtime_error); +} + +BOOST_AUTO_TEST_CASE(throw_exception_if_NombreDeTermesDesLignes_out_of_bound) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.NombreDeVariables = 1; + problemHebdo.NombreDeContraintes = 3; + problemHebdo.NombreDeTermesDesLignes = {0, 3}; + problemHebdo.IndicesDebutDeLigne = {0, 3, 6, 7, 8}; + BOOST_CHECK_THROW(translator.commonProblemData(&problemHebdo), std::runtime_error); +} + +// NombreDeCoefficients +BOOST_AUTO_TEST_CASE(NombreDeCoefficients_is_properly_computed) +{ + HebdoProblemToLpsTranslator translator; + PROBLEME_ANTARES_A_RESOUDRE problemHebdo; + problemHebdo.NombreDeVariables = 1; + problemHebdo.NombreDeContraintes = 3; + problemHebdo.IndicesDebutDeLigne = {0, 3, 6}; + problemHebdo.NombreDeTermesDesLignes = {3, 3, 3}; + problemHebdo.CoefficientsDeLaMatriceDesContraintes = {0, 1, 2, 3, 4, 5, 6, 7, 8}; + problemHebdo.IndicesColonnes = {0, 1, 2, 3, 4, 5, 6, 7, 8}; + + auto ret = translator.commonProblemData(&problemHebdo); + BOOST_CHECK_EQUAL(ret.CoeffCount, 9); +} diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-ntc-renderer.h b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-ntc-renderer.h index 9bb7cdfd1f..edc1c49580 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-ntc-renderer.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-ntc-renderer.h @@ -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 . -*/ + * 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 . + */ #pragma once #include "scenario-builder-renderer-base.h" diff --git a/src/vcpkg.json b/src/vcpkg.json index fdd3963fd5..08acfb9e79 100644 --- a/src/vcpkg.json +++ b/src/vcpkg.json @@ -24,7 +24,7 @@ "version>=": "1.81.0" }, { - "name": "boost-algorithm", + "name": "boost-core", "version>=": "1.81.0" }, {