# JuMP returning incorrect value after deleting/adding anonymous variable and constraint

**URL:** <https://discourse.julialang.org/t/jump-returning-incorrect-value-after-deleting-adding-anonymous-variable-and-constraint/38036>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [April 22, 2020, 6:15pm UTC](https://discourse.julialang.org/t/jump-returning-incorrect-value-after-deleting-adding-anonymous-variable-and-constraint/38036 "2020-04-22T18:15:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cby](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@cby](https://discourse.julialang.org/u/cby)\
**Post date:** [April 22, 2020, 6:15pm UTC](https://discourse.julialang.org/t/jump-returning-incorrect-value-after-deleting-adding-anonymous-variable-and-constraint/38036/1 "2020-04-22T18:15:16Z")

</div>

When I use an anonymous variable and constraint, optimize, delete and re-add them, then optimize again, I get two different solutions, the second of which is incorrect. However, the model is still printing correctly. What might be going on here?

(JuMP v0.21.2, Gurobi v0.7.6, Julia v1.4)

```julia
using JuMP
using Gurobi

m = Model(Gurobi.Optimizer)
set_optimizer_attribute(m,"OutputFlag",0)

@variable(m, 0<=y<=4)
x = @variable(m, base_name="x",lower_bound=0,upper_bound=4) 
con = @constraint(m, x+y == 3)
@objective(m, Max, x+y)
print(m)
optimize!(m)
println("x1= ",value(x),"; y1= ",value(y),"; objv = ",objective_value(m))

delete(m,con)
delete(m,x)

x = @variable(m, base_name="x",lower_bound=0,upper_bound=4) 
con = @constraint(m, x+y == 3)
@objective(m, Max, x+y)
print(m)
optimize!(m)
println("x2= ",value(x),"; y2= ",value(y),"; objv = ",objective_value(m))

```

This gives the following output:

```julia
Max x + y
Subject to
 x + y = 3.0
 y ≥ 0.0
 x ≥ 0.0
 y ≤ 4.0
 x ≤ 4.0
x1= 0.0; y1= 3.0; objv = 3.0
Max x + y
Subject to
 x + y = 3.0
 y ≥ 0.0
 x ≥ 0.0
 y ≤ 4.0
 x ≤ 4.0
x2= 1.0; y2= 0.0; objv = -0.0

```

---

<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:** [April 23, 2020, 1:46am UTC](https://discourse.julialang.org/t/jump-returning-incorrect-value-after-deleting-adding-anonymous-variable-and-constraint/38036/2 "2020-04-23T01:46:25Z")

</div>

It looks like you have indeed found a bug. Let me take a look.

---

<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:** [April 23, 2020, 2:20am UTC](https://discourse.julialang.org/t/jump-returning-incorrect-value-after-deleting-adding-anonymous-variable-and-constraint/38036/3 "2020-04-23T02:20:12Z")

</div>

Opened an issue: [More fun with lazy update semantics · Issue #315 · jump-dev/Gurobi.jl · GitHub](https://github.com/JuliaOpt/Gurobi.jl/issues/315). Will contact Gurobi support.
