However, in the MPS file, the variables/constraints appear to be renamed to generic names such as:
c0
c1
c2
...
I solve the MPS file on another machine using Gurobi and get a feasible solution in a .sol file.
My problem is that I want to map the .sol solution back to the original JuMP variables, such as:
x2[1,(1,_0)]
B2[1,(1,_0)]
Tnk[1,1]
but because the MPS file uses different/generic names, I’m not able to identify which solution variable corresponds to which original JuMP variable.
The model is generated in Julia, solved on another machine from the exported MPS, and then I want to analyze the solution back in my original Julia code.
Any recommended workflow for this would be helpful. Thanks!
JuMP’s MPS write does preserve names, but the MPS file does have some limits on what names it can preserve.
julia> using JuMP
julia> begin
model = Model()
@variable(model, x >= 0)
@objective(model, Min, 2 * x)
@constraint(model, c, x <= 1)
write_to_file(model, "/tmp/model.mps")
print(read("/tmp/model.mps", String))
end
NAME
ROWS
N OBJ
L c
COLUMNS
x c 1
x OBJ 2
RHS
rhs c 1
RANGES
BOUNDS
LO bounds x 0
PL bounds x
ENDATA
Use the MathOptFormat file instead:
julia> begin # Computer A
using JuMP
model = Model()
@variable(model, x >= 0)
@objective(model, Min, 2 * x)
@constraint(model, c, x <= 1)
write_to_file(model, "/tmp/model.mof.json")
end
julia> begin # Computer B
using JuMP, Gurobi, JSON
model = read_from_file("/tmp/model.mof.json")
set_optimizer(model, Gurobi.Optimizer)
set_silent(model)
optimize!(model)
write(
"/tmp/sol.json",
JSON.json(Dict(name(x) => value(x) for x in all_variables(model))),
)
end;
Set parameter WLSAccessID
Set parameter WLSSecret
Set parameter LicenseID to value 722777
WLS license 722777 - registered to JuMP Development
julia> begin # Computer A
using JSON
JSON.parsefile("/tmp/sol.json")
end
JSON.Object{String, Any} with 1 entry:
"x" => 0.0