Selecting a random neighbor

Hi, I'm totally new to BGL. I would like to know what is the best way to select a random neighbor of a vertex in an undirected graph without having to iterate through all neighbors. Can anyone help me with that? Thanks! George. -- George Bezerra Doctoral Student Department of Computer Science University of New Mexico, USA

On Tue, 20 Dec 2011, George Bezerra wrote:
Hi, I'm totally new to BGL. I would like to know what is the best way to select a random neighbor of a vertex in an undirected graph without having to iterate through all neighbors. Can anyone help me with that? Thanks!
There is an out_degree() function you can call, then use a random number from 0 to that value to index a particular outgoing edge. Use std::advance for counting to take advantage of out_edge_iterator types that directly support random access (not all do). -- Jeremiah Willcock
participants (2)
-
George Bezerra
-
Jeremiah Willcock