Nearest latin square

205 Views Asked by At

given a n x n matrix A with integer entries is there any way to find the nearest n x n latin square to it, say, e.g., in the Frobenius norm? I am looking for some type of convex optimization...

Alternatively, with no much hope to have a positive answer, I am looking for a "global" convex function (like a norm...) to be able to test if a given matrix is a latin square.

Thanks a lot!!!

1

There are 1 best solutions below

2
On

If you let $a_{i,j,k}$ be zero or one depending on whether the $i,j$th entry of your latin square is $k$, then you can write down inequalities $a_{i,j,k} \geq 0$, $\sum_i a_{i,j,k} = 1$, $\sum_j a_{i,j,k} = 1$ and minimize the objective function $\sum_{i,j,k} (k a_{i,j,k}- b_{i,j})^2$ where $(b_{ij})$ is your original square. This is a binary quadratic programming problem and there are solvers available online.