saebyn / munkres-cpp

Kuhn-Munkres (Hungarian) Algorithm in C++
http://saebyn.info/2007/05/22/munkres-code-v2/
GNU General Public License v2.0
205 stars 79 forks source link

Wrong solution result for non square matrix. #10

Closed Gluttton closed 8 years ago

Gluttton commented 10 years ago

Based on test: MunkresTest.solve_3x2_NonObviousSolutionCase001_Success solution result for non square matrix is wrong.

Possibly reason (in my opinion):

  1. Wrong test case.
  2. Algorithm designed only for square matrix (so special assertion is required).
  3. Error in algorithm.
saebyn commented 10 years ago

This test passes when I disable the row/column minimization functions, so I'm going to start by looking in there to see if that's the problem.

saebyn commented 10 years ago

Nope, I never bothered to add support for non-square input matrices (and now I've discovered that fact), so that seems to have been the problem.

saebyn commented 10 years ago

Commit ae77d7ed17be95964aa15594c3de212c7032f0d5 adds support for rectangular inputs.

Gluttton commented 8 years ago

The problem have not solved completely.

Here is the related issue. Also commits 0acab86c220b839f5dec6ff68e66e4ef2ab10707 5b66cd73a5b85bba5544ebe3bd852c29fc434fa7 were added and related to the issue.

The problem is required more deeper research.

P.S. If input into the Google search field "the assignment problem no" the Google will prompt "n square matrix". So it looks like that such problem is really exists ;) .

Gluttton commented 8 years ago

I've simplified test data with preserving their behaviour. Instead of:

  Matrix<double> etalon_matrix{
    {-1.0, -1.0, -1.0, -1.0},
    { 0.0, -1.0, -1.0, -1.0},
    {-1.0,  0.0, -1.0, -1.0},
    {-1.0, -1.0, -1.0, -1.0},
    {-1.0, -1.0, -1.0,  0.0},
    {-1.0, -1.0,  0.0, -1.0}
  };
  Matrix<double> test_matrix{
    {1.79769e+308, 7.33184e+08,  9.41561e+08,  2.79247e+08},
    {3.06449e+08,  1.79769e+308, 3.3464e+08,   7.06878e+08},
    {9.93296e+08,  1.9414e+08,   1.79769e+308, 1.14174e+08},
    {3.51623e+08,  2.48635e+08,  7.81242e+08,  1.79769e+308},
    {7.02639e+08,  8.51663e+08,  9.37382e+08,  4.96945e+07},
    {7.58851e+08,  8.58445e+08,  8.7235e+07,   5.47076e+08}
  };

I use:

  Matrix<double> etalon_matrix{
    {-1.0, -1.0},
    { 0.0, -1.0},
    {-1.0,  0.0}
  };
  Matrix<double> test_matrix{
    {1.0e+17, 3},
    {2,       1.0e+17},
    {4,       1}
  };

etc...

After playing with simple tests I found out that my test cases for 7x5 and 5x7 matrices was wrong.

So it looks like the problem was fixed with commit 0acab86c220b839f5dec6ff68e66e4ef2ab10707 .