I am trying to implement a mathematical model in JuMP but cant seem to figure out how i should write this constraint because i needs to be in both A and P
@constraint(m,
[(i,j) in data.A, i in data.P],
sum(xs[(i, j), s] for s in data.Si[i]) - x[(i, j)] == 0
)
the error i get is : LoadError: syntax: local variable name “i” conflicts with an argument
how can i make this constraint work?
JuMP’s @constraint macro with multiple index declarations like [(i,j) in data.A, i in data.P] treats i as a macro argument in the outer scope, causing a name conflict when i is also used inside the generator expression.
Use a single set for iteration that combines both conditions, ensuring i is only a local generator variable:
@constraint(m, [(i,j) in data.A if i in data.P],
sum(xs[(i, j), s] for s in data.Si[i]) - x[(i, j)] == 0
)