Read MPS file using MathOptInterface and extract each variable from MOI

Please read the below code. It can read MPS file. How can I get each variable from m? Please share the code.

using JuMP
using GLPK
using MathOptInterface

const MOI = MathOptInterface
mathoptformat_model = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MPS)
FILE_NAME=“E:\file1.mps”
MOI.read_from_file(mathoptformat_model, FILE_NAME)
m = Model(GLPK.Optimizer)
MOI.copy_to(m, mathoptformat_model)

Did you try JuMP.all_variables?

gr8

1 Like