From edc1e0276a46d35bbf6c44abb53e585adadc1cec Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir <abdoulbari.zakir@gmail.com> Date: Wed, 13 Nov 2024 10:55:13 +0100 Subject: [PATCH] update --- src/cpp/benders/benders_core/common.cpp | 9 ++++++++- .../antares-xpansion/benders/benders_core/common.h | 4 +++- src/cpp/benders/factories/BendersFactory.cpp | 5 ++--- .../antares-xpansion/benders/factories/BendersFactory.h | 5 ----- src/cpp/benders/merge_mps/MergeMPS.cpp | 2 +- tests/cpp/outer_loop/outer_loop_test.cpp | 6 +++--- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/cpp/benders/benders_core/common.cpp b/src/cpp/benders/benders_core/common.cpp index 6ff942024..b6b9db61d 100644 --- a/src/cpp/benders/benders_core/common.cpp +++ b/src/cpp/benders/benders_core/common.cpp @@ -1,5 +1,6 @@ #include "antares-xpansion/benders/benders_core/common.h" +#include <antares-xpansion/xpansion_interfaces/LogUtils.h> /*! * \brief Return the distance between two point using 2-norm * @@ -29,6 +30,11 @@ void usage(int argc) { } } +struct InvalidStructureFile + : public LogUtils::XpansionError<std::runtime_error> { + using LogUtils::XpansionError<std::runtime_error>::XpansionError; +}; + /*! * \brief Build the input from the structure file * @@ -44,7 +50,8 @@ void usage(int argc) { * \note The id in the coupling_map is that of the variable in the solver *responsible for the creation of the structure file. */ -CouplingMap build_input(const std::filesystem::path &structure_path) { +CouplingMap CouplingMapGenerator::build_input( + const std::filesystem::path &structure_path) { CouplingMap coupling_map; std::ifstream summary(structure_path, std::ios::in); if (!summary) { diff --git a/src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/common.h b/src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/common.h index f2799800f..f8af018f7 100644 --- a/src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/common.h +++ b/src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/common.h @@ -191,5 +191,7 @@ struct BendersBaseOptions : public BaseOptions { }; void usage(int argc); -CouplingMap build_input(const std::filesystem::path &structure_path); +struct CouplingMapGenerator { + static CouplingMap build_input(const std::filesystem::path &structure_path); +}; Json::Value get_json_file_content(const std::filesystem::path &json_file); diff --git a/src/cpp/benders/factories/BendersFactory.cpp b/src/cpp/benders/factories/BendersFactory.cpp index bdf62d07f..a07e81ee7 100644 --- a/src/cpp/benders/factories/BendersFactory.cpp +++ b/src/cpp/benders/factories/BendersFactory.cpp @@ -12,7 +12,6 @@ #include "antares-xpansion/benders/factories/WriterFactories.h" #include "antares-xpansion/helpers/AreaParser.h" #include "antares-xpansion/helpers/Timer.h" -#include "antares-xpansion/xpansion_interfaces/ILogger.h" #include "antares-xpansion/xpansion_interfaces/LogUtils.h" BENDERSMETHOD DeduceBendersMethod(size_t coupling_map_size, size_t batch_size, @@ -39,8 +38,8 @@ pBendersBase BendersMainFactory::PrepareForExecution(bool external_loop) { BendersBaseOptions benders_options(options_.get_benders_options()); benders_options.EXTERNAL_LOOP_OPTIONS.DO_OUTER_LOOP = external_loop; - - const auto coupling_map = build_input(benders_options.STRUCTURE_FILE); + const auto coupling_map = + CouplingMapGenerator::build_input(benders_options.STRUCTURE_FILE); method_ = DeduceBendersMethod(coupling_map.size(), options_.BATCH_SIZE, external_loop); diff --git a/src/cpp/benders/factories/include/antares-xpansion/benders/factories/BendersFactory.h b/src/cpp/benders/factories/include/antares-xpansion/benders/factories/BendersFactory.h index 7c36d7f5b..98362bb46 100644 --- a/src/cpp/benders/factories/include/antares-xpansion/benders/factories/BendersFactory.h +++ b/src/cpp/benders/factories/include/antares-xpansion/benders/factories/BendersFactory.h @@ -6,11 +6,6 @@ #include "antares-xpansion/benders/benders_core/common.h" #include "antares-xpansion/benders/benders_mpi/BendersMPI.h" -struct InvalidStructureFile - : public LogUtils::XpansionError<std::runtime_error> { - using LogUtils::XpansionError<std::runtime_error>::XpansionError; -}; - class BendersMainFactory { private: char** argv_; diff --git a/src/cpp/benders/merge_mps/MergeMPS.cpp b/src/cpp/benders/merge_mps/MergeMPS.cpp index 2b5f910e2..eedc7b2b7 100644 --- a/src/cpp/benders/merge_mps/MergeMPS.cpp +++ b/src/cpp/benders/merge_mps/MergeMPS.cpp @@ -13,7 +13,7 @@ MergeMPS::MergeMPS(const MergeMPSOptions &options, Logger &logger, void MergeMPS::launch() { const auto inputRootDir = std::filesystem::path(_options.INPUTROOT); auto structure_path(inputRootDir / _options.STRUCTURE_FILE); - CouplingMap input = build_input(structure_path); + CouplingMap input = CouplingMapGenerator::build_input(structure_path); SolverFactory factory; std::string solver_to_use = diff --git a/tests/cpp/outer_loop/outer_loop_test.cpp b/tests/cpp/outer_loop/outer_loop_test.cpp index 9a555e6b0..53f607451 100644 --- a/tests/cpp/outer_loop/outer_loop_test.cpp +++ b/tests/cpp/outer_loop/outer_loop_test.cpp @@ -101,9 +101,9 @@ void CheckMinInvestmentConstraint(const VariableMap& master_variables, TEST_P(MasterUpdateBaseTest, ConstraintIsAddedBendersMPI) { BendersBaseOptions bendersoptions = BuildBendersOptions(); - CouplingMap coupling_map = - build_input(std::filesystem::path(bendersoptions.INPUTROOT) / - bendersoptions.STRUCTURE_FILE); + CouplingMap coupling_map = CouplingMapGenerator::build_input( + std::filesystem::path(bendersoptions.INPUTROOT) / + bendersoptions.STRUCTURE_FILE); // override solver bendersoptions.SOLVER_NAME = GetParam(); bendersoptions.EXTERNAL_LOOP_OPTIONS.DO_OUTER_LOOP = true;