mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
Conclude JumpModel
This commit is contained in:
@@ -6,6 +6,7 @@ version = "0.1.0"
|
||||
[deps]
|
||||
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
|
||||
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
|
||||
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
|
||||
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
|
||||
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
|
||||
MIPLearn = "2b1277c3-b477-4c49-a15e-7ba350325c68"
|
||||
|
||||
BIN
test/fixtures/bell5.h5
vendored
BIN
test/fixtures/bell5.h5
vendored
Binary file not shown.
@@ -1,3 +1,6 @@
|
||||
using JuMP
|
||||
import MIPLearn: from_str_array, to_str_array
|
||||
|
||||
function build_model()
|
||||
data = SetCoverData(
|
||||
costs = [5, 10, 12, 6, 8],
|
||||
@@ -12,6 +15,10 @@ end
|
||||
|
||||
function test_solvers_jump()
|
||||
test_solvers_jump_extract()
|
||||
test_solvers_jump_add_constrs()
|
||||
test_solvers_jump_fix_vars()
|
||||
test_solvers_jump_warm_starts()
|
||||
test_solvers_jump_write()
|
||||
end
|
||||
|
||||
function test_solvers_jump_extract()
|
||||
@@ -30,7 +37,7 @@ function test_solvers_jump_extract()
|
||||
end
|
||||
|
||||
function test_str_array(key, expected)
|
||||
actual = MIPLearn.from_str_array(h5.get_array(key))
|
||||
actual = from_str_array(h5.get_array(key))
|
||||
@debug actual, expected
|
||||
@test actual !== nothing
|
||||
@test all(actual .== expected)
|
||||
@@ -74,7 +81,7 @@ function test_solvers_jump_extract()
|
||||
test_array("lp_var_reduced_costs", [-5, 0, 6, 0, 2])
|
||||
test_array("lp_var_values", [1, 0, 0, 1, 0])
|
||||
test_str_array("lp_var_basis_status", ["U", "B", "L", "B", "L"])
|
||||
test_str_array("lp_constr_basis_status", ["B","N","N"])
|
||||
test_str_array("lp_constr_basis_status", ["B", "N", "N"])
|
||||
test_array("lp_constr_sa_rhs_up", [2, 2, 1])
|
||||
test_array("lp_constr_sa_rhs_down", [-Inf, 1, 0])
|
||||
test_array("lp_var_sa_obj_up", [10, Inf, Inf, 8, Inf])
|
||||
@@ -96,3 +103,54 @@ function test_solvers_jump_extract()
|
||||
mip_wallclock_time = h5.get_scalar("mip_wallclock_time")
|
||||
@test mip_wallclock_time >= 0
|
||||
end
|
||||
|
||||
function test_solvers_jump_add_constrs()
|
||||
h5 = H5File(tempname(), "w")
|
||||
model = build_model()
|
||||
model.extract_after_load(h5)
|
||||
model.add_constrs(
|
||||
to_str_array(["x[2]", "x[3]"]),
|
||||
[
|
||||
0 1
|
||||
1 0
|
||||
],
|
||||
to_str_array(["=", "="]),
|
||||
[0, 0],
|
||||
)
|
||||
model.optimize()
|
||||
model.extract_after_mip(h5)
|
||||
@test all(h5.get_array("mip_var_values") .≈ [1, 0, 0, 0, 1])
|
||||
end
|
||||
|
||||
function test_solvers_jump_fix_vars()
|
||||
h5 = H5File(tempname(), "w")
|
||||
model = build_model()
|
||||
model.extract_after_load(h5)
|
||||
model.fix_variables(
|
||||
to_str_array(["x[2]", "x[3]"]),
|
||||
[0, 0],
|
||||
)
|
||||
model.optimize()
|
||||
model.extract_after_mip(h5)
|
||||
@test all(h5.get_array("mip_var_values") .≈ [1, 0, 0, 0, 1])
|
||||
end
|
||||
|
||||
function test_solvers_jump_warm_starts()
|
||||
# TODO: Check presence of warm start on log file
|
||||
h5 = H5File(tempname(), "w")
|
||||
model = build_model()
|
||||
model.extract_after_load(h5)
|
||||
model.set_warm_starts(
|
||||
to_str_array(["x[0]", "x[1]", "x[2]", "x[3]", "x[4]"]),
|
||||
[1 0 0 0 1],
|
||||
)
|
||||
model.optimize()
|
||||
end
|
||||
|
||||
function test_solvers_jump_write()
|
||||
mps_filename = "$(tempname()).mps"
|
||||
model = build_model()
|
||||
model.write(mps_filename)
|
||||
@test isfile(mps_filename)
|
||||
rm(mps_filename)
|
||||
end
|
||||
Reference in New Issue
Block a user