我想得到图的最大匹配度。
现在,我使用Networkx中的算法:nx.algorithms.bipartite.matching.hopcroft_karp_matching(G)
然而,我在SNAPenter link description here中没有找到类似的算法。
对于NetworKit,我找到了这个页面:enter link description here。但是我不知道怎么用它。
有什么想法吗?如何使用NetworKit/SNAP来获得图的最大匹配?
发布于 2021-03-29 15:35:23
关于NetworKit:还没有提供计算精确最大匹配的算法,但您可以使用networkit.matching.PathGrowingMatcher,它实现了Drake和Hougardy 1的最大匹配的线性时间1/2近似算法。您可以按如下方式使用它:
import networkit as nk
# g is your graph
# Create and run the matching algorithm
matcher = nk.matching.PathGrowingMatcher(g).run()
# Get the matching, this returns an object of type networkit.matching.Matching
matching = matcher.getMatching()
# You can parse the computed matching by using
# matching.isMatched and matching.mate, for example:
for u in g.iterNodes():
if matching.isMatched(u):
print(f"Node {u} is matched with node {matching.mate(u)}")https://stackoverflow.com/questions/66845610
复制相似问题