首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用NetworKit/SNAP获得最大匹配?

如何使用NetworKit/SNAP获得最大匹配?
EN

Stack Overflow用户
提问于 2021-03-29 03:51:49
回答 1查看 53关注 0票数 0

我想得到图的最大匹配度。

现在,我使用Networkx中的算法:nx.algorithms.bipartite.matching.hopcroft_karp_matching(G)

然而,我在SNAPenter link description here中没有找到类似的算法。

对于NetworKit,我找到了这个页面:enter link description here。但是我不知道怎么用它。

有什么想法吗?如何使用NetworKit/SNAP来获得图的最大匹配?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-29 15:35:23

关于NetworKit:还没有提供计算精确最大匹配的算法,但您可以使用networkit.matching.PathGrowingMatcher,它实现了Drake和Hougardy 1的最大匹配的线性时间1/2近似算法。您可以按如下方式使用它:

代码语言:javascript
复制
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)}")

1

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66845610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档