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