# Solution foun by heuristic GLPK

**URL:** https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772
**Category:** Optimization (Mathematical)
**Created:** [May 4, 2020, 10:41pm UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772 "2020-05-04T22:41:50Z")
**Posts on this page:** 10
**Page:** 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: [May 4, 2020, 10:41pm UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/1 "2020-05-04T22:41:50Z")

</div>

Hi guys!  
I am using GLPK solver for a MIP. The output terminal shows me the next information:

GLPK Simplex Optimizer, v4.64  
16 rows, 120 columns, 800 non-zeros  
1: obj = 4.548322148e+003 inf = 0.000e+000 (0)

- 

```
9: obj = 3.270600000e+003 inf = 0.000e+000 (0)

```

OPTIMAL LP SOLUTION FOUND  
GLPK Integer Optimizer, v4.64  
16 rows, 120 columns, 800 non-zeros  
120 integer variables, all of which are binary  
Integer optimization begins…

- 

```
9: mip = not found yet >= -inf (1; 0)

```

Solution found by heuristic: 3351

- 14: \>\>\>\>\> 3.330000000e+003 \>= 3.330000000e+003 0.0% (1; 3)
- 14: mip = 3.330000000e+003 \>= tree is empty 0.0% (0; 7)  
INTEGER OPTIMAL SOLUTION FOUND

I don’t want him to use heuristics to find a solution and, I don’t know which parameter i should disable for this.

Do you have any idea how to disable the option: provide solution found by heuristic in GLPK.

Thanks for your help!

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [May 5, 2020, 12:22am UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/2 "2020-05-05T00:22:17Z")

</div>

May I ask why you don’t want heuristics?

---

<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: [May 5, 2020, 12:29am UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/3 "2020-05-05T00:29:45Z")

</div>

I’m not sure if GLPK has an option to turn all heuristics off.

I’ve moved your question to the `Optimization (Mathematical)` category.

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [May 5, 2020, 12:32am UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/4 "2020-05-05T00:32:54Z")

</div>

anyway, you can always look at the manual: ftp://ftp.gnu.org/gnu/glpk/ …  
it seems that the only heuristic ON by default is: simple rounding (sr\_heur)

---

<div class="post-metadata">

### Author: ![dragond4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dragond4/32/18123_2.png) [@dragond4](https://discourse.julialang.org/u/dragond4)
#### Post date: [September 23, 2020, 8:16am UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/5 "2020-09-23T08:16:58Z")

</div>

Hi joaquimg,

sorry for replying to a post dating back 4 months, but I think there is at least one good reason for disabling the _simple rounding heuristic_ in GLPK.  
Namely, there is a [known bug](https://en.m.wikibooks.org/wiki/GLPK/Callback_functions) with that heuristic and the lazy constraint callback in GLPK: if am not wrong, when a solution is found by the _simple rounding heuristic_, it is not checked for feasibility by invoking the lazy constraint callback.  
The bug is reported at least until GLPK 4.60, but I experienced a similar issue with a more recent version of GLPK in Julia 1.5.0. This implies that if the solution found by _simple rounding heuristic_ satisfies the constraints in the model, it is considered (incorrectly) feasible also if some lazy constraints are in fact violated (just because…they are not checked).  
In a branch-and-bound this may prune the search-tree nodes containing the correct optimal solution, thus reporting incorrect solutions.  
The suggested workaround is to turn off the _simple rounding heuristic_, via flag `sr_heur` (which I did not find how to do in JuMP).  
Thanks for your attention!  
Michele

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [September 23, 2020, 1:20pm UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/6 "2020-09-23T13:20:22Z")

</div>

There is a sketch on how to set parameters in: [https://github.com/jump-dev/GLPK.jl#glpkoptimizer](https://github.com/jump-dev/GLPK.jl#glpkoptimizer)  
Thus you can do:

```julia
using JuMP, GLPK
model = Model(GLPK.Optimizer)
set_optimizer_attribute(model, "sr_heur", GLPK.GLP_OFF)

```

---

<div class="post-metadata">

### Author: ![dragond4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dragond4/32/18123_2.png) [@dragond4](https://discourse.julialang.org/u/dragond4)
#### Post date: [September 23, 2020, 2:49pm UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/7 "2020-09-23T14:49:16Z")

</div>

Hi joaquimg,  
thanks for your reply.  
Unfortunately I was already aware of the sketch you sent me, on how to set GLPK parameters in JuMP.  
It seems that the flag `sr_heur` is not supported by JuMP, or that the one you were referring to is not the correct way to do.  
More precisely, trying

```julia
set_optimizer_attribute(model, "sr_heur", GLPK.GLP_OFF)

```

returns me the error:

> UndefVarError: GLP\_OFF not defined  
> Stacktrace:  
> [1] getproperty at .\Base.jl:26 [inlined]

Also trying with:

```julia
set_optimizer_attribute(model, "sr_heur", 0)

```

gives the error:

> MathOptInterface.UnsupportedAttribute{MathOptInterface.RawParameter}: Attribute MathOptInterface.RawParameter(“sr\_heur”) is not supported by the model.  
> Stacktrace:  
> [1] set(::GLPK.Optimizer, ::MathOptInterface.RawParameter, ::Int64) at .julia\packages\GLPK\oTTtu\src\MOI\_wrapper.jl:315

explicitly saying that `sr_heur` is not supported.  
I did this tests on a machine running Windows 8.1, Julia 1.5.0 and GLPK v4.64.  
Best regards,  
Michele

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [September 23, 2020, 5:13pm UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/9 "2020-09-23T17:13:21Z")

</div>

Please run:  
] st  
And paste results here.  
It must be a version problem.

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [September 23, 2020, 5:17pm UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/10 "2020-09-23T17:17:31Z")

</div>

I am on the latest versions:  
JuMP 0.21.5  
MathOptInterface 0.9.17  
GLPK 0.14.2 (GLPK.jl the julia wrapper not GLPK itself)

---

<div class="post-metadata">

### Author: ![dragond4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dragond4/32/18123_2.png) [@dragond4](https://discourse.julialang.org/u/dragond4)
#### Post date: [September 23, 2020, 8:04pm UTC](https://discourse.julialang.org/t/solution-foun-by-heuristic-glpk/38772/11 "2020-09-23T20:04:30Z")

</div>

Hello joaquimg,

thanks again for your support. This is the output you asked in a previous message (I keep only the relevant stuff):

> (@v1.5) pkg\> st  
> Status `.julia\environments\v1.5\Project.toml`  
> [a076750e] CPLEX v0.6.6  
> [60bf3e95] GLPK v0.13.0  
> [4076af6c] JuMP v0.21.3

You were 100% right: updating the JuMP and GLPK packages to the latest versions, the _simple rounding heuristic_ was successfully disabled as you suggested, using:

```julia
set_optimizer_attribute(model, "sr_heur", GLPK.GLP_OFF)

```

Best regards,  
Michele
