python - 图工具有投影二分图的方法吗?
问题描述
我正在尝试将二分图投影到两个单模式图中。
我想使用双投影方法分析二分图。我一直在使用 NetworkX,但我想尝试一下 graph-tool,因为它声称效率更高。我的图表有可能很快变得非常大,所以我想使用最有效的方法/包。包 graph-tool 声称效率更高,我想尝试一下,但我找不到使用它来投影二分图的方法。有谁知道这是否可以使用图形工具?我发现的唯一信息是创建者要求提出类似问题的人创建一张票,以便他/他们可以开始处理它,但它是从 2014 年开始的。
解决方案
我遇到了同样的问题并得到了解决方案。我已经让它在多达 500 万个节点的图表上工作。
它遵循三个主要步骤:
- 使用 is_bipartite 函数生成一个布尔数组,每个顶点所属的集合。
- 在要删除的集合上循环,在所有邻居组合之间添加边。
- 使用 GraphView 通过仅保留感兴趣集的节点来生成新图形。
g = gt.lattice([5,5])
is_biparitite, part = gt.is_bipartite(g, partition=True)
gt.graph_draw(g, vertex_fill_color=part) # to view the full graph coloured by set
from itertools import combinations
g_temp = g.copy() # this is a deepcopy
for v, bipartite_label in enumerate(part):
if bipartite_label == 0:
neighbours = list(g.vertex(v).all_neighbours())
for s, t in combinations(neighbours, 2):
g_temp.add_edge(s, t)
g_projected = gt.Graph(gt.GraphView(g_temp, vfilt=part.a==1), prune=True)
gt.graph_draw(g_projected)
推荐阅读
- c# - Microsoft.Data.SqlClient.SqlConnection 在调试/发布中工作,但在安装程序中失败
- java - 为什么非易失性变量在 CPU 共享缓存上更新?
- django - 使用参数作为 url 的一部分以及如何在 django rest 框架上处理它
- discord - 尝试为不和谐机器人设置权限,但似乎无法
- c - 如何检查二维数组中两个单元格之间的直接路径是否被给定单元格阻塞?
- python - FTP:如何处理挂起和恢复下载?
- python - 词干词频
- java - 我应该使用 cacerts 还是本地 trustore 但不能同时使用两者?
- python - OpenGL:我将如何实现纹理数组?
- python - 如何删除我的建议命令所需的引号用法