# Write to MPS

**URL:** <https://discourse.julialang.org/t/write-to-mps/40995>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [June 8, 2020, 2:21pm UTC](https://discourse.julialang.org/t/write-to-mps/40995 "2020-06-08T14:21:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [June 8, 2020, 2:21pm UTC](https://discourse.julialang.org/t/write-to-mps/40995/1 "2020-06-08T14:21:02Z")

</div>

How does the MPS writer of Gurobi work?

```julia
using JuMP, Gurobi

model = Model(Gurobi.Optimizer)

@variables(model, begin
    0 <= x <= 5
    0 <= y <= 10, Int
    z, Bin
end)

@objective(model, Max, x + 2y + 5z)
@constraint(model, x + y + z <= 10)
@constraint(model, x + 2y + z <= 15)

Gurobi.write_model(model.moi_backend.optimizer.model.inner, "test.mps")

```

gives me an empty file:

```nohighlight
NAME 
ROWS
 N OBJ
COLUMNS
RHS
BOUNDS
ENDATA

```

`JuMP.write_to_file(model, "test_JuMP.mps")` would work.  
The reason seems to be that the `inner` model is empty until `optimize!` is called.  
How do I transfer the model without a call of `optimize!`?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [June 8, 2020, 3:37pm UTC](https://discourse.julialang.org/t/write-to-mps/40995/2 "2020-06-08T15:37:02Z")

</div>

To avoid the `copy_to` on `optimize!`, use direct mode:

```nohighlight
model = direct_model(Gurobi.Optimizer())
@variables(model, begin
    0 <= x <= 5
    0 <= y <= 10, Int
    z, Bin
end)
@objective(model, Max, x + 2y + 5z)
@constraint(model, x + y + z <= 10)
@constraint(model, x + 2y + z <= 15)
Gurobi.write_model(backend(model), "test.mps")

```
