Skip to content

Commit

Permalink
print basic data
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Nov 20, 2023
1 parent d3527c4 commit d341b1b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
37 changes: 36 additions & 1 deletion src/cpp/benders/logger/MathLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,46 @@ void MathLogger::write_header() {
log_destination << std::endl;
}

void MathLogger::Print(const MathLoggerData& data) {
log_destination << Indent(10) << data.iteration;
if (data.lower_bound == -1e20)
log_destination << Indent(20) << "-INF";
else
log_destination << Indent(20) << std::scientific << std::setprecision(10)
<< data.lower_bound;
if (data.upper_bound == +1e20)
log_destination << Indent(20) << "+INF";
else
log_destination << Indent(20) << std::scientific << std::setprecision(10)
<< data.upper_bound;
if (data.best_upper_bound == +1e20)
log_destination << Indent(20) << "+INF";
else
log_destination << Indent(20) << std::scientific << std::setprecision(10)
<< data.best_upper_bound;
log_destination << Indent(15) << std::scientific << std::setprecision(2)
<< data.best_upper_bound - data.lower_bound;

log_destination << Indent(15) << std::scientific << std::setprecision(2)
<< (data.best_upper_bound - data.lower_bound) /
data.best_upper_bound;

log_destination << Indent(15) << data.min_simplexiter;
log_destination << Indent(15) << data.max_simplexiter;

log_destination << Indent(15) << data.deletedcut;
log_destination << Indent(15) << std::setprecision(2) << data.time_master;
log_destination << Indent(15) << std::setprecision(2)
<< data.time_subproblems;

log_destination << std::endl;
}

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)
std::cerr << PrefixMessage(LogUtils::LOGLEVEL::ERR, MATHLOGGERCONTEXT)
<< "Invalid file name passed as parameter" << std::endl;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/cpp/benders/logger/include/logger/MathLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <iomanip>
#include <iostream>
#include <list>
const std::string MATHLOGGERCONTEXT = "Benders";

struct MathLoggerData {
int iteration;
Expand All @@ -20,7 +21,6 @@ struct MathLoggerData {
double time_master;
double time_subproblems;
// double alpha;
const std::string CONTEXT = "Benders";
};

class LogDestination {
Expand Down Expand Up @@ -53,8 +53,7 @@ std::ostream& LogDestination::operator<<(const T& obj) {
struct MathLogger {
explicit MathLogger(std::ostream* stream) : log_destination(stream) {}
void write_header();

MathLoggerData data;
void Print(const MathLoggerData& data);
LogDestination log_destination;
};

Expand Down

0 comments on commit d341b1b

Please sign in to comment.