igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] How to enter and process a general tree in python using igr


From: harun pirim
Subject: Re: [igraph] How to enter and process a general tree in python using igraph
Date: Sat, 4 Sep 2010 19:00:14 -0500


The depth first search is not implemented yet, but it's easy to
implement it:

def dfsiter(graph, root):
   stack = [root]
       visited = set(stack)
       while stack:
           vertex = stack.pop()
               yield vertex
               not_visited_neis = set(graph.neighbors(vertex)) - visited
               stack.extend(not_visited_neis)
               visited.update(not_visited_neis)

for vertex in tree.dfsiter(0):
   print vertex.index


if it is not too time consuming can someone write an R code for DFS?

thanks
 
> and for finding a certain path from the root to a leaf node.
See the get_shortest_paths() method of the Graph object:

>>> g.shortest_paths(0, [5])
[[0, 2, 5]]

Note that g.shortest_paths can be used to determine the shortest paths
from a given vertex to more than one other vertex:

>>> g.shortest_paths(0, [5, 7])
[[0, 2, 5], [0, 1, 3, 7]]

--
Tamas

_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help


reply via email to

[Prev in Thread] Current Thread [Next in Thread]