I am trying to find the minimum combination of absolute values from this matrix.
mat =
{{-348, -194, -191, -101, -67, 31},
{-293, -139, -136, -46, -12, 86},
{-261, -107, -104, -14, 20, 118},
{-139, 15, 18, 108, 142, 240},
{-151, 3, 6, 96, 130, 228},
{4, 158, 161, 251, 285, 383}}
I want to find a set of 6 elements that have the smallest sum of the absolute values when taking one element per row and per column. So in this case, either {4, 3, 18, 14, 12, 31}
or {4, 15, 6, 14, 12, 31}
.
eval = Flatten[ Table[{{i1, j1}, {i2, j2}, Abs@mat[[i1, j1]] + Abs@mat[[i2, j2]]}, {i1, 1, n}, {j1, 1, n}, {i2, DeleteCases[Range@n, i1]}, {j2, DeleteCases[Range@n, j1]}], 3];
and then extracting the minimum withmin = Extract[eval, First@Position[eval[[;; , 3]], Min@eval[[;; , 3]]]]
$\endgroup$ – Mauricio Fernández Aug 1 '17 at 8:10{{1, 2}, {5, 6}, {6, 4}, {4, 5}, {2, 1}, {3, 3}}
. There isdim!
possibilities and for the matrix he mention there are two with minimal summed absolute value $\endgroup$ – Coolwater Aug 1 '17 at 8:12