简体   繁体   English

在igraph-python中按照指示处理的无向图

[英]Undirected graphs treated as directed in igraph-python

I have a graph that I create by reading in a GML file. 我有一个通过读取GML文件创建的图表。 I'm trying to find all of the edges that touch a node N. My code is as follows: 我正在尝试找到触及节点N的所有边缘。我的代码如下:

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

I noticed, when debugging, that edge_set would often contain only one edge, but when I changed _source to _target , I would get a different set of edges. 我注意到,在调试时,edge_set通常只包含一个边,但是当我将_source更改为_target ,我会得到一组不同的边。 I tried adding 我尝试添加

self.simGraph = self.simGraph.as_undirected() 

but got the same results. 但得到了相同的结果。

Am I missing something? 我错过了什么吗?

You might be getting different sets of edges when you use the current vertex as 'source' or 'target'. 当您将当前顶点用作“源”或“目标”时,可能会获得不同的边集。 It seems like igraph is randomly assigning 'source' and 'target' roles to vertices for undirected networks but it knows that the network is undirected. 似乎igraph正在将“源”和“目标”角色随机分配给无向网络的顶点,但它知道网络是无向的。 Even if you generate an undirected network from scratch, the set of edges connected to a vertex will be different when you set that vertex as a source or a target. 即使您从头开始生成无向网络,当您将该顶点设置为源或目标时,连接到顶点的边集也会不同。 If you want to get a list of edges (id's) incident on ao vertex i, use the following 如果要获取ao vertex i上的边缘列表(id),请使用以下命令

g.incident(i)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM