Set depending of an index

Dear all,
I have a constraint in a integer program like

@constraint(modelo,[j in J,i in I],
    sum(x[i,k,h] for h in H for k in S_j) <= 1
)

My problem is how can I write this constraint by using the set S_j.
For example, if j=1, then S_j = {2,4}, if j=2, S_j = {1,3,4}, if j=3 S_j = {2,5,6} and so on, for each j I have a S_j with a diferent cardinality.
Best regards.

S = [[2, 4], [1, 3, 4], [2, 5, 6]]
model = Model()
@variable(model, x[1:6])
@constraint(model, [j in 1:3], sum(x[k] for k in S[j]) <= 1)
1 Like