deba@432
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
deba@430
|
2 |
*
|
deba@432
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
deba@430
|
4 |
*
|
alpar@463
|
5 |
* Copyright (C) 2003-2009
|
deba@430
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@430
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@430
|
8 |
*
|
deba@430
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@430
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@430
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@430
|
12 |
*
|
deba@430
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@430
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@430
|
15 |
* purpose.
|
deba@430
|
16 |
*
|
deba@430
|
17 |
*/
|
deba@430
|
18 |
|
deba@430
|
19 |
#include<iostream>
|
deba@430
|
20 |
#include<lemon/concept_check.h>
|
deba@430
|
21 |
|
deba@430
|
22 |
#include<lemon/list_graph.h>
|
deba@430
|
23 |
#include<lemon/smart_graph.h>
|
deba@430
|
24 |
|
deba@430
|
25 |
#include<lemon/concepts/digraph.h>
|
deba@430
|
26 |
#include<lemon/concepts/graph.h>
|
deba@430
|
27 |
|
deba@432
|
28 |
#include<lemon/adaptors.h>
|
deba@430
|
29 |
|
deba@430
|
30 |
#include <limits>
|
deba@430
|
31 |
#include <lemon/bfs.h>
|
deba@430
|
32 |
#include <lemon/path.h>
|
deba@430
|
33 |
|
deba@430
|
34 |
#include"test/test_tools.h"
|
deba@430
|
35 |
#include"test/graph_test.h"
|
deba@430
|
36 |
|
deba@430
|
37 |
using namespace lemon;
|
deba@430
|
38 |
|
deba@432
|
39 |
void checkReverseDigraph() {
|
deba@432
|
40 |
checkConcept<concepts::Digraph, ReverseDigraph<concepts::Digraph> >();
|
deba@430
|
41 |
|
deba@430
|
42 |
typedef ListDigraph Digraph;
|
deba@432
|
43 |
typedef ReverseDigraph<Digraph> Adaptor;
|
deba@430
|
44 |
|
deba@430
|
45 |
Digraph digraph;
|
deba@430
|
46 |
Adaptor adaptor(digraph);
|
deba@430
|
47 |
|
deba@430
|
48 |
Digraph::Node n1 = digraph.addNode();
|
deba@430
|
49 |
Digraph::Node n2 = digraph.addNode();
|
deba@430
|
50 |
Digraph::Node n3 = digraph.addNode();
|
deba@430
|
51 |
|
deba@430
|
52 |
Digraph::Arc a1 = digraph.addArc(n1, n2);
|
deba@430
|
53 |
Digraph::Arc a2 = digraph.addArc(n1, n3);
|
deba@430
|
54 |
Digraph::Arc a3 = digraph.addArc(n2, n3);
|
deba@432
|
55 |
|
deba@430
|
56 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
57 |
checkGraphArcList(adaptor, 3);
|
deba@430
|
58 |
checkGraphConArcList(adaptor, 3);
|
deba@430
|
59 |
|
deba@430
|
60 |
checkGraphOutArcList(adaptor, n1, 0);
|
deba@430
|
61 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
62 |
checkGraphOutArcList(adaptor, n3, 2);
|
deba@430
|
63 |
|
deba@430
|
64 |
checkGraphInArcList(adaptor, n1, 2);
|
deba@430
|
65 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
66 |
checkGraphInArcList(adaptor, n3, 0);
|
deba@430
|
67 |
|
deba@430
|
68 |
checkNodeIds(adaptor);
|
deba@430
|
69 |
checkArcIds(adaptor);
|
deba@430
|
70 |
|
deba@430
|
71 |
checkGraphNodeMap(adaptor);
|
deba@430
|
72 |
checkGraphArcMap(adaptor);
|
deba@430
|
73 |
|
deba@430
|
74 |
for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
|
deba@430
|
75 |
check(adaptor.source(a) == digraph.target(a), "Wrong reverse");
|
deba@430
|
76 |
check(adaptor.target(a) == digraph.source(a), "Wrong reverse");
|
deba@430
|
77 |
}
|
deba@430
|
78 |
}
|
deba@430
|
79 |
|
deba@432
|
80 |
void checkSubDigraph() {
|
deba@432
|
81 |
checkConcept<concepts::Digraph,
|
deba@432
|
82 |
SubDigraph<concepts::Digraph,
|
deba@430
|
83 |
concepts::Digraph::NodeMap<bool>,
|
deba@430
|
84 |
concepts::Digraph::ArcMap<bool> > >();
|
deba@430
|
85 |
|
deba@430
|
86 |
typedef ListDigraph Digraph;
|
deba@430
|
87 |
typedef Digraph::NodeMap<bool> NodeFilter;
|
deba@430
|
88 |
typedef Digraph::ArcMap<bool> ArcFilter;
|
deba@432
|
89 |
typedef SubDigraph<Digraph, NodeFilter, ArcFilter> Adaptor;
|
deba@430
|
90 |
|
deba@430
|
91 |
Digraph digraph;
|
deba@430
|
92 |
NodeFilter node_filter(digraph);
|
deba@430
|
93 |
ArcFilter arc_filter(digraph);
|
deba@430
|
94 |
Adaptor adaptor(digraph, node_filter, arc_filter);
|
deba@430
|
95 |
|
deba@430
|
96 |
Digraph::Node n1 = digraph.addNode();
|
deba@430
|
97 |
Digraph::Node n2 = digraph.addNode();
|
deba@430
|
98 |
Digraph::Node n3 = digraph.addNode();
|
deba@430
|
99 |
|
deba@430
|
100 |
Digraph::Arc a1 = digraph.addArc(n1, n2);
|
deba@430
|
101 |
Digraph::Arc a2 = digraph.addArc(n1, n3);
|
deba@430
|
102 |
Digraph::Arc a3 = digraph.addArc(n2, n3);
|
deba@430
|
103 |
|
deba@430
|
104 |
node_filter[n1] = node_filter[n2] = node_filter[n3] = true;
|
deba@430
|
105 |
arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true;
|
alpar@463
|
106 |
|
deba@430
|
107 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
108 |
checkGraphArcList(adaptor, 3);
|
deba@430
|
109 |
checkGraphConArcList(adaptor, 3);
|
deba@430
|
110 |
|
deba@430
|
111 |
checkGraphOutArcList(adaptor, n1, 2);
|
deba@430
|
112 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
113 |
checkGraphOutArcList(adaptor, n3, 0);
|
deba@430
|
114 |
|
deba@430
|
115 |
checkGraphInArcList(adaptor, n1, 0);
|
deba@430
|
116 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
117 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
118 |
|
deba@430
|
119 |
checkNodeIds(adaptor);
|
deba@430
|
120 |
checkArcIds(adaptor);
|
deba@430
|
121 |
|
deba@430
|
122 |
checkGraphNodeMap(adaptor);
|
deba@430
|
123 |
checkGraphArcMap(adaptor);
|
deba@430
|
124 |
|
deba@432
|
125 |
arc_filter[a2] = false;
|
deba@430
|
126 |
|
deba@430
|
127 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
128 |
checkGraphArcList(adaptor, 2);
|
deba@430
|
129 |
checkGraphConArcList(adaptor, 2);
|
deba@430
|
130 |
|
deba@430
|
131 |
checkGraphOutArcList(adaptor, n1, 1);
|
deba@430
|
132 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
133 |
checkGraphOutArcList(adaptor, n3, 0);
|
deba@430
|
134 |
|
deba@430
|
135 |
checkGraphInArcList(adaptor, n1, 0);
|
deba@430
|
136 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
137 |
checkGraphInArcList(adaptor, n3, 1);
|
deba@430
|
138 |
|
deba@430
|
139 |
checkNodeIds(adaptor);
|
deba@430
|
140 |
checkArcIds(adaptor);
|
deba@430
|
141 |
|
deba@430
|
142 |
checkGraphNodeMap(adaptor);
|
deba@430
|
143 |
checkGraphArcMap(adaptor);
|
deba@430
|
144 |
|
deba@432
|
145 |
node_filter[n1] = false;
|
deba@430
|
146 |
|
deba@430
|
147 |
checkGraphNodeList(adaptor, 2);
|
deba@430
|
148 |
checkGraphArcList(adaptor, 1);
|
deba@430
|
149 |
checkGraphConArcList(adaptor, 1);
|
deba@430
|
150 |
|
deba@430
|
151 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
152 |
checkGraphOutArcList(adaptor, n3, 0);
|
deba@430
|
153 |
|
deba@430
|
154 |
checkGraphInArcList(adaptor, n2, 0);
|
deba@430
|
155 |
checkGraphInArcList(adaptor, n3, 1);
|
deba@430
|
156 |
|
deba@430
|
157 |
checkNodeIds(adaptor);
|
deba@430
|
158 |
checkArcIds(adaptor);
|
deba@430
|
159 |
|
deba@430
|
160 |
checkGraphNodeMap(adaptor);
|
deba@430
|
161 |
checkGraphArcMap(adaptor);
|
deba@430
|
162 |
|
deba@430
|
163 |
node_filter[n1] = node_filter[n2] = node_filter[n3] = false;
|
deba@430
|
164 |
arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false;
|
deba@430
|
165 |
|
deba@430
|
166 |
checkGraphNodeList(adaptor, 0);
|
deba@430
|
167 |
checkGraphArcList(adaptor, 0);
|
deba@430
|
168 |
checkGraphConArcList(adaptor, 0);
|
deba@430
|
169 |
|
deba@430
|
170 |
checkNodeIds(adaptor);
|
deba@430
|
171 |
checkArcIds(adaptor);
|
deba@430
|
172 |
|
deba@430
|
173 |
checkGraphNodeMap(adaptor);
|
deba@430
|
174 |
checkGraphArcMap(adaptor);
|
deba@430
|
175 |
}
|
deba@430
|
176 |
|
deba@432
|
177 |
void checkFilterNodes1() {
|
deba@432
|
178 |
checkConcept<concepts::Digraph,
|
deba@432
|
179 |
FilterNodes<concepts::Digraph,
|
deba@430
|
180 |
concepts::Digraph::NodeMap<bool> > >();
|
deba@430
|
181 |
|
deba@430
|
182 |
typedef ListDigraph Digraph;
|
deba@430
|
183 |
typedef Digraph::NodeMap<bool> NodeFilter;
|
deba@432
|
184 |
typedef FilterNodes<Digraph, NodeFilter> Adaptor;
|
deba@430
|
185 |
|
deba@430
|
186 |
Digraph digraph;
|
deba@430
|
187 |
NodeFilter node_filter(digraph);
|
deba@430
|
188 |
Adaptor adaptor(digraph, node_filter);
|
deba@430
|
189 |
|
deba@430
|
190 |
Digraph::Node n1 = digraph.addNode();
|
deba@430
|
191 |
Digraph::Node n2 = digraph.addNode();
|
deba@430
|
192 |
Digraph::Node n3 = digraph.addNode();
|
deba@430
|
193 |
|
deba@430
|
194 |
Digraph::Arc a1 = digraph.addArc(n1, n2);
|
deba@430
|
195 |
Digraph::Arc a2 = digraph.addArc(n1, n3);
|
deba@430
|
196 |
Digraph::Arc a3 = digraph.addArc(n2, n3);
|
deba@430
|
197 |
|
deba@430
|
198 |
node_filter[n1] = node_filter[n2] = node_filter[n3] = true;
|
alpar@463
|
199 |
|
deba@430
|
200 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
201 |
checkGraphArcList(adaptor, 3);
|
deba@430
|
202 |
checkGraphConArcList(adaptor, 3);
|
deba@430
|
203 |
|
deba@430
|
204 |
checkGraphOutArcList(adaptor, n1, 2);
|
deba@430
|
205 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
206 |
checkGraphOutArcList(adaptor, n3, 0);
|
deba@430
|
207 |
|
deba@430
|
208 |
checkGraphInArcList(adaptor, n1, 0);
|
deba@430
|
209 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
210 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
211 |
|
deba@430
|
212 |
checkNodeIds(adaptor);
|
deba@430
|
213 |
checkArcIds(adaptor);
|
deba@430
|
214 |
|
deba@430
|
215 |
checkGraphNodeMap(adaptor);
|
deba@430
|
216 |
checkGraphArcMap(adaptor);
|
deba@430
|
217 |
|
deba@432
|
218 |
node_filter[n1] = false;
|
deba@430
|
219 |
|
deba@430
|
220 |
checkGraphNodeList(adaptor, 2);
|
deba@430
|
221 |
checkGraphArcList(adaptor, 1);
|
deba@430
|
222 |
checkGraphConArcList(adaptor, 1);
|
deba@430
|
223 |
|
deba@430
|
224 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
225 |
checkGraphOutArcList(adaptor, n3, 0);
|
deba@430
|
226 |
|
deba@430
|
227 |
checkGraphInArcList(adaptor, n2, 0);
|
deba@430
|
228 |
checkGraphInArcList(adaptor, n3, 1);
|
deba@430
|
229 |
|
deba@430
|
230 |
checkNodeIds(adaptor);
|
deba@430
|
231 |
checkArcIds(adaptor);
|
deba@430
|
232 |
|
deba@430
|
233 |
checkGraphNodeMap(adaptor);
|
deba@430
|
234 |
checkGraphArcMap(adaptor);
|
deba@430
|
235 |
|
deba@430
|
236 |
node_filter[n1] = node_filter[n2] = node_filter[n3] = false;
|
deba@430
|
237 |
|
deba@430
|
238 |
checkGraphNodeList(adaptor, 0);
|
deba@430
|
239 |
checkGraphArcList(adaptor, 0);
|
deba@430
|
240 |
checkGraphConArcList(adaptor, 0);
|
deba@430
|
241 |
|
deba@430
|
242 |
checkNodeIds(adaptor);
|
deba@430
|
243 |
checkArcIds(adaptor);
|
deba@430
|
244 |
|
deba@430
|
245 |
checkGraphNodeMap(adaptor);
|
deba@430
|
246 |
checkGraphArcMap(adaptor);
|
deba@430
|
247 |
}
|
deba@430
|
248 |
|
deba@432
|
249 |
void checkFilterArcs() {
|
deba@432
|
250 |
checkConcept<concepts::Digraph,
|
deba@432
|
251 |
FilterArcs<concepts::Digraph,
|
deba@430
|
252 |
concepts::Digraph::ArcMap<bool> > >();
|
deba@430
|
253 |
|
deba@430
|
254 |
typedef ListDigraph Digraph;
|
deba@430
|
255 |
typedef Digraph::ArcMap<bool> ArcFilter;
|
deba@432
|
256 |
typedef FilterArcs<Digraph, ArcFilter> Adaptor;
|
deba@430
|
257 |
|
deba@430
|
258 |
Digraph digraph;
|
deba@430
|
259 |
ArcFilter arc_filter(digraph);
|
deba@430
|
260 |
Adaptor adaptor(digraph, arc_filter);
|
deba@430
|
261 |
|
deba@430
|
262 |
Digraph::Node n1 = digraph.addNode();
|
deba@430
|
263 |
Digraph::Node n2 = digraph.addNode();
|
deba@430
|
264 |
Digraph::Node n3 = digraph.addNode();
|
deba@430
|
265 |
|
deba@430
|
266 |
Digraph::Arc a1 = digraph.addArc(n1, n2);
|
deba@430
|
267 |
Digraph::Arc a2 = digraph.addArc(n1, n3);
|
deba@430
|
268 |
Digraph::Arc a3 = digraph.addArc(n2, n3);
|
deba@430
|
269 |
|
deba@430
|
270 |
arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true;
|
alpar@463
|
271 |
|
deba@430
|
272 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
273 |
checkGraphArcList(adaptor, 3);
|
deba@430
|
274 |
checkGraphConArcList(adaptor, 3);
|
deba@430
|
275 |
|
deba@430
|
276 |
checkGraphOutArcList(adaptor, n1, 2);
|
deba@430
|
277 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
278 |
checkGraphOutArcList(adaptor, n3, 0);
|
deba@430
|
279 |
|
deba@430
|
280 |
checkGraphInArcList(adaptor, n1, 0);
|
deba@430
|
281 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
282 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
283 |
|
deba@430
|
284 |
checkNodeIds(adaptor);
|
deba@430
|
285 |
checkArcIds(adaptor);
|
deba@430
|
286 |
|
deba@430
|
287 |
checkGraphNodeMap(adaptor);
|
deba@430
|
288 |
checkGraphArcMap(adaptor);
|
deba@430
|
289 |
|
deba@432
|
290 |
arc_filter[a2] = false;
|
deba@430
|
291 |
|
deba@430
|
292 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
293 |
checkGraphArcList(adaptor, 2);
|
deba@430
|
294 |
checkGraphConArcList(adaptor, 2);
|
deba@430
|
295 |
|
deba@430
|
296 |
checkGraphOutArcList(adaptor, n1, 1);
|
deba@430
|
297 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
298 |
checkGraphOutArcList(adaptor, n3, 0);
|
deba@430
|
299 |
|
deba@430
|
300 |
checkGraphInArcList(adaptor, n1, 0);
|
deba@430
|
301 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
302 |
checkGraphInArcList(adaptor, n3, 1);
|
deba@430
|
303 |
|
deba@430
|
304 |
checkNodeIds(adaptor);
|
deba@430
|
305 |
checkArcIds(adaptor);
|
deba@430
|
306 |
|
deba@430
|
307 |
checkGraphNodeMap(adaptor);
|
deba@430
|
308 |
checkGraphArcMap(adaptor);
|
deba@430
|
309 |
|
deba@430
|
310 |
arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false;
|
deba@430
|
311 |
|
deba@430
|
312 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
313 |
checkGraphArcList(adaptor, 0);
|
deba@430
|
314 |
checkGraphConArcList(adaptor, 0);
|
deba@430
|
315 |
|
deba@430
|
316 |
checkNodeIds(adaptor);
|
deba@430
|
317 |
checkArcIds(adaptor);
|
deba@430
|
318 |
|
deba@430
|
319 |
checkGraphNodeMap(adaptor);
|
deba@430
|
320 |
checkGraphArcMap(adaptor);
|
deba@430
|
321 |
}
|
deba@430
|
322 |
|
deba@432
|
323 |
void checkUndirector() {
|
deba@432
|
324 |
checkConcept<concepts::Graph, Undirector<concepts::Digraph> >();
|
deba@430
|
325 |
|
deba@430
|
326 |
typedef ListDigraph Digraph;
|
deba@432
|
327 |
typedef Undirector<Digraph> Adaptor;
|
deba@430
|
328 |
|
deba@430
|
329 |
Digraph digraph;
|
deba@430
|
330 |
Adaptor adaptor(digraph);
|
deba@430
|
331 |
|
deba@430
|
332 |
Digraph::Node n1 = digraph.addNode();
|
deba@430
|
333 |
Digraph::Node n2 = digraph.addNode();
|
deba@430
|
334 |
Digraph::Node n3 = digraph.addNode();
|
deba@430
|
335 |
|
deba@430
|
336 |
Digraph::Arc a1 = digraph.addArc(n1, n2);
|
deba@430
|
337 |
Digraph::Arc a2 = digraph.addArc(n1, n3);
|
deba@430
|
338 |
Digraph::Arc a3 = digraph.addArc(n2, n3);
|
deba@432
|
339 |
|
deba@430
|
340 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
341 |
checkGraphArcList(adaptor, 6);
|
deba@430
|
342 |
checkGraphEdgeList(adaptor, 3);
|
deba@430
|
343 |
checkGraphConArcList(adaptor, 6);
|
deba@430
|
344 |
checkGraphConEdgeList(adaptor, 3);
|
deba@430
|
345 |
|
deba@430
|
346 |
checkGraphOutArcList(adaptor, n1, 2);
|
deba@430
|
347 |
checkGraphOutArcList(adaptor, n2, 2);
|
deba@430
|
348 |
checkGraphOutArcList(adaptor, n3, 2);
|
deba@430
|
349 |
|
deba@430
|
350 |
checkGraphInArcList(adaptor, n1, 2);
|
deba@430
|
351 |
checkGraphInArcList(adaptor, n2, 2);
|
deba@430
|
352 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
353 |
|
deba@430
|
354 |
checkGraphIncEdgeList(adaptor, n1, 2);
|
deba@430
|
355 |
checkGraphIncEdgeList(adaptor, n2, 2);
|
deba@430
|
356 |
checkGraphIncEdgeList(adaptor, n3, 2);
|
deba@430
|
357 |
|
deba@430
|
358 |
checkNodeIds(adaptor);
|
deba@430
|
359 |
checkArcIds(adaptor);
|
deba@430
|
360 |
checkEdgeIds(adaptor);
|
deba@430
|
361 |
|
deba@430
|
362 |
checkGraphNodeMap(adaptor);
|
deba@430
|
363 |
checkGraphArcMap(adaptor);
|
deba@430
|
364 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
365 |
|
deba@430
|
366 |
for (Adaptor::EdgeIt e(adaptor); e != INVALID; ++e) {
|
deba@430
|
367 |
check(adaptor.u(e) == digraph.source(e), "Wrong undir");
|
deba@430
|
368 |
check(adaptor.v(e) == digraph.target(e), "Wrong undir");
|
deba@430
|
369 |
}
|
deba@430
|
370 |
|
deba@430
|
371 |
}
|
deba@430
|
372 |
|
deba@432
|
373 |
void checkResidual() {
|
deba@432
|
374 |
checkConcept<concepts::Digraph,
|
deba@432
|
375 |
Residual<concepts::Digraph,
|
deba@432
|
376 |
concepts::Digraph::ArcMap<int>,
|
deba@430
|
377 |
concepts::Digraph::ArcMap<int> > >();
|
deba@430
|
378 |
|
deba@430
|
379 |
typedef ListDigraph Digraph;
|
deba@430
|
380 |
typedef Digraph::ArcMap<int> IntArcMap;
|
deba@432
|
381 |
typedef Residual<Digraph, IntArcMap> Adaptor;
|
deba@430
|
382 |
|
deba@430
|
383 |
Digraph digraph;
|
deba@430
|
384 |
IntArcMap capacity(digraph), flow(digraph);
|
deba@430
|
385 |
Adaptor adaptor(digraph, capacity, flow);
|
deba@430
|
386 |
|
deba@430
|
387 |
Digraph::Node n1 = digraph.addNode();
|
deba@430
|
388 |
Digraph::Node n2 = digraph.addNode();
|
deba@430
|
389 |
Digraph::Node n3 = digraph.addNode();
|
deba@430
|
390 |
Digraph::Node n4 = digraph.addNode();
|
deba@430
|
391 |
|
deba@430
|
392 |
Digraph::Arc a1 = digraph.addArc(n1, n2);
|
deba@430
|
393 |
Digraph::Arc a2 = digraph.addArc(n1, n3);
|
deba@430
|
394 |
Digraph::Arc a3 = digraph.addArc(n1, n4);
|
deba@430
|
395 |
Digraph::Arc a4 = digraph.addArc(n2, n3);
|
deba@430
|
396 |
Digraph::Arc a5 = digraph.addArc(n2, n4);
|
deba@430
|
397 |
Digraph::Arc a6 = digraph.addArc(n3, n4);
|
deba@430
|
398 |
|
deba@430
|
399 |
capacity[a1] = 8;
|
deba@430
|
400 |
capacity[a2] = 6;
|
deba@430
|
401 |
capacity[a3] = 4;
|
deba@430
|
402 |
capacity[a4] = 4;
|
deba@430
|
403 |
capacity[a5] = 6;
|
deba@430
|
404 |
capacity[a6] = 10;
|
deba@430
|
405 |
|
deba@430
|
406 |
for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
|
deba@430
|
407 |
flow[a] = 0;
|
deba@430
|
408 |
}
|
deba@432
|
409 |
|
deba@430
|
410 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
411 |
checkGraphArcList(adaptor, 6);
|
deba@430
|
412 |
checkGraphConArcList(adaptor, 6);
|
deba@430
|
413 |
|
deba@430
|
414 |
checkGraphOutArcList(adaptor, n1, 3);
|
deba@430
|
415 |
checkGraphOutArcList(adaptor, n2, 2);
|
deba@430
|
416 |
checkGraphOutArcList(adaptor, n3, 1);
|
deba@430
|
417 |
checkGraphOutArcList(adaptor, n4, 0);
|
deba@430
|
418 |
|
deba@430
|
419 |
checkGraphInArcList(adaptor, n1, 0);
|
deba@430
|
420 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
421 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
422 |
checkGraphInArcList(adaptor, n4, 3);
|
deba@430
|
423 |
|
deba@430
|
424 |
for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
|
deba@430
|
425 |
flow[a] = capacity[a] / 2;
|
deba@430
|
426 |
}
|
deba@432
|
427 |
|
deba@430
|
428 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
429 |
checkGraphArcList(adaptor, 12);
|
deba@430
|
430 |
checkGraphConArcList(adaptor, 12);
|
deba@430
|
431 |
|
deba@430
|
432 |
checkGraphOutArcList(adaptor, n1, 3);
|
deba@430
|
433 |
checkGraphOutArcList(adaptor, n2, 3);
|
deba@430
|
434 |
checkGraphOutArcList(adaptor, n3, 3);
|
deba@430
|
435 |
checkGraphOutArcList(adaptor, n4, 3);
|
deba@430
|
436 |
|
deba@430
|
437 |
checkGraphInArcList(adaptor, n1, 3);
|
deba@430
|
438 |
checkGraphInArcList(adaptor, n2, 3);
|
deba@430
|
439 |
checkGraphInArcList(adaptor, n3, 3);
|
deba@430
|
440 |
checkGraphInArcList(adaptor, n4, 3);
|
deba@430
|
441 |
|
deba@430
|
442 |
checkNodeIds(adaptor);
|
deba@430
|
443 |
checkArcIds(adaptor);
|
deba@430
|
444 |
|
deba@430
|
445 |
checkGraphNodeMap(adaptor);
|
deba@430
|
446 |
checkGraphArcMap(adaptor);
|
deba@430
|
447 |
|
deba@430
|
448 |
for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
|
deba@430
|
449 |
flow[a] = capacity[a];
|
deba@430
|
450 |
}
|
deba@432
|
451 |
|
deba@430
|
452 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
453 |
checkGraphArcList(adaptor, 6);
|
deba@430
|
454 |
checkGraphConArcList(adaptor, 6);
|
deba@430
|
455 |
|
deba@430
|
456 |
checkGraphOutArcList(adaptor, n1, 0);
|
deba@430
|
457 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
458 |
checkGraphOutArcList(adaptor, n3, 2);
|
deba@430
|
459 |
checkGraphOutArcList(adaptor, n4, 3);
|
deba@430
|
460 |
|
deba@430
|
461 |
checkGraphInArcList(adaptor, n1, 3);
|
deba@430
|
462 |
checkGraphInArcList(adaptor, n2, 2);
|
deba@430
|
463 |
checkGraphInArcList(adaptor, n3, 1);
|
deba@430
|
464 |
checkGraphInArcList(adaptor, n4, 0);
|
deba@430
|
465 |
|
deba@430
|
466 |
for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
|
deba@430
|
467 |
flow[a] = 0;
|
deba@430
|
468 |
}
|
deba@430
|
469 |
|
deba@430
|
470 |
int flow_value = 0;
|
deba@430
|
471 |
while (true) {
|
deba@432
|
472 |
|
deba@430
|
473 |
Bfs<Adaptor> bfs(adaptor);
|
deba@430
|
474 |
bfs.run(n1, n4);
|
deba@432
|
475 |
|
deba@430
|
476 |
if (!bfs.reached(n4)) break;
|
deba@430
|
477 |
|
deba@430
|
478 |
Path<Adaptor> p = bfs.path(n4);
|
deba@432
|
479 |
|
deba@430
|
480 |
int min = std::numeric_limits<int>::max();
|
deba@430
|
481 |
for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
|
deba@432
|
482 |
if (adaptor.residualCapacity(a) < min)
|
deba@432
|
483 |
min = adaptor.residualCapacity(a);
|
deba@430
|
484 |
}
|
deba@430
|
485 |
|
deba@430
|
486 |
for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
|
deba@430
|
487 |
adaptor.augment(a, min);
|
deba@430
|
488 |
}
|
deba@430
|
489 |
flow_value += min;
|
deba@430
|
490 |
}
|
deba@430
|
491 |
|
deba@430
|
492 |
check(flow_value == 18, "Wrong flow with res graph adaptor");
|
deba@430
|
493 |
|
deba@430
|
494 |
}
|
deba@430
|
495 |
|
deba@432
|
496 |
void checkSplitNodes() {
|
deba@432
|
497 |
checkConcept<concepts::Digraph, SplitNodes<concepts::Digraph> >();
|
deba@430
|
498 |
|
deba@430
|
499 |
typedef ListDigraph Digraph;
|
deba@432
|
500 |
typedef SplitNodes<Digraph> Adaptor;
|
deba@430
|
501 |
|
deba@430
|
502 |
Digraph digraph;
|
deba@430
|
503 |
Adaptor adaptor(digraph);
|
deba@430
|
504 |
|
deba@430
|
505 |
Digraph::Node n1 = digraph.addNode();
|
deba@430
|
506 |
Digraph::Node n2 = digraph.addNode();
|
deba@430
|
507 |
Digraph::Node n3 = digraph.addNode();
|
deba@430
|
508 |
|
deba@430
|
509 |
Digraph::Arc a1 = digraph.addArc(n1, n2);
|
deba@430
|
510 |
Digraph::Arc a2 = digraph.addArc(n1, n3);
|
deba@430
|
511 |
Digraph::Arc a3 = digraph.addArc(n2, n3);
|
deba@432
|
512 |
|
deba@430
|
513 |
checkGraphNodeList(adaptor, 6);
|
deba@430
|
514 |
checkGraphArcList(adaptor, 6);
|
deba@430
|
515 |
checkGraphConArcList(adaptor, 6);
|
deba@430
|
516 |
|
deba@430
|
517 |
checkGraphOutArcList(adaptor, adaptor.inNode(n1), 1);
|
deba@430
|
518 |
checkGraphOutArcList(adaptor, adaptor.outNode(n1), 2);
|
deba@430
|
519 |
checkGraphOutArcList(adaptor, adaptor.inNode(n2), 1);
|
deba@430
|
520 |
checkGraphOutArcList(adaptor, adaptor.outNode(n2), 1);
|
deba@430
|
521 |
checkGraphOutArcList(adaptor, adaptor.inNode(n3), 1);
|
deba@430
|
522 |
checkGraphOutArcList(adaptor, adaptor.outNode(n3), 0);
|
deba@430
|
523 |
|
deba@430
|
524 |
checkGraphInArcList(adaptor, adaptor.inNode(n1), 0);
|
deba@430
|
525 |
checkGraphInArcList(adaptor, adaptor.outNode(n1), 1);
|
deba@430
|
526 |
checkGraphInArcList(adaptor, adaptor.inNode(n2), 1);
|
deba@430
|
527 |
checkGraphInArcList(adaptor, adaptor.outNode(n2), 1);
|
deba@430
|
528 |
checkGraphInArcList(adaptor, adaptor.inNode(n3), 2);
|
deba@430
|
529 |
checkGraphInArcList(adaptor, adaptor.outNode(n3), 1);
|
deba@430
|
530 |
|
deba@430
|
531 |
checkNodeIds(adaptor);
|
deba@430
|
532 |
checkArcIds(adaptor);
|
deba@432
|
533 |
|
deba@430
|
534 |
checkGraphNodeMap(adaptor);
|
deba@430
|
535 |
checkGraphArcMap(adaptor);
|
deba@430
|
536 |
|
deba@430
|
537 |
for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
|
deba@430
|
538 |
if (adaptor.origArc(a)) {
|
deba@430
|
539 |
Digraph::Arc oa = a;
|
deba@432
|
540 |
check(adaptor.source(a) == adaptor.outNode(digraph.source(oa)),
|
deba@432
|
541 |
"Wrong split");
|
deba@432
|
542 |
check(adaptor.target(a) == adaptor.inNode(digraph.target(oa)),
|
deba@432
|
543 |
"Wrong split");
|
deba@430
|
544 |
} else {
|
deba@430
|
545 |
Digraph::Node on = a;
|
deba@430
|
546 |
check(adaptor.source(a) == adaptor.inNode(on), "Wrong split");
|
deba@430
|
547 |
check(adaptor.target(a) == adaptor.outNode(on), "Wrong split");
|
deba@430
|
548 |
}
|
deba@430
|
549 |
}
|
deba@430
|
550 |
}
|
deba@430
|
551 |
|
deba@432
|
552 |
void checkSubGraph() {
|
deba@432
|
553 |
checkConcept<concepts::Graph,
|
deba@432
|
554 |
SubGraph<concepts::Graph,
|
deba@430
|
555 |
concepts::Graph::NodeMap<bool>,
|
deba@430
|
556 |
concepts::Graph::EdgeMap<bool> > >();
|
deba@430
|
557 |
|
deba@430
|
558 |
typedef ListGraph Graph;
|
deba@430
|
559 |
typedef Graph::NodeMap<bool> NodeFilter;
|
deba@430
|
560 |
typedef Graph::EdgeMap<bool> EdgeFilter;
|
deba@432
|
561 |
typedef SubGraph<Graph, NodeFilter, EdgeFilter> Adaptor;
|
deba@430
|
562 |
|
deba@430
|
563 |
Graph graph;
|
deba@430
|
564 |
NodeFilter node_filter(graph);
|
deba@430
|
565 |
EdgeFilter edge_filter(graph);
|
deba@430
|
566 |
Adaptor adaptor(graph, node_filter, edge_filter);
|
deba@430
|
567 |
|
deba@430
|
568 |
Graph::Node n1 = graph.addNode();
|
deba@430
|
569 |
Graph::Node n2 = graph.addNode();
|
deba@430
|
570 |
Graph::Node n3 = graph.addNode();
|
deba@430
|
571 |
Graph::Node n4 = graph.addNode();
|
deba@430
|
572 |
|
deba@430
|
573 |
Graph::Edge e1 = graph.addEdge(n1, n2);
|
deba@430
|
574 |
Graph::Edge e2 = graph.addEdge(n1, n3);
|
deba@430
|
575 |
Graph::Edge e3 = graph.addEdge(n2, n3);
|
deba@430
|
576 |
Graph::Edge e4 = graph.addEdge(n3, n4);
|
deba@430
|
577 |
|
deba@430
|
578 |
node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true;
|
deba@430
|
579 |
edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true;
|
alpar@463
|
580 |
|
deba@430
|
581 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
582 |
checkGraphArcList(adaptor, 8);
|
deba@430
|
583 |
checkGraphEdgeList(adaptor, 4);
|
deba@430
|
584 |
checkGraphConArcList(adaptor, 8);
|
deba@430
|
585 |
checkGraphConEdgeList(adaptor, 4);
|
deba@430
|
586 |
|
deba@430
|
587 |
checkGraphOutArcList(adaptor, n1, 2);
|
deba@430
|
588 |
checkGraphOutArcList(adaptor, n2, 2);
|
deba@430
|
589 |
checkGraphOutArcList(adaptor, n3, 3);
|
deba@430
|
590 |
checkGraphOutArcList(adaptor, n4, 1);
|
deba@430
|
591 |
|
deba@430
|
592 |
checkGraphInArcList(adaptor, n1, 2);
|
deba@430
|
593 |
checkGraphInArcList(adaptor, n2, 2);
|
deba@430
|
594 |
checkGraphInArcList(adaptor, n3, 3);
|
deba@430
|
595 |
checkGraphInArcList(adaptor, n4, 1);
|
deba@430
|
596 |
|
deba@430
|
597 |
checkGraphIncEdgeList(adaptor, n1, 2);
|
deba@430
|
598 |
checkGraphIncEdgeList(adaptor, n2, 2);
|
deba@430
|
599 |
checkGraphIncEdgeList(adaptor, n3, 3);
|
deba@430
|
600 |
checkGraphIncEdgeList(adaptor, n4, 1);
|
deba@430
|
601 |
|
deba@430
|
602 |
checkNodeIds(adaptor);
|
deba@430
|
603 |
checkArcIds(adaptor);
|
deba@430
|
604 |
checkEdgeIds(adaptor);
|
deba@430
|
605 |
|
deba@430
|
606 |
checkGraphNodeMap(adaptor);
|
deba@430
|
607 |
checkGraphArcMap(adaptor);
|
deba@430
|
608 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
609 |
|
deba@432
|
610 |
edge_filter[e2] = false;
|
deba@430
|
611 |
|
deba@430
|
612 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
613 |
checkGraphArcList(adaptor, 6);
|
deba@430
|
614 |
checkGraphEdgeList(adaptor, 3);
|
deba@430
|
615 |
checkGraphConArcList(adaptor, 6);
|
deba@430
|
616 |
checkGraphConEdgeList(adaptor, 3);
|
deba@430
|
617 |
|
deba@430
|
618 |
checkGraphOutArcList(adaptor, n1, 1);
|
deba@430
|
619 |
checkGraphOutArcList(adaptor, n2, 2);
|
deba@430
|
620 |
checkGraphOutArcList(adaptor, n3, 2);
|
deba@430
|
621 |
checkGraphOutArcList(adaptor, n4, 1);
|
deba@430
|
622 |
|
deba@430
|
623 |
checkGraphInArcList(adaptor, n1, 1);
|
deba@430
|
624 |
checkGraphInArcList(adaptor, n2, 2);
|
deba@430
|
625 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
626 |
checkGraphInArcList(adaptor, n4, 1);
|
deba@430
|
627 |
|
deba@430
|
628 |
checkGraphIncEdgeList(adaptor, n1, 1);
|
deba@430
|
629 |
checkGraphIncEdgeList(adaptor, n2, 2);
|
deba@430
|
630 |
checkGraphIncEdgeList(adaptor, n3, 2);
|
deba@430
|
631 |
checkGraphIncEdgeList(adaptor, n4, 1);
|
deba@430
|
632 |
|
deba@430
|
633 |
checkNodeIds(adaptor);
|
deba@430
|
634 |
checkArcIds(adaptor);
|
deba@430
|
635 |
checkEdgeIds(adaptor);
|
deba@430
|
636 |
|
deba@430
|
637 |
checkGraphNodeMap(adaptor);
|
deba@430
|
638 |
checkGraphArcMap(adaptor);
|
deba@430
|
639 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
640 |
|
deba@432
|
641 |
node_filter[n1] = false;
|
deba@430
|
642 |
|
deba@430
|
643 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
644 |
checkGraphArcList(adaptor, 4);
|
deba@430
|
645 |
checkGraphEdgeList(adaptor, 2);
|
deba@430
|
646 |
checkGraphConArcList(adaptor, 4);
|
deba@430
|
647 |
checkGraphConEdgeList(adaptor, 2);
|
deba@430
|
648 |
|
deba@430
|
649 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
650 |
checkGraphOutArcList(adaptor, n3, 2);
|
deba@430
|
651 |
checkGraphOutArcList(adaptor, n4, 1);
|
deba@430
|
652 |
|
deba@430
|
653 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
654 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
655 |
checkGraphInArcList(adaptor, n4, 1);
|
deba@430
|
656 |
|
deba@430
|
657 |
checkGraphIncEdgeList(adaptor, n2, 1);
|
deba@430
|
658 |
checkGraphIncEdgeList(adaptor, n3, 2);
|
deba@430
|
659 |
checkGraphIncEdgeList(adaptor, n4, 1);
|
deba@430
|
660 |
|
deba@430
|
661 |
checkNodeIds(adaptor);
|
deba@430
|
662 |
checkArcIds(adaptor);
|
deba@430
|
663 |
checkEdgeIds(adaptor);
|
deba@430
|
664 |
|
deba@430
|
665 |
checkGraphNodeMap(adaptor);
|
deba@430
|
666 |
checkGraphArcMap(adaptor);
|
deba@430
|
667 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
668 |
|
deba@430
|
669 |
node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = false;
|
deba@430
|
670 |
edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = false;
|
deba@430
|
671 |
|
deba@430
|
672 |
checkGraphNodeList(adaptor, 0);
|
deba@430
|
673 |
checkGraphArcList(adaptor, 0);
|
deba@430
|
674 |
checkGraphEdgeList(adaptor, 0);
|
deba@430
|
675 |
checkGraphConArcList(adaptor, 0);
|
deba@430
|
676 |
checkGraphConEdgeList(adaptor, 0);
|
deba@430
|
677 |
|
deba@430
|
678 |
checkNodeIds(adaptor);
|
deba@430
|
679 |
checkArcIds(adaptor);
|
deba@430
|
680 |
checkEdgeIds(adaptor);
|
deba@430
|
681 |
|
deba@430
|
682 |
checkGraphNodeMap(adaptor);
|
deba@430
|
683 |
checkGraphArcMap(adaptor);
|
deba@430
|
684 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
685 |
}
|
deba@430
|
686 |
|
deba@432
|
687 |
void checkFilterNodes2() {
|
deba@432
|
688 |
checkConcept<concepts::Graph,
|
deba@432
|
689 |
FilterNodes<concepts::Graph,
|
deba@430
|
690 |
concepts::Graph::NodeMap<bool> > >();
|
deba@430
|
691 |
|
deba@430
|
692 |
typedef ListGraph Graph;
|
deba@430
|
693 |
typedef Graph::NodeMap<bool> NodeFilter;
|
deba@432
|
694 |
typedef FilterNodes<Graph, NodeFilter> Adaptor;
|
deba@430
|
695 |
|
deba@430
|
696 |
Graph graph;
|
deba@430
|
697 |
NodeFilter node_filter(graph);
|
deba@430
|
698 |
Adaptor adaptor(graph, node_filter);
|
deba@430
|
699 |
|
deba@430
|
700 |
Graph::Node n1 = graph.addNode();
|
deba@430
|
701 |
Graph::Node n2 = graph.addNode();
|
deba@430
|
702 |
Graph::Node n3 = graph.addNode();
|
deba@430
|
703 |
Graph::Node n4 = graph.addNode();
|
deba@430
|
704 |
|
deba@430
|
705 |
Graph::Edge e1 = graph.addEdge(n1, n2);
|
deba@430
|
706 |
Graph::Edge e2 = graph.addEdge(n1, n3);
|
deba@430
|
707 |
Graph::Edge e3 = graph.addEdge(n2, n3);
|
deba@430
|
708 |
Graph::Edge e4 = graph.addEdge(n3, n4);
|
deba@430
|
709 |
|
deba@430
|
710 |
node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true;
|
alpar@463
|
711 |
|
deba@430
|
712 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
713 |
checkGraphArcList(adaptor, 8);
|
deba@430
|
714 |
checkGraphEdgeList(adaptor, 4);
|
deba@430
|
715 |
checkGraphConArcList(adaptor, 8);
|
deba@430
|
716 |
checkGraphConEdgeList(adaptor, 4);
|
deba@430
|
717 |
|
deba@430
|
718 |
checkGraphOutArcList(adaptor, n1, 2);
|
deba@430
|
719 |
checkGraphOutArcList(adaptor, n2, 2);
|
deba@430
|
720 |
checkGraphOutArcList(adaptor, n3, 3);
|
deba@430
|
721 |
checkGraphOutArcList(adaptor, n4, 1);
|
deba@430
|
722 |
|
deba@430
|
723 |
checkGraphInArcList(adaptor, n1, 2);
|
deba@430
|
724 |
checkGraphInArcList(adaptor, n2, 2);
|
deba@430
|
725 |
checkGraphInArcList(adaptor, n3, 3);
|
deba@430
|
726 |
checkGraphInArcList(adaptor, n4, 1);
|
deba@430
|
727 |
|
deba@430
|
728 |
checkGraphIncEdgeList(adaptor, n1, 2);
|
deba@430
|
729 |
checkGraphIncEdgeList(adaptor, n2, 2);
|
deba@430
|
730 |
checkGraphIncEdgeList(adaptor, n3, 3);
|
deba@430
|
731 |
checkGraphIncEdgeList(adaptor, n4, 1);
|
deba@430
|
732 |
|
deba@430
|
733 |
checkNodeIds(adaptor);
|
deba@430
|
734 |
checkArcIds(adaptor);
|
deba@430
|
735 |
checkEdgeIds(adaptor);
|
deba@430
|
736 |
|
deba@430
|
737 |
checkGraphNodeMap(adaptor);
|
deba@430
|
738 |
checkGraphArcMap(adaptor);
|
deba@430
|
739 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
740 |
|
deba@432
|
741 |
node_filter[n1] = false;
|
deba@430
|
742 |
|
deba@430
|
743 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
744 |
checkGraphArcList(adaptor, 4);
|
deba@430
|
745 |
checkGraphEdgeList(adaptor, 2);
|
deba@430
|
746 |
checkGraphConArcList(adaptor, 4);
|
deba@430
|
747 |
checkGraphConEdgeList(adaptor, 2);
|
deba@430
|
748 |
|
deba@430
|
749 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
750 |
checkGraphOutArcList(adaptor, n3, 2);
|
deba@430
|
751 |
checkGraphOutArcList(adaptor, n4, 1);
|
deba@430
|
752 |
|
deba@430
|
753 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
754 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
755 |
checkGraphInArcList(adaptor, n4, 1);
|
deba@430
|
756 |
|
deba@430
|
757 |
checkGraphIncEdgeList(adaptor, n2, 1);
|
deba@430
|
758 |
checkGraphIncEdgeList(adaptor, n3, 2);
|
deba@430
|
759 |
checkGraphIncEdgeList(adaptor, n4, 1);
|
deba@430
|
760 |
|
deba@430
|
761 |
checkNodeIds(adaptor);
|
deba@430
|
762 |
checkArcIds(adaptor);
|
deba@430
|
763 |
checkEdgeIds(adaptor);
|
deba@430
|
764 |
|
deba@430
|
765 |
checkGraphNodeMap(adaptor);
|
deba@430
|
766 |
checkGraphArcMap(adaptor);
|
deba@430
|
767 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
768 |
|
deba@430
|
769 |
node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = false;
|
deba@430
|
770 |
|
deba@430
|
771 |
checkGraphNodeList(adaptor, 0);
|
deba@430
|
772 |
checkGraphArcList(adaptor, 0);
|
deba@430
|
773 |
checkGraphEdgeList(adaptor, 0);
|
deba@430
|
774 |
checkGraphConArcList(adaptor, 0);
|
deba@430
|
775 |
checkGraphConEdgeList(adaptor, 0);
|
deba@430
|
776 |
|
deba@430
|
777 |
checkNodeIds(adaptor);
|
deba@430
|
778 |
checkArcIds(adaptor);
|
deba@430
|
779 |
checkEdgeIds(adaptor);
|
deba@430
|
780 |
|
deba@430
|
781 |
checkGraphNodeMap(adaptor);
|
deba@430
|
782 |
checkGraphArcMap(adaptor);
|
deba@430
|
783 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
784 |
}
|
deba@430
|
785 |
|
deba@432
|
786 |
void checkFilterEdges() {
|
deba@432
|
787 |
checkConcept<concepts::Graph,
|
deba@432
|
788 |
FilterEdges<concepts::Graph,
|
deba@430
|
789 |
concepts::Graph::EdgeMap<bool> > >();
|
deba@430
|
790 |
|
deba@430
|
791 |
typedef ListGraph Graph;
|
deba@430
|
792 |
typedef Graph::EdgeMap<bool> EdgeFilter;
|
deba@432
|
793 |
typedef FilterEdges<Graph, EdgeFilter> Adaptor;
|
deba@430
|
794 |
|
deba@430
|
795 |
Graph graph;
|
deba@430
|
796 |
EdgeFilter edge_filter(graph);
|
deba@430
|
797 |
Adaptor adaptor(graph, edge_filter);
|
deba@430
|
798 |
|
deba@430
|
799 |
Graph::Node n1 = graph.addNode();
|
deba@430
|
800 |
Graph::Node n2 = graph.addNode();
|
deba@430
|
801 |
Graph::Node n3 = graph.addNode();
|
deba@430
|
802 |
Graph::Node n4 = graph.addNode();
|
deba@430
|
803 |
|
deba@430
|
804 |
Graph::Edge e1 = graph.addEdge(n1, n2);
|
deba@430
|
805 |
Graph::Edge e2 = graph.addEdge(n1, n3);
|
deba@430
|
806 |
Graph::Edge e3 = graph.addEdge(n2, n3);
|
deba@430
|
807 |
Graph::Edge e4 = graph.addEdge(n3, n4);
|
deba@430
|
808 |
|
deba@430
|
809 |
edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true;
|
alpar@463
|
810 |
|
deba@430
|
811 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
812 |
checkGraphArcList(adaptor, 8);
|
deba@430
|
813 |
checkGraphEdgeList(adaptor, 4);
|
deba@430
|
814 |
checkGraphConArcList(adaptor, 8);
|
deba@430
|
815 |
checkGraphConEdgeList(adaptor, 4);
|
deba@430
|
816 |
|
deba@430
|
817 |
checkGraphOutArcList(adaptor, n1, 2);
|
deba@430
|
818 |
checkGraphOutArcList(adaptor, n2, 2);
|
deba@430
|
819 |
checkGraphOutArcList(adaptor, n3, 3);
|
deba@430
|
820 |
checkGraphOutArcList(adaptor, n4, 1);
|
deba@430
|
821 |
|
deba@430
|
822 |
checkGraphInArcList(adaptor, n1, 2);
|
deba@430
|
823 |
checkGraphInArcList(adaptor, n2, 2);
|
deba@430
|
824 |
checkGraphInArcList(adaptor, n3, 3);
|
deba@430
|
825 |
checkGraphInArcList(adaptor, n4, 1);
|
deba@430
|
826 |
|
deba@430
|
827 |
checkGraphIncEdgeList(adaptor, n1, 2);
|
deba@430
|
828 |
checkGraphIncEdgeList(adaptor, n2, 2);
|
deba@430
|
829 |
checkGraphIncEdgeList(adaptor, n3, 3);
|
deba@430
|
830 |
checkGraphIncEdgeList(adaptor, n4, 1);
|
deba@430
|
831 |
|
deba@430
|
832 |
checkNodeIds(adaptor);
|
deba@430
|
833 |
checkArcIds(adaptor);
|
deba@430
|
834 |
checkEdgeIds(adaptor);
|
deba@430
|
835 |
|
deba@430
|
836 |
checkGraphNodeMap(adaptor);
|
deba@430
|
837 |
checkGraphArcMap(adaptor);
|
deba@430
|
838 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
839 |
|
deba@432
|
840 |
edge_filter[e2] = false;
|
deba@430
|
841 |
|
deba@430
|
842 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
843 |
checkGraphArcList(adaptor, 6);
|
deba@430
|
844 |
checkGraphEdgeList(adaptor, 3);
|
deba@430
|
845 |
checkGraphConArcList(adaptor, 6);
|
deba@430
|
846 |
checkGraphConEdgeList(adaptor, 3);
|
deba@430
|
847 |
|
deba@430
|
848 |
checkGraphOutArcList(adaptor, n1, 1);
|
deba@430
|
849 |
checkGraphOutArcList(adaptor, n2, 2);
|
deba@430
|
850 |
checkGraphOutArcList(adaptor, n3, 2);
|
deba@430
|
851 |
checkGraphOutArcList(adaptor, n4, 1);
|
deba@430
|
852 |
|
deba@430
|
853 |
checkGraphInArcList(adaptor, n1, 1);
|
deba@430
|
854 |
checkGraphInArcList(adaptor, n2, 2);
|
deba@430
|
855 |
checkGraphInArcList(adaptor, n3, 2);
|
deba@430
|
856 |
checkGraphInArcList(adaptor, n4, 1);
|
deba@430
|
857 |
|
deba@430
|
858 |
checkGraphIncEdgeList(adaptor, n1, 1);
|
deba@430
|
859 |
checkGraphIncEdgeList(adaptor, n2, 2);
|
deba@430
|
860 |
checkGraphIncEdgeList(adaptor, n3, 2);
|
deba@430
|
861 |
checkGraphIncEdgeList(adaptor, n4, 1);
|
deba@430
|
862 |
|
deba@430
|
863 |
checkNodeIds(adaptor);
|
deba@430
|
864 |
checkArcIds(adaptor);
|
deba@430
|
865 |
checkEdgeIds(adaptor);
|
deba@430
|
866 |
|
deba@430
|
867 |
checkGraphNodeMap(adaptor);
|
deba@430
|
868 |
checkGraphArcMap(adaptor);
|
deba@430
|
869 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
870 |
|
deba@430
|
871 |
edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = false;
|
deba@430
|
872 |
|
deba@430
|
873 |
checkGraphNodeList(adaptor, 4);
|
deba@430
|
874 |
checkGraphArcList(adaptor, 0);
|
deba@430
|
875 |
checkGraphEdgeList(adaptor, 0);
|
deba@430
|
876 |
checkGraphConArcList(adaptor, 0);
|
deba@430
|
877 |
checkGraphConEdgeList(adaptor, 0);
|
deba@430
|
878 |
|
deba@430
|
879 |
checkNodeIds(adaptor);
|
deba@430
|
880 |
checkArcIds(adaptor);
|
deba@430
|
881 |
checkEdgeIds(adaptor);
|
deba@430
|
882 |
|
deba@430
|
883 |
checkGraphNodeMap(adaptor);
|
deba@430
|
884 |
checkGraphArcMap(adaptor);
|
deba@430
|
885 |
checkGraphEdgeMap(adaptor);
|
deba@430
|
886 |
}
|
deba@430
|
887 |
|
deba@432
|
888 |
void checkOrienter() {
|
deba@432
|
889 |
checkConcept<concepts::Digraph,
|
deba@432
|
890 |
Orienter<concepts::Graph, concepts::Graph::EdgeMap<bool> > >();
|
deba@430
|
891 |
|
deba@430
|
892 |
typedef ListGraph Graph;
|
deba@430
|
893 |
typedef ListGraph::EdgeMap<bool> DirMap;
|
deba@432
|
894 |
typedef Orienter<Graph> Adaptor;
|
deba@430
|
895 |
|
deba@430
|
896 |
Graph graph;
|
deba@430
|
897 |
DirMap dir(graph, true);
|
deba@430
|
898 |
Adaptor adaptor(graph, dir);
|
deba@430
|
899 |
|
deba@430
|
900 |
Graph::Node n1 = graph.addNode();
|
deba@430
|
901 |
Graph::Node n2 = graph.addNode();
|
deba@430
|
902 |
Graph::Node n3 = graph.addNode();
|
deba@430
|
903 |
|
deba@430
|
904 |
Graph::Edge e1 = graph.addEdge(n1, n2);
|
deba@430
|
905 |
Graph::Edge e2 = graph.addEdge(n1, n3);
|
deba@430
|
906 |
Graph::Edge e3 = graph.addEdge(n2, n3);
|
deba@432
|
907 |
|
deba@430
|
908 |
checkGraphNodeList(adaptor, 3);
|
deba@430
|
909 |
checkGraphArcList(adaptor, 3);
|
deba@430
|
910 |
checkGraphConArcList(adaptor, 3);
|
deba@432
|
911 |
|
deba@430
|
912 |
{
|
deba@430
|
913 |
dir[e1] = true;
|
deba@430
|
914 |
Adaptor::Node u = adaptor.source(e1);
|
deba@430
|
915 |
Adaptor::Node v = adaptor.target(e1);
|
deba@432
|
916 |
|
deba@430
|
917 |
dir[e1] = false;
|
deba@430
|
918 |
check (u == adaptor.target(e1), "Wrong dir");
|
deba@430
|
919 |
check (v == adaptor.source(e1), "Wrong dir");
|
deba@430
|
920 |
|
deba@430
|
921 |
check ((u == n1 && v == n2) || (u == n2 && v == n1), "Wrong dir");
|
deba@430
|
922 |
dir[e1] = n1 == u;
|
deba@430
|
923 |
}
|
deba@430
|
924 |
|
deba@430
|
925 |
{
|
deba@430
|
926 |
dir[e2] = true;
|
deba@430
|
927 |
Adaptor::Node u = adaptor.source(e2);
|
deba@430
|
928 |
Adaptor::Node v = adaptor.target(e2);
|
deba@432
|
929 |
|
deba@430
|
930 |
dir[e2] = false;
|
deba@430
|
931 |
check (u == adaptor.target(e2), "Wrong dir");
|
deba@430
|
932 |
check (v == adaptor.source(e2), "Wrong dir");
|
deba@430
|
933 |
|
deba@430
|
934 |
check ((u == n1 && v == n3) || (u == n3 && v == n1), "Wrong dir");
|
deba@430
|
935 |
dir[e2] = n3 == u;
|
deba@430
|
936 |
}
|
deba@430
|
937 |
|
deba@430
|
938 |
{
|
deba@430
|
939 |
dir[e3] = true;
|
deba@430
|
940 |
Adaptor::Node u = adaptor.source(e3);
|
deba@430
|
941 |
Adaptor::Node v = adaptor.target(e3);
|
deba@432
|
942 |
|
deba@430
|
943 |
dir[e3] = false;
|
deba@430
|
944 |
check (u == adaptor.target(e3), "Wrong dir");
|
deba@430
|
945 |
check (v == adaptor.source(e3), "Wrong dir");
|
deba@430
|
946 |
|
deba@430
|
947 |
check ((u == n2 && v == n3) || (u == n3 && v == n2), "Wrong dir");
|
deba@430
|
948 |
dir[e3] = n2 == u;
|
deba@430
|
949 |
}
|
deba@430
|
950 |
|
deba@430
|
951 |
checkGraphOutArcList(adaptor, n1, 1);
|
deba@430
|
952 |
checkGraphOutArcList(adaptor, n2, 1);
|
deba@430
|
953 |
checkGraphOutArcList(adaptor, n3, 1);
|
deba@430
|
954 |
|
deba@430
|
955 |
checkGraphInArcList(adaptor, n1, 1);
|
deba@430
|
956 |
checkGraphInArcList(adaptor, n2, 1);
|
deba@430
|
957 |
checkGraphInArcList(adaptor, n3, 1);
|
deba@430
|
958 |
|
deba@430
|
959 |
checkNodeIds(adaptor);
|
deba@430
|
960 |
checkArcIds(adaptor);
|
deba@430
|
961 |
|
deba@430
|
962 |
checkGraphNodeMap(adaptor);
|
deba@430
|
963 |
checkGraphArcMap(adaptor);
|
deba@430
|
964 |
|
deba@430
|
965 |
}
|
deba@430
|
966 |
|
deba@430
|
967 |
|
deba@430
|
968 |
int main(int, const char **) {
|
deba@430
|
969 |
|
deba@432
|
970 |
checkReverseDigraph();
|
deba@432
|
971 |
checkSubDigraph();
|
deba@432
|
972 |
checkFilterNodes1();
|
deba@432
|
973 |
checkFilterArcs();
|
deba@432
|
974 |
checkUndirector();
|
deba@432
|
975 |
checkResidual();
|
deba@432
|
976 |
checkSplitNodes();
|
deba@430
|
977 |
|
deba@432
|
978 |
checkSubGraph();
|
deba@432
|
979 |
checkFilterNodes2();
|
deba@432
|
980 |
checkFilterEdges();
|
deba@432
|
981 |
checkOrienter();
|
deba@430
|
982 |
|
deba@430
|
983 |
return 0;
|
deba@430
|
984 |
}
|