Skip to content

Commit

Permalink
Use FW callback (ZIB-IOL#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhendryc authored Aug 26, 2022
1 parent 822d1d0 commit dd50936
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ function build_bnb_callback(tree, time_ref, list_lb_cb, list_ub_cb, list_time_cb

headers = [" ", "Iteration", "Open", "Bound", "Incumbent", "Gap (abs)", "Gap (rel)", "Time (s)", "Nodes/sec", "FW (ms)", "LMO (ms)", "LMO (calls c)", "FW (Its)", "#ActiveSet", "Discarded"]
format_string = "%1s %10i %10i %14e %14e %14e %14e %14e %14e %14i %14i %14i %10i %12i %10i\n"
#print_callback = FrankWolfe.print_callback
print_callback = FrankWolfe.print_callback
print_iter = get(tree.root.options, :print_iter, 100)

if verbose
print_callback_b(headers, format_string, print_header=true)
print_callback(headers, format_string, print_header=true)
end
return function callback(tree, node; worse_than_incumbent=false, node_infeasible=false, lb_update = false)
if !node_infeasible
Expand Down Expand Up @@ -258,9 +258,9 @@ function build_bnb_callback(tree, time_ref, list_lb_cb, list_ub_cb, list_time_cb
end
if verbose && (mod(iteration, print_iter) == 0 || iteration == 1 || Bonobo.terminated(tree) || tree.root.updated_incumbent[])
if (mod(iteration, print_iter*40) == 0)
print_callback_b(headers, format_string, print_header=true)
print_callback(headers, format_string, print_header=true)
end
print_callback_b((incumbent_updated, iteration, nodes_left, tree_lb(tree), tree.incumbent, dual_gap, relative_gap(tree.incumbent,tree_lb(tree)), time / 1000.0, tree.num_nodes/time * 1000.0, fw_time, LMO_time, tree.root.problem.lmo.ncalls, fw_iter, active_set_size, discarded_set_size), format_string, print_header=false)
print_callback((incumbent_updated, iteration, nodes_left, tree_lb(tree), tree.incumbent, dual_gap, relative_gap(tree.incumbent,tree_lb(tree)), time / 1000.0, tree.num_nodes/time * 1000.0, fw_time, LMO_time, tree.root.problem.lmo.ncalls, fw_iter, active_set_size, discarded_set_size), format_string, print_header=false)
tree.root.updated_incumbent[] = false
end
# lmo calls per layer
Expand Down
35 changes: 0 additions & 35 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,41 +231,6 @@ function sparse_min_via_enum(f, n, k, values = fill(0:1,n))
return best_val, best_sol
end

# ONLY a hack! Issue with eval in FrankWolfe
"""
print_callback(state,storage)
Handles formating of the callback state into a table format with consistent length independent of state values.
"""
function print_callback_b(data, format_string; print_header=false, print_footer=false)
print_formatted(fmt, args...) = @eval @printf($fmt, $(args...))
if print_header || print_footer
temp = strip(format_string, ['\n'])
temp = replace(temp, "%" => "")
temp = replace(temp, "e" => "")
temp = replace(temp, "i" => "")
temp = replace(temp, "s" => "")
temp = split(temp, " ")
len = 0
for i in temp
len = len + parse(Int, i)
end
lenHeaderFooter = len + 2 + length(temp) - 1
if print_footer
line = "-"^lenHeaderFooter
@printf("%s\n", line)
end
if print_header
line = "-"^lenHeaderFooter
@printf("\n%s\n", line)
s_format_string = replace(format_string, "e" => "s")
s_format_string = replace(s_format_string, "i" => "s")
print_formatted(s_format_string, data...)
@printf("%s\n", line)
end
else
print_formatted(format_string, data...)
end
end

# utility function to print the values of the parameters
_value_to_print(::Bonobo.BFS) = "Move best bound"
Expand Down

0 comments on commit dd50936

Please sign in to comment.