Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/test/adjacency_matrix_test.cpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 10.2 KB
Line 
1/* adjacency_matrix_test.cpp source file
2 *
3 * Copyright Cromwell D. Enage 2004
4 *
5 * Distributed under the Boost Software License, Version 1.0. (See
6 * accompanying file LICENSE_1_0.txt or copy at
7 * http://www.boost.org/LICENSE_1_0.txt)
8 */
9
10/*
11 * Defines the std::ios class and std::cout, its global output instance.
12 */
13#include <iostream>
14
15/*
16 * Defines the boost::property_map class template and the boost::get and
17 * boost::put function templates.
18 */
19#include <boost/property_map.hpp>
20
21/*
22 * Defines the boost::graph_traits class template.
23 */
24#include <boost/graph/graph_traits.hpp>
25
26/*
27 * Defines the vertex and edge property tags.
28 */
29#include <boost/graph/properties.hpp>
30
31/*
32 * Defines the boost::adjacency_list class template and its associated
33 * non-member function templates.
34 */
35#include <boost/graph/adjacency_list.hpp>
36
37/*
38 * Defines the boost::adjacency_matrix class template and its associated
39 * non-member function templates.
40 */
41#include <boost/graph/adjacency_matrix.hpp>
42
43#include <boost/test/minimal.hpp>
44
45template<typename Graph1, typename Graph2>
46void run_test()
47{
48   typedef typename boost::property_map<Graph1, boost::vertex_index_t>::type
49           IndexMap1;
50   typedef typename boost::property_map<Graph2, boost::vertex_index_t>::type
51           IndexMap2;
52
53   Graph1 g1(24);
54   Graph2 g2(24);
55
56   boost::add_edge(boost::vertex(0, g1), boost::vertex(7, g1), g1);
57   boost::add_edge(boost::vertex(0, g2), boost::vertex(7, g2), g2);
58   boost::add_edge(boost::vertex(1, g1), boost::vertex(2, g1), g1);
59   boost::add_edge(boost::vertex(1, g2), boost::vertex(2, g2), g2);
60   boost::add_edge(boost::vertex(2, g1), boost::vertex(10, g1), g1);
61   boost::add_edge(boost::vertex(2, g2), boost::vertex(10, g2), g2);
62   boost::add_edge(boost::vertex(2, g1), boost::vertex(5, g1), g1);
63   boost::add_edge(boost::vertex(2, g2), boost::vertex(5, g2), g2);
64   boost::add_edge(boost::vertex(3, g1), boost::vertex(10, g1), g1);
65   boost::add_edge(boost::vertex(3, g2), boost::vertex(10, g2), g2);
66   boost::add_edge(boost::vertex(3, g1), boost::vertex(0, g1), g1);
67   boost::add_edge(boost::vertex(3, g2), boost::vertex(0, g2), g2);
68   boost::add_edge(boost::vertex(4, g1), boost::vertex(5, g1), g1);
69   boost::add_edge(boost::vertex(4, g2), boost::vertex(5, g2), g2);
70   boost::add_edge(boost::vertex(4, g1), boost::vertex(0, g1), g1);
71   boost::add_edge(boost::vertex(4, g2), boost::vertex(0, g2), g2);
72   boost::add_edge(boost::vertex(5, g1), boost::vertex(14, g1), g1);
73   boost::add_edge(boost::vertex(5, g2), boost::vertex(14, g2), g2);
74   boost::add_edge(boost::vertex(6, g1), boost::vertex(3, g1), g1);
75   boost::add_edge(boost::vertex(6, g2), boost::vertex(3, g2), g2);
76   boost::add_edge(boost::vertex(7, g1), boost::vertex(17, g1), g1);
77   boost::add_edge(boost::vertex(7, g2), boost::vertex(17, g2), g2);
78   boost::add_edge(boost::vertex(7, g1), boost::vertex(11, g1), g1);
79   boost::add_edge(boost::vertex(7, g2), boost::vertex(11, g2), g2);
80   boost::add_edge(boost::vertex(8, g1), boost::vertex(17, g1), g1);
81   boost::add_edge(boost::vertex(8, g2), boost::vertex(17, g2), g2);
82   boost::add_edge(boost::vertex(8, g1), boost::vertex(1, g1), g1);
83   boost::add_edge(boost::vertex(8, g2), boost::vertex(1, g2), g2);
84   boost::add_edge(boost::vertex(9, g1), boost::vertex(11, g1), g1);
85   boost::add_edge(boost::vertex(9, g2), boost::vertex(11, g2), g2);
86   boost::add_edge(boost::vertex(9, g1), boost::vertex(1, g1), g1);
87   boost::add_edge(boost::vertex(9, g2), boost::vertex(1, g2), g2);
88   boost::add_edge(boost::vertex(10, g1), boost::vertex(19, g1), g1);
89   boost::add_edge(boost::vertex(10, g2), boost::vertex(19, g2), g2);
90   boost::add_edge(boost::vertex(10, g1), boost::vertex(15, g1), g1);
91   boost::add_edge(boost::vertex(10, g2), boost::vertex(15, g2), g2);
92   boost::add_edge(boost::vertex(10, g1), boost::vertex(8, g1), g1);
93   boost::add_edge(boost::vertex(10, g2), boost::vertex(8, g2), g2);
94   boost::add_edge(boost::vertex(11, g1), boost::vertex(19, g1), g1);
95   boost::add_edge(boost::vertex(11, g2), boost::vertex(19, g2), g2);
96   boost::add_edge(boost::vertex(11, g1), boost::vertex(15, g1), g1);
97   boost::add_edge(boost::vertex(11, g2), boost::vertex(15, g2), g2);
98   boost::add_edge(boost::vertex(11, g1), boost::vertex(4, g1), g1);
99   boost::add_edge(boost::vertex(11, g2), boost::vertex(4, g2), g2);
100   boost::add_edge(boost::vertex(12, g1), boost::vertex(19, g1), g1);
101   boost::add_edge(boost::vertex(12, g2), boost::vertex(19, g2), g2);
102   boost::add_edge(boost::vertex(12, g1), boost::vertex(8, g1), g1);
103   boost::add_edge(boost::vertex(12, g2), boost::vertex(8, g2), g2);
104   boost::add_edge(boost::vertex(12, g1), boost::vertex(4, g1), g1);
105   boost::add_edge(boost::vertex(12, g2), boost::vertex(4, g2), g2);
106   boost::add_edge(boost::vertex(13, g1), boost::vertex(15, g1), g1);
107   boost::add_edge(boost::vertex(13, g2), boost::vertex(15, g2), g2);
108   boost::add_edge(boost::vertex(13, g1), boost::vertex(8, g1), g1);
109   boost::add_edge(boost::vertex(13, g2), boost::vertex(8, g2), g2);
110   boost::add_edge(boost::vertex(13, g1), boost::vertex(4, g1), g1);
111   boost::add_edge(boost::vertex(13, g2), boost::vertex(4, g2), g2);
112   boost::add_edge(boost::vertex(14, g1), boost::vertex(22, g1), g1);
113   boost::add_edge(boost::vertex(14, g2), boost::vertex(22, g2), g2);
114   boost::add_edge(boost::vertex(14, g1), boost::vertex(12, g1), g1);
115   boost::add_edge(boost::vertex(14, g2), boost::vertex(12, g2), g2);
116   boost::add_edge(boost::vertex(15, g1), boost::vertex(22, g1), g1);
117   boost::add_edge(boost::vertex(15, g2), boost::vertex(22, g2), g2);
118   boost::add_edge(boost::vertex(15, g1), boost::vertex(6, g1), g1);
119   boost::add_edge(boost::vertex(15, g2), boost::vertex(6, g2), g2);
120   boost::add_edge(boost::vertex(16, g1), boost::vertex(12, g1), g1);
121   boost::add_edge(boost::vertex(16, g2), boost::vertex(12, g2), g2);
122   boost::add_edge(boost::vertex(16, g1), boost::vertex(6, g1), g1);
123   boost::add_edge(boost::vertex(16, g2), boost::vertex(6, g2), g2);
124   boost::add_edge(boost::vertex(17, g1), boost::vertex(20, g1), g1);
125   boost::add_edge(boost::vertex(17, g2), boost::vertex(20, g2), g2);
126   boost::add_edge(boost::vertex(18, g1), boost::vertex(9, g1), g1);
127   boost::add_edge(boost::vertex(18, g2), boost::vertex(9, g2), g2);
128   boost::add_edge(boost::vertex(19, g1), boost::vertex(23, g1), g1);
129   boost::add_edge(boost::vertex(19, g2), boost::vertex(23, g2), g2);
130   boost::add_edge(boost::vertex(19, g1), boost::vertex(18, g1), g1);
131   boost::add_edge(boost::vertex(19, g2), boost::vertex(18, g2), g2);
132   boost::add_edge(boost::vertex(20, g1), boost::vertex(23, g1), g1);
133   boost::add_edge(boost::vertex(20, g2), boost::vertex(23, g2), g2);
134   boost::add_edge(boost::vertex(20, g1), boost::vertex(13, g1), g1);
135   boost::add_edge(boost::vertex(20, g2), boost::vertex(13, g2), g2);
136   boost::add_edge(boost::vertex(21, g1), boost::vertex(18, g1), g1);
137   boost::add_edge(boost::vertex(21, g2), boost::vertex(18, g2), g2);
138   boost::add_edge(boost::vertex(21, g1), boost::vertex(13, g1), g1);
139   boost::add_edge(boost::vertex(21, g2), boost::vertex(13, g2), g2);
140   boost::add_edge(boost::vertex(22, g1), boost::vertex(21, g1), g1);
141   boost::add_edge(boost::vertex(22, g2), boost::vertex(21, g2), g2);
142   boost::add_edge(boost::vertex(23, g1), boost::vertex(16, g1), g1);
143   boost::add_edge(boost::vertex(23, g2), boost::vertex(16, g2), g2);
144
145   IndexMap1 index_map1 = boost::get(boost::vertex_index_t(), g1);
146   IndexMap2 index_map2 = boost::get(boost::vertex_index_t(), g2);
147   typename boost::graph_traits<Graph1>::vertex_iterator vi1, vend1;
148   typename boost::graph_traits<Graph2>::vertex_iterator vi2, vend2;
149
150   typename boost::graph_traits<Graph1>::adjacency_iterator ai1, aend1;
151   typename boost::graph_traits<Graph2>::adjacency_iterator ai2, aend2;
152
153   for (boost::tie(vi1, vend1) = boost::vertices(g1), boost::tie(vi2, vend2) =boost::vertices(g2); vi1 != vend1; ++vi1, ++vi2)
154   {
155      BOOST_CHECK(boost::get(index_map1, *vi1) == boost::get(index_map2, *vi2));
156
157      for (boost::tie(ai1, aend1) = boost::adjacent_vertices(*vi1, g1),
158             boost::tie(ai2, aend2) = boost::adjacent_vertices(*vi2, g2);
159           ai1 != aend1;
160           ++ai1, ++ai2)
161      {
162        BOOST_CHECK(boost::get(index_map1, *ai1) == boost::get(index_map2, *ai2));
163      }
164   }
165
166   typename boost::graph_traits<Graph1>::out_edge_iterator ei1, eend1;
167   typename boost::graph_traits<Graph2>::out_edge_iterator ei2, eend2;
168
169   for (boost::tie(vi1, vend1) = boost::vertices(g1),
170          boost::tie(vi2, vend2) = boost::vertices(g2); vi1 != vend1; ++vi1, ++vi2)
171   {
172      BOOST_CHECK(boost::get(index_map1, *vi1) == boost::get(index_map2, *vi2));
173
174      for (boost::tie(ei1, eend1) = boost::out_edges(*vi1, g1), 
175             boost::tie(ei2, eend2) = boost::out_edges(*vi2, g2);
176           ei1 != eend1;
177           ++ei1, ++ei2)
178      {
179        BOOST_CHECK(boost::get(index_map1, boost::target(*ei1, g1)) == boost::get(index_map2, boost::target(*ei2, g2)));
180      }
181   }
182
183   typename boost::graph_traits<Graph1>::in_edge_iterator iei1, ieend1;
184   typename boost::graph_traits<Graph2>::in_edge_iterator iei2, ieend2;
185
186   for (boost::tie(vi1, vend1) = boost::vertices(g1),
187          boost::tie(vi2, vend2) = boost::vertices(g2); vi1 != vend1; ++vi1, ++vi2)
188   {
189      BOOST_CHECK(boost::get(index_map1, *vi1) == boost::get(index_map2, *vi2));
190
191      for (boost::tie(iei1, ieend1) = boost::in_edges(*vi1, g1), 
192             boost::tie(iei2, ieend2) = boost::in_edges(*vi2, g2);
193           iei1 != ieend1;
194           ++iei1, ++iei2)
195      {
196        BOOST_CHECK(boost::get(index_map1, boost::target(*iei1, g1)) == boost::get(index_map2, boost::target(*iei2, g2)));
197      }
198   }
199}
200
201int test_main(int, char*[])
202{
203    // Use setS to keep out edges in order, so they match the adjacency_matrix.
204   typedef boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS>
205           UGraph1;
206   typedef boost::adjacency_matrix<boost::undirectedS>
207           UGraph2;
208   run_test<UGraph1, UGraph2>();
209
210    // Use setS to keep out edges in order, so they match the adjacency_matrix.
211   typedef boost::adjacency_list<boost::setS, boost::vecS, 
212                                 boost::bidirectionalS>
213           BGraph1;
214   typedef boost::adjacency_matrix<boost::directedS>
215           BGraph2;
216   run_test<BGraph1, BGraph2>();
217
218   return 0;
219}
220
Note: See TracBrowser for help on using the repository browser.