diff --git a/antares-version.json b/antares-version.json index dd1aa7452..b9b8f0b57 100644 --- a/antares-version.json +++ b/antares-version.json @@ -1,6 +1,6 @@ { - "antares_version": "8.7.0", - "antares_version_executable": "8.7", + "antares_version": "8.8.0-rc2", + "antares_version_executable": "8.8", "antares_xpansion_version": "1.1.0", "antares_deps_version": "2.0.7", "minizip_ng_version": "3.0.6" diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index 4a04e1eb4..71e239603 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -654,8 +654,10 @@ LogData BendersBase::bendersDataToLogData( data.number_of_subproblem_resolved + cumulative_number_of_subproblem_resolved_before_resume}; } -void BendersBase::set_log_file(const std::filesystem::path &log_name) { - _log_name = log_name; +void BendersBase::set_log_file(const std::filesystem::path &log_file) { + _log_name = log_file; + + solver_log_manager_ = SolverLogManager(log_name()); } /*! @@ -715,7 +717,7 @@ void BendersBase::AddSubproblem( subproblem_map[kvp.first] = std::make_shared( kvp.second, GetSubproblemPath(kvp.first), SubproblemWeight(_data.nsubproblem, kvp.first), _options.SOLVER_NAME, - _options.LOG_LEVEL, log_name(), _logger); + _options.LOG_LEVEL, solver_log_manager_, _logger); } void BendersBase::free_subproblems() { diff --git a/src/cpp/benders/benders_core/SubproblemWorker.cpp b/src/cpp/benders/benders_core/SubproblemWorker.cpp index 8a0fc0e5e..111ed586b 100644 --- a/src/cpp/benders/benders_core/SubproblemWorker.cpp +++ b/src/cpp/benders/benders_core/SubproblemWorker.cpp @@ -13,9 +13,10 @@ SubproblemWorker::SubproblemWorker( VariableMap const &variable_map, const std::filesystem::path &path_to_mps, double const &slave_weight, const std::string &solver_name, - const int log_level, const std::filesystem::path &log_name, Logger logger) + const int log_level, SolverLogManager&solver_log_manager, + Logger logger) : Worker(logger) { - init(variable_map, path_to_mps, solver_name, log_level, log_name); + init(variable_map, path_to_mps, solver_name, log_level, solver_log_manager); int mps_ncols(_solver->get_ncols()); DblVector obj_func_coeffs(mps_ncols); diff --git a/src/cpp/benders/benders_core/Worker.cpp b/src/cpp/benders/benders_core/Worker.cpp index b0525c285..8eb22cb49 100644 --- a/src/cpp/benders/benders_core/Worker.cpp +++ b/src/cpp/benders/benders_core/Worker.cpp @@ -37,15 +37,16 @@ void Worker::get_value(double &lb) const { void Worker::init(VariableMap const &variable_map, const std::filesystem::path &path_to_mps, std::string const &solver_name, int log_level, - const std::filesystem::path &log_name) { + SolverLogManager&solver_log_manager) { _path_to_mps = path_to_mps; SolverFactory factory; + if (_is_master) { - _solver = - factory.create_solver(solver_name, SOLVER_TYPE::INTEGER, log_name); + _solver = factory.create_solver(solver_name, SOLVER_TYPE::INTEGER, + solver_log_manager); } else { - _solver = - factory.create_solver(solver_name, SOLVER_TYPE::CONTINUOUS, log_name); + _solver = factory.create_solver(solver_name, SOLVER_TYPE::CONTINUOUS, + solver_log_manager); } _solver->init(); diff --git a/src/cpp/benders/benders_core/WorkerMaster.cpp b/src/cpp/benders/benders_core/WorkerMaster.cpp index f9b0ad757..1758511fd 100644 --- a/src/cpp/benders/benders_core/WorkerMaster.cpp +++ b/src/cpp/benders/benders_core/WorkerMaster.cpp @@ -19,18 +19,17 @@ WorkerMaster::WorkerMaster(Logger logger) : Worker(logger) { * \param log_level : solver log level * \param subproblems_count : number of subproblems */ -WorkerMaster::WorkerMaster(VariableMap const &variable_map, - const std::filesystem::path &path_to_mps, - const std::string &solver_name, const int log_level, - int subproblems_count, - const std::filesystem::path &log_name, - const bool mps_has_alpha, Logger logger) +WorkerMaster::WorkerMaster( + VariableMap const &variable_map, const std::filesystem::path &path_to_mps, + const std::string &solver_name, const int log_level, int subproblems_count, + SolverLogManager&solver_log_manager, + const bool mps_has_alpha, Logger logger) : Worker(logger), subproblems_count(subproblems_count), _mps_has_alpha(mps_has_alpha) { _is_master = true; - init(variable_map, path_to_mps, solver_name, log_level, log_name); + init(variable_map, path_to_mps, solver_name, log_level, solver_log_manager); if (!_mps_has_alpha) { _set_upper_bounds(); } diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index ca4b05472..19b38c97c 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -136,6 +136,8 @@ class BendersBase { return cumulative_number_of_subproblem_resolved_before_resume; } + SolverLogManager solver_log_manager_; + private: void print_master_and_cut(std::ostream &file, int ite, WorkerMasterDataPtr &trace, Point const &xopt); @@ -157,7 +159,7 @@ class BendersBase { private: BendersBaseOptions _options; unsigned int _totalNbProblems = 0; - std::filesystem::path _log_name; + std::filesystem::path _log_name = ""; BendersRelevantIterationsData relevantIterationData_ = { std::make_shared(), nullptr}; WorkerMasterPtr _master; diff --git a/src/cpp/benders/benders_core/include/SubproblemWorker.h b/src/cpp/benders/benders_core/include/SubproblemWorker.h index ef745f545..9af7bcd0b 100644 --- a/src/cpp/benders/benders_core/include/SubproblemWorker.h +++ b/src/cpp/benders/benders_core/include/SubproblemWorker.h @@ -18,7 +18,8 @@ class SubproblemWorker : public Worker { SubproblemWorker(VariableMap const &variable_map, const std::filesystem::path &path_to_mps, double const &slave_weight, const std::string &solver_name, - const int log_level, const std::filesystem::path &log_name, + const int log_level, + SolverLogManager&solver_log_manager, Logger logger); virtual ~SubproblemWorker() = default; diff --git a/src/cpp/benders/benders_core/include/Worker.h b/src/cpp/benders/benders_core/include/Worker.h index 5641416fa..b41a5521c 100644 --- a/src/cpp/benders/benders_core/include/Worker.h +++ b/src/cpp/benders/benders_core/include/Worker.h @@ -22,7 +22,7 @@ class Worker { void init(VariableMap const &variable_map, const std::filesystem::path &path_to_mps, std::string const &solver_name, int log_level, - const std::filesystem::path &log_name); + SolverLogManager&solver_log_manager); virtual ~Worker() = default; void get_value(double &lb) const; diff --git a/src/cpp/benders/benders_core/include/WorkerMaster.h b/src/cpp/benders/benders_core/include/WorkerMaster.h index ac09b1483..fa64ff561 100644 --- a/src/cpp/benders/benders_core/include/WorkerMaster.h +++ b/src/cpp/benders/benders_core/include/WorkerMaster.h @@ -15,7 +15,8 @@ class WorkerMaster : public Worker { WorkerMaster(VariableMap const &variable_map, const std::filesystem::path &path_to_mps, const std::string &solver_name, const int log_level, - int subproblems_count, const std::filesystem::path &log_name, + int subproblems_count, + SolverLogManager&solver_log_manager, bool mps_has_alpha, Logger logger); virtual ~WorkerMaster() = default; diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index 5757066fd..5c86a6f35 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -44,8 +44,8 @@ void BendersMpi::BuildMasterProblem() { if (_world.rank() == rank_0) { reset_master(new WorkerMaster(master_variable_map, get_master_path(), get_solver_name(), get_log_level(), - _data.nsubproblem, log_name(), IsResumeMode(), - _logger)); + _data.nsubproblem, solver_log_manager_, + IsResumeMode(), _logger)); } } /*! diff --git a/src/cpp/benders/benders_sequential/BendersSequential.cpp b/src/cpp/benders/benders_sequential/BendersSequential.cpp index ff3464969..e595ba17d 100644 --- a/src/cpp/benders/benders_sequential/BendersSequential.cpp +++ b/src/cpp/benders/benders_sequential/BendersSequential.cpp @@ -24,9 +24,10 @@ BendersSequential::BendersSequential(BendersBaseOptions const &options, void BendersSequential::InitializeProblems() { MatchProblemToId(); - reset_master(new WorkerMaster( - master_variable_map, get_master_path(), get_solver_name(), - get_log_level(), _data.nsubproblem, log_name(), IsResumeMode(), _logger)); + reset_master(new WorkerMaster(master_variable_map, get_master_path(), + get_solver_name(), get_log_level(), + _data.nsubproblem, solver_log_manager_, + IsResumeMode(), _logger)); for (const auto &problem : coupling_map) { const auto subProblemFilePath = GetSubproblemPath(problem.first); diff --git a/src/cpp/benders/factories/BendersFactory.cpp b/src/cpp/benders/factories/BendersFactory.cpp index 58b1b702a..35df81627 100644 --- a/src/cpp/benders/factories/BendersFactory.cpp +++ b/src/cpp/benders/factories/BendersFactory.cpp @@ -64,6 +64,7 @@ int RunBenders(char** argv, const std::filesystem::path& options_file, std::ostringstream oss_l = start_message(options, benders->BendersName()); oss_l << std::endl; logger->display_message(oss_l.str()); + benders->set_log_file(log_reports_name); writer->write_log_level(options.LOG_LEVEL); @@ -118,4 +119,4 @@ BendersMainFactory::BendersMainFactory( } int BendersMainFactory::Run() const { return RunBenders(argv_, options_file_, *penv_, *pworld_, method_); -} \ No newline at end of file +} diff --git a/src/cpp/benders/logger/UserFile.cpp b/src/cpp/benders/logger/UserFile.cpp index 2668fdb18..b856f72d7 100644 --- a/src/cpp/benders/logger/UserFile.cpp +++ b/src/cpp/benders/logger/UserFile.cpp @@ -24,7 +24,11 @@ UserFile::UserFile(const std::filesystem::path &filename) { } } -UserFile::~UserFile() { _file.close(); } +UserFile::~UserFile() { + if (_file.is_open()) { + _file.close(); + } +} void UserFile::display_message(const std::string &str) { _file << PrefixMessage(LogUtils::LOGLEVEL::INFO, CONTEXT) << str << std::endl; diff --git a/src/cpp/lpnamer/main/RunProblemGeneration.cpp b/src/cpp/lpnamer/main/RunProblemGeneration.cpp index f08164257..c6cbf682f 100644 --- a/src/cpp/lpnamer/main/RunProblemGeneration.cpp +++ b/src/cpp/lpnamer/main/RunProblemGeneration.cpp @@ -117,7 +117,7 @@ void validateMasterFormulation( } std::vector> getXpansionProblems( - const std::filesystem::path& log_file_path, const std::string& solver_name, + SolverLogManager& solver_log_manager, const std::string& solver_name, const std::vector& mpsList, std::filesystem::path& lpDir_, std::shared_ptr& reader) { std::vector problem_names; @@ -126,7 +126,7 @@ std::vector> getXpansionProblems( [](ProblemData const& data) { return data._problem_mps; }); auto adapter = std::make_shared(lpDir_, reader, problem_names); - return adapter->provideProblems(solver_name, log_file_path); + return adapter->provideProblems(solver_name, solver_log_manager); } void RunProblemGeneration( const std::filesystem::path& xpansion_output_dir, @@ -171,16 +171,18 @@ void RunProblemGeneration( bool use_zip_implementation = true; bool use_file_implementation = false; + + auto solver_log_manager = SolverLogManager(log_file_path); Couplings couplings; - LinkProblemsGenerator linkProblemsGenerator(lpDir_, links, solver_name, - logger, log_file_path, rename_problems); + LinkProblemsGenerator linkProblemsGenerator( + lpDir_, links, solver_name, logger, solver_log_manager, rename_problems); if (use_zip_implementation) { std::shared_ptr reader = InstantiateZipReader(antares_archive_path); /* Main stuff */ std::vector> xpansion_problems = - getXpansionProblems(log_file_path, solver_name, mpsList, lpDir_, + getXpansionProblems(solver_log_manager, solver_name, mpsList, lpDir_, reader); std::vector, ProblemData>> @@ -228,7 +230,7 @@ void RunProblemGeneration( XpansionProblemsFromAntaresProvider adapter(lps); auto xpansion_problems = - adapter.provideProblems(solver_name, log_file_path); + adapter.provideProblems(solver_name, solver_log_manager); std::vector, ProblemData>> problems_and_data; for (int i = 0; i < xpansion_problems.size(); ++i) { @@ -259,7 +261,7 @@ void RunProblemGeneration( MasterGeneration master_generation( xpansion_output_dir, links, additionalConstraints, couplings, - master_formulation, solver_name, logger, log_file_path); + master_formulation, solver_name, logger, solver_log_manager); (*logger)(LogUtils::LOGLEVEL::INFO) << "Problem Generation ran in: " << format_time_str(problem_generation_timer.elapsed()) << std::endl; diff --git a/src/cpp/lpnamer/problem_modifier/AntaresProblemToXpansionProblemTranslator.cpp b/src/cpp/lpnamer/problem_modifier/AntaresProblemToXpansionProblemTranslator.cpp index 4268e6fdc..8c1ee291d 100644 --- a/src/cpp/lpnamer/problem_modifier/AntaresProblemToXpansionProblemTranslator.cpp +++ b/src/cpp/lpnamer/problem_modifier/AntaresProblemToXpansionProblemTranslator.cpp @@ -11,11 +11,10 @@ std::shared_ptr AntaresProblemToXpansionProblemTranslator::translateToXpansionProblem( const LpsFromAntares& lps, unsigned int year, unsigned int week, - const std::string& solver_name, - const std::filesystem::path& log_file_path) { + const std::string& solver_name, SolverLogManager& solver_log_manager) { SolverFactory factory; auto problem = std::make_shared( - factory.create_solver(solver_name, log_file_path)); + factory.create_solver(solver_name, solver_log_manager)); problem->init(); const auto& constant = lps._constant; const auto& hebdo = lps._hebdo.at({year, week}); diff --git a/src/cpp/lpnamer/problem_modifier/AntaresProblemToXpansionProblemTranslator.h b/src/cpp/lpnamer/problem_modifier/AntaresProblemToXpansionProblemTranslator.h index 354a75300..1c6e2fa48 100644 --- a/src/cpp/lpnamer/problem_modifier/AntaresProblemToXpansionProblemTranslator.h +++ b/src/cpp/lpnamer/problem_modifier/AntaresProblemToXpansionProblemTranslator.h @@ -11,7 +11,6 @@ class AntaresProblemToXpansionProblemTranslator { public: [[nodiscard]] static std::shared_ptr translateToXpansionProblem( const LpsFromAntares& lps, unsigned int year, unsigned int week, - const std::string& solver_name, - const std::filesystem::path& log_file_path); + const std::string& solver_name, SolverLogManager& solver_log_manager); static std::vector convertSignToLEG(char* data); }; diff --git a/src/cpp/lpnamer/problem_modifier/IProblemProviderPort.h b/src/cpp/lpnamer/problem_modifier/IProblemProviderPort.h index 02770f866..0c85a9568 100644 --- a/src/cpp/lpnamer/problem_modifier/IProblemProviderPort.h +++ b/src/cpp/lpnamer/problem_modifier/IProblemProviderPort.h @@ -11,5 +11,5 @@ class IProblemProviderPort { virtual ~IProblemProviderPort() = default; [[nodiscard]] virtual std::shared_ptr provide_problem( const std::string& solver_name, - const std::filesystem::path& log_file_path) const = 0; + SolverLogManager& solver_log_manager) const = 0; }; diff --git a/src/cpp/lpnamer/problem_modifier/IXpansionProblemsProvider.h b/src/cpp/lpnamer/problem_modifier/IXpansionProblemsProvider.h index 21ce5f5cb..89c3e24ed 100644 --- a/src/cpp/lpnamer/problem_modifier/IXpansionProblemsProvider.h +++ b/src/cpp/lpnamer/problem_modifier/IXpansionProblemsProvider.h @@ -12,5 +12,5 @@ class IXpansionProblemsProvider { virtual ~IXpansionProblemsProvider() = default; [[nodiscard]] virtual std::vector> provideProblems( const std::string& solver_name, - const std::filesystem::path& log_file_path) const = 0; + SolverLogManager& solver_log_manager) const = 0; }; diff --git a/src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.cpp b/src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.cpp index 5c4259bf8..2f741eae4 100644 --- a/src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.cpp +++ b/src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.cpp @@ -29,18 +29,16 @@ void LinkProblemsGenerator::treat( const std::string &problem_name, Couplings &couplings, IProblemProviderPort *problem_provider, - IProblemVariablesProviderPort *variable_provider, - IProblemWriter *writer) const { + IProblemVariablesProviderPort *variable_provider, IProblemWriter *writer) { auto in_prblm = - problem_provider->provide_problem(_solver_name, log_file_path_); + problem_provider->provide_problem(_solver_name, solver_log_manager_); treat(problem_name, couplings, in_prblm.get(), variable_provider, writer); } void LinkProblemsGenerator::treat( const std::string &problem_name, Couplings &couplings, Problem *problem, - IProblemVariablesProviderPort *variable_provider, - IProblemWriter *writer) const { + IProblemVariablesProviderPort *variable_provider, IProblemWriter *writer) { ProblemVariables problem_variables = variable_provider->Provide(); if (rename_problems_) { @@ -74,7 +72,8 @@ void LinkProblemsGenerator::treatloop(const std::filesystem::path &root, [&](const auto &mps) { auto adapter = std::make_unique( root, mps._problem_mps); - auto problem = adapter->provide_problem(_solver_name, log_file_path_); + auto problem = + adapter->provide_problem(_solver_name, solver_log_manager_); std::unique_ptr variables_provider; if (rename_problems_) { variables_provider = std::make_unique( diff --git a/src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.h b/src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.h index 59ab56e47..cb75ed2b0 100644 --- a/src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.h +++ b/src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.h @@ -32,13 +32,12 @@ class LinkProblemsGenerator { std::filesystem::path& lpDir, const std::vector& links, std::string solver_name, ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger, - std::filesystem::path log_file_path, - bool rename_problems) + SolverLogManager& solver_log_manager, bool rename_problems) : _links(links), _solver_name(std::move(solver_name)), lpDir_(lpDir), logger_(std::move(logger)), - log_file_path_(std::move(log_file_path)), + solver_log_manager_(solver_log_manager), rename_problems_(rename_problems) {} void treatloop(const std::filesystem::path& root, Couplings& couplings, @@ -46,11 +45,11 @@ class LinkProblemsGenerator { IProblemWriter* writer); void treat(const std::string& problem_name, Couplings& couplings, Problem* problem, IProblemVariablesProviderPort* variable_provider, - IProblemWriter* writer) const; + IProblemWriter* writer); void treat(const std::string& problem_name, Couplings& couplings, IProblemProviderPort* problem_provider, IProblemVariablesProviderPort* variable_provider, - IProblemWriter* writer) const; + IProblemWriter* writer); private: const std::vector& _links; @@ -58,6 +57,6 @@ class LinkProblemsGenerator { std::filesystem::path lpDir_ = ""; ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger_; mutable std::mutex coupling_mutex_; - std::filesystem::path log_file_path_; bool rename_problems_ = false; + SolverLogManager& solver_log_manager_; }; diff --git a/src/cpp/lpnamer/problem_modifier/MPSFileProblemProviderAdapter.cpp b/src/cpp/lpnamer/problem_modifier/MPSFileProblemProviderAdapter.cpp index be09c7565..533e4cb90 100644 --- a/src/cpp/lpnamer/problem_modifier/MPSFileProblemProviderAdapter.cpp +++ b/src/cpp/lpnamer/problem_modifier/MPSFileProblemProviderAdapter.cpp @@ -9,11 +9,11 @@ #include "multisolver_interface/SolverFactory.h" std::shared_ptr MPSFileProblemProviderAdapter::provide_problem( const std::string& solver_name, - const std::filesystem::path& log_file_path) const { + SolverLogManager& solver_log_manager) const { SolverFactory factory; auto const lp_mps_name = lp_dir_ / problem_name_; auto in_prblm = std::make_shared( - factory.create_solver(solver_name, log_file_path)); + factory.create_solver(solver_name, solver_log_manager)); in_prblm->read_prob_mps(lp_mps_name); return in_prblm; diff --git a/src/cpp/lpnamer/problem_modifier/MPSFileProblemProviderAdapter.h b/src/cpp/lpnamer/problem_modifier/MPSFileProblemProviderAdapter.h index 6df68af81..712152315 100644 --- a/src/cpp/lpnamer/problem_modifier/MPSFileProblemProviderAdapter.h +++ b/src/cpp/lpnamer/problem_modifier/MPSFileProblemProviderAdapter.h @@ -11,7 +11,7 @@ class MPSFileProblemProviderAdapter : public IProblemProviderPort { const std::string& problem_name); [[nodiscard]] std::shared_ptr provide_problem( const std::string& solver_name, - const std::filesystem::path& log_file_path) const override; + SolverLogManager& solver_log_manager) const override; const std::filesystem::path lp_dir_; const std::string& problem_name_; }; diff --git a/src/cpp/lpnamer/problem_modifier/MasterGeneration.cpp b/src/cpp/lpnamer/problem_modifier/MasterGeneration.cpp index 59001d5df..79552088e 100644 --- a/src/cpp/lpnamer/problem_modifier/MasterGeneration.cpp +++ b/src/cpp/lpnamer/problem_modifier/MasterGeneration.cpp @@ -12,11 +12,11 @@ MasterGeneration::MasterGeneration( const AdditionalConstraints &additionalConstraints_p, Couplings &couplings, std::string const &master_formulation, std::string const &solver_name, ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger, - const std::filesystem::path &log_file_path) + SolverLogManager&solver_log_manager) : logger_(logger) { add_candidates(links); write_master_mps(rootPath, master_formulation, solver_name, - additionalConstraints_p, log_file_path); + additionalConstraints_p, solver_log_manager); write_structure_file(rootPath, couplings); } @@ -36,10 +36,10 @@ void MasterGeneration::write_master_mps( const std::filesystem::path &rootPath, std::string const &master_formulation, std::string const &solver_name, const AdditionalConstraints &additionalConstraints_p, - const std::filesystem::path &log_file_path) const { + SolverLogManager&solver_log_manager) const { SolverAbstract::Ptr master_l = MasterProblemBuilder(master_formulation) - .build(solver_name, candidates, log_file_path); + .build(solver_name, candidates, solver_log_manager); treatAdditionalConstraints(master_l, additionalConstraints_p, logger_); std::string const &lp_name = "master"; diff --git a/src/cpp/lpnamer/problem_modifier/MasterGeneration.h b/src/cpp/lpnamer/problem_modifier/MasterGeneration.h index 7c9588df9..e284e2c12 100644 --- a/src/cpp/lpnamer/problem_modifier/MasterGeneration.h +++ b/src/cpp/lpnamer/problem_modifier/MasterGeneration.h @@ -25,15 +25,15 @@ class MasterGeneration { Couplings &couplings, std::string const &master_formulation, std::string const &solver_name, ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger, - const std::filesystem::path &log_file_path); + SolverLogManager&solver_log_manager); private: /*methods*/ void add_candidates(const std::vector &links); - void write_master_mps(const std::filesystem::path &rootPath, - std::string const &master_formulation, - std::string const &solver_name, - const AdditionalConstraints &additionalConstraints_p, - const std::filesystem::path &log_file_path) const; + void write_master_mps( + const std::filesystem::path &rootPath, + std::string const &master_formulation, std::string const &solver_name, + const AdditionalConstraints &additionalConstraints_p, + SolverLogManager&solver_log_manager) const; void write_structure_file(const std::filesystem::path &rootPath, const Couplings &couplings) const; diff --git a/src/cpp/lpnamer/problem_modifier/MasterProblemBuilder.cpp b/src/cpp/lpnamer/problem_modifier/MasterProblemBuilder.cpp index 66ad8a7dd..8830d15b8 100644 --- a/src/cpp/lpnamer/problem_modifier/MasterProblemBuilder.cpp +++ b/src/cpp/lpnamer/problem_modifier/MasterProblemBuilder.cpp @@ -16,12 +16,12 @@ MasterProblemBuilder::MasterProblemBuilder( std::shared_ptr MasterProblemBuilder::build( const std::string& solverName, const std::vector& candidates, - const std::filesystem::path& log_file_path) { + SolverLogManager& solver_log_manager) { _indexOfNvar.clear(); _indexOfPmaxVar.clear(); SolverFactory factory; - auto master_l = factory.create_solver(solverName, log_file_path); + auto master_l = factory.create_solver(solverName, solver_log_manager); addVariablesPmaxOnEachCandidate(candidates, master_l); diff --git a/src/cpp/lpnamer/problem_modifier/MasterProblemBuilder.h b/src/cpp/lpnamer/problem_modifier/MasterProblemBuilder.h index 8633edb13..28cfabe05 100644 --- a/src/cpp/lpnamer/problem_modifier/MasterProblemBuilder.h +++ b/src/cpp/lpnamer/problem_modifier/MasterProblemBuilder.h @@ -19,7 +19,7 @@ class MasterProblemBuilder { explicit MasterProblemBuilder(const std::string& master_formulation); std::shared_ptr build( const std::string& solverName, const std::vector& candidates, - const std::filesystem::path& log_file_path); + SolverLogManager& solver_log_manager); private: void addNvarOnEachIntegerCandidate( diff --git a/src/cpp/lpnamer/problem_modifier/XpansionProblemsFromAntaresProvider.cpp b/src/cpp/lpnamer/problem_modifier/XpansionProblemsFromAntaresProvider.cpp index f4f7aa79d..090095e89 100644 --- a/src/cpp/lpnamer/problem_modifier/XpansionProblemsFromAntaresProvider.cpp +++ b/src/cpp/lpnamer/problem_modifier/XpansionProblemsFromAntaresProvider.cpp @@ -16,7 +16,7 @@ XpansionProblemsFromAntaresProvider::XpansionProblemsFromAntaresProvider( std::vector> XpansionProblemsFromAntaresProvider::provideProblems( const std::string& solver_name, - const std::filesystem::path& log_file_path) const { + SolverLogManager& solver_log_manager) const { std::vector> xpansion_problems; xpansion_problems.reserve( XpansionProblemsFromAntaresProvider::antares_hebdo_problems._hebdo @@ -26,7 +26,7 @@ XpansionProblemsFromAntaresProvider::provideProblems( xpansion_problems.push_back( AntaresProblemToXpansionProblemTranslator::translateToXpansionProblem( XpansionProblemsFromAntaresProvider::antares_hebdo_problems, - problem_id.year, problem_id.week, solver_name, log_file_path)); + problem_id.year, problem_id.week, solver_name, solver_log_manager)); } return xpansion_problems; } \ No newline at end of file diff --git a/src/cpp/lpnamer/problem_modifier/XpansionProblemsFromAntaresProvider.h b/src/cpp/lpnamer/problem_modifier/XpansionProblemsFromAntaresProvider.h index 576044fb1..7a1a09c4d 100644 --- a/src/cpp/lpnamer/problem_modifier/XpansionProblemsFromAntaresProvider.h +++ b/src/cpp/lpnamer/problem_modifier/XpansionProblemsFromAntaresProvider.h @@ -13,6 +13,6 @@ class XpansionProblemsFromAntaresProvider : public IXpansionProblemsProvider { explicit XpansionProblemsFromAntaresProvider(LpsFromAntares antares); [[nodiscard]] std::vector> provideProblems( const std::string& solver_name, - const std::filesystem::path& log_file_path) const override; + SolverLogManager& solver_log_manager) const override; LpsFromAntares antares_hebdo_problems; }; diff --git a/src/cpp/lpnamer/problem_modifier/ZipProblemProviderAdapter.cpp b/src/cpp/lpnamer/problem_modifier/ZipProblemProviderAdapter.cpp index 5406f89bc..a8bf4a9a8 100644 --- a/src/cpp/lpnamer/problem_modifier/ZipProblemProviderAdapter.cpp +++ b/src/cpp/lpnamer/problem_modifier/ZipProblemProviderAdapter.cpp @@ -17,13 +17,13 @@ void ZipProblemProviderAdapter::reader_extract_file( std::shared_ptr ZipProblemProviderAdapter::provide_problem( const std::string& solver_name, - const std::filesystem::path& log_file_path) const { + SolverLogManager& solver_log_manager) const { reader_extract_file(problem_name_, *archive_reader_, lp_dir_); SolverFactory factory; auto const lp_mps_name = ZipProblemProviderAdapter::lp_dir_ / ZipProblemProviderAdapter::problem_name_; auto in_prblm = std::make_shared( - factory.create_solver(solver_name, log_file_path)); + factory.create_solver(solver_name, solver_log_manager)); in_prblm->read_prob_mps(lp_mps_name); return in_prblm; diff --git a/src/cpp/lpnamer/problem_modifier/ZipProblemProviderAdapter.h b/src/cpp/lpnamer/problem_modifier/ZipProblemProviderAdapter.h index 9c1d4c480..75ebc4f2b 100644 --- a/src/cpp/lpnamer/problem_modifier/ZipProblemProviderAdapter.h +++ b/src/cpp/lpnamer/problem_modifier/ZipProblemProviderAdapter.h @@ -18,6 +18,6 @@ class ZipProblemProviderAdapter : public IProblemProviderPort { const std::string problem_name_; [[nodiscard]] std::shared_ptr provide_problem( const std::string& solver_name, - const std::filesystem::path& log_file_path) const override; + SolverLogManager& solver_log_manager) const override; std::shared_ptr archive_reader_; }; diff --git a/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp b/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp index e7047a539..bf8aeae6f 100644 --- a/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp +++ b/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp @@ -13,7 +13,7 @@ std::vector> ZipProblemsProviderAdapter::provideProblems( const std::string& solver_name, - const std::filesystem::path& log_file_path) const { + SolverLogManager& solver_log_manager) const { std::vector> problems(problem_names_.size()); // Order is important. Problems need to be in the same order as names std::transform(std::execution::par, @@ -23,7 +23,7 @@ ZipProblemsProviderAdapter::provideProblems( ZipProblemProviderAdapter problem_provider(lp_dir_, name, archive_reader_); return problem_provider.provide_problem(solver_name, - log_file_path); + solver_log_manager); }); return problems; } diff --git a/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.h b/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.h index 4a53f4907..0036bd8dc 100644 --- a/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.h +++ b/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.h @@ -13,7 +13,7 @@ class ZipProblemsProviderAdapter : public IXpansionProblemsProvider { std::vector problem_names); [[nodiscard]] std::vector> provideProblems( const std::string& solver_name, - const std::filesystem::path& log_file_path) const override; + SolverLogManager& solver_log_manager) const override; std::shared_ptr archive_reader_; std::filesystem::path lp_dir_; std::vector problem_names_; diff --git a/src/cpp/multisolver_interface/SolverCbc.cpp b/src/cpp/multisolver_interface/SolverCbc.cpp index d7e689234..06d3de0fc 100644 --- a/src/cpp/multisolver_interface/SolverCbc.cpp +++ b/src/cpp/multisolver_interface/SolverCbc.cpp @@ -8,20 +8,14 @@ *************************************************************************************************/ int SolverCbc::_NumberOfProblems = 0; -SolverCbc::SolverCbc(const std::filesystem::path &log_file) : SolverCbc() { - _log_file = log_file; - if (_log_file.empty()) { +SolverCbc::SolverCbc(SolverLogManager &log_manager) : SolverCbc() { + _fp = log_manager.log_file_ptr; + if (!_fp) { std::cout << "Empty log file name, fallback to default behaviour" << std::endl; } else { - if ((_fp = fopen(_log_file.string().c_str(), "a+")) == nullptr) { - std::cerr << "Invalid log file name passed as parameter: " << _log_file - << std::endl; - } else { - setvbuf(_fp, nullptr, _IONBF, 0); - _clp_inner_solver.messageHandler()->setFilePointer(_fp); - _cbc.messageHandler()->setFilePointer(_fp); - } + _clp_inner_solver.messageHandler()->setFilePointer(_fp); + _cbc.messageHandler()->setFilePointer(_fp); } } SolverCbc::SolverCbc() { @@ -34,14 +28,13 @@ SolverCbc::SolverCbc(const std::shared_ptr toCopy) // Try to cast the solver in fictif to a SolverCbc if (const auto c = dynamic_cast(toCopy.get())) { _clp_inner_solver = OsiClpSolverInterface(c->_clp_inner_solver); - _log_file = toCopy->_log_file; - _fp = fopen(_log_file.string().c_str(), "a+"); - if (_fp != nullptr) { - setvbuf(_fp, nullptr, _IONBF, 0); + + defineCbcModelFromInnerSolver(); + _fp = c->_fp; + if (_fp) { _clp_inner_solver.messageHandler()->setFilePointer(_fp); _cbc.messageHandler()->setFilePointer(_fp); } - defineCbcModelFromInnerSolver(); } else { _NumberOfProblems -= 1; throw InvalidSolverForCopyException(toCopy->get_solver_name(), name_, @@ -51,10 +44,6 @@ SolverCbc::SolverCbc(const std::shared_ptr toCopy) SolverCbc::~SolverCbc() { _NumberOfProblems -= 1; - if (_fp != nullptr) { - fclose(_fp); - _fp = nullptr; - } free(); } diff --git a/src/cpp/multisolver_interface/SolverCbc.h b/src/cpp/multisolver_interface/SolverCbc.h index 57484779a..f81228f0d 100644 --- a/src/cpp/multisolver_interface/SolverCbc.h +++ b/src/cpp/multisolver_interface/SolverCbc.h @@ -39,7 +39,7 @@ class SolverCbc : public SolverAbstract { * @brief Default constructor of a CBC solver */ SolverCbc(); - explicit SolverCbc(const std::filesystem::path &log_file); + explicit SolverCbc(SolverLogManager&log_manager); /** * @brief Copy constructor of solver, copy the problem toCopy in memory and diff --git a/src/cpp/multisolver_interface/SolverClp.cpp b/src/cpp/multisolver_interface/SolverClp.cpp index 1071ed073..e770a6e60 100644 --- a/src/cpp/multisolver_interface/SolverClp.cpp +++ b/src/cpp/multisolver_interface/SolverClp.cpp @@ -8,38 +8,28 @@ *************************************************************************************************/ int SolverClp::_NumberOfProblems = 0; -SolverClp::SolverClp(const std::filesystem::path &log_file) : SolverClp() { - _log_file = log_file; - if (_log_file.empty()) { +SolverClp::SolverClp(SolverLogManager &log_manager) : SolverClp() { + _fp = log_manager.log_file_ptr; + if (!_fp) { std::cout << "Empty log file name, fallback to default behaviour" << std::endl; } else { - if ((_fp = fopen(_log_file.string().c_str(), "a+")) == NULL) { - std::cerr << "Invalid log file name passed as parameter: " << _log_file - << std::endl; - } else { - setvbuf(_fp, NULL, _IONBF, 0); - _clp.messageHandler()->setFilePointer(_fp); - } + _clp.messageHandler()->setFilePointer(_fp); } } SolverClp::SolverClp() { _NumberOfProblems += 1; - _fp = nullptr; set_output_log_level(0); } SolverClp::SolverClp(const std::shared_ptr toCopy) : SolverClp() { - _fp = nullptr; // Try to cast the solver in fictif to a SolverClp if (const auto c = dynamic_cast(toCopy.get())) { _clp = ClpSimplex(c->_clp); - _log_file = toCopy->_log_file; - _fp = fopen(_log_file.string().c_str(), "a+"); - if (_fp != nullptr) { - setvbuf(_fp, nullptr, _IONBF, 0); - _clp.messageHandler()->setFilePointer(_fp); + _fp = c->_fp; + if (_fp) { + _clp.messageHandler()->setFilePointer(c->_fp); } } else { _NumberOfProblems -= 1; @@ -50,10 +40,6 @@ SolverClp::SolverClp(const std::shared_ptr toCopy) SolverClp::~SolverClp() { _NumberOfProblems -= 1; - if (_fp != nullptr) { - fclose(_fp); - _fp = nullptr; - } free(); } diff --git a/src/cpp/multisolver_interface/SolverClp.h b/src/cpp/multisolver_interface/SolverClp.h index 803a7e8d6..9be4aa893 100644 --- a/src/cpp/multisolver_interface/SolverClp.h +++ b/src/cpp/multisolver_interface/SolverClp.h @@ -40,7 +40,7 @@ class SolverClp : public SolverAbstract { * @brief Default constructor of a CLP solver */ SolverClp(); - explicit SolverClp(const std::filesystem::path &log_file); + explicit SolverClp(SolverLogManager &log_manager); /** * @brief Copy constructor of CLP, copy the problem toCopy in memory and name diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index 62be10ca0..1ec81c52b 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -21,40 +21,76 @@ SolverFactory::SolverFactory() { SolverAbstract::Ptr SolverFactory::create_solver( const std::string &solver_name, const SOLVER_TYPE solver_type) const { - return create_solver(solver_name, solver_type, ""); + if (solver_name == "") { + throw InvalidSolverNameException(solver_name, LOGLOCATION); + } +#ifdef XPRESS + else if (solver_name == XPRESS_STR) { + return std::make_shared(); + } +#endif +#ifdef COIN_OR + if (solver_name == COIN_STR && solver_type == SOLVER_TYPE::CONTINUOUS) { + return std::make_shared(); + } else if (solver_name == COIN_STR && solver_type == SOLVER_TYPE::INTEGER) { + return std::make_shared(); + } +#endif + else { + throw InvalidSolverNameException(solver_name, LOGLOCATION); + } } + SolverAbstract::Ptr SolverFactory::create_solver( const std::string &solver_name, const SOLVER_TYPE solver_type, - const std::filesystem::path &log_name) const { + SolverLogManager &log_manager) const { #ifdef COIN_OR if (solver_name == COIN_STR && solver_type == SOLVER_TYPE::CONTINUOUS) { - return std::make_shared(log_name); + return std::make_shared(log_manager); } else if (solver_name == COIN_STR && solver_type == SOLVER_TYPE::INTEGER) { - return std::make_shared(log_name); + return std::make_shared(log_manager); } #endif - return create_solver(solver_name, log_name); + return create_solver(solver_name, log_manager); } + SolverAbstract::Ptr SolverFactory::create_solver( const std::string &solver_name) const { - return create_solver(solver_name, ""); + if (solver_name == "") { + throw InvalidSolverNameException(solver_name, LOGLOCATION); + } +#ifdef XPRESS + else if (solver_name == XPRESS_STR) { + return std::make_shared(); + } +#endif +#ifdef COIN_OR + else if (solver_name == CLP_STR) { + return std::make_shared(); + } else if (solver_name == CBC_STR) { + return std::make_shared(); + } +#endif + else { + throw InvalidSolverNameException(solver_name, LOGLOCATION); + } } + SolverAbstract::Ptr SolverFactory::create_solver( - const std::string &solver_name, - const std::filesystem::path &log_name) const { + const std::string &solver_name, SolverLogManager &log_manager) const { if (solver_name == "") { throw InvalidSolverNameException(solver_name, LOGLOCATION); } #ifdef XPRESS else if (solver_name == XPRESS_STR) { - return std::make_shared(log_name); + return std::make_shared(log_manager); } #endif #ifdef COIN_OR else if (solver_name == CLP_STR) { - return std::make_shared(log_name); + return std::make_shared(log_manager); } else if (solver_name == CBC_STR) { - return std::make_shared(log_name); + return std::make_shared(log_manager); } #endif else { diff --git a/src/cpp/multisolver_interface/SolverXpress.cpp b/src/cpp/multisolver_interface/SolverXpress.cpp index 49e88e4a4..1832f0c3d 100644 --- a/src/cpp/multisolver_interface/SolverXpress.cpp +++ b/src/cpp/multisolver_interface/SolverXpress.cpp @@ -14,11 +14,10 @@ int SolverXpress::_NumberOfProblems = 0; std::mutex SolverXpress::license_guard; const std::map TYPETONAME = {{1, "rows"}, {2, "columns"}}; -SolverXpress::SolverXpress(const std::filesystem::path &log_file) - : SolverXpress() { - _log_file = log_file; - if (_log_file != "") { +SolverXpress::SolverXpress(SolverLogManager &log_manager) : SolverXpress() { + if (log_manager.log_file_path != "") { _log_stream.open(_log_file, std::ofstream::out | std::ofstream::app); + _log_file = log_manager.log_file_path; add_stream(_log_stream); } } diff --git a/src/cpp/multisolver_interface/SolverXpress.h b/src/cpp/multisolver_interface/SolverXpress.h index fbe6d3613..06cd8bf61 100644 --- a/src/cpp/multisolver_interface/SolverXpress.h +++ b/src/cpp/multisolver_interface/SolverXpress.h @@ -33,7 +33,7 @@ class SolverXpress : public SolverAbstract { * @brief Default constructor of a XPRESS solver */ SolverXpress(); - SolverXpress(const std::filesystem::path &log_file); + SolverXpress(SolverLogManager &log_manager); /** * @brief Copy constructor of XPRESS, copy the problem toCopy in memory and diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/SolverAbstract.h b/src/cpp/multisolver_interface/include/multisolver_interface/SolverAbstract.h index 1eae50699..6ad34e3be 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/SolverAbstract.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/SolverAbstract.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -12,6 +13,53 @@ #include "LogUtils.h" +class SolverLogManager { + public: + explicit SolverLogManager() = default; + explicit SolverLogManager(const SolverLogManager &other) + : SolverLogManager(other.log_file_path) {} + + explicit SolverLogManager(const std::filesystem::path &log_file) + : log_file_path(log_file) { + init(); + } + + SolverLogManager &operator=(const SolverLogManager &other) { + if (this == &other) { + return *this; + } + log_file_path = other.log_file_path; + init(); + return *this; + } + + void init() { +#ifdef __linux__ + if (log_file_path.empty() || + (log_file_ptr = fopen(log_file_path.string().c_str(), "a+")) == nullptr) +#elif _WIN32 + if (log_file_path.empty() || + (log_file_ptr = _fsopen(log_file_path.string().c_str(), "a+", + _SH_DENYNO)) == nullptr) +#endif + { + std::cout << "Invalid log file name passed as parameter: " + << std::quoted(log_file_path.string()) << std::endl; + } else { + setvbuf(log_file_ptr, nullptr, _IONBF, 0); + } + } + ~SolverLogManager() { + if (log_file_ptr) { + fclose(log_file_ptr); + log_file_ptr = nullptr; + } + } + + FILE *log_file_ptr = nullptr; + std::filesystem::path log_file_path = ""; +}; + class InvalidStatusException : public LogUtils::XpansionError { public: diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h b/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h index 91594b58d..20cdfe57e 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h @@ -33,7 +33,7 @@ class SolverFactory { SolverAbstract::Ptr create_solver(const std::string &solver_name) const; SolverAbstract::Ptr create_solver( const std::string &solver_name, - const std::filesystem::path &log_name) const; + SolverLogManager&log_manager) const; /** * @brief Creates and returns to an object solver from the wanted @@ -46,7 +46,7 @@ class SolverFactory { const SOLVER_TYPE solver_type) const; SolverAbstract::Ptr create_solver( const std::string &solver_name, const SOLVER_TYPE solver_type, - const std::filesystem::path &log_name) const; + SolverLogManager&log_manager) const; /** * @brief Copy constructor : Creates and returns to an object solver from the diff --git a/src/python/antares_xpansion/__version__.py.in b/src/python/antares_xpansion/__version__.py.in index 8a80bfa4a..70fee4dea 100644 --- a/src/python/antares_xpansion/__version__.py.in +++ b/src/python/antares_xpansion/__version__.py.in @@ -1,2 +1,2 @@ __version__ = "${CMAKE_PROJECT_VERSION}" -__antares_simulator_version__ = "${ANTARES_VERSION_TAG}" +__antares_simulator_version__ = "${ANTARES_VERSION}" diff --git a/src/python/antares_xpansion/antares_driver.py b/src/python/antares_xpansion/antares_driver.py index b52d9bce2..e47d425b7 100644 --- a/src/python/antares_xpansion/antares_driver.py +++ b/src/python/antares_xpansion/antares_driver.py @@ -103,7 +103,7 @@ def _get_antares_cmd(self): cmd = [str(self.antares_exe_path), self.data_dir, self.ANTARES_N_CPU_OPTION, str(self.antares_n_cpu), self.zip_option] simulator_version = version.parse(__antares_simulator_version__) simulator_version_with_named_mps = version.parse(self.FIRST_VERSION_WITH_NAMED_PROBLEMS) - if (simulator_version.major > simulator_version_with_named_mps.major) or (simulator_version.major == simulator_version_with_named_mps.major and simulator_version.minor == simulator_version_with_named_mps.minor): + if (simulator_version.major > simulator_version_with_named_mps.major) or (simulator_version.major >= simulator_version_with_named_mps.major and simulator_version.minor >= simulator_version_with_named_mps.minor): cmd.append("--named-mps-problems") return cmd diff --git a/src/python/antares_xpansion/config_loader.py b/src/python/antares_xpansion/config_loader.py index f533e00d9..7330b4736 100644 --- a/src/python/antares_xpansion/config_loader.py +++ b/src/python/antares_xpansion/config_loader.py @@ -504,6 +504,9 @@ def _set_last_simulation_name(self): self._last_study = self.last_modified_study(self.antares_output()) self._set_xpansion_simulation_name() + class NotAnXpansionOutputDir(Exception): + pass + def _set_xpansion_simulation_name(self): if self.step() in ["resume", "sensitivity"] : @@ -512,6 +515,11 @@ def _set_xpansion_simulation_name(self): self._xpansion_simulation_name = self._last_study.parent / self._last_study.stem with zipfile.ZipFile(self._last_study, 'r') as output_zip: output_zip.extractall(self._xpansion_simulation_name) + elif self.step() == "benders": + if(not self._last_study.name.endswith("-Xpansion")): + raise ConfigLoader.NotAnXpansionOutputDir(f"Error! {self._last_study} is not an Xpansion output directory") + self._xpansion_simulation_name = self._last_study + else: self._xpansion_simulation_name = self._last_study.parent / \ (self._last_study.stem+"-Xpansion") diff --git a/tests/cpp/benders/benders_sequential_test.cpp b/tests/cpp/benders/benders_sequential_test.cpp index 4f1e37910..acf7f2c29 100644 --- a/tests/cpp/benders/benders_sequential_test.cpp +++ b/tests/cpp/benders/benders_sequential_test.cpp @@ -78,10 +78,11 @@ class BendersSequentialDouble : public BendersSequential { void InitializeProblems() override { MatchProblemToId(); + auto solver_log_manager = SolverLogManager(log_name()); reset_master(new WorkerMaster(master_variable_map, get_master_path(), get_solver_name(), get_log_level(), - _data.nsubproblem, log_name(), IsResumeMode(), - _logger)); + _data.nsubproblem, solver_log_manager, + IsResumeMode(), _logger)); for (const auto &problem : coupling_map) { const auto subProblemFilePath = GetSubproblemPath(problem.first); AddSubproblem(problem); diff --git a/tests/cpp/lp_namer/MasterProblemBuilderTest.cpp b/tests/cpp/lp_namer/MasterProblemBuilderTest.cpp index 827f0f606..725181d15 100644 --- a/tests/cpp/lp_namer/MasterProblemBuilderTest.cpp +++ b/tests/cpp/lp_namer/MasterProblemBuilderTest.cpp @@ -32,9 +32,9 @@ TEST(MasterProblemBuilderTest, test_one_candidate_not_integer) { candidates.insert(candidates.end(), candidateFromLink.begin(), candidateFromLink.end()); } - + auto solver_log_manager = SolverLogManager(""); auto master_problem = MasterProblemBuilder(master_formulation) - .build(solver_name, candidates, ""); + .build(solver_name, candidates, solver_log_manager); ASSERT_EQ(master_problem->get_ncols(), 1); ASSERT_EQ( master_problem->get_col_names(0, master_problem->get_ncols() - 1)[0], @@ -87,8 +87,9 @@ TEST(MasterProblemBuilderTest, test_one_candidate_integer_problem_integer) { candidateFromLink.end()); } + auto solver_log_manager = SolverLogManager(""); auto master_problem = MasterProblemBuilder(master_formulation) - .build(solver_name, candidates, ""); + .build(solver_name, candidates, solver_log_manager); ASSERT_EQ(master_problem->get_ncols(), 2); std::vector colTypeArray(master_problem->get_ncols()); @@ -149,8 +150,9 @@ TEST(MasterProblemBuilderTest, test_one_candidate_integer_problem_relaxed) { candidateFromLink.end()); } + auto solver_log_manager = SolverLogManager(""); auto master_problem = MasterProblemBuilder(master_formulation) - .build(solver_name, candidates, ""); + .build(solver_name, candidates, solver_log_manager); ASSERT_EQ(master_problem->get_ncols(), 1); ASSERT_EQ( master_problem->get_col_names(0, master_problem->get_ncols() - 1)[0], diff --git a/tests/cpp/sensitivity/SensitivityPbModifierTest.cpp b/tests/cpp/sensitivity/SensitivityPbModifierTest.cpp index 4b579e7e5..c1ff05934 100644 --- a/tests/cpp/sensitivity/SensitivityPbModifierTest.cpp +++ b/tests/cpp/sensitivity/SensitivityPbModifierTest.cpp @@ -55,7 +55,9 @@ class SensitivityProblemModifierTest : public ::testing::Test std::string solver_name = "CBC"; SolverFactory factory; - SolverAbstract::Ptr solver_model = factory.create_solver(solver_name, std::tmpnam(nullptr)); + auto solver_log_manager = SolverLogManager(std::tmpnam(nullptr)); + SolverAbstract::Ptr solver_model = + factory.create_solver(solver_name, solver_log_manager); solver_model->init(); solver_model->read_prob_mps(last_master_mps_path); diff --git a/tests/cpp/sensitivity/SensitivityStudyTest.cpp b/tests/cpp/sensitivity/SensitivityStudyTest.cpp index a50fdac79..6559f5b9b 100644 --- a/tests/cpp/sensitivity/SensitivityStudyTest.cpp +++ b/tests/cpp/sensitivity/SensitivityStudyTest.cpp @@ -38,7 +38,8 @@ class SensitivityStudyTest : public ::testing::Test { void init_solver(std::string solver_name, std::string last_master_mps_path) { SolverFactory factory; - math_problem = factory.create_solver(solver_name, std::tmpnam(nullptr)); + auto solver_log_manager = SolverLogManager(std::tmpnam(nullptr)); + math_problem = factory.create_solver(solver_name, solver_log_manager); math_problem->init(); math_problem->read_prob_mps(last_master_mps_path); } diff --git a/tests/python/test_antares_driver.py b/tests/python/test_antares_driver.py index 806e5d7b0..8411e6290 100644 --- a/tests/python/test_antares_driver.py +++ b/tests/python/test_antares_driver.py @@ -239,8 +239,8 @@ def get_settings_dir(antares_study_path: Path): class TestAntaresDriver: def setup_method(self): #TODO update antares version which comes with named problems - self.nammed_problems = version.parse(__antares_simulator_version__) >= version.parse("8.6") - + #self.nammed_problems = version.parse(__antares_simulator_version__) >= version.parse("8.6") + self.nammed_problems=True def test_antares_cmd(self, tmp_path): study_dir = tmp_path exe_path = "/Path/to/bin1"