|
|
|
@ -3,7 +3,7 @@
|
|
|
|
|
# Released under the modified BSD license. See COPYING.md for more details.
|
|
|
|
|
|
|
|
|
|
using JuMP
|
|
|
|
|
using JLD2
|
|
|
|
|
import JSON
|
|
|
|
|
|
|
|
|
|
mutable struct JuMPInstance <: Instance
|
|
|
|
|
py::Union{Nothing,PyCall.PyObject}
|
|
|
|
@ -75,42 +75,31 @@ function save(filename::AbstractString, instance::JuMPInstance)::Nothing
|
|
|
|
|
write_to_file(model, mps_filename)
|
|
|
|
|
mps = read(mps_filename)
|
|
|
|
|
|
|
|
|
|
# Pickle instance.py.samples. Ideally, we would use dumps and loads, but this
|
|
|
|
|
# causes some issues with PyCall, probably due to automatic type conversions.
|
|
|
|
|
samples_filename = tempname()
|
|
|
|
|
miplearn.write_pickle_gz(instance.samples, samples_filename)
|
|
|
|
|
samples = read(samples_filename)
|
|
|
|
|
|
|
|
|
|
# Generate JLD2 file
|
|
|
|
|
jldsave(
|
|
|
|
|
filename;
|
|
|
|
|
miplearn_version="0.2",
|
|
|
|
|
mps=mps,
|
|
|
|
|
ext=model.ext[:miplearn],
|
|
|
|
|
samples=samples,
|
|
|
|
|
)
|
|
|
|
|
# Generate HDF5
|
|
|
|
|
h5 = Hdf5Sample(filename, mode="w")
|
|
|
|
|
h5.put_scalar("miplearn_version", "0002")
|
|
|
|
|
h5.put_bytes("mps", mps)
|
|
|
|
|
h5.put_scalar("jump_ext", JSON.json(model.ext[:miplearn]))
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function _check_miplearn_version(file)
|
|
|
|
|
v = file["miplearn_version"]
|
|
|
|
|
v == "0.2" || error(
|
|
|
|
|
function _check_miplearn_version(h5)
|
|
|
|
|
v = h5.get_scalar("miplearn_version")
|
|
|
|
|
v == "0002" || error(
|
|
|
|
|
"The file you are trying to load has been generated by " *
|
|
|
|
|
"MIPLearn $(v) and you are currently running MIPLearn 0.2. " *
|
|
|
|
|
"MIPLearn $(v) and you are currently running MIPLearn 0002 " *
|
|
|
|
|
"Reading files generated by different versions of MIPLearn is " *
|
|
|
|
|
"not currently supported."
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function load_instance(filename::AbstractString)::JuMPInstance
|
|
|
|
|
jldopen(filename, "r") do file
|
|
|
|
|
_check_miplearn_version(file)
|
|
|
|
|
instance = JuMPInstance(file["mps"], file["ext"])
|
|
|
|
|
samples_filename = tempname()
|
|
|
|
|
write(samples_filename, file["samples"])
|
|
|
|
|
instance.samples = miplearn.read_pickle_gz(samples_filename)
|
|
|
|
|
h5 = Hdf5Sample(filename)
|
|
|
|
|
_check_miplearn_version(h5)
|
|
|
|
|
mps = h5.get_bytes("mps")
|
|
|
|
|
ext = h5.get_scalar("jump_ext")
|
|
|
|
|
instance = JuMPInstance(Vector{UInt8}(mps), JSON.parse(ext))
|
|
|
|
|
return instance
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
export JuMPInstance, save, load_instance
|
|
|
|
|