Unable to fix a JuMP variable, when it hasn't been fixed

using JuMP
m = Model()
@variable(m, z >= 0)
@objective(m, Min, z)
@show is_fixed(z)
fix(z, 1)

The above code generates:

is_fixed(z) = false
ERROR: LoadError: Unable to fix z to 1 because it has existing variable bounds. Consider calling `JuMP.fix(variable, value; force=true)` which will delete existing bounds before fixing the variable.

Is this normal? I am on JuMP v0.22.0.

FYI, when the variable is unrestricted, it works fine.

m = Model()
@variable(m, z)
@objective(m, Min, z)
@show is_fixed(z) # false
fix(z, 1)
@show is_fixed(z) # true
1 Like

This is normal behaviour; see
https://jump.dev/JuMP.jl/stable/manual/variables/#Create-a-fixed-variable

2 Likes