I have an application in mind, and I need to do the following analysis, but am having a high degree of difficulty conceptualizing it in terms of syntax. I understand what I want, but cannot seem to pull through in terms of code. I have two n by n matrices, call them matrix A and matrix B. The sum of all the entries in each n by n matrix is defined to be 1 for all n. I want to be able to “convert” matrix A to matrix B. However, I want to do this with the following counter and by rearrangement with the following conditions (pretend here n is 3 but I want to generalize it to any n) :
Moving 1 unit horizontally or 1 unit vertically (no diagonal movement allowed) is equivalent to 1 point cost So for example:
$\begin{matrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{matrix}$ $\qquad$to $\qquad$ $ \begin{matrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 1 & 0 & 0 \\ \end{matrix} $
is 2 points cost because I moved the 1 two units down. Similarly,
$\begin{matrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{matrix}$ $\qquad$to $\qquad$ $ \begin{matrix} 0 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0 \\ \end{matrix} $
is equivalent to 2 points because I had to go 1 unit left and 1 unit down. However,
$\begin{matrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{matrix}$ $\qquad$to $\qquad$ $ \begin{matrix} 0 & 0.8 & 0 \\ 0.2 & 0 & 0 \\ 0 & 0 & 0 \\ \end{matrix} $
Should be equivalent to 1 because you’re leaving 0.2 1 unit away, and 0.8 1 unit away (0.2*1+0.8*1). And then,
$\begin{matrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{matrix}$ $\qquad$to $\qquad$ $ \begin{matrix} 0 & 0 & 0.8 \\ 0.2 & 0 & 0 \\ 0 & 0 & 0 \\ \end{matrix} $
Should be equivalent to 1.8 because you are moving 0.2 1 unit away down and 0.8 2 units away right (0.2*1+0.8*2). However, I may not always have just a “1” that needs to be doled out everywhere, I could have matrices like:
$\begin{matrix} 0.2 & 0.1 & 0.1 \\ 0 & 0.3 & 0 \\ 0.04 & 0.06 & 0.2 \\ \end{matrix}$ $\qquad$to $\qquad$ $ \begin{matrix} 0.1 & 0.42 & 0.1 \\ 0.08 & 0.02 & 0.05 \\ 0.2 & 0 & 0.03 \\ \end{matrix} $
And I will need to optimize in terms of points. Can anyone help me?

