Read .lp file into JuMP model in direct mode

Is it possible to read a .lp file into a JuMP optimization model in direct mode? I’m not sure how to combine direct_model and read_from_file to achieve this.

1 Like

What solver is in direct_model?

I guess you could do:

model = direct_model(Gurobi.Optimizer())
lp = read_from_file("model.lp")
MOI.copy_to(model, lp)

I’m planning to use Gurobi. That approach is raising the following error:

ERROR: copy_to is not supported by the solver Model. Did you mean to call optimize!(dest::AbstractOptimizer, src::ModelLike) instead?

I think that this will work, at least it worked in my computer locally with HiGHS.

model = direct_model(Gurobi.Optimizer())
lp = read_from_file("model.lp")
MOI.copy_to(backend(model), lp)
optimize!(model)

Other possibility is to call MOI.optimize! directly

model = direct_model(Gurobi.Optimizer())
lp = read_from_file("model.lp")
MOI.optimize!(backend(model), lp)
1 Like