Hello, I am new to Julia and trying to model a
relatively complicated optimization problem from other lenguage(GAMS). I am stuck in trying to apply a summation in a constraint and its depndence index to be in a range present in an array.
For example:
a=["1:10","5:10","7:10"]
@variable(m, x[i in 1:32, j in 1:10])
@constraint(m, con[i in 1:32], sum(x[i,j] for j in a[i] ) >=0 )
I have 2 problems from these:
Apparently you cant call a array value to the sum
I dont think the range beeing a string can be used either.
If anyone has an idea to replace this would be greate. The model has over 200 variables so its too time consuming to do it manually.
Hello, thank you for the fast response! It works perfect like that for array of 1D but I have not been able to do it for 2D array.
Let me explain better the problem: this is a constraint depending on agents and years.
using JuMP
A=["1:32";"2:32";;"3:32";"4:32" ......, "32:32"]
model=Model()
@variable(model, x[i in 1:10,w in 1:32])
@constraint(model, con2[i in 1:10, w in 1:32], x[i,w] + sum(y[i,k] for k in a[i,w] ) >= 0)
println(model)
So, A is a 2D array of sets of times. 1:32 = 1,2,3,4 ,… ,32.
Every agent i takes a desition x_i,w. But, also there is a desition y _i,k in which the year k will depend on the set of years given by the array A for agent i and year w. So, if it is agent 1 and year 1, the set for the summation is 1:32, so, there will be a sumation of y[1,1] + y[1,2] + … + y[1,32].
So my problem is how to be able to put the sets of time in a 2D array or any other suggestion to attack the problem.
Hello. I knew that it cant be in string mode. O just put it that way because i have not been able to program a 10x32 matrix or 2D array with the elements beeing ranges