Problems in obtaing of the Relative Gap

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[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:

ethodError: 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!

Closing this thread because it’s a duplicate of Obtaining Gap in integer programming.

1 Like