Boost logo

Boost Users :

Subject: Re: [Boost-users] Selecting a random neighbor
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2011-12-20 19:09:04


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net