|
|
@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
using JuMP
|
|
|
|
|
|
|
|
import MIPLearn: from_str_array, to_str_array
|
|
|
|
|
|
|
|
|
|
|
|
function build_model()
|
|
|
|
function build_model()
|
|
|
|
data = SetCoverData(
|
|
|
|
data = SetCoverData(
|
|
|
|
costs = [5, 10, 12, 6, 8],
|
|
|
|
costs = [5, 10, 12, 6, 8],
|
|
|
@ -12,6 +15,10 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
function test_solvers_jump()
|
|
|
|
function test_solvers_jump()
|
|
|
|
test_solvers_jump_extract()
|
|
|
|
test_solvers_jump_extract()
|
|
|
|
|
|
|
|
test_solvers_jump_add_constrs()
|
|
|
|
|
|
|
|
test_solvers_jump_fix_vars()
|
|
|
|
|
|
|
|
test_solvers_jump_warm_starts()
|
|
|
|
|
|
|
|
test_solvers_jump_write()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function test_solvers_jump_extract()
|
|
|
|
function test_solvers_jump_extract()
|
|
|
@ -30,7 +37,7 @@ function test_solvers_jump_extract()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function test_str_array(key, expected)
|
|
|
|
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
|
|
|
|
@debug actual, expected
|
|
|
|
@test actual !== nothing
|
|
|
|
@test actual !== nothing
|
|
|
|
@test all(actual .== expected)
|
|
|
|
@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_reduced_costs", [-5, 0, 6, 0, 2])
|
|
|
|
test_array("lp_var_values", [1, 0, 0, 1, 0])
|
|
|
|
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_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_up", [2, 2, 1])
|
|
|
|
test_array("lp_constr_sa_rhs_down", [-Inf, 1, 0])
|
|
|
|
test_array("lp_constr_sa_rhs_down", [-Inf, 1, 0])
|
|
|
|
test_array("lp_var_sa_obj_up", [10, Inf, Inf, 8, Inf])
|
|
|
|
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")
|
|
|
|
mip_wallclock_time = h5.get_scalar("mip_wallclock_time")
|
|
|
|
@test mip_wallclock_time >= 0
|
|
|
|
@test mip_wallclock_time >= 0
|
|
|
|
end
|
|
|
|
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
|