Hello,
I was wondering if there's a equivalent to NetworkX's has_path function. I'd like to check if there is a path between two given vertexes, and if there is, then return True. This can be done in NetworkX with has_path. I think this is doable in graph-tool with StopSearch method, but I couldn't figure out a way to implement it. Any help is appreciated.
Thanks.
Am 23.09.18 um 18:18 schrieb Ozgun Altunkaya:
Hello,
I was wondering if there's a equivalent to NetworkX's has_path function. I'd like to check if there is a path between two given vertexes, and if there is, then return True. This can be done in NetworkX with has_path. I think this is doable in graph-tool with StopSearch method, but I couldn't figure out a way to implement it. Any help is appreciated.
This is trivial, just do:
has_path = shortest_distance(g, u, v) < g.num_vertices()
Best, Tiago
Hi,
Thanks for the reply. I've got two more questions:
edges = g.edge(1, 536) for e in edges: print(e)
returns None because there's no such edge. However, when I run
gt.shortest_distance(g, 1, 536)
it returns 2, but there shouldn't exist a path with length 2 between those points, am I wrong about this? What am I missing?
Also, slightly related, I added those points with g.add_edge_list(my_edge_list), which is a list of integer couples between 1 and 18000. Is there a way to run shortest_path just by using those numbers, without indexes?
Like, gt.shortest_path(g, 1, 536)
The above returns
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/anaconda3/lib/python3.6/site-packages/graph_tool/topology/__init__.py", line 1882, in shortest_path for e in v.in_edges() if g.is_directed() else v.out_edges(): AttributeError: 'int' object has no attribute 'in_edges'
On 9/24/18 10:57 AM, Tiago de Paula Peixoto wrote:
Am 23.09.18 um 18:18 schrieb Ozgun Altunkaya:
Hello,
I was wondering if there's a equivalent to NetworkX's has_path function. I'd like to check if there is a path between two given vertexes, and if there is, then return True. This can be done in NetworkX with has_path. I think this is doable in graph-tool with StopSearch method, but I couldn't figure out a way to implement it. Any help is appreciated.
This is trivial, just do:
has_path = shortest_distance(g, u, v) < g.num_vertices()
Best, Tiago
Am 25.09.18 um 00:51 schrieb Ozgun Altunkaya:
Hi,
Thanks for the reply. I've got two more questions:
edges = g.edge(1, 536) for e in edges: print(e)
returns None because there's no such edge. However, when I run
gt.shortest_distance(g, 1, 536)
it returns 2, but there shouldn't exist a path with length 2 between those points, am I wrong about this? What am I missing?
The existence of an edge between two nodes means that they are at a distance one from one another. The absence of an edge means the distance must be 2 or larger. A distance of 2 just means they share a neighbor.
Also, slightly related, I added those points with g.add_edge_list(my_edge_list), which is a list of integer couples between 1 and 18000. Is there a way to run shortest_path just by using those numbers, without indexes?
Like, gt.shortest_path(g, 1, 536)
The above returns
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/anaconda3/lib/python3.6/site-packages/graph_tool/topology/__init__.py", line 1882, in shortest_path for e in v.in_edges() if g.is_directed() else v.out_edges(): AttributeError: 'int' object has no attribute 'in_edges'
The function expects vertex descriptors:
shortest_path(g, g.vertex(1), g.vertex(536))
I'll fix it so that it accept indices for convenience.
Best, Tiago