Preface:
There is a net of $N$ almost-straight paths on an aerial map. Some of them intersect with another. At the points of intersection there are possibly a "mis-tie", which is expressed as a number, which is zero if the paths are properly "tied" at the intersection. All those numbers are incorporated into a $N\times N$ matrix $A$, where the cell $A_{ij}$ contains a value of a "mis-tie" at the point of intersection of paths $i$ and $j$. A "mis-tie" is signed, so $A_{ij}=-A{ji}$ (that is, if $i$ is "above" $j$ then $j$ is "below" $i$). There is "nothing" in cells $A_{ij}$ if paths $i$ and $j$ do not intersect.
Problem:
I'd like to minimize (in some sense) the mis-ties by shifting the paths "up" and "down", that is, by adding|subtracting a number from an entire row|column of a matrix $A$ (not affecting the "nothing" cells).
How can I calculate the optimal shifts to all of the paths to minimize the mis-ties? For example, to minimize $\sum_{ij: A_{ij}\neq 0} (A_{ij})^2$ ?