# Read MPS file using MathOptInterface and extract each variable from MOI

**URL:** <https://discourse.julialang.org/t/read-mps-file-using-mathoptinterface-and-extract-each-variable-from-moi/72753>\
**Category:** Optimization (Mathematical)\
**Created:** [December 8, 2021, 8:32am UTC](https://discourse.julialang.org/t/read-mps-file-using-mathoptinterface-and-extract-each-variable-from-moi/72753 "2021-12-08T08:32:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gopal2017](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gopal2017/32/31747_2.png) [@gopal2017](https://discourse.julialang.org/u/gopal2017)\
**Post date:** [December 8, 2021, 8:32am UTC](https://discourse.julialang.org/t/read-mps-file-using-mathoptinterface-and-extract-each-variable-from-moi/72753/1 "2021-12-08T08:32:31Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [December 8, 2021, 1:11pm UTC](https://discourse.julialang.org/t/read-mps-file-using-mathoptinterface-and-extract-each-variable-from-moi/72753/2 "2021-12-08T13:11:30Z")

</div>

Did you try [`JuMP.all_variables`](https://jump.dev/JuMP.jl/dev/reference/variables/#JuMP.all_variables)?

---

<div class="post-metadata">

**Author:** ![gopal2017](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gopal2017/32/31747_2.png) [@gopal2017](https://discourse.julialang.org/u/gopal2017)\
**Post date:** [December 8, 2021, 1:28pm UTC](https://discourse.julialang.org/t/read-mps-file-using-mathoptinterface-and-extract-each-variable-from-moi/72753/3 "2021-12-08T13:28:42Z")

</div>

gr8
