Scope of variables in optimisation

function foo()
    model = Model()
    @variable(model, x)
    return model
end

function bar()
    model = foo()
    x = model[:x]
    value(x)
end

You need to call set_upper_bound on y after it has been built.

using JuMP, Clp
model = Model(Clp.Optimizer)
@variable(model, x >= 0)
@objective(model, Min)
for l = 1:4
    set_lower_bound(x, l)
    optimize!(model)
    @show value(x)
end
1 Like