Hi All,
I couldn't figure out how to use the component_index facility of the
incremental components algorithm when operating on an listS, listS
adjecency_list so I rolled my own as per below.
Any suggestion on how to use the provided interface are appreciated.
Hi Kelly,
A couple of weeks ago I saw a good example of "iterator_property_map"
usage in the similar situation but for connected_components() algorithm
(you need to add vertex_index property). Probably this can help you,
Sean Kelly wrote:
mainly to improve perfomance. Please, take a look on this example.
///////////////////////////////////////////////////////////////////////
#include
#include <vector>
#include <map>
#include <iostream> // for std::cout
#include <algorithm> // for std::for_each
#include // for boost::tie
#include // for boost::graph_traits
#include
#include
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;
}