0
votes

I need to solve a problem where my decision variables are binary and are a 2 dimensional matrix, in Cplex y[p][q], p and q both have the same range papers=1..78. I need to incorporate a constraint that restricts the sum of both a row and column to be smaller or equal to 1. For ex. the sum of row 32 and column 32 can only be smaller or equal than 1.

Therefore I made a constraint like this:

forall(p in papers) sum (q in papers) y[p][q] + y[q][p] <= 1;

Cplex gives an error at the second 'q': name "q" does not exist

I don't really know what I'm doing wrong, I would appreciate the help.

Thanks in advance!

1

1 Answers

0
votes

From memory, the sum(q in papers) only applies to the immediate following term. Try putting the two separate parts in parentheses, like:

forall(p in papers) sum (q in papers) ( y[p][q] + y[q][p] ) <= 1;