Skip to content

Commit

Permalink
start Math log
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Nov 20, 2023
1 parent c0c7cef commit 3423dfc
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cpp/benders/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/cpp/benders/logger/MathLogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "logger/MathLogger.h"

#include <iostream>

#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;
}
}
50 changes: 50 additions & 0 deletions src/cpp/benders/logger/include/logger/MathLogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#pragma once

#include <filesystem>
#include <fstream>

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 <class T>
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_;
};

0 comments on commit 3423dfc

Please sign in to comment.