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