From 1586ab55a729eabb2939ee80497e4c2ec68b1e47 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 16 Nov 2023 17:33:35 +0100 Subject: [PATCH] [skip] better --- src/solver/utils/ortools_utils.cpp | 21 ++++++++++----------- src/solver/utils/ortools_utils.h | 30 ++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index 2a9701873b..820255b252 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -34,20 +34,19 @@ namespace Optimization { void setOrtoolsSolverLogs(MPSolver* solver, OrtoolsLogHandler& ortools_logger) { - // TODO won't work in ci, needs ortools update - // see https://github.com/rte-france/or-tools/pull/112 - // std::filesystem::path log_file = logs.logfile().c_str(); - // auto log_directory = log_file.parent_path(); - // auto myid = std::this_thread::get_id(); - // std::stringstream ss; - // ss << myid; - // auto log_file_per_thread = log_directory / (std::string("thread_") + ss.str() + ".log"); - // // TODO - // log_writer.open(log_file_per_thread, std::ofstream::out | std::ofstream::app); - // log_streams.push_back(&log_writer); solver->EnableOutput(&ortools_logger); } +OrtoolsLogHandler::OrtoolsLogHandler() +{ + std::filesystem::path log_file = logs.logfile().c_str(); + auto log_directory = log_file.parent_path(); + auto myid = std::this_thread::get_id(); + std::stringstream ss; + ss << myid; + auto log_file_per_thread = log_directory / (std::string("thread_") + ss.str() + ".log"); + log_writer_.open(log_file_per_thread, std::ofstream::out | std::ofstream::app); +} ProblemSimplexeNommeConverter::ProblemSimplexeNommeConverter( const std::string& solverName, const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* problemeSimplexe) : diff --git a/src/solver/utils/ortools_utils.h b/src/solver/utils/ortools_utils.h index 6045acfc69..890f80eaf6 100644 --- a/src/solver/utils/ortools_utils.h +++ b/src/solver/utils/ortools_utils.h @@ -12,16 +12,6 @@ using namespace operations_research; -class OrtoolsLogHandler : public LogHandlerInterface -{ -public: - // tmp test with std::cout - explicit OrtoolsLogHandler() = default; - void message(const char* msg) override - { - std::cout << msg << std::endl; - } -}; void ORTOOLS_EcrireJeuDeDonneesLineaireAuFormatMPS(MPSolver* solver, Antares::Solver::IResultWriter& writer, const std::string& filename); @@ -58,6 +48,26 @@ namespace Antares { namespace Optimization { + +class OrtoolsLogHandler : public LogHandlerInterface +{ +public: + // tmp test with std::cout + explicit OrtoolsLogHandler(); + void message(const char* msg) override + { + log_writer_ << msg << std::endl; + } + +private: + // TODO won't work in ci, needs ortools update + // see https://github.com/rte-france/or-tools/pull/112 + + // // TODO + std::ofstream log_writer_; + // log_writer.open(log_file_per_thread, std::ofstream::out | std::ofstream::app); + // log_streams.push_back(&log_writer); +}; void setOrtoolsSolverLogs(MPSolver* solver, OrtoolsLogHandler &ortools_logger); class Nomenclature {