mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
Remove MPS from HDF5 file
This commit is contained in:
@@ -6,23 +6,30 @@ using JuMP
|
||||
using MIPLearn
|
||||
using Cbc
|
||||
|
||||
|
||||
@testset "FileInstance" begin
|
||||
@testset "solve" begin
|
||||
model = build_knapsack_model()
|
||||
instance = JuMPInstance(model)
|
||||
@testset "Solve" begin
|
||||
data = KnapsackData()
|
||||
filename = tempname()
|
||||
save(filename, instance)
|
||||
|
||||
h5 = MIPLearn.Hdf5Sample(filename)
|
||||
@test h5.get_scalar("miplearn_version") == "0002"
|
||||
@test length(h5.get_bytes("mps")) > 0
|
||||
@test length(h5.get_scalar("jump_ext")) > 0
|
||||
|
||||
file_instance = FileInstance(filename)
|
||||
MIPLearn.save_data(filename, data)
|
||||
instance = FileInstance(filename, build_knapsack_model)
|
||||
solver = LearningSolver(Cbc.Optimizer)
|
||||
solve!(solver, file_instance)
|
||||
solve!(solver, instance)
|
||||
|
||||
@test length(h5.get_array("mip_var_values")) == 3
|
||||
h5 = Hdf5Sample(filename)
|
||||
@test h5.get_scalar("mip_wallclock_time") > 0
|
||||
end
|
||||
|
||||
@testset "Save and load data" begin
|
||||
filename = tempname()
|
||||
data = KnapsackData(
|
||||
weights = [5.0, 5.0, 5.0],
|
||||
prices = [1.0, 1.0, 1.0],
|
||||
capacity = 3.0,
|
||||
)
|
||||
MIPLearn.save_data(filename, data)
|
||||
loaded = MIPLearn.load_data(filename)
|
||||
@test loaded.weights == [5.0, 5.0, 5.0]
|
||||
@test loaded.prices == [1.0, 1.0, 1.0]
|
||||
@test loaded.capacity == 3.0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ function enforce_lazy(model::Model, cb_data, violation::String)::Nothing
|
||||
return
|
||||
end
|
||||
|
||||
function build_model()
|
||||
function build_model(data)
|
||||
model = Model()
|
||||
@variable(model, x, Bin)
|
||||
@variable(model, y, Bin)
|
||||
@@ -41,7 +41,7 @@ end
|
||||
|
||||
@testset "Lazy callback" begin
|
||||
@testset "JuMPInstance" begin
|
||||
model = build_model()
|
||||
model = build_model(nothing)
|
||||
instance = JuMPInstance(model)
|
||||
solver = LearningSolver(Cbc.Optimizer)
|
||||
solve!(solver, instance)
|
||||
@@ -50,13 +50,12 @@ end
|
||||
end
|
||||
|
||||
@testset "FileInstance" begin
|
||||
model = build_model()
|
||||
instance = JuMPInstance(model)
|
||||
data = nothing
|
||||
filename = tempname()
|
||||
save(filename, instance)
|
||||
file_instance = FileInstance(filename, lazycb = (find_lazy, enforce_lazy))
|
||||
MIPLearn.save_data(filename, data)
|
||||
instance = FileInstance(filename, build_model)
|
||||
solver = LearningSolver(Cbc.Optimizer)
|
||||
solve!(solver, file_instance)
|
||||
solve!(solver, instance)
|
||||
h5 = MIPLearn.Hdf5Sample(filename)
|
||||
@test h5.get_array("mip_var_values") == [1.0, 0.0]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user