# Obtaining Gap in integer programming

**URL:** <https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377>\
**Category:** Optimization (Mathematical)\
**Created:** [February 9, 2020, 1:34pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377 "2020-02-09T13:34:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [February 9, 2020, 1:34pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/1 "2020-02-09T13:34:04Z")

</div>

Hello dear,  
I have an interest to obtain the relative Gap in a optimization integer problem. I have consulted [Reference · MathOptInterface](http://www.juliaopt.org/MathOptInterface.jl/stable/apireference/#MathOptInterface.RelativeGap)  
and when I give the command RelativeGap(), nothing happens.  
The CPLEX and Julia have the versions 12.8 and 1.0.4, respectivelly.  
Anyone could help me please?  
A small example of how can I use this command.  
Many 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:** [February 9, 2020, 5:22pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/2 "2020-02-09T17:22:03Z")

</div>

See [[docs] document how to get MOI attributes · Issue #2057 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/issues/2057)

```nohighlight
model = Model()
optimize!(model)
MOI.get(model, MOI.RelativeGap())

```

Edit: I’ve opened a pull request to improve the documentation: [Add docs for MOI.get by odow · Pull Request #2156 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/pull/2156)

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [February 10, 2020, 8:31pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/3 "2020-02-10T20:31:11Z")

</div>

Sorry, but don’t work yet!  
I have the following simple problem:

```julia
using JuMP
using CPLEX
m = Model(with_optimizer(CPLEX.Optimizer))

c = [1; 2; 5]
A = [-1 1 3;
      1 3 -7]
b = [-5; 10]

@variable(m, x[1:3] >= 0)
@objective(m, Max, sum( c[i]*x[i] for i=1:3) )

@constraint(m, constraint[j=1:2], sum( A[j,i]*x[i] for i=1:3 ) <= b[j] )

@constraint(m, bound, x[1] <= 10)

optimize!(m)

print(m)

println("Optimal Solutions:")
for i=1:3
  println("x[$i] = ", getvalue(x[i]))
end

println("Dual Variables:")
for j=1:2
  println("dual[$j] = ", getdual(constraint[j]))
end

x_value = JuMP.value.(x)
time = MOI.get(m, MOI.SolveTime())
Gap = MOI.get(m, MOI.RelativeGap())

```

When I insert the command `Gap = MOI.get(m, MOI.RelativeGap())` a error message appears:

```julia
MethodError: no method matching get(::Model, ::MathOptInterface.RelativeGap)
Closest candidates are:
  get(!Matched::REPL.Terminals.TTYTerminal, ::Any, !Matched::Any) at C:\Users\julia\AppData\Local\Julia-1.0.4\share\julia\stdlib\v1.0\REPL\src\Terminals.jl:176
  get(!Matched::IdDict{K,V}, ::Any, !Matched::Any) where {K, V} at abstractdict.jl:597
  get(!Matched::Base.Iterators.Pairs, ::Any, !Matched::Any) at iterators.jl:252
  ...
top-level scope at none:0

```

Anyone could help me please?  
For a long time this have been a problem for me!

---

<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 10, 2020, 10:21pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/4 "2020-02-10T22:21:16Z")

</div>

`MOI.get` only works with JuMP 0.20 and above. You should update your version of JuMP and code.

Here is the latest documentation: [Introduction · JuMP](https://www.juliaopt.org/JuMP.jl/stable/)

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [February 10, 2020, 11:06pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/5 "2020-02-10T23:06:57Z")

</div>

Many thanks for the hint.  
And the Julia language? The version 1.0.4 work?

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [February 10, 2020, 11:25pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/6 "2020-02-10T23:25:48Z")

</div>

Other question: How can I update the JuMP version v0.20?  
Could you provide the command for the update?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 10, 2020, 11:27pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/7 "2020-02-10T23:27:24Z")

</div>

if you type `]up` in julia, it will update all packages.

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [February 10, 2020, 11:31pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/8 "2020-02-10T23:31:17Z")

</div>

I would like to update only JuMP.  
How can I do this?

---

<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, 2020, 2:43pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/9 "2020-02-11T14:43:54Z")

</div>

If you haven’t used Julia’s package manager much, you should read the documentation: [Pkg · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Pkg).

It can do lots of helpful things!

> And the Julia language? The version 1.0.4 work?

Yes. We’re committed to supporting the Julia 1.0.x release series.

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [February 11, 2020, 2:58pm UTC](https://discourse.julialang.org/t/obtaining-gap-in-integer-programming/34377/10 "2020-02-11T14:58:30Z")

</div>

Perfect! Now I was able to access the number of nodes and the Gap.  
I thank the forum members for helping me.  
Thank you.
