//======================================================================= // Copyright 2007 Aaron Windsor // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //======================================================================= #include #include #include #include #include #include #include using namespace boost; template void reset_edge_index(Graph& g) { typename property_map::type index = get(edge_index, g); typename graph_traits::edge_iterator ei, ei_end; typename graph_traits::edges_size_type cnt = 0; for(boost::tie(ei,ei_end) = edges(g); ei != ei_end; ++ei) put(index, *ei, cnt++); } template void make_cycle(Graph& g, int size) { typedef typename graph_traits::vertex_descriptor vertex_t; vertex_t first_vertex = add_vertex(g); vertex_t prev_vertex = first_vertex; for(int i = 1; i < size; ++i) { vertex_t curr_vertex = add_vertex(g); add_edge(curr_vertex, prev_vertex, g); prev_vertex = curr_vertex; } add_edge(first_vertex, prev_vertex, g); } struct UpdateVertexIndex { template void update(Graph& g) { typename property_map::type index = get(vertex_index, g); typename graph_traits::vertex_iterator vi, vi_end; typename graph_traits::vertices_size_type cnt = 0; for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi) put(index, *vi, cnt++); } }; struct NoVertexIndexUpdater { template void update(Graph&) {} }; template void test_cycle(VertexIndexUpdater vertex_index_updater, int size) { Graph g; make_cycle(g, size); vertex_index_updater.update(g); reset_edge_index(g); typedef std::vector< typename graph_traits::edge_descriptor > edge_vector_t; typedef std::vector< edge_vector_t > embedding_storage_t; typedef iterator_property_map < typename embedding_storage_t::iterator, typename property_map::type > embedding_t; embedding_storage_t embedding_storage(num_vertices(g)); embedding_t embedding(embedding_storage.begin(), get(vertex_index, g)); typename graph_traits::vertex_iterator vi, vi_end; for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi) std::copy(out_edges(*vi,g).first, out_edges(*vi,g).second, std::back_inserter(embedding[*vi])); BOOST_CHECK(boyer_myrvold_planarity_test(g)); make_maximal_planar(g, embedding); reset_edge_index(g); // A graph is maximal planar exactly when it's both // planar and has 3 * num_vertices(g) - 6 edges. BOOST_CHECK(num_edges(g) == 3 * num_vertices(g) - 6); BOOST_CHECK(boyer_myrvold_planarity_test(g)); } int test_main(int, char* []) { typedef adjacency_list , property > VVgraph_t; typedef adjacency_list , property > VLgraph_t; typedef adjacency_list , property > LVgraph_t; typedef adjacency_list , property > LLgraph_t; typedef adjacency_list , property > SSgraph_t; test_cycle(NoVertexIndexUpdater(), 10); test_cycle(NoVertexIndexUpdater(), 50); test_cycle(UpdateVertexIndex(), 3); test_cycle(UpdateVertexIndex(), 30); test_cycle(NoVertexIndexUpdater(), 15); test_cycle(NoVertexIndexUpdater(), 45); test_cycle(UpdateVertexIndex(), 8); test_cycle(UpdateVertexIndex(), 19); test_cycle(UpdateVertexIndex(), 13); test_cycle(UpdateVertexIndex(), 20); return 0; }