Stop Julia at certain optimiality gap and return decision variables

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.

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

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

or

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

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

Thank you, it works.

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

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?

JuMP has been updated.

The new syntax is

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

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?

The list of CPLEX parameters can be found here: IBM Documentation

Warmstarts can set set using
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

1 Like

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:

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.

1 Like

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!

Use:

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:

set_parameter(model, "CPXPARAM_MIP_Strategy_VariableSelect", 1)

Thank you so much!
it works perfectly!