Can I use the Hungarian algorithm to find max cost?

[亡魂溺海] 提交于 2019-12-04 11:49:08

问题


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?


回答1:


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.




回答2:


As David said in the comment:

Multiply the cost matrix by -1 for maximization.


来源:https://stackoverflow.com/questions/17520691/can-i-use-the-hungarian-algorithm-to-find-max-cost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!