This is not, per se, very useful, but sorting a parameter inside a MIP model is not very easy for MIP solvers. Obviously, if you need a sorted parameter in the model, it is better to use a sorting algorithm. But useless models can still be interesting.
I use:
Input: a 1-dimensional parameter with values.
Output: a 1-dimensional variable with the values sorted in ascending order.
We can implement this with a permutation matrix X, which is a permuted identity matrix. In a MIP context, this becomes a binary variable with some assignment constraints.
MIP Model for sorting pi |
---|
minz=0∑ixi,j=1∀j∑jxi,j=1∀iyi=∑jxi,j⋅pjyi≥yi−1xi,j∈{0,1} |