7

I'm trying to implement the Hungarian algorithm. Everything is fine except for when the matrix isn't square. All the methods I've searched are saying that I should make it square by adding dummy rows/columns, and filling the dummy row/column with the maximum number in the matrix. My question is that won't this affect the final result? Shouldn't the dummy row/column be filled with at least max+1?

Sarah K
  • 71
  • 1
  • 2
  • I agree with your assessment. I always use max+1. – mikeTronix Sep 13 '18 at 00:15
  • 2
    I should note that this completely depends on whether you are set up for minimizing cost or maximizing throughput. In the latter case, set these additional rows/columns to zero, as suggested by Yay295. – mikeTronix Sep 13 '18 at 00:24
  • Zero won't work for the maximizing case if any weights are negative. – fuglede Jul 04 '19 at 19:15
  • 1
    It should also be noted that if you care about performance, the approach of adding dummies will generally increase the time it takes to solve the problem more than using specialized algorithms that cater to the non-square case would. See e.g. Bijsterbosch, Volgenant. *Solving the Rectangular assignment problem and applications*. 2010. Annals of Operations Research 181(1):443-462. DOI: 10.1007/s10479-010-0757-3 – fuglede Aug 18 '19 at 07:58

2 Answers2

5

The dummy values should all be zero. The point is that it doesn't matter which one you choose, you're going to ignore those choices in the end because they weren't in the original data. By making them zero (at the start), your algorithm won't have to work as hard to find a value you're not going to use.

Yay295
  • 1,628
  • 3
  • 17
  • 29
2

The main idea of the Hungarian algorithm is built upon the fact that the "optimal assignment of jobs, remains the same if a number is added/subtracted from all entries of any row or column of the matrix". Therefore, it does not matter if you use dummy value as "max or max+1 or 0". It can be set as any number and better it is 0 (as Yay295 said, the algorithm would like to work less if entries are already 0)

IY4
  • 160
  • 1
  • 7