# How to omit arithmetic error of MIP solver in JuMP?

**URL:** <https://discourse.julialang.org/t/how-to-omit-arithmetic-error-of-mip-solver-in-jump/87242>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [September 13, 2022, 11:12pm UTC](https://discourse.julialang.org/t/how-to-omit-arithmetic-error-of-mip-solver-in-jump/87242 "2022-09-13T23:12:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jian\_ZUO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jian_zuo/32/33738_2.png) [@Jian\_ZUO](https://discourse.julialang.org/u/Jian_ZUO)\
**Post date:** [September 13, 2022, 11:12pm UTC](https://discourse.julialang.org/t/how-to-omit-arithmetic-error-of-mip-solver-in-jump/87242/1 "2022-09-13T23:12:15Z")

</div>

Hi all,  
I am working on a nonlinear type MIP optimization problem solved through JuMP.  
My solution is based on Juniper and HiGHS:

```julia
using Juniper
using HiGHS
using JuMP
using Ipopt
R10, R20 = 0.18, 0.195

L11, L21 = 2.4, 2.4

Ld_dec = 2.4

w1 = R10 / sum([R10, R20])

w2 = R20 / sum([R10, R20])

lb = 0.42 / Ld_dec

ub = 3.87 / Ld_dec

dec_step = 300

nl_solver = optimizer_with_attributes(Ipopt.Optimizer, "print_level"=>0)

mip_solver = optimizer_with_attributes(HiGHS.Optimizer, "output_flag"=>false)

minlp_solver = optimizer_with_attributes(Juniper.Optimizer, "nl_solver"=>nl_solver, "mip_solver"=>mip_solver)

mfc = Model(minlp_solver)

# set_silent(mfc)

@variable(mfc, u, Bin)

@variable(mfc, v, Bin)

@variable(mfc, 0.0<=x<=ub)

@variable(mfc, 0.0<=y<=ub)

@NLconstraint(mfc, x<=ub*u)

@NLconstraint(mfc, x>=lb*u)

@NLconstraint(mfc, y<=ub*v)

@NLconstraint(mfc, y>=lb*v)

@constraint(mfc, x+y==1)

@NLobjective(mfc, Min, (u*w1 * (x*Ld_dec-L11)^2 + v*w2 * (y*Ld_dec-L21)^2) + (u*w1*(0.01245 + 0.0257 * (x*Ld_dec - 2.38)^2) + v*w2*(0.01245+ 0.0257 * (y*Ld_dec - 2.38)^2)) * dec_step)

optimize!(mfc)

println("x: $(value(x))")

println("y: $(value(y))")

```

I obtained:

```julia
#branches: 2
Obj: 1.7942803188090848
x: 0.9999999966479224
y: 3.3520777017322965e-9

```

The expected results should be x=1.0, y=0.0.  
This is due to an arithmetic calculation accuracy problem? How can I obtain an ‘accurate’ desired results?  
Thank you in advance!

---

<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:** [September 13, 2022, 11:16pm UTC](https://discourse.julialang.org/t/how-to-omit-arithmetic-error-of-mip-solver-in-jump/87242/2 "2022-09-13T23:16:35Z")

</div>

> This is due to an arithmetic calculation accuracy problem?

Yes. solvers do not use exact arithmetic, they use tolerances, and will only ever be accurate to their tolerance, which is usually somewhere between 1e-6 and 1e-9.

See

- [Debugging · JuMP](https://jump.dev/JuMP.jl/dev/tutorials/getting_started/debugging/#Solve-failures)
- [https://www.gurobi.com/documentation/9.5/refman/grb\_tolerances\_and\_the\_lim.html](https://www.gurobi.com/documentation/9.5/refman/grb_tolerances_and_the_lim.html)

> How can I obtain an ‘accurate’ desired results?

You cannot find the exact solution. This is a limitation of numerical solvers.

---

<div class="post-metadata">

**Author:** ![Jian\_ZUO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jian_zuo/32/33738_2.png) [@Jian\_ZUO](https://discourse.julialang.org/u/Jian_ZUO)\
**Post date:** [September 13, 2022, 11:28pm UTC](https://discourse.julialang.org/t/how-to-omit-arithmetic-error-of-mip-solver-in-jump/87242/3 "2022-09-13T23:28:47Z")

</div>

I see. Thank you very much for the explanation! @odow
