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@440
|
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@774
|
22 |
#include <lemon/static_graph.h>
|
deba@353
|
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@374
|
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@374
|
61 |
Arc a2 = G.addArc(n2, n1),
|
kpeter@374
|
62 |
a3 = G.addArc(n2, n3),
|
kpeter@374
|
63 |
a4 = G.addArc(n2, n3);
|
kpeter@374
|
64 |
|
kpeter@374
|
65 |
checkGraphNodeList(G, 3);
|
kpeter@374
|
66 |
checkGraphArcList(G, 4);
|
kpeter@374
|
67 |
|
kpeter@374
|
68 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@374
|
69 |
checkGraphOutArcList(G, n2, 3);
|
kpeter@374
|
70 |
checkGraphOutArcList(G, n3, 0);
|
kpeter@374
|
71 |
|
kpeter@374
|
72 |
checkGraphInArcList(G, n1, 1);
|
kpeter@374
|
73 |
checkGraphInArcList(G, n2, 1);
|
kpeter@374
|
74 |
checkGraphInArcList(G, n3, 2);
|
kpeter@374
|
75 |
|
kpeter@374
|
76 |
checkGraphConArcList(G, 4);
|
kpeter@374
|
77 |
|
kpeter@374
|
78 |
checkNodeIds(G);
|
kpeter@374
|
79 |
checkArcIds(G);
|
kpeter@374
|
80 |
checkGraphNodeMap(G);
|
kpeter@374
|
81 |
checkGraphArcMap(G);
|
kpeter@374
|
82 |
}
|
kpeter@374
|
83 |
|
kpeter@374
|
84 |
template <class Digraph>
|
kpeter@374
|
85 |
void checkDigraphSplit() {
|
kpeter@374
|
86 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@374
|
87 |
|
kpeter@374
|
88 |
Digraph G;
|
kpeter@374
|
89 |
Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
|
kpeter@374
|
90 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
|
kpeter@374
|
91 |
a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
|
kpeter@374
|
92 |
|
kpeter@374
|
93 |
Node n4 = G.split(n2);
|
kpeter@374
|
94 |
|
kpeter@374
|
95 |
check(G.target(OutArcIt(G, n2)) == n4 &&
|
kpeter@374
|
96 |
G.source(InArcIt(G, n4)) == n2,
|
kpeter@374
|
97 |
"Wrong split.");
|
kpeter@374
|
98 |
|
kpeter@374
|
99 |
checkGraphNodeList(G, 4);
|
kpeter@374
|
100 |
checkGraphArcList(G, 5);
|
kpeter@374
|
101 |
|
kpeter@374
|
102 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@374
|
103 |
checkGraphOutArcList(G, n2, 1);
|
kpeter@374
|
104 |
checkGraphOutArcList(G, n3, 0);
|
kpeter@374
|
105 |
checkGraphOutArcList(G, n4, 3);
|
kpeter@374
|
106 |
|
kpeter@374
|
107 |
checkGraphInArcList(G, n1, 1);
|
kpeter@374
|
108 |
checkGraphInArcList(G, n2, 1);
|
kpeter@374
|
109 |
checkGraphInArcList(G, n3, 2);
|
kpeter@374
|
110 |
checkGraphInArcList(G, n4, 1);
|
kpeter@374
|
111 |
|
kpeter@374
|
112 |
checkGraphConArcList(G, 5);
|
kpeter@374
|
113 |
}
|
kpeter@374
|
114 |
|
kpeter@374
|
115 |
template <class Digraph>
|
kpeter@374
|
116 |
void checkDigraphAlter() {
|
kpeter@374
|
117 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@374
|
118 |
|
kpeter@374
|
119 |
Digraph G;
|
kpeter@374
|
120 |
Node n1 = G.addNode(), n2 = G.addNode(),
|
kpeter@374
|
121 |
n3 = G.addNode(), n4 = G.addNode();
|
kpeter@374
|
122 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
|
kpeter@374
|
123 |
a3 = G.addArc(n4, n3), a4 = G.addArc(n4, n3),
|
kpeter@374
|
124 |
a5 = G.addArc(n2, n4);
|
kpeter@374
|
125 |
|
kpeter@374
|
126 |
checkGraphNodeList(G, 4);
|
kpeter@374
|
127 |
checkGraphArcList(G, 5);
|
kpeter@374
|
128 |
|
kpeter@374
|
129 |
// Check changeSource() and changeTarget()
|
kpeter@374
|
130 |
G.changeTarget(a4, n1);
|
kpeter@374
|
131 |
|
kpeter@374
|
132 |
checkGraphNodeList(G, 4);
|
kpeter@374
|
133 |
checkGraphArcList(G, 5);
|
kpeter@374
|
134 |
|
kpeter@374
|
135 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@374
|
136 |
checkGraphOutArcList(G, n2, 1);
|
kpeter@374
|
137 |
checkGraphOutArcList(G, n3, 0);
|
kpeter@374
|
138 |
checkGraphOutArcList(G, n4, 3);
|
kpeter@374
|
139 |
|
kpeter@374
|
140 |
checkGraphInArcList(G, n1, 2);
|
kpeter@374
|
141 |
checkGraphInArcList(G, n2, 1);
|
kpeter@374
|
142 |
checkGraphInArcList(G, n3, 1);
|
kpeter@374
|
143 |
checkGraphInArcList(G, n4, 1);
|
kpeter@374
|
144 |
|
kpeter@374
|
145 |
checkGraphConArcList(G, 5);
|
kpeter@374
|
146 |
|
kpeter@374
|
147 |
G.changeSource(a4, n3);
|
kpeter@374
|
148 |
|
kpeter@374
|
149 |
checkGraphNodeList(G, 4);
|
kpeter@374
|
150 |
checkGraphArcList(G, 5);
|
kpeter@374
|
151 |
|
kpeter@374
|
152 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@374
|
153 |
checkGraphOutArcList(G, n2, 1);
|
kpeter@374
|
154 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@374
|
155 |
checkGraphOutArcList(G, n4, 2);
|
kpeter@374
|
156 |
|
kpeter@374
|
157 |
checkGraphInArcList(G, n1, 2);
|
kpeter@374
|
158 |
checkGraphInArcList(G, n2, 1);
|
kpeter@374
|
159 |
checkGraphInArcList(G, n3, 1);
|
kpeter@374
|
160 |
checkGraphInArcList(G, n4, 1);
|
kpeter@374
|
161 |
|
kpeter@374
|
162 |
checkGraphConArcList(G, 5);
|
kpeter@374
|
163 |
|
kpeter@374
|
164 |
// Check contract()
|
kpeter@374
|
165 |
G.contract(n2, n4, false);
|
kpeter@374
|
166 |
|
kpeter@374
|
167 |
checkGraphNodeList(G, 3);
|
kpeter@374
|
168 |
checkGraphArcList(G, 5);
|
kpeter@374
|
169 |
|
kpeter@374
|
170 |
checkGraphOutArcList(G, n1, 1);
|
kpeter@374
|
171 |
checkGraphOutArcList(G, n2, 3);
|
kpeter@374
|
172 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@374
|
173 |
|
kpeter@374
|
174 |
checkGraphInArcList(G, n1, 2);
|
kpeter@374
|
175 |
checkGraphInArcList(G, n2, 2);
|
kpeter@374
|
176 |
checkGraphInArcList(G, n3, 1);
|
kpeter@374
|
177 |
|
kpeter@374
|
178 |
checkGraphConArcList(G, 5);
|
kpeter@374
|
179 |
|
kpeter@374
|
180 |
G.contract(n2, n1);
|
kpeter@374
|
181 |
|
kpeter@374
|
182 |
checkGraphNodeList(G, 2);
|
kpeter@374
|
183 |
checkGraphArcList(G, 3);
|
kpeter@374
|
184 |
|
kpeter@374
|
185 |
checkGraphOutArcList(G, n2, 2);
|
kpeter@374
|
186 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@374
|
187 |
|
kpeter@374
|
188 |
checkGraphInArcList(G, n2, 2);
|
kpeter@374
|
189 |
checkGraphInArcList(G, n3, 1);
|
kpeter@374
|
190 |
|
kpeter@374
|
191 |
checkGraphConArcList(G, 3);
|
kpeter@374
|
192 |
}
|
kpeter@374
|
193 |
|
kpeter@374
|
194 |
template <class Digraph>
|
kpeter@374
|
195 |
void checkDigraphErase() {
|
kpeter@374
|
196 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@374
|
197 |
|
kpeter@374
|
198 |
Digraph G;
|
kpeter@374
|
199 |
Node n1 = G.addNode(), n2 = G.addNode(),
|
kpeter@374
|
200 |
n3 = G.addNode(), n4 = G.addNode();
|
kpeter@374
|
201 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
|
kpeter@374
|
202 |
a3 = G.addArc(n4, n3), a4 = G.addArc(n3, n1),
|
kpeter@374
|
203 |
a5 = G.addArc(n2, n4);
|
kpeter@374
|
204 |
|
kpeter@374
|
205 |
// Check arc deletion
|
kpeter@374
|
206 |
G.erase(a1);
|
kpeter@374
|
207 |
|
kpeter@374
|
208 |
checkGraphNodeList(G, 4);
|
kpeter@374
|
209 |
checkGraphArcList(G, 4);
|
kpeter@374
|
210 |
|
kpeter@374
|
211 |
checkGraphOutArcList(G, n1, 0);
|
kpeter@374
|
212 |
checkGraphOutArcList(G, n2, 1);
|
kpeter@374
|
213 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@374
|
214 |
checkGraphOutArcList(G, n4, 2);
|
kpeter@374
|
215 |
|
kpeter@374
|
216 |
checkGraphInArcList(G, n1, 2);
|
kpeter@374
|
217 |
checkGraphInArcList(G, n2, 0);
|
kpeter@374
|
218 |
checkGraphInArcList(G, n3, 1);
|
kpeter@374
|
219 |
checkGraphInArcList(G, n4, 1);
|
kpeter@374
|
220 |
|
kpeter@374
|
221 |
checkGraphConArcList(G, 4);
|
kpeter@374
|
222 |
|
kpeter@374
|
223 |
// Check node deletion
|
kpeter@374
|
224 |
G.erase(n4);
|
kpeter@374
|
225 |
|
kpeter@374
|
226 |
checkGraphNodeList(G, 3);
|
kpeter@374
|
227 |
checkGraphArcList(G, 1);
|
kpeter@374
|
228 |
|
kpeter@374
|
229 |
checkGraphOutArcList(G, n1, 0);
|
kpeter@374
|
230 |
checkGraphOutArcList(G, n2, 0);
|
kpeter@374
|
231 |
checkGraphOutArcList(G, n3, 1);
|
kpeter@374
|
232 |
checkGraphOutArcList(G, n4, 0);
|
kpeter@374
|
233 |
|
kpeter@374
|
234 |
checkGraphInArcList(G, n1, 1);
|
kpeter@374
|
235 |
checkGraphInArcList(G, n2, 0);
|
kpeter@374
|
236 |
checkGraphInArcList(G, n3, 0);
|
kpeter@374
|
237 |
checkGraphInArcList(G, n4, 0);
|
kpeter@374
|
238 |
|
kpeter@374
|
239 |
checkGraphConArcList(G, 1);
|
kpeter@374
|
240 |
}
|
kpeter@374
|
241 |
|
kpeter@374
|
242 |
|
kpeter@374
|
243 |
template <class Digraph>
|
kpeter@374
|
244 |
void checkDigraphSnapshot() {
|
kpeter@374
|
245 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
|
kpeter@374
|
246 |
|
kpeter@374
|
247 |
Digraph G;
|
kpeter@374
|
248 |
Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
|
kpeter@374
|
249 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
|
kpeter@374
|
250 |
a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
|
kpeter@374
|
251 |
|
kpeter@374
|
252 |
typename Digraph::Snapshot snapshot(G);
|
kpeter@374
|
253 |
|
kpeter@374
|
254 |
Node n = G.addNode();
|
kpeter@374
|
255 |
G.addArc(n3, n);
|
kpeter@374
|
256 |
G.addArc(n, n3);
|
kpeter@374
|
257 |
|
kpeter@374
|
258 |
checkGraphNodeList(G, 4);
|
kpeter@374
|
259 |
checkGraphArcList(G, 6);
|
kpeter@374
|
260 |
|
kpeter@374
|
261 |
snapshot.restore();
|
kpeter@374
|
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@374
|
281 |
G.addNode();
|
kpeter@374
|
282 |
snapshot.save(G);
|
kpeter@374
|
283 |
|
kpeter@374
|
284 |
G.addArc(G.addNode(), G.addNode());
|
kpeter@374
|
285 |
|
kpeter@374
|
286 |
snapshot.restore();
|
kpeter@374
|
287 |
|
kpeter@374
|
288 |
checkGraphNodeList(G, 4);
|
kpeter@374
|
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@774
|
321 |
{ // Checking StaticDigraph
|
kpeter@774
|
322 |
checkConcept<Digraph, StaticDigraph>();
|
kpeter@774
|
323 |
checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
|
kpeter@774
|
324 |
}
|
kpeter@354
|
325 |
{ // Checking FullDigraph
|
kpeter@354
|
326 |
checkConcept<Digraph, FullDigraph>();
|
kpeter@354
|
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@774
|
380 |
void checkStaticDigraph() {
|
kpeter@774
|
381 |
SmartDigraph g;
|
kpeter@774
|
382 |
SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
|
kpeter@774
|
383 |
SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
|
kpeter@774
|
384 |
|
kpeter@774
|
385 |
StaticDigraph G;
|
kpeter@774
|
386 |
|
kpeter@774
|
387 |
checkGraphNodeList(G, 0);
|
kpeter@774
|
388 |
checkGraphArcList(G, 0);
|
kpeter@774
|
389 |
|
kpeter@774
|
390 |
G.build(g, nref, aref);
|
kpeter@774
|
391 |
|
kpeter@774
|
392 |
checkGraphNodeList(G, 0);
|
kpeter@774
|
393 |
checkGraphArcList(G, 0);
|
kpeter@774
|
394 |
|
kpeter@774
|
395 |
SmartDigraph::Node
|
kpeter@774
|
396 |
n1 = g.addNode(),
|
kpeter@774
|
397 |
n2 = g.addNode(),
|
kpeter@774
|
398 |
n3 = g.addNode();
|
kpeter@774
|
399 |
|
kpeter@774
|
400 |
G.build(g, nref, aref);
|
kpeter@774
|
401 |
|
kpeter@774
|
402 |
checkGraphNodeList(G, 3);
|
kpeter@774
|
403 |
checkGraphArcList(G, 0);
|
kpeter@774
|
404 |
|
kpeter@774
|
405 |
SmartDigraph::Arc a1 = g.addArc(n1, n2);
|
kpeter@774
|
406 |
|
kpeter@774
|
407 |
G.build(g, nref, aref);
|
kpeter@774
|
408 |
|
kpeter@774
|
409 |
check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
|
kpeter@774
|
410 |
"Wrong arc or wrong references");
|
kpeter@774
|
411 |
checkGraphNodeList(G, 3);
|
kpeter@774
|
412 |
checkGraphArcList(G, 1);
|
kpeter@774
|
413 |
|
kpeter@774
|
414 |
checkGraphOutArcList(G, nref[n1], 1);
|
kpeter@774
|
415 |
checkGraphOutArcList(G, nref[n2], 0);
|
kpeter@774
|
416 |
checkGraphOutArcList(G, nref[n3], 0);
|
kpeter@774
|
417 |
|
kpeter@774
|
418 |
checkGraphInArcList(G, nref[n1], 0);
|
kpeter@774
|
419 |
checkGraphInArcList(G, nref[n2], 1);
|
kpeter@774
|
420 |
checkGraphInArcList(G, nref[n3], 0);
|
kpeter@774
|
421 |
|
kpeter@774
|
422 |
checkGraphConArcList(G, 1);
|
kpeter@774
|
423 |
|
kpeter@774
|
424 |
SmartDigraph::Arc
|
kpeter@774
|
425 |
a2 = g.addArc(n2, n1),
|
kpeter@774
|
426 |
a3 = g.addArc(n2, n3),
|
kpeter@774
|
427 |
a4 = g.addArc(n2, n3);
|
kpeter@774
|
428 |
|
kpeter@774
|
429 |
digraphCopy(g, G).nodeRef(nref).run();
|
kpeter@774
|
430 |
|
kpeter@774
|
431 |
checkGraphNodeList(G, 3);
|
kpeter@774
|
432 |
checkGraphArcList(G, 4);
|
kpeter@774
|
433 |
|
kpeter@774
|
434 |
checkGraphOutArcList(G, nref[n1], 1);
|
kpeter@774
|
435 |
checkGraphOutArcList(G, nref[n2], 3);
|
kpeter@774
|
436 |
checkGraphOutArcList(G, nref[n3], 0);
|
kpeter@774
|
437 |
|
kpeter@774
|
438 |
checkGraphInArcList(G, nref[n1], 1);
|
kpeter@774
|
439 |
checkGraphInArcList(G, nref[n2], 1);
|
kpeter@774
|
440 |
checkGraphInArcList(G, nref[n3], 2);
|
kpeter@774
|
441 |
|
kpeter@774
|
442 |
checkGraphConArcList(G, 4);
|
kpeter@774
|
443 |
|
kpeter@774
|
444 |
checkNodeIds(G);
|
kpeter@774
|
445 |
checkArcIds(G);
|
kpeter@774
|
446 |
checkGraphNodeMap(G);
|
kpeter@774
|
447 |
checkGraphArcMap(G);
|
kpeter@776
|
448 |
|
kpeter@776
|
449 |
int n = G.nodeNum();
|
kpeter@776
|
450 |
int m = G.arcNum();
|
kpeter@776
|
451 |
check(G.index(G.node(n-1)) == n-1, "Wrong index.");
|
kpeter@776
|
452 |
check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
|
kpeter@774
|
453 |
}
|
kpeter@774
|
454 |
|
alpar@375
|
455 |
void checkFullDigraph(int num) {
|
alpar@375
|
456 |
typedef FullDigraph Digraph;
|
alpar@375
|
457 |
DIGRAPH_TYPEDEFS(Digraph);
|
alpar@375
|
458 |
Digraph G(num);
|
alpar@375
|
459 |
|
alpar@375
|
460 |
checkGraphNodeList(G, num);
|
alpar@375
|
461 |
checkGraphArcList(G, num * num);
|
alpar@375
|
462 |
|
alpar@375
|
463 |
for (NodeIt n(G); n != INVALID; ++n) {
|
alpar@375
|
464 |
checkGraphOutArcList(G, n, num);
|
alpar@375
|
465 |
checkGraphInArcList(G, n, num);
|
alpar@375
|
466 |
}
|
alpar@375
|
467 |
|
alpar@375
|
468 |
checkGraphConArcList(G, num * num);
|
alpar@375
|
469 |
|
alpar@375
|
470 |
checkNodeIds(G);
|
alpar@375
|
471 |
checkArcIds(G);
|
alpar@375
|
472 |
checkGraphNodeMap(G);
|
alpar@375
|
473 |
checkGraphArcMap(G);
|
alpar@375
|
474 |
|
alpar@375
|
475 |
for (int i = 0; i < G.nodeNum(); ++i) {
|
alpar@375
|
476 |
check(G.index(G(i)) == i, "Wrong index");
|
alpar@375
|
477 |
}
|
alpar@375
|
478 |
|
alpar@375
|
479 |
for (NodeIt s(G); s != INVALID; ++s) {
|
alpar@375
|
480 |
for (NodeIt t(G); t != INVALID; ++t) {
|
alpar@375
|
481 |
Arc a = G.arc(s, t);
|
alpar@375
|
482 |
check(G.source(a) == s && G.target(a) == t, "Wrong arc lookup");
|
alpar@375
|
483 |
}
|
alpar@375
|
484 |
}
|
alpar@375
|
485 |
}
|
alpar@375
|
486 |
|
deba@228
|
487 |
void checkDigraphs() {
|
kpeter@171
|
488 |
{ // Checking ListDigraph
|
kpeter@374
|
489 |
checkDigraphBuild<ListDigraph>();
|
kpeter@374
|
490 |
checkDigraphSplit<ListDigraph>();
|
kpeter@374
|
491 |
checkDigraphAlter<ListDigraph>();
|
kpeter@374
|
492 |
checkDigraphErase<ListDigraph>();
|
kpeter@374
|
493 |
checkDigraphSnapshot<ListDigraph>();
|
deba@228
|
494 |
checkDigraphValidityErase<ListDigraph>();
|
deba@57
|
495 |
}
|
kpeter@171
|
496 |
{ // Checking SmartDigraph
|
kpeter@374
|
497 |
checkDigraphBuild<SmartDigraph>();
|
kpeter@374
|
498 |
checkDigraphSplit<SmartDigraph>();
|
kpeter@374
|
499 |
checkDigraphSnapshot<SmartDigraph>();
|
deba@228
|
500 |
checkDigraphValidity<SmartDigraph>();
|
kpeter@171
|
501 |
}
|
kpeter@774
|
502 |
{ // Checking StaticDigraph
|
kpeter@774
|
503 |
checkStaticDigraph();
|
kpeter@774
|
504 |
}
|
deba@353
|
505 |
{ // Checking FullDigraph
|
deba@353
|
506 |
checkFullDigraph(8);
|
deba@353
|
507 |
}
|
kpeter@171
|
508 |
}
|
deba@57
|
509 |
|
kpeter@171
|
510 |
int main() {
|
deba@228
|
511 |
checkDigraphs();
|
deba@228
|
512 |
checkConcepts();
|
deba@57
|
513 |
return 0;
|
deba@57
|
514 |
}
|