[BOOST USERS] [ BGL ] [GRAPH ] iterating through the vertices and edges of a filter graph

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. (
http://programmingexamples.net/wiki/CPP/Boost/BGL/FilteredGraph)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include

On Thu, 26 Jan 2012, srinivas boppu wrote:
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. (http://programmingexamples.net/wiki/CPP/Boost/BGL/FilteredGraph)
------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
#include <iostream> #include
#include #include #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 > Graph; typedef property_map ::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; boost::print_graph(g); vertex_id_filter<Graph> filter; filtered_graph filteredGraph(g, boost::keep_all(), filter); // ( graph, EdgePredicate, VertexPredicate) std::cout << "Filtered graph:" << std::endl; boost::print_graph(filteredGraph); 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.
Yes, you use those functions and use the filtered_iterators produced to do your iteration. The special iterator type is used to return only the vertices and edges allowed by the filter. Iteration is exactly the same as on an unfiltered graph, just with the filtered_graph's iterators and functions. -- Jeremiah Willcock

Yes, you use those functions and use the filtered_iterators produced to do your iteration. The special iterator type is used to return only the vertices and edges allowed by the filter. Iteration is exactly the same as on an unfiltered graph, just with the filtered_graph's iterators and functions.
-- Jeremiah Willcock
Srinivas, I updated the example to get a vertex_iterator at the end: http://programmingexamples.net/wiki/CPP/Boost/BGL/FilteredGraphVertices David

Thank you all !!
It works and I understood the mistake I was making after looking at the
example.
Regards,
Srinivas Boppu
On Thu, Jan 26, 2012 at 4:26 PM, David Doria
Yes, you use those functions and use the filtered_iterators produced to do your iteration. The special iterator type is used to return only the vertices and edges allowed by the filter. Iteration is exactly the same as on an unfiltered graph, just with the filtered_graph's iterators and functions.
-- Jeremiah Willcock
Srinivas,
I updated the example to get a vertex_iterator at the end:
http://programmingexamples.net/wiki/CPP/Boost/BGL/FilteredGraphVertices
David _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
David Doria
-
Jeremiah Willcock
-
srinivas boppu