| 1 | //======================================================================= |
|---|
| 2 | // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee, |
|---|
| 3 | // |
|---|
| 4 | // Distributed under the Boost Software License, Version 1.0. (See |
|---|
| 5 | // accompanying file LICENSE_1_0.txt or copy at |
|---|
| 6 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 7 | //======================================================================= |
|---|
| 8 | #include <boost/config.hpp> |
|---|
| 9 | #include <vector> |
|---|
| 10 | #include <list> |
|---|
| 11 | #include <boost/graph/biconnected_components.hpp> |
|---|
| 12 | #include <boost/graph/adjacency_list.hpp> |
|---|
| 13 | #include <iterator> |
|---|
| 14 | #include <iostream> |
|---|
| 15 | |
|---|
| 16 | namespace boost |
|---|
| 17 | { |
|---|
| 18 | struct edge_component_t |
|---|
| 19 | { |
|---|
| 20 | enum |
|---|
| 21 | { num = 555 }; |
|---|
| 22 | typedef edge_property_tag kind; |
|---|
| 23 | } |
|---|
| 24 | edge_component; |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | int |
|---|
| 28 | main() |
|---|
| 29 | { |
|---|
| 30 | using namespace boost; |
|---|
| 31 | typedef adjacency_list < vecS, vecS, undirectedS, |
|---|
| 32 | no_property, property < edge_component_t, std::size_t > >graph_t; |
|---|
| 33 | typedef graph_traits < graph_t >::vertex_descriptor vertex_t; |
|---|
| 34 | graph_t g(9); |
|---|
| 35 | add_edge(0, 5, g); |
|---|
| 36 | add_edge(0, 1, g); |
|---|
| 37 | add_edge(0, 6, g); |
|---|
| 38 | add_edge(1, 2, g); |
|---|
| 39 | add_edge(1, 3, g); |
|---|
| 40 | add_edge(1, 4, g); |
|---|
| 41 | add_edge(2, 3, g); |
|---|
| 42 | add_edge(4, 5, g); |
|---|
| 43 | add_edge(6, 8, g); |
|---|
| 44 | add_edge(6, 7, g); |
|---|
| 45 | add_edge(7, 8, g); |
|---|
| 46 | |
|---|
| 47 | property_map < graph_t, edge_component_t >::type |
|---|
| 48 | component = get(edge_component, g); |
|---|
| 49 | |
|---|
| 50 | std::size_t num_comps = biconnected_components(g, component); |
|---|
| 51 | std::cerr << "Found " << num_comps << " biconnected components.\n"; |
|---|
| 52 | |
|---|
| 53 | std::vector<vertex_t> art_points; |
|---|
| 54 | articulation_points(g, std::back_inserter(art_points)); |
|---|
| 55 | std::cerr << "Found " << art_points.size() << " articulation points.\n"; |
|---|
| 56 | |
|---|
| 57 | std::cout << "graph A {\n" << " node[shape=\"circle\"]\n"; |
|---|
| 58 | |
|---|
| 59 | for (std::size_t i = 0; i < art_points.size(); ++i) { |
|---|
| 60 | std::cout << (char)(art_points[i] + 'A') |
|---|
| 61 | << " [ style=\"filled\", fillcolor=\"red\" ];" |
|---|
| 62 | << std::endl; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | graph_traits < graph_t >::edge_iterator ei, ei_end; |
|---|
| 66 | for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) |
|---|
| 67 | std::cout << (char)(source(*ei, g) + 'A') << " -- " |
|---|
| 68 | << (char)(target(*ei, g) + 'A') |
|---|
| 69 | << "[label=\"" << component[*ei] << "\"]\n"; |
|---|
| 70 | std::cout << "}\n"; |
|---|
| 71 | |
|---|
| 72 | return 0; |
|---|
| 73 | } |
|---|