Skip to content

Commit

Permalink
Add lambdas to math logs (#821)
Browse files Browse the repository at this point in the history
Closes #816
  • Loading branch information
tbittar authored May 21, 2024
1 parent 1531c00 commit 92040c2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
20 changes: 15 additions & 5 deletions src/cpp/benders/benders_core/BendersBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,15 +1020,25 @@ double BendersBase::ExternalLoopLambdaMin() const {
return outer_loop_biLevel_.LambdaMin();
}

void BendersBase::init_data(double external_loop_lambda) {
void BendersBase::init_data(double external_loop_lambda,
double external_loop_lambda_min,
double external_loop_lambda_max) {
benders_timer.restart();
auto benders_num_run = _data.outer_loop_current_iteration_data.benders_num_run;
auto outer_loop_bilevel_best_ub = _data.outer_loop_current_iteration_data.outer_loop_bilevel_best_ub;
auto benders_num_run =
_data.outer_loop_current_iteration_data.benders_num_run;
auto outer_loop_bilevel_best_ub =
_data.outer_loop_current_iteration_data.outer_loop_bilevel_best_ub;
init_data();
_data.outer_loop_current_iteration_data.outer_loop_criterion.clear();
_data.outer_loop_current_iteration_data.benders_num_run = benders_num_run;
_data.outer_loop_current_iteration_data.outer_loop_bilevel_best_ub = outer_loop_bilevel_best_ub;
_data.outer_loop_current_iteration_data.external_loop_lambda = external_loop_lambda;
_data.outer_loop_current_iteration_data.outer_loop_bilevel_best_ub =
outer_loop_bilevel_best_ub;
_data.outer_loop_current_iteration_data.external_loop_lambda =
external_loop_lambda;
_data.outer_loop_current_iteration_data.external_loop_lambda_min =
external_loop_lambda_min;
_data.outer_loop_current_iteration_data.external_loop_lambda_max =
external_loop_lambda_max;
}

bool BendersBase::ExternalLoopFoundFeasible() const {
Expand Down
17 changes: 15 additions & 2 deletions src/cpp/benders/benders_core/BendersMathLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ std::vector<std::string> HeadersManagerExternalLoop::HeadersList() {
headers_list.push_back("Max Criterion");
headers_list.push_back("Area Max Criterion");
headers_list.push_back("Bilevel best ub");
headers_list.push_back("Lambda");
headers_list.push_back("Lambda min");
headers_list.push_back("Lambda max");
auto base_headers = HeadersManager::HeadersList();
std::move(base_headers.begin(), base_headers.end(),
std::back_inserter(headers_list));
Expand Down Expand Up @@ -167,8 +170,18 @@ void PrintExternalLoopData(LogDestination& log_destination,
<< data.outer_loop_current_iteration_data.max_criterion;
log_destination << data.outer_loop_current_iteration_data.max_criterion_area;

log_destination << std::scientific << std::setprecision(10)
<< data.outer_loop_current_iteration_data.outer_loop_bilevel_best_ub;
log_destination
<< std::scientific << std::setprecision(10)
<< data.outer_loop_current_iteration_data.outer_loop_bilevel_best_ub;
log_destination
<< std::scientific << std::setprecision(10)
<< data.outer_loop_current_iteration_data.external_loop_lambda;
log_destination
<< std::scientific << std::setprecision(10)
<< data.outer_loop_current_iteration_data.external_loop_lambda_min;
log_destination
<< std::scientific << std::setprecision(10)
<< data.outer_loop_current_iteration_data.external_loop_lambda_max;
PrintBendersData(log_destination, data, type, method);
}
void MathLoggerBaseExternalLoop::Print(const CurrentIterationData& data) {
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/include/BendersBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class BendersBase {
OuterLoopCurrentIterationData GetOuterLoopData() const;
std::vector<double> GetOuterLoopCriterionAtBestBenders() const;
virtual void init_data();
void init_data(double external_loop_lambda);
void init_data(double external_loop_lambda, double external_loop_lambda_min, double external_loop_lambda_max);

double ExternalLoopLambdaMax() const;
double ExternalLoopLambdaMin() const;
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/benders/benders_core/include/BendersStructsDatas.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct OuterLoopCurrentIterationData{
double max_criterion_best_it = 0.;
double outer_loop_bilevel_best_ub = +1e20;
double external_loop_lambda = 0.;
double external_loop_lambda_min = 0.;
double external_loop_lambda_max = 0.;
std::string max_criterion_area;
std::string max_criterion_area_best_it;
};
Expand Down
4 changes: 3 additions & 1 deletion src/cpp/benders/outer_loop/OuterLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void OuterLoop::Run() {
bool stop_update_master = false;
while (!stop_update_master) {
PrintLog();
benders_->init_data(master_updater_->Rhs());
benders_->init_data(master_updater_->Rhs(),
benders_->ExternalLoopLambdaMin(),
benders_->ExternalLoopLambdaMax());
benders_->launch();
if(!benders_->isExceptionRaised()) {
benders_->RunExternalLoopBilevelChecks();
Expand Down

0 comments on commit 92040c2

Please sign in to comment.