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/test/minimal.hpp>
19 using namespace boost
;
22 template <typename Graph
>
23 void reset_edge_index(Graph
& g
)
25 typename property_map
<Graph
, edge_index_t
>::type index
= get(edge_index
, g
);
26 typename graph_traits
<Graph
>::edge_iterator ei
, ei_end
;
27 typename graph_traits
<Graph
>::edges_size_type cnt
= 0;
28 for(boost::tie(ei
,ei_end
) = edges(g
); ei
!= ei_end
; ++ei
)
29 put(index
, *ei
, cnt
++);
33 template <typename Graph
>
34 void make_line_graph(Graph
& g
, int size
)
36 typedef typename graph_traits
<Graph
>::vertex_descriptor vertex_t
;
38 vertex_t prev_vertex
= add_vertex(g
);
40 for(int i
= 1; i
< size
; ++i
)
42 vertex_t curr_vertex
= add_vertex(g
);
43 add_edge(curr_vertex
, prev_vertex
, g
);
44 prev_vertex
= curr_vertex
;
49 struct UpdateVertexIndex
51 template <typename Graph
>
54 typename property_map
<Graph
, vertex_index_t
>::type index
= get(vertex_index
, g
);
55 typename graph_traits
<Graph
>::vertex_iterator vi
, vi_end
;
56 typename graph_traits
<Graph
>::vertices_size_type cnt
= 0;
57 for(boost::tie(vi
,vi_end
) = vertices(g
); vi
!= vi_end
; ++vi
)
58 put(index
, *vi
, cnt
++);
63 struct NoVertexIndexUpdater
65 template <typename Graph
> void update(Graph
&) {}
70 template <typename Graph
, typename VertexIndexUpdater
>
71 void test_line_graph(VertexIndexUpdater vertex_index_updater
, int size
)
75 make_line_graph(g
, size
);
76 vertex_index_updater
.update(g
);
79 typedef std::vector
< typename graph_traits
<Graph
>::edge_descriptor
> edge_vector_t
;
80 typedef std::vector
< edge_vector_t
> embedding_storage_t
;
81 typedef iterator_property_map
82 < typename
embedding_storage_t::iterator
,
83 typename property_map
<Graph
, vertex_index_t
>::type
86 embedding_storage_t
embedding_storage(num_vertices(g
));
87 embedding_t
embedding(embedding_storage
.begin(), get(vertex_index
, g
));
89 typename graph_traits
<Graph
>::vertex_iterator vi
, vi_end
;
90 for(boost::tie(vi
,vi_end
) = vertices(g
); vi
!= vi_end
; ++vi
)
91 std::copy(out_edges(*vi
,g
).first
, out_edges(*vi
,g
).second
, std::back_inserter(embedding
[*vi
]));
93 BOOST_CHECK(biconnected_components(g
, make_vector_property_map
<int>(get(edge_index
,g
))) > 1);
94 BOOST_CHECK(boyer_myrvold_planarity_test(g
));
95 make_biconnected_planar(g
, embedding
);
97 BOOST_CHECK(biconnected_components(g
, make_vector_property_map
<int>(get(edge_index
,g
))) == 1);
98 BOOST_CHECK(boyer_myrvold_planarity_test(g
));
106 int test_main(int, char* [])
108 typedef adjacency_list
112 property
<vertex_index_t
, int>,
113 property
<edge_index_t
, int>
117 typedef adjacency_list
121 property
<vertex_index_t
, int>,
122 property
<edge_index_t
, int>
126 typedef adjacency_list
130 property
<vertex_index_t
, int>,
131 property
<edge_index_t
, int>
135 typedef adjacency_list
139 property
<vertex_index_t
, int>,
140 property
<edge_index_t
, int>
144 typedef adjacency_list
148 property
<vertex_index_t
, int>,
149 property
<edge_index_t
, int>
153 test_line_graph
<VVgraph_t
>(NoVertexIndexUpdater(), 10);
154 test_line_graph
<VVgraph_t
>(NoVertexIndexUpdater(), 50);
156 test_line_graph
<VLgraph_t
>(UpdateVertexIndex(), 3);
157 test_line_graph
<VLgraph_t
>(UpdateVertexIndex(), 30);
159 test_line_graph
<LVgraph_t
>(NoVertexIndexUpdater(), 15);
160 test_line_graph
<LVgraph_t
>(NoVertexIndexUpdater(), 45);
162 test_line_graph
<LLgraph_t
>(UpdateVertexIndex(), 8);
163 test_line_graph
<LLgraph_t
>(UpdateVertexIndex(), 19);
165 test_line_graph
<SSgraph_t
>(UpdateVertexIndex(), 13);
166 test_line_graph
<SSgraph_t
>(UpdateVertexIndex(), 20);