JuMP : how to read a lp problem from file (lp FORMAT) with variables names?

Hi,

I read a linear problem:

my_model = JuMP.read_from_file("toto.lp")

but it seems that the variable names used in the file are lost and I wonder how to display the solution:

A JuMP Model
├ solver: none
├ objective_sense: MIN_SENSE
│ └ objective_function_type: JuMP.AffExpr
├ num_variables: 295
├ num_constraints: 639
│ ├ JuMP.AffExpr in MOI.EqualTo{Float64}: 105
│ ├ JuMP.AffExpr in MOI.LessThan{Float64}: 31
│ ├ JuMP.VariableRef in MOI.EqualTo{Float64}: 85
│ ├ JuMP.VariableRef in MOI.GreaterThan{Float64}: 209
│ └ JuMP.VariableRef in MOI.LessThan{Float64}: 209
└ Names registered in the model: none
JuMP.set_optimizer(mrg_model,HiGHS.Optimizer)
optimize!(problem.model)
LP   has 136 rows; 295 cols; 522 nonzeros
Coefficient ranges:
  Matrix [1e-02, 1e+01]
  Cost   [3e-03, 1e+00]
  Bound  [6e-04, 7e+00]
  RHS    [3e-04, 6e+00]
Solving LP without presolve, or with basis, or unconstrained
Model status        : Optimal
Objective value     : -8.0420908334e-01
P-D objective error :  1.2768923006e-16
HiGHS run time      :          0.00

Any idea ?

So “Names registered in the model: none” means that we didn’t store anything in object_dictionary(model), so you can’t do, for example, model[:x].

But variable and constraint names are read, so you can do variable_by_name(model, "x").

To display the solution, you could do:

solution = Dict(name(x) => value(x) for x in all_variables(model))
1 Like

Thank you very much !

1 Like