I’m trying to reconstruct the optimization problem from the LP file that was generated from some commercial tool that has limited flexibility.
I found a few relevant postings here and learned that I have to use the direct mode.
Here’s the MWE of my case:
using JuMP, Gurobi
m = Model(Gurobi.Optimizer)
@variable(m, -1 <= x[i in 1:2] <= 3)
@objective(m, Min, 3x[1] - 5x[2])
write_to_file(m, "test_direct.lp")
Assuming the LP file was generated from the above code, the below code doesn’t work.
m2 = direct_model(Gurobi.Optimizer())
lp = read_from_file("test_direct.lp")
MOI.optimize!(backend(m2), lp);
all_variables(m2)
termination_status(m2)
value.(x_1_)
value.(m2[:x_1_])
Here’s the error message:
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.2.0 23C71)
CPU model: Apple M2 Pro
Thread count: 12 physical cores, 12 logical processors, using up to 12 threads
Optimize a model with 0 rows, 2 columns and 0 nonzeros
Model fingerprint: 0x3093ddcd
Coefficient statistics:
Matrix range [0e+00, 0e+00]
Objective range [3e+00, 5e+00]
Bounds range [1e+00, 3e+00]
RHS range [0e+00, 0e+00]
Presolve removed 0 rows and 2 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 -1.8000000e+01 0.000000e+00 0.000000e+00 0s
Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective -1.800000000e+01
User-callback calls 23, time in user-callback 0.00 sec
2-element Vector{VariableRef}:
x_1_
x_2_
OPTIMAL::TerminationStatusCode = 1
ERROR: UndefVarError: `x_1_` not defined
Stacktrace:
[1] top-level scope
@ ~/Dropbox/Julia/JuMP-lp_file/ex_writeLPfile.jl:14
ERROR: KeyError: key :x_1_ not found
Stacktrace:
[1] getindex(m::Model, name::Symbol)
@ JuMP ~/.julia/packages/JuMP/R53zo/src/JuMP.jl:918
[2] top-level scope
@ ~/Dropbox/Julia/JuMP-lp_file/ex_writeLPfile.jl:15
Can anyone let me know if there is a way to use value.(x)
in this circumstances?