在 igraph-python 中被视为有向图的无向图

Undirected graphs treated as directed in igraph-python

我有一张通过读取 GML 文件创建的图表。我试图找到接触节点 N 的所有边。我的代码如下:

self.simGraph = Graph.Read_GML(file_name)
node = self.simGraph.vs.find(title=title)
edge_set = self.simGraph.es.select(_source=node.index)

我注意到,在调试时,edge_set 通常只包含一条边,但是当我将 _source 更改为 _target 时,我会得到一组不同的边。我尝试添加

self.simGraph = self.simGraph.as_undirected() 

但得到了相同的结果。

我错过了什么吗?

当您将当前顶点用作 'source' 或 'target' 时,您可能会得到不同的边集。似乎 igraph 随机分配 'source' 和 'target' 角色给无向网络的顶点,但它知道网络是无向的。即使您从头开始生成无向网络,当您将该顶点设置为源或目标时,连接到该顶点的边集也会不同。如果你想获得一个 o 顶点 i 上的边(id's)列表,使用下面的

g.incident(i)