#include #include #include #include namespace boost { enum vertex_component_t { vertex_component = 111 }; BOOST_INSTALL_PROPERTY(vertex, component); } using namespace boost; template struct vertexComponent { vertexComponent() {} vertexComponent(ComponentMap component, int f_component) : m_component(component), m_f_component(f_component) {} template bool operator()(const Vertex& v) const { return (get(m_component, v) == m_f_component); } ComponentMap m_component; int m_f_component; }; template struct edgeComponent { edgeComponent() {} edgeComponent(ComponentMap component, Graph g, int f_component) : m_component(component), m_g(g), m_f_component(f_component) {} template bool operator()(const Edge& e) const { return (get(m_component, source(e, m_g)) == m_f_component) && (get(m_component, target(e, m_g)) == m_f_component); } ComponentMap m_component; Graph m_g; int m_f_component; }; int main(int argc, char ** argv) { typedef adjacency_list > Graph; typedef property_map::type ComponentMap; typedef filtered_graph, vertexComponent > FilteredGraph; graph_traits < Graph >::vertex_iterator vi, vi_end; graph_traits < Graph >::out_edge_iterator oei, oei_end; graph_traits < FilteredGraph >::vertex_iterator fvi, fvi_end; graph_traits < FilteredGraph >::out_edge_iterator foei, foei_end; enum { A, B, C, D, E, F, G, H, I, N }; const char* name = "ABCDEFGHI"; Graph g(N); add_edge(A, B, g); add_edge(C, D, g); add_edge(D, E, g); add_edge(E, C, g); add_edge(F, A, g); add_edge(F, B, g); add_edge(G, H, g); add_edge(G, I, g); add_edge(H, I, g); std::cout<"< component(N); int numComponents = connected_components(g, make_iterator_property_map(component.begin(), get(vertex_index, g))); std::cout<<"Graph has "< efilter(get(vertex_component, g), g, i); vertexComponent vfilter(get(vertex_component, g), i); FilteredGraph fg(g, efilter, vfilter); std::cout<<"Filtered graph (component "<"<