Boost logo

Boost Users :

From: Dmitry Bufistov (dmitry_at_[hidden])
Date: 2006-04-21 05:30:04


Hola Andre,
pleas take a look in this. Works more o less.
Atentamente,
--dmitry

André Loose wrote:
> Hi,
>
> I use an undirected graph with bundled properties and want to find out,
> whether it is connected, or not. Reading the documentation and some
> examples using property maps, I did not succeed in getting it to work.
> A minimal example that reproduces the compile errors follows. What am I
> doing wrong here:
>


#include <boost/config.hpp>
#include <boost/graph/graph_traits.hpp> // for boost::graph_traits
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
#include <boost/graph/iteration_macros.hpp>

struct Node
{
        typedef int vertex_index_t;
        vertex_index_t m_vertex_index;
        static vertex_index_t Node::* svertex_index;
};

Node::vertex_index_t Node::* svertex_index = &Node::m_vertex_index;

struct Boundary
{
        double something;
};

typedef boost::adjacency_list<
   boost::setS, boost::listS, boost::undirectedS,
   Node, Boundary, boost::no_property, boost::setS> Graph;

int main(int argc, char*argv[])
{
        using namespace boost;
        Graph g(5);
        // manually intialize the vertex index,
        // because we have listS as vertex list type
        int n = 0;
        BGL_FORALL_VERTICES(vd, g, Graph)
        {
                put(svertex_index, g, vd, n++);
        }
        typedef graph_traits<Graph>::vertex_descriptor vertex_t;
        std::map<vertex_t, int> comps;
        property_map<Graph, Node::vertex_index_t Node::*>::type i_m(get(svertex_index, g));
        int num = connected_components(g, make_assoc_property_map(comps),
                boost::vertex_index_map(i_m));
        std::cout << "Number of cc: " << num << std::endl;
        return 0;
}


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