In my JuMP model, the LP file preserves the original variable names, but the MPS file appears to rename them, so how can I map the Gurobi .sol solution back to the original JuMP variables?

Hi everyone,

I’m generating both .lp and .mps files from the same JuMP model using Gurobi.

In the LP file, the original JuMP variable names are preserved, for example:

1200 x2[1,(1,_0)]
- 41054.62117964038 B2[1,(1,_0)]
- 0.15 Tnk[1,1]

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!

This answer by Oscar showed up, could you try that? JuMP : how to read a lp problem from file (lp FORMAT) with variables names? - #2 by odow

Hi @amit_97,

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