-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/low level logs #723
Closed
a-zakir
wants to merge
32
commits into
AntaresSimulatorTeam:develop
from
BAZ-C:feature/low-level-logs
Closed
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3423dfc
start Math log
a-zakir f184ff7
add overloaded method
a-zakir 4cfd573
fix platform specific standard
a-zakir d3527c4
add MathloggerDriver
a-zakir d341b1b
print basic data
a-zakir f28101c
add math logger in benders
a-zakir 3710fbb
Benders take mathlooger
a-zakir e2e9a91
print maths log
a-zakir 847b9db
add missing include
a-zakir b2680f0
fix
a-zakir ef37857
print more data
a-zakir 896fdde
Reset Simplex Iterations Bounds
a-zakir 3616fcf
introducing MathlogImplementation
a-zakir ff73b89
fix
a-zakir 53adca3
fix
a-zakir 7307b13
ok
a-zakir 707b6e5
set log destination
a-zakir 9402964
@tbittar remarks
a-zakir 6871cd1
split behaviour and data holders
a-zakir bcc6c24
rename data header
a-zakir 7edbb4b
add "other time"
a-zakir 37baeb1
align columns
a-zakir 59af269
align headers and data
a-zakir c2a13ec
fix master time
a-zakir d6810e6
add CUMULATIVE nb of sub-pblm
a-zakir 00e909f
add num of subproblem solved / iteration
a-zakir 5d29a74
add "expert" option for logs
a-zakir 474380d
update
a-zakir 8fb0d30
to fit terminal width
a-zakir c5df2ae
add expert_logs option in python code
a-zakir 40b09f2
update doc
a-zakir e233d64
remove unused function
a-zakir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,20 @@ | ||
#include "BendersMathLogger.h" | ||
|
||
void MathLoggerDriver::add_logger( | ||
std::shared_ptr<MathLoggerImplementation> logger) { | ||
if (logger) { | ||
math_loggers_.push_back(logger); | ||
} | ||
} | ||
|
||
void MathLoggerDriver::Print(const CurrentIterationData& data) { | ||
for (auto logger : math_loggers_) { | ||
logger->Print(data); | ||
} | ||
} | ||
|
||
void MathLoggerDriver::write_header() { | ||
for (auto logger : math_loggers_) { | ||
logger->write_header(); | ||
} | ||
} |
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
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
139 changes: 139 additions & 0 deletions
139
src/cpp/benders/benders_core/include/BendersMathLogger.h
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,139 @@ | ||
#pragma once | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <list> | ||
#include <memory> | ||
|
||
#include "BendersStructsDatas.h" | ||
#include "common.h" | ||
const std::string MATHLOGGERCONTEXT = "Benders"; | ||
|
||
inline std::string Indent(int size) { return std::string(size, ' '); } | ||
const std::string ITERATION = Indent(10) + "ITERATION"; | ||
const std::string LB = Indent(20) + "LB"; | ||
const std::string UB = Indent(20) + "UB"; | ||
const std::string BESTUB = Indent(20) + "BESTUB"; | ||
const std::string ABSOLUTE_GAP = Indent(15) + "ABSOLUTE GAP"; | ||
const std::string RELATIVE_GAP = Indent(15) + "RELATIVE GAP"; | ||
const std::string MINSIMPLEX = Indent(15) + "MINSIMPLEX"; | ||
const std::string MAXSIMPLEX = Indent(15) + "MAXSIMPLEX"; | ||
const std::string TIMEMASTER = Indent(15) + "TIMEMASTER"; | ||
const std::string SUB_PROBLEMS_TIME_CPU = | ||
Indent(15) + "SUB-PROBLEMS TIME (CPU)"; | ||
const std::string SUB_PROBLEMS_TIME_WALL = | ||
Indent(15) + "SUB-PROBLEMS TIME (WALL)"; | ||
const std::string TIME_NOT_DOING_MASTER_OR_SUB_PROBLEMS_WALL = | ||
Indent(15) + "TIME NOT DOING MASTER OR SUB-PROBLEMS (WALL)"; | ||
class LogDestination { | ||
public: | ||
explicit LogDestination(std::ostream* stream) : stream_(stream) {} | ||
|
||
// for std::endl | ||
std::ostream& operator<<(std::ostream& (*function)(std::ostream&)) { | ||
// write obj to stream | ||
return function(*stream_); | ||
} | ||
|
||
template <class T> | ||
std::ostream& operator<<(const T& obj); | ||
|
||
private: | ||
std::ostream* stream_; | ||
}; | ||
template <class T> | ||
std::ostream& LogDestination::operator<<(const T& obj) { | ||
// write obj to stream | ||
return (*stream_) << std::left << obj; | ||
} | ||
|
||
struct MathLoggerBehaviour { | ||
void write_header() { | ||
setHeadersList(); | ||
for (const auto& header : Headers()) { | ||
LogsDestination() << header; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR contains console logs. Please review or remove them. |
||
LogsDestination() << std::endl; | ||
} | ||
virtual void Print(const CurrentIterationData& data) = 0; | ||
virtual std::list<std::string> Headers() const = 0; | ||
virtual LogDestination& LogsDestination() = 0; | ||
virtual void setHeadersList() = 0; | ||
}; | ||
|
||
struct MathLogger : public MathLoggerBehaviour { | ||
explicit MathLogger(std::ostream* stream) : log_destination_(stream) {} | ||
explicit MathLogger() : log_destination_(&std::cout) {} | ||
virtual void Print(const CurrentIterationData& data) = 0; | ||
std::list<std::string> Headers() const override { return headers_; } | ||
virtual LogDestination& LogsDestination() { return log_destination_; } | ||
virtual void setHeadersList() = 0; | ||
|
||
protected: | ||
void setHeadersList(const std::list<std::string>& headers); | ||
|
||
private: | ||
std::list<std::string> headers_; | ||
LogDestination log_destination_; | ||
}; | ||
|
||
struct MathLoggerBase : public MathLogger { | ||
using MathLogger::MathLogger; | ||
void Print(const CurrentIterationData& data) override; | ||
|
||
void setHeadersList() override; | ||
}; | ||
|
||
struct MathLoggerBendersByBatch : public MathLogger { | ||
using MathLogger::MathLogger; | ||
void Print(const CurrentIterationData& data) override; | ||
|
||
void setHeadersList() override; | ||
}; | ||
|
||
class MathLoggerImplementation : public MathLoggerBehaviour { | ||
public: | ||
explicit MathLoggerImplementation(const BENDERSMETHOD& method, | ||
std::ostream* stream) { | ||
if (method == BENDERSMETHOD::BENDERS) { | ||
implementation_ = std::make_shared<MathLoggerBase>(stream); | ||
} else if (method == BENDERSMETHOD::BENDERSBYBATCH) { | ||
implementation_ = std::make_shared<MathLoggerBendersByBatch>(stream); | ||
} | ||
// else | ||
} | ||
explicit MathLoggerImplementation(const BENDERSMETHOD& method) { | ||
if (method == BENDERSMETHOD::BENDERS) { | ||
implementation_ = std::make_shared<MathLoggerBase>(); | ||
} else if (method == BENDERSMETHOD::BENDERSBYBATCH) { | ||
implementation_ = std::make_shared<MathLoggerBendersByBatch>(); | ||
} | ||
// else } | ||
} | ||
|
||
void Print(const CurrentIterationData& data) { implementation_->Print(data); } | ||
|
||
protected: | ||
void setHeadersList() override { implementation_->setHeadersList(); } | ||
std::list<std::string> Headers() const override { | ||
return implementation_->Headers(); | ||
} | ||
virtual LogDestination& LogsDestination() { | ||
return implementation_->LogsDestination(); | ||
} | ||
|
||
private: | ||
std::shared_ptr<MathLogger> implementation_; | ||
}; | ||
|
||
class MathLoggerDriver { | ||
public: | ||
MathLoggerDriver() = default; | ||
void write_header(); | ||
|
||
void add_logger(std::shared_ptr<MathLoggerImplementation> logger); | ||
void Print(const CurrentIterationData& data); | ||
|
||
private: | ||
std::list<std::shared_ptr<MathLoggerImplementation>> math_loggers_; | ||
}; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code if useless