Modeling permutations
Moderator: aileen
Forum rules
Please ask questions in the other sub-forums
Please ask questions in the other sub-forums
Modeling permutations
How can I model a vector of integer variables x(i) that can assume values 1,2,…,card(i), and each x(i) should be different, i.e. x(i) <> x(j) for all i <> j ?
Re: Modeling permutations
This looks like we need the help of a permutation matrix P=p(i,j), where there is exactly one 1 in each row and column, and the other elements are zero. The identity matrix is a trivial example of a permutation matrix. Other ones just have some rows and columns of the identity matrix interchanged. To model this in a MIP use binary variables p and add the constraints:
The different values for our vector x can now be calculated as:
Because x is automatically integer if p is integer, we can declare x as a normal continuous variable.
Code: Select all
alias (i,j);
binary variables p(i,j);
equations rowsum(i) colsum(j);
rowsum(i).. sum(j, p(i,j)) =e= 1;
colsum(j).. sum(i, p(i,j)) =e= 1;
Code: Select all
x(i) =e= sum(j, ord(j)*p(i,j));