8

The Hungarian algorithm solves the assignment problem in polynomial time. Given workers and tasks, and an n×n matrix containing the cost of assigning each worker to a task, it can find the cost minimizing assignment.

I want to find the choice for which cost is max? Can I do it using Hungarian or any similar method? Or this can only be done exponentially?

alvas
  • 115,346
  • 109
  • 446
  • 738
codersofthedark
  • 9,183
  • 8
  • 45
  • 70

2 Answers2

11

Wikipedia says:

If the goal is to find the assignment that yields the maximum cost, the problem can be altered to fit the setting by replacing each cost with the maximum cost subtracted by the cost.

So if I understand correctly: among all the costs you have as input, you find the maximum value. Then you replace each cost x by max - x. This way you still have positive costs and you can run the Hungarian algorithm.

Said differently: Hungarian tries to minimize the assignment cost. So, if you are looking for the maximum, you can reverse the costs: x -> -x. However, some implementations (don't know if all or any) require positive numbers. So the idea is to add a constant value to each cost in order to have positive numbers. This constant value does not change the resulting affectation.

Maxime Chéramy
  • 17,761
  • 8
  • 54
  • 75
  • can u explain with an example? – codersofthedark Jul 08 '13 at 07:09
  • @UtxD see my last edit. What don't you understand? I don't have the time right now to write a full example and I don't feel it's necessary. – Maxime Chéramy Jul 08 '13 at 07:37
  • The Wikipedia entry says that you need nonnegative costs, but that's probably not true for most implementations (though the resulting monotonicity property is convenient for the analysis). – David Eisenstat Jul 08 '13 at 12:11
  • 3
    (So just multiply the cost matrix by -1 for maximization.) – David Eisenstat Jul 08 '13 at 12:14
  • @DavidEisenstat I have edited my answer. I don't remember the details of this algorithm so I don't know if it's really mandatory but it's nothing to add a constant value to all costs (and does not change the affectation). You can always remove that cost at the end if you need the cost value too. – Maxime Chéramy Jul 08 '13 at 12:18
6

As David said in the comment:

Multiply the cost matrix by -1 for maximization.
codersofthedark
  • 9,183
  • 8
  • 45
  • 70