Skip to content

Commit

Permalink
Postsolve (#114)
Browse files Browse the repository at this point in the history
* restructure postsolve

* update print statement

* end block

* adapt callback

Co-authored-by: Mathieu Besançon <[email protected]>
  • Loading branch information
hannahtro and matbesancon authored Jan 6, 2023
1 parent f300ba5 commit ddd2b0e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
26 changes: 13 additions & 13 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,24 +514,24 @@ function postsolve(tree, result, time_ref, verbose, use_postsolve, max_iteration
)

# update tree
if primal <= tree.incumbent + 1e-2
if primal < tree.incumbent
tree.root.updated_incumbent[] = true
tree.incumbent = primal
tree.lb = tree.root.problem.solving_stage == OPT_TREE_EMPTY ? primal - dual_gap : tree.lb
else
if tree.lb > primal - dual_gap
@warn "tree.lb > primal - dual_gap"
end
end
if primal < tree.incumbent
tree.root.updated_incumbent[] = true
tree.incumbent = primal
tree.lb = tree.root.problem.solving_stage == OPT_TREE_EMPTY ? primal - dual_gap : tree.lb
tree.incumbent_solution.objective = tree.solutions[1].objective = primal
tree.incumbent_solution.solution = tree.solutions[1].solution = x
else
@warn "primal > tree.incumbent + 1e-2"
if primal < tree.incumbent && tree.lb > primal - dual_gap
@warn "tree.lb > primal - dual_gap"
else
@warn "primal >= tree.incumbent"
end
@warn "postsolve did not improve the solution"
primal = tree.incumbent_solution.objective = tree.solutions[1].objective
x = tree.incumbent_solution.solution = tree.solutions[1].solution
end
end


result[:primal_objective] = primal
result[:dual_bound] = tree_lb(tree)
result[:rel_dual_gap] = relative_gap(primal, tree_lb(tree))
Expand Down Expand Up @@ -559,7 +559,7 @@ function postsolve(tree, result, time_ref, verbose, use_postsolve, max_iteration
println("\t LMO calls / node: $(tree.root.problem.lmo.ncalls / tree.num_nodes)\n")
end

# Reset LMO
# Reset LMO
int_bounds = IntegerBounds()
build_LMO(
tree.root.problem.lmo,
Expand Down
2 changes: 1 addition & 1 deletion test/mean_risk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const M1 = (A1 + A1') / 2
)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down
8 changes: 4 additions & 4 deletions test/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ N = 5.0
)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -304,7 +304,7 @@ end
)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -484,7 +484,7 @@ push!(groups, ((k-1)*group_size+1):pg)
)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -646,7 +646,7 @@ end
)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ include("interface_test.jl")
node = Bonobo.get_next_node(tree, tree.options.traverse_strategy)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -228,7 +228,7 @@ const diff = Random.rand(Bool, n) * 0.6 .+ 0.3
),
)
function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -320,7 +320,7 @@ end
),
)
function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -402,7 +402,7 @@ const diff1 = rand(Bool, n1) * 0.8 .+ 1.1
end
function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -506,7 +506,7 @@ const diff1 = rand(Bool, n1) * 0.8 .+ 1.1
)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -610,7 +610,7 @@ end
)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down Expand Up @@ -718,7 +718,7 @@ end
)

function build_FW_callback(tree)
return function fw_callback(state, active_set)
return function fw_callback(state, active_set, args...)
# print("Primal: $(state.primal)\n")
# print("Length of active set: $(length(active_set.weights))\n")
end
Expand Down
4 changes: 2 additions & 2 deletions test/sparse_regression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const M = 2 * var(A)
)

function build_FW_callback(tree)
return function fw_callback(state, active_set) end
return function fw_callback(state, active_set, args...) end
end

fw_callback = build_FW_callback(tree)
Expand Down Expand Up @@ -284,7 +284,7 @@ push!(groups, ((k_int-1)*group_size+p+1):2p)
)

function build_FW_callback(tree)
return function fw_callback(state, active_set) end
return function fw_callback(state, active_set, args...) end
end

fw_callback = build_FW_callback(tree)
Expand Down

0 comments on commit ddd2b0e

Please sign in to comment.