加权二分图完美匹配算法,numpy实现,KM递归版本。当然还有BFS版本和费用流
原理和其他实现参考
https://blog.csdn.net/sixdaycoder/article/details/47720471
https://blog.csdn.net/u014754127/article/details/78086014
import numpy as np
class max_bipartite_graph_match(object):
def __init__(self,graph):
self.graph = graph
self.max_weight = graph.sum()
self.n,self.m = graph.shape
assert self.n == self.m
self.lx = self.graph.max(1)
self.ly = np.array([0] * self.m, dtype=int) #if weight of edges is float, change dtype to float
self.match = np.array([-1] * self.n, dtype=int)
self.slack = np.array([0] * self.m, dtype=int)
self.visx = np.array([False] * self.n, dtype=