Dynamic expreesion name in JuMP

Hi All,
is there a way to create dynamic expression name in Julia? like the code given below Julia 1.2

mod2=Model()
@variable(mod2,x[ i in 1:13])
@variable(mod2,y[ i in 1:13])
@constraint(mod2, [i in 1:13], x[i]+y[i]>=30)
for i in 1:13
temp$i=    @expression(mod2,x[i]+y[i]+3)
@constraint(mod2,temp$i<=100)
end
print(mod2)


Thanks

Can you use a Julia container?

temp = Array{AffExpr}(undef, 13)
for i in 1:13
   temp[i] = @expression(mod2,x[i]+y[i]+3)
end

@constraint(mod2, [i=1:13], temp[i] <= 100)
2 Likes
mod2=Model()
@variable(mod2,x[ i in 1:13])
@variable(mod2,y[ i in 1:13])
@constraint(mod2, [i in 1:13], x[i]+y[i]>=30)

temp = Vector{Any}(undef, 13)
for i in 1:13
    temp[i]=    @expression(mod2,x[i]+y[i]+3)
end
@constraint(mod2,temp .<= 100)

print(mod2)
1 Like

Nice answer :yum:

1 Like