# Boost Users :

Subject: Re: [Boost-users] [Graph] Computing reachable vertices on a graph
From: Florian.PONROY_at_[hidden]
Date: 2009-03-23 04:50:01

Hi Steven,

I just tried your solution, which works perfectly well. The vector is
actually sized to the number of reachable nodes. I just added a
reachable.reserve(max_number_of_nodes) to avoid multiple reallocations.

Thank you very much for your help,

Florian

-----Message d'origine-----
De : boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]]De la part de Steven
Watanabe
Envoyé : vendredi 20 mars 2009 18:36
À : boost-users_at_[hidden]
Objet : Re: [Boost-users] [Graph] Computing reachable vertices on a
graph

AMDG

Florian.PONROY_at_[hidden] wrote:
> I need to get the list of all reachable vertices from a given vertex in a
graph. I'm currently using the BFS algorithm to achieve that, which seems to
fit well to my need.
>

How does this work:

#include <boost/graph/visitors.hpp>
#include <vector>
#include <iterator>

boost::vecS,
boost::directedS > Graph;

int main() {

Graph G(1);

typedef Graph::vertex_descriptor Vertex;
std::vector<Vertex> reachable;

// The source vertex
Vertex s = *(boost::vertices(G).first);

boost::visitor(
boost::make_bfs_visitor(
boost::write_property(
boost::identity_property_map(),
std::back_inserter(reachable),
boost::on_discover_vertex()))));
}

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users