alpar@209
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
deba@57
|
2 |
*
|
alpar@209
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
deba@57
|
4 |
*
|
alpar@1270
|
5 |
* Copyright (C) 2003-2013
|
deba@57
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@57
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@57
|
8 |
*
|
deba@57
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@57
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@57
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@57
|
12 |
*
|
deba@57
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@57
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@57
|
15 |
* purpose.
|
deba@57
|
16 |
*
|
deba@57
|
17 |
*/
|
deba@57
|
18 |
|
deba@57
|
19 |
#include <lemon/concepts/graph.h>
|
deba@57
|
20 |
#include <lemon/list_graph.h>
|
deba@109
|
21 |
#include <lemon/smart_graph.h>
|
deba@365
|
22 |
#include <lemon/full_graph.h>
|
kpeter@346
|
23 |
#include <lemon/grid_graph.h>
|
kpeter@377
|
24 |
#include <lemon/hypercube_graph.h>
|
deba@57
|
25 |
|
deba@57
|
26 |
#include "test_tools.h"
|
kpeter@171
|
27 |
#include "graph_test.h"
|
deba@57
|
28 |
|
deba@57
|
29 |
using namespace lemon;
|
deba@57
|
30 |
using namespace lemon::concepts;
|
deba@57
|
31 |
|
deba@228
|
32 |
template <class Graph>
|
kpeter@387
|
33 |
void checkGraphBuild() {
|
deba@228
|
34 |
TEMPLATE_GRAPH_TYPEDEFS(Graph);
|
deba@228
|
35 |
|
deba@228
|
36 |
Graph G;
|
deba@228
|
37 |
checkGraphNodeList(G, 0);
|
deba@228
|
38 |
checkGraphEdgeList(G, 0);
|
kpeter@387
|
39 |
checkGraphArcList(G, 0);
|
deba@228
|
40 |
|
kpeter@783
|
41 |
G.reserveNode(3);
|
kpeter@783
|
42 |
G.reserveEdge(3);
|
kpeter@783
|
43 |
|
deba@228
|
44 |
Node
|
deba@228
|
45 |
n1 = G.addNode(),
|
deba@228
|
46 |
n2 = G.addNode(),
|
deba@228
|
47 |
n3 = G.addNode();
|
deba@228
|
48 |
checkGraphNodeList(G, 3);
|
deba@228
|
49 |
checkGraphEdgeList(G, 0);
|
kpeter@387
|
50 |
checkGraphArcList(G, 0);
|
deba@228
|
51 |
|
deba@228
|
52 |
Edge e1 = G.addEdge(n1, n2);
|
deba@228
|
53 |
check((G.u(e1) == n1 && G.v(e1) == n2) || (G.u(e1) == n2 && G.v(e1) == n1),
|
deba@228
|
54 |
"Wrong edge");
|
kpeter@387
|
55 |
|
deba@228
|
56 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
57 |
checkGraphEdgeList(G, 1);
|
deba@228
|
58 |
checkGraphArcList(G, 2);
|
deba@228
|
59 |
|
kpeter@387
|
60 |
checkGraphIncEdgeArcLists(G, n1, 1);
|
kpeter@387
|
61 |
checkGraphIncEdgeArcLists(G, n2, 1);
|
kpeter@387
|
62 |
checkGraphIncEdgeArcLists(G, n3, 0);
|
deba@228
|
63 |
|
kpeter@387
|
64 |
checkGraphConEdgeList(G, 1);
|
kpeter@387
|
65 |
checkGraphConArcList(G, 2);
|
deba@228
|
66 |
|
kpeter@387
|
67 |
Edge e2 = G.addEdge(n2, n1),
|
kpeter@387
|
68 |
e3 = G.addEdge(n2, n3);
|
alpar@1257
|
69 |
::lemon::ignore_unused_variable_warning(e2,e3);
|
deba@228
|
70 |
|
kpeter@387
|
71 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
72 |
checkGraphEdgeList(G, 3);
|
kpeter@387
|
73 |
checkGraphArcList(G, 6);
|
deba@228
|
74 |
|
kpeter@387
|
75 |
checkGraphIncEdgeArcLists(G, n1, 2);
|
kpeter@387
|
76 |
checkGraphIncEdgeArcLists(G, n2, 3);
|
kpeter@387
|
77 |
checkGraphIncEdgeArcLists(G, n3, 1);
|
deba@228
|
78 |
|
kpeter@387
|
79 |
checkGraphConEdgeList(G, 3);
|
deba@228
|
80 |
checkGraphConArcList(G, 6);
|
deba@228
|
81 |
|
deba@228
|
82 |
checkArcDirections(G);
|
deba@228
|
83 |
|
deba@228
|
84 |
checkNodeIds(G);
|
deba@228
|
85 |
checkArcIds(G);
|
deba@228
|
86 |
checkEdgeIds(G);
|
deba@228
|
87 |
checkGraphNodeMap(G);
|
deba@228
|
88 |
checkGraphArcMap(G);
|
deba@228
|
89 |
checkGraphEdgeMap(G);
|
deba@228
|
90 |
}
|
deba@228
|
91 |
|
kpeter@387
|
92 |
template <class Graph>
|
kpeter@387
|
93 |
void checkGraphAlter() {
|
kpeter@387
|
94 |
TEMPLATE_GRAPH_TYPEDEFS(Graph);
|
kpeter@387
|
95 |
|
kpeter@387
|
96 |
Graph G;
|
kpeter@387
|
97 |
Node n1 = G.addNode(), n2 = G.addNode(),
|
kpeter@387
|
98 |
n3 = G.addNode(), n4 = G.addNode();
|
kpeter@387
|
99 |
Edge e1 = G.addEdge(n1, n2), e2 = G.addEdge(n2, n1),
|
kpeter@387
|
100 |
e3 = G.addEdge(n2, n3), e4 = G.addEdge(n1, n4),
|
kpeter@387
|
101 |
e5 = G.addEdge(n4, n3);
|
alpar@1257
|
102 |
::lemon::ignore_unused_variable_warning(e1,e3,e4,e5);
|
kpeter@387
|
103 |
|
kpeter@387
|
104 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
105 |
checkGraphEdgeList(G, 5);
|
kpeter@387
|
106 |
checkGraphArcList(G, 10);
|
kpeter@387
|
107 |
|
kpeter@387
|
108 |
// Check changeU() and changeV()
|
kpeter@387
|
109 |
if (G.u(e2) == n2) {
|
kpeter@387
|
110 |
G.changeU(e2, n3);
|
kpeter@387
|
111 |
} else {
|
kpeter@387
|
112 |
G.changeV(e2, n3);
|
kpeter@387
|
113 |
}
|
kpeter@387
|
114 |
|
kpeter@387
|
115 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
116 |
checkGraphEdgeList(G, 5);
|
kpeter@387
|
117 |
checkGraphArcList(G, 10);
|
kpeter@387
|
118 |
|
kpeter@387
|
119 |
checkGraphIncEdgeArcLists(G, n1, 3);
|
kpeter@387
|
120 |
checkGraphIncEdgeArcLists(G, n2, 2);
|
kpeter@387
|
121 |
checkGraphIncEdgeArcLists(G, n3, 3);
|
kpeter@387
|
122 |
checkGraphIncEdgeArcLists(G, n4, 2);
|
kpeter@387
|
123 |
|
kpeter@387
|
124 |
checkGraphConEdgeList(G, 5);
|
kpeter@387
|
125 |
checkGraphConArcList(G, 10);
|
kpeter@387
|
126 |
|
kpeter@387
|
127 |
if (G.u(e2) == n1) {
|
kpeter@387
|
128 |
G.changeU(e2, n2);
|
kpeter@387
|
129 |
} else {
|
kpeter@387
|
130 |
G.changeV(e2, n2);
|
kpeter@387
|
131 |
}
|
kpeter@387
|
132 |
|
kpeter@387
|
133 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
134 |
checkGraphEdgeList(G, 5);
|
kpeter@387
|
135 |
checkGraphArcList(G, 10);
|
kpeter@387
|
136 |
|
kpeter@387
|
137 |
checkGraphIncEdgeArcLists(G, n1, 2);
|
kpeter@387
|
138 |
checkGraphIncEdgeArcLists(G, n2, 3);
|
kpeter@387
|
139 |
checkGraphIncEdgeArcLists(G, n3, 3);
|
kpeter@387
|
140 |
checkGraphIncEdgeArcLists(G, n4, 2);
|
kpeter@387
|
141 |
|
kpeter@387
|
142 |
checkGraphConEdgeList(G, 5);
|
kpeter@387
|
143 |
checkGraphConArcList(G, 10);
|
kpeter@387
|
144 |
|
kpeter@387
|
145 |
// Check contract()
|
kpeter@387
|
146 |
G.contract(n1, n4, false);
|
kpeter@387
|
147 |
|
kpeter@387
|
148 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
149 |
checkGraphEdgeList(G, 5);
|
kpeter@387
|
150 |
checkGraphArcList(G, 10);
|
kpeter@387
|
151 |
|
kpeter@387
|
152 |
checkGraphIncEdgeArcLists(G, n1, 4);
|
kpeter@387
|
153 |
checkGraphIncEdgeArcLists(G, n2, 3);
|
kpeter@387
|
154 |
checkGraphIncEdgeArcLists(G, n3, 3);
|
kpeter@387
|
155 |
|
kpeter@387
|
156 |
checkGraphConEdgeList(G, 5);
|
kpeter@387
|
157 |
checkGraphConArcList(G, 10);
|
kpeter@387
|
158 |
|
kpeter@387
|
159 |
G.contract(n2, n3);
|
kpeter@387
|
160 |
|
kpeter@387
|
161 |
checkGraphNodeList(G, 2);
|
kpeter@387
|
162 |
checkGraphEdgeList(G, 3);
|
kpeter@387
|
163 |
checkGraphArcList(G, 6);
|
kpeter@387
|
164 |
|
kpeter@387
|
165 |
checkGraphIncEdgeArcLists(G, n1, 4);
|
kpeter@387
|
166 |
checkGraphIncEdgeArcLists(G, n2, 2);
|
kpeter@387
|
167 |
|
kpeter@387
|
168 |
checkGraphConEdgeList(G, 3);
|
kpeter@387
|
169 |
checkGraphConArcList(G, 6);
|
kpeter@387
|
170 |
}
|
kpeter@387
|
171 |
|
kpeter@387
|
172 |
template <class Graph>
|
kpeter@387
|
173 |
void checkGraphErase() {
|
kpeter@387
|
174 |
TEMPLATE_GRAPH_TYPEDEFS(Graph);
|
kpeter@387
|
175 |
|
kpeter@387
|
176 |
Graph G;
|
kpeter@387
|
177 |
Node n1 = G.addNode(), n2 = G.addNode(),
|
kpeter@387
|
178 |
n3 = G.addNode(), n4 = G.addNode();
|
kpeter@387
|
179 |
Edge e1 = G.addEdge(n1, n2), e2 = G.addEdge(n2, n1),
|
kpeter@387
|
180 |
e3 = G.addEdge(n2, n3), e4 = G.addEdge(n1, n4),
|
kpeter@387
|
181 |
e5 = G.addEdge(n4, n3);
|
alpar@1257
|
182 |
::lemon::ignore_unused_variable_warning(e1,e3,e4,e5);
|
kpeter@387
|
183 |
|
kpeter@387
|
184 |
// Check edge deletion
|
kpeter@387
|
185 |
G.erase(e2);
|
kpeter@387
|
186 |
|
kpeter@387
|
187 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
188 |
checkGraphEdgeList(G, 4);
|
kpeter@387
|
189 |
checkGraphArcList(G, 8);
|
kpeter@387
|
190 |
|
kpeter@387
|
191 |
checkGraphIncEdgeArcLists(G, n1, 2);
|
kpeter@387
|
192 |
checkGraphIncEdgeArcLists(G, n2, 2);
|
kpeter@387
|
193 |
checkGraphIncEdgeArcLists(G, n3, 2);
|
kpeter@387
|
194 |
checkGraphIncEdgeArcLists(G, n4, 2);
|
kpeter@387
|
195 |
|
kpeter@387
|
196 |
checkGraphConEdgeList(G, 4);
|
kpeter@387
|
197 |
checkGraphConArcList(G, 8);
|
kpeter@387
|
198 |
|
kpeter@387
|
199 |
// Check node deletion
|
kpeter@387
|
200 |
G.erase(n3);
|
kpeter@387
|
201 |
|
kpeter@387
|
202 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
203 |
checkGraphEdgeList(G, 2);
|
kpeter@387
|
204 |
checkGraphArcList(G, 4);
|
kpeter@387
|
205 |
|
kpeter@387
|
206 |
checkGraphIncEdgeArcLists(G, n1, 2);
|
kpeter@387
|
207 |
checkGraphIncEdgeArcLists(G, n2, 1);
|
kpeter@387
|
208 |
checkGraphIncEdgeArcLists(G, n4, 1);
|
kpeter@387
|
209 |
|
kpeter@387
|
210 |
checkGraphConEdgeList(G, 2);
|
kpeter@387
|
211 |
checkGraphConArcList(G, 4);
|
kpeter@387
|
212 |
}
|
kpeter@387
|
213 |
|
kpeter@387
|
214 |
|
kpeter@387
|
215 |
template <class Graph>
|
kpeter@387
|
216 |
void checkGraphSnapshot() {
|
kpeter@387
|
217 |
TEMPLATE_GRAPH_TYPEDEFS(Graph);
|
kpeter@387
|
218 |
|
kpeter@387
|
219 |
Graph G;
|
kpeter@387
|
220 |
Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
|
kpeter@387
|
221 |
Edge e1 = G.addEdge(n1, n2), e2 = G.addEdge(n2, n1),
|
kpeter@387
|
222 |
e3 = G.addEdge(n2, n3);
|
alpar@1257
|
223 |
::lemon::ignore_unused_variable_warning(e1,e2,e3);
|
kpeter@387
|
224 |
|
kpeter@387
|
225 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
226 |
checkGraphEdgeList(G, 3);
|
kpeter@387
|
227 |
checkGraphArcList(G, 6);
|
kpeter@387
|
228 |
|
kpeter@387
|
229 |
typename Graph::Snapshot snapshot(G);
|
kpeter@387
|
230 |
|
kpeter@387
|
231 |
Node n = G.addNode();
|
kpeter@387
|
232 |
G.addEdge(n3, n);
|
kpeter@387
|
233 |
G.addEdge(n, n3);
|
kpeter@387
|
234 |
G.addEdge(n3, n2);
|
kpeter@387
|
235 |
|
kpeter@387
|
236 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
237 |
checkGraphEdgeList(G, 6);
|
kpeter@387
|
238 |
checkGraphArcList(G, 12);
|
kpeter@387
|
239 |
|
kpeter@387
|
240 |
snapshot.restore();
|
kpeter@387
|
241 |
|
kpeter@387
|
242 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
243 |
checkGraphEdgeList(G, 3);
|
kpeter@387
|
244 |
checkGraphArcList(G, 6);
|
kpeter@387
|
245 |
|
kpeter@387
|
246 |
checkGraphIncEdgeArcLists(G, n1, 2);
|
kpeter@387
|
247 |
checkGraphIncEdgeArcLists(G, n2, 3);
|
kpeter@387
|
248 |
checkGraphIncEdgeArcLists(G, n3, 1);
|
kpeter@387
|
249 |
|
kpeter@387
|
250 |
checkGraphConEdgeList(G, 3);
|
kpeter@387
|
251 |
checkGraphConArcList(G, 6);
|
kpeter@387
|
252 |
|
kpeter@387
|
253 |
checkNodeIds(G);
|
kpeter@387
|
254 |
checkEdgeIds(G);
|
kpeter@387
|
255 |
checkArcIds(G);
|
kpeter@387
|
256 |
checkGraphNodeMap(G);
|
kpeter@387
|
257 |
checkGraphEdgeMap(G);
|
kpeter@387
|
258 |
checkGraphArcMap(G);
|
kpeter@387
|
259 |
|
kpeter@387
|
260 |
G.addNode();
|
kpeter@387
|
261 |
snapshot.save(G);
|
kpeter@387
|
262 |
|
kpeter@387
|
263 |
G.addEdge(G.addNode(), G.addNode());
|
kpeter@387
|
264 |
|
kpeter@387
|
265 |
snapshot.restore();
|
kpeter@787
|
266 |
snapshot.save(G);
|
kpeter@787
|
267 |
|
kpeter@787
|
268 |
checkGraphNodeList(G, 4);
|
kpeter@787
|
269 |
checkGraphEdgeList(G, 3);
|
kpeter@787
|
270 |
checkGraphArcList(G, 6);
|
alpar@956
|
271 |
|
kpeter@787
|
272 |
G.addEdge(G.addNode(), G.addNode());
|
kpeter@787
|
273 |
|
kpeter@787
|
274 |
snapshot.restore();
|
kpeter@387
|
275 |
|
kpeter@387
|
276 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
277 |
checkGraphEdgeList(G, 3);
|
kpeter@387
|
278 |
checkGraphArcList(G, 6);
|
kpeter@387
|
279 |
}
|
kpeter@387
|
280 |
|
deba@365
|
281 |
void checkFullGraph(int num) {
|
deba@365
|
282 |
typedef FullGraph Graph;
|
deba@365
|
283 |
GRAPH_TYPEDEFS(Graph);
|
deba@365
|
284 |
|
deba@365
|
285 |
Graph G(num);
|
kpeter@784
|
286 |
check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
|
kpeter@784
|
287 |
"Wrong size");
|
kpeter@784
|
288 |
|
kpeter@784
|
289 |
G.resize(num);
|
kpeter@784
|
290 |
check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
|
kpeter@784
|
291 |
"Wrong size");
|
kpeter@784
|
292 |
|
deba@365
|
293 |
checkGraphNodeList(G, num);
|
deba@365
|
294 |
checkGraphEdgeList(G, num * (num - 1) / 2);
|
deba@365
|
295 |
|
deba@365
|
296 |
for (NodeIt n(G); n != INVALID; ++n) {
|
kpeter@377
|
297 |
checkGraphOutArcList(G, n, num - 1);
|
kpeter@377
|
298 |
checkGraphInArcList(G, n, num - 1);
|
kpeter@377
|
299 |
checkGraphIncEdgeList(G, n, num - 1);
|
deba@365
|
300 |
}
|
deba@365
|
301 |
|
deba@365
|
302 |
checkGraphConArcList(G, num * (num - 1));
|
deba@365
|
303 |
checkGraphConEdgeList(G, num * (num - 1) / 2);
|
deba@365
|
304 |
|
deba@365
|
305 |
checkArcDirections(G);
|
deba@365
|
306 |
|
deba@365
|
307 |
checkNodeIds(G);
|
deba@365
|
308 |
checkArcIds(G);
|
deba@365
|
309 |
checkEdgeIds(G);
|
deba@365
|
310 |
checkGraphNodeMap(G);
|
deba@365
|
311 |
checkGraphArcMap(G);
|
deba@365
|
312 |
checkGraphEdgeMap(G);
|
deba@365
|
313 |
|
kpeter@377
|
314 |
|
deba@365
|
315 |
for (int i = 0; i < G.nodeNum(); ++i) {
|
deba@365
|
316 |
check(G.index(G(i)) == i, "Wrong index");
|
deba@365
|
317 |
}
|
deba@365
|
318 |
|
deba@365
|
319 |
for (NodeIt u(G); u != INVALID; ++u) {
|
deba@365
|
320 |
for (NodeIt v(G); v != INVALID; ++v) {
|
deba@365
|
321 |
Edge e = G.edge(u, v);
|
deba@365
|
322 |
Arc a = G.arc(u, v);
|
deba@365
|
323 |
if (u == v) {
|
deba@365
|
324 |
check(e == INVALID, "Wrong edge lookup");
|
deba@365
|
325 |
check(a == INVALID, "Wrong arc lookup");
|
deba@365
|
326 |
} else {
|
deba@365
|
327 |
check((G.u(e) == u && G.v(e) == v) ||
|
deba@365
|
328 |
(G.u(e) == v && G.v(e) == u), "Wrong edge lookup");
|
deba@365
|
329 |
check(G.source(a) == u && G.target(a) == v, "Wrong arc lookup");
|
deba@365
|
330 |
}
|
deba@365
|
331 |
}
|
deba@365
|
332 |
}
|
deba@365
|
333 |
}
|
deba@365
|
334 |
|
deba@228
|
335 |
void checkConcepts() {
|
kpeter@171
|
336 |
{ // Checking graph components
|
deba@57
|
337 |
checkConcept<BaseGraphComponent, BaseGraphComponent >();
|
deba@57
|
338 |
|
alpar@209
|
339 |
checkConcept<IDableGraphComponent<>,
|
deba@57
|
340 |
IDableGraphComponent<> >();
|
deba@57
|
341 |
|
alpar@209
|
342 |
checkConcept<IterableGraphComponent<>,
|
deba@57
|
343 |
IterableGraphComponent<> >();
|
deba@57
|
344 |
|
alpar@209
|
345 |
checkConcept<MappableGraphComponent<>,
|
deba@57
|
346 |
MappableGraphComponent<> >();
|
deba@57
|
347 |
}
|
kpeter@171
|
348 |
{ // Checking skeleton graph
|
kpeter@171
|
349 |
checkConcept<Graph, Graph>();
|
deba@57
|
350 |
}
|
kpeter@171
|
351 |
{ // Checking ListGraph
|
kpeter@171
|
352 |
checkConcept<Graph, ListGraph>();
|
kpeter@171
|
353 |
checkConcept<AlterableGraphComponent<>, ListGraph>();
|
kpeter@171
|
354 |
checkConcept<ExtendableGraphComponent<>, ListGraph>();
|
kpeter@171
|
355 |
checkConcept<ClearableGraphComponent<>, ListGraph>();
|
kpeter@171
|
356 |
checkConcept<ErasableGraphComponent<>, ListGraph>();
|
kpeter@171
|
357 |
}
|
kpeter@171
|
358 |
{ // Checking SmartGraph
|
kpeter@171
|
359 |
checkConcept<Graph, SmartGraph>();
|
kpeter@171
|
360 |
checkConcept<AlterableGraphComponent<>, SmartGraph>();
|
kpeter@171
|
361 |
checkConcept<ExtendableGraphComponent<>, SmartGraph>();
|
kpeter@171
|
362 |
checkConcept<ClearableGraphComponent<>, SmartGraph>();
|
kpeter@171
|
363 |
}
|
deba@365
|
364 |
{ // Checking FullGraph
|
deba@365
|
365 |
checkConcept<Graph, FullGraph>();
|
deba@365
|
366 |
}
|
kpeter@346
|
367 |
{ // Checking GridGraph
|
kpeter@346
|
368 |
checkConcept<Graph, GridGraph>();
|
kpeter@346
|
369 |
}
|
kpeter@377
|
370 |
{ // Checking HypercubeGraph
|
kpeter@377
|
371 |
checkConcept<Graph, HypercubeGraph>();
|
kpeter@377
|
372 |
}
|
deba@57
|
373 |
}
|
deba@57
|
374 |
|
deba@57
|
375 |
template <typename Graph>
|
deba@228
|
376 |
void checkGraphValidity() {
|
deba@149
|
377 |
TEMPLATE_GRAPH_TYPEDEFS(Graph);
|
deba@57
|
378 |
Graph g;
|
deba@57
|
379 |
|
deba@57
|
380 |
Node
|
deba@57
|
381 |
n1 = g.addNode(),
|
deba@57
|
382 |
n2 = g.addNode(),
|
deba@57
|
383 |
n3 = g.addNode();
|
deba@57
|
384 |
|
deba@57
|
385 |
Edge
|
deba@57
|
386 |
e1 = g.addEdge(n1, n2),
|
deba@57
|
387 |
e2 = g.addEdge(n2, n3);
|
alpar@1257
|
388 |
::lemon::ignore_unused_variable_warning(e2);
|
deba@57
|
389 |
|
kpeter@171
|
390 |
check(g.valid(n1), "Wrong validity check");
|
kpeter@171
|
391 |
check(g.valid(e1), "Wrong validity check");
|
kpeter@171
|
392 |
check(g.valid(g.direct(e1, true)), "Wrong validity check");
|
kpeter@171
|
393 |
|
kpeter@171
|
394 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
|
kpeter@171
|
395 |
check(!g.valid(g.edgeFromId(-1)), "Wrong validity check");
|
kpeter@171
|
396 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
|
deba@57
|
397 |
}
|
deba@57
|
398 |
|
deba@149
|
399 |
template <typename Graph>
|
deba@228
|
400 |
void checkGraphValidityErase() {
|
deba@149
|
401 |
TEMPLATE_GRAPH_TYPEDEFS(Graph);
|
deba@149
|
402 |
Graph g;
|
deba@149
|
403 |
|
deba@149
|
404 |
Node
|
deba@149
|
405 |
n1 = g.addNode(),
|
deba@149
|
406 |
n2 = g.addNode(),
|
deba@149
|
407 |
n3 = g.addNode();
|
deba@149
|
408 |
|
deba@149
|
409 |
Edge
|
deba@149
|
410 |
e1 = g.addEdge(n1, n2),
|
deba@149
|
411 |
e2 = g.addEdge(n2, n3);
|
deba@149
|
412 |
|
kpeter@171
|
413 |
check(g.valid(n1), "Wrong validity check");
|
kpeter@171
|
414 |
check(g.valid(e1), "Wrong validity check");
|
kpeter@171
|
415 |
check(g.valid(g.direct(e1, true)), "Wrong validity check");
|
deba@149
|
416 |
|
deba@149
|
417 |
g.erase(n1);
|
deba@149
|
418 |
|
kpeter@171
|
419 |
check(!g.valid(n1), "Wrong validity check");
|
kpeter@171
|
420 |
check(g.valid(n2), "Wrong validity check");
|
kpeter@171
|
421 |
check(g.valid(n3), "Wrong validity check");
|
kpeter@171
|
422 |
check(!g.valid(e1), "Wrong validity check");
|
kpeter@171
|
423 |
check(g.valid(e2), "Wrong validity check");
|
deba@149
|
424 |
|
kpeter@171
|
425 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
|
kpeter@171
|
426 |
check(!g.valid(g.edgeFromId(-1)), "Wrong validity check");
|
kpeter@171
|
427 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
|
deba@149
|
428 |
}
|
deba@149
|
429 |
|
deba@347
|
430 |
void checkGridGraph(int width, int height) {
|
deba@347
|
431 |
typedef GridGraph Graph;
|
deba@347
|
432 |
GRAPH_TYPEDEFS(Graph);
|
deba@347
|
433 |
Graph G(width, height);
|
deba@57
|
434 |
|
kpeter@348
|
435 |
check(G.width() == width, "Wrong column number");
|
kpeter@348
|
436 |
check(G.height() == height, "Wrong row number");
|
alpar@209
|
437 |
|
kpeter@784
|
438 |
G.resize(width, height);
|
kpeter@784
|
439 |
check(G.width() == width, "Wrong column number");
|
kpeter@784
|
440 |
check(G.height() == height, "Wrong row number");
|
kpeter@784
|
441 |
|
deba@347
|
442 |
for (int i = 0; i < width; ++i) {
|
deba@347
|
443 |
for (int j = 0; j < height; ++j) {
|
deba@347
|
444 |
check(G.col(G(i, j)) == i, "Wrong column");
|
deba@347
|
445 |
check(G.row(G(i, j)) == j, "Wrong row");
|
deba@347
|
446 |
check(G.pos(G(i, j)).x == i, "Wrong column");
|
deba@347
|
447 |
check(G.pos(G(i, j)).y == j, "Wrong row");
|
kpeter@346
|
448 |
}
|
kpeter@346
|
449 |
}
|
deba@57
|
450 |
|
deba@347
|
451 |
for (int j = 0; j < height; ++j) {
|
deba@347
|
452 |
for (int i = 0; i < width - 1; ++i) {
|
deba@347
|
453 |
check(G.source(G.right(G(i, j))) == G(i, j), "Wrong right");
|
deba@347
|
454 |
check(G.target(G.right(G(i, j))) == G(i + 1, j), "Wrong right");
|
kpeter@346
|
455 |
}
|
deba@347
|
456 |
check(G.right(G(width - 1, j)) == INVALID, "Wrong right");
|
kpeter@346
|
457 |
}
|
deba@57
|
458 |
|
deba@347
|
459 |
for (int j = 0; j < height; ++j) {
|
deba@347
|
460 |
for (int i = 1; i < width; ++i) {
|
deba@347
|
461 |
check(G.source(G.left(G(i, j))) == G(i, j), "Wrong left");
|
deba@347
|
462 |
check(G.target(G.left(G(i, j))) == G(i - 1, j), "Wrong left");
|
kpeter@346
|
463 |
}
|
deba@347
|
464 |
check(G.left(G(0, j)) == INVALID, "Wrong left");
|
kpeter@346
|
465 |
}
|
deba@57
|
466 |
|
deba@347
|
467 |
for (int i = 0; i < width; ++i) {
|
deba@347
|
468 |
for (int j = 0; j < height - 1; ++j) {
|
deba@347
|
469 |
check(G.source(G.up(G(i, j))) == G(i, j), "Wrong up");
|
deba@347
|
470 |
check(G.target(G.up(G(i, j))) == G(i, j + 1), "Wrong up");
|
kpeter@346
|
471 |
}
|
deba@347
|
472 |
check(G.up(G(i, height - 1)) == INVALID, "Wrong up");
|
kpeter@346
|
473 |
}
|
deba@228
|
474 |
|
deba@347
|
475 |
for (int i = 0; i < width; ++i) {
|
deba@347
|
476 |
for (int j = 1; j < height; ++j) {
|
deba@347
|
477 |
check(G.source(G.down(G(i, j))) == G(i, j), "Wrong down");
|
deba@347
|
478 |
check(G.target(G.down(G(i, j))) == G(i, j - 1), "Wrong down");
|
kpeter@346
|
479 |
}
|
deba@347
|
480 |
check(G.down(G(i, 0)) == INVALID, "Wrong down");
|
kpeter@346
|
481 |
}
|
kpeter@346
|
482 |
|
deba@347
|
483 |
checkGraphNodeList(G, width * height);
|
deba@347
|
484 |
checkGraphEdgeList(G, width * (height - 1) + (width - 1) * height);
|
deba@347
|
485 |
checkGraphArcList(G, 2 * (width * (height - 1) + (width - 1) * height));
|
kpeter@346
|
486 |
|
deba@347
|
487 |
for (NodeIt n(G); n != INVALID; ++n) {
|
deba@347
|
488 |
int nb = 4;
|
deba@347
|
489 |
if (G.col(n) == 0) --nb;
|
deba@347
|
490 |
if (G.col(n) == width - 1) --nb;
|
deba@347
|
491 |
if (G.row(n) == 0) --nb;
|
deba@347
|
492 |
if (G.row(n) == height - 1) --nb;
|
kpeter@346
|
493 |
|
deba@347
|
494 |
checkGraphOutArcList(G, n, nb);
|
deba@347
|
495 |
checkGraphInArcList(G, n, nb);
|
deba@347
|
496 |
checkGraphIncEdgeList(G, n, nb);
|
deba@347
|
497 |
}
|
kpeter@346
|
498 |
|
deba@347
|
499 |
checkArcDirections(G);
|
kpeter@346
|
500 |
|
deba@347
|
501 |
checkGraphConArcList(G, 2 * (width * (height - 1) + (width - 1) * height));
|
deba@347
|
502 |
checkGraphConEdgeList(G, width * (height - 1) + (width - 1) * height);
|
kpeter@346
|
503 |
|
deba@347
|
504 |
checkNodeIds(G);
|
deba@347
|
505 |
checkArcIds(G);
|
deba@347
|
506 |
checkEdgeIds(G);
|
deba@347
|
507 |
checkGraphNodeMap(G);
|
deba@347
|
508 |
checkGraphArcMap(G);
|
deba@347
|
509 |
checkGraphEdgeMap(G);
|
kpeter@346
|
510 |
|
kpeter@346
|
511 |
}
|
deba@228
|
512 |
|
kpeter@377
|
513 |
void checkHypercubeGraph(int dim) {
|
kpeter@377
|
514 |
GRAPH_TYPEDEFS(HypercubeGraph);
|
kpeter@377
|
515 |
|
kpeter@377
|
516 |
HypercubeGraph G(dim);
|
kpeter@784
|
517 |
check(G.dimension() == dim, "Wrong dimension");
|
kpeter@784
|
518 |
|
kpeter@784
|
519 |
G.resize(dim);
|
kpeter@784
|
520 |
check(G.dimension() == dim, "Wrong dimension");
|
alpar@956
|
521 |
|
kpeter@377
|
522 |
checkGraphNodeList(G, 1 << dim);
|
alpar@385
|
523 |
checkGraphEdgeList(G, dim * (1 << (dim-1)));
|
kpeter@377
|
524 |
checkGraphArcList(G, dim * (1 << dim));
|
kpeter@377
|
525 |
|
kpeter@377
|
526 |
Node n = G.nodeFromId(dim);
|
alpar@1257
|
527 |
::lemon::ignore_unused_variable_warning(n);
|
kpeter@377
|
528 |
|
kpeter@377
|
529 |
for (NodeIt n(G); n != INVALID; ++n) {
|
kpeter@377
|
530 |
checkGraphIncEdgeList(G, n, dim);
|
kpeter@377
|
531 |
for (IncEdgeIt e(G, n); e != INVALID; ++e) {
|
kpeter@377
|
532 |
check( (G.u(e) == n &&
|
alpar@385
|
533 |
G.id(G.v(e)) == (G.id(n) ^ (1 << G.dimension(e)))) ||
|
kpeter@377
|
534 |
(G.v(e) == n &&
|
alpar@385
|
535 |
G.id(G.u(e)) == (G.id(n) ^ (1 << G.dimension(e)))),
|
kpeter@377
|
536 |
"Wrong edge or wrong dimension");
|
kpeter@377
|
537 |
}
|
kpeter@377
|
538 |
|
kpeter@377
|
539 |
checkGraphOutArcList(G, n, dim);
|
kpeter@377
|
540 |
for (OutArcIt a(G, n); a != INVALID; ++a) {
|
kpeter@377
|
541 |
check(G.source(a) == n &&
|
alpar@385
|
542 |
G.id(G.target(a)) == (G.id(n) ^ (1 << G.dimension(a))),
|
kpeter@377
|
543 |
"Wrong arc or wrong dimension");
|
kpeter@377
|
544 |
}
|
kpeter@377
|
545 |
|
kpeter@377
|
546 |
checkGraphInArcList(G, n, dim);
|
kpeter@377
|
547 |
for (InArcIt a(G, n); a != INVALID; ++a) {
|
kpeter@377
|
548 |
check(G.target(a) == n &&
|
alpar@385
|
549 |
G.id(G.source(a)) == (G.id(n) ^ (1 << G.dimension(a))),
|
kpeter@377
|
550 |
"Wrong arc or wrong dimension");
|
kpeter@377
|
551 |
}
|
kpeter@377
|
552 |
}
|
kpeter@377
|
553 |
|
kpeter@377
|
554 |
checkGraphConArcList(G, (1 << dim) * dim);
|
alpar@385
|
555 |
checkGraphConEdgeList(G, dim * (1 << (dim-1)));
|
kpeter@377
|
556 |
|
kpeter@377
|
557 |
checkArcDirections(G);
|
kpeter@377
|
558 |
|
kpeter@377
|
559 |
checkNodeIds(G);
|
kpeter@377
|
560 |
checkArcIds(G);
|
kpeter@377
|
561 |
checkEdgeIds(G);
|
kpeter@377
|
562 |
checkGraphNodeMap(G);
|
kpeter@377
|
563 |
checkGraphArcMap(G);
|
kpeter@377
|
564 |
checkGraphEdgeMap(G);
|
kpeter@377
|
565 |
}
|
deba@57
|
566 |
|
deba@228
|
567 |
void checkGraphs() {
|
kpeter@171
|
568 |
{ // Checking ListGraph
|
kpeter@387
|
569 |
checkGraphBuild<ListGraph>();
|
kpeter@387
|
570 |
checkGraphAlter<ListGraph>();
|
kpeter@387
|
571 |
checkGraphErase<ListGraph>();
|
kpeter@387
|
572 |
checkGraphSnapshot<ListGraph>();
|
deba@228
|
573 |
checkGraphValidityErase<ListGraph>();
|
kpeter@171
|
574 |
}
|
kpeter@171
|
575 |
{ // Checking SmartGraph
|
kpeter@387
|
576 |
checkGraphBuild<SmartGraph>();
|
kpeter@387
|
577 |
checkGraphSnapshot<SmartGraph>();
|
deba@228
|
578 |
checkGraphValidity<SmartGraph>();
|
kpeter@171
|
579 |
}
|
kpeter@377
|
580 |
{ // Checking FullGraph
|
deba@365
|
581 |
checkFullGraph(7);
|
deba@365
|
582 |
checkFullGraph(8);
|
deba@365
|
583 |
}
|
kpeter@346
|
584 |
{ // Checking GridGraph
|
deba@347
|
585 |
checkGridGraph(5, 8);
|
deba@347
|
586 |
checkGridGraph(8, 5);
|
deba@347
|
587 |
checkGridGraph(5, 5);
|
deba@347
|
588 |
checkGridGraph(0, 0);
|
deba@347
|
589 |
checkGridGraph(1, 1);
|
kpeter@346
|
590 |
}
|
kpeter@377
|
591 |
{ // Checking HypercubeGraph
|
kpeter@377
|
592 |
checkHypercubeGraph(1);
|
kpeter@377
|
593 |
checkHypercubeGraph(2);
|
kpeter@377
|
594 |
checkHypercubeGraph(3);
|
kpeter@377
|
595 |
checkHypercubeGraph(4);
|
kpeter@377
|
596 |
}
|
kpeter@171
|
597 |
}
|
kpeter@171
|
598 |
|
deba@57
|
599 |
int main() {
|
deba@228
|
600 |
checkConcepts();
|
deba@228
|
601 |
checkGraphs();
|
deba@57
|
602 |
return 0;
|
deba@57
|
603 |
}
|