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/digraph.h>
|
deba@57
|
20 |
#include <lemon/list_graph.h>
|
kpeter@171
|
21 |
#include <lemon/smart_graph.h>
|
kpeter@821
|
22 |
#include <lemon/static_graph.h>
|
deba@365
|
23 |
#include <lemon/full_graph.h>
|
deba@57
|
24 |
|
deba@57
|
25 |
#include "test_tools.h"
|
kpeter@171
|
26 |
#include "graph_test.h"
|
deba@57
|
27 |
|
deba@57
|
28 |
using namespace lemon;
|
deba@57
|
29 |
using namespace lemon::concepts;
|
deba@57
|
30 |
|
deba@228
|
31 |
template <class Digraph>
|
kpeter@387
|
32 |
void checkDigraphBuild() {
|
deba@228
|
33 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
deba@228
|
34 |
Digraph G;
|
deba@228
|
35 |
|
deba@228
|
36 |
checkGraphNodeList(G, 0);
|
deba@228
|
37 |
checkGraphArcList(G, 0);
|
deba@228
|
38 |
|
deba@228
|
39 |
Node
|
deba@228
|
40 |
n1 = G.addNode(),
|
deba@228
|
41 |
n2 = G.addNode(),
|
deba@228
|
42 |
n3 = G.addNode();
|
deba@228
|
43 |
checkGraphNodeList(G, 3);
|
deba@228
|
44 |
checkGraphArcList(G, 0);
|
deba@228
|
45 |
|
deba@228
|
46 |
Arc a1 = G.addArc(n1, n2);
|
deba@228
|
47 |
check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc");
|
deba@228
|
48 |
checkGraphNodeList(G, 3);
|
deba@228
|
49 |
checkGraphArcList(G, 1);
|
deba@228
|
50 |
|
deba@228
|
51 |
checkGraphOutArcList(G, n1, 1);
|
deba@228
|
52 |
checkGraphOutArcList(G, n2, 0);
|
deba@228
|
53 |
checkGraphOutArcList(G, n3, 0);
|
deba@228
|
54 |
|
deba@228
|
55 |
checkGraphInArcList(G, n1, 0);
|
deba@228
|
56 |
checkGraphInArcList(G, n2, 1);
|
deba@228
|
57 |
checkGraphInArcList(G, n3, 0);
|
deba@228
|
58 |
|
deba@228
|
59 |
checkGraphConArcList(G, 1);
|
deba@228
|
60 |
|
kpeter@387
|
61 |
Arc a2 = G.addArc(n2, n1),
|
kpeter@387
|
62 |
a3 = G.addArc(n2, n3),
|
kpeter@387
|
63 |
a4 = G.addArc(n2, n3);
|
kpeter@387
|
64 |
|
kpeter@387
|
65 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
66 |
checkGraphArcList(G, 4);
|
kpeter@387
|
67 |
|
kpeter@387
|
68 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@387
|
69 |
checkGraphOutArcList(G, n2, 3);
|
kpeter@387
|
70 |
checkGraphOutArcList(G, n3, 0);
|
kpeter@387
|
71 |
|
kpeter@387
|
72 |
checkGraphInArcList(G, n1, 1);
|
kpeter@387
|
73 |
checkGraphInArcList(G, n2, 1);
|
kpeter@387
|
74 |
checkGraphInArcList(G, n3, 2);
|
kpeter@387
|
75 |
|
kpeter@387
|
76 |
checkGraphConArcList(G, 4);
|
kpeter@387
|
77 |
|
kpeter@387
|
78 |
checkNodeIds(G);
|
kpeter@387
|
79 |
checkArcIds(G);
|
kpeter@387
|
80 |
checkGraphNodeMap(G);
|
kpeter@387
|
81 |
checkGraphArcMap(G);
|
kpeter@387
|
82 |
}
|
kpeter@387
|
83 |
|
kpeter@387
|
84 |
template <class Digraph>
|
kpeter@387
|
85 |
void checkDigraphSplit() {
|
kpeter@387
|
86 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@387
|
87 |
|
kpeter@387
|
88 |
Digraph G;
|
kpeter@387
|
89 |
Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
|
kpeter@387
|
90 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
|
kpeter@387
|
91 |
a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
|
kpeter@387
|
92 |
|
kpeter@387
|
93 |
Node n4 = G.split(n2);
|
kpeter@387
|
94 |
|
kpeter@387
|
95 |
check(G.target(OutArcIt(G, n2)) == n4 &&
|
kpeter@387
|
96 |
G.source(InArcIt(G, n4)) == n2,
|
kpeter@387
|
97 |
"Wrong split.");
|
kpeter@387
|
98 |
|
kpeter@387
|
99 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
100 |
checkGraphArcList(G, 5);
|
kpeter@387
|
101 |
|
kpeter@387
|
102 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@387
|
103 |
checkGraphOutArcList(G, n2, 1);
|
kpeter@387
|
104 |
checkGraphOutArcList(G, n3, 0);
|
kpeter@387
|
105 |
checkGraphOutArcList(G, n4, 3);
|
kpeter@387
|
106 |
|
kpeter@387
|
107 |
checkGraphInArcList(G, n1, 1);
|
kpeter@387
|
108 |
checkGraphInArcList(G, n2, 1);
|
kpeter@387
|
109 |
checkGraphInArcList(G, n3, 2);
|
kpeter@387
|
110 |
checkGraphInArcList(G, n4, 1);
|
kpeter@387
|
111 |
|
kpeter@387
|
112 |
checkGraphConArcList(G, 5);
|
kpeter@387
|
113 |
}
|
kpeter@387
|
114 |
|
kpeter@387
|
115 |
template <class Digraph>
|
kpeter@387
|
116 |
void checkDigraphAlter() {
|
kpeter@387
|
117 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@387
|
118 |
|
kpeter@387
|
119 |
Digraph G;
|
kpeter@387
|
120 |
Node n1 = G.addNode(), n2 = G.addNode(),
|
kpeter@387
|
121 |
n3 = G.addNode(), n4 = G.addNode();
|
kpeter@387
|
122 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
|
kpeter@387
|
123 |
a3 = G.addArc(n4, n3), a4 = G.addArc(n4, n3),
|
kpeter@387
|
124 |
a5 = G.addArc(n2, n4);
|
kpeter@387
|
125 |
|
kpeter@387
|
126 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
127 |
checkGraphArcList(G, 5);
|
kpeter@387
|
128 |
|
kpeter@387
|
129 |
// Check changeSource() and changeTarget()
|
kpeter@387
|
130 |
G.changeTarget(a4, n1);
|
kpeter@387
|
131 |
|
kpeter@387
|
132 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
133 |
checkGraphArcList(G, 5);
|
kpeter@387
|
134 |
|
kpeter@387
|
135 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@387
|
136 |
checkGraphOutArcList(G, n2, 1);
|
kpeter@387
|
137 |
checkGraphOutArcList(G, n3, 0);
|
kpeter@387
|
138 |
checkGraphOutArcList(G, n4, 3);
|
kpeter@387
|
139 |
|
kpeter@387
|
140 |
checkGraphInArcList(G, n1, 2);
|
kpeter@387
|
141 |
checkGraphInArcList(G, n2, 1);
|
kpeter@387
|
142 |
checkGraphInArcList(G, n3, 1);
|
kpeter@387
|
143 |
checkGraphInArcList(G, n4, 1);
|
kpeter@387
|
144 |
|
kpeter@387
|
145 |
checkGraphConArcList(G, 5);
|
kpeter@387
|
146 |
|
kpeter@387
|
147 |
G.changeSource(a4, n3);
|
kpeter@387
|
148 |
|
kpeter@387
|
149 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
150 |
checkGraphArcList(G, 5);
|
kpeter@387
|
151 |
|
kpeter@387
|
152 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@387
|
153 |
checkGraphOutArcList(G, n2, 1);
|
kpeter@387
|
154 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@387
|
155 |
checkGraphOutArcList(G, n4, 2);
|
kpeter@387
|
156 |
|
kpeter@387
|
157 |
checkGraphInArcList(G, n1, 2);
|
kpeter@387
|
158 |
checkGraphInArcList(G, n2, 1);
|
kpeter@387
|
159 |
checkGraphInArcList(G, n3, 1);
|
kpeter@387
|
160 |
checkGraphInArcList(G, n4, 1);
|
kpeter@387
|
161 |
|
kpeter@387
|
162 |
checkGraphConArcList(G, 5);
|
kpeter@387
|
163 |
|
kpeter@387
|
164 |
// Check contract()
|
kpeter@387
|
165 |
G.contract(n2, n4, false);
|
kpeter@387
|
166 |
|
kpeter@387
|
167 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
168 |
checkGraphArcList(G, 5);
|
kpeter@387
|
169 |
|
kpeter@387
|
170 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@387
|
171 |
checkGraphOutArcList(G, n2, 3);
|
kpeter@387
|
172 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@387
|
173 |
|
kpeter@387
|
174 |
checkGraphInArcList(G, n1, 2);
|
kpeter@387
|
175 |
checkGraphInArcList(G, n2, 2);
|
kpeter@387
|
176 |
checkGraphInArcList(G, n3, 1);
|
kpeter@387
|
177 |
|
kpeter@387
|
178 |
checkGraphConArcList(G, 5);
|
kpeter@387
|
179 |
|
kpeter@387
|
180 |
G.contract(n2, n1);
|
kpeter@387
|
181 |
|
kpeter@387
|
182 |
checkGraphNodeList(G, 2);
|
kpeter@387
|
183 |
checkGraphArcList(G, 3);
|
kpeter@387
|
184 |
|
kpeter@387
|
185 |
checkGraphOutArcList(G, n2, 2);
|
kpeter@387
|
186 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@387
|
187 |
|
kpeter@387
|
188 |
checkGraphInArcList(G, n2, 2);
|
kpeter@387
|
189 |
checkGraphInArcList(G, n3, 1);
|
kpeter@387
|
190 |
|
kpeter@387
|
191 |
checkGraphConArcList(G, 3);
|
kpeter@387
|
192 |
}
|
kpeter@387
|
193 |
|
kpeter@387
|
194 |
template <class Digraph>
|
kpeter@387
|
195 |
void checkDigraphErase() {
|
kpeter@387
|
196 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@387
|
197 |
|
kpeter@387
|
198 |
Digraph G;
|
kpeter@387
|
199 |
Node n1 = G.addNode(), n2 = G.addNode(),
|
kpeter@387
|
200 |
n3 = G.addNode(), n4 = G.addNode();
|
kpeter@387
|
201 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
|
kpeter@387
|
202 |
a3 = G.addArc(n4, n3), a4 = G.addArc(n3, n1),
|
kpeter@387
|
203 |
a5 = G.addArc(n2, n4);
|
kpeter@387
|
204 |
|
kpeter@387
|
205 |
// Check arc deletion
|
kpeter@387
|
206 |
G.erase(a1);
|
kpeter@387
|
207 |
|
kpeter@387
|
208 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
209 |
checkGraphArcList(G, 4);
|
kpeter@387
|
210 |
|
kpeter@387
|
211 |
checkGraphOutArcList(G, n1, 0);
|
kpeter@387
|
212 |
checkGraphOutArcList(G, n2, 1);
|
kpeter@387
|
213 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@387
|
214 |
checkGraphOutArcList(G, n4, 2);
|
kpeter@387
|
215 |
|
kpeter@387
|
216 |
checkGraphInArcList(G, n1, 2);
|
kpeter@387
|
217 |
checkGraphInArcList(G, n2, 0);
|
kpeter@387
|
218 |
checkGraphInArcList(G, n3, 1);
|
kpeter@387
|
219 |
checkGraphInArcList(G, n4, 1);
|
kpeter@387
|
220 |
|
kpeter@387
|
221 |
checkGraphConArcList(G, 4);
|
kpeter@387
|
222 |
|
kpeter@387
|
223 |
// Check node deletion
|
kpeter@387
|
224 |
G.erase(n4);
|
kpeter@387
|
225 |
|
kpeter@387
|
226 |
checkGraphNodeList(G, 3);
|
kpeter@387
|
227 |
checkGraphArcList(G, 1);
|
kpeter@387
|
228 |
|
kpeter@387
|
229 |
checkGraphOutArcList(G, n1, 0);
|
kpeter@387
|
230 |
checkGraphOutArcList(G, n2, 0);
|
kpeter@387
|
231 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@387
|
232 |
checkGraphOutArcList(G, n4, 0);
|
kpeter@387
|
233 |
|
kpeter@387
|
234 |
checkGraphInArcList(G, n1, 1);
|
kpeter@387
|
235 |
checkGraphInArcList(G, n2, 0);
|
kpeter@387
|
236 |
checkGraphInArcList(G, n3, 0);
|
kpeter@387
|
237 |
checkGraphInArcList(G, n4, 0);
|
kpeter@387
|
238 |
|
kpeter@387
|
239 |
checkGraphConArcList(G, 1);
|
kpeter@387
|
240 |
}
|
kpeter@387
|
241 |
|
kpeter@387
|
242 |
|
kpeter@387
|
243 |
template <class Digraph>
|
kpeter@387
|
244 |
void checkDigraphSnapshot() {
|
kpeter@387
|
245 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@387
|
246 |
|
kpeter@387
|
247 |
Digraph G;
|
kpeter@387
|
248 |
Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
|
kpeter@387
|
249 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
|
kpeter@387
|
250 |
a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
|
kpeter@387
|
251 |
|
kpeter@387
|
252 |
typename Digraph::Snapshot snapshot(G);
|
kpeter@387
|
253 |
|
kpeter@387
|
254 |
Node n = G.addNode();
|
kpeter@387
|
255 |
G.addArc(n3, n);
|
kpeter@387
|
256 |
G.addArc(n, n3);
|
kpeter@387
|
257 |
|
kpeter@387
|
258 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
259 |
checkGraphArcList(G, 6);
|
kpeter@387
|
260 |
|
kpeter@387
|
261 |
snapshot.restore();
|
kpeter@387
|
262 |
|
deba@228
|
263 |
checkGraphNodeList(G, 3);
|
deba@228
|
264 |
checkGraphArcList(G, 4);
|
deba@228
|
265 |
|
deba@228
|
266 |
checkGraphOutArcList(G, n1, 1);
|
deba@228
|
267 |
checkGraphOutArcList(G, n2, 3);
|
deba@228
|
268 |
checkGraphOutArcList(G, n3, 0);
|
deba@228
|
269 |
|
deba@228
|
270 |
checkGraphInArcList(G, n1, 1);
|
deba@228
|
271 |
checkGraphInArcList(G, n2, 1);
|
deba@228
|
272 |
checkGraphInArcList(G, n3, 2);
|
deba@228
|
273 |
|
deba@228
|
274 |
checkGraphConArcList(G, 4);
|
deba@228
|
275 |
|
deba@228
|
276 |
checkNodeIds(G);
|
deba@228
|
277 |
checkArcIds(G);
|
deba@228
|
278 |
checkGraphNodeMap(G);
|
deba@228
|
279 |
checkGraphArcMap(G);
|
deba@228
|
280 |
|
kpeter@387
|
281 |
G.addNode();
|
kpeter@387
|
282 |
snapshot.save(G);
|
kpeter@387
|
283 |
|
kpeter@387
|
284 |
G.addArc(G.addNode(), G.addNode());
|
kpeter@387
|
285 |
|
kpeter@387
|
286 |
snapshot.restore();
|
kpeter@387
|
287 |
|
kpeter@387
|
288 |
checkGraphNodeList(G, 4);
|
kpeter@387
|
289 |
checkGraphArcList(G, 4);
|
deba@228
|
290 |
}
|
deba@228
|
291 |
|
deba@228
|
292 |
void checkConcepts() {
|
kpeter@171
|
293 |
{ // Checking digraph components
|
deba@57
|
294 |
checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
|
deba@57
|
295 |
|
alpar@209
|
296 |
checkConcept<IDableDigraphComponent<>,
|
deba@57
|
297 |
IDableDigraphComponent<> >();
|
deba@57
|
298 |
|
alpar@209
|
299 |
checkConcept<IterableDigraphComponent<>,
|
deba@57
|
300 |
IterableDigraphComponent<> >();
|
deba@57
|
301 |
|
alpar@209
|
302 |
checkConcept<MappableDigraphComponent<>,
|
deba@57
|
303 |
MappableDigraphComponent<> >();
|
deba@57
|
304 |
}
|
kpeter@171
|
305 |
{ // Checking skeleton digraph
|
deba@57
|
306 |
checkConcept<Digraph, Digraph>();
|
deba@57
|
307 |
}
|
kpeter@171
|
308 |
{ // Checking ListDigraph
|
kpeter@171
|
309 |
checkConcept<Digraph, ListDigraph>();
|
deba@57
|
310 |
checkConcept<AlterableDigraphComponent<>, ListDigraph>();
|
deba@57
|
311 |
checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
|
deba@57
|
312 |
checkConcept<ClearableDigraphComponent<>, ListDigraph>();
|
deba@57
|
313 |
checkConcept<ErasableDigraphComponent<>, ListDigraph>();
|
kpeter@171
|
314 |
}
|
kpeter@171
|
315 |
{ // Checking SmartDigraph
|
kpeter@171
|
316 |
checkConcept<Digraph, SmartDigraph>();
|
kpeter@171
|
317 |
checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
|
kpeter@171
|
318 |
checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
|
kpeter@171
|
319 |
checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
|
kpeter@171
|
320 |
}
|
kpeter@821
|
321 |
{ // Checking StaticDigraph
|
kpeter@821
|
322 |
checkConcept<Digraph, StaticDigraph>();
|
kpeter@821
|
323 |
checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
|
kpeter@821
|
324 |
}
|
kpeter@366
|
325 |
{ // Checking FullDigraph
|
kpeter@366
|
326 |
checkConcept<Digraph, FullDigraph>();
|
kpeter@366
|
327 |
}
|
kpeter@171
|
328 |
}
|
deba@57
|
329 |
|
kpeter@171
|
330 |
template <typename Digraph>
|
deba@228
|
331 |
void checkDigraphValidity() {
|
kpeter@171
|
332 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@171
|
333 |
Digraph g;
|
kpeter@171
|
334 |
|
kpeter@171
|
335 |
Node
|
kpeter@171
|
336 |
n1 = g.addNode(),
|
kpeter@171
|
337 |
n2 = g.addNode(),
|
kpeter@171
|
338 |
n3 = g.addNode();
|
kpeter@171
|
339 |
|
kpeter@171
|
340 |
Arc
|
kpeter@171
|
341 |
e1 = g.addArc(n1, n2),
|
kpeter@171
|
342 |
e2 = g.addArc(n2, n3);
|
kpeter@171
|
343 |
|
kpeter@171
|
344 |
check(g.valid(n1), "Wrong validity check");
|
kpeter@171
|
345 |
check(g.valid(e1), "Wrong validity check");
|
kpeter@171
|
346 |
|
kpeter@171
|
347 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
|
kpeter@171
|
348 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
|
kpeter@171
|
349 |
}
|
kpeter@171
|
350 |
|
kpeter@171
|
351 |
template <typename Digraph>
|
deba@228
|
352 |
void checkDigraphValidityErase() {
|
kpeter@171
|
353 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@171
|
354 |
Digraph g;
|
kpeter@171
|
355 |
|
kpeter@171
|
356 |
Node
|
kpeter@171
|
357 |
n1 = g.addNode(),
|
kpeter@171
|
358 |
n2 = g.addNode(),
|
kpeter@171
|
359 |
n3 = g.addNode();
|
kpeter@171
|
360 |
|
kpeter@171
|
361 |
Arc
|
kpeter@171
|
362 |
e1 = g.addArc(n1, n2),
|
kpeter@171
|
363 |
e2 = g.addArc(n2, n3);
|
kpeter@171
|
364 |
|
kpeter@171
|
365 |
check(g.valid(n1), "Wrong validity check");
|
kpeter@171
|
366 |
check(g.valid(e1), "Wrong validity check");
|
kpeter@171
|
367 |
|
kpeter@171
|
368 |
g.erase(n1);
|
kpeter@171
|
369 |
|
kpeter@171
|
370 |
check(!g.valid(n1), "Wrong validity check");
|
kpeter@171
|
371 |
check(g.valid(n2), "Wrong validity check");
|
kpeter@171
|
372 |
check(g.valid(n3), "Wrong validity check");
|
kpeter@171
|
373 |
check(!g.valid(e1), "Wrong validity check");
|
kpeter@171
|
374 |
check(g.valid(e2), "Wrong validity check");
|
kpeter@171
|
375 |
|
kpeter@171
|
376 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
|
kpeter@171
|
377 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
|
kpeter@171
|
378 |
}
|
kpeter@171
|
379 |
|
kpeter@821
|
380 |
void checkStaticDigraph() {
|
kpeter@821
|
381 |
SmartDigraph g;
|
kpeter@821
|
382 |
SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
|
kpeter@821
|
383 |
SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
|
kpeter@821
|
384 |
|
kpeter@821
|
385 |
StaticDigraph G;
|
kpeter@821
|
386 |
|
kpeter@821
|
387 |
checkGraphNodeList(G, 0);
|
kpeter@821
|
388 |
checkGraphArcList(G, 0);
|
kpeter@821
|
389 |
|
kpeter@821
|
390 |
G.build(g, nref, aref);
|
kpeter@821
|
391 |
|
kpeter@821
|
392 |
checkGraphNodeList(G, 0);
|
kpeter@821
|
393 |
checkGraphArcList(G, 0);
|
kpeter@821
|
394 |
|
kpeter@821
|
395 |
SmartDigraph::Node
|
kpeter@821
|
396 |
n1 = g.addNode(),
|
kpeter@821
|
397 |
n2 = g.addNode(),
|
kpeter@821
|
398 |
n3 = g.addNode();
|
kpeter@821
|
399 |
|
kpeter@821
|
400 |
G.build(g, nref, aref);
|
kpeter@821
|
401 |
|
kpeter@821
|
402 |
checkGraphNodeList(G, 3);
|
kpeter@821
|
403 |
checkGraphArcList(G, 0);
|
kpeter@821
|
404 |
|
kpeter@821
|
405 |
SmartDigraph::Arc a1 = g.addArc(n1, n2);
|
kpeter@821
|
406 |
|
kpeter@821
|
407 |
G.build(g, nref, aref);
|
kpeter@821
|
408 |
|
kpeter@821
|
409 |
check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
|
kpeter@821
|
410 |
"Wrong arc or wrong references");
|
kpeter@821
|
411 |
checkGraphNodeList(G, 3);
|
kpeter@821
|
412 |
checkGraphArcList(G, 1);
|
kpeter@821
|
413 |
|
kpeter@821
|
414 |
checkGraphOutArcList(G, nref[n1], 1);
|
kpeter@821
|
415 |
checkGraphOutArcList(G, nref[n2], 0);
|
kpeter@821
|
416 |
checkGraphOutArcList(G, nref[n3], 0);
|
kpeter@821
|
417 |
|
kpeter@821
|
418 |
checkGraphInArcList(G, nref[n1], 0);
|
kpeter@821
|
419 |
checkGraphInArcList(G, nref[n2], 1);
|
kpeter@821
|
420 |
checkGraphInArcList(G, nref[n3], 0);
|
kpeter@821
|
421 |
|
kpeter@821
|
422 |
checkGraphConArcList(G, 1);
|
kpeter@821
|
423 |
|
kpeter@821
|
424 |
SmartDigraph::Arc
|
kpeter@821
|
425 |
a2 = g.addArc(n2, n1),
|
kpeter@821
|
426 |
a3 = g.addArc(n2, n3),
|
kpeter@821
|
427 |
a4 = g.addArc(n2, n3);
|
kpeter@821
|
428 |
|
kpeter@821
|
429 |
digraphCopy(g, G).nodeRef(nref).run();
|
kpeter@821
|
430 |
|
kpeter@821
|
431 |
checkGraphNodeList(G, 3);
|
kpeter@821
|
432 |
checkGraphArcList(G, 4);
|
kpeter@821
|
433 |
|
kpeter@821
|
434 |
checkGraphOutArcList(G, nref[n1], 1);
|
kpeter@821
|
435 |
checkGraphOutArcList(G, nref[n2], 3);
|
kpeter@821
|
436 |
checkGraphOutArcList(G, nref[n3], 0);
|
kpeter@821
|
437 |
|
kpeter@821
|
438 |
checkGraphInArcList(G, nref[n1], 1);
|
kpeter@821
|
439 |
checkGraphInArcList(G, nref[n2], 1);
|
kpeter@821
|
440 |
checkGraphInArcList(G, nref[n3], 2);
|
kpeter@821
|
441 |
|
kpeter@821
|
442 |
checkGraphConArcList(G, 4);
|
kpeter@821
|
443 |
|
kpeter@821
|
444 |
checkNodeIds(G);
|
kpeter@821
|
445 |
checkArcIds(G);
|
kpeter@821
|
446 |
checkGraphNodeMap(G);
|
kpeter@821
|
447 |
checkGraphArcMap(G);
|
kpeter@821
|
448 |
}
|
kpeter@821
|
449 |
|
alpar@388
|
450 |
void checkFullDigraph(int num) {
|
alpar@388
|
451 |
typedef FullDigraph Digraph;
|
alpar@388
|
452 |
DIGRAPH_TYPEDEFS(Digraph);
|
alpar@388
|
453 |
Digraph G(num);
|
alpar@388
|
454 |
|
alpar@388
|
455 |
checkGraphNodeList(G, num);
|
alpar@388
|
456 |
checkGraphArcList(G, num * num);
|
alpar@388
|
457 |
|
alpar@388
|
458 |
for (NodeIt n(G); n != INVALID; ++n) {
|
alpar@388
|
459 |
checkGraphOutArcList(G, n, num);
|
alpar@388
|
460 |
checkGraphInArcList(G, n, num);
|
alpar@388
|
461 |
}
|
alpar@388
|
462 |
|
alpar@388
|
463 |
checkGraphConArcList(G, num * num);
|
alpar@388
|
464 |
|
alpar@388
|
465 |
checkNodeIds(G);
|
alpar@388
|
466 |
checkArcIds(G);
|
alpar@388
|
467 |
checkGraphNodeMap(G);
|
alpar@388
|
468 |
checkGraphArcMap(G);
|
alpar@388
|
469 |
|
alpar@388
|
470 |
for (int i = 0; i < G.nodeNum(); ++i) {
|
alpar@388
|
471 |
check(G.index(G(i)) == i, "Wrong index");
|
alpar@388
|
472 |
}
|
alpar@388
|
473 |
|
alpar@388
|
474 |
for (NodeIt s(G); s != INVALID; ++s) {
|
alpar@388
|
475 |
for (NodeIt t(G); t != INVALID; ++t) {
|
alpar@388
|
476 |
Arc a = G.arc(s, t);
|
alpar@388
|
477 |
check(G.source(a) == s && G.target(a) == t, "Wrong arc lookup");
|
alpar@388
|
478 |
}
|
alpar@388
|
479 |
}
|
alpar@388
|
480 |
}
|
alpar@388
|
481 |
|
deba@228
|
482 |
void checkDigraphs() {
|
kpeter@171
|
483 |
{ // Checking ListDigraph
|
kpeter@387
|
484 |
checkDigraphBuild<ListDigraph>();
|
kpeter@387
|
485 |
checkDigraphSplit<ListDigraph>();
|
kpeter@387
|
486 |
checkDigraphAlter<ListDigraph>();
|
kpeter@387
|
487 |
checkDigraphErase<ListDigraph>();
|
kpeter@387
|
488 |
checkDigraphSnapshot<ListDigraph>();
|
deba@228
|
489 |
checkDigraphValidityErase<ListDigraph>();
|
deba@57
|
490 |
}
|
kpeter@171
|
491 |
{ // Checking SmartDigraph
|
kpeter@387
|
492 |
checkDigraphBuild<SmartDigraph>();
|
kpeter@387
|
493 |
checkDigraphSplit<SmartDigraph>();
|
kpeter@387
|
494 |
checkDigraphSnapshot<SmartDigraph>();
|
deba@228
|
495 |
checkDigraphValidity<SmartDigraph>();
|
kpeter@171
|
496 |
}
|
kpeter@821
|
497 |
{ // Checking StaticDigraph
|
kpeter@821
|
498 |
checkStaticDigraph();
|
kpeter@821
|
499 |
}
|
deba@365
|
500 |
{ // Checking FullDigraph
|
deba@365
|
501 |
checkFullDigraph(8);
|
deba@365
|
502 |
}
|
kpeter@171
|
503 |
}
|
deba@57
|
504 |
|
kpeter@171
|
505 |
int main() {
|
deba@228
|
506 |
checkDigraphs();
|
deba@228
|
507 |
checkConcepts();
|
deba@57
|
508 |
return 0;
|
deba@57
|
509 |
}
|