1 //=======================================================================
2 // Copyright 2007 Aaron Windsor
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 //=======================================================================
9 #include <boost/graph/adjacency_list.hpp>
10 #include <boost/graph/properties.hpp>
11 #include <boost/graph/make_biconnected_planar.hpp>
12 #include <boost/graph/biconnected_components.hpp>
13 #include <boost/graph/boyer_myrvold_planar_test.hpp>
14 #include <boost/property_map/property_map.hpp>
15 #include <boost/property_map/vector_property_map.hpp>
16 #include <boost/core/lightweight_test.hpp>
18 using namespace boost
;
20 template < typename Graph
> void reset_edge_index(Graph
& g
)
22 typename property_map
< Graph
, edge_index_t
>::type index
24 typename graph_traits
< Graph
>::edge_iterator ei
, ei_end
;
25 typename graph_traits
< Graph
>::edges_size_type cnt
= 0;
26 for (boost::tie(ei
, ei_end
) = edges(g
); ei
!= ei_end
; ++ei
)
27 put(index
, *ei
, cnt
++);
30 template < typename Graph
> void make_line_graph(Graph
& g
, int size
)
32 typedef typename graph_traits
< Graph
>::vertex_descriptor vertex_t
;
34 vertex_t prev_vertex
= add_vertex(g
);
36 for (int i
= 1; i
< size
; ++i
)
38 vertex_t curr_vertex
= add_vertex(g
);
39 add_edge(curr_vertex
, prev_vertex
, g
);
40 prev_vertex
= curr_vertex
;
44 struct UpdateVertexIndex
46 template < typename Graph
> void update(Graph
& g
)
48 typename property_map
< Graph
, vertex_index_t
>::type index
49 = get(vertex_index
, g
);
50 typename graph_traits
< Graph
>::vertex_iterator vi
, vi_end
;
51 typename graph_traits
< Graph
>::vertices_size_type cnt
= 0;
52 for (boost::tie(vi
, vi_end
) = vertices(g
); vi
!= vi_end
; ++vi
)
53 put(index
, *vi
, cnt
++);
57 struct NoVertexIndexUpdater
59 template < typename Graph
> void update(Graph
&) {}
62 template < typename Graph
, typename VertexIndexUpdater
>
63 void test_line_graph(VertexIndexUpdater vertex_index_updater
, int size
)
67 make_line_graph(g
, size
);
68 vertex_index_updater
.update(g
);
71 typedef std::vector
< typename graph_traits
< Graph
>::edge_descriptor
>
73 typedef std::vector
< edge_vector_t
> embedding_storage_t
;
74 typedef iterator_property_map
< typename
embedding_storage_t::iterator
,
75 typename property_map
< Graph
, vertex_index_t
>::type
>
78 embedding_storage_t
embedding_storage(num_vertices(g
));
79 embedding_t
embedding(embedding_storage
.begin(), get(vertex_index
, g
));
81 typename graph_traits
< Graph
>::vertex_iterator vi
, vi_end
;
82 for (boost::tie(vi
, vi_end
) = vertices(g
); vi
!= vi_end
; ++vi
)
83 std::copy(out_edges(*vi
, g
).first
, out_edges(*vi
, g
).second
,
84 std::back_inserter(embedding
[*vi
]));
86 BOOST_TEST(biconnected_components(
87 g
, make_vector_property_map
< int >(get(edge_index
, g
)))
89 BOOST_TEST(boyer_myrvold_planarity_test(g
));
90 make_biconnected_planar(g
, embedding
);
92 BOOST_TEST(biconnected_components(
93 g
, make_vector_property_map
< int >(get(edge_index
, g
)))
95 BOOST_TEST(boyer_myrvold_planarity_test(g
));
98 int main(int, char*[])
100 typedef adjacency_list
< vecS
, vecS
, undirectedS
,
101 property
< vertex_index_t
, int >, property
< edge_index_t
, int > >
104 typedef adjacency_list
< vecS
, listS
, undirectedS
,
105 property
< vertex_index_t
, int >, property
< edge_index_t
, int > >
108 typedef adjacency_list
< listS
, vecS
, undirectedS
,
109 property
< vertex_index_t
, int >, property
< edge_index_t
, int > >
112 typedef adjacency_list
< listS
, listS
, undirectedS
,
113 property
< vertex_index_t
, int >, property
< edge_index_t
, int > >
116 typedef adjacency_list
< setS
, setS
, undirectedS
,
117 property
< vertex_index_t
, int >, property
< edge_index_t
, int > >
120 test_line_graph
< VVgraph_t
>(NoVertexIndexUpdater(), 10);
121 test_line_graph
< VVgraph_t
>(NoVertexIndexUpdater(), 50);
123 test_line_graph
< VLgraph_t
>(UpdateVertexIndex(), 3);
124 test_line_graph
< VLgraph_t
>(UpdateVertexIndex(), 30);
126 test_line_graph
< LVgraph_t
>(NoVertexIndexUpdater(), 15);
127 test_line_graph
< LVgraph_t
>(NoVertexIndexUpdater(), 45);
129 test_line_graph
< LLgraph_t
>(UpdateVertexIndex(), 8);
130 test_line_graph
< LLgraph_t
>(UpdateVertexIndex(), 19);
132 test_line_graph
< SSgraph_t
>(UpdateVertexIndex(), 13);
133 test_line_graph
< SSgraph_t
>(UpdateVertexIndex(), 20);
135 return boost::report_errors();