Cuts: Store variable names

master
Alinson S. Xavier 3 years ago
parent 41f9234de1
commit b5a76e4588
Signed by: isoron
GPG Key ID: 0DA8E4B9E1109DCA

@ -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

@ -43,7 +43,8 @@ function PyObject(m::SparseMatrixCSC)
).tocoo()
end
include("Cuts/BlackBox/cplex.jl")
export Hdf5Sample
end # module

@ -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

@ -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"

Loading…
Cancel
Save