Add gmi test; update H5

This commit is contained in:
2024-05-29 09:48:54 -05:00
parent 93e604817b
commit 1c204d765e
9 changed files with 39 additions and 8 deletions

View File

@@ -86,11 +86,7 @@ function bb_run(optimizer_name, optimizer; large = true)
BB.ReliabilityBranching(aggregation = :min, collect = true),
]
h5 = H5File("$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
mip_obj_bound = h5.get_scalar("mip_obj_bound")
h5.file.close()
mip = BB.init(optimizer)
@@ -98,7 +94,7 @@ function bb_run(optimizer_name, optimizer; large = true)
@info optimizer_name, branch_rule, instance
@time BB.solve!(
mip,
initial_primal_bound = mip_primal_bound,
initial_primal_bound = mip_obj_bound,
print_interval = 1,
node_limit = 25,
branch_rule = branch_rule,

View File

@@ -0,0 +1,23 @@
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
# Copyright (C) 2020-2024, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.
using HiGHS
function test_cuts_tableau_gmi()
mps_filename = "$BASEDIR/../fixtures/bell5.mps.gz"
h5_filename = "$BASEDIR/../fixtures/bell5.h5"
collect_gmi(mps_filename, optimizer = HiGHS.Optimizer)
h5 = H5File(h5_filename, "r")
try
cuts_lb = h5.get_array("cuts_lb")
cuts_ub = h5.get_array("cuts_ub")
cuts_lhs = h5.get_sparse("cuts_lhs")
n_cuts = length(cuts_lb)
@test n_cuts > 0
@test n_cuts == length(cuts_ub)
@test cuts_lhs.shape[1] == n_cuts
finally
h5.close()
end
end

View File

@@ -19,6 +19,7 @@ include("BB/test_bb.jl")
include("components/test_cuts.jl")
include("components/test_lazy.jl")
include("Cuts/BlackBox/test_cplex.jl")
include("Cuts/tableau/test_gmi.jl")
include("problems/test_setcover.jl")
include("problems/test_stab.jl")
include("problems/test_tsp.jl")

View File

@@ -4,6 +4,7 @@
using MIPLearn
using JLD2
using SparseArrays
struct _TestStruct
n::Int
@@ -35,6 +36,8 @@ function test_h5()
_test_roundtrip_array(h5, [1, 2, 3])
_test_roundtrip_array(h5, [1.0, 2.0, 3.0])
_test_roundtrip_str_array(h5, ["A", "BB", "CCC"])
_test_roundtrip_sparse(h5, sparse([1; 2; 3], [1; 2; 3], [1; 2; 3]))
# _test_roundtrip_sparse(h5, sparse([1; 2; 3], [1; 2; 3], [1; 2; 3], 4, 4))
@test h5.get_array("unknown-key") === nothing
h5.close()
end
@@ -79,3 +82,11 @@ function _test_roundtrip_str_array(h5, original)
@test recovered !== nothing
@test all(original .== recovered)
end
function _test_roundtrip_sparse(h5, original)
h5.put_sparse("key", original)
recovered = MIPLearn.convert(SparseMatrixCSC, h5.get_sparse("key"))
@test recovered !== nothing
@test size(original) == size(recovered)
@test all(original .== recovered)
end