| 1 | #include <boost/graph/adjacency_list.hpp>
|
|---|
| 2 | #include <boost/graph/depth_first_search.hpp>
|
|---|
| 3 | #include <boost/graph/biconnected_components.hpp>
|
|---|
| 4 | //#include "biconnected_components_fix.hpp"
|
|---|
| 5 |
|
|---|
| 6 | #include <iostream>
|
|---|
| 7 |
|
|---|
| 8 | using namespace boost;
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 | struct edge_component_t
|
|---|
| 12 | {
|
|---|
| 13 | typedef edge_property_tag kind;
|
|---|
| 14 | };
|
|---|
| 15 |
|
|---|
| 16 | typedef adjacency_list<
|
|---|
| 17 | vecS,
|
|---|
| 18 | vecS,
|
|---|
| 19 | directedS,
|
|---|
| 20 | no_property,
|
|---|
| 21 | property< edge_component_t, std::size_t > > Graph;
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | // my_visitor, simply writes to stdout which edge it comes across
|
|---|
| 27 | struct my_visitor : public default_dfs_visitor
|
|---|
| 28 | {
|
|---|
| 29 | template< typename Edge, typename Graph >
|
|---|
| 30 | void tree_edge( const Edge& e, const Graph& g )
|
|---|
| 31 | {
|
|---|
| 32 | std::cout << "tree: " << source( e, g ) << " -> " << target( e, g ) << "\n";
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | template< typename Edge, typename Graph >
|
|---|
| 36 | void forward_or_cross_edge( const Edge& e, const Graph& g )
|
|---|
| 37 | {
|
|---|
| 38 | std::cout << "forw: " << source( e, g ) << " -> " << target( e, g ) << "\n";
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | template< typename Edge, typename Graph >
|
|---|
| 42 | void back_edge( const Edge& e, const Graph& g )
|
|---|
| 43 | {
|
|---|
| 44 | std::cout << "back: " << source( e, g ) << " -> " << target( e, g ) << "\n";
|
|---|
| 45 | }
|
|---|
| 46 | };
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | int main ( int argc, char* argv[] )
|
|---|
| 53 | {
|
|---|
| 54 | // Create graph
|
|---|
| 55 | Graph g(4);
|
|---|
| 56 | add_edge( 0,1,g);
|
|---|
| 57 | add_edge( 1,0,g);
|
|---|
| 58 | add_edge( 1,2,g);
|
|---|
| 59 | add_edge( 2,1,g);
|
|---|
| 60 | add_edge( 2,3,g);
|
|---|
| 61 | add_edge( 3,2,g);
|
|---|
| 62 | add_edge( 3,0,g);
|
|---|
| 63 | add_edge( 0,3,g);
|
|---|
| 64 |
|
|---|
| 65 | // Print the graph to be sure
|
|---|
| 66 | print_graph( g );
|
|---|
| 67 |
|
|---|
| 68 | // component map
|
|---|
| 69 | property_map< Graph, edge_component_t >::type component = get( edge_component_t(), g );
|
|---|
| 70 |
|
|---|
| 71 | // compute biconnected components with our interior visitor
|
|---|
| 72 | biconnected_components( g, component, visitor( my_visitor() ) );
|
|---|
| 73 |
|
|---|
| 74 | return 0;
|
|---|
| 75 |
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|