# About the optimization problem choice in JuMP v0.19

**URL:** https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [February 20, 2019, 5:11pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018 "2019-02-20T17:11:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![ErwanPiR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erwanpir/32/11434_2.png) [@ErwanPiR](https://discourse.julialang.org/u/ErwanPiR)
#### Post date: [February 20, 2019, 5:11pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/1 "2019-02-20T17:11:00Z")

</div>

I hope this isn’t a dumb question…

With the precedent version of JuMP, to define the kind of optimization problem (LP, MIP,…), the syntax was

> Model(solver=GLPKSolverMIP(args…))

or

> Model(solver=GLPKSolverLP())

I read in the documentation that now the syntax is :

> Model(with\_optimizer(GLPK.Optimizer, args…))

So I don’t understand where to define the kind of optimization problem… I trie several tests but didn’t find out…

I you can enlighten me 🙂 !

Thanks

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [February 20, 2019, 5:16pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/2 "2019-02-20T17:16:00Z")

</div>

I would also enjoy a clear an succinct summary of what happens with the various options, including bridges and `direct_model`. The documentation drops lots of hints, but I still feel a little fuzzy on exactly what is going on when I call `optimize!`.

Thanks again to all those who worked on JuMP 0.19 by the way! The Gurobi wrapper has been fixed and tagged so I’m now happily using 0.19 for my “big” problems. 😄

---

<div class="post-metadata">

### Author: ![chkwon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chkwon/32/3632_2.png) [@chkwon](https://discourse.julialang.org/u/chkwon)
#### Post date: [February 20, 2019, 5:56pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/3 "2019-02-20T17:56:09Z")

</div>

```julia
Model(with_optimizer(GLPK.Optimizer))

```

will just work.

---

<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 20, 2019, 7:12pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/4 "2019-02-20T19:12:22Z")

</div>

In the previous version, GLPK had two types of solvers (LP and MIP), and we forced the user to choose.

Now, the wrapper will choose for you. To by clear:

```julia
Model(solver = GLPKSolverLP())
# becomes
Model(with_optimizer(GLPK.Optimizer))

Model(solver = GLPKSolverMIP())
# becomes
Model(with_optimizer(GLPK.Optimizer))
```

---

<div class="post-metadata">

### Author: ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)
#### Post date: [February 20, 2019, 9:13pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/5 "2019-02-20T21:13:04Z")

</div>

[Solvers · JuMP](http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/#Automatic-and-Manual-modes-1) and [Solvers · JuMP](http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/#Direct-mode-1) are intended to cover this. Please open issues if there are points that are unclear in the docs.

See also slides 41-42 at [http://www.juliaopt.org/meetings/bordeaux2018/lubin.pdf](http://www.juliaopt.org/meetings/bordeaux2018/lubin.pdf). They’re a bit out of date though (from JuMP-dev in July, 2018).

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [February 20, 2019, 9:27pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/6 "2019-02-20T21:27:40Z")

</div>

I think my main confusion right now is around the following: I’ll tell you how I think it works and please correct me if I’m wrong:

If you create a model with `direct_model`, all changes you make to that model, such as adding variables are constraints, are called on the back-end immediately when the JuMP calls are made (e.g. `@variable` in JuMP results in a bunch of “`add_variable`” C++ calls). If instead you create a model with `Model(with_optimizer(opt))`, the a JuMP object is created representing the problem, and this does not translate into actual C++ (or whatever) calls until the user calls `optimize!`. If a `LazyBridge` optimizer is used, the form of the problem created in the back-end is equivalent but not necessarily identical to what you just created in JuMP.

---

<div class="post-metadata">

### Author: ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)
#### Post date: [February 21, 2019, 2:30am UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/7 "2019-02-21T02:30:27Z")

</div>

> [@ExpandingMan](#):
>
> If you create a model with `direct_model` , all changes you make to that model, such as adding variables are constraints, are called on the back-end immediately when the JuMP calls are made (e.g. `@variable` in JuMP results in a bunch of “ `add_variable` ” C++ calls).

Correct.

> [@ExpandingMan](#):
>
> If instead you create a model with `Model(with_optimizer(opt))` , the a JuMP object is created representing the problem, and this does not translate into actual C++ (or whatever) calls until the user calls `optimize!` .

Not quite. JuMP itself stores no copies of the model. The model data is stored in a `CachingOptimizer` (defined in `MOI.Utilities`) that manages loading and synchronizing the model data with the underlying optimizer (e.g., Gurobi). A `CachingOptimizer` can be in one of three states:

> <https://github.com/jump-dev/MathOptInterface.jl/blob/05b79b7ca59049c930cfdd4476fa06ab0d447559/src/Utilities/cachingoptimizer.jl#L13-L17>

`JuMP.optimize!` triggers a switch to `ATTACHED_OPTIMIZER` if the `CachingOptimizer` is not already in that state, but you can control it manually also:

> <https://github.com/jump-dev/JuMP.jl/blob/2dcec46949921d1fa7d026522270601d282df1df/src/optimizer_interface.jl#L30-L33>

`direct_model` and JuMP’s `MANUAL` mode did not exist prior to JuMP 0.19. JuMP’s `AUTOMATIC` mode is essentially what happened in 0.18 but in a more ad-hoc and less transparent way.

Bridges sit in the middle of all this and perform a minimal set of transformations (i.e., [computed by a shortest path algorithm](https://youtu.be/C8dHxJCUHYw?t=1000)) between the constraints that the user wrote down and the constraints that a solver natively accepts.

---

<div class="post-metadata">

### Author: ![ErwanPiR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erwanpir/32/11434_2.png) [@ErwanPiR](https://discourse.julialang.org/u/ErwanPiR)
#### Post date: [February 21, 2019, 1:00pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/8 "2019-02-21T13:00:42Z")

</div>

Thank you all for your answers. It is clearer now.

I’m not sure if it’s necessary to open an issue for the docs but it’s true that I haven’t found any mention to the selection of the kind of optimization problem even in the sections  
[http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/#Automatic-and-Manual-modes-1](http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/#Automatic-and-Manual-modes-1)  
and [Solvers · JuMP](http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/#Direct-mode-1) mentioned.

Thanks again for your 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 21, 2019, 2:20pm UTC](https://discourse.julialang.org/t/about-the-optimization-problem-choice-in-jump-v0-19/21018/9 "2019-02-21T14:20:29Z")

</div>

> [@ErwanPiR](#):
>
> I haven’t found any mention to the selection of the kind of optimization problem

This used to be a special case for GLPK. It no longer is. You don’t need to choose a priori what kind of optimization problem you are building.
