NOT related to my related question! (Different problem source)
This time, I want to sort a symmetric matrix M, and it must stay symmetric (i.e. row and col sort is the same). WLOG the diagonal is 0 (no relevance). This means the following restraint: Assume that M is
{{0, 2, 3, 6}, {2, 0, 1, 4}, {3, 1, 0, 5}, {6, 4, 5, 0}}
then your allowed operations are any row swap (here 2 and 3)
{{0, 2, 3, 6}, {3, 1, 0, 5}, {2, 0, 1, 4}, {6, 4, 5, 0}}
and now you must accompany it with same col swap (also 2 and 3)
{{0, 3, 2, 6}, {3, 0, 1, 5}, {2, 1, 0, 4}, {6, 5, 4, 0}}
so M is symmetric again. You are done when M is smallest by alphanumeric comparison:
{{0, 1, 2, 4}, {1, 0, 3, 5}, {2, 3, 0, 6}, {4, 5, 6, 0}}
This of course means that the linked answer doesn't work anymore:
{{0, 2, 3, 6}, {2, 0, 1, 4}, {3, 1, 0, 5}, {6, 4, 5, 0}}
becomes a fixed point (where instead 1 shall go into the first row).
Neither does it work to just elide the diagonal, sort just by row and with the same permutation by col:
{{0, 1, 2, 4}, {1, 0, 3, 5}, {2, 3, 0, 1}, {4, 5, 1, 0}}
is correctly sorted without the 0, but not the solution.
My working algorithm is generating all possible n! M and fish out the smallest. A much better almost working is in the comments.
{2, 3, 0, 6}
. The 2 and 3 are swapped around. $\endgroup$