From 3423dfc4e50af0f0e48cfa510c784b4a0f204c65 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 20 Nov 2023 12:59:22 +0100 Subject: [PATCH] start Math log --- src/cpp/benders/logger/CMakeLists.txt | 3 +- src/cpp/benders/logger/MathLogger.cpp | 15 ++++++ .../logger/include/logger/MathLogger.h | 50 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/cpp/benders/logger/MathLogger.cpp create mode 100644 src/cpp/benders/logger/include/logger/MathLogger.h diff --git a/src/cpp/benders/logger/CMakeLists.txt b/src/cpp/benders/logger/CMakeLists.txt index cd0bf4f45..d322c811a 100644 --- a/src/cpp/benders/logger/CMakeLists.txt +++ b/src/cpp/benders/logger/CMakeLists.txt @@ -5,7 +5,8 @@ add_library (logger_lib User.cpp UserFile.cpp CandidateLog.cpp - IterationResultLog.cpp ) + IterationResultLog.cpp + MathLogger.cpp ) target_link_libraries (logger_lib PUBLIC diff --git a/src/cpp/benders/logger/MathLogger.cpp b/src/cpp/benders/logger/MathLogger.cpp new file mode 100644 index 000000000..eca640be7 --- /dev/null +++ b/src/cpp/benders/logger/MathLogger.cpp @@ -0,0 +1,15 @@ +#include "logger/MathLogger.h" + +#include + +#include "LoggerUtils.h" +void MathLogger::write_header() {} + +MathLoggerFile::MathLoggerFile(const std::filesystem::path &filename) + : MathLogger(&file_stream_) { + file_stream_.open(filename, std::ofstream::out | std::ofstream::app); + if (file_stream_.fail()) { + std::cerr << PrefixMessage(LogUtils::LOGLEVEL::ERR, data.CONTEXT) + << "Invalid file name passed as parameter" << std::endl; + } +} \ No newline at end of file diff --git a/src/cpp/benders/logger/include/logger/MathLogger.h b/src/cpp/benders/logger/include/logger/MathLogger.h new file mode 100644 index 000000000..bfb51cc9e --- /dev/null +++ b/src/cpp/benders/logger/include/logger/MathLogger.h @@ -0,0 +1,50 @@ + +#pragma once + +#include +#include + +struct MathLoggerData { + int iteration; + double lower_bound; + double upper_bound; + double best_upper_bound; + double optimality_gap; + double relative_gap; + int max_simplexiter; + int min_simplexiter; + int deletedcut; + double time_master; + double time_subproblems; + double alpha; + const std::string CONTEXT = "Benders"; +}; + +class LogDestination { + public: + explicit LogDestination(std::ostream* stream) : stream_(stream) {} + template + std::ostream& operator<<(const T& obj) { + // write obj to stream + return (*stream_) << T; + } + + private: + std::ostream* stream_; +}; + +struct MathLogger { + explicit MathLogger(std::ostream* stream) : log_destination(stream) {} + void write_header(); + + MathLoggerData data; + LogDestination log_destination; +}; + +class MathLoggerFile : public MathLogger { + public: + explicit MathLoggerFile(const std::filesystem::path& log_file); + + private: + std::ofstream file_stream_; +}; \ No newline at end of file