mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
BB: Fix incorrect set_bounds call; add failing tests
This commit is contained in:
@@ -58,6 +58,13 @@ function solve!(
|
|||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
continue
|
continue
|
||||||
else
|
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)
|
ids = generate_indices(pool, 2)
|
||||||
branch_var = find_branching_var(branch_rule, node, pool)
|
branch_var = find_branching_var(branch_rule, node, pool)
|
||||||
|
|
||||||
@@ -136,8 +143,7 @@ function _create_node(
|
|||||||
fractional_variables = Variable[]
|
fractional_variables = Variable[]
|
||||||
fractional_values = Float64[]
|
fractional_values = Float64[]
|
||||||
end
|
end
|
||||||
n_branch = length(branch_vars)
|
set_bounds!(mip, mip.int_vars, mip.int_vars_lb, mip.int_vars_ub)
|
||||||
set_bounds!(mip, branch_vars, zeros(n_branch), ones(n_branch))
|
|
||||||
return Node(
|
return Node(
|
||||||
mip,
|
mip,
|
||||||
index,
|
index,
|
||||||
@@ -197,3 +203,11 @@ function solve!(
|
|||||||
|
|
||||||
return pool
|
return pool
|
||||||
end
|
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)
|
σ = sortperm(pseudocost_scores, rev = true)
|
||||||
sorted_vars = node.fractional_variables[σ]
|
sorted_vars = node.fractional_variables[σ]
|
||||||
_strong_branch_start(node)
|
_set_node_bounds(node)
|
||||||
no_improv_count, n_sb_calls = 0, 0
|
no_improv_count, n_sb_calls = 0, 0
|
||||||
max_score, max_var = pseudocost_scores[σ[1]], sorted_vars[1]
|
max_score, max_var = pseudocost_scores[σ[1]], sorted_vars[1]
|
||||||
for (i, var) in enumerate(sorted_vars)
|
for (i, var) in enumerate(sorted_vars)
|
||||||
@@ -72,6 +72,6 @@ function find_branching_var(
|
|||||||
end
|
end
|
||||||
no_improv_count <= rule.look_ahead || break
|
no_improv_count <= rule.look_ahead || break
|
||||||
end
|
end
|
||||||
_strong_branch_end(node)
|
_unset_node_bounds(node)
|
||||||
return max_var
|
return max_var
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function find_branching_var(rule::StrongBranching, node::Node, pool::NodePool)::
|
|||||||
]
|
]
|
||||||
σ = sortperm(pseudocost_scores, rev = true)
|
σ = sortperm(pseudocost_scores, rev = true)
|
||||||
sorted_vars = node.fractional_variables[σ]
|
sorted_vars = node.fractional_variables[σ]
|
||||||
_strong_branch_start(node)
|
_set_node_bounds(node)
|
||||||
no_improv_count, call_count = 0, 0
|
no_improv_count, call_count = 0, 0
|
||||||
max_score, max_var = (-Inf, -Inf), sorted_vars[1]
|
max_score, max_var = (-Inf, -Inf), sorted_vars[1]
|
||||||
for (i, var) in enumerate(sorted_vars)
|
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
|
no_improv_count <= rule.look_ahead || break
|
||||||
call_count <= rule.max_calls || break
|
call_count <= rule.max_calls || break
|
||||||
end
|
end
|
||||||
_strong_branch_end(node)
|
_unset_node_bounds(node)
|
||||||
return max_var
|
return max_var
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -94,11 +94,3 @@ function _strong_branch_score(;
|
|||||||
end
|
end
|
||||||
return (obj_change_up * obj_change_down, var.index)
|
return (obj_change_up * obj_change_down, var.index)
|
||||||
end
|
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 JuMP
|
||||||
using Test
|
using Test
|
||||||
using MIPLearn.BB
|
using MIPLearn.BB
|
||||||
|
using MIPLearn
|
||||||
|
|
||||||
basepath = @__DIR__
|
basepath = @__DIR__
|
||||||
|
|
||||||
@@ -80,17 +81,25 @@ function runtests(optimizer_name, optimizer; large = true)
|
|||||||
BB.HybridBranching(),
|
BB.HybridBranching(),
|
||||||
]
|
]
|
||||||
for branch_rule in branch_rules
|
for branch_rule in branch_rules
|
||||||
filename = "$basepath/../fixtures/vpm2.mps.gz"
|
for instance in ["bell5", "vpm2"]
|
||||||
mip = BB.init(optimizer)
|
h5 = Hdf5Sample("$basepath/../fixtures/$instance.h5")
|
||||||
BB.read!(mip, filename)
|
mip_lower_bound = h5.get_scalar("mip_lower_bound")
|
||||||
@info optimizer_name, branch_rule
|
mip_upper_bound = h5.get_scalar("mip_upper_bound")
|
||||||
@time BB.solve!(
|
mip_sense = h5.get_scalar("mip_sense")
|
||||||
mip,
|
mip_primal_bound = mip_sense == "min" ? mip_upper_bound : mip_lower_bound
|
||||||
initial_primal_bound = 13.75,
|
h5.file.close()
|
||||||
print_interval = 10,
|
|
||||||
node_limit = 100,
|
mip = BB.init(optimizer)
|
||||||
branch_rule = branch_rule,
|
BB.read!(mip, "$basepath/../fixtures/$instance.mps.gz")
|
||||||
)
|
@info optimizer_name, branch_rule, instance
|
||||||
|
@time BB.solve!(
|
||||||
|
mip,
|
||||||
|
initial_primal_bound = mip_primal_bound,
|
||||||
|
print_interval = 10,
|
||||||
|
node_limit = 100,
|
||||||
|
branch_rule = branch_rule,
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
BIN
test/fixtures/bell5.h5
vendored
Normal file
BIN
test/fixtures/bell5.h5
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/bell5.mps.gz
vendored
Normal file
BIN
test/fixtures/bell5.mps.gz
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/vpm2.h5
vendored
Normal file
BIN
test/fixtures/vpm2.h5
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user