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