gpt4 book ai didi

python - 二分图所有可能的最大匹配

转载 作者:太空狗 更新时间:2023-10-29 20:55:44 24 4
gpt4 key购买 nike

我正在使用 networkx找到 maximum cardinality matching的二分图。

匹配的边对于特定图不是唯一的。

有没有办法找到所有的最大匹配?

对于下面的例子,下面的所有边都可以是最大匹配:

{1: 2, 2: 1}{1: 3, 3: 1}{1: 4, 4: 1}

import networkx as nx
import matplotlib.pyplot as plt

G = nx.MultiDiGraph()
edges = [(1,3), (1,4), (1,2)]

nx.is_bipartite(G)
True

nx.draw(G, with_labels=True)
plt.show()

bipartite graph

不幸的是,

nx.bipartite.maximum_matching(G)

只返回

{1: 2, 2: 1}

有没有办法让我也获得其他组合?

最佳答案

Takeaki Uno 的论文“Algorithms for Enumerating All Perfect, Maximum and Maximal Matchings in Bipartite Graphs”有这方面的算法。 http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.107.8179&rep=rep1&type=pdf

定理 2 说“二分图中的最大匹配可以在 O(mn^1/2+nNm) 时间和 O(m) 空间,其中 Nm 是 G 中最大匹配的数量。"

关于python - 二分图所有可能的最大匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37144423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com