Munkres code v2.

As promised, here is the updated version of my Munkres algorithm code. The memory leak issue has been fixed, as well as the problems with the code sometimes failing to find a linear assignment for larger matrices.

Posted on May 22, 2007

Comments on This Post:

On June 4, 2007, Arrigo Marchiori said:
I think I found a bug in your code, that made main.cpp crash if a rectangular matrix, with more columns than lines, was created. In the destructor of the Matrix class, file matrix.cpp line 82, the for loop that deletes the single rows has m_columns as maximum value, instead of m_rows. Thank you for this piece of code! :-)
On June 4, 2007, John Weaver said:
Thanks Arrigo! This problem is now fixed.
On August 24, 2007, Anthony said:
Hi John, Thanks a lot for this piece of code, it is going to save me a lot of time! Regards, Anthony
On August 22, 2007, robert said:
Hi friend, When I compile your code using .NET 2003. There two errors said that the 'srandom' and random are unknown identifiers. Do you have any idea about that? Best, robert.
On August 22, 2007, John Weaver said:
Hi Robert, You'll probably have to replace random() and srandom() with rand() and srand() in order to get it compiled on Windows. I haven't tried to compile this code on Windows since I added the test code in main.cpp. -- John
On August 28, 2007, Anthony said:
Ouch ... my previous comment is poorly formatted, so I'm reposting it: Hi John, I would have mailed this to you, but I was unable to find your email address, so I'll say what I have to say here. I think there is something wrong, or at least unclear with your code. In munkres.cpp: <code> int Munkres::step1(void) { for ( int row = 0 ; row In "for loops" A and B, I think <code>&amp;&amp; !isstarred</code> should be added to the stop condition. It is at best useless to keep iterating if you found something that fits your needs; and at worst, but I think it is, wrong, because it will alter your results (in which way? difficult to say so, there are few comments in your code). About Munkres::pair_in_list: I think there is a simpler way to do that (meaning you don't need to write a new method), use STL find (http://www.sgi.com/tech/stl/find.html). Some other suggestions: * try to keep your code STL-oriented (e.g. use std::vector instead of bool* for row_mask and col_mask in class Munkres), it will be safer, shorter, and you won't have to worry about those new's and delete's * replace your #define directives for Z_NORMAL, Z_STAR and Z_PRIME with static const int variables that will be private members of Munkres * add more comments, please ;-) Hm... that's it for now. I'm having problems with your code not always yielding an optimal solution for some instances, but it's only a subroutine of a much larger program, so I might be the one who's doing something wrong elsewhere, I don't know. I hope you find these suggestions useful and that you will get back to me. Anyway, thanks again for this source! Anthony
On October 9, 2007, Akis said:
Hi John, I admit that you did a very nice job with the algorithm. The Munkres V2 code will save me lot of time. Now my question is: Can it handle infinite numbers? And if not, could that be done? e.g. a matrix like: [0.5 inf inf inf] should give me [0 -1 -1 -1] and not [0 -1 -1 0] which is the case If I use a very large numbers instead. Regards Akis
On January 7, 2008, Blake said:
I had a problem with the Munkres class not resetting the mask_matrix to zeros after the initial call to "Solve". It resizes this matrix, but this apparently doesn't reset it. As a result previous results (matrix entries set to ZPRIME) are incorrectly stored in this matrix causing incorrect associations. I added a call to the clear() function after the resize, and this seems to have fixed things. Other than that the code seems to work great. Thanks.

Comments are closed.