Boost logo

Boost Users :

From: Detlef Mages (mages_at_[hidden])
Date: 2006-04-21 06:53:33


Hi,

What you  are missing is a color map. One solution is to use bundled
properties:

#include <boost/config.hpp>
#include <vector>
#include <map>
#include <iostream>                      // for std::cout
#include <algorithm>                     // for std::for_each
#include <boost/utility.hpp>             // for boost::tie
#include <boost/graph/graph_traits.hpp>  // for boost::graph_traits
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>

using namespace boost;

struct Node
{
 int index;
 //****color property******************************
 boost::default_color_type m_algo_color;
 //****color property******************************
};

struct Boundary
{
 double something;
};

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

int main(int argc, char*argv[])
{
 Graph g(5);
 boost::graph_traits<Graph>::vertex_iterator vi, viend;
 std::vector< int > c( num_vertices(g) );
 int num;
 // manually intialize the vertex index,
 // because we have listS as vertex list type
 int n = 0;
 for (tie(vi, viend) = vertices(g); vi != viend; ++vi, ++n) {
     g[*vi].index = n;
 }

 //****modified call******************************
 num = connected_components(g, make_iterator_property_map(c.begin(),
get(&Node::index, g)), boost::color_map( get(&Node::m_algo_color, g) ));
 //****modified call******************************
 return 0;
}

Detlef


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