Hi,
i am currently developing a mixed integer model and need to pass an initial solution from a previous run to Gurobi. I probably could do it using JuMP’s setvalue()
function. It would be much more handy however, to just generate an *.mst file from a solved model to then pass it to the solver before the next run.
I was already successful in generating an *.mst file by using MyJuMPModel.internalModel.inner
. This is how I generated the file:
grb_mod = MyJuMPModel.internalModel.inner
write_model(grb_mod, "out.mst")
I read on Gurobi’s website that the function GRBread()
can be used to provide the solver with a starting vector, by passing an *.mst file. Unfortunately, this function is currently not exposed in the Gurobi
package. Thus, I was trying to expose this function with limited success. Limited success meaning that I do not get error messages but Gurobi does not seem to use the starting vector.
In the Gurobi
package I added the following function to grb_model.jl
:
function grb_read(model::Model, filename::String)
@assert isascii(filename) # TODO: support non-ascii file names
@assert model.ptr_model != C_NULL
ret = @grb_ccall(read, Cint,
(Ptr{Void}, Ptr{UInt8}),
model.ptr_model, filename)
if ret != 0
throw(GurobiError(model.env, ret))
end
nothing
end
Also, I added this function in the export section of the Gurobi.jl
file.
This function is based on a call of GRBread()
in one of Gurobi’s '.cpp files.
GRBModel::read(const string& filename)
{
if (Cmodel == NULL) throw
GRBException("Model not loaded", GRB_ERROR_INTERNAL);
int error = GRBread(Cmodel, filename.c_str());
if (error) throw GRBException(string(GRBgeterrormsg(Cenv)), error);
}
Some advice or thoughts on this would be great.
Is it possible to use *.mst files for this purpose?
Since, I was not getting any errors, but the internalModel
does not seem to change, I figured that something must be wrong with the pointer to the model in the function. I do not have any experience with ccalls in Julia.
Anton
I provided a detailed solution in an answer below.