Hello, in a JuMP model I need to fix some variables, and these variables to fix are defined in a dictionary.
This works:
using JuMP, Ipopt
fvars = Dict{String,Float64}("c" => 5)
m = Model(Ipopt.Optimizer)
# [...]
@variable(m, c)
for (k,v) in fvars
fix(eval(Symbol(k)), v; force = true)
end
# [...]
However if I wrap the model in a module I got an UndefVarError
:
module Foo
using JuMP, Ipopt
function foo()
fvars = Dict{String,Float64}("c" => 5)
m = Model(Ipopt.Optimizer)
# [...]
@variable(m, c)
for (k,v) in fvars
fix(eval(Symbol(k)), v; force = true)
end
# [...]
end
end
ERROR: UndefVarError:
cnot defined in
Main.Foo``
I guess the “eval” somehow happens too early, is there any workaround ?