Skip to content

Commit 06d531a

Browse files
committed
adjusted column spacing in bnb logs. added opening mode for logger.
1 parent 89ebcbb commit 06d531a

File tree

2 files changed

+53
-47
lines changed

2 files changed

+53
-47
lines changed

cpp/src/dual_simplex/branch_and_bound.cpp

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ std::string user_mip_gap(f_t obj_value, f_t lower_bound)
195195
inline const char* feasible_solution_symbol(thread_type_t type)
196196
{
197197
switch (type) {
198-
case thread_type_t::EXPLORATION: return "B";
199-
case thread_type_t::DIVING: return "D";
200-
default: return "U";
198+
case thread_type_t::EXPLORATION: return "B ";
199+
case thread_type_t::DIVING: return "D ";
200+
default: return "U ";
201201
}
202202
}
203203

@@ -310,7 +310,7 @@ void branch_and_bound_t<i_t, f_t>::set_new_solution(const std::vector<f_t>& solu
310310
std::string gap = user_mip_gap<f_t>(user_obj, user_lower);
311311

312312
settings_.log.printf(
313-
"H %+13.6e %+10.6e %s %9.2f\n",
313+
"H %+13.6e %+10.6e %s %9.2f\n",
314314
user_obj,
315315
user_lower,
316316
gap.c_str(),
@@ -423,7 +423,7 @@ void branch_and_bound_t<i_t, f_t>::repair_heuristic_solutions()
423423
std::string user_gap = user_mip_gap<f_t>(obj, lower);
424424

425425
settings_.log.printf(
426-
"H %+13.6e %+10.6e %s %9.2f\n",
426+
"H %+13.6e %+10.6e %s %9.2f\n",
427427
obj,
428428
lower,
429429
user_gap.c_str(),
@@ -534,17 +534,17 @@ void branch_and_bound_t<i_t, f_t>::add_feasible_solution(f_t leaf_objective,
534534
f_t lower_bound = get_lower_bound();
535535
f_t obj = compute_user_objective(original_lp_, upper_bound_);
536536
f_t lower = compute_user_objective(original_lp_, lower_bound);
537-
settings_.log.printf(
538-
"%s%10d %10lu %+13.6e %+10.6e %6d %7.1e %s %9.2f\n",
539-
feasible_solution_symbol(thread_type),
540-
nodes_explored,
541-
nodes_unexplored,
542-
obj,
543-
lower,
544-
leaf_depth,
545-
nodes_explored > 0 ? exploration_stats_.total_lp_iters / nodes_explored : 0,
546-
user_mip_gap<f_t>(obj, lower).c_str(),
547-
toc(exploration_stats_.start_time));
537+
f_t iter_node = nodes_explored > 0 ? exploration_stats_.total_lp_iters / nodes_explored : 0;
538+
settings_.log.printf("%s%10d %10lu %+13.6e %+10.6e %6d %7.1e %s %9.2f\n",
539+
feasible_solution_symbol(thread_type),
540+
nodes_explored,
541+
nodes_unexplored,
542+
obj,
543+
lower,
544+
leaf_depth,
545+
iter_node,
546+
user_mip_gap<f_t>(obj, lower).c_str(),
547+
toc(exploration_stats_.start_time));
548548

549549
send_solution = true;
550550
}
@@ -611,18 +611,20 @@ node_solve_info_t branch_and_bound_t<i_t, f_t>::solve_node(
611611
ss << "simplex-" << std::this_thread::get_id() << ".log";
612612
std::string logname;
613613
ss >> logname;
614-
lp_settings.set_log_filename(logname);
615-
lp_settings.log.enable_log_to_file("a+");
614+
lp_settings.log.set_log_file(logname, "a");
616615
lp_settings.log.log_to_console = false;
617616
lp_settings.log.printf(
618-
"%s node id = %d, branch var = %d, fractional val = %f, variable lower bound = %f, variable "
619-
"upper bound = %f\n",
617+
"%scurrent node: id = %d, depth = %d, branch var = %d, branch dir = %s, fractional val = "
618+
"%f, variable lower bound = %f, variable upper bound = %f, branch vstatus = %d\n\n",
620619
settings_.log.log_prefix.c_str(),
621620
node_ptr->node_id,
621+
node_ptr->depth,
622622
node_ptr->branch_var,
623+
node_ptr->branch_dir == rounding_direction_t::DOWN ? "DOWN" : "UP",
623624
node_ptr->fractional_val,
624625
node_ptr->branch_var_lower,
625-
node_ptr->branch_var_upper);
626+
node_ptr->branch_var_upper,
627+
node_ptr->vstatus[node_ptr->branch_var]);
626628
#endif
627629

628630
// Reset the bound_changed markers
@@ -685,6 +687,10 @@ node_solve_info_t branch_and_bound_t<i_t, f_t>::solve_node(
685687
}
686688
}
687689

690+
#ifdef LOG_NODE_SIMPLEX
691+
lp_settings.log.printf("\nLP status: %d\n\n", lp_status);
692+
#endif
693+
688694
if (lp_status == dual::status_t::DUAL_UNBOUNDED) {
689695
// Node was infeasible. Do not branch
690696
node_ptr->lower_bound = inf;
@@ -810,17 +816,17 @@ void branch_and_bound_t<i_t, f_t>::exploration_ramp_up(mip_node_t<i_t, f_t>* nod
810816
std::string gap_user = user_mip_gap<f_t>(obj, user_lower);
811817
i_t nodes_explored = exploration_stats_.nodes_explored;
812818
i_t nodes_unexplored = exploration_stats_.nodes_unexplored;
813-
814-
settings_.log.printf(
815-
" %10d %10lu %+13.6e %+10.6e %6d %7.1e %s %9.2f\n",
816-
nodes_explored,
817-
nodes_unexplored,
818-
obj,
819-
user_lower,
820-
node->depth,
821-
nodes_explored > 0 ? exploration_stats_.total_lp_iters / nodes_explored : 0,
822-
gap_user.c_str(),
823-
now);
819+
f_t iter_node = nodes_explored > 0 ? exploration_stats_.total_lp_iters / nodes_explored : 0;
820+
821+
settings_.log.printf(" %10d %10lu %+13.6e %+10.6e %6d %7.1e %s %9.2f\n",
822+
nodes_explored,
823+
nodes_unexplored,
824+
obj,
825+
user_lower,
826+
node->depth,
827+
iter_node,
828+
gap_user.c_str(),
829+
now);
824830

825831
exploration_stats_.nodes_since_last_log = 0;
826832
exploration_stats_.last_log = tic();
@@ -941,17 +947,17 @@ void branch_and_bound_t<i_t, f_t>::explore_subtree(i_t task_id,
941947
std::string gap_user = user_mip_gap<f_t>(obj, user_lower);
942948
i_t nodes_explored = exploration_stats_.nodes_explored;
943949
i_t nodes_unexplored = exploration_stats_.nodes_unexplored;
944-
945-
settings_.log.printf(
946-
" %10d %10lu %+13.6e %+10.6e %6d %7.1e %s %9.2f\n",
947-
nodes_explored,
948-
nodes_unexplored,
949-
obj,
950-
user_lower,
951-
node_ptr->depth,
952-
nodes_explored > 0 ? exploration_stats_.total_lp_iters / nodes_explored : 0,
953-
gap_user.c_str(),
954-
now);
950+
f_t iter_node = nodes_explored > 0 ? exploration_stats_.total_lp_iters / nodes_explored : 0;
951+
952+
settings_.log.printf(" %10d %10lu %+13.6e %+10.6e %6d %7.1e %s %9.2f\n",
953+
nodes_explored,
954+
nodes_unexplored,
955+
obj,
956+
user_lower,
957+
node_ptr->depth,
958+
iter_node,
959+
gap_user.c_str(),
960+
now);
955961
exploration_stats_.last_log = tic();
956962
exploration_stats_.nodes_since_last_log = 0;
957963
}

cpp/src/dual_simplex/logger.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ class logger_t {
3030
{
3131
}
3232

33-
void enable_log_to_file(std::string mode = "w")
33+
void enable_log_to_file(const char* mode = "w")
3434
{
3535
if (log_file != nullptr) { std::fclose(log_file); }
36-
log_file = std::fopen(log_filename.c_str(), mode.c_str());
36+
log_file = std::fopen(log_filename.c_str(), mode);
3737
log_to_file = true;
3838
}
3939

40-
void set_log_file(const std::string& filename)
40+
void set_log_file(const std::string& filename, const char* mode = "w")
4141
{
4242
log_filename = filename;
43-
enable_log_to_file();
43+
enable_log_to_file(mode);
4444
}
4545

4646
void close_log_file()

0 commit comments

Comments
 (0)