BB: Fix incorrect set_bounds call; add failing tests

master
Alinson S. Xavier 3 years ago
parent adba8389ce
commit a8e6c6da22
Signed by: isoron
GPG Key ID: 0DA8E4B9E1109DCA

@ -58,6 +58,13 @@ function solve!(
sleep(0.1)
continue
else
# Assert node is feasible
_set_node_bounds(node)
status, _ = solve_relaxation!(mip)
@assert status == :Optimal
_unset_node_bounds(node)
# Find branching variable
ids = generate_indices(pool, 2)
branch_var = find_branching_var(branch_rule, node, pool)
@ -136,8 +143,7 @@ function _create_node(
fractional_variables = Variable[]
fractional_values = Float64[]
end
n_branch = length(branch_vars)
set_bounds!(mip, branch_vars, zeros(n_branch), ones(n_branch))
set_bounds!(mip, mip.int_vars, mip.int_vars_lb, mip.int_vars_ub)
return Node(
mip,
index,
@ -197,3 +203,11 @@ function solve!(
return pool
end
function _set_node_bounds(node::Node)
set_bounds!(node.mip, node.branch_vars, node.branch_lb, node.branch_ub)
end
function _unset_node_bounds(node::Node)
set_bounds!(node.mip, node.mip.int_vars, node.mip.int_vars_lb, node.mip.int_vars_ub)
end

@ -34,7 +34,7 @@ function find_branching_var(
]
σ = sortperm(pseudocost_scores, rev = true)
sorted_vars = node.fractional_variables[σ]
_strong_branch_start(node)
_set_node_bounds(node)
no_improv_count, n_sb_calls = 0, 0
max_score, max_var = pseudocost_scores[σ[1]], sorted_vars[1]
for (i, var) in enumerate(sorted_vars)
@ -72,6 +72,6 @@ function find_branching_var(
end
no_improv_count <= rule.look_ahead || break
end
_strong_branch_end(node)
_unset_node_bounds(node)
return max_var
end

@ -32,7 +32,7 @@ function find_branching_var(rule::StrongBranching, node::Node, pool::NodePool)::
]
σ = sortperm(pseudocost_scores, rev = true)
sorted_vars = node.fractional_variables[σ]
_strong_branch_start(node)
_set_node_bounds(node)
no_improv_count, call_count = 0, 0
max_score, max_var = (-Inf, -Inf), sorted_vars[1]
for (i, var) in enumerate(sorted_vars)
@ -55,7 +55,7 @@ function find_branching_var(rule::StrongBranching, node::Node, pool::NodePool)::
no_improv_count <= rule.look_ahead || break
call_count <= rule.max_calls || break
end
_strong_branch_end(node)
_unset_node_bounds(node)
return max_var
end
@ -94,11 +94,3 @@ function _strong_branch_score(;
end
return (obj_change_up * obj_change_down, var.index)
end
function _strong_branch_start(node::Node)
set_bounds!(node.mip, node.branch_vars, node.branch_lb, node.branch_ub)
end
function _strong_branch_end(node::Node)
set_bounds!(node.mip, node.mip.int_vars, node.mip.int_vars_lb, node.mip.int_vars_ub)
end

@ -6,6 +6,7 @@ using Clp
using JuMP
using Test
using MIPLearn.BB
using MIPLearn
basepath = @__DIR__
@ -80,13 +81,20 @@ function runtests(optimizer_name, optimizer; large = true)
BB.HybridBranching(),
]
for branch_rule in branch_rules
filename = "$basepath/../fixtures/vpm2.mps.gz"
for instance in ["bell5", "vpm2"]
h5 = Hdf5Sample("$basepath/../fixtures/$instance.h5")
mip_lower_bound = h5.get_scalar("mip_lower_bound")
mip_upper_bound = h5.get_scalar("mip_upper_bound")
mip_sense = h5.get_scalar("mip_sense")
mip_primal_bound = mip_sense == "min" ? mip_upper_bound : mip_lower_bound
h5.file.close()
mip = BB.init(optimizer)
BB.read!(mip, filename)
@info optimizer_name, branch_rule
BB.read!(mip, "$basepath/../fixtures/$instance.mps.gz")
@info optimizer_name, branch_rule, instance
@time BB.solve!(
mip,
initial_primal_bound = 13.75,
initial_primal_bound = mip_primal_bound,
print_interval = 10,
node_limit = 100,
branch_rule = branch_rule,
@ -95,6 +103,7 @@ function runtests(optimizer_name, optimizer; large = true)
end
end
end
end
@testset "BB" begin
# @time runtests(

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save