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 {