diff --git a/src/Cuts/BlackBox/cplex.jl b/src/Cuts/BlackBox/cplex.jl index 5324dc6..bc37068 100644 --- a/src/Cuts/BlackBox/cplex.jl +++ b/src/Cuts/BlackBox/cplex.jl @@ -80,6 +80,11 @@ function collect( ncuts = length([cr for cr in constraints if select(cr)]) cuts_lhs = spzeros(ncuts, nvars) cuts_rhs = Float64[] + cuts_var_names = String[] + + for i in 0:(nvars-1) + push!(cuts_var_names, name(VariableRef(model, MOI.VariableIndex(i)))) + end offset = 1 for conRef in constraints @@ -98,6 +103,7 @@ function collect( h5 = Hdf5Sample(h5_filename) h5.put_sparse("cuts_cpx_lhs", cuts_lhs) h5.put_array("cuts_cpx_rhs", cuts_rhs) + h5.put_array("cuts_cpx_var_names", to_str_array(cuts_var_names)) h5.file.close() return diff --git a/src/MIPLearn.jl b/src/MIPLearn.jl index b2d5b95..3cb303a 100644 --- a/src/MIPLearn.jl +++ b/src/MIPLearn.jl @@ -43,7 +43,8 @@ function PyObject(m::SparseMatrixCSC) ).tocoo() end - include("Cuts/BlackBox/cplex.jl") +export Hdf5Sample + end # module \ No newline at end of file diff --git a/test/Cuts/BlackBox/test_cplex.jl b/test/Cuts/BlackBox/test_cplex.jl index adb87bc..7b97e50 100644 --- a/test/Cuts/BlackBox/test_cplex.jl +++ b/test/Cuts/BlackBox/test_cplex.jl @@ -3,6 +3,7 @@ # Released under the modified BSD license. See COPYING.md for more details. using HDF5 +using MIPLearn function test_cuts_blackbox_cplex() # Prepare filenames @@ -13,10 +14,10 @@ function test_cuts_blackbox_cplex() MIPLearn.collect(mps_filename, CplexBlackBoxCuts()) # Read HDF5 file - h5open(h5_filename, "r+") do h5 - rhs = h5["cuts_cpx_rhs"] - lhs = h5["cuts_cpx_lhs"] - ncuts = length(rhs) - @test size(lhs) == (ncuts, 104) - end + h5 = Hdf5Sample(h5_filename) + lhs = h5.get_sparse("cuts_cpx_lhs") + rhs = h5.get_array("cuts_cpx_rhs") + h5.file.close() + @test lhs.shape == (22, 100) + @test length(rhs) == 22 end diff --git a/test/Project.toml b/test/Project.toml index 8af131f..6639866 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,5 +1,6 @@ [deps] HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" MIPLearn = "2b1277c3-b477-4c49-a15e-7ba350325c68" Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"