-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_; | ||
}; |