Multi-dimensional array of tuples

Welcome. A good start is often write things as a functions:

tuple_match(n,L,x,a,p) = [(i,j) for i in 2:n, j in 1:(n-1) if (i in L || j in L) && (value(x[i, j, p]) >= a)]

or a more general version would be

tuple_match(S1,S2,L,x,a,p) = [(i,j) for i in S1, j in S2 if (i in L || j in L) && (value(x[i, j, p]) >= a)]

where S1 = 2:n and S2 = 1:(n-1) etc. in your code.

Here I’m using Comprehensions.

Then you could write, for given values of n, L, x, a ,

g = [tuple_match(n, L, x, a, p) for p in 1:P]
2 Likes