 # Obtaining Gap in integer programming

Hello dear,
I have an interest to obtain the relative Gap in a optimization integer problem. I have consulted 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.
A small example of how can I use this command.
Many thanks.

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

Edit: I’ve opened a pull request to improve the documentation: https://github.com/JuliaOpt/JuMP.jl/pull/2156

1 Like

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

``````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 <= 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:

``````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

``````

For a long time this have been a problem for me!

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

Here is the latest documentation: https://www.juliaopt.org/JuMP.jl/stable/

1 Like

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

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

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

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

If you haven’t used Julia’s package manager much, you should read the documentation: 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.

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

1 Like