Jonker, Roy, and Anton Volgenant. “A shortest augmenting path algorithm for dense and sparse linear assignment problems.” Computing 38.4 (1987): 325-340.
github工具:https://github.com/src-d/lapjv
这个算法用于指派问题,求最小代价,时间复杂度O(n3)
在书本上我们学过用匈牙利解法,jonker-volgenant算法(也称lapjv算法)是一个比匈牙利解法更快的算法,算法流程学习中,这里是使用示例
使用示例
from lapjv import lapjv
import numpy as np
cost_matrix = np.array([
[1, 5, 3],
[2, 3, 7],
[5, 2, 9]
])
x_assign, y_assign, _ = lapjv(cost_matrix)
# 总代价最小
cost_value = 0
for _x, _y in zip(x_assign, y_assign):
print("选择", _x, _y)
cost_value += cost_matrix[_x, _y]
print("最小代价为:{}".format(cost_value))