# CPLEX: CPXwritemipstarts without optimize!

**URL:** <https://discourse.julialang.org/t/cplex-cpxwritemipstarts-without-optimize/109973>\
**Category:** Optimization (Mathematical)\
**Created:** [February 9, 2024, 9:43am UTC](https://discourse.julialang.org/t/cplex-cpxwritemipstarts-without-optimize/109973 "2024-02-09T09:43:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [February 9, 2024, 9:43am UTC](https://discourse.julialang.org/t/cplex-cpxwritemipstarts-without-optimize/109973/1 "2024-02-09T09:43:17Z")

</div>

Hi,

I would like to be able to save a model and its warm start as the solver got them when calling `optimize!`.

```julia
using JuMP
using CPLEX
m = Model(CPLEX.Optimizer);
direct_m = direct_model(CPLEX.Optimizer());
@variable(m, foo, Bin);
set_start_value(foo, 1);
MOI.copy_to(backend(direct_m), m);
backend_model = unsafe_backend(direct_m);
env = backend_model.env;
lp = backend_model.lp;
CPXwriteprob(env, lp, "CPLEX_model.mps", "MPS");
CPXwritemipstarts(env, lp, "CPLEX_mipstart.mst", 0, 0);

```

Writing the MPS works but not the MIP start: `CPLEX Error 3020: No MIP start exists.`

Julia packages:

- CPLEX v1.0.3
- JuMP v1.19.0

and CPLEX 22.1.1

I have no clue on how to extract the MIP start. Any idea?

---

<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:** [February 9, 2024, 8:22pm UTC](https://discourse.julialang.org/t/cplex-cpxwritemipstarts-without-optimize/109973/2 "2024-02-09T20:22:07Z")

</div>

Hi @remi-garcia

We add the mip starts inside optimize because the user might modify them at any point.

You’d need to do something similar to the code around here

> <https://github.com/jump-dev/CPLEX.jl/blob/6e0fdafc7df51bb710fb3e95f5bb7563ec984f65/src/MOI/MOI_wrapper.jl#L2748>

---

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [February 10, 2024, 9:28am UTC](https://discourse.julialang.org/t/cplex-cpxwritemipstarts-without-optimize/109973/3 "2024-02-10T09:28:03Z")

</div>

Thank you for pointing me in this direction, I’ll do some tests.

---

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [February 10, 2024, 10:00pm UTC](https://discourse.julialang.org/t/cplex-cpxwritemipstarts-without-optimize/109973/4 "2024-02-10T22:00:23Z")

</div>

This works great. Maybe it would be a nice thing to decompose `optimize!` into `_load_model!` `_optimize!` and `read_optimize!`?

In any case, it does what I wanted to do, which is actually not what I need… 😅

Thanks again for the help

---

<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:** [February 11, 2024, 6:06am UTC](https://discourse.julialang.org/t/cplex-cpxwritemipstarts-without-optimize/109973/5 "2024-02-11T06:06:58Z")

</div>

Whats the ultimate goal? Do you really just want a way to write mst files from JuMP?

---

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [February 11, 2024, 7:42am UTC](https://discourse.julialang.org/t/cplex-cpxwritemipstarts-without-optimize/109973/6 "2024-02-11T07:42:23Z")

</div>

I encounter a bug, solving a model leads to `optimal` in \<1s on a computer and `infeasible` on another.

The ultimate goal is to be able to have the solver in the exact same state as before optimization to extract info from it, for replicability without julia.

But extracting MPS+MST or LP+MST is not sufficient as the constraints are exported and/or read in a different order (yes, the order of the constraints is actually very important as the model becomes feasible if I randomize their order with [`ShuffleContraints`](https://github.com/remi-garcia/ShuffleConstraints)…)
