Reputation: 45
I am still quite new in Julia but I was wondering if there is a way to make a self reference in an @expression statement in JuMP.
For instance I would like to be able to make this statement:
n = 3
@expression(model_opt, D[i=1:9], i>n ? D[i-n] : i)
which would define a vector D as follows
D = [1 2 3 1 2 3 1 2 3]
But for the moment Julia just tells me that D is not known
UndefVarError: D not defined
Thank you in advance for your help!
Upvotes: 1
Views: 140
Reputation: 953
Welcome to Julia, you're in for a ride. No, that is not supported. You can write a for
loop instead:
D = []
n = 3
for i in 1:9
push!(D, @expression(model_opt, i>n ? D[i-n] : i))
end
Upvotes: 1