0

I am trying to define a constraint containing summation over two indices, k and t.

for i in data.I    
    for j in 1:length(data.P[i])
        @constraint(m, w[i, j, length(data.T[data.P[i][j]])]/(1+sum(data.A[i][k][t] for k in 1:length(data.P[i]), t in data.T[data.P[i][k]])) <= s[i, j])
    end
end

I get the following error in running the code:

ERROR: LoadError: UndefVarError: k not defined

I have implemented the same model in OPL for CPLEX in the same way, and this was not an issue. Am I not allowed to introduce such variable as an index in the summation, then use it subsequently as an index to an array within the same sum() as I am trying to do above?

dylee
  • 75
  • 6

2 Answers2

1

This is a question of Julia syntax:

julia> sum(i+j for i in 1:3, j in 1:i)
ERROR: UndefVarError: i not defined

julia> sum(i+j for i in 1:3 for j in 1:i)
24

The same should hold for JuMP.

mlubin
  • 943
  • 5
  • 10
0

My colleague found a workaround to this issue. Converting the sum into the equivalent double sum made it work, i.e.:

sum(data.A[i][k][t] for k = 1:length(data.P[i]), t = data.T[data.P[i][k]]) 

was changed to:

sum(sum(data.A[i][k][t] for t = data.T[data.P[i][k]]) for k = 1:length(data.P[i]))

This solves the issue.

dylee
  • 75
  • 6