Boost logo

Boost Users :

Subject: [Boost-users] [BOOST USERS] [ BGL ] [GRAPH ] iterating through the vertices and edges of a filter graph
From: srinivas boppu (srinivas.fau_at_[hidden])
Date: 2012-01-26 08:06:44

Hello All,

I need a small help in iterating through the vertices and edges of a
filtered graph.

Here is some sample code of the filtered graph. (


#include <iostream>
 #include <boost/graph/adjacency_list.hpp>#include
<boost/array.hpp>#include <boost/graph/filtered_graph.hpp>#include
 template <typename TGraph>struct vertex_id_filter{
  bool operator()(const typename
boost::graph_traits<TGraph>::vertex_descriptor& v) const
    return 3 < v; // keep all vertx_descriptors greater than 3
 int main(){
  using namespace boost;

  typedef adjacency_list<vecS, vecS, directedS,
    no_property, property<edge_weight_t, int> > Graph;
  typedef property_map<Graph, edge_weight_t>::type EdgeWeightMap;

  unsigned int numberOfVertices = 10;
  Graph g(numberOfVertices);
  for(unsigned int i = 0; i < numberOfVertices - 1; ++i)
    add_edge(i, i+1, g);

  std::cout << "Original graph:" << std::endl;

  vertex_id_filter<Graph> filter;
  filtered_graph<Graph, boost::keep_all, vertex_id_filter<Graph> >
filteredGraph(g, boost::keep_all(), filter); // (graph, EdgePredicate,

  std::cout << "Filtered graph:" << std::endl;
  return 0;}


Here is my question.

How do I iterate through the vertices and edges of "filteredGraph".
I wanted to use the functions

vertices( filteredGraph) and edges(filteredGraph)

seems that we cannot use these functions as in the case of filtered graphs
they return filtered_iterators.

Please, can some one extend the above example and show me how to iterate
through the vertices and edges.

Thanks and Regards,
Srinivas Boppu

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at