# Stop Julia at certain optimiality gap and return decision variables

**URL:** <https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957>\
**Category:** Optimization (Mathematical)\
**Created:** [March 29, 2017, 7:57pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957 "2017-03-29T19:57:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duaa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/duaa/32/3774_2.png) [@Duaa](https://discourse.julialang.org/u/Duaa)\
**Post date:** [March 29, 2017, 7:57pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/1 "2017-03-29T19:57:01Z")

</div>

I have a MILP problem and I am trying to solve it using CPLEX package through JuMP in Julia Language. However, the problem takes a long time to be solved. Is there a way to stop the program and return decision variables when the optimality gap reaches for example 10%. Thank you.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 29, 2017, 8:01pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/2 "2017-03-29T20:01:52Z")

</div>

I haven’t used CPLEX, but I believe you can do:

```julia
m = Model(solver=CplexSolver(CPX_PARAM_EPGAP=1e-2))

```

or

```julia
setsolver(m, CplexSolver(CPX_PARAM_EPGAP=1e-2))

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 29, 2017, 8:02pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/3 "2017-03-29T20:02:22Z")

</div>

(the above assumes you are using CPLEX through JuMP, which I just realized you didn’t actually say).

---

<div class="post-metadata">

**Author:** ![Duaa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/duaa/32/3774_2.png) [@Duaa](https://discourse.julialang.org/u/Duaa)\
**Post date:** [March 29, 2017, 11:13pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/4 "2017-03-29T23:13:17Z")

</div>

Thank you, it works.

---

<div class="post-metadata">

**Author:** ![Duaa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/duaa/32/3774_2.png) [@Duaa](https://discourse.julialang.org/u/Duaa)\
**Post date:** [March 29, 2017, 11:14pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/5 "2017-03-29T23:14:06Z")

</div>

Yes, I am using CPLEX through JuMP.  
Sorry for not mentioning it.

---

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [February 20, 2019, 2:16am UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/6 "2019-02-20T02:16:52Z")

</div>

Hi @rdeits,

I am using Julia 1.1.0 and following packages:

“Clp” =\> v"0.6.1"  
“Atom” =\> v"0.7.14"  
“CPLEX” =\> v"0.4.3"  
“JuMP” =\> v"0.19.0"  
“Juno” =\> v"0.5.4"  
“Conda” =\> v"1.2.0"  
“ExcelReaders” =\> v"0.10.3"  
“MathProgBase” =\> v"0.7.7"  
“XLSX” =\> v"0.4.6"  
“Cbc” =\> v"0.6.0"  
“DataFrames” =\> v"0.17.1".

I am trying to set `m = Model(solver=CplexSolver(CPX_PARAM_EPGAP=1e-2))`, but I am getting the following error:

`The solver= keyword is no longer available in JuMP 0.19 and later.`

However, they are suggesting a link for the reference which is somehow not a valid link.

Any help in this regard would be highly appreciated. Also, could you please share any link where I can find how to set different stopping criteria for the CPLEX solver through JuMP?

---

<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, 2:28am UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/7 "2019-02-20T02:28:00Z")

</div>

JuMP has been updated.

> [@JuMP v0.19 has been released](https://discourse.julialang.org/t/jump-v0-19-has-been-released/20878):
>
> We are thrilled to announce the release of JuMP v0.19. Work on this release started nearly two years ago at the [first JuMP-dev meetup](http://www.juliaopt.org/meetings/mit2017/). As introduced in [an earlier post](https://discourse.julialang.org/t/mathoptinterface-and-upcoming-breaking-changes-in-jump-0-19/4874) and at the [second JuMP-dev meetup](https://youtu.be/_u6e184vBhc?list=PLP8iPy9hna6RJUxzYlWENcs9yf-CRoDvD), JuMP has undergone a major refactoring to replace its solver interface from [MathProgBase (MPB)](https://github.com/JuliaOpt/MathProgBase.jl) to the new [MathOptInterface (MOI)](https://github.com/JuliaOpt/MathOptInterface.jl), receiving many new features and improvements along the way. While MPB had three different interfaces: linear/quadratic, conic and nonlinear, MOI is completely generi…

The new syntax is

```julia
m = Model(with_optimizer(CPLEX.Optimizer, CPX_PARAM_EPGAP=1e-2))

```

---

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [February 20, 2019, 4:40am UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/8 "2019-02-20T04:40:52Z")

</div>

Thanks, @odow . Any idea where can I find the list of keywords to set the stopping criteria, example: absolute MIP gap, relative MIP gap, time etc.? Also, is there a way to set a warm start?

---

<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, 2:28pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/9 "2019-02-20T14:28:54Z")

</div>

The list of CPLEX parameters can be found here: [IBM Documentation](https://www.ibm.com/support/knowledgecenter/en/SS9UKU_12.8.0/com.ibm.cplex.zos.help/CPLEX/Parameters/topics/introListAlpha.html)

Warmstarts can set set using  
[https://github.com/JuliaOpt/JuMP.jl/blob/fbc5c80763a17067199e95b4e2e1554823fadbce/src/variables.jl#L692-L712](https://github.com/JuliaOpt/JuMP.jl/blob/fbc5c80763a17067199e95b4e2e1554823fadbce/src/variables.jl#L692-L712)

These were mistakenly missing from the docs: [start\_value and set\_start\_value are not listed in the documentation · Issue #1871 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/issues/1871)

---

<div class="post-metadata">

**Author:** ![NiclasMattsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclasmattsson/32/21988_2.png) [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)\
**Post date:** [February 20, 2019, 2:42pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/10 "2019-02-20T14:42:46Z")

</div>

You’ll soon discover that it’s extremely clunky to navigate the parameter list using the web interface. Luckily IBM also makes a nice easily searchable PDF of the whole thing, but to my knowledge they don’t actually link to it anywhere. Some time ago I googled my way to an old version and then found the latest one by just modifying the URL:

> **[paramcplex.pdf](https://www.ibm.com/docs/en/SSSA5P_12.8.0/ilog.odms.studio.help/pdf/paramcplex.pdf)**
>
> 1573.50 KB

By the way, I think the old parameter names are being deprecated. So if you want to future proof your code you may want to use the newer more verbose names, e.g. `CPXPARAM_MIP_Tolerances_MIPGap` instead of `CPX_PARAM_EPGAP`.

---

<div class="post-metadata">

**Author:** ![lausilvag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lausilvag/32/9778_2.png) [@lausilvag](https://discourse.julialang.org/u/lausilvag)\
**Post date:** [January 9, 2020, 4:11pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/11 "2020-01-09T16:11:57Z")

</div>

Hi!  
I have the same problem. I am using Julia 1.2.0 and the following packages:  
CPLEX=V.12.9  
JuMP =V. 0.20.1

I am trying with this code:  
using JuMP, CPLEX  
m= Model(with\_optimizer(CPLEX.Optimizer, CPXPARAM\_MIP\_Strategy\_VariableSelect=1))

and this is the error: " no method matching CPLEX.Optimizer (;CPXPARAM\_MIP\_Strategy\_VariableSelect=1)"

Please, can you help me?  
Thanks!

---

<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:** [January 9, 2020, 4:19pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/12 "2020-01-09T16:19:10Z")

</div>

~~Use:~~

~~ 

```nohighlight
model = Model(with_optimizer(CPLEX.Optimizer))
MOI.set(model, MOI.RawParameter("CPXPARAM_MIP_Strategy_VariableSelect"), 1)

```

 ~~

~~We should improve the user-experience of this.~~

We already have:

```julia
set_parameter(model, "CPXPARAM_MIP_Strategy_VariableSelect", 1)

```

---

<div class="post-metadata">

**Author:** ![lausilvag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lausilvag/32/9778_2.png) [@lausilvag](https://discourse.julialang.org/u/lausilvag)\
**Post date:** [January 9, 2020, 4:43pm UTC](https://discourse.julialang.org/t/stop-julia-at-certain-optimiality-gap-and-return-decision-variables/2957/13 "2020-01-09T16:43:04Z")

</div>

Thank you so much!  
it works perfectly!
