Skip to content

Commit a10baaf

Browse files
committed
Add standalone Boost tests for make_biconnected_planar and make_maximal_planar
1 parent d36ac1a commit a10baaf

2 files changed

Lines changed: 213 additions & 0 deletions

File tree

gsoc_tests/test_biconnected.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//=======================================================================
2+
// Copyright 2007 Aaron Windsor
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 <iostream>
9+
#include <boost/graph/adjacency_list.hpp>
10+
#include <boost/graph/properties.hpp>
11+
#include <boost/graph/graph_traits.hpp>
12+
#include <boost/property_map/property_map.hpp>
13+
#include <boost/ref.hpp>
14+
#include <vector>
15+
16+
#include <boost/graph/biconnected_components.hpp>
17+
#include <boost/graph/make_biconnected_planar.hpp>
18+
#include <boost/graph/boyer_myrvold_planar_test.hpp>
19+
20+
using namespace boost;
21+
22+
int main(int argc, char** argv)
23+
{
24+
25+
typedef adjacency_list< vecS, vecS, undirectedS,
26+
property< vertex_index_t, int >, property< edge_index_t, int > >
27+
graph;
28+
29+
typedef adjacency_list< vecS, vecS, undirectedS,
30+
property< vertex_index_t, int >, property< edge_index_t, int > >
31+
graph;
32+
33+
// Create the graph - a straight line
34+
graph g(6);
35+
add_edge(0, 1, g);
36+
add_edge(1, 2, g);
37+
add_edge(2, 3, g);
38+
add_edge(3, 4, g);
39+
add_edge(4, 0, g); // Outer cycle
40+
add_edge(5, 0, g);
41+
add_edge(5, 1, g);
42+
add_edge(5, 2, g);
43+
add_edge(5, 3, g);
44+
add_edge(5, 4, g); // Center 5 connected to all
45+
46+
// Initialize the interior edge index
47+
auto e_index = get(edge_index, g);
48+
graph_traits< graph >::edges_size_type edge_count = 0;
49+
graph_traits< graph >::edge_iterator ei, ei_end;
50+
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
51+
put(e_index, *ei, edge_count++);
52+
53+
// Test for planarity; compute the planar embedding as a side-effect
54+
typedef std::vector< graph_traits< graph >::edge_descriptor > vec_t;
55+
std::vector< vec_t > embedding(num_vertices(g));
56+
if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
57+
boyer_myrvold_params::embedding = &embedding[0]))
58+
std::cout << "Input graph is planar" << std::endl;
59+
else
60+
std::cout << "Input graph is not planar" << std::endl;
61+
62+
typedef std::vector< graph_traits< graph >::edges_size_type >
63+
component_storage_t;
64+
typedef iterator_property_map< component_storage_t::iterator,
65+
property_map< graph, edge_index_t >::type >
66+
component_map_t;
67+
68+
component_storage_t component_storage(num_edges(g));
69+
component_map_t component(component_storage.begin(), get(edge_index, g));
70+
71+
std::cout << "Before calling make_biconnected_planar, the graph has "
72+
<< biconnected_components(g, component)
73+
<< " biconnected components" << std::endl;
74+
75+
make_biconnected_planar(g, &embedding[0]);
76+
77+
// Re-initialize the edge index, since we just added a few edges
78+
edge_count = 0;
79+
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
80+
put(e_index, *ei, edge_count++);
81+
82+
// Re-size the storage for the biconnected components, since we
83+
// just added a few edges
84+
85+
component_storage.resize(num_edges(g));
86+
component = component_map_t(component_storage.begin(), get(edge_index, g));
87+
88+
std::cout << "After calling make_biconnected_planar, the graph has "
89+
<< biconnected_components(g, component)
90+
<< " biconnected components" << std::endl;
91+
92+
if (boyer_myrvold_planarity_test(g))
93+
std::cout << "Also, the graph is still planar." << std::endl;
94+
else
95+
std::cout << "But the graph is not still planar." << std::endl;
96+
97+
return 0;
98+
}

gsoc_tests/test_maximalplanar.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//=======================================================================
2+
// Copyright 2007 Aaron Windsor
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 <iostream>
9+
#include <boost/graph/adjacency_list.hpp>
10+
#include <boost/graph/properties.hpp>
11+
#include <boost/graph/graph_traits.hpp>
12+
#include <boost/property_map/property_map.hpp>
13+
#include <boost/ref.hpp>
14+
#include <vector>
15+
16+
#include <boost/graph/make_biconnected_planar.hpp>
17+
#include <boost/graph/make_maximal_planar.hpp>
18+
#include <boost/graph/planar_face_traversal.hpp>
19+
#include <boost/graph/boyer_myrvold_planar_test.hpp>
20+
21+
// This example shows how to start with a connected planar graph
22+
// and add edges to make the graph maximal planar (triangulated.)
23+
// Any maximal planar simple graph on n vertices has 3n - 6 edges and
24+
// 2n - 4 faces, a consequence of Euler's formula.
25+
26+
using namespace boost;
27+
28+
// This visitor is passed to planar_face_traversal to count the
29+
// number of faces.
30+
struct face_counter : public planar_face_traversal_visitor
31+
{
32+
face_counter() : count(0) {}
33+
void begin_face() { ++count; }
34+
int count;
35+
};
36+
37+
int main(int argc, char** argv)
38+
{
39+
40+
typedef adjacency_list< vecS, vecS, undirectedS,
41+
property< vertex_index_t, int >, property< edge_index_t, int > >
42+
graph;
43+
44+
45+
graph g(5);
46+
add_edge(0, 1, g);
47+
add_edge(0, 2, g);
48+
add_edge(0, 3, g);
49+
add_edge(0, 4, g);
50+
// Star: 0 is center, 1-4 are leaves
51+
52+
std::cout << "Since the input graph is planar with " << num_vertices(g)
53+
<< " vertices," << std::endl
54+
<< "The output graph should be planar with "
55+
<< 3 * num_vertices(g) - 6 << " edges and "
56+
<< 2 * num_vertices(g) - 4 << " faces." << std::endl;
57+
58+
// Initialize the interior edge index
59+
auto e_index = get(edge_index, g);
60+
graph_traits< graph >::edges_size_type edge_count = 0;
61+
graph_traits< graph >::edge_iterator ei, ei_end;
62+
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
63+
put(e_index, *ei, edge_count++);
64+
65+
// Test for planarity; compute the planar embedding as a side-effect
66+
typedef std::vector< graph_traits< graph >::edge_descriptor > vec_t;
67+
std::vector< vec_t > embedding(num_vertices(g));
68+
if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
69+
boyer_myrvold_params::embedding = &embedding[0]))
70+
std::cout << "Input graph is planar" << std::endl;
71+
else
72+
std::cout << "Input graph is not planar" << std::endl;
73+
74+
make_biconnected_planar(g, &embedding[0]);
75+
76+
// Re-initialize the edge index, since we just added a few edges
77+
edge_count = 0;
78+
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
79+
put(e_index, *ei, edge_count++);
80+
81+
// Test for planarity again; compute the planar embedding as a side-effect
82+
if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
83+
boyer_myrvold_params::embedding = &embedding[0]))
84+
std::cout << "After calling make_biconnected, the graph is still planar"
85+
<< std::endl;
86+
else
87+
std::cout << "After calling make_biconnected, the graph is not planar"
88+
<< std::endl;
89+
90+
make_maximal_planar(g, &embedding[0]);
91+
92+
// Re-initialize the edge index, since we just added a few edges
93+
edge_count = 0;
94+
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
95+
put(e_index, *ei, edge_count++);
96+
97+
// Test for planarity one final time; compute the planar embedding as a
98+
// side-effect
99+
std::cout << "After calling make_maximal_planar, the final graph ";
100+
if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
101+
boyer_myrvold_params::embedding = &embedding[0]))
102+
std::cout << "is planar." << std::endl;
103+
else
104+
std::cout << "is not planar." << std::endl;
105+
106+
std::cout << "The final graph has " << num_edges(g) << " edges."
107+
<< std::endl;
108+
109+
face_counter count_visitor;
110+
planar_face_traversal(g, &embedding[0], count_visitor);
111+
std::cout << "The final graph has " << count_visitor.count << " faces."
112+
<< std::endl;
113+
114+
return 0;
115+
}

0 commit comments

Comments
 (0)