It takes <10 lines of Python code to do that so it’s unlikely that we’ll 
provide a separate function for that. Something along the lines of:  

import random, itertools

def random_walk_iterator(graph, v):
    while True:
        yield v
        v = random.choice(graph.neighbors(v))

walk = itertools.islice(random_walk_iterator(graph, start), desired_length)

Note that you need extra care in random_walk_iterator when the graph is 
directed because you have to handle cases when you get stuck in a dead end.

--  
T.


On Friday, 21 February 2014 at 06:11, Ahmed Abdeen Hamed wrote:

> It would be ideal if I can do a random walk that starts with a vertex and 
> randomly selects the next node until the path lengths is satisfied. I tried 
> community_walktrap() but it doesn't seem to be giving me what I need.  
>  
> -Ahmed
>  
>  
>  
> On Thu, Feb 20, 2014 at 11:38 PM, Ahmed Abdeen Hamed <[email protected] 
> (mailto:[email protected])> wrote:
> > Hello friends,
> >  
> > How can I perform graph traversal using BFS with a certain number of steps? 
> > Say I want start start with a source node s and then step when I find n 
> > number of traversed vertices?  
> >  
> > Much appreciated!
> >  
> > -Ahmed  
> _______________________________________________
> igraph-help mailing list
> [email protected] (mailto:[email protected])
> https://lists.nongnu.org/mailman/listinfo/igraph-help




_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to