In JuMP, it appears that expressions, constraints, and variables cannot be dynamically named using string interpolation (i.e., the $
symbol) directly within the identifiers of the @variable
or @expression
macros. Given this limitation, I am curious about the best approach to dynamically generate names for expressions and constraints within a loop.
Currently, my workaround involves defining an empty dictionary outside the loop, which is then populated with expressions and constraints as follows:
exp = Dict()
for s in 1:S
exp[s] = @expression(model, sum(a[i] * x[i] for i in 1:n))
# Additional code follows
end
Is this approach considered the recommended practice for naming expressions and constraints dynamically?