]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright 2009 Andrew Sutton |
2 | // | |
3 | // Use, modification and distribution are subject to the | |
4 | // Boost Software License, Version 1.0 (See accompanying file | |
5 | // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifndef TEST_DESTRUCTION_HPP | |
8 | #define TEST_DESTRUCTION_HPP | |
9 | ||
10 | #include <boost/concept/assert.hpp> | |
11 | #include <utility> | |
12 | ||
13 | /** @name Destroy Graph | |
14 | * Destroy the graph by removing vertices (if possible). | |
15 | */ | |
16 | //@{ | |
17 | // This will basically catch adjacency matrices, which don't get torn down. | |
f67539c2 | 18 | template < typename Graph, typename VertexSet, typename Remove, typename Label > |
7c673cae | 19 | void destroy_graph(Graph&, VertexSet const&, Remove, Label) |
f67539c2 TL |
20 | { |
21 | } | |
7c673cae FG |
22 | |
23 | // This matches MutableGraph, so just remove a vertex and then clear. | |
f67539c2 TL |
24 | template < typename Graph, typename VertexSet > |
25 | void destroy_graph( | |
26 | Graph& g, VertexSet const& verts, boost::mpl::true_, boost::mpl::false_) | |
27 | { | |
7c673cae | 28 | using namespace boost; |
f67539c2 TL |
29 | BOOST_CONCEPT_ASSERT((VertexListGraphConcept< Graph >)); |
30 | BOOST_CONCEPT_ASSERT((VertexMutableGraphConcept< Graph >)); | |
7c673cae FG |
31 | |
32 | std::cout << "...destroy_normal\n"; | |
33 | // Remove the roof vertex | |
34 | remove_vertex(verts[0], g); | |
35 | BOOST_ASSERT(num_vertices(g) == N - 1); | |
36 | } | |
37 | ||
38 | // This will match labeled graphs. | |
f67539c2 TL |
39 | template < typename Graph, typename VertexSet > |
40 | void destroy_graph( | |
41 | Graph& g, VertexSet const&, boost::mpl::false_, boost::mpl::true_) | |
42 | { | |
7c673cae | 43 | using namespace boost; |
f67539c2 | 44 | BOOST_CONCEPT_ASSERT((VertexListGraphConcept< Graph >)); |
7c673cae FG |
45 | // BOOST_CONCEPT_ASSERT(( VeretexMutableGraphConcept<Graph> )); |
46 | ||
47 | std::cout << "...destroy_labeled\n"; | |
48 | // Remove the roof vertex | |
49 | remove_vertex(0, g); | |
50 | BOOST_ASSERT(num_vertices(g) == N - 1); | |
51 | } | |
52 | //@} | |
53 | ||
7c673cae FG |
54 | /** @name Disconnect Graph |
55 | * Disconnect edges in the graph. Note that this doesn't fully disconnect the | |
56 | * graph. It simply determines if we can disconnect an edge or two and verify | |
57 | * that the resulting graph is valid. The Labeled type parameter is used to | |
58 | * dispatch for unlabeled and labeled graphs. | |
59 | * | |
60 | * @todo This doesn't quite work for multigraphs... | |
61 | */ | |
62 | //@{ | |
63 | ||
f67539c2 TL |
64 | template < typename Graph, typename VertexSet > |
65 | void disconnect_graph(Graph& g, VertexSet const& verts, boost::mpl::false_) | |
66 | { | |
7c673cae | 67 | using namespace boost; |
f67539c2 TL |
68 | BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >)); |
69 | BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept< Graph >)); | |
7c673cae FG |
70 | |
71 | std::cout << "...disconnect_normal\n"; | |
f67539c2 | 72 | typedef typename graph_traits< Graph >::edge_descriptor Edge; |
7c673cae FG |
73 | |
74 | // Disconnect the "lollipop" from the house. | |
75 | Edge e = edge(verts[5], verts[3], g).first; | |
76 | remove_edge(e, g); | |
77 | BOOST_ASSERT(num_edges(g) == M - 1); | |
78 | ||
79 | // Remove the "floor" edge from the house. | |
80 | remove_edge(verts[3], verts[2], g); | |
81 | BOOST_ASSERT(num_edges(g) == M - 2); | |
82 | ||
83 | // Fully disconnect the roof vertex. | |
84 | clear_vertex(verts[0], g); | |
85 | BOOST_ASSERT(num_edges(g) == M - 4); | |
86 | ||
87 | // What happens if we try to remove an edge that doesn't exist? | |
88 | remove_edge(verts[5], verts[0], g); | |
89 | BOOST_ASSERT(num_edges(g) == M - 4); | |
90 | } | |
91 | ||
f67539c2 TL |
92 | template < typename Graph, typename VertexSet > |
93 | void disconnect_graph(Graph& g, VertexSet const&, boost::mpl::true_) | |
94 | { | |
7c673cae | 95 | using namespace boost; |
f67539c2 | 96 | BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >)); |
7c673cae FG |
97 | // BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>)); |
98 | ||
99 | std::cout << "...disconnect_labeled\n"; | |
f67539c2 | 100 | typedef typename boost::graph_traits< Graph >::edge_descriptor Edge; |
7c673cae FG |
101 | |
102 | // Disconnect the "lollipop" from the house. | |
103 | Edge e = boost::edge_by_label(5, 3, g).first; | |
104 | boost::remove_edge(e, g); | |
105 | BOOST_ASSERT(boost::num_edges(g) == M - 1); | |
106 | ||
107 | // Remove the "floor" edge from the house. | |
108 | boost::remove_edge_by_label(3, 2, g); | |
109 | BOOST_ASSERT(boost::num_edges(g) == M - 2); | |
110 | ||
111 | // Fully disconnect the roof vertex. | |
112 | clear_vertex_by_label(0, g); | |
113 | BOOST_ASSERT(boost::num_edges(g) == M - 4); | |
114 | ||
115 | // What happens if we try to remove an edge that doesn't exist? | |
116 | boost::remove_edge_by_label(5, 0, g); | |
117 | BOOST_ASSERT(boost::num_edges(g) == M - 4); | |
118 | } | |
119 | //@} | |
120 | ||
121 | #endif |