# Potential bug on relative gap calculation

**URL:** <https://discourse.julialang.org/t/potential-bug-on-relative-gap-calculation/36323>\
**Category:** Optimization (Mathematical)\
**Tags:** bug\
**Created:** [March 21, 2020, 11:47pm UTC](https://discourse.julialang.org/t/potential-bug-on-relative-gap-calculation/36323 "2020-03-21T23:47:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [March 21, 2020, 11:47pm UTC](https://discourse.julialang.org/t/potential-bug-on-relative-gap-calculation/36323/1 "2020-03-21T23:47:16Z")

</div>

Whatever the MIP tolerance I get the relative mip gap is always zero.

I am using:

MOI.get(model, MOI.RelativeGap())

JuMP v"0.20.1"  
Xpress v"0.10.0"

Seems to be an issue either in JuMP or in Xpress

---

<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:** [March 22, 2020, 5:57pm UTC](https://discourse.julialang.org/t/potential-bug-on-relative-gap-calculation/36323/2 "2020-03-22T17:57:09Z")

</div>

Do you have an example?

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [March 26, 2020, 8:48pm UTC](https://discourse.julialang.org/t/potential-bug-on-relative-gap-calculation/36323/3 "2020-03-26T20:48:11Z")

</div>

See below:

The expression MOI.get(model, MOI.RelativeGap()) always returns zero, regardless of the tolerance achieved by the solver.

# -----------------------------------------

using JuMP  
using Xpress

# Preparing an optimization model

m = Model(with\_optimizer(Xpress.Optimizer, OUTPUTLOG = 0, MIPRELSTOP = 0.0001 ))

# Declaring variables

@variable(m, 0\<= x1 \<=10)  
@variable(m, x2 \>=0, Int)  
@variable(m, x3[i=1:100000], Bin)  
@variable(m, obj\_function \>= 0 )

# Setting the objective

@objective(m, Max, obj\_function )

# Adding constraints

@constraint(m, constraint0, sum(x3[i] for i in 1:100000) \<= 1000)  
@constraint(m, constraint1, -x1 + x2 + sum(rand()\*x3[i] for i in 1:100000) \<= 500)  
@constraint(m, constraint2, x1 + 3x2 - sum(rand()\*x3[i] for i in 1:100000) \<= 800)  
@constraint(m, constraint3, x1 + 2x2 + sum(rand()\*x3[i] for i in 1:100000) == obj\_function)

# Solving the optimization problem

optimize!(m)

MOI.get(m, MOI.RelativeGap())  
JuMP.value(obj\_function)

MOI.get(m, MOI.SolveTime())

# With MIPRELSTOP = 0.9

# MOI.get(m, MOI.RelativeGap()) is 0

# JuMP.value(obj\_function) is 798.9799221022847

# With MIPRELSTOP = 0.0001

# MOI.get(m, MOI.RelativeGap()) is 0

# JuMP.value(obj\_function) is 1888.5283814454042

---

<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:** [March 27, 2020, 2:54am UTC](https://discourse.julialang.org/t/potential-bug-on-relative-gap-calculation/36323/4 "2020-03-27T02:54:09Z")

</div>

I’ve opened an issue: [Bug in ObjectiveBound · Issue #83 · jump-dev/Xpress.jl · GitHub](https://github.com/JuliaOpt/Xpress.jl/issues/83)
