0

So this seems very strange to me. I was solving the assignment problem on a 174x174 matrix first using Hungarian algorithm (munkres python package) and then solving it using the Google OR tools min-cost flow solver. I benchmarked the times it took and Munkres ran extremely slow (almost 12 times slower!):

Munkres: 48.2650001049s

GoogleOR: 4.4240000248s

As these are optimization algorithms, the resultant selections were the same, but why is GoogleOR so much faster? Could anyone explain?

Edit: The reason I find this even more surprising is that Munkres algorithm was specifically designed for solving the assignment problem whereas min-cost-flow is a far more generic algorithm.

Thanks.

user3425451
  • 25
  • 1
  • 7
  • The worst-case complexity describes asymptotic behaviour; furthermore, specific implementations might vary in the actual constants. For a given set of instances, a worse performance of the algorithm with "better" worst-case complexity itself is not a contradiction. – Codor Apr 27 '17 at 08:31
  • Thanks for the quick response Codor. I guess I should have clarified that the upper bounded time complexity wasn't my main question. What I'm really interested in is how there could be such a huge speedup, especially considering that Munkres is **designed** specifically for assignment problem whereas min-cost-flow is far more generic. Updated post to reflect this. – user3425451 Apr 27 '17 at 08:34
  • 1
    I would guess GoogleOR is better optimized. As a comparison, my own C++ implementation can solve a 1000x1000 matrix in the same time it took GoogleOR to solve that 174x174 matrix, so both of these times seem slow to me. – Yay295 Apr 27 '17 at 21:55
  • Okay, that makes more sense. Is it possible that because I'm running this in Python it makes the processing slower? I should also clarify that the cost values in the matrix I'm using can sometimes be quite large (somewhere around 10^7 or 10^8). Anyways, thanks! – user3425451 Apr 27 '17 at 22:30
  • Yes. Python is fairly easy to program in, but that also makes it slower than some other languages. Your numbers would have to be another order of magnitude larger for that to start being a possible issue. – Yay295 Apr 27 '17 at 23:28
  • Okay, I was also wondering if your implementation is a min-cost flow solution or specifically the Munkres algorithm? – user3425451 Apr 27 '17 at 23:30
  • 1
    It's a modification of Munkres that allows for non-square matrices. – Yay295 Apr 27 '17 at 23:55
  • 1
    The `Munkres` package is pure python plus `numpy`. The GoogleOR problem is written in Python, but uses `pywrapgraph`. The name suggests it's a Py wrapper to some sort of `graph` package, probably fast compiled code. With a different mix of interpreted/compiled code you can't meaningfully compare the algorithms. When I wrote my own version the MurrayState code in `numpy` I got a substantial speedup by moving one search function to Cython/C code. – hpaulj May 17 '17 at 16:42

0 Answers0