0
33
0
35
35
89
88
76
75
16
16
31
31
27
25
23
23
35
35
30
31
14
14
16
15
10
10
Changeset was too big and was cut off... Show full diff
... | ... |
@@ -7,33 +7,33 @@ |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
namespace lemon { |
20 | 20 |
|
21 | 21 |
/** |
22 | 22 |
@defgroup datas Data Structures |
23 |
This group |
|
23 |
This group contains the several data structures implemented in LEMON. |
|
24 | 24 |
*/ |
25 | 25 |
|
26 | 26 |
/** |
27 | 27 |
@defgroup graphs Graph Structures |
28 | 28 |
@ingroup datas |
29 | 29 |
\brief Graph structures implemented in LEMON. |
30 | 30 |
|
31 | 31 |
The implementation of combinatorial algorithms heavily relies on |
32 | 32 |
efficient graph implementations. LEMON offers data structures which are |
33 | 33 |
planned to be easily used in an experimental phase of implementation studies, |
34 | 34 |
and thereafter the program code can be made efficient by small modifications. |
35 | 35 |
|
36 | 36 |
The most efficient implementation of diverse applications require the |
37 | 37 |
usage of different physical graph implementations. These differences |
38 | 38 |
appear in the size of graph we require to handle, memory or time usage |
39 | 39 |
limitations or in the set of operations through which the graph can be |
... | ... |
@@ -129,68 +129,68 @@ |
129 | 129 |
This means that in a situation, when a <tt>const %ListDigraph&</tt> |
130 | 130 |
reference to a graph is given, then it have to be instantiated with |
131 | 131 |
<tt>Digraph=const %ListDigraph</tt>. |
132 | 132 |
\code |
133 | 133 |
int algorithm1(const ListDigraph& g) { |
134 | 134 |
ReverseDigraph<const ListDigraph> rg(g); |
135 | 135 |
return algorithm2(rg); |
136 | 136 |
} |
137 | 137 |
\endcode |
138 | 138 |
*/ |
139 | 139 |
|
140 | 140 |
/** |
141 | 141 |
@defgroup semi_adaptors Semi-Adaptor Classes for Graphs |
142 | 142 |
@ingroup graphs |
143 | 143 |
\brief Graph types between real graphs and graph adaptors. |
144 | 144 |
|
145 |
This group |
|
145 |
This group contains some graph types between real graphs and graph adaptors. |
|
146 | 146 |
These classes wrap graphs to give new functionality as the adaptors do it. |
147 | 147 |
On the other hand they are not light-weight structures as the adaptors. |
148 | 148 |
*/ |
149 | 149 |
|
150 | 150 |
/** |
151 | 151 |
@defgroup maps Maps |
152 | 152 |
@ingroup datas |
153 | 153 |
\brief Map structures implemented in LEMON. |
154 | 154 |
|
155 |
This group |
|
155 |
This group contains the map structures implemented in LEMON. |
|
156 | 156 |
|
157 | 157 |
LEMON provides several special purpose maps and map adaptors that e.g. combine |
158 | 158 |
new maps from existing ones. |
159 | 159 |
|
160 | 160 |
<b>See also:</b> \ref map_concepts "Map Concepts". |
161 | 161 |
*/ |
162 | 162 |
|
163 | 163 |
/** |
164 | 164 |
@defgroup graph_maps Graph Maps |
165 | 165 |
@ingroup maps |
166 | 166 |
\brief Special graph-related maps. |
167 | 167 |
|
168 |
This group |
|
168 |
This group contains maps that are specifically designed to assign |
|
169 | 169 |
values to the nodes and arcs/edges of graphs. |
170 | 170 |
|
171 | 171 |
If you are looking for the standard graph maps (\c NodeMap, \c ArcMap, |
172 | 172 |
\c EdgeMap), see the \ref graph_concepts "Graph Structure Concepts". |
173 | 173 |
*/ |
174 | 174 |
|
175 | 175 |
/** |
176 | 176 |
\defgroup map_adaptors Map Adaptors |
177 | 177 |
\ingroup maps |
178 | 178 |
\brief Tools to create new maps from existing ones |
179 | 179 |
|
180 |
This group |
|
180 |
This group contains map adaptors that are used to create "implicit" |
|
181 | 181 |
maps from other maps. |
182 | 182 |
|
183 | 183 |
Most of them are \ref concepts::ReadMap "read-only maps". |
184 | 184 |
They can make arithmetic and logical operations between one or two maps |
185 | 185 |
(negation, shifting, addition, multiplication, logical 'and', 'or', |
186 | 186 |
'not' etc.) or e.g. convert a map to another one of different Value type. |
187 | 187 |
|
188 | 188 |
The typical usage of this classes is passing implicit maps to |
189 | 189 |
algorithms. If a function type algorithm is called then the function |
190 | 190 |
type map adaptors can be used comfortable. For example let's see the |
191 | 191 |
usage of map adaptors with the \c graphToEps() function. |
192 | 192 |
\code |
193 | 193 |
Color nodeColor(int deg) { |
194 | 194 |
if (deg >= 2) { |
195 | 195 |
return Color(0.5, 0.0, 0.5); |
196 | 196 |
} else if (deg == 1) { |
... | ... |
@@ -227,138 +227,138 @@ |
227 | 227 |
|
228 | 228 |
Dijkstra<Digraph, TimeMap> dijkstra(graph, time); |
229 | 229 |
dijkstra.run(source, target); |
230 | 230 |
\endcode |
231 | 231 |
We have a length map and a maximum speed map on the arcs of a digraph. |
232 | 232 |
The minimum time to pass the arc can be calculated as the division of |
233 | 233 |
the two maps which can be done implicitly with the \c DivMap template |
234 | 234 |
class. We use the implicit minimum time map as the length map of the |
235 | 235 |
\c Dijkstra algorithm. |
236 | 236 |
*/ |
237 | 237 |
|
238 | 238 |
/** |
239 | 239 |
@defgroup matrices Matrices |
240 | 240 |
@ingroup datas |
241 | 241 |
\brief Two dimensional data storages implemented in LEMON. |
242 | 242 |
|
243 |
This group |
|
243 |
This group contains two dimensional data storages implemented in LEMON. |
|
244 | 244 |
*/ |
245 | 245 |
|
246 | 246 |
/** |
247 | 247 |
@defgroup paths Path Structures |
248 | 248 |
@ingroup datas |
249 | 249 |
\brief %Path structures implemented in LEMON. |
250 | 250 |
|
251 |
This group |
|
251 |
This group contains the path structures implemented in LEMON. |
|
252 | 252 |
|
253 | 253 |
LEMON provides flexible data structures to work with paths. |
254 | 254 |
All of them have similar interfaces and they can be copied easily with |
255 | 255 |
assignment operators and copy constructors. This makes it easy and |
256 | 256 |
efficient to have e.g. the Dijkstra algorithm to store its result in |
257 | 257 |
any kind of path structure. |
258 | 258 |
|
259 | 259 |
\sa lemon::concepts::Path |
260 | 260 |
*/ |
261 | 261 |
|
262 | 262 |
/** |
263 | 263 |
@defgroup auxdat Auxiliary Data Structures |
264 | 264 |
@ingroup datas |
265 | 265 |
\brief Auxiliary data structures implemented in LEMON. |
266 | 266 |
|
267 |
This group |
|
267 |
This group contains some data structures implemented in LEMON in |
|
268 | 268 |
order to make it easier to implement combinatorial algorithms. |
269 | 269 |
*/ |
270 | 270 |
|
271 | 271 |
/** |
272 | 272 |
@defgroup algs Algorithms |
273 |
\brief This group |
|
273 |
\brief This group contains the several algorithms |
|
274 | 274 |
implemented in LEMON. |
275 | 275 |
|
276 |
This group |
|
276 |
This group contains the several algorithms |
|
277 | 277 |
implemented in LEMON. |
278 | 278 |
*/ |
279 | 279 |
|
280 | 280 |
/** |
281 | 281 |
@defgroup search Graph Search |
282 | 282 |
@ingroup algs |
283 | 283 |
\brief Common graph search algorithms. |
284 | 284 |
|
285 |
This group |
|
285 |
This group contains the common graph search algorithms, namely |
|
286 | 286 |
\e breadth-first \e search (BFS) and \e depth-first \e search (DFS). |
287 | 287 |
*/ |
288 | 288 |
|
289 | 289 |
/** |
290 | 290 |
@defgroup shortest_path Shortest Path Algorithms |
291 | 291 |
@ingroup algs |
292 | 292 |
\brief Algorithms for finding shortest paths. |
293 | 293 |
|
294 |
This group |
|
294 |
This group contains the algorithms for finding shortest paths in digraphs. |
|
295 | 295 |
|
296 | 296 |
- \ref Dijkstra algorithm for finding shortest paths from a source node |
297 | 297 |
when all arc lengths are non-negative. |
298 | 298 |
- \ref BellmanFord "Bellman-Ford" algorithm for finding shortest paths |
299 | 299 |
from a source node when arc lenghts can be either positive or negative, |
300 | 300 |
but the digraph should not contain directed cycles with negative total |
301 | 301 |
length. |
302 | 302 |
- \ref FloydWarshall "Floyd-Warshall" and \ref Johnson "Johnson" algorithms |
303 | 303 |
for solving the \e all-pairs \e shortest \e paths \e problem when arc |
304 | 304 |
lenghts can be either positive or negative, but the digraph should |
305 | 305 |
not contain directed cycles with negative total length. |
306 | 306 |
- \ref Suurballe A successive shortest path algorithm for finding |
307 | 307 |
arc-disjoint paths between two nodes having minimum total length. |
308 | 308 |
*/ |
309 | 309 |
|
310 | 310 |
/** |
311 | 311 |
@defgroup max_flow Maximum Flow Algorithms |
312 | 312 |
@ingroup algs |
313 | 313 |
\brief Algorithms for finding maximum flows. |
314 | 314 |
|
315 |
This group |
|
315 |
This group contains the algorithms for finding maximum flows and |
|
316 | 316 |
feasible circulations. |
317 | 317 |
|
318 | 318 |
The \e maximum \e flow \e problem is to find a flow of maximum value between |
319 | 319 |
a single source and a single target. Formally, there is a \f$G=(V,A)\f$ |
320 | 320 |
digraph, a \f$cap:A\rightarrow\mathbf{R}^+_0\f$ capacity function and |
321 | 321 |
\f$s, t \in V\f$ source and target nodes. |
322 | 322 |
A maximum flow is an \f$f:A\rightarrow\mathbf{R}^+_0\f$ solution of the |
323 | 323 |
following optimization problem. |
324 | 324 |
|
325 | 325 |
\f[ \max\sum_{a\in\delta_{out}(s)}f(a) - \sum_{a\in\delta_{in}(s)}f(a) \f] |
326 | 326 |
\f[ \sum_{a\in\delta_{out}(v)} f(a) = \sum_{a\in\delta_{in}(v)} f(a) |
327 | 327 |
\qquad \forall v\in V\setminus\{s,t\} \f] |
328 | 328 |
\f[ 0 \leq f(a) \leq cap(a) \qquad \forall a\in A \f] |
329 | 329 |
|
330 | 330 |
LEMON contains several algorithms for solving maximum flow problems: |
331 | 331 |
- \ref EdmondsKarp Edmonds-Karp algorithm. |
332 | 332 |
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm. |
333 | 333 |
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees. |
334 | 334 |
- \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees. |
335 | 335 |
|
336 | 336 |
In most cases the \ref Preflow "Preflow" algorithm provides the |
337 | 337 |
fastest method for computing a maximum flow. All implementations |
338 | 338 |
provides functions to also query the minimum cut, which is the dual |
339 | 339 |
problem of the maximum flow. |
340 | 340 |
*/ |
341 | 341 |
|
342 | 342 |
/** |
343 | 343 |
@defgroup min_cost_flow Minimum Cost Flow Algorithms |
344 | 344 |
@ingroup algs |
345 | 345 |
|
346 | 346 |
\brief Algorithms for finding minimum cost flows and circulations. |
347 | 347 |
|
348 |
This group |
|
348 |
This group contains the algorithms for finding minimum cost flows and |
|
349 | 349 |
circulations. |
350 | 350 |
|
351 | 351 |
The \e minimum \e cost \e flow \e problem is to find a feasible flow of |
352 | 352 |
minimum total cost from a set of supply nodes to a set of demand nodes |
353 | 353 |
in a network with capacity constraints and arc costs. |
354 | 354 |
Formally, let \f$G=(V,A)\f$ be a digraph, |
355 | 355 |
\f$lower, upper: A\rightarrow\mathbf{Z}^+_0\f$ denote the lower and |
356 | 356 |
upper bounds for the flow values on the arcs, |
357 | 357 |
\f$cost: A\rightarrow\mathbf{Z}^+_0\f$ denotes the cost per unit flow |
358 | 358 |
on the arcs, and |
359 | 359 |
\f$supply: V\rightarrow\mathbf{Z}\f$ denotes the supply/demand values |
360 | 360 |
of the nodes. |
361 | 361 |
A minimum cost flow is an \f$f:A\rightarrow\mathbf{R}^+_0\f$ solution of |
362 | 362 |
the following optimization problem. |
363 | 363 |
|
364 | 364 |
\f[ \min\sum_{a\in A} f(a) cost(a) \f] |
... | ... |
@@ -369,74 +369,74 @@ |
369 | 369 |
LEMON contains several algorithms for solving minimum cost flow problems: |
370 | 370 |
- \ref CycleCanceling Cycle-canceling algorithms. |
371 | 371 |
- \ref CapacityScaling Successive shortest path algorithm with optional |
372 | 372 |
capacity scaling. |
373 | 373 |
- \ref CostScaling Push-relabel and augment-relabel algorithms based on |
374 | 374 |
cost scaling. |
375 | 375 |
- \ref NetworkSimplex Primal network simplex algorithm with various |
376 | 376 |
pivot strategies. |
377 | 377 |
*/ |
378 | 378 |
|
379 | 379 |
/** |
380 | 380 |
@defgroup min_cut Minimum Cut Algorithms |
381 | 381 |
@ingroup algs |
382 | 382 |
|
383 | 383 |
\brief Algorithms for finding minimum cut in graphs. |
384 | 384 |
|
385 |
This group |
|
385 |
This group contains the algorithms for finding minimum cut in graphs. |
|
386 | 386 |
|
387 | 387 |
The \e minimum \e cut \e problem is to find a non-empty and non-complete |
388 | 388 |
\f$X\f$ subset of the nodes with minimum overall capacity on |
389 | 389 |
outgoing arcs. Formally, there is a \f$G=(V,A)\f$ digraph, a |
390 | 390 |
\f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function. The minimum |
391 | 391 |
cut is the \f$X\f$ solution of the next optimization problem: |
392 | 392 |
|
393 | 393 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}} |
394 | 394 |
\sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f] |
395 | 395 |
|
396 | 396 |
LEMON contains several algorithms related to minimum cut problems: |
397 | 397 |
|
398 | 398 |
- \ref HaoOrlin "Hao-Orlin algorithm" for calculating minimum cut |
399 | 399 |
in directed graphs. |
400 | 400 |
- \ref NagamochiIbaraki "Nagamochi-Ibaraki algorithm" for |
401 | 401 |
calculating minimum cut in undirected graphs. |
402 |
- \ref |
|
402 |
- \ref GomoryHu "Gomory-Hu tree computation" for calculating |
|
403 | 403 |
all-pairs minimum cut in undirected graphs. |
404 | 404 |
|
405 | 405 |
If you want to find minimum cut just between two distinict nodes, |
406 | 406 |
see the \ref max_flow "maximum flow problem". |
407 | 407 |
*/ |
408 | 408 |
|
409 | 409 |
/** |
410 | 410 |
@defgroup graph_prop Connectivity and Other Graph Properties |
411 | 411 |
@ingroup algs |
412 | 412 |
\brief Algorithms for discovering the graph properties |
413 | 413 |
|
414 |
This group |
|
414 |
This group contains the algorithms for discovering the graph properties |
|
415 | 415 |
like connectivity, bipartiteness, euler property, simplicity etc. |
416 | 416 |
|
417 | 417 |
\image html edge_biconnected_components.png |
418 | 418 |
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth |
419 | 419 |
*/ |
420 | 420 |
|
421 | 421 |
/** |
422 | 422 |
@defgroup planar Planarity Embedding and Drawing |
423 | 423 |
@ingroup algs |
424 | 424 |
\brief Algorithms for planarity checking, embedding and drawing |
425 | 425 |
|
426 |
This group |
|
426 |
This group contains the algorithms for planarity checking, |
|
427 | 427 |
embedding and drawing. |
428 | 428 |
|
429 | 429 |
\image html planar.png |
430 | 430 |
\image latex planar.eps "Plane graph" width=\textwidth |
431 | 431 |
*/ |
432 | 432 |
|
433 | 433 |
/** |
434 | 434 |
@defgroup matching Matching Algorithms |
435 | 435 |
@ingroup algs |
436 | 436 |
\brief Algorithms for finding matchings in graphs and bipartite graphs. |
437 | 437 |
|
438 | 438 |
This group contains algorithm objects and functions to calculate |
439 | 439 |
matchings in graphs and bipartite graphs. The general matching problem is |
440 | 440 |
finding a subset of the arcs which does not shares common endpoints. |
441 | 441 |
|
442 | 442 |
There are several different algorithms for calculate matchings in |
... | ... |
@@ -461,219 +461,219 @@ |
461 | 461 |
maximum cardinality matching in general graphs. |
462 | 462 |
- \ref MaxWeightedMatching Edmond's blossom shrinking algorithm for calculating |
463 | 463 |
maximum weighted matching in general graphs. |
464 | 464 |
- \ref MaxWeightedPerfectMatching |
465 | 465 |
Edmond's blossom shrinking algorithm for calculating maximum weighted |
466 | 466 |
perfect matching in general graphs. |
467 | 467 |
|
468 | 468 |
\image html bipartite_matching.png |
469 | 469 |
\image latex bipartite_matching.eps "Bipartite Matching" width=\textwidth |
470 | 470 |
*/ |
471 | 471 |
|
472 | 472 |
/** |
473 | 473 |
@defgroup spantree Minimum Spanning Tree Algorithms |
474 | 474 |
@ingroup algs |
475 | 475 |
\brief Algorithms for finding a minimum cost spanning tree in a graph. |
476 | 476 |
|
477 |
This group |
|
477 |
This group contains the algorithms for finding a minimum cost spanning |
|
478 | 478 |
tree in a graph. |
479 | 479 |
*/ |
480 | 480 |
|
481 | 481 |
/** |
482 | 482 |
@defgroup auxalg Auxiliary Algorithms |
483 | 483 |
@ingroup algs |
484 | 484 |
\brief Auxiliary algorithms implemented in LEMON. |
485 | 485 |
|
486 |
This group |
|
486 |
This group contains some algorithms implemented in LEMON |
|
487 | 487 |
in order to make it easier to implement complex algorithms. |
488 | 488 |
*/ |
489 | 489 |
|
490 | 490 |
/** |
491 | 491 |
@defgroup approx Approximation Algorithms |
492 | 492 |
@ingroup algs |
493 | 493 |
\brief Approximation algorithms. |
494 | 494 |
|
495 |
This group |
|
495 |
This group contains the approximation and heuristic algorithms |
|
496 | 496 |
implemented in LEMON. |
497 | 497 |
*/ |
498 | 498 |
|
499 | 499 |
/** |
500 | 500 |
@defgroup gen_opt_group General Optimization Tools |
501 |
\brief This group |
|
501 |
\brief This group contains some general optimization frameworks |
|
502 | 502 |
implemented in LEMON. |
503 | 503 |
|
504 |
This group |
|
504 |
This group contains some general optimization frameworks |
|
505 | 505 |
implemented in LEMON. |
506 | 506 |
*/ |
507 | 507 |
|
508 | 508 |
/** |
509 | 509 |
@defgroup lp_group Lp and Mip Solvers |
510 | 510 |
@ingroup gen_opt_group |
511 | 511 |
\brief Lp and Mip solver interfaces for LEMON. |
512 | 512 |
|
513 |
This group |
|
513 |
This group contains Lp and Mip solver interfaces for LEMON. The |
|
514 | 514 |
various LP solvers could be used in the same manner with this |
515 | 515 |
interface. |
516 | 516 |
*/ |
517 | 517 |
|
518 | 518 |
/** |
519 | 519 |
@defgroup lp_utils Tools for Lp and Mip Solvers |
520 | 520 |
@ingroup lp_group |
521 | 521 |
\brief Helper tools to the Lp and Mip solvers. |
522 | 522 |
|
523 | 523 |
This group adds some helper tools to general optimization framework |
524 | 524 |
implemented in LEMON. |
525 | 525 |
*/ |
526 | 526 |
|
527 | 527 |
/** |
528 | 528 |
@defgroup metah Metaheuristics |
529 | 529 |
@ingroup gen_opt_group |
530 | 530 |
\brief Metaheuristics for LEMON library. |
531 | 531 |
|
532 |
This group |
|
532 |
This group contains some metaheuristic optimization tools. |
|
533 | 533 |
*/ |
534 | 534 |
|
535 | 535 |
/** |
536 | 536 |
@defgroup utils Tools and Utilities |
537 | 537 |
\brief Tools and utilities for programming in LEMON |
538 | 538 |
|
539 | 539 |
Tools and utilities for programming in LEMON. |
540 | 540 |
*/ |
541 | 541 |
|
542 | 542 |
/** |
543 | 543 |
@defgroup gutils Basic Graph Utilities |
544 | 544 |
@ingroup utils |
545 | 545 |
\brief Simple basic graph utilities. |
546 | 546 |
|
547 |
This group |
|
547 |
This group contains some simple basic graph utilities. |
|
548 | 548 |
*/ |
549 | 549 |
|
550 | 550 |
/** |
551 | 551 |
@defgroup misc Miscellaneous Tools |
552 | 552 |
@ingroup utils |
553 | 553 |
\brief Tools for development, debugging and testing. |
554 | 554 |
|
555 |
This group |
|
555 |
This group contains several useful tools for development, |
|
556 | 556 |
debugging and testing. |
557 | 557 |
*/ |
558 | 558 |
|
559 | 559 |
/** |
560 | 560 |
@defgroup timecount Time Measuring and Counting |
561 | 561 |
@ingroup misc |
562 | 562 |
\brief Simple tools for measuring the performance of algorithms. |
563 | 563 |
|
564 |
This group |
|
564 |
This group contains simple tools for measuring the performance |
|
565 | 565 |
of algorithms. |
566 | 566 |
*/ |
567 | 567 |
|
568 | 568 |
/** |
569 | 569 |
@defgroup exceptions Exceptions |
570 | 570 |
@ingroup utils |
571 | 571 |
\brief Exceptions defined in LEMON. |
572 | 572 |
|
573 |
This group |
|
573 |
This group contains the exceptions defined in LEMON. |
|
574 | 574 |
*/ |
575 | 575 |
|
576 | 576 |
/** |
577 | 577 |
@defgroup io_group Input-Output |
578 | 578 |
\brief Graph Input-Output methods |
579 | 579 |
|
580 |
This group |
|
580 |
This group contains the tools for importing and exporting graphs |
|
581 | 581 |
and graph related data. Now it supports the \ref lgf-format |
582 | 582 |
"LEMON Graph Format", the \c DIMACS format and the encapsulated |
583 | 583 |
postscript (EPS) format. |
584 | 584 |
*/ |
585 | 585 |
|
586 | 586 |
/** |
587 | 587 |
@defgroup lemon_io LEMON Graph Format |
588 | 588 |
@ingroup io_group |
589 | 589 |
\brief Reading and writing LEMON Graph Format. |
590 | 590 |
|
591 |
This group |
|
591 |
This group contains methods for reading and writing |
|
592 | 592 |
\ref lgf-format "LEMON Graph Format". |
593 | 593 |
*/ |
594 | 594 |
|
595 | 595 |
/** |
596 | 596 |
@defgroup eps_io Postscript Exporting |
597 | 597 |
@ingroup io_group |
598 | 598 |
\brief General \c EPS drawer and graph exporter |
599 | 599 |
|
600 |
This group |
|
600 |
This group contains general \c EPS drawing methods and special |
|
601 | 601 |
graph exporting tools. |
602 | 602 |
*/ |
603 | 603 |
|
604 | 604 |
/** |
605 | 605 |
@defgroup dimacs_group DIMACS format |
606 | 606 |
@ingroup io_group |
607 | 607 |
\brief Read and write files in DIMACS format |
608 | 608 |
|
609 | 609 |
Tools to read a digraph from or write it to a file in DIMACS format data. |
610 | 610 |
*/ |
611 | 611 |
|
612 | 612 |
/** |
613 | 613 |
@defgroup nauty_group NAUTY Format |
614 | 614 |
@ingroup io_group |
615 | 615 |
\brief Read \e Nauty format |
616 | 616 |
|
617 | 617 |
Tool to read graphs from \e Nauty format data. |
618 | 618 |
*/ |
619 | 619 |
|
620 | 620 |
/** |
621 | 621 |
@defgroup concept Concepts |
622 | 622 |
\brief Skeleton classes and concept checking classes |
623 | 623 |
|
624 |
This group |
|
624 |
This group contains the data/algorithm skeletons and concept checking |
|
625 | 625 |
classes implemented in LEMON. |
626 | 626 |
|
627 | 627 |
The purpose of the classes in this group is fourfold. |
628 | 628 |
|
629 | 629 |
- These classes contain the documentations of the %concepts. In order |
630 | 630 |
to avoid document multiplications, an implementation of a concept |
631 | 631 |
simply refers to the corresponding concept class. |
632 | 632 |
|
633 | 633 |
- These classes declare every functions, <tt>typedef</tt>s etc. an |
634 | 634 |
implementation of the %concepts should provide, however completely |
635 | 635 |
without implementations and real data structures behind the |
636 | 636 |
interface. On the other hand they should provide nothing else. All |
637 | 637 |
the algorithms working on a data structure meeting a certain concept |
638 | 638 |
should compile with these classes. (Though it will not run properly, |
639 | 639 |
of course.) In this way it is easily to check if an algorithm |
640 | 640 |
doesn't use any extra feature of a certain implementation. |
641 | 641 |
|
642 | 642 |
- The concept descriptor classes also provide a <em>checker class</em> |
643 | 643 |
that makes it possible to check whether a certain implementation of a |
644 | 644 |
concept indeed provides all the required features. |
645 | 645 |
|
646 | 646 |
- Finally, They can serve as a skeleton of a new implementation of a concept. |
647 | 647 |
*/ |
648 | 648 |
|
649 | 649 |
/** |
650 | 650 |
@defgroup graph_concepts Graph Structure Concepts |
651 | 651 |
@ingroup concept |
652 | 652 |
\brief Skeleton and concept checking classes for graph structures |
653 | 653 |
|
654 |
This group |
|
654 |
This group contains the skeletons and concept checking classes of LEMON's |
|
655 | 655 |
graph structures and helper classes used to implement these. |
656 | 656 |
*/ |
657 | 657 |
|
658 | 658 |
/** |
659 | 659 |
@defgroup map_concepts Map Concepts |
660 | 660 |
@ingroup concept |
661 | 661 |
\brief Skeleton and concept checking classes for maps |
662 | 662 |
|
663 |
This group |
|
663 |
This group contains the skeletons and concept checking classes of maps. |
|
664 | 664 |
*/ |
665 | 665 |
|
666 | 666 |
/** |
667 | 667 |
\anchor demoprograms |
668 | 668 |
|
669 | 669 |
@defgroup demos Demo Programs |
670 | 670 |
|
671 | 671 |
Some demo programs are listed here. Their full source codes can be found in |
672 | 672 |
the \c demo subdirectory of the source tree. |
673 | 673 |
|
674 | 674 |
It order to compile them, use <tt>--enable-demo</tt> configure option when |
675 | 675 |
build the library. |
676 | 676 |
*/ |
677 | 677 |
|
678 | 678 |
/** |
679 | 679 |
@defgroup tools Standalone Utility Applications |
... | ... |
@@ -32,30 +32,25 @@ |
32 | 32 |
with graphs. |
33 | 33 |
|
34 | 34 |
<b> |
35 | 35 |
LEMON is an <a class="el" href="http://opensource.org/">open source</a> |
36 | 36 |
project. |
37 | 37 |
You are free to use it in your commercial or |
38 | 38 |
non-commercial applications under very permissive |
39 | 39 |
\ref license "license terms". |
40 | 40 |
</b> |
41 | 41 |
|
42 | 42 |
\subsection howtoread How to read the documentation |
43 | 43 |
|
44 | 44 |
If you want to get a quick start and see the most important features then |
45 | 45 |
take a look at our \ref quicktour |
46 | 46 |
"Quick Tour to LEMON" which will guide you along. |
47 | 47 |
|
48 |
If you already feel like using our library, see the page that tells you |
|
49 |
\ref getstart "How to start using LEMON". |
|
50 |
|
|
51 |
If you |
|
52 |
want to see how LEMON works, see |
|
53 |
some \ref demoprograms "demo programs". |
|
48 |
If you already feel like using our library, see the |
|
49 |
<a class="el" href="http://lemon.cs.elte.hu/pub/tutorial/">LEMON Tutorial</a>. |
|
54 | 50 |
|
55 | 51 |
If you know what you are looking for then try to find it under the |
56 |
<a class="el" href="modules.html">Modules</a> |
|
57 |
section. |
|
52 |
<a class="el" href="modules.html">Modules</a> section. |
|
58 | 53 |
|
59 | 54 |
If you are a user of the old (0.x) series of LEMON, please check out the |
60 | 55 |
\ref migration "Migration Guide" for the backward incompatibilities. |
61 | 56 |
*/ |
... | ... |
@@ -2241,116 +2241,114 @@ |
2241 | 2241 |
typedef GraphAdaptorExtender<UndirectorBase<DGR> > Parent; |
2242 | 2242 |
protected: |
2243 | 2243 |
Undirector() { } |
2244 | 2244 |
public: |
2245 | 2245 |
|
2246 | 2246 |
/// \brief Constructor |
2247 | 2247 |
/// |
2248 | 2248 |
/// Creates an undirected graph from the given digraph. |
2249 | 2249 |
Undirector(DGR& digraph) { |
2250 | 2250 |
initialize(digraph); |
2251 | 2251 |
} |
2252 | 2252 |
|
2253 | 2253 |
/// \brief Arc map combined from two original arc maps |
2254 | 2254 |
/// |
2255 | 2255 |
/// This map adaptor class adapts two arc maps of the underlying |
2256 | 2256 |
/// digraph to get an arc map of the undirected graph. |
2257 |
/// Its value type is inherited from the first arc map type |
|
2258 |
/// (\c %ForwardMap). |
|
2259 |
|
|
2257 |
/// Its value type is inherited from the first arc map type (\c FW). |
|
2258 |
/// \tparam FW The type of the "foward" arc map. |
|
2259 |
/// \tparam BK The type of the "backward" arc map. |
|
2260 |
template <typename FW, typename BK> |
|
2260 | 2261 |
class CombinedArcMap { |
2261 | 2262 |
public: |
2262 | 2263 |
|
2263 | 2264 |
/// The key type of the map |
2264 | 2265 |
typedef typename Parent::Arc Key; |
2265 | 2266 |
/// The value type of the map |
2266 |
typedef typename ForwardMap::Value Value; |
|
2267 |
|
|
2268 |
typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag; |
|
2269 |
|
|
2270 |
typedef typename MapTraits<ForwardMap>::ReturnValue ReturnValue; |
|
2271 |
typedef typename MapTraits<ForwardMap>::ConstReturnValue ConstReturnValue; |
|
2272 |
typedef typename MapTraits<ForwardMap>::ReturnValue Reference; |
|
2273 |
typedef typename MapTraits<ForwardMap>::ConstReturnValue ConstReference; |
|
2267 |
typedef typename FW::Value Value; |
|
2268 |
|
|
2269 |
typedef typename MapTraits<FW>::ReferenceMapTag ReferenceMapTag; |
|
2270 |
|
|
2271 |
typedef typename MapTraits<FW>::ReturnValue ReturnValue; |
|
2272 |
typedef typename MapTraits<FW>::ConstReturnValue ConstReturnValue; |
|
2273 |
typedef typename MapTraits<FW>::ReturnValue Reference; |
|
2274 |
typedef typename MapTraits<FW>::ConstReturnValue ConstReference; |
|
2274 | 2275 |
|
2275 | 2276 |
/// Constructor |
2276 |
CombinedArcMap( |
|
2277 |
CombinedArcMap(FW& forward, BK& backward) |
|
2277 | 2278 |
: _forward(&forward), _backward(&backward) {} |
2278 | 2279 |
|
2279 | 2280 |
/// Sets the value associated with the given key. |
2280 | 2281 |
void set(const Key& e, const Value& a) { |
2281 | 2282 |
if (Parent::direction(e)) { |
2282 | 2283 |
_forward->set(e, a); |
2283 | 2284 |
} else { |
2284 | 2285 |
_backward->set(e, a); |
2285 | 2286 |
} |
2286 | 2287 |
} |
2287 | 2288 |
|
2288 | 2289 |
/// Returns the value associated with the given key. |
2289 | 2290 |
ConstReturnValue operator[](const Key& e) const { |
2290 | 2291 |
if (Parent::direction(e)) { |
2291 | 2292 |
return (*_forward)[e]; |
2292 | 2293 |
} else { |
2293 | 2294 |
return (*_backward)[e]; |
2294 | 2295 |
} |
2295 | 2296 |
} |
2296 | 2297 |
|
2297 | 2298 |
/// Returns a reference to the value associated with the given key. |
2298 | 2299 |
ReturnValue operator[](const Key& e) { |
2299 | 2300 |
if (Parent::direction(e)) { |
2300 | 2301 |
return (*_forward)[e]; |
2301 | 2302 |
} else { |
2302 | 2303 |
return (*_backward)[e]; |
2303 | 2304 |
} |
2304 | 2305 |
} |
2305 | 2306 |
|
2306 | 2307 |
protected: |
2307 | 2308 |
|
2308 |
ForwardMap* _forward; |
|
2309 |
BackwardMap* _backward; |
|
2309 |
FW* _forward; |
|
2310 |
BK* _backward; |
|
2310 | 2311 |
|
2311 | 2312 |
}; |
2312 | 2313 |
|
2313 | 2314 |
/// \brief Returns a combined arc map |
2314 | 2315 |
/// |
2315 | 2316 |
/// This function just returns a combined arc map. |
2316 |
template <typename ForwardMap, typename BackwardMap> |
|
2317 |
static CombinedArcMap<ForwardMap, BackwardMap> |
|
2318 |
combinedArcMap(ForwardMap& forward, BackwardMap& backward) { |
|
2319 |
return CombinedArcMap<ForwardMap, BackwardMap>(forward, backward); |
|
2320 |
} |
|
2321 |
|
|
2322 |
template <typename ForwardMap, typename BackwardMap> |
|
2323 |
static CombinedArcMap<const ForwardMap, BackwardMap> |
|
2324 |
combinedArcMap(const ForwardMap& forward, BackwardMap& backward) { |
|
2325 |
return CombinedArcMap<const ForwardMap, |
|
2326 |
BackwardMap>(forward, backward); |
|
2327 |
} |
|
2328 |
|
|
2329 |
template <typename ForwardMap, typename BackwardMap> |
|
2330 |
static CombinedArcMap<ForwardMap, const BackwardMap> |
|
2331 |
combinedArcMap(ForwardMap& forward, const BackwardMap& backward) { |
|
2332 |
return CombinedArcMap<ForwardMap, |
|
2333 |
const BackwardMap>(forward, backward); |
|
2334 |
} |
|
2335 |
|
|
2336 |
template <typename ForwardMap, typename BackwardMap> |
|
2337 |
static CombinedArcMap<const ForwardMap, const BackwardMap> |
|
2338 |
combinedArcMap(const ForwardMap& forward, const BackwardMap& backward) { |
|
2339 |
return CombinedArcMap<const ForwardMap, |
|
2340 |
|
|
2317 |
template <typename FW, typename BK> |
|
2318 |
static CombinedArcMap<FW, BK> |
|
2319 |
combinedArcMap(FW& forward, BK& backward) { |
|
2320 |
return CombinedArcMap<FW, BK>(forward, backward); |
|
2321 |
} |
|
2322 |
|
|
2323 |
template <typename FW, typename BK> |
|
2324 |
static CombinedArcMap<const FW, BK> |
|
2325 |
combinedArcMap(const FW& forward, BK& backward) { |
|
2326 |
return CombinedArcMap<const FW, BK>(forward, backward); |
|
2327 |
} |
|
2328 |
|
|
2329 |
template <typename FW, typename BK> |
|
2330 |
static CombinedArcMap<FW, const BK> |
|
2331 |
combinedArcMap(FW& forward, const BK& backward) { |
|
2332 |
return CombinedArcMap<FW, const BK>(forward, backward); |
|
2333 |
} |
|
2334 |
|
|
2335 |
template <typename FW, typename BK> |
|
2336 |
static CombinedArcMap<const FW, const BK> |
|
2337 |
combinedArcMap(const FW& forward, const BK& backward) { |
|
2338 |
return CombinedArcMap<const FW, const BK>(forward, backward); |
|
2341 | 2339 |
} |
2342 | 2340 |
|
2343 | 2341 |
}; |
2344 | 2342 |
|
2345 | 2343 |
/// \brief Returns a read-only Undirector adaptor |
2346 | 2344 |
/// |
2347 | 2345 |
/// This function just returns a read-only \ref Undirector adaptor. |
2348 | 2346 |
/// \ingroup graph_adaptors |
2349 | 2347 |
/// \relates Undirector |
2350 | 2348 |
template<typename DGR> |
2351 | 2349 |
Undirector<const DGR> undirector(const DGR& digraph) { |
2352 | 2350 |
return Undirector<const DGR>(digraph); |
2353 | 2351 |
} |
2354 | 2352 |
|
2355 | 2353 |
|
2356 | 2354 |
template <typename GR, typename DM> |
... | ... |
@@ -3393,172 +3391,175 @@ |
3393 | 3391 |
static Arc arc(const DigraphNode& n) { |
3394 | 3392 |
return Parent::arc(n); |
3395 | 3393 |
} |
3396 | 3394 |
|
3397 | 3395 |
/// \brief Returns the arc that corresponds to the given original arc. |
3398 | 3396 |
/// |
3399 | 3397 |
/// Returns the arc in the adaptor that corresponds to the given |
3400 | 3398 |
/// original arc. |
3401 | 3399 |
static Arc arc(const DigraphArc& a) { |
3402 | 3400 |
return Parent::arc(a); |
3403 | 3401 |
} |
3404 | 3402 |
|
3405 | 3403 |
/// \brief Node map combined from two original node maps |
3406 | 3404 |
/// |
3407 | 3405 |
/// This map adaptor class adapts two node maps of the original digraph |
3408 | 3406 |
/// to get a node map of the split digraph. |
3409 |
/// Its value type is inherited from the first node map type |
|
3410 |
/// (\c InNodeMap). |
|
3411 |
|
|
3407 |
/// Its value type is inherited from the first node map type (\c IN). |
|
3408 |
/// \tparam IN The type of the node map for the in-nodes. |
|
3409 |
/// \tparam OUT The type of the node map for the out-nodes. |
|
3410 |
template <typename IN, typename OUT> |
|
3412 | 3411 |
class CombinedNodeMap { |
3413 | 3412 |
public: |
3414 | 3413 |
|
3415 | 3414 |
/// The key type of the map |
3416 | 3415 |
typedef Node Key; |
3417 | 3416 |
/// The value type of the map |
3418 |
typedef typename InNodeMap::Value Value; |
|
3419 |
|
|
3420 |
typedef typename MapTraits<InNodeMap>::ReferenceMapTag ReferenceMapTag; |
|
3421 |
typedef typename MapTraits<InNodeMap>::ReturnValue ReturnValue; |
|
3422 |
typedef typename MapTraits<InNodeMap>::ConstReturnValue ConstReturnValue; |
|
3423 |
typedef typename MapTraits<InNodeMap>::ReturnValue Reference; |
|
3424 |
typedef typename |
|
3417 |
typedef typename IN::Value Value; |
|
3418 |
|
|
3419 |
typedef typename MapTraits<IN>::ReferenceMapTag ReferenceMapTag; |
|
3420 |
typedef typename MapTraits<IN>::ReturnValue ReturnValue; |
|
3421 |
typedef typename MapTraits<IN>::ConstReturnValue ConstReturnValue; |
|
3422 |
typedef typename MapTraits<IN>::ReturnValue Reference; |
|
3423 |
typedef typename MapTraits<IN>::ConstReturnValue ConstReference; |
|
3425 | 3424 |
|
3426 | 3425 |
/// Constructor |
3427 |
CombinedNodeMap( |
|
3426 |
CombinedNodeMap(IN& in_map, OUT& out_map) |
|
3428 | 3427 |
: _in_map(in_map), _out_map(out_map) {} |
3429 | 3428 |
|
3430 | 3429 |
/// Returns the value associated with the given key. |
3431 | 3430 |
Value operator[](const Key& key) const { |
3432 | 3431 |
if (SplitNodesBase<const DGR>::inNode(key)) { |
3433 | 3432 |
return _in_map[key]; |
3434 | 3433 |
} else { |
3435 | 3434 |
return _out_map[key]; |
3436 | 3435 |
} |
3437 | 3436 |
} |
3438 | 3437 |
|
3439 | 3438 |
/// Returns a reference to the value associated with the given key. |
3440 | 3439 |
Value& operator[](const Key& key) { |
3441 | 3440 |
if (SplitNodesBase<const DGR>::inNode(key)) { |
3442 | 3441 |
return _in_map[key]; |
3443 | 3442 |
} else { |
3444 | 3443 |
return _out_map[key]; |
3445 | 3444 |
} |
3446 | 3445 |
} |
3447 | 3446 |
|
3448 | 3447 |
/// Sets the value associated with the given key. |
3449 | 3448 |
void set(const Key& key, const Value& value) { |
3450 | 3449 |
if (SplitNodesBase<const DGR>::inNode(key)) { |
3451 | 3450 |
_in_map.set(key, value); |
3452 | 3451 |
} else { |
3453 | 3452 |
_out_map.set(key, value); |
3454 | 3453 |
} |
3455 | 3454 |
} |
3456 | 3455 |
|
3457 | 3456 |
private: |
3458 | 3457 |
|
3459 |
InNodeMap& _in_map; |
|
3460 |
OutNodeMap& _out_map; |
|
3458 |
IN& _in_map; |
|
3459 |
OUT& _out_map; |
|
3461 | 3460 |
|
3462 | 3461 |
}; |
3463 | 3462 |
|
3464 | 3463 |
|
3465 | 3464 |
/// \brief Returns a combined node map |
3466 | 3465 |
/// |
3467 | 3466 |
/// This function just returns a combined node map. |
3468 |
template <typename InNodeMap, typename OutNodeMap> |
|
3469 |
static CombinedNodeMap<InNodeMap, OutNodeMap> |
|
3470 |
combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) { |
|
3471 |
return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map); |
|
3472 |
} |
|
3473 |
|
|
3474 |
template <typename InNodeMap, typename OutNodeMap> |
|
3475 |
static CombinedNodeMap<const InNodeMap, OutNodeMap> |
|
3476 |
combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) { |
|
3477 |
return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map); |
|
3478 |
} |
|
3479 |
|
|
3480 |
template <typename InNodeMap, typename OutNodeMap> |
|
3481 |
static CombinedNodeMap<InNodeMap, const OutNodeMap> |
|
3482 |
combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) { |
|
3483 |
return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map); |
|
3484 |
} |
|
3485 |
|
|
3486 |
template <typename InNodeMap, typename OutNodeMap> |
|
3487 |
static CombinedNodeMap<const InNodeMap, const OutNodeMap> |
|
3488 |
combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) { |
|
3489 |
return CombinedNodeMap<const InNodeMap, |
|
3490 |
|
|
3467 |
template <typename IN, typename OUT> |
|
3468 |
static CombinedNodeMap<IN, OUT> |
|
3469 |
combinedNodeMap(IN& in_map, OUT& out_map) { |
|
3470 |
return CombinedNodeMap<IN, OUT>(in_map, out_map); |
|
3471 |
} |
|
3472 |
|
|
3473 |
template <typename IN, typename OUT> |
|
3474 |
static CombinedNodeMap<const IN, OUT> |
|
3475 |
combinedNodeMap(const IN& in_map, OUT& out_map) { |
|
3476 |
return CombinedNodeMap<const IN, OUT>(in_map, out_map); |
|
3477 |
} |
|
3478 |
|
|
3479 |
template <typename IN, typename OUT> |
|
3480 |
static CombinedNodeMap<IN, const OUT> |
|
3481 |
combinedNodeMap(IN& in_map, const OUT& out_map) { |
|
3482 |
return CombinedNodeMap<IN, const OUT>(in_map, out_map); |
|
3483 |
} |
|
3484 |
|
|
3485 |
template <typename IN, typename OUT> |
|
3486 |
static CombinedNodeMap<const IN, const OUT> |
|
3487 |
combinedNodeMap(const IN& in_map, const OUT& out_map) { |
|
3488 |
return CombinedNodeMap<const IN, const OUT>(in_map, out_map); |
|
3491 | 3489 |
} |
3492 | 3490 |
|
3493 | 3491 |
/// \brief Arc map combined from an arc map and a node map of the |
3494 | 3492 |
/// original digraph. |
3495 | 3493 |
/// |
3496 | 3494 |
/// This map adaptor class adapts an arc map and a node map of the |
3497 | 3495 |
/// original digraph to get an arc map of the split digraph. |
3498 |
/// Its value type is inherited from the original arc map type |
|
3499 |
/// (\c ArcMap). |
|
3500 |
|
|
3496 |
/// Its value type is inherited from the original arc map type (\c AM). |
|
3497 |
/// \tparam AM The type of the arc map. |
|
3498 |
/// \tparam NM the type of the node map. |
|
3499 |
template <typename AM, typename NM> |
|
3501 | 3500 |
class CombinedArcMap { |
3502 | 3501 |
public: |
3503 | 3502 |
|
3504 | 3503 |
/// The key type of the map |
3505 | 3504 |
typedef Arc Key; |
3506 | 3505 |
/// The value type of the map |
3507 |
typedef typename ArcMap::Value Value; |
|
3508 |
|
|
3509 |
typedef typename MapTraits<ArcMap>::ReferenceMapTag ReferenceMapTag; |
|
3510 |
typedef typename MapTraits<ArcMap>::ReturnValue ReturnValue; |
|
3511 |
typedef typename MapTraits<ArcMap>::ConstReturnValue ConstReturnValue; |
|
3512 |
typedef typename MapTraits<ArcMap>::ReturnValue Reference; |
|
3513 |
typedef typename |
|
3506 |
typedef typename AM::Value Value; |
|
3507 |
|
|
3508 |
typedef typename MapTraits<AM>::ReferenceMapTag ReferenceMapTag; |
|
3509 |
typedef typename MapTraits<AM>::ReturnValue ReturnValue; |
|
3510 |
typedef typename MapTraits<AM>::ConstReturnValue ConstReturnValue; |
|
3511 |
typedef typename MapTraits<AM>::ReturnValue Reference; |
|
3512 |
typedef typename MapTraits<AM>::ConstReturnValue ConstReference; |
|
3514 | 3513 |
|
3515 | 3514 |
/// Constructor |
3516 |
CombinedArcMap( |
|
3515 |
CombinedArcMap(AM& arc_map, NM& node_map) |
|
3517 | 3516 |
: _arc_map(arc_map), _node_map(node_map) {} |
3518 | 3517 |
|
3519 | 3518 |
/// Returns the value associated with the given key. |
3520 | 3519 |
Value operator[](const Key& arc) const { |
3521 | 3520 |
if (SplitNodesBase<const DGR>::origArc(arc)) { |
3522 | 3521 |
return _arc_map[arc]; |
3523 | 3522 |
} else { |
3524 | 3523 |
return _node_map[arc]; |
3525 | 3524 |
} |
3526 | 3525 |
} |
3527 | 3526 |
|
3528 | 3527 |
/// Returns a reference to the value associated with the given key. |
3529 | 3528 |
Value& operator[](const Key& arc) { |
3530 | 3529 |
if (SplitNodesBase<const DGR>::origArc(arc)) { |
3531 | 3530 |
return _arc_map[arc]; |
3532 | 3531 |
} else { |
3533 | 3532 |
return _node_map[arc]; |
3534 | 3533 |
} |
3535 | 3534 |
} |
3536 | 3535 |
|
3537 | 3536 |
/// Sets the value associated with the given key. |
3538 | 3537 |
void set(const Arc& arc, const Value& val) { |
3539 | 3538 |
if (SplitNodesBase<const DGR>::origArc(arc)) { |
3540 | 3539 |
_arc_map.set(arc, val); |
3541 | 3540 |
} else { |
3542 | 3541 |
_node_map.set(arc, val); |
3543 | 3542 |
} |
3544 | 3543 |
} |
3545 | 3544 |
|
3546 | 3545 |
private: |
3547 |
ArcMap& _arc_map; |
|
3548 |
NodeMap& _node_map; |
|
3546 |
|
|
3547 |
AM& _arc_map; |
|
3548 |
NM& _node_map; |
|
3549 |
|
|
3549 | 3550 |
}; |
3550 | 3551 |
|
3551 | 3552 |
/// \brief Returns a combined arc map |
3552 | 3553 |
/// |
3553 | 3554 |
/// This function just returns a combined arc map. |
3554 | 3555 |
template <typename ArcMap, typename NodeMap> |
3555 | 3556 |
static CombinedArcMap<ArcMap, NodeMap> |
3556 | 3557 |
combinedArcMap(ArcMap& arc_map, NodeMap& node_map) { |
3557 | 3558 |
return CombinedArcMap<ArcMap, NodeMap>(arc_map, node_map); |
3558 | 3559 |
} |
3559 | 3560 |
|
3560 | 3561 |
template <typename ArcMap, typename NodeMap> |
3561 | 3562 |
static CombinedArcMap<const ArcMap, NodeMap> |
3562 | 3563 |
combinedArcMap(const ArcMap& arc_map, NodeMap& node_map) { |
3563 | 3564 |
return CombinedArcMap<const ArcMap, NodeMap>(arc_map, node_map); |
3564 | 3565 |
} |
... | ... |
@@ -20,327 +20,328 @@ |
20 | 20 |
#define LEMON_BIN_HEAP_H |
21 | 21 |
|
22 | 22 |
///\ingroup auxdat |
23 | 23 |
///\file |
24 | 24 |
///\brief Binary Heap implementation. |
25 | 25 |
|
26 | 26 |
#include <vector> |
27 | 27 |
#include <utility> |
28 | 28 |
#include <functional> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
|
32 | 32 |
///\ingroup auxdat |
33 | 33 |
/// |
34 | 34 |
///\brief A Binary Heap implementation. |
35 | 35 |
/// |
36 |
///This class implements the \e binary \e heap data structure. A \e heap |
|
37 |
///is a data structure for storing items with specified values called \e |
|
38 |
///priorities in such a way that finding the item with minimum priority is |
|
39 |
///efficient. \c Compare specifies the ordering of the priorities. In a heap |
|
40 |
/// |
|
36 |
///This class implements the \e binary \e heap data structure. |
|
41 | 37 |
/// |
42 |
///\tparam _Prio Type of the priority of the items. |
|
43 |
///\tparam _ItemIntMap A read and writable Item int map, used internally |
|
38 |
///A \e heap is a data structure for storing items with specified values |
|
39 |
///called \e priorities in such a way that finding the item with minimum |
|
40 |
///priority is efficient. \c Comp specifies the ordering of the priorities. |
|
41 |
///In a heap one can change the priority of an item, add or erase an |
|
42 |
///item, etc. |
|
43 |
/// |
|
44 |
///\tparam PR Type of the priority of the items. |
|
45 |
///\tparam IM A read and writable item map with int values, used internally |
|
44 | 46 |
///to handle the cross references. |
45 |
///\tparam _Compare A class for the ordering of the priorities. The |
|
46 |
///default is \c std::less<_Prio>. |
|
47 |
///\tparam Comp A functor class for the ordering of the priorities. |
|
48 |
///The default is \c std::less<PR>. |
|
47 | 49 |
/// |
48 | 50 |
///\sa FibHeap |
49 | 51 |
///\sa Dijkstra |
50 |
template <typename _Prio, typename _ItemIntMap, |
|
51 |
typename _Compare = std::less<_Prio> > |
|
52 |
template <typename PR, typename IM, typename Comp = std::less<PR> > |
|
52 | 53 |
class BinHeap { |
53 | 54 |
|
54 | 55 |
public: |
55 | 56 |
///\e |
56 |
typedef |
|
57 |
typedef IM ItemIntMap; |
|
57 | 58 |
///\e |
58 |
typedef |
|
59 |
typedef PR Prio; |
|
59 | 60 |
///\e |
60 | 61 |
typedef typename ItemIntMap::Key Item; |
61 | 62 |
///\e |
62 | 63 |
typedef std::pair<Item,Prio> Pair; |
63 | 64 |
///\e |
64 |
typedef |
|
65 |
typedef Comp Compare; |
|
65 | 66 |
|
66 | 67 |
/// \brief Type to represent the items states. |
67 | 68 |
/// |
68 | 69 |
/// Each Item element have a state associated to it. It may be "in heap", |
69 | 70 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
70 | 71 |
/// heap's point of view, but may be useful to the user. |
71 | 72 |
/// |
72 |
/// The ItemIntMap \e should be initialized in such way that it maps |
|
73 |
/// PRE_HEAP (-1) to any element to be put in the heap... |
|
73 |
/// The item-int map must be initialized in such way that it assigns |
|
74 |
/// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap. |
|
74 | 75 |
enum State { |
75 |
IN_HEAP = 0, |
|
76 |
PRE_HEAP = -1, |
|
77 |
|
|
76 |
IN_HEAP = 0, ///< \e |
|
77 |
PRE_HEAP = -1, ///< \e |
|
78 |
POST_HEAP = -2 ///< \e |
|
78 | 79 |
}; |
79 | 80 |
|
80 | 81 |
private: |
81 |
std::vector<Pair> data; |
|
82 |
Compare comp; |
|
83 |
|
|
82 |
std::vector<Pair> _data; |
|
83 |
Compare _comp; |
|
84 |
ItemIntMap &_iim; |
|
84 | 85 |
|
85 | 86 |
public: |
86 | 87 |
/// \brief The constructor. |
87 | 88 |
/// |
88 | 89 |
/// The constructor. |
89 |
/// \param |
|
90 |
/// \param map should be given to the constructor, since it is used |
|
90 | 91 |
/// internally to handle the cross references. The value of the map |
91 |
/// should be PRE_HEAP (-1) for each element. |
|
92 |
explicit BinHeap(ItemIntMap &_iim) : iim(_iim) {} |
|
92 |
/// must be \c PRE_HEAP (<tt>-1</tt>) for every item. |
|
93 |
explicit BinHeap(ItemIntMap &map) : _iim(map) {} |
|
93 | 94 |
|
94 | 95 |
/// \brief The constructor. |
95 | 96 |
/// |
96 | 97 |
/// The constructor. |
97 |
/// \param |
|
98 |
/// \param map should be given to the constructor, since it is used |
|
98 | 99 |
/// internally to handle the cross references. The value of the map |
99 | 100 |
/// should be PRE_HEAP (-1) for each element. |
100 | 101 |
/// |
101 |
/// \param _comp The comparator function object. |
|
102 |
BinHeap(ItemIntMap &_iim, const Compare &_comp) |
|
103 |
|
|
102 |
/// \param comp The comparator function object. |
|
103 |
BinHeap(ItemIntMap &map, const Compare &comp) |
|
104 |
: _iim(map), _comp(comp) {} |
|
104 | 105 |
|
105 | 106 |
|
106 | 107 |
/// The number of items stored in the heap. |
107 | 108 |
/// |
108 | 109 |
/// \brief Returns the number of items stored in the heap. |
109 |
int size() const { return |
|
110 |
int size() const { return _data.size(); } |
|
110 | 111 |
|
111 | 112 |
/// \brief Checks if the heap stores no items. |
112 | 113 |
/// |
113 | 114 |
/// Returns \c true if and only if the heap stores no items. |
114 |
bool empty() const { return |
|
115 |
bool empty() const { return _data.empty(); } |
|
115 | 116 |
|
116 | 117 |
/// \brief Make empty this heap. |
117 | 118 |
/// |
118 | 119 |
/// Make empty this heap. It does not change the cross reference map. |
119 | 120 |
/// If you want to reuse what is not surely empty you should first clear |
120 | 121 |
/// the heap and after that you should set the cross reference map for |
121 | 122 |
/// each item to \c PRE_HEAP. |
122 | 123 |
void clear() { |
123 |
|
|
124 |
_data.clear(); |
|
124 | 125 |
} |
125 | 126 |
|
126 | 127 |
private: |
127 | 128 |
static int parent(int i) { return (i-1)/2; } |
128 | 129 |
|
129 | 130 |
static int second_child(int i) { return 2*i+2; } |
130 | 131 |
bool less(const Pair &p1, const Pair &p2) const { |
131 |
return |
|
132 |
return _comp(p1.second, p2.second); |
|
132 | 133 |
} |
133 | 134 |
|
134 | 135 |
int bubble_up(int hole, Pair p) { |
135 | 136 |
int par = parent(hole); |
136 |
while( hole>0 && less(p,data[par]) ) { |
|
137 |
move(data[par],hole); |
|
137 |
while( hole>0 && less(p,_data[par]) ) { |
|
138 |
move(_data[par],hole); |
|
138 | 139 |
hole = par; |
139 | 140 |
par = parent(hole); |
140 | 141 |
} |
141 | 142 |
move(p, hole); |
142 | 143 |
return hole; |
143 | 144 |
} |
144 | 145 |
|
145 | 146 |
int bubble_down(int hole, Pair p, int length) { |
146 | 147 |
int child = second_child(hole); |
147 | 148 |
while(child < length) { |
148 |
if( less( |
|
149 |
if( less(_data[child-1], _data[child]) ) { |
|
149 | 150 |
--child; |
150 | 151 |
} |
151 |
if( !less( |
|
152 |
if( !less(_data[child], p) ) |
|
152 | 153 |
goto ok; |
153 |
move( |
|
154 |
move(_data[child], hole); |
|
154 | 155 |
hole = child; |
155 | 156 |
child = second_child(hole); |
156 | 157 |
} |
157 | 158 |
child--; |
158 |
if( child<length && less(data[child], p) ) { |
|
159 |
move(data[child], hole); |
|
159 |
if( child<length && less(_data[child], p) ) { |
|
160 |
move(_data[child], hole); |
|
160 | 161 |
hole=child; |
161 | 162 |
} |
162 | 163 |
ok: |
163 | 164 |
move(p, hole); |
164 | 165 |
return hole; |
165 | 166 |
} |
166 | 167 |
|
167 | 168 |
void move(const Pair &p, int i) { |
168 |
data[i] = p; |
|
169 |
iim.set(p.first, i); |
|
169 |
_data[i] = p; |
|
170 |
_iim.set(p.first, i); |
|
170 | 171 |
} |
171 | 172 |
|
172 | 173 |
public: |
173 | 174 |
/// \brief Insert a pair of item and priority into the heap. |
174 | 175 |
/// |
175 | 176 |
/// Adds \c p.first to the heap with priority \c p.second. |
176 | 177 |
/// \param p The pair to insert. |
177 | 178 |
void push(const Pair &p) { |
178 |
int n = data.size(); |
|
179 |
data.resize(n+1); |
|
179 |
int n = _data.size(); |
|
180 |
_data.resize(n+1); |
|
180 | 181 |
bubble_up(n, p); |
181 | 182 |
} |
182 | 183 |
|
183 | 184 |
/// \brief Insert an item into the heap with the given heap. |
184 | 185 |
/// |
185 | 186 |
/// Adds \c i to the heap with priority \c p. |
186 | 187 |
/// \param i The item to insert. |
187 | 188 |
/// \param p The priority of the item. |
188 | 189 |
void push(const Item &i, const Prio &p) { push(Pair(i,p)); } |
189 | 190 |
|
190 | 191 |
/// \brief Returns the item with minimum priority relative to \c Compare. |
191 | 192 |
/// |
192 | 193 |
/// This method returns the item with minimum priority relative to \c |
193 | 194 |
/// Compare. |
194 | 195 |
/// \pre The heap must be nonempty. |
195 | 196 |
Item top() const { |
196 |
return |
|
197 |
return _data[0].first; |
|
197 | 198 |
} |
198 | 199 |
|
199 | 200 |
/// \brief Returns the minimum priority relative to \c Compare. |
200 | 201 |
/// |
201 | 202 |
/// It returns the minimum priority relative to \c Compare. |
202 | 203 |
/// \pre The heap must be nonempty. |
203 | 204 |
Prio prio() const { |
204 |
return |
|
205 |
return _data[0].second; |
|
205 | 206 |
} |
206 | 207 |
|
207 | 208 |
/// \brief Deletes the item with minimum priority relative to \c Compare. |
208 | 209 |
/// |
209 | 210 |
/// This method deletes the item with minimum priority relative to \c |
210 | 211 |
/// Compare from the heap. |
211 | 212 |
/// \pre The heap must be non-empty. |
212 | 213 |
void pop() { |
213 |
int n = data.size()-1; |
|
214 |
iim.set(data[0].first, POST_HEAP); |
|
214 |
int n = _data.size()-1; |
|
215 |
_iim.set(_data[0].first, POST_HEAP); |
|
215 | 216 |
if (n > 0) { |
216 |
bubble_down(0, |
|
217 |
bubble_down(0, _data[n], n); |
|
217 | 218 |
} |
218 |
|
|
219 |
_data.pop_back(); |
|
219 | 220 |
} |
220 | 221 |
|
221 | 222 |
/// \brief Deletes \c i from the heap. |
222 | 223 |
/// |
223 | 224 |
/// This method deletes item \c i from the heap. |
224 | 225 |
/// \param i The item to erase. |
225 | 226 |
/// \pre The item should be in the heap. |
226 | 227 |
void erase(const Item &i) { |
227 |
int h = iim[i]; |
|
228 |
int n = data.size()-1; |
|
229 |
|
|
228 |
int h = _iim[i]; |
|
229 |
int n = _data.size()-1; |
|
230 |
_iim.set(_data[h].first, POST_HEAP); |
|
230 | 231 |
if( h < n ) { |
231 |
if ( bubble_up(h, data[n]) == h) { |
|
232 |
bubble_down(h, data[n], n); |
|
232 |
if ( bubble_up(h, _data[n]) == h) { |
|
233 |
bubble_down(h, _data[n], n); |
|
233 | 234 |
} |
234 | 235 |
} |
235 |
|
|
236 |
_data.pop_back(); |
|
236 | 237 |
} |
237 | 238 |
|
238 | 239 |
|
239 | 240 |
/// \brief Returns the priority of \c i. |
240 | 241 |
/// |
241 | 242 |
/// This function returns the priority of item \c i. |
243 |
/// \param i The item. |
|
242 | 244 |
/// \pre \c i must be in the heap. |
243 |
/// \param i The item. |
|
244 | 245 |
Prio operator[](const Item &i) const { |
245 |
int idx = iim[i]; |
|
246 |
return data[idx].second; |
|
246 |
int idx = _iim[i]; |
|
247 |
return _data[idx].second; |
|
247 | 248 |
} |
248 | 249 |
|
249 | 250 |
/// \brief \c i gets to the heap with priority \c p independently |
250 | 251 |
/// if \c i was already there. |
251 | 252 |
/// |
252 | 253 |
/// This method calls \ref push(\c i, \c p) if \c i is not stored |
253 | 254 |
/// in the heap and sets the priority of \c i to \c p otherwise. |
254 | 255 |
/// \param i The item. |
255 | 256 |
/// \param p The priority. |
256 | 257 |
void set(const Item &i, const Prio &p) { |
257 |
int idx = |
|
258 |
int idx = _iim[i]; |
|
258 | 259 |
if( idx < 0 ) { |
259 | 260 |
push(i,p); |
260 | 261 |
} |
261 |
else if( |
|
262 |
else if( _comp(p, _data[idx].second) ) { |
|
262 | 263 |
bubble_up(idx, Pair(i,p)); |
263 | 264 |
} |
264 | 265 |
else { |
265 |
bubble_down(idx, Pair(i,p), |
|
266 |
bubble_down(idx, Pair(i,p), _data.size()); |
|
266 | 267 |
} |
267 | 268 |
} |
268 | 269 |
|
269 | 270 |
/// \brief Decreases the priority of \c i to \c p. |
270 | 271 |
/// |
271 | 272 |
/// This method decreases the priority of item \c i to \c p. |
273 |
/// \param i The item. |
|
274 |
/// \param p The priority. |
|
272 | 275 |
/// \pre \c i must be stored in the heap with priority at least \c |
273 | 276 |
/// p relative to \c Compare. |
274 |
/// \param i The item. |
|
275 |
/// \param p The priority. |
|
276 | 277 |
void decrease(const Item &i, const Prio &p) { |
277 |
int idx = |
|
278 |
int idx = _iim[i]; |
|
278 | 279 |
bubble_up(idx, Pair(i,p)); |
279 | 280 |
} |
280 | 281 |
|
281 | 282 |
/// \brief Increases the priority of \c i to \c p. |
282 | 283 |
/// |
283 | 284 |
/// This method sets the priority of item \c i to \c p. |
285 |
/// \param i The item. |
|
286 |
/// \param p The priority. |
|
284 | 287 |
/// \pre \c i must be stored in the heap with priority at most \c |
285 | 288 |
/// p relative to \c Compare. |
286 |
/// \param i The item. |
|
287 |
/// \param p The priority. |
|
288 | 289 |
void increase(const Item &i, const Prio &p) { |
289 |
int idx = iim[i]; |
|
290 |
bubble_down(idx, Pair(i,p), data.size()); |
|
290 |
int idx = _iim[i]; |
|
291 |
bubble_down(idx, Pair(i,p), _data.size()); |
|
291 | 292 |
} |
292 | 293 |
|
293 | 294 |
/// \brief Returns if \c item is in, has already been in, or has |
294 | 295 |
/// never been in the heap. |
295 | 296 |
/// |
296 | 297 |
/// This method returns PRE_HEAP if \c item has never been in the |
297 | 298 |
/// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP |
298 | 299 |
/// otherwise. In the latter case it is possible that \c item will |
299 | 300 |
/// get back to the heap again. |
300 | 301 |
/// \param i The item. |
301 | 302 |
State state(const Item &i) const { |
302 |
int s = |
|
303 |
int s = _iim[i]; |
|
303 | 304 |
if( s>=0 ) |
304 | 305 |
s=0; |
305 | 306 |
return State(s); |
306 | 307 |
} |
307 | 308 |
|
308 | 309 |
/// \brief Sets the state of the \c item in the heap. |
309 | 310 |
/// |
310 | 311 |
/// Sets the state of the \c item in the heap. It can be used to |
311 | 312 |
/// manually clear the heap when it is important to achive the |
312 | 313 |
/// better time complexity. |
313 | 314 |
/// \param i The item. |
314 | 315 |
/// \param st The state. It should not be \c IN_HEAP. |
315 | 316 |
void state(const Item& i, State st) { |
316 | 317 |
switch (st) { |
317 | 318 |
case POST_HEAP: |
318 | 319 |
case PRE_HEAP: |
319 | 320 |
if (state(i) == IN_HEAP) { |
320 | 321 |
erase(i); |
321 | 322 |
} |
322 |
|
|
323 |
_iim[i] = st; |
|
323 | 324 |
break; |
324 | 325 |
case IN_HEAP: |
325 | 326 |
break; |
326 | 327 |
} |
327 | 328 |
} |
328 | 329 |
|
329 | 330 |
/// \brief Replaces an item in the heap. |
330 | 331 |
/// |
331 | 332 |
/// The \c i item is replaced with \c j item. The \c i item should |
332 | 333 |
/// be in the heap, while the \c j should be out of the heap. The |
333 | 334 |
/// \c i item will out of the heap and \c j will be in the heap |
334 | 335 |
/// with the same prioriority as prevoiusly the \c i item. |
335 | 336 |
void replace(const Item& i, const Item& j) { |
336 |
int idx = iim[i]; |
|
337 |
iim.set(i, iim[j]); |
|
338 |
iim.set(j, idx); |
|
339 |
data[idx].first = j; |
|
337 |
int idx = _iim[i]; |
|
338 |
_iim.set(i, _iim[j]); |
|
339 |
_iim.set(j, idx); |
|
340 |
_data[idx].first = j; |
|
340 | 341 |
} |
341 | 342 |
|
342 | 343 |
}; // class BinHeap |
343 | 344 |
|
344 | 345 |
} // namespace lemon |
345 | 346 |
|
346 | 347 |
#endif // LEMON_BIN_HEAP_H |
... | ... |
@@ -11,40 +11,40 @@ |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_BITS_EDGE_SET_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_EDGE_SET_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/core.h> |
23 | 23 |
#include <lemon/error.h> |
24 | 24 |
#include <lemon/bits/default_map.h> |
25 | 25 |
#include <lemon/bits/map_extender.h> |
26 | 26 |
|
27 |
///\ingroup digraphbits |
|
28 |
///\file |
|
29 |
|
|
27 |
//\ingroup digraphbits |
|
28 |
//\file |
|
29 |
//\brief Extenders for the arc set types |
|
30 | 30 |
namespace lemon { |
31 | 31 |
|
32 |
/// \ingroup digraphbits |
|
33 |
/// |
|
34 |
// |
|
32 |
// \ingroup digraphbits |
|
33 |
// |
|
34 |
// \brief Extender for the ArcSets |
|
35 | 35 |
template <typename Base> |
36 | 36 |
class ArcSetExtender : public Base { |
37 | 37 |
public: |
38 | 38 |
|
39 | 39 |
typedef Base Parent; |
40 | 40 |
typedef ArcSetExtender Digraph; |
41 | 41 |
|
42 | 42 |
// Base extensions |
43 | 43 |
|
44 | 44 |
typedef typename Parent::Node Node; |
45 | 45 |
typedef typename Parent::Arc Arc; |
46 | 46 |
|
47 | 47 |
int maxId(Node) const { |
48 | 48 |
return Parent::maxNodeId(); |
49 | 49 |
} |
50 | 50 |
|
... | ... |
@@ -59,46 +59,44 @@ |
59 | 59 |
Arc fromId(int id, Arc) const { |
60 | 60 |
return Parent::arcFromId(id); |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
Node oppositeNode(const Node &n, const Arc &e) const { |
64 | 64 |
if (n == Parent::source(e)) |
65 | 65 |
return Parent::target(e); |
66 | 66 |
else if(n==Parent::target(e)) |
67 | 67 |
return Parent::source(e); |
68 | 68 |
else |
69 | 69 |
return INVALID; |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
|
73 | 73 |
// Alteration notifier extensions |
74 | 74 |
|
75 |
|
|
75 |
// The arc observer registry. |
|
76 | 76 |
typedef AlterationNotifier<ArcSetExtender, Arc> ArcNotifier; |
77 | 77 |
|
78 | 78 |
protected: |
79 | 79 |
|
80 | 80 |
mutable ArcNotifier arc_notifier; |
81 | 81 |
|
82 | 82 |
public: |
83 | 83 |
|
84 | 84 |
using Parent::notifier; |
85 | 85 |
|
86 |
/// \brief Gives back the arc alteration notifier. |
|
87 |
/// |
|
88 |
|
|
86 |
// Gives back the arc alteration notifier. |
|
89 | 87 |
ArcNotifier& notifier(Arc) const { |
90 | 88 |
return arc_notifier; |
91 | 89 |
} |
92 | 90 |
|
93 | 91 |
// Iterable extensions |
94 | 92 |
|
95 | 93 |
class NodeIt : public Node { |
96 | 94 |
const Digraph* digraph; |
97 | 95 |
public: |
98 | 96 |
|
99 | 97 |
NodeIt() {} |
100 | 98 |
|
101 | 99 |
NodeIt(Invalid i) : Node(i) { } |
102 | 100 |
|
103 | 101 |
explicit NodeIt(const Digraph& _graph) : digraph(&_graph) { |
104 | 102 |
_graph.first(static_cast<Node&>(*this)); |
... | ... |
@@ -172,56 +170,56 @@ |
172 | 170 |
|
173 | 171 |
InArcIt(const Digraph& _graph, const Node& node) |
174 | 172 |
: digraph(&_graph) { |
175 | 173 |
_graph.firstIn(*this, node); |
176 | 174 |
} |
177 | 175 |
|
178 | 176 |
InArcIt(const Digraph& _graph, const Arc& arc) : |
179 | 177 |
Arc(arc), digraph(&_graph) {} |
180 | 178 |
|
181 | 179 |
InArcIt& operator++() { |
182 | 180 |
digraph->nextIn(*this); |
183 | 181 |
return *this; |
184 | 182 |
} |
185 | 183 |
|
186 | 184 |
}; |
187 | 185 |
|
188 |
/// \brief Base node of the iterator |
|
189 |
/// |
|
190 |
// |
|
186 |
// \brief Base node of the iterator |
|
187 |
// |
|
188 |
// Returns the base node (ie. the source in this case) of the iterator |
|
191 | 189 |
Node baseNode(const OutArcIt &e) const { |
192 | 190 |
return Parent::source(static_cast<const Arc&>(e)); |
193 | 191 |
} |
194 |
/// \brief Running node of the iterator |
|
195 |
/// |
|
196 |
/// Returns the running node (ie. the target in this case) of the |
|
197 |
/// iterator |
|
192 |
// \brief Running node of the iterator |
|
193 |
// |
|
194 |
// Returns the running node (ie. the target in this case) of the |
|
195 |
// iterator |
|
198 | 196 |
Node runningNode(const OutArcIt &e) const { |
199 | 197 |
return Parent::target(static_cast<const Arc&>(e)); |
200 | 198 |
} |
201 | 199 |
|
202 |
/// \brief Base node of the iterator |
|
203 |
/// |
|
204 |
// |
|
200 |
// \brief Base node of the iterator |
|
201 |
// |
|
202 |
// Returns the base node (ie. the target in this case) of the iterator |
|
205 | 203 |
Node baseNode(const InArcIt &e) const { |
206 | 204 |
return Parent::target(static_cast<const Arc&>(e)); |
207 | 205 |
} |
208 |
/// \brief Running node of the iterator |
|
209 |
/// |
|
210 |
/// Returns the running node (ie. the source in this case) of the |
|
211 |
/// iterator |
|
206 |
// \brief Running node of the iterator |
|
207 |
// |
|
208 |
// Returns the running node (ie. the source in this case) of the |
|
209 |
// iterator |
|
212 | 210 |
Node runningNode(const InArcIt &e) const { |
213 | 211 |
return Parent::source(static_cast<const Arc&>(e)); |
214 | 212 |
} |
215 | 213 |
|
216 | 214 |
using Parent::first; |
217 | 215 |
|
218 | 216 |
// Mappable extension |
219 | 217 |
|
220 | 218 |
template <typename _Value> |
221 | 219 |
class ArcMap |
222 | 220 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > { |
223 | 221 |
public: |
224 | 222 |
typedef ArcSetExtender Digraph; |
225 | 223 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
226 | 224 |
|
227 | 225 |
explicit ArcMap(const Digraph& _g) |
... | ... |
@@ -258,35 +256,35 @@ |
258 | 256 |
void erase(const Arc& arc) { |
259 | 257 |
notifier(Arc()).erase(arc); |
260 | 258 |
Parent::erase(arc); |
261 | 259 |
} |
262 | 260 |
|
263 | 261 |
ArcSetExtender() { |
264 | 262 |
arc_notifier.setContainer(*this); |
265 | 263 |
} |
266 | 264 |
|
267 | 265 |
~ArcSetExtender() { |
268 | 266 |
arc_notifier.clear(); |
269 | 267 |
} |
270 | 268 |
|
271 | 269 |
}; |
272 | 270 |
|
273 | 271 |
|
274 |
/// \ingroup digraphbits |
|
275 |
/// |
|
276 |
// |
|
272 |
// \ingroup digraphbits |
|
273 |
// |
|
274 |
// \brief Extender for the EdgeSets |
|
277 | 275 |
template <typename Base> |
278 | 276 |
class EdgeSetExtender : public Base { |
279 | 277 |
|
280 | 278 |
public: |
281 | 279 |
|
282 | 280 |
typedef Base Parent; |
283 | 281 |
typedef EdgeSetExtender Digraph; |
284 | 282 |
|
285 | 283 |
typedef typename Parent::Node Node; |
286 | 284 |
typedef typename Parent::Arc Arc; |
287 | 285 |
typedef typename Parent::Edge Edge; |
288 | 286 |
|
289 | 287 |
|
290 | 288 |
int maxId(Node) const { |
291 | 289 |
return Parent::maxNodeId(); |
292 | 290 |
} |
... | ... |
@@ -479,69 +477,69 @@ |
479 | 477 |
|
480 | 478 |
IncEdgeIt(const Digraph& _graph, const Node &n) : digraph(&_graph) { |
481 | 479 |
_graph.firstInc(*this, direction, n); |
482 | 480 |
} |
483 | 481 |
|
484 | 482 |
IncEdgeIt(const Digraph& _graph, const Edge &ue, const Node &n) |
485 | 483 |
: digraph(&_graph), Edge(ue) { |
486 | 484 |
direction = (_graph.source(ue) == n); |
487 | 485 |
} |
488 | 486 |
|
489 | 487 |
IncEdgeIt& operator++() { |
490 | 488 |
digraph->nextInc(*this, direction); |
491 | 489 |
return *this; |
492 | 490 |
} |
493 | 491 |
}; |
494 | 492 |
|
495 |
/// \brief Base node of the iterator |
|
496 |
/// |
|
497 |
// |
|
493 |
// \brief Base node of the iterator |
|
494 |
// |
|
495 |
// Returns the base node (ie. the source in this case) of the iterator |
|
498 | 496 |
Node baseNode(const OutArcIt &e) const { |
499 | 497 |
return Parent::source(static_cast<const Arc&>(e)); |
500 | 498 |
} |
501 |
/// \brief Running node of the iterator |
|
502 |
/// |
|
503 |
/// Returns the running node (ie. the target in this case) of the |
|
504 |
/// iterator |
|
499 |
// \brief Running node of the iterator |
|
500 |
// |
|
501 |
// Returns the running node (ie. the target in this case) of the |
|
502 |
// iterator |
|
505 | 503 |
Node runningNode(const OutArcIt &e) const { |
506 | 504 |
return Parent::target(static_cast<const Arc&>(e)); |
507 | 505 |
} |
508 | 506 |
|
509 |
/// \brief Base node of the iterator |
|
510 |
/// |
|
511 |
// |
|
507 |
// \brief Base node of the iterator |
|
508 |
// |
|
509 |
// Returns the base node (ie. the target in this case) of the iterator |
|
512 | 510 |
Node baseNode(const InArcIt &e) const { |
513 | 511 |
return Parent::target(static_cast<const Arc&>(e)); |
514 | 512 |
} |
515 |
/// \brief Running node of the iterator |
|
516 |
/// |
|
517 |
/// Returns the running node (ie. the source in this case) of the |
|
518 |
/// iterator |
|
513 |
// \brief Running node of the iterator |
|
514 |
// |
|
515 |
// Returns the running node (ie. the source in this case) of the |
|
516 |
// iterator |
|
519 | 517 |
Node runningNode(const InArcIt &e) const { |
520 | 518 |
return Parent::source(static_cast<const Arc&>(e)); |
521 | 519 |
} |
522 | 520 |
|
523 |
/// Base node of the iterator |
|
524 |
/// |
|
525 |
// |
|
521 |
// Base node of the iterator |
|
522 |
// |
|
523 |
// Returns the base node of the iterator |
|
526 | 524 |
Node baseNode(const IncEdgeIt &e) const { |
527 | 525 |
return e.direction ? u(e) : v(e); |
528 | 526 |
} |
529 |
/// Running node of the iterator |
|
530 |
/// |
|
531 |
// |
|
527 |
// Running node of the iterator |
|
528 |
// |
|
529 |
// Returns the running node of the iterator |
|
532 | 530 |
Node runningNode(const IncEdgeIt &e) const { |
533 | 531 |
return e.direction ? v(e) : u(e); |
534 | 532 |
} |
535 | 533 |
|
536 | 534 |
|
537 | 535 |
template <typename _Value> |
538 | 536 |
class ArcMap |
539 | 537 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > { |
540 | 538 |
public: |
541 | 539 |
typedef EdgeSetExtender Digraph; |
542 | 540 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
543 | 541 |
|
544 | 542 |
ArcMap(const Digraph& _g) |
545 | 543 |
: Parent(_g) {} |
546 | 544 |
ArcMap(const Digraph& _g, const _Value& _v) |
547 | 545 |
: Parent(_g, _v) {} |
... | ... |
@@ -202,106 +202,106 @@ |
202 | 202 |
bool _local_level; |
203 | 203 |
|
204 | 204 |
typedef typename Digraph::template NodeMap<Value> ExcessMap; |
205 | 205 |
ExcessMap* _excess; |
206 | 206 |
|
207 | 207 |
Tolerance _tol; |
208 | 208 |
int _el; |
209 | 209 |
|
210 | 210 |
public: |
211 | 211 |
|
212 | 212 |
typedef Circulation Create; |
213 | 213 |
|
214 | 214 |
///\name Named Template Parameters |
215 | 215 |
|
216 | 216 |
///@{ |
217 | 217 |
|
218 |
template <typename |
|
218 |
template <typename T> |
|
219 | 219 |
struct SetFlowMapTraits : public Traits { |
220 |
typedef |
|
220 |
typedef T FlowMap; |
|
221 | 221 |
static FlowMap *createFlowMap(const Digraph&) { |
222 | 222 |
LEMON_ASSERT(false, "FlowMap is not initialized"); |
223 | 223 |
return 0; // ignore warnings |
224 | 224 |
} |
225 | 225 |
}; |
226 | 226 |
|
227 | 227 |
/// \brief \ref named-templ-param "Named parameter" for setting |
228 | 228 |
/// FlowMap type |
229 | 229 |
/// |
230 | 230 |
/// \ref named-templ-param "Named parameter" for setting FlowMap |
231 | 231 |
/// type. |
232 |
template <typename |
|
232 |
template <typename T> |
|
233 | 233 |
struct SetFlowMap |
234 | 234 |
: public Circulation<Digraph, LCapMap, UCapMap, DeltaMap, |
235 |
SetFlowMapTraits< |
|
235 |
SetFlowMapTraits<T> > { |
|
236 | 236 |
typedef Circulation<Digraph, LCapMap, UCapMap, DeltaMap, |
237 |
SetFlowMapTraits< |
|
237 |
SetFlowMapTraits<T> > Create; |
|
238 | 238 |
}; |
239 | 239 |
|
240 |
template <typename |
|
240 |
template <typename T> |
|
241 | 241 |
struct SetElevatorTraits : public Traits { |
242 |
typedef |
|
242 |
typedef T Elevator; |
|
243 | 243 |
static Elevator *createElevator(const Digraph&, int) { |
244 | 244 |
LEMON_ASSERT(false, "Elevator is not initialized"); |
245 | 245 |
return 0; // ignore warnings |
246 | 246 |
} |
247 | 247 |
}; |
248 | 248 |
|
249 | 249 |
/// \brief \ref named-templ-param "Named parameter" for setting |
250 | 250 |
/// Elevator type |
251 | 251 |
/// |
252 | 252 |
/// \ref named-templ-param "Named parameter" for setting Elevator |
253 | 253 |
/// type. If this named parameter is used, then an external |
254 | 254 |
/// elevator object must be passed to the algorithm using the |
255 | 255 |
/// \ref elevator(Elevator&) "elevator()" function before calling |
256 | 256 |
/// \ref run() or \ref init(). |
257 | 257 |
/// \sa SetStandardElevator |
258 |
template <typename |
|
258 |
template <typename T> |
|
259 | 259 |
struct SetElevator |
260 | 260 |
: public Circulation<Digraph, LCapMap, UCapMap, DeltaMap, |
261 |
SetElevatorTraits< |
|
261 |
SetElevatorTraits<T> > { |
|
262 | 262 |
typedef Circulation<Digraph, LCapMap, UCapMap, DeltaMap, |
263 |
SetElevatorTraits< |
|
263 |
SetElevatorTraits<T> > Create; |
|
264 | 264 |
}; |
265 | 265 |
|
266 |
template <typename |
|
266 |
template <typename T> |
|
267 | 267 |
struct SetStandardElevatorTraits : public Traits { |
268 |
typedef |
|
268 |
typedef T Elevator; |
|
269 | 269 |
static Elevator *createElevator(const Digraph& digraph, int max_level) { |
270 | 270 |
return new Elevator(digraph, max_level); |
271 | 271 |
} |
272 | 272 |
}; |
273 | 273 |
|
274 | 274 |
/// \brief \ref named-templ-param "Named parameter" for setting |
275 | 275 |
/// Elevator type with automatic allocation |
276 | 276 |
/// |
277 | 277 |
/// \ref named-templ-param "Named parameter" for setting Elevator |
278 | 278 |
/// type with automatic allocation. |
279 | 279 |
/// The Elevator should have standard constructor interface to be |
280 | 280 |
/// able to automatically created by the algorithm (i.e. the |
281 | 281 |
/// digraph and the maximum level should be passed to it). |
282 | 282 |
/// However an external elevator object could also be passed to the |
283 | 283 |
/// algorithm with the \ref elevator(Elevator&) "elevator()" function |
284 | 284 |
/// before calling \ref run() or \ref init(). |
285 | 285 |
/// \sa SetElevator |
286 |
template <typename |
|
286 |
template <typename T> |
|
287 | 287 |
struct SetStandardElevator |
288 | 288 |
: public Circulation<Digraph, LCapMap, UCapMap, DeltaMap, |
289 |
SetStandardElevatorTraits< |
|
289 |
SetStandardElevatorTraits<T> > { |
|
290 | 290 |
typedef Circulation<Digraph, LCapMap, UCapMap, DeltaMap, |
291 |
SetStandardElevatorTraits< |
|
291 |
SetStandardElevatorTraits<T> > Create; |
|
292 | 292 |
}; |
293 | 293 |
|
294 | 294 |
/// @} |
295 | 295 |
|
296 | 296 |
protected: |
297 | 297 |
|
298 | 298 |
Circulation() {} |
299 | 299 |
|
300 | 300 |
public: |
301 | 301 |
|
302 | 302 |
/// The constructor of the class. |
303 | 303 |
|
304 | 304 |
/// The constructor of the class. |
305 | 305 |
/// \param g The digraph the algorithm runs on. |
306 | 306 |
/// \param lo The lower bound capacity of the arcs. |
307 | 307 |
/// \param up The upper bound capacity of the arcs. |
... | ... |
@@ -669,33 +669,33 @@ |
669 | 669 |
*/ |
670 | 670 |
bool barrier(const Node& node) const |
671 | 671 |
{ |
672 | 672 |
return (*_level)[node] >= _el; |
673 | 673 |
} |
674 | 674 |
|
675 | 675 |
/// \brief Gives back a barrier. |
676 | 676 |
/// |
677 | 677 |
/// This function sets \c bar to the characteristic vector of the |
678 | 678 |
/// found barrier. \c bar should be a \ref concepts::WriteMap "writable" |
679 | 679 |
/// node map with \c bool (or convertible) value type. |
680 | 680 |
/// |
681 | 681 |
/// If a feasible circulation is found, the function gives back an |
682 | 682 |
/// empty set, so \c bar[v] will be \c false for all nodes \c v. |
683 | 683 |
/// |
684 | 684 |
/// \note This function calls \ref barrier() for each node, |
685 |
/// so it runs in |
|
685 |
/// so it runs in O(n) time. |
|
686 | 686 |
/// |
687 | 687 |
/// \pre Either \ref run() or \ref init() must be called before |
688 | 688 |
/// using this function. |
689 | 689 |
/// |
690 | 690 |
/// \sa barrier() |
691 | 691 |
/// \sa checkBarrier() |
692 | 692 |
template<class BarrierMap> |
693 | 693 |
void barrierMap(BarrierMap &bar) const |
694 | 694 |
{ |
695 | 695 |
for(NodeIt n(_g);n!=INVALID;++n) |
696 | 696 |
bar.set(n, (*_level)[n] >= _el); |
697 | 697 |
} |
698 | 698 |
|
699 | 699 |
/// @} |
700 | 700 |
|
701 | 701 |
/// \name Checker Functions |
... | ... |
@@ -588,49 +588,61 @@ |
588 | 588 |
return INVALID; |
589 | 589 |
} |
590 | 590 |
|
591 | 591 |
/// \brief Returns true if the arc has default orientation. |
592 | 592 |
/// |
593 | 593 |
/// Returns whether the given directed arc is same orientation as |
594 | 594 |
/// the corresponding edge's default orientation. |
595 | 595 |
bool direction(Arc) const { return true; } |
596 | 596 |
|
597 | 597 |
/// \brief Returns the opposite directed arc. |
598 | 598 |
/// |
599 | 599 |
/// Returns the opposite directed arc. |
600 | 600 |
Arc oppositeArc(Arc) const { return INVALID; } |
601 | 601 |
|
602 | 602 |
/// \brief Opposite node on an arc |
603 | 603 |
/// |
604 |
/// \return |
|
604 |
/// \return The opposite of the given node on the given edge. |
|
605 | 605 |
Node oppositeNode(Node, Edge) const { return INVALID; } |
606 | 606 |
|
607 | 607 |
/// \brief First node of the edge. |
608 | 608 |
/// |
609 |
/// \return |
|
609 |
/// \return The first node of the given edge. |
|
610 | 610 |
/// |
611 | 611 |
/// Naturally edges don't have direction and thus |
612 |
/// don't have source and target node. But we use these two methods |
|
613 |
/// to query the two nodes of the arc. The direction of the arc |
|
614 |
/// |
|
612 |
/// don't have source and target node. However we use \c u() and \c v() |
|
613 |
/// methods to query the two nodes of the arc. The direction of the |
|
614 |
/// arc which arises this way is called the inherent direction of the |
|
615 | 615 |
/// edge, and is used to define the "default" direction |
616 | 616 |
/// of the directed versions of the arcs. |
617 |
/// \sa |
|
617 |
/// \sa v() |
|
618 |
/// \sa direction() |
|
618 | 619 |
Node u(Edge) const { return INVALID; } |
619 | 620 |
|
620 | 621 |
/// \brief Second node of the edge. |
622 |
/// |
|
623 |
/// \return The second node of the given edge. |
|
624 |
/// |
|
625 |
/// Naturally edges don't have direction and thus |
|
626 |
/// don't have source and target node. However we use \c u() and \c v() |
|
627 |
/// methods to query the two nodes of the arc. The direction of the |
|
628 |
/// arc which arises this way is called the inherent direction of the |
|
629 |
/// edge, and is used to define the "default" direction |
|
630 |
/// of the directed versions of the arcs. |
|
631 |
/// \sa u() |
|
632 |
/// \sa direction() |
|
621 | 633 |
Node v(Edge) const { return INVALID; } |
622 | 634 |
|
623 | 635 |
/// \brief Source node of the directed arc. |
624 | 636 |
Node source(Arc) const { return INVALID; } |
625 | 637 |
|
626 | 638 |
/// \brief Target node of the directed arc. |
627 | 639 |
Node target(Arc) const { return INVALID; } |
628 | 640 |
|
629 | 641 |
/// \brief Returns the id of the node. |
630 | 642 |
int id(Node) const { return -1; } |
631 | 643 |
|
632 | 644 |
/// \brief Returns the id of the edge. |
633 | 645 |
int id(Edge) const { return -1; } |
634 | 646 |
|
635 | 647 |
/// \brief Returns the id of the arc. |
636 | 648 |
int id(Arc) const { return -1; } |
... | ... |
@@ -7,57 +7,56 @@ |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
///\ingroup graph_concepts |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of graph components. |
22 | 22 |
|
23 |
|
|
24 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
25 | 24 |
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
26 | 25 |
|
27 | 26 |
#include <lemon/core.h> |
28 | 27 |
#include <lemon/concepts/maps.h> |
29 | 28 |
|
30 | 29 |
#include <lemon/bits/alteration_notifier.h> |
31 | 30 |
|
32 | 31 |
namespace lemon { |
33 | 32 |
namespace concepts { |
34 | 33 |
|
35 | 34 |
/// \brief Skeleton class for graph Node and Arc types |
36 | 35 |
/// |
37 | 36 |
/// This class describes the interface of Node and Arc (and Edge |
38 | 37 |
/// in undirected graphs) subtypes of graph types. |
39 | 38 |
/// |
40 | 39 |
/// \note This class is a template class so that we can use it to |
41 | 40 |
/// create graph skeleton classes. The reason for this is than Node |
42 | 41 |
/// and Arc types should \em not derive from the same base class. |
43 | 42 |
/// For Node you should instantiate it with character 'n' and for Arc |
44 | 43 |
/// with 'a'. |
45 | 44 |
|
46 | 45 |
#ifndef DOXYGEN |
47 |
template <char |
|
46 |
template <char sel = '0'> |
|
48 | 47 |
#endif |
49 | 48 |
class GraphItem { |
50 | 49 |
public: |
51 | 50 |
/// \brief Default constructor. |
52 | 51 |
/// |
53 | 52 |
/// \warning The default constructor is not required to set |
54 | 53 |
/// the item to some well-defined value. So you should consider it |
55 | 54 |
/// as uninitialized. |
56 | 55 |
GraphItem() {} |
57 | 56 |
/// \brief Copy constructor. |
58 | 57 |
/// |
59 | 58 |
/// Copy constructor. |
60 | 59 |
/// |
61 | 60 |
GraphItem(const GraphItem &) {} |
62 | 61 |
/// \brief Invalid constructor \& conversion. |
63 | 62 |
/// |
... | ... |
@@ -283,37 +282,37 @@ |
283 | 282 |
bool d = graph.direction(e); |
284 | 283 |
ignore_unused_variable_warning(d); |
285 | 284 |
} |
286 | 285 |
} |
287 | 286 |
|
288 | 287 |
const _Graph& graph; |
289 | 288 |
}; |
290 | 289 |
|
291 | 290 |
}; |
292 | 291 |
|
293 | 292 |
/// \brief An empty idable base digraph class. |
294 | 293 |
/// |
295 | 294 |
/// This class provides beside the core digraph features |
296 | 295 |
/// core id functions for the digraph structure. |
297 | 296 |
/// The most of the base digraphs should conform to this concept. |
298 | 297 |
/// The id's are unique and immutable. |
299 |
template <typename _Base = BaseDigraphComponent> |
|
300 |
class IDableDigraphComponent : public _Base { |
|
298 |
template <typename BAS = BaseDigraphComponent> |
|
299 |
class IDableDigraphComponent : public BAS { |
|
301 | 300 |
public: |
302 | 301 |
|
303 |
typedef |
|
302 |
typedef BAS Base; |
|
304 | 303 |
typedef typename Base::Node Node; |
305 | 304 |
typedef typename Base::Arc Arc; |
306 | 305 |
|
307 | 306 |
/// \brief Gives back an unique integer id for the Node. |
308 | 307 |
/// |
309 | 308 |
/// Gives back an unique integer id for the Node. |
310 | 309 |
/// |
311 | 310 |
int id(const Node&) const { return -1;} |
312 | 311 |
|
313 | 312 |
/// \brief Gives back the node by the unique id. |
314 | 313 |
/// |
315 | 314 |
/// Gives back the node by the unique id. |
316 | 315 |
/// If the digraph does not contain node with the given id |
317 | 316 |
/// then the result of the function is undetermined. |
318 | 317 |
Node nodeFromId(int) const { return INVALID;} |
319 | 318 |
|
... | ... |
@@ -361,40 +360,40 @@ |
361 | 360 |
nid = digraph.maxNodeId(); |
362 | 361 |
ignore_unused_variable_warning(nid); |
363 | 362 |
eid = digraph.maxArcId(); |
364 | 363 |
ignore_unused_variable_warning(eid); |
365 | 364 |
} |
366 | 365 |
|
367 | 366 |
const _Digraph& digraph; |
368 | 367 |
}; |
369 | 368 |
}; |
370 | 369 |
|
371 | 370 |
/// \brief An empty idable base undirected graph class. |
372 | 371 |
/// |
373 | 372 |
/// This class provides beside the core undirected graph features |
374 | 373 |
/// core id functions for the undirected graph structure. The |
375 | 374 |
/// most of the base undirected graphs should conform to this |
376 | 375 |
/// concept. The id's are unique and immutable. |
377 |
template <typename _Base = BaseGraphComponent> |
|
378 |
class IDableGraphComponent : public IDableDigraphComponent<_Base> { |
|
376 |
template <typename BAS = BaseGraphComponent> |
|
377 |
class IDableGraphComponent : public IDableDigraphComponent<BAS> { |
|
379 | 378 |
public: |
380 | 379 |
|
381 |
typedef |
|
380 |
typedef BAS Base; |
|
382 | 381 |
typedef typename Base::Edge Edge; |
383 | 382 |
|
384 |
using IDableDigraphComponent< |
|
383 |
using IDableDigraphComponent<Base>::id; |
|
385 | 384 |
|
386 | 385 |
/// \brief Gives back an unique integer id for the Edge. |
387 | 386 |
/// |
388 | 387 |
/// Gives back an unique integer id for the Edge. |
389 | 388 |
/// |
390 | 389 |
int id(const Edge&) const { return -1;} |
391 | 390 |
|
392 | 391 |
/// \brief Gives back the edge by the unique id. |
393 | 392 |
/// |
394 | 393 |
/// Gives back the edge by the unique id. If the |
395 | 394 |
/// graph does not contain arc with the given id then the |
396 | 395 |
/// result of the function is undetermined. |
397 | 396 |
Edge edgeFromId(int) const { return INVALID;} |
398 | 397 |
|
399 | 398 |
/// \brief Gives back an integer greater or equal to the maximum |
400 | 399 |
/// Edge id. |
... | ... |
@@ -412,50 +411,50 @@ |
412 | 411 |
typename _Graph::Edge edge; |
413 | 412 |
int ueid = graph.id(edge); |
414 | 413 |
ueid = graph.id(edge); |
415 | 414 |
edge = graph.edgeFromId(ueid); |
416 | 415 |
ueid = graph.maxEdgeId(); |
417 | 416 |
ignore_unused_variable_warning(ueid); |
418 | 417 |
} |
419 | 418 |
|
420 | 419 |
const _Graph& graph; |
421 | 420 |
}; |
422 | 421 |
}; |
423 | 422 |
|
424 | 423 |
/// \brief Skeleton class for graph NodeIt and ArcIt |
425 | 424 |
/// |
426 | 425 |
/// Skeleton class for graph NodeIt and ArcIt. |
427 | 426 |
/// |
428 |
template <typename _Graph, typename _Item> |
|
429 |
class GraphItemIt : public _Item { |
|
427 |
template <typename GR, typename Item> |
|
428 |
class GraphItemIt : public Item { |
|
430 | 429 |
public: |
431 | 430 |
/// \brief Default constructor. |
432 | 431 |
/// |
433 | 432 |
/// @warning The default constructor sets the iterator |
434 | 433 |
/// to an undefined value. |
435 | 434 |
GraphItemIt() {} |
436 | 435 |
/// \brief Copy constructor. |
437 | 436 |
/// |
438 | 437 |
/// Copy constructor. |
439 | 438 |
/// |
440 | 439 |
GraphItemIt(const GraphItemIt& ) {} |
441 | 440 |
/// \brief Sets the iterator to the first item. |
442 | 441 |
/// |
443 | 442 |
/// Sets the iterator to the first item of \c the graph. |
444 | 443 |
/// |
445 |
explicit GraphItemIt(const |
|
444 |
explicit GraphItemIt(const GR&) {} |
|
446 | 445 |
/// \brief Invalid constructor \& conversion. |
447 | 446 |
/// |
448 | 447 |
/// This constructor initializes the item to be invalid. |
449 | 448 |
/// \sa Invalid for more details. |
450 | 449 |
GraphItemIt(Invalid) {} |
451 | 450 |
/// \brief Assign operator for items. |
452 | 451 |
/// |
453 | 452 |
/// The items are assignable. |
454 | 453 |
/// |
455 | 454 |
GraphItemIt& operator=(const GraphItemIt&) { return *this; } |
456 | 455 |
/// \brief Next item. |
457 | 456 |
/// |
458 | 457 |
/// Assign the iterator to the next item. |
459 | 458 |
/// |
460 | 459 |
GraphItemIt& operator++() { return *this; } |
461 | 460 |
/// \brief Equality operator |
... | ... |
@@ -466,130 +465,130 @@ |
466 | 465 |
/// \brief Inequality operator |
467 | 466 |
/// |
468 | 467 |
/// \sa operator==(Node n) |
469 | 468 |
/// |
470 | 469 |
bool operator!=(const GraphItemIt&) const { return true;} |
471 | 470 |
|
472 | 471 |
template<typename _GraphItemIt> |
473 | 472 |
struct Constraints { |
474 | 473 |
void constraints() { |
475 | 474 |
_GraphItemIt it1(g); |
476 | 475 |
_GraphItemIt it2; |
477 | 476 |
|
478 | 477 |
it2 = ++it1; |
479 | 478 |
++it2 = it1; |
480 | 479 |
++(++it1); |
481 | 480 |
|
482 |
|
|
481 |
Item bi = it1; |
|
483 | 482 |
bi = it2; |
484 | 483 |
} |
485 |
|
|
484 |
GR& g; |
|
486 | 485 |
}; |
487 | 486 |
}; |
488 | 487 |
|
489 | 488 |
/// \brief Skeleton class for graph InArcIt and OutArcIt |
490 | 489 |
/// |
491 | 490 |
/// \note Because InArcIt and OutArcIt may not inherit from the same |
492 |
/// base class, the _selector is a additional template parameter. For |
|
493 |
/// InArcIt you should instantiate it with character 'i' and for |
|
491 |
/// base class, the \c sel is a additional template parameter (selector). |
|
492 |
/// For InArcIt you should instantiate it with character 'i' and for |
|
494 | 493 |
/// OutArcIt with 'o'. |
495 |
template <typename _Graph, |
|
496 |
typename _Item = typename _Graph::Arc, |
|
497 |
typename _Base = typename _Graph::Node, |
|
498 |
char _selector = '0'> |
|
499 |
|
|
494 |
template <typename GR, |
|
495 |
typename Item = typename GR::Arc, |
|
496 |
typename Base = typename GR::Node, |
|
497 |
char sel = '0'> |
|
498 |
class GraphIncIt : public Item { |
|
500 | 499 |
public: |
501 | 500 |
/// \brief Default constructor. |
502 | 501 |
/// |
503 | 502 |
/// @warning The default constructor sets the iterator |
504 | 503 |
/// to an undefined value. |
505 | 504 |
GraphIncIt() {} |
506 | 505 |
/// \brief Copy constructor. |
507 | 506 |
/// |
508 | 507 |
/// Copy constructor. |
509 | 508 |
/// |
510 |
GraphIncIt(GraphIncIt const& gi) : |
|
509 |
GraphIncIt(GraphIncIt const& gi) : Item(gi) {} |
|
511 | 510 |
/// \brief Sets the iterator to the first arc incoming into or outgoing |
512 | 511 |
/// from the node. |
513 | 512 |
/// |
514 | 513 |
/// Sets the iterator to the first arc incoming into or outgoing |
515 | 514 |
/// from the node. |
516 | 515 |
/// |
517 |
explicit GraphIncIt(const |
|
516 |
explicit GraphIncIt(const GR&, const Base&) {} |
|
518 | 517 |
/// \brief Invalid constructor \& conversion. |
519 | 518 |
/// |
520 | 519 |
/// This constructor initializes the item to be invalid. |
521 | 520 |
/// \sa Invalid for more details. |
522 | 521 |
GraphIncIt(Invalid) {} |
523 | 522 |
/// \brief Assign operator for iterators. |
524 | 523 |
/// |
525 | 524 |
/// The iterators are assignable. |
526 | 525 |
/// |
527 | 526 |
GraphIncIt& operator=(GraphIncIt const&) { return *this; } |
528 | 527 |
/// \brief Next item. |
529 | 528 |
/// |
530 | 529 |
/// Assign the iterator to the next item. |
531 | 530 |
/// |
532 | 531 |
GraphIncIt& operator++() { return *this; } |
533 | 532 |
|
534 | 533 |
/// \brief Equality operator |
535 | 534 |
/// |
536 | 535 |
/// Two iterators are equal if and only if they point to the |
537 | 536 |
/// same object or both are invalid. |
538 | 537 |
bool operator==(const GraphIncIt&) const { return true;} |
539 | 538 |
|
540 | 539 |
/// \brief Inequality operator |
541 | 540 |
/// |
542 | 541 |
/// \sa operator==(Node n) |
543 | 542 |
/// |
544 | 543 |
bool operator!=(const GraphIncIt&) const { return true;} |
545 | 544 |
|
546 | 545 |
template <typename _GraphIncIt> |
547 | 546 |
struct Constraints { |
548 | 547 |
void constraints() { |
549 |
checkConcept<GraphItem< |
|
548 |
checkConcept<GraphItem<sel>, _GraphIncIt>(); |
|
550 | 549 |
_GraphIncIt it1(graph, node); |
551 | 550 |
_GraphIncIt it2; |
552 | 551 |
|
553 | 552 |
it2 = ++it1; |
554 | 553 |
++it2 = it1; |
555 | 554 |
++(++it1); |
556 |
|
|
555 |
Item e = it1; |
|
557 | 556 |
e = it2; |
558 | 557 |
|
559 | 558 |
} |
560 | 559 |
|
561 |
_Item arc; |
|
562 |
_Base node; |
|
563 |
|
|
560 |
Item arc; |
|
561 |
Base node; |
|
562 |
GR graph; |
|
564 | 563 |
_GraphIncIt it; |
565 | 564 |
}; |
566 | 565 |
}; |
567 | 566 |
|
568 | 567 |
|
569 | 568 |
/// \brief An empty iterable digraph class. |
570 | 569 |
/// |
571 | 570 |
/// This class provides beside the core digraph features |
572 | 571 |
/// iterator based iterable interface for the digraph structure. |
573 | 572 |
/// This concept is part of the Digraph concept. |
574 |
template <typename _Base = BaseDigraphComponent> |
|
575 |
class IterableDigraphComponent : public _Base { |
|
573 |
template <typename BAS = BaseDigraphComponent> |
|
574 |
class IterableDigraphComponent : public BAS { |
|
576 | 575 |
|
577 | 576 |
public: |
578 | 577 |
|
579 |
typedef |
|
578 |
typedef BAS Base; |
|
580 | 579 |
typedef typename Base::Node Node; |
581 | 580 |
typedef typename Base::Arc Arc; |
582 | 581 |
|
583 | 582 |
typedef IterableDigraphComponent Digraph; |
584 | 583 |
|
585 | 584 |
/// \name Base iteration |
586 | 585 |
/// |
587 | 586 |
/// This interface provides functions for iteration on digraph items |
588 | 587 |
/// |
589 | 588 |
/// @{ |
590 | 589 |
|
591 | 590 |
/// \brief Gives back the first node in the iterating order. |
592 | 591 |
/// |
593 | 592 |
/// Gives back the first node in the iterating order. |
594 | 593 |
/// |
595 | 594 |
void first(Node&) const {} |
... | ... |
@@ -743,51 +742,51 @@ |
743 | 742 |
n = digraph.baseNode(oeit); |
744 | 743 |
n = digraph.runningNode(oeit); |
745 | 744 |
ignore_unused_variable_warning(n); |
746 | 745 |
} |
747 | 746 |
} |
748 | 747 |
|
749 | 748 |
const _Digraph& digraph; |
750 | 749 |
|
751 | 750 |
}; |
752 | 751 |
}; |
753 | 752 |
|
754 | 753 |
/// \brief An empty iterable undirected graph class. |
755 | 754 |
/// |
756 | 755 |
/// This class provides beside the core graph features iterator |
757 | 756 |
/// based iterable interface for the undirected graph structure. |
758 | 757 |
/// This concept is part of the Graph concept. |
759 |
template <typename _Base = BaseGraphComponent> |
|
760 |
class IterableGraphComponent : public IterableDigraphComponent<_Base> { |
|
758 |
template <typename BAS = BaseGraphComponent> |
|
759 |
class IterableGraphComponent : public IterableDigraphComponent<BAS> { |
|
761 | 760 |
public: |
762 | 761 |
|
763 |
typedef |
|
762 |
typedef BAS Base; |
|
764 | 763 |
typedef typename Base::Node Node; |
765 | 764 |
typedef typename Base::Arc Arc; |
766 | 765 |
typedef typename Base::Edge Edge; |
767 | 766 |
|
768 | 767 |
|
769 | 768 |
typedef IterableGraphComponent Graph; |
770 | 769 |
|
771 | 770 |
/// \name Base iteration |
772 | 771 |
/// |
773 | 772 |
/// This interface provides functions for iteration on graph items |
774 | 773 |
/// @{ |
775 | 774 |
|
776 |
using IterableDigraphComponent<_Base>::first; |
|
777 |
using IterableDigraphComponent<_Base>::next; |
|
775 |
using IterableDigraphComponent<Base>::first; |
|
776 |
using IterableDigraphComponent<Base>::next; |
|
778 | 777 |
|
779 | 778 |
/// \brief Gives back the first edge in the iterating |
780 | 779 |
/// order. |
781 | 780 |
/// |
782 | 781 |
/// Gives back the first edge in the iterating order. |
783 | 782 |
/// |
784 | 783 |
void first(Edge&) const {} |
785 | 784 |
|
786 | 785 |
/// \brief Gives back the next edge in the iterating |
787 | 786 |
/// order. |
788 | 787 |
/// |
789 | 788 |
/// Gives back the next edge in the iterating order. |
790 | 789 |
/// |
791 | 790 |
void next(Edge&) const {} |
792 | 791 |
|
793 | 792 |
|
... | ... |
@@ -795,34 +794,34 @@ |
795 | 794 |
/// given node. |
796 | 795 |
/// |
797 | 796 |
/// Gives back the first of the edges from the given |
798 | 797 |
/// node. The bool parameter gives back that direction which |
799 | 798 |
/// gives a good direction of the edge so the source of the |
800 | 799 |
/// directed arc is the given node. |
801 | 800 |
void firstInc(Edge&, bool&, const Node&) const {} |
802 | 801 |
|
803 | 802 |
/// \brief Gives back the next of the edges from the |
804 | 803 |
/// given node. |
805 | 804 |
/// |
806 | 805 |
/// Gives back the next of the edges from the given |
807 | 806 |
/// node. The bool parameter should be used as the \c firstInc() |
808 | 807 |
/// use it. |
809 | 808 |
void nextInc(Edge&, bool&) const {} |
810 | 809 |
|
811 |
using IterableDigraphComponent<_Base>::baseNode; |
|
812 |
using IterableDigraphComponent<_Base>::runningNode; |
|
810 |
using IterableDigraphComponent<Base>::baseNode; |
|
811 |
using IterableDigraphComponent<Base>::runningNode; |
|
813 | 812 |
|
814 | 813 |
/// @} |
815 | 814 |
|
816 | 815 |
/// \name Class based iteration |
817 | 816 |
/// |
818 | 817 |
/// This interface provides functions for iteration on graph items |
819 | 818 |
/// |
820 | 819 |
/// @{ |
821 | 820 |
|
822 | 821 |
/// \brief This iterator goes through each node. |
823 | 822 |
/// |
824 | 823 |
/// This iterator goes through each node. |
825 | 824 |
typedef GraphItemIt<Graph, Edge> EdgeIt; |
826 | 825 |
/// \brief This iterator goes trough the incident arcs of a |
827 | 826 |
/// node. |
828 | 827 |
/// |
... | ... |
@@ -862,49 +861,48 @@ |
862 | 861 |
} |
863 | 862 |
|
864 | 863 |
{ |
865 | 864 |
checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>, |
866 | 865 |
typename _Graph::EdgeIt >(); |
867 | 866 |
checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, |
868 | 867 |
typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>(); |
869 | 868 |
|
870 | 869 |
typename _Graph::Node n; |
871 | 870 |
typename _Graph::IncEdgeIt ueit(INVALID); |
872 | 871 |
n = graph.baseNode(ueit); |
873 | 872 |
n = graph.runningNode(ueit); |
874 | 873 |
} |
875 | 874 |
} |
876 | 875 |
|
877 | 876 |
const _Graph& graph; |
878 |
|
|
879 | 877 |
}; |
880 | 878 |
}; |
881 | 879 |
|
882 | 880 |
/// \brief An empty alteration notifier digraph class. |
883 | 881 |
/// |
884 | 882 |
/// This class provides beside the core digraph features alteration |
885 | 883 |
/// notifier interface for the digraph structure. This implements |
886 | 884 |
/// an observer-notifier pattern for each digraph item. More |
887 | 885 |
/// obsevers can be registered into the notifier and whenever an |
888 | 886 |
/// alteration occured in the digraph all the observers will |
889 | 887 |
/// notified about it. |
890 |
template <typename _Base = BaseDigraphComponent> |
|
891 |
class AlterableDigraphComponent : public _Base { |
|
888 |
template <typename BAS = BaseDigraphComponent> |
|
889 |
class AlterableDigraphComponent : public BAS { |
|
892 | 890 |
public: |
893 | 891 |
|
894 |
typedef |
|
892 |
typedef BAS Base; |
|
895 | 893 |
typedef typename Base::Node Node; |
896 | 894 |
typedef typename Base::Arc Arc; |
897 | 895 |
|
898 | 896 |
|
899 | 897 |
/// The node observer registry. |
900 | 898 |
typedef AlterationNotifier<AlterableDigraphComponent, Node> |
901 | 899 |
NodeNotifier; |
902 | 900 |
/// The arc observer registry. |
903 | 901 |
typedef AlterationNotifier<AlterableDigraphComponent, Arc> |
904 | 902 |
ArcNotifier; |
905 | 903 |
|
906 | 904 |
/// \brief Gives back the node alteration notifier. |
907 | 905 |
/// |
908 | 906 |
/// Gives back the node alteration notifier. |
909 | 907 |
NodeNotifier& notifier(Node) const { |
910 | 908 |
return NodeNotifier(); |
... | ... |
@@ -932,83 +930,81 @@ |
932 | 930 |
} |
933 | 931 |
|
934 | 932 |
const _Digraph& digraph; |
935 | 933 |
|
936 | 934 |
}; |
937 | 935 |
|
938 | 936 |
}; |
939 | 937 |
|
940 | 938 |
/// \brief An empty alteration notifier undirected graph class. |
941 | 939 |
/// |
942 | 940 |
/// This class provides beside the core graph features alteration |
943 | 941 |
/// notifier interface for the graph structure. This implements |
944 | 942 |
/// an observer-notifier pattern for each graph item. More |
945 | 943 |
/// obsevers can be registered into the notifier and whenever an |
946 | 944 |
/// alteration occured in the graph all the observers will |
947 | 945 |
/// notified about it. |
948 |
template <typename _Base = BaseGraphComponent> |
|
949 |
class AlterableGraphComponent : public AlterableDigraphComponent<_Base> { |
|
946 |
template <typename BAS = BaseGraphComponent> |
|
947 |
class AlterableGraphComponent : public AlterableDigraphComponent<BAS> { |
|
950 | 948 |
public: |
951 | 949 |
|
952 |
typedef |
|
950 |
typedef BAS Base; |
|
953 | 951 |
typedef typename Base::Edge Edge; |
954 | 952 |
|
955 | 953 |
|
956 | 954 |
/// The arc observer registry. |
957 | 955 |
typedef AlterationNotifier<AlterableGraphComponent, Edge> |
958 | 956 |
EdgeNotifier; |
959 | 957 |
|
960 | 958 |
/// \brief Gives back the arc alteration notifier. |
961 | 959 |
/// |
962 | 960 |
/// Gives back the arc alteration notifier. |
963 | 961 |
EdgeNotifier& notifier(Edge) const { |
964 | 962 |
return EdgeNotifier(); |
965 | 963 |
} |
966 | 964 |
|
967 | 965 |
template <typename _Graph> |
968 | 966 |
struct Constraints { |
969 | 967 |
void constraints() { |
970 | 968 |
checkConcept<AlterableGraphComponent<Base>, _Graph>(); |
971 | 969 |
typename _Graph::EdgeNotifier& uen |
972 | 970 |
= graph.notifier(typename _Graph::Edge()); |
973 | 971 |
ignore_unused_variable_warning(uen); |
974 | 972 |
} |
975 | 973 |
|
976 | 974 |
const _Graph& graph; |
977 |
|
|
978 | 975 |
}; |
979 |
|
|
980 | 976 |
}; |
981 | 977 |
|
982 | 978 |
/// \brief Class describing the concept of graph maps |
983 | 979 |
/// |
984 | 980 |
/// This class describes the common interface of the graph maps |
985 | 981 |
/// (NodeMap, ArcMap), that is maps that can be used to |
986 | 982 |
/// associate data to graph descriptors (nodes or arcs). |
987 |
template <typename _Graph, typename _Item, typename _Value> |
|
988 |
class GraphMap : public ReadWriteMap<_Item, _Value> { |
|
983 |
template <typename GR, typename K, typename V> |
|
984 |
class GraphMap : public ReadWriteMap<K, V> { |
|
989 | 985 |
public: |
990 | 986 |
|
991 |
typedef ReadWriteMap< |
|
987 |
typedef ReadWriteMap<K, V> Parent; |
|
992 | 988 |
|
993 | 989 |
/// The graph type of the map. |
994 |
typedef |
|
990 |
typedef GR Graph; |
|
995 | 991 |
/// The key type of the map. |
996 |
typedef |
|
992 |
typedef K Key; |
|
997 | 993 |
/// The value type of the map. |
998 |
typedef |
|
994 |
typedef V Value; |
|
999 | 995 |
|
1000 | 996 |
/// \brief Construct a new map. |
1001 | 997 |
/// |
1002 | 998 |
/// Construct a new map for the graph. |
1003 | 999 |
explicit GraphMap(const Graph&) {} |
1004 | 1000 |
/// \brief Construct a new map with default value. |
1005 | 1001 |
/// |
1006 | 1002 |
/// Construct a new map for the graph and initalise the values. |
1007 | 1003 |
GraphMap(const Graph&, const Value&) {} |
1008 | 1004 |
|
1009 | 1005 |
private: |
1010 | 1006 |
/// \brief Copy constructor. |
1011 | 1007 |
/// |
1012 | 1008 |
/// Copy Constructor. |
1013 | 1009 |
GraphMap(const GraphMap&) : Parent() {} |
1014 | 1010 |
|
... | ... |
@@ -1042,113 +1038,113 @@ |
1042 | 1038 |
ignore_unused_variable_warning(a2); |
1043 | 1039 |
// ignore_unused_variable_warning(b); |
1044 | 1040 |
} |
1045 | 1041 |
|
1046 | 1042 |
const _Map &c; |
1047 | 1043 |
const Graph &g; |
1048 | 1044 |
const typename GraphMap::Value &t; |
1049 | 1045 |
}; |
1050 | 1046 |
|
1051 | 1047 |
}; |
1052 | 1048 |
|
1053 | 1049 |
/// \brief An empty mappable digraph class. |
1054 | 1050 |
/// |
1055 | 1051 |
/// This class provides beside the core digraph features |
1056 | 1052 |
/// map interface for the digraph structure. |
1057 | 1053 |
/// This concept is part of the Digraph concept. |
1058 |
template <typename _Base = BaseDigraphComponent> |
|
1059 |
class MappableDigraphComponent : public _Base { |
|
1054 |
template <typename BAS = BaseDigraphComponent> |
|
1055 |
class MappableDigraphComponent : public BAS { |
|
1060 | 1056 |
public: |
1061 | 1057 |
|
1062 |
typedef |
|
1058 |
typedef BAS Base; |
|
1063 | 1059 |
typedef typename Base::Node Node; |
1064 | 1060 |
typedef typename Base::Arc Arc; |
1065 | 1061 |
|
1066 | 1062 |
typedef MappableDigraphComponent Digraph; |
1067 | 1063 |
|
1068 | 1064 |
/// \brief ReadWrite map of the nodes. |
1069 | 1065 |
/// |
1070 | 1066 |
/// ReadWrite map of the nodes. |
1071 | 1067 |
/// |
1072 |
template <typename _Value> |
|
1073 |
class NodeMap : public GraphMap<Digraph, Node, _Value> { |
|
1068 |
template <typename V> |
|
1069 |
class NodeMap : public GraphMap<Digraph, Node, V> { |
|
1074 | 1070 |
public: |
1075 |
typedef GraphMap<MappableDigraphComponent, Node, |
|
1071 |
typedef GraphMap<MappableDigraphComponent, Node, V> Parent; |
|
1076 | 1072 |
|
1077 | 1073 |
/// \brief Construct a new map. |
1078 | 1074 |
/// |
1079 | 1075 |
/// Construct a new map for the digraph. |
1080 | 1076 |
explicit NodeMap(const MappableDigraphComponent& digraph) |
1081 | 1077 |
: Parent(digraph) {} |
1082 | 1078 |
|
1083 | 1079 |
/// \brief Construct a new map with default value. |
1084 | 1080 |
/// |
1085 | 1081 |
/// Construct a new map for the digraph and initalise the values. |
1086 |
NodeMap(const MappableDigraphComponent& digraph, const |
|
1082 |
NodeMap(const MappableDigraphComponent& digraph, const V& value) |
|
1087 | 1083 |
: Parent(digraph, value) {} |
1088 | 1084 |
|
1089 | 1085 |
private: |
1090 | 1086 |
/// \brief Copy constructor. |
1091 | 1087 |
/// |
1092 | 1088 |
/// Copy Constructor. |
1093 | 1089 |
NodeMap(const NodeMap& nm) : Parent(nm) {} |
1094 | 1090 |
|
1095 | 1091 |
/// \brief Assign operator. |
1096 | 1092 |
/// |
1097 | 1093 |
/// Assign operator. |
1098 | 1094 |
template <typename CMap> |
1099 | 1095 |
NodeMap& operator=(const CMap&) { |
1100 |
checkConcept<ReadMap<Node, |
|
1096 |
checkConcept<ReadMap<Node, V>, CMap>(); |
|
1101 | 1097 |
return *this; |
1102 | 1098 |
} |
1103 | 1099 |
|
1104 | 1100 |
}; |
1105 | 1101 |
|
1106 | 1102 |
/// \brief ReadWrite map of the arcs. |
1107 | 1103 |
/// |
1108 | 1104 |
/// ReadWrite map of the arcs. |
1109 | 1105 |
/// |
1110 |
template <typename _Value> |
|
1111 |
class ArcMap : public GraphMap<Digraph, Arc, _Value> { |
|
1106 |
template <typename V> |
|
1107 |
class ArcMap : public GraphMap<Digraph, Arc, V> { |
|
1112 | 1108 |
public: |
1113 |
typedef GraphMap<MappableDigraphComponent, Arc, |
|
1109 |
typedef GraphMap<MappableDigraphComponent, Arc, V> Parent; |
|
1114 | 1110 |
|
1115 | 1111 |
/// \brief Construct a new map. |
1116 | 1112 |
/// |
1117 | 1113 |
/// Construct a new map for the digraph. |
1118 | 1114 |
explicit ArcMap(const MappableDigraphComponent& digraph) |
1119 | 1115 |
: Parent(digraph) {} |
1120 | 1116 |
|
1121 | 1117 |
/// \brief Construct a new map with default value. |
1122 | 1118 |
/// |
1123 | 1119 |
/// Construct a new map for the digraph and initalise the values. |
1124 |
ArcMap(const MappableDigraphComponent& digraph, const |
|
1120 |
ArcMap(const MappableDigraphComponent& digraph, const V& value) |
|
1125 | 1121 |
: Parent(digraph, value) {} |
1126 | 1122 |
|
1127 | 1123 |
private: |
1128 | 1124 |
/// \brief Copy constructor. |
1129 | 1125 |
/// |
1130 | 1126 |
/// Copy Constructor. |
1131 | 1127 |
ArcMap(const ArcMap& nm) : Parent(nm) {} |
1132 | 1128 |
|
1133 | 1129 |
/// \brief Assign operator. |
1134 | 1130 |
/// |
1135 | 1131 |
/// Assign operator. |
1136 | 1132 |
template <typename CMap> |
1137 | 1133 |
ArcMap& operator=(const CMap&) { |
1138 |
checkConcept<ReadMap<Arc, |
|
1134 |
checkConcept<ReadMap<Arc, V>, CMap>(); |
|
1139 | 1135 |
return *this; |
1140 | 1136 |
} |
1141 | 1137 |
|
1142 | 1138 |
}; |
1143 | 1139 |
|
1144 | 1140 |
|
1145 | 1141 |
template <typename _Digraph> |
1146 | 1142 |
struct Constraints { |
1147 | 1143 |
|
1148 | 1144 |
struct Dummy { |
1149 | 1145 |
int value; |
1150 | 1146 |
Dummy() : value(0) {} |
1151 | 1147 |
Dummy(int _v) : value(_v) {} |
1152 | 1148 |
}; |
1153 | 1149 |
|
1154 | 1150 |
void constraints() { |
... | ... |
@@ -1178,74 +1174,74 @@ |
1178 | 1174 |
} { // Dummy map test |
1179 | 1175 |
typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap; |
1180 | 1176 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>, |
1181 | 1177 |
DummyArcMap >(); |
1182 | 1178 |
} |
1183 | 1179 |
} |
1184 | 1180 |
|
1185 | 1181 |
_Digraph& digraph; |
1186 | 1182 |
}; |
1187 | 1183 |
}; |
1188 | 1184 |
|
1189 | 1185 |
/// \brief An empty mappable base bipartite graph class. |
1190 | 1186 |
/// |
1191 | 1187 |
/// This class provides beside the core graph features |
1192 | 1188 |
/// map interface for the graph structure. |
1193 | 1189 |
/// This concept is part of the Graph concept. |
1194 |
template <typename _Base = BaseGraphComponent> |
|
1195 |
class MappableGraphComponent : public MappableDigraphComponent<_Base> { |
|
1190 |
template <typename BAS = BaseGraphComponent> |
|
1191 |
class MappableGraphComponent : public MappableDigraphComponent<BAS> { |
|
1196 | 1192 |
public: |
1197 | 1193 |
|
1198 |
typedef |
|
1194 |
typedef BAS Base; |
|
1199 | 1195 |
typedef typename Base::Edge Edge; |
1200 | 1196 |
|
1201 | 1197 |
typedef MappableGraphComponent Graph; |
1202 | 1198 |
|
1203 | 1199 |
/// \brief ReadWrite map of the edges. |
1204 | 1200 |
/// |
1205 | 1201 |
/// ReadWrite map of the edges. |
1206 | 1202 |
/// |
1207 |
template <typename _Value> |
|
1208 |
class EdgeMap : public GraphMap<Graph, Edge, _Value> { |
|
1203 |
template <typename V> |
|
1204 |
class EdgeMap : public GraphMap<Graph, Edge, V> { |
|
1209 | 1205 |
public: |
1210 |
typedef GraphMap<MappableGraphComponent, Edge, |
|
1206 |
typedef GraphMap<MappableGraphComponent, Edge, V> Parent; |
|
1211 | 1207 |
|
1212 | 1208 |
/// \brief Construct a new map. |
1213 | 1209 |
/// |
1214 | 1210 |
/// Construct a new map for the graph. |
1215 | 1211 |
explicit EdgeMap(const MappableGraphComponent& graph) |
1216 | 1212 |
: Parent(graph) {} |
1217 | 1213 |
|
1218 | 1214 |
/// \brief Construct a new map with default value. |
1219 | 1215 |
/// |
1220 | 1216 |
/// Construct a new map for the graph and initalise the values. |
1221 |
EdgeMap(const MappableGraphComponent& graph, const |
|
1217 |
EdgeMap(const MappableGraphComponent& graph, const V& value) |
|
1222 | 1218 |
: Parent(graph, value) {} |
1223 | 1219 |
|
1224 | 1220 |
private: |
1225 | 1221 |
/// \brief Copy constructor. |
1226 | 1222 |
/// |
1227 | 1223 |
/// Copy Constructor. |
1228 | 1224 |
EdgeMap(const EdgeMap& nm) : Parent(nm) {} |
1229 | 1225 |
|
1230 | 1226 |
/// \brief Assign operator. |
1231 | 1227 |
/// |
1232 | 1228 |
/// Assign operator. |
1233 | 1229 |
template <typename CMap> |
1234 | 1230 |
EdgeMap& operator=(const CMap&) { |
1235 |
checkConcept<ReadMap<Edge, |
|
1231 |
checkConcept<ReadMap<Edge, V>, CMap>(); |
|
1236 | 1232 |
return *this; |
1237 | 1233 |
} |
1238 | 1234 |
|
1239 | 1235 |
}; |
1240 | 1236 |
|
1241 | 1237 |
|
1242 | 1238 |
template <typename _Graph> |
1243 | 1239 |
struct Constraints { |
1244 | 1240 |
|
1245 | 1241 |
struct Dummy { |
1246 | 1242 |
int value; |
1247 | 1243 |
Dummy() : value(0) {} |
1248 | 1244 |
Dummy(int _v) : value(_v) {} |
1249 | 1245 |
}; |
1250 | 1246 |
|
1251 | 1247 |
void constraints() { |
... | ... |
@@ -1263,39 +1259,39 @@ |
1263 | 1259 |
typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap; |
1264 | 1260 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>, |
1265 | 1261 |
DummyEdgeMap >(); |
1266 | 1262 |
} |
1267 | 1263 |
} |
1268 | 1264 |
|
1269 | 1265 |
_Graph& graph; |
1270 | 1266 |
}; |
1271 | 1267 |
}; |
1272 | 1268 |
|
1273 | 1269 |
/// \brief An empty extendable digraph class. |
1274 | 1270 |
/// |
1275 | 1271 |
/// This class provides beside the core digraph features digraph |
1276 | 1272 |
/// extendable interface for the digraph structure. The main |
1277 | 1273 |
/// difference between the base and this interface is that the |
1278 | 1274 |
/// digraph alterations should handled already on this level. |
1279 |
template <typename _Base = BaseDigraphComponent> |
|
1280 |
class ExtendableDigraphComponent : public _Base { |
|
1275 |
template <typename BAS = BaseDigraphComponent> |
|
1276 |
class ExtendableDigraphComponent : public BAS { |
|
1281 | 1277 |
public: |
1282 |
typedef |
|
1278 |
typedef BAS Base; |
|
1283 | 1279 |
|
1284 |
typedef typename _Base::Node Node; |
|
1285 |
typedef typename _Base::Arc Arc; |
|
1280 |
typedef typename Base::Node Node; |
|
1281 |
typedef typename Base::Arc Arc; |
|
1286 | 1282 |
|
1287 | 1283 |
/// \brief Adds a new node to the digraph. |
1288 | 1284 |
/// |
1289 | 1285 |
/// Adds a new node to the digraph. |
1290 | 1286 |
/// |
1291 | 1287 |
Node addNode() { |
1292 | 1288 |
return INVALID; |
1293 | 1289 |
} |
1294 | 1290 |
|
1295 | 1291 |
/// \brief Adds a new arc connects the given two nodes. |
1296 | 1292 |
/// |
1297 | 1293 |
/// Adds a new arc connects the the given two nodes. |
1298 | 1294 |
Arc addArc(const Node&, const Node&) { |
1299 | 1295 |
return INVALID; |
1300 | 1296 |
} |
1301 | 1297 |
|
... | ... |
@@ -1308,39 +1304,39 @@ |
1308 | 1304 |
node_b = digraph.addNode(); |
1309 | 1305 |
typename _Digraph::Arc arc; |
1310 | 1306 |
arc = digraph.addArc(node_a, node_b); |
1311 | 1307 |
} |
1312 | 1308 |
|
1313 | 1309 |
_Digraph& digraph; |
1314 | 1310 |
}; |
1315 | 1311 |
}; |
1316 | 1312 |
|
1317 | 1313 |
/// \brief An empty extendable base undirected graph class. |
1318 | 1314 |
/// |
1319 | 1315 |
/// This class provides beside the core undirected graph features |
1320 | 1316 |
/// core undircted graph extend interface for the graph structure. |
1321 | 1317 |
/// The main difference between the base and this interface is |
1322 | 1318 |
/// that the graph alterations should handled already on this |
1323 | 1319 |
/// level. |
1324 |
template <typename _Base = BaseGraphComponent> |
|
1325 |
class ExtendableGraphComponent : public _Base { |
|
1320 |
template <typename BAS = BaseGraphComponent> |
|
1321 |
class ExtendableGraphComponent : public BAS { |
|
1326 | 1322 |
public: |
1327 | 1323 |
|
1328 |
typedef _Base Base; |
|
1329 |
typedef typename _Base::Node Node; |
|
1330 |
typedef |
|
1324 |
typedef BAS Base; |
|
1325 |
typedef typename Base::Node Node; |
|
1326 |
typedef typename Base::Edge Edge; |
|
1331 | 1327 |
|
1332 | 1328 |
/// \brief Adds a new node to the graph. |
1333 | 1329 |
/// |
1334 | 1330 |
/// Adds a new node to the graph. |
1335 | 1331 |
/// |
1336 | 1332 |
Node addNode() { |
1337 | 1333 |
return INVALID; |
1338 | 1334 |
} |
1339 | 1335 |
|
1340 | 1336 |
/// \brief Adds a new arc connects the given two nodes. |
1341 | 1337 |
/// |
1342 | 1338 |
/// Adds a new arc connects the the given two nodes. |
1343 | 1339 |
Edge addArc(const Node&, const Node&) { |
1344 | 1340 |
return INVALID; |
1345 | 1341 |
} |
1346 | 1342 |
|
... | ... |
@@ -1352,37 +1348,37 @@ |
1352 | 1348 |
node_a = graph.addNode(); |
1353 | 1349 |
node_b = graph.addNode(); |
1354 | 1350 |
typename _Graph::Edge edge; |
1355 | 1351 |
edge = graph.addEdge(node_a, node_b); |
1356 | 1352 |
} |
1357 | 1353 |
|
1358 | 1354 |
_Graph& graph; |
1359 | 1355 |
}; |
1360 | 1356 |
}; |
1361 | 1357 |
|
1362 | 1358 |
/// \brief An empty erasable digraph class. |
1363 | 1359 |
/// |
1364 | 1360 |
/// This class provides beside the core digraph features core erase |
1365 | 1361 |
/// functions for the digraph structure. The main difference between |
1366 | 1362 |
/// the base and this interface is that the digraph alterations |
1367 | 1363 |
/// should handled already on this level. |
1368 |
template <typename _Base = BaseDigraphComponent> |
|
1369 |
class ErasableDigraphComponent : public _Base { |
|
1364 |
template <typename BAS = BaseDigraphComponent> |
|
1365 |
class ErasableDigraphComponent : public BAS { |
|
1370 | 1366 |
public: |
1371 | 1367 |
|
1372 |
typedef |
|
1368 |
typedef BAS Base; |
|
1373 | 1369 |
typedef typename Base::Node Node; |
1374 | 1370 |
typedef typename Base::Arc Arc; |
1375 | 1371 |
|
1376 | 1372 |
/// \brief Erase a node from the digraph. |
1377 | 1373 |
/// |
1378 | 1374 |
/// Erase a node from the digraph. This function should |
1379 | 1375 |
/// erase all arcs connecting to the node. |
1380 | 1376 |
void erase(const Node&) {} |
1381 | 1377 |
|
1382 | 1378 |
/// \brief Erase an arc from the digraph. |
1383 | 1379 |
/// |
1384 | 1380 |
/// Erase an arc from the digraph. |
1385 | 1381 |
/// |
1386 | 1382 |
void erase(const Arc&) {} |
1387 | 1383 |
|
1388 | 1384 |
template <typename _Digraph> |
... | ... |
@@ -1392,37 +1388,37 @@ |
1392 | 1388 |
typename _Digraph::Node node; |
1393 | 1389 |
digraph.erase(node); |
1394 | 1390 |
typename _Digraph::Arc arc; |
1395 | 1391 |
digraph.erase(arc); |
1396 | 1392 |
} |
1397 | 1393 |
|
1398 | 1394 |
_Digraph& digraph; |
1399 | 1395 |
}; |
1400 | 1396 |
}; |
1401 | 1397 |
|
1402 | 1398 |
/// \brief An empty erasable base undirected graph class. |
1403 | 1399 |
/// |
1404 | 1400 |
/// This class provides beside the core undirected graph features |
1405 | 1401 |
/// core erase functions for the undirceted graph structure. The |
1406 | 1402 |
/// main difference between the base and this interface is that |
1407 | 1403 |
/// the graph alterations should handled already on this level. |
1408 |
template <typename _Base = BaseGraphComponent> |
|
1409 |
class ErasableGraphComponent : public _Base { |
|
1404 |
template <typename BAS = BaseGraphComponent> |
|
1405 |
class ErasableGraphComponent : public BAS { |
|
1410 | 1406 |
public: |
1411 | 1407 |
|
1412 |
typedef |
|
1408 |
typedef BAS Base; |
|
1413 | 1409 |
typedef typename Base::Node Node; |
1414 | 1410 |
typedef typename Base::Edge Edge; |
1415 | 1411 |
|
1416 | 1412 |
/// \brief Erase a node from the graph. |
1417 | 1413 |
/// |
1418 | 1414 |
/// Erase a node from the graph. This function should erase |
1419 | 1415 |
/// arcs connecting to the node. |
1420 | 1416 |
void erase(const Node&) {} |
1421 | 1417 |
|
1422 | 1418 |
/// \brief Erase an arc from the graph. |
1423 | 1419 |
/// |
1424 | 1420 |
/// Erase an arc from the graph. |
1425 | 1421 |
/// |
1426 | 1422 |
void erase(const Edge&) {} |
1427 | 1423 |
|
1428 | 1424 |
template <typename _Graph> |
... | ... |
@@ -1432,66 +1428,66 @@ |
1432 | 1428 |
typename _Graph::Node node; |
1433 | 1429 |
graph.erase(node); |
1434 | 1430 |
typename _Graph::Edge edge; |
1435 | 1431 |
graph.erase(edge); |
1436 | 1432 |
} |
1437 | 1433 |
|
1438 | 1434 |
_Graph& graph; |
1439 | 1435 |
}; |
1440 | 1436 |
}; |
1441 | 1437 |
|
1442 | 1438 |
/// \brief An empty clearable base digraph class. |
1443 | 1439 |
/// |
1444 | 1440 |
/// This class provides beside the core digraph features core clear |
1445 | 1441 |
/// functions for the digraph structure. The main difference between |
1446 | 1442 |
/// the base and this interface is that the digraph alterations |
1447 | 1443 |
/// should handled already on this level. |
1448 |
template <typename _Base = BaseDigraphComponent> |
|
1449 |
class ClearableDigraphComponent : public _Base { |
|
1444 |
template <typename BAS = BaseDigraphComponent> |
|
1445 |
class ClearableDigraphComponent : public BAS { |
|
1450 | 1446 |
public: |
1451 | 1447 |
|
1452 |
typedef |
|
1448 |
typedef BAS Base; |
|
1453 | 1449 |
|
1454 | 1450 |
/// \brief Erase all nodes and arcs from the digraph. |
1455 | 1451 |
/// |
1456 | 1452 |
/// Erase all nodes and arcs from the digraph. |
1457 | 1453 |
/// |
1458 | 1454 |
void clear() {} |
1459 | 1455 |
|
1460 | 1456 |
template <typename _Digraph> |
1461 | 1457 |
struct Constraints { |
1462 | 1458 |
void constraints() { |
1463 | 1459 |
checkConcept<Base, _Digraph>(); |
1464 | 1460 |
digraph.clear(); |
1465 | 1461 |
} |
1466 | 1462 |
|
1467 | 1463 |
_Digraph digraph; |
1468 | 1464 |
}; |
1469 | 1465 |
}; |
1470 | 1466 |
|
1471 | 1467 |
/// \brief An empty clearable base undirected graph class. |
1472 | 1468 |
/// |
1473 | 1469 |
/// This class provides beside the core undirected graph features |
1474 | 1470 |
/// core clear functions for the undirected graph structure. The |
1475 | 1471 |
/// main difference between the base and this interface is that |
1476 | 1472 |
/// the graph alterations should handled already on this level. |
1477 |
template <typename _Base = BaseGraphComponent> |
|
1478 |
class ClearableGraphComponent : public ClearableDigraphComponent<_Base> { |
|
1473 |
template <typename BAS = BaseGraphComponent> |
|
1474 |
class ClearableGraphComponent : public ClearableDigraphComponent<BAS> { |
|
1479 | 1475 |
public: |
1480 | 1476 |
|
1481 |
typedef |
|
1477 |
typedef BAS Base; |
|
1482 | 1478 |
|
1483 | 1479 |
template <typename _Graph> |
1484 | 1480 |
struct Constraints { |
1485 | 1481 |
void constraints() { |
1486 | 1482 |
checkConcept<ClearableGraphComponent<Base>, _Graph>(); |
1487 | 1483 |
} |
1488 | 1484 |
|
1489 | 1485 |
_Graph graph; |
1490 | 1486 |
}; |
1491 | 1487 |
}; |
1492 | 1488 |
|
1493 | 1489 |
} |
1494 | 1490 |
|
1495 | 1491 |
} |
1496 | 1492 |
|
1497 | 1493 |
#endif |
... | ... |
@@ -22,56 +22,71 @@ |
22 | 22 |
|
23 | 23 |
#ifndef LEMON_CONCEPTS_HEAP_H |
24 | 24 |
#define LEMON_CONCEPTS_HEAP_H |
25 | 25 |
|
26 | 26 |
#include <lemon/core.h> |
27 | 27 |
#include <lemon/concept_check.h> |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup concept |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// \brief The heap concept. |
37 | 37 |
/// |
38 |
/// Concept class describing the main interface of heaps. |
|
39 |
template <typename Priority, typename ItemIntMap> |
|
38 |
/// Concept class describing the main interface of heaps. A \e heap |
|
39 |
/// is a data structure for storing items with specified values called |
|
40 |
/// \e priorities in such a way that finding the item with minimum |
|
41 |
/// priority is efficient. In a heap one can change the priority of an |
|
42 |
/// item, add or erase an item, etc. |
|
43 |
/// |
|
44 |
/// \tparam PR Type of the priority of the items. |
|
45 |
/// \tparam IM A read and writable item map with int values, used |
|
46 |
/// internally to handle the cross references. |
|
47 |
/// \tparam Comp A functor class for the ordering of the priorities. |
|
48 |
/// The default is \c std::less<PR>. |
|
49 |
#ifdef DOXYGEN |
|
50 |
template <typename PR, typename IM, typename Comp = std::less<PR> > |
|
51 |
#else |
|
52 |
template <typename PR, typename IM> |
|
53 |
#endif |
|
40 | 54 |
class Heap { |
41 | 55 |
public: |
42 | 56 |
|
57 |
/// Type of the item-int map. |
|
58 |
typedef IM ItemIntMap; |
|
59 |
/// Type of the priorities. |
|
60 |
typedef PR Prio; |
|
43 | 61 |
/// Type of the items stored in the heap. |
44 | 62 |
typedef typename ItemIntMap::Key Item; |
45 | 63 |
|
46 |
/// Type of the priorities. |
|
47 |
typedef Priority Prio; |
|
48 |
|
|
49 | 64 |
/// \brief Type to represent the states of the items. |
50 | 65 |
/// |
51 | 66 |
/// Each item has a state associated to it. It can be "in heap", |
52 | 67 |
/// "pre heap" or "post heap". The later two are indifferent |
53 | 68 |
/// from the point of view of the heap, but may be useful for |
54 | 69 |
/// the user. |
55 | 70 |
/// |
56 |
/// The \c ItemIntMap must be initialized in such a way, that it |
|
57 |
/// assigns \c PRE_HEAP (<tt>-1</tt>) to every item. |
|
71 |
/// The item-int map must be initialized in such way that it assigns |
|
72 |
/// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap. |
|
58 | 73 |
enum State { |
59 |
IN_HEAP = 0, |
|
60 |
PRE_HEAP = -1, |
|
61 |
|
|
74 |
IN_HEAP = 0, ///< The "in heap" state constant. |
|
75 |
PRE_HEAP = -1, ///< The "pre heap" state constant. |
|
76 |
POST_HEAP = -2 ///< The "post heap" state constant. |
|
62 | 77 |
}; |
63 | 78 |
|
64 | 79 |
/// \brief The constructor. |
65 | 80 |
/// |
66 | 81 |
/// The constructor. |
67 | 82 |
/// \param map A map that assigns \c int values to keys of type |
68 | 83 |
/// \c Item. It is used internally by the heap implementations to |
69 | 84 |
/// handle the cross references. The assigned value must be |
70 | 85 |
/// \c PRE_HEAP (<tt>-1</tt>) for every item. |
71 | 86 |
explicit Heap(ItemIntMap &map) {} |
72 | 87 |
|
73 | 88 |
/// \brief The number of items stored in the heap. |
74 | 89 |
/// |
75 | 90 |
/// Returns the number of items stored in the heap. |
76 | 91 |
int size() const { return 0; } |
77 | 92 |
|
... | ... |
@@ -106,61 +121,61 @@ |
106 | 121 |
|
107 | 122 |
/// \brief Removes the item having minimum priority. |
108 | 123 |
/// |
109 | 124 |
/// Removes the item having minimum priority. |
110 | 125 |
/// \pre The heap must be non-empty. |
111 | 126 |
void pop() {} |
112 | 127 |
|
113 | 128 |
/// \brief Removes an item from the heap. |
114 | 129 |
/// |
115 | 130 |
/// Removes the given item from the heap if it is already stored. |
116 | 131 |
/// \param i The item to delete. |
117 | 132 |
void erase(const Item &i) {} |
118 | 133 |
|
119 | 134 |
/// \brief The priority of an item. |
120 | 135 |
/// |
121 | 136 |
/// Returns the priority of the given item. |
137 |
/// \param i The item. |
|
122 | 138 |
/// \pre \c i must be in the heap. |
123 |
/// \param i The item. |
|
124 | 139 |
Prio operator[](const Item &i) const {} |
125 | 140 |
|
126 | 141 |
/// \brief Sets the priority of an item or inserts it, if it is |
127 | 142 |
/// not stored in the heap. |
128 | 143 |
/// |
129 | 144 |
/// This method sets the priority of the given item if it is |
130 | 145 |
/// already stored in the heap. |
131 | 146 |
/// Otherwise it inserts the given item with the given priority. |
132 | 147 |
/// |
133 | 148 |
/// \param i The item. |
134 | 149 |
/// \param p The priority. |
135 | 150 |
void set(const Item &i, const Prio &p) {} |
136 | 151 |
|
137 | 152 |
/// \brief Decreases the priority of an item to the given value. |
138 | 153 |
/// |
139 | 154 |
/// Decreases the priority of an item to the given value. |
140 |
/// \pre \c i must be stored in the heap with priority at least \c p. |
|
141 | 155 |
/// \param i The item. |
142 | 156 |
/// \param p The priority. |
157 |
/// \pre \c i must be stored in the heap with priority at least \c p. |
|
143 | 158 |
void decrease(const Item &i, const Prio &p) {} |
144 | 159 |
|
145 | 160 |
/// \brief Increases the priority of an item to the given value. |
146 | 161 |
/// |
147 | 162 |
/// Increases the priority of an item to the given value. |
148 |
/// \pre \c i must be stored in the heap with priority at most \c p. |
|
149 | 163 |
/// \param i The item. |
150 | 164 |
/// \param p The priority. |
165 |
/// \pre \c i must be stored in the heap with priority at most \c p. |
|
151 | 166 |
void increase(const Item &i, const Prio &p) {} |
152 | 167 |
|
153 | 168 |
/// \brief Returns if an item is in, has already been in, or has |
154 | 169 |
/// never been in the heap. |
155 | 170 |
/// |
156 | 171 |
/// This method returns \c PRE_HEAP if the given item has never |
157 | 172 |
/// been in the heap, \c IN_HEAP if it is in the heap at the moment, |
158 | 173 |
/// and \c POST_HEAP otherwise. |
159 | 174 |
/// In the latter case it is possible that the item will get back |
160 | 175 |
/// to the heap again. |
161 | 176 |
/// \param i The item. |
162 | 177 |
State state(const Item &i) const {} |
163 | 178 |
|
164 | 179 |
/// \brief Sets the state of an item in the heap. |
165 | 180 |
/// |
166 | 181 |
/// Sets the state of the given item in the heap. It can be used |
... | ... |
@@ -25,45 +25,45 @@ |
25 | 25 |
#define LEMON_CONCEPTS_PATH_H |
26 | 26 |
|
27 | 27 |
#include <lemon/core.h> |
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup concept |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// \brief A skeleton structure for representing directed paths in |
37 | 37 |
/// a digraph. |
38 | 38 |
/// |
39 | 39 |
/// A skeleton structure for representing directed paths in a |
40 | 40 |
/// digraph. |
41 |
/// \tparam |
|
41 |
/// \tparam GR The digraph type in which the path is. |
|
42 | 42 |
/// |
43 | 43 |
/// In a sense, the path can be treated as a list of arcs. The |
44 | 44 |
/// lemon path type stores just this list. As a consequence it |
45 | 45 |
/// cannot enumerate the nodes in the path and the zero length |
46 | 46 |
/// paths cannot store the source. |
47 | 47 |
/// |
48 |
template <typename |
|
48 |
template <typename GR> |
|
49 | 49 |
class Path { |
50 | 50 |
public: |
51 | 51 |
|
52 | 52 |
/// Type of the underlying digraph. |
53 |
typedef |
|
53 |
typedef GR Digraph; |
|
54 | 54 |
/// Arc type of the underlying digraph. |
55 | 55 |
typedef typename Digraph::Arc Arc; |
56 | 56 |
|
57 | 57 |
class ArcIt; |
58 | 58 |
|
59 | 59 |
/// \brief Default constructor |
60 | 60 |
Path() {} |
61 | 61 |
|
62 | 62 |
/// \brief Template constructor |
63 | 63 |
template <typename CPath> |
64 | 64 |
Path(const CPath& cpath) {} |
65 | 65 |
|
66 | 66 |
/// \brief Template assigment |
67 | 67 |
template <typename CPath> |
68 | 68 |
Path& operator=(const CPath& cpath) { |
69 | 69 |
ignore_unused_variable_warning(cpath); |
... | ... |
@@ -192,44 +192,43 @@ |
192 | 192 |
/// \brief A skeleton structure for path dumpers. |
193 | 193 |
/// |
194 | 194 |
/// A skeleton structure for path dumpers. The path dumpers are |
195 | 195 |
/// the generalization of the paths. The path dumpers can |
196 | 196 |
/// enumerate the arcs of the path wheter in forward or in |
197 | 197 |
/// backward order. In most time these classes are not used |
198 | 198 |
/// directly rather it used to assign a dumped class to a real |
199 | 199 |
/// path type. |
200 | 200 |
/// |
201 | 201 |
/// The main purpose of this concept is that the shortest path |
202 | 202 |
/// algorithms can enumerate easily the arcs in reverse order. |
203 | 203 |
/// If we would like to give back a real path from these |
204 | 204 |
/// algorithms then we should create a temporarly path object. In |
205 | 205 |
/// LEMON such algorithms gives back a path dumper what can |
206 | 206 |
/// assigned to a real path and the dumpers can be implemented as |
207 | 207 |
/// an adaptor class to the predecessor map. |
208 |
|
|
209 |
/// \tparam _Digraph The digraph type in which the path is. |
|
208 |
/// |
|
209 |
/// \tparam GR The digraph type in which the path is. |
|
210 | 210 |
/// |
211 | 211 |
/// The paths can be constructed from any path type by a |
212 | 212 |
/// template constructor or a template assignment operator. |
213 |
/// |
|
214 |
template <typename _Digraph> |
|
213 |
template <typename GR> |
|
215 | 214 |
class PathDumper { |
216 | 215 |
public: |
217 | 216 |
|
218 | 217 |
/// Type of the underlying digraph. |
219 |
typedef |
|
218 |
typedef GR Digraph; |
|
220 | 219 |
/// Arc type of the underlying digraph. |
221 | 220 |
typedef typename Digraph::Arc Arc; |
222 | 221 |
|
223 | 222 |
/// Length of the path ie. the number of arcs in the path. |
224 | 223 |
int length() const { return 0;} |
225 | 224 |
|
226 | 225 |
/// Returns whether the path is empty. |
227 | 226 |
bool empty() const { return true;} |
228 | 227 |
|
229 | 228 |
/// \brief Forward or reverse dumping |
230 | 229 |
/// |
231 | 230 |
/// If the RevPathTag is defined and true then reverse dumping |
232 | 231 |
/// is provided in the path dumper. In this case instead of the |
233 | 232 |
/// ArcIt the RevArcIt iterator should be implemented in the |
234 | 233 |
/// dumper. |
235 | 234 |
typedef False RevPathTag; |
... | ... |
@@ -33,33 +33,33 @@ |
33 | 33 |
#include <functional> |
34 | 34 |
|
35 | 35 |
/// \ingroup connectivity |
36 | 36 |
/// \file |
37 | 37 |
/// \brief Connectivity algorithms |
38 | 38 |
/// |
39 | 39 |
/// Connectivity algorithms |
40 | 40 |
|
41 | 41 |
namespace lemon { |
42 | 42 |
|
43 | 43 |
/// \ingroup connectivity |
44 | 44 |
/// |
45 | 45 |
/// \brief Check whether the given undirected graph is connected. |
46 | 46 |
/// |
47 | 47 |
/// Check whether the given undirected graph is connected. |
48 | 48 |
/// \param graph The undirected graph. |
49 |
/// \return |
|
49 |
/// \return \c true when there is path between any two nodes in the graph. |
|
50 | 50 |
/// \note By definition, the empty graph is connected. |
51 | 51 |
template <typename Graph> |
52 | 52 |
bool connected(const Graph& graph) { |
53 | 53 |
checkConcept<concepts::Graph, Graph>(); |
54 | 54 |
typedef typename Graph::NodeIt NodeIt; |
55 | 55 |
if (NodeIt(graph) == INVALID) return true; |
56 | 56 |
Dfs<Graph> dfs(graph); |
57 | 57 |
dfs.run(NodeIt(graph)); |
58 | 58 |
for (NodeIt it(graph); it != INVALID; ++it) { |
59 | 59 |
if (!dfs.reached(it)) { |
60 | 60 |
return false; |
61 | 61 |
} |
62 | 62 |
} |
63 | 63 |
return true; |
64 | 64 |
} |
65 | 65 |
|
... | ... |
@@ -221,33 +221,33 @@ |
221 | 221 |
int& _cutNum; |
222 | 222 |
|
223 | 223 |
typename Digraph::template NodeMap<int> _compMap; |
224 | 224 |
int _num; |
225 | 225 |
}; |
226 | 226 |
|
227 | 227 |
} |
228 | 228 |
|
229 | 229 |
|
230 | 230 |
/// \ingroup connectivity |
231 | 231 |
/// |
232 | 232 |
/// \brief Check whether the given directed graph is strongly connected. |
233 | 233 |
/// |
234 | 234 |
/// Check whether the given directed graph is strongly connected. The |
235 | 235 |
/// graph is strongly connected when any two nodes of the graph are |
236 | 236 |
/// connected with directed paths in both direction. |
237 |
/// \return |
|
237 |
/// \return \c false when the graph is not strongly connected. |
|
238 | 238 |
/// \see connected |
239 | 239 |
/// |
240 | 240 |
/// \note By definition, the empty graph is strongly connected. |
241 | 241 |
template <typename Digraph> |
242 | 242 |
bool stronglyConnected(const Digraph& digraph) { |
243 | 243 |
checkConcept<concepts::Digraph, Digraph>(); |
244 | 244 |
|
245 | 245 |
typedef typename Digraph::Node Node; |
246 | 246 |
typedef typename Digraph::NodeIt NodeIt; |
247 | 247 |
|
248 | 248 |
typename Digraph::Node source = NodeIt(digraph); |
249 | 249 |
if (source == INVALID) return true; |
250 | 250 |
|
251 | 251 |
using namespace _connectivity_bits; |
252 | 252 |
|
253 | 253 |
typedef DfsVisitor<Digraph> Visitor; |
... | ... |
@@ -696,33 +696,33 @@ |
696 | 696 |
}; |
697 | 697 |
|
698 | 698 |
} |
699 | 699 |
|
700 | 700 |
template <typename Graph> |
701 | 701 |
int countBiNodeConnectedComponents(const Graph& graph); |
702 | 702 |
|
703 | 703 |
/// \ingroup connectivity |
704 | 704 |
/// |
705 | 705 |
/// \brief Checks the graph is bi-node-connected. |
706 | 706 |
/// |
707 | 707 |
/// This function checks that the undirected graph is bi-node-connected |
708 | 708 |
/// graph. The graph is bi-node-connected if any two undirected edge is |
709 | 709 |
/// on same circle. |
710 | 710 |
/// |
711 | 711 |
/// \param graph The graph. |
712 |
/// \return |
|
712 |
/// \return \c true when the graph bi-node-connected. |
|
713 | 713 |
template <typename Graph> |
714 | 714 |
bool biNodeConnected(const Graph& graph) { |
715 | 715 |
return countBiNodeConnectedComponents(graph) <= 1; |
716 | 716 |
} |
717 | 717 |
|
718 | 718 |
/// \ingroup connectivity |
719 | 719 |
/// |
720 | 720 |
/// \brief Count the biconnected components. |
721 | 721 |
/// |
722 | 722 |
/// This function finds the bi-node-connected components in an undirected |
723 | 723 |
/// graph. The biconnected components are the classes of an equivalence |
724 | 724 |
/// relation on the undirected edges. Two undirected edge is in relationship |
725 | 725 |
/// when they are on same circle. |
726 | 726 |
/// |
727 | 727 |
/// \param graph The graph. |
728 | 728 |
/// \return The number of components. |
... | ... |
@@ -1217,33 +1217,33 @@ |
1217 | 1217 |
} |
1218 | 1218 |
} |
1219 | 1219 |
} |
1220 | 1220 |
|
1221 | 1221 |
/// \ingroup connectivity |
1222 | 1222 |
/// |
1223 | 1223 |
/// \brief Sort the nodes of a DAG into topolgical order. |
1224 | 1224 |
/// |
1225 | 1225 |
/// Sort the nodes of a DAG into topolgical order. It also checks |
1226 | 1226 |
/// that the given graph is DAG. |
1227 | 1227 |
/// |
1228 | 1228 |
/// \param digraph The graph. It must be directed and acyclic. |
1229 | 1229 |
/// \retval order A readable - writable node map. The values will be set |
1230 | 1230 |
/// from 0 to the number of the nodes in the graph minus one. Each values |
1231 | 1231 |
/// of the map will be set exactly once, the values will be set descending |
1232 | 1232 |
/// order. |
1233 |
/// \return |
|
1233 |
/// \return \c false when the graph is not DAG. |
|
1234 | 1234 |
/// |
1235 | 1235 |
/// \see topologicalSort |
1236 | 1236 |
/// \see dag |
1237 | 1237 |
template <typename Digraph, typename NodeMap> |
1238 | 1238 |
bool checkedTopologicalSort(const Digraph& digraph, NodeMap& order) { |
1239 | 1239 |
using namespace _connectivity_bits; |
1240 | 1240 |
|
1241 | 1241 |
checkConcept<concepts::Digraph, Digraph>(); |
1242 | 1242 |
checkConcept<concepts::ReadWriteMap<typename Digraph::Node, int>, |
1243 | 1243 |
NodeMap>(); |
1244 | 1244 |
|
1245 | 1245 |
typedef typename Digraph::Node Node; |
1246 | 1246 |
typedef typename Digraph::NodeIt NodeIt; |
1247 | 1247 |
typedef typename Digraph::Arc Arc; |
1248 | 1248 |
|
1249 | 1249 |
for (NodeIt it(digraph); it != INVALID; ++it) { |
... | ... |
@@ -1266,33 +1266,33 @@ |
1266 | 1266 |
if (dfs.reached(target) && order[target] == -1) { |
1267 | 1267 |
return false; |
1268 | 1268 |
} |
1269 | 1269 |
dfs.processNextArc(); |
1270 | 1270 |
} |
1271 | 1271 |
} |
1272 | 1272 |
} |
1273 | 1273 |
return true; |
1274 | 1274 |
} |
1275 | 1275 |
|
1276 | 1276 |
/// \ingroup connectivity |
1277 | 1277 |
/// |
1278 | 1278 |
/// \brief Check that the given directed graph is a DAG. |
1279 | 1279 |
/// |
1280 | 1280 |
/// Check that the given directed graph is a DAG. The DAG is |
1281 | 1281 |
/// an Directed Acyclic Digraph. |
1282 |
/// \return |
|
1282 |
/// \return \c false when the graph is not DAG. |
|
1283 | 1283 |
/// \see acyclic |
1284 | 1284 |
template <typename Digraph> |
1285 | 1285 |
bool dag(const Digraph& digraph) { |
1286 | 1286 |
|
1287 | 1287 |
checkConcept<concepts::Digraph, Digraph>(); |
1288 | 1288 |
|
1289 | 1289 |
typedef typename Digraph::Node Node; |
1290 | 1290 |
typedef typename Digraph::NodeIt NodeIt; |
1291 | 1291 |
typedef typename Digraph::Arc Arc; |
1292 | 1292 |
|
1293 | 1293 |
typedef typename Digraph::template NodeMap<bool> ProcessedMap; |
1294 | 1294 |
|
1295 | 1295 |
typename Dfs<Digraph>::template SetProcessedMap<ProcessedMap>:: |
1296 | 1296 |
Create dfs(digraph); |
1297 | 1297 |
|
1298 | 1298 |
ProcessedMap processed(digraph); |
... | ... |
@@ -1308,33 +1308,33 @@ |
1308 | 1308 |
if (dfs.reached(target) && !processed[target]) { |
1309 | 1309 |
return false; |
1310 | 1310 |
} |
1311 | 1311 |
dfs.processNextArc(); |
1312 | 1312 |
} |
1313 | 1313 |
} |
1314 | 1314 |
} |
1315 | 1315 |
return true; |
1316 | 1316 |
} |
1317 | 1317 |
|
1318 | 1318 |
/// \ingroup connectivity |
1319 | 1319 |
/// |
1320 | 1320 |
/// \brief Check that the given undirected graph is acyclic. |
1321 | 1321 |
/// |
1322 | 1322 |
/// Check that the given undirected graph acyclic. |
1323 | 1323 |
/// \param graph The undirected graph. |
1324 |
/// \return |
|
1324 |
/// \return \c true when there is no circle in the graph. |
|
1325 | 1325 |
/// \see dag |
1326 | 1326 |
template <typename Graph> |
1327 | 1327 |
bool acyclic(const Graph& graph) { |
1328 | 1328 |
checkConcept<concepts::Graph, Graph>(); |
1329 | 1329 |
typedef typename Graph::Node Node; |
1330 | 1330 |
typedef typename Graph::NodeIt NodeIt; |
1331 | 1331 |
typedef typename Graph::Arc Arc; |
1332 | 1332 |
Dfs<Graph> dfs(graph); |
1333 | 1333 |
dfs.init(); |
1334 | 1334 |
for (NodeIt it(graph); it != INVALID; ++it) { |
1335 | 1335 |
if (!dfs.reached(it)) { |
1336 | 1336 |
dfs.addSource(it); |
1337 | 1337 |
while (!dfs.emptyQueue()) { |
1338 | 1338 |
Arc edge = dfs.nextArc(); |
1339 | 1339 |
Node source = graph.source(edge); |
1340 | 1340 |
Node target = graph.target(edge); |
... | ... |
@@ -1342,33 +1342,33 @@ |
1342 | 1342 |
dfs.predArc(source) != graph.oppositeArc(edge)) { |
1343 | 1343 |
return false; |
1344 | 1344 |
} |
1345 | 1345 |
dfs.processNextArc(); |
1346 | 1346 |
} |
1347 | 1347 |
} |
1348 | 1348 |
} |
1349 | 1349 |
return true; |
1350 | 1350 |
} |
1351 | 1351 |
|
1352 | 1352 |
/// \ingroup connectivity |
1353 | 1353 |
/// |
1354 | 1354 |
/// \brief Check that the given undirected graph is tree. |
1355 | 1355 |
/// |
1356 | 1356 |
/// Check that the given undirected graph is tree. |
1357 | 1357 |
/// \param graph The undirected graph. |
1358 |
/// \return |
|
1358 |
/// \return \c true when the graph is acyclic and connected. |
|
1359 | 1359 |
template <typename Graph> |
1360 | 1360 |
bool tree(const Graph& graph) { |
1361 | 1361 |
checkConcept<concepts::Graph, Graph>(); |
1362 | 1362 |
typedef typename Graph::Node Node; |
1363 | 1363 |
typedef typename Graph::NodeIt NodeIt; |
1364 | 1364 |
typedef typename Graph::Arc Arc; |
1365 | 1365 |
Dfs<Graph> dfs(graph); |
1366 | 1366 |
dfs.init(); |
1367 | 1367 |
dfs.addSource(NodeIt(graph)); |
1368 | 1368 |
while (!dfs.emptyQueue()) { |
1369 | 1369 |
Arc edge = dfs.nextArc(); |
1370 | 1370 |
Node source = graph.source(edge); |
1371 | 1371 |
Node target = graph.target(edge); |
1372 | 1372 |
if (dfs.reached(target) && |
1373 | 1373 |
dfs.predArc(source) != graph.oppositeArc(edge)) { |
1374 | 1374 |
return false; |
... | ... |
@@ -1435,33 +1435,33 @@ |
1435 | 1435 |
|
1436 | 1436 |
private: |
1437 | 1437 |
|
1438 | 1438 |
const Digraph& _graph; |
1439 | 1439 |
PartMap& _part; |
1440 | 1440 |
bool& _bipartite; |
1441 | 1441 |
}; |
1442 | 1442 |
} |
1443 | 1443 |
|
1444 | 1444 |
/// \ingroup connectivity |
1445 | 1445 |
/// |
1446 | 1446 |
/// \brief Check if the given undirected graph is bipartite or not |
1447 | 1447 |
/// |
1448 | 1448 |
/// The function checks if the given undirected \c graph graph is bipartite |
1449 | 1449 |
/// or not. The \ref Bfs algorithm is used to calculate the result. |
1450 | 1450 |
/// \param graph The undirected graph. |
1451 |
/// \return |
|
1451 |
/// \return \c true if \c graph is bipartite, \c false otherwise. |
|
1452 | 1452 |
/// \sa bipartitePartitions |
1453 | 1453 |
template<typename Graph> |
1454 | 1454 |
inline bool bipartite(const Graph &graph){ |
1455 | 1455 |
using namespace _connectivity_bits; |
1456 | 1456 |
|
1457 | 1457 |
checkConcept<concepts::Graph, Graph>(); |
1458 | 1458 |
|
1459 | 1459 |
typedef typename Graph::NodeIt NodeIt; |
1460 | 1460 |
typedef typename Graph::ArcIt ArcIt; |
1461 | 1461 |
|
1462 | 1462 |
bool bipartite = true; |
1463 | 1463 |
|
1464 | 1464 |
BipartiteVisitor<Graph> |
1465 | 1465 |
visitor(graph, bipartite); |
1466 | 1466 |
BfsVisit<Graph, BipartiteVisitor<Graph> > |
1467 | 1467 |
bfs(graph, visitor); |
... | ... |
@@ -1476,33 +1476,33 @@ |
1476 | 1476 |
} |
1477 | 1477 |
} |
1478 | 1478 |
return true; |
1479 | 1479 |
} |
1480 | 1480 |
|
1481 | 1481 |
/// \ingroup connectivity |
1482 | 1482 |
/// |
1483 | 1483 |
/// \brief Check if the given undirected graph is bipartite or not |
1484 | 1484 |
/// |
1485 | 1485 |
/// The function checks if the given undirected graph is bipartite |
1486 | 1486 |
/// or not. The \ref Bfs algorithm is used to calculate the result. |
1487 | 1487 |
/// During the execution, the \c partMap will be set as the two |
1488 | 1488 |
/// partitions of the graph. |
1489 | 1489 |
/// \param graph The undirected graph. |
1490 | 1490 |
/// \retval partMap A writable bool map of nodes. It will be set as the |
1491 | 1491 |
/// two partitions of the graph. |
1492 |
/// \return |
|
1492 |
/// \return \c true if \c graph is bipartite, \c false otherwise. |
|
1493 | 1493 |
template<typename Graph, typename NodeMap> |
1494 | 1494 |
inline bool bipartitePartitions(const Graph &graph, NodeMap &partMap){ |
1495 | 1495 |
using namespace _connectivity_bits; |
1496 | 1496 |
|
1497 | 1497 |
checkConcept<concepts::Graph, Graph>(); |
1498 | 1498 |
|
1499 | 1499 |
typedef typename Graph::Node Node; |
1500 | 1500 |
typedef typename Graph::NodeIt NodeIt; |
1501 | 1501 |
typedef typename Graph::ArcIt ArcIt; |
1502 | 1502 |
|
1503 | 1503 |
bool bipartite = true; |
1504 | 1504 |
|
1505 | 1505 |
BipartitePartitionsVisitor<Graph, NodeMap> |
1506 | 1506 |
visitor(graph, partMap, bipartite); |
1507 | 1507 |
BfsVisit<Graph, BipartitePartitionsVisitor<Graph, NodeMap> > |
1508 | 1508 |
bfs(graph, visitor); |
... | ... |
@@ -1021,37 +1021,37 @@ |
1021 | 1021 |
return _core_bits::FindArcSelector<Graph>::find(g, u, v, prev); |
1022 | 1022 |
} |
1023 | 1023 |
|
1024 | 1024 |
/// \brief Iterator for iterating on parallel arcs connecting the same nodes. |
1025 | 1025 |
/// |
1026 | 1026 |
/// Iterator for iterating on parallel arcs connecting the same nodes. It is |
1027 | 1027 |
/// a higher level interface for the \ref findArc() function. You can |
1028 | 1028 |
/// use it the following way: |
1029 | 1029 |
///\code |
1030 | 1030 |
/// for (ConArcIt<Graph> it(g, src, trg); it != INVALID; ++it) { |
1031 | 1031 |
/// ... |
1032 | 1032 |
/// } |
1033 | 1033 |
///\endcode |
1034 | 1034 |
/// |
1035 | 1035 |
///\sa findArc() |
1036 | 1036 |
///\sa ArcLookUp, AllArcLookUp, DynArcLookUp |
1037 |
template <typename _Graph> |
|
1038 |
class ConArcIt : public _Graph::Arc { |
|
1037 |
template <typename GR> |
|
1038 |
class ConArcIt : public GR::Arc { |
|
1039 | 1039 |
public: |
1040 | 1040 |
|
1041 |
typedef |
|
1041 |
typedef GR Graph; |
|
1042 | 1042 |
typedef typename Graph::Arc Parent; |
1043 | 1043 |
|
1044 | 1044 |
typedef typename Graph::Arc Arc; |
1045 | 1045 |
typedef typename Graph::Node Node; |
1046 | 1046 |
|
1047 | 1047 |
/// \brief Constructor. |
1048 | 1048 |
/// |
1049 | 1049 |
/// Construct a new ConArcIt iterating on the arcs that |
1050 | 1050 |
/// connects nodes \c u and \c v. |
1051 | 1051 |
ConArcIt(const Graph& g, Node u, Node v) : _graph(g) { |
1052 | 1052 |
Parent::operator=(findArc(_graph, u, v)); |
1053 | 1053 |
} |
1054 | 1054 |
|
1055 | 1055 |
/// \brief Constructor. |
1056 | 1056 |
/// |
1057 | 1057 |
/// Construct a new ConArcIt that continues the iterating from arc \c a. |
... | ... |
@@ -1144,37 +1144,37 @@ |
1144 | 1144 |
typename Graph::Edge p = INVALID) { |
1145 | 1145 |
return _core_bits::FindEdgeSelector<Graph>::find(g, u, v, p); |
1146 | 1146 |
} |
1147 | 1147 |
|
1148 | 1148 |
/// \brief Iterator for iterating on parallel edges connecting the same nodes. |
1149 | 1149 |
/// |
1150 | 1150 |
/// Iterator for iterating on parallel edges connecting the same nodes. |
1151 | 1151 |
/// It is a higher level interface for the findEdge() function. You can |
1152 | 1152 |
/// use it the following way: |
1153 | 1153 |
///\code |
1154 | 1154 |
/// for (ConEdgeIt<Graph> it(g, u, v); it != INVALID; ++it) { |
1155 | 1155 |
/// ... |
1156 | 1156 |
/// } |
1157 | 1157 |
///\endcode |
1158 | 1158 |
/// |
1159 | 1159 |
///\sa findEdge() |
1160 |
template <typename _Graph> |
|
1161 |
class ConEdgeIt : public _Graph::Edge { |
|
1160 |
template <typename GR> |
|
1161 |
class ConEdgeIt : public GR::Edge { |
|
1162 | 1162 |
public: |
1163 | 1163 |
|
1164 |
typedef |
|
1164 |
typedef GR Graph; |
|
1165 | 1165 |
typedef typename Graph::Edge Parent; |
1166 | 1166 |
|
1167 | 1167 |
typedef typename Graph::Edge Edge; |
1168 | 1168 |
typedef typename Graph::Node Node; |
1169 | 1169 |
|
1170 | 1170 |
/// \brief Constructor. |
1171 | 1171 |
/// |
1172 | 1172 |
/// Construct a new ConEdgeIt iterating on the edges that |
1173 | 1173 |
/// connects nodes \c u and \c v. |
1174 | 1174 |
ConEdgeIt(const Graph& g, Node u, Node v) : _graph(g), _u(u), _v(v) { |
1175 | 1175 |
Parent::operator=(findEdge(_graph, _u, _v)); |
1176 | 1176 |
} |
1177 | 1177 |
|
1178 | 1178 |
/// \brief Constructor. |
1179 | 1179 |
/// |
1180 | 1180 |
/// Construct a new ConEdgeIt that continues iterating from edge \c e. |
... | ... |
@@ -1198,55 +1198,55 @@ |
1198 | 1198 |
///Using this class, you can find an arc in a digraph from a given |
1199 | 1199 |
///source to a given target in amortized time <em>O</em>(log<em>d</em>), |
1200 | 1200 |
///where <em>d</em> is the out-degree of the source node. |
1201 | 1201 |
/// |
1202 | 1202 |
///It is possible to find \e all parallel arcs between two nodes with |
1203 | 1203 |
///the \c operator() member. |
1204 | 1204 |
/// |
1205 | 1205 |
///This is a dynamic data structure. Consider to use \ref ArcLookUp or |
1206 | 1206 |
///\ref AllArcLookUp if your digraph is not changed so frequently. |
1207 | 1207 |
/// |
1208 | 1208 |
///This class uses a self-adjusting binary search tree, the Splay tree |
1209 | 1209 |
///of Sleator and Tarjan to guarantee the logarithmic amortized |
1210 | 1210 |
///time bound for arc look-ups. This class also guarantees the |
1211 | 1211 |
///optimal time bound in a constant factor for any distribution of |
1212 | 1212 |
///queries. |
1213 | 1213 |
/// |
1214 |
///\tparam |
|
1214 |
///\tparam GR The type of the underlying digraph. |
|
1215 | 1215 |
/// |
1216 | 1216 |
///\sa ArcLookUp |
1217 | 1217 |
///\sa AllArcLookUp |
1218 |
template< |
|
1218 |
template <typename GR> |
|
1219 | 1219 |
class DynArcLookUp |
1220 |
: protected ItemSetTraits< |
|
1220 |
: protected ItemSetTraits<GR, typename GR::Arc>::ItemNotifier::ObserverBase |
|
1221 | 1221 |
{ |
1222 | 1222 |
public: |
1223 |
typedef typename ItemSetTraits< |
|
1223 |
typedef typename ItemSetTraits<GR, typename GR::Arc> |
|
1224 | 1224 |
::ItemNotifier::ObserverBase Parent; |
1225 | 1225 |
|
1226 |
TEMPLATE_DIGRAPH_TYPEDEFS(G); |
|
1227 |
typedef G Digraph; |
|
1226 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
|
1227 |
typedef GR Digraph; |
|
1228 | 1228 |
|
1229 | 1229 |
protected: |
1230 | 1230 |
|
1231 |
class AutoNodeMap : public ItemSetTraits< |
|
1231 |
class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type { |
|
1232 | 1232 |
public: |
1233 | 1233 |
|
1234 |
typedef typename ItemSetTraits< |
|
1234 |
typedef typename ItemSetTraits<GR, Node>::template Map<Arc>::Type Parent; |
|
1235 | 1235 |
|
1236 |
AutoNodeMap(const |
|
1236 |
AutoNodeMap(const GR& digraph) : Parent(digraph, INVALID) {} |
|
1237 | 1237 |
|
1238 | 1238 |
virtual void add(const Node& node) { |
1239 | 1239 |
Parent::add(node); |
1240 | 1240 |
Parent::set(node, INVALID); |
1241 | 1241 |
} |
1242 | 1242 |
|
1243 | 1243 |
virtual void add(const std::vector<Node>& nodes) { |
1244 | 1244 |
Parent::add(nodes); |
1245 | 1245 |
for (int i = 0; i < int(nodes.size()); ++i) { |
1246 | 1246 |
Parent::set(nodes[i], INVALID); |
1247 | 1247 |
} |
1248 | 1248 |
} |
1249 | 1249 |
|
1250 | 1250 |
virtual void build() { |
1251 | 1251 |
Parent::build(); |
1252 | 1252 |
Node it; |
... | ... |
@@ -1610,42 +1610,42 @@ |
1610 | 1610 |
}; |
1611 | 1611 |
|
1612 | 1612 |
///Fast arc look-up between given endpoints. |
1613 | 1613 |
|
1614 | 1614 |
///Using this class, you can find an arc in a digraph from a given |
1615 | 1615 |
///source to a given target in time <em>O</em>(log<em>d</em>), |
1616 | 1616 |
///where <em>d</em> is the out-degree of the source node. |
1617 | 1617 |
/// |
1618 | 1618 |
///It is not possible to find \e all parallel arcs between two nodes. |
1619 | 1619 |
///Use \ref AllArcLookUp for this purpose. |
1620 | 1620 |
/// |
1621 | 1621 |
///\warning This class is static, so you should call refresh() (or at |
1622 | 1622 |
///least refresh(Node)) to refresh this data structure whenever the |
1623 | 1623 |
///digraph changes. This is a time consuming (superlinearly proportional |
1624 | 1624 |
///(<em>O</em>(<em>m</em> log<em>m</em>)) to the number of arcs). |
1625 | 1625 |
/// |
1626 |
///\tparam |
|
1626 |
///\tparam GR The type of the underlying digraph. |
|
1627 | 1627 |
/// |
1628 | 1628 |
///\sa DynArcLookUp |
1629 | 1629 |
///\sa AllArcLookUp |
1630 |
template<class |
|
1630 |
template<class GR> |
|
1631 | 1631 |
class ArcLookUp |
1632 | 1632 |
{ |
1633 | 1633 |
public: |
1634 |
TEMPLATE_DIGRAPH_TYPEDEFS(G); |
|
1635 |
typedef G Digraph; |
|
1634 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
|
1635 |
typedef GR Digraph; |
|
1636 | 1636 |
|
1637 | 1637 |
protected: |
1638 | 1638 |
const Digraph &_g; |
1639 | 1639 |
typename Digraph::template NodeMap<Arc> _head; |
1640 | 1640 |
typename Digraph::template ArcMap<Arc> _left; |
1641 | 1641 |
typename Digraph::template ArcMap<Arc> _right; |
1642 | 1642 |
|
1643 | 1643 |
class ArcLess { |
1644 | 1644 |
const Digraph &g; |
1645 | 1645 |
public: |
1646 | 1646 |
ArcLess(const Digraph &_g) : g(_g) {} |
1647 | 1647 |
bool operator()(Arc a,Arc b) const |
1648 | 1648 |
{ |
1649 | 1649 |
return g.target(a)<g.target(b); |
1650 | 1650 |
} |
1651 | 1651 |
}; |
... | ... |
@@ -1720,83 +1720,83 @@ |
1720 | 1720 |
return e; |
1721 | 1721 |
} |
1722 | 1722 |
|
1723 | 1723 |
}; |
1724 | 1724 |
|
1725 | 1725 |
///Fast look-up of all arcs between given endpoints. |
1726 | 1726 |
|
1727 | 1727 |
///This class is the same as \ref ArcLookUp, with the addition |
1728 | 1728 |
///that it makes it possible to find all parallel arcs between given |
1729 | 1729 |
///endpoints. |
1730 | 1730 |
/// |
1731 | 1731 |
///\warning This class is static, so you should call refresh() (or at |
1732 | 1732 |
///least refresh(Node)) to refresh this data structure whenever the |
1733 | 1733 |
///digraph changes. This is a time consuming (superlinearly proportional |
1734 | 1734 |
///(<em>O</em>(<em>m</em> log<em>m</em>)) to the number of arcs). |
1735 | 1735 |
/// |
1736 |
///\tparam |
|
1736 |
///\tparam GR The type of the underlying digraph. |
|
1737 | 1737 |
/// |
1738 | 1738 |
///\sa DynArcLookUp |
1739 | 1739 |
///\sa ArcLookUp |
1740 |
template<class G> |
|
1741 |
class AllArcLookUp : public ArcLookUp<G> |
|
1740 |
template<class GR> |
|
1741 |
class AllArcLookUp : public ArcLookUp<GR> |
|
1742 | 1742 |
{ |
1743 |
using ArcLookUp<G>::_g; |
|
1744 |
using ArcLookUp<G>::_right; |
|
1745 |
using ArcLookUp<G>::_left; |
|
1746 |
using ArcLookUp<G>::_head; |
|
1743 |
using ArcLookUp<GR>::_g; |
|
1744 |
using ArcLookUp<GR>::_right; |
|
1745 |
using ArcLookUp<GR>::_left; |
|
1746 |
using ArcLookUp<GR>::_head; |
|
1747 | 1747 |
|
1748 |
TEMPLATE_DIGRAPH_TYPEDEFS(G); |
|
1749 |
typedef G Digraph; |
|
1748 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
|
1749 |
typedef GR Digraph; |
|
1750 | 1750 |
|
1751 | 1751 |
typename Digraph::template ArcMap<Arc> _next; |
1752 | 1752 |
|
1753 | 1753 |
Arc refreshNext(Arc head,Arc next=INVALID) |
1754 | 1754 |
{ |
1755 | 1755 |
if(head==INVALID) return next; |
1756 | 1756 |
else { |
1757 | 1757 |
next=refreshNext(_right[head],next); |
1758 | 1758 |
_next[head]=( next!=INVALID && _g.target(next)==_g.target(head)) |
1759 | 1759 |
? next : INVALID; |
1760 | 1760 |
return refreshNext(_left[head],head); |
1761 | 1761 |
} |
1762 | 1762 |
} |
1763 | 1763 |
|
1764 | 1764 |
void refreshNext() |
1765 | 1765 |
{ |
1766 | 1766 |
for(NodeIt n(_g);n!=INVALID;++n) refreshNext(_head[n]); |
1767 | 1767 |
} |
1768 | 1768 |
|
1769 | 1769 |
public: |
1770 | 1770 |
///Constructor |
1771 | 1771 |
|
1772 | 1772 |
///Constructor. |
1773 | 1773 |
/// |
1774 | 1774 |
///It builds up the search database, which remains valid until the digraph |
1775 | 1775 |
///changes. |
1776 |
AllArcLookUp(const Digraph &g) : ArcLookUp< |
|
1776 |
AllArcLookUp(const Digraph &g) : ArcLookUp<GR>(g), _next(g) {refreshNext();} |
|
1777 | 1777 |
|
1778 | 1778 |
///Refresh the data structure at a node. |
1779 | 1779 |
|
1780 | 1780 |
///Build up the search database of node \c n. |
1781 | 1781 |
/// |
1782 | 1782 |
///It runs in time <em>O</em>(<em>d</em> log<em>d</em>), where <em>d</em> is |
1783 | 1783 |
///the number of the outgoing arcs of \c n. |
1784 | 1784 |
void refresh(Node n) |
1785 | 1785 |
{ |
1786 |
ArcLookUp< |
|
1786 |
ArcLookUp<GR>::refresh(n); |
|
1787 | 1787 |
refreshNext(_head[n]); |
1788 | 1788 |
} |
1789 | 1789 |
|
1790 | 1790 |
///Refresh the full data structure. |
1791 | 1791 |
|
1792 | 1792 |
///Build up the full search database. In fact, it simply calls |
1793 | 1793 |
///\ref refresh(Node) "refresh(n)" for each node \c n. |
1794 | 1794 |
/// |
1795 | 1795 |
///It runs in time <em>O</em>(<em>m</em> log<em>D</em>), where <em>m</em> is |
1796 | 1796 |
///the number of the arcs in the digraph and <em>D</em> is the maximum |
1797 | 1797 |
///out-degree of the digraph. |
1798 | 1798 |
void refresh() |
1799 | 1799 |
{ |
1800 | 1800 |
for(NodeIt n(_g);n!=INVALID;++n) refresh(_head[n]); |
1801 | 1801 |
} |
1802 | 1802 |
|
... | ... |
@@ -1817,30 +1817,30 @@ |
1817 | 1817 |
///... |
1818 | 1818 |
///int n = 0; |
1819 | 1819 |
///for(Arc a = ae(u,v); a != INVALID; a=ae(u,v,a)) n++; |
1820 | 1820 |
///\endcode |
1821 | 1821 |
/// |
1822 | 1822 |
///Finding the first arc take <em>O</em>(log<em>d</em>) time, |
1823 | 1823 |
///where <em>d</em> is the number of outgoing arcs of \c s. Then the |
1824 | 1824 |
///consecutive arcs are found in constant time. |
1825 | 1825 |
/// |
1826 | 1826 |
///\warning If you change the digraph, refresh() must be called before using |
1827 | 1827 |
///this operator. If you change the outgoing arcs of |
1828 | 1828 |
///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough. |
1829 | 1829 |
/// |
1830 | 1830 |
#ifdef DOXYGEN |
1831 | 1831 |
Arc operator()(Node s, Node t, Arc prev=INVALID) const {} |
1832 | 1832 |
#else |
1833 |
using ArcLookUp< |
|
1833 |
using ArcLookUp<GR>::operator() ; |
|
1834 | 1834 |
Arc operator()(Node s, Node t, Arc prev) const |
1835 | 1835 |
{ |
1836 | 1836 |
return prev==INVALID?(*this)(s,t):_next[prev]; |
1837 | 1837 |
} |
1838 | 1838 |
#endif |
1839 | 1839 |
|
1840 | 1840 |
}; |
1841 | 1841 |
|
1842 | 1842 |
/// @} |
1843 | 1843 |
|
1844 | 1844 |
} //namespace lemon |
1845 | 1845 |
|
1846 | 1846 |
#endif |
... | ... |
@@ -25,95 +25,97 @@ |
25 | 25 |
|
26 | 26 |
#include <limits> |
27 | 27 |
#include <lemon/list_graph.h> |
28 | 28 |
#include <lemon/bin_heap.h> |
29 | 29 |
#include <lemon/bits/path_dump.h> |
30 | 30 |
#include <lemon/core.h> |
31 | 31 |
#include <lemon/error.h> |
32 | 32 |
#include <lemon/maps.h> |
33 | 33 |
#include <lemon/path.h> |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
/// \brief Default operation traits for the Dijkstra algorithm class. |
38 | 38 |
/// |
39 | 39 |
/// This operation traits class defines all computational operations and |
40 | 40 |
/// constants which are used in the Dijkstra algorithm. |
41 |
template <typename |
|
41 |
template <typename V> |
|
42 | 42 |
struct DijkstraDefaultOperationTraits { |
43 |
/// \e |
|
44 |
typedef V Value; |
|
43 | 45 |
/// \brief Gives back the zero value of the type. |
44 | 46 |
static Value zero() { |
45 | 47 |
return static_cast<Value>(0); |
46 | 48 |
} |
47 | 49 |
/// \brief Gives back the sum of the given two elements. |
48 | 50 |
static Value plus(const Value& left, const Value& right) { |
49 | 51 |
return left + right; |
50 | 52 |
} |
51 | 53 |
/// \brief Gives back true only if the first value is less than the second. |
52 | 54 |
static bool less(const Value& left, const Value& right) { |
53 | 55 |
return left < right; |
54 | 56 |
} |
55 | 57 |
}; |
56 | 58 |
|
57 | 59 |
///Default traits class of Dijkstra class. |
58 | 60 |
|
59 | 61 |
///Default traits class of Dijkstra class. |
60 | 62 |
///\tparam GR The type of the digraph. |
61 |
///\tparam LM The type of the length map. |
|
62 |
template<class GR, class LM> |
|
63 |
///\tparam LEN The type of the length map. |
|
64 |
template<typename GR, typename LEN> |
|
63 | 65 |
struct DijkstraDefaultTraits |
64 | 66 |
{ |
65 | 67 |
///The type of the digraph the algorithm runs on. |
66 | 68 |
typedef GR Digraph; |
67 | 69 |
|
68 | 70 |
///The type of the map that stores the arc lengths. |
69 | 71 |
|
70 | 72 |
///The type of the map that stores the arc lengths. |
71 | 73 |
///It must meet the \ref concepts::ReadMap "ReadMap" concept. |
72 |
typedef |
|
74 |
typedef LEN LengthMap; |
|
73 | 75 |
///The type of the length of the arcs. |
74 |
typedef typename |
|
76 |
typedef typename LEN::Value Value; |
|
75 | 77 |
|
76 | 78 |
/// Operation traits for %Dijkstra algorithm. |
77 | 79 |
|
78 | 80 |
/// This class defines the operations that are used in the algorithm. |
79 | 81 |
/// \see DijkstraDefaultOperationTraits |
80 | 82 |
typedef DijkstraDefaultOperationTraits<Value> OperationTraits; |
81 | 83 |
|
82 | 84 |
/// The cross reference type used by the heap. |
83 | 85 |
|
84 | 86 |
/// The cross reference type used by the heap. |
85 | 87 |
/// Usually it is \c Digraph::NodeMap<int>. |
86 | 88 |
typedef typename Digraph::template NodeMap<int> HeapCrossRef; |
87 | 89 |
///Instantiates a \c HeapCrossRef. |
88 | 90 |
|
89 | 91 |
///This function instantiates a \ref HeapCrossRef. |
90 | 92 |
/// \param g is the digraph, to which we would like to define the |
91 | 93 |
/// \ref HeapCrossRef. |
92 | 94 |
static HeapCrossRef *createHeapCrossRef(const Digraph &g) |
93 | 95 |
{ |
94 | 96 |
return new HeapCrossRef(g); |
95 | 97 |
} |
96 | 98 |
|
97 | 99 |
///The heap type used by the %Dijkstra algorithm. |
98 | 100 |
|
99 | 101 |
///The heap type used by the Dijkstra algorithm. |
100 | 102 |
/// |
101 | 103 |
///\sa BinHeap |
102 | 104 |
///\sa Dijkstra |
103 |
typedef BinHeap<typename |
|
105 |
typedef BinHeap<typename LEN::Value, HeapCrossRef, std::less<Value> > Heap; |
|
104 | 106 |
///Instantiates a \c Heap. |
105 | 107 |
|
106 | 108 |
///This function instantiates a \ref Heap. |
107 | 109 |
static Heap *createHeap(HeapCrossRef& r) |
108 | 110 |
{ |
109 | 111 |
return new Heap(r); |
110 | 112 |
} |
111 | 113 |
|
112 | 114 |
///\brief The type of the map that stores the predecessor |
113 | 115 |
///arcs of the shortest paths. |
114 | 116 |
/// |
115 | 117 |
///The type of the map that stores the predecessor |
116 | 118 |
///arcs of the shortest paths. |
117 | 119 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
118 | 120 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
119 | 121 |
///Instantiates a \c PredMap. |
... | ... |
@@ -137,74 +139,74 @@ |
137 | 139 |
///This function instantiates a \ref ProcessedMap. |
138 | 140 |
///\param g is the digraph, to which |
139 | 141 |
///we would like to define the \ref ProcessedMap. |
140 | 142 |
#ifdef DOXYGEN |
141 | 143 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
142 | 144 |
#else |
143 | 145 |
static ProcessedMap *createProcessedMap(const Digraph &) |
144 | 146 |
#endif |
145 | 147 |
{ |
146 | 148 |
return new ProcessedMap(); |
147 | 149 |
} |
148 | 150 |
|
149 | 151 |
///The type of the map that stores the distances of the nodes. |
150 | 152 |
|
151 | 153 |
///The type of the map that stores the distances of the nodes. |
152 | 154 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
153 |
typedef typename Digraph::template NodeMap<typename |
|
155 |
typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap; |
|
154 | 156 |
///Instantiates a \c DistMap. |
155 | 157 |
|
156 | 158 |
///This function instantiates a \ref DistMap. |
157 | 159 |
///\param g is the digraph, to which we would like to define |
158 | 160 |
///the \ref DistMap. |
159 | 161 |
static DistMap *createDistMap(const Digraph &g) |
160 | 162 |
{ |
161 | 163 |
return new DistMap(g); |
162 | 164 |
} |
163 | 165 |
}; |
164 | 166 |
|
165 | 167 |
///%Dijkstra algorithm class. |
166 | 168 |
|
167 | 169 |
/// \ingroup shortest_path |
168 | 170 |
///This class provides an efficient implementation of the %Dijkstra algorithm. |
169 | 171 |
/// |
170 | 172 |
///The arc lengths are passed to the algorithm using a |
171 | 173 |
///\ref concepts::ReadMap "ReadMap", |
172 | 174 |
///so it is easy to change it to any kind of length. |
173 | 175 |
///The type of the length is determined by the |
174 | 176 |
///\ref concepts::ReadMap::Value "Value" of the length map. |
175 | 177 |
///It is also possible to change the underlying priority heap. |
176 | 178 |
/// |
177 | 179 |
///There is also a \ref dijkstra() "function-type interface" for the |
178 | 180 |
///%Dijkstra algorithm, which is convenient in the simplier cases and |
179 | 181 |
///it can be used easier. |
180 | 182 |
/// |
181 | 183 |
///\tparam GR The type of the digraph the algorithm runs on. |
182 | 184 |
///The default type is \ref ListDigraph. |
183 |
///\tparam |
|
185 |
///\tparam LEN A \ref concepts::ReadMap "readable" arc map that specifies |
|
184 | 186 |
///the lengths of the arcs. |
185 | 187 |
///It is read once for each arc, so the map may involve in |
186 | 188 |
///relatively time consuming process to compute the arc lengths if |
187 | 189 |
///it is necessary. The default map type is \ref |
188 | 190 |
///concepts::Digraph::ArcMap "GR::ArcMap<int>". |
189 | 191 |
#ifdef DOXYGEN |
190 |
template <typename GR, typename |
|
192 |
template <typename GR, typename LEN, typename TR> |
|
191 | 193 |
#else |
192 | 194 |
template <typename GR=ListDigraph, |
193 |
typename LM=typename GR::template ArcMap<int>, |
|
194 |
typename TR=DijkstraDefaultTraits<GR,LM> > |
|
195 |
typename LEN=typename GR::template ArcMap<int>, |
|
196 |
typename TR=DijkstraDefaultTraits<GR,LEN> > |
|
195 | 197 |
#endif |
196 | 198 |
class Dijkstra { |
197 | 199 |
public: |
198 | 200 |
|
199 | 201 |
///The type of the digraph the algorithm runs on. |
200 | 202 |
typedef typename TR::Digraph Digraph; |
201 | 203 |
|
202 | 204 |
///The type of the length of the arcs. |
203 | 205 |
typedef typename TR::LengthMap::Value Value; |
204 | 206 |
///The type of the map that stores the arc lengths. |
205 | 207 |
typedef typename TR::LengthMap LengthMap; |
206 | 208 |
///\brief The type of the map that stores the predecessor arcs of the |
207 | 209 |
///shortest paths. |
208 | 210 |
typedef typename TR::PredMap PredMap; |
209 | 211 |
///The type of the map that stores the distances of the nodes. |
210 | 212 |
typedef typename TR::DistMap DistMap; |
... | ... |
@@ -900,45 +902,45 @@ |
900 | 902 |
/// |
901 | 903 |
///\pre Either \ref run(Node) "run()" or \ref init() |
902 | 904 |
///must be called before using this function and |
903 | 905 |
///node \c v must be reached but not necessarily processed. |
904 | 906 |
Value currentDist(Node v) const { |
905 | 907 |
return processed(v) ? (*_dist)[v] : (*_heap)[v]; |
906 | 908 |
} |
907 | 909 |
|
908 | 910 |
///@} |
909 | 911 |
}; |
910 | 912 |
|
911 | 913 |
|
912 | 914 |
///Default traits class of dijkstra() function. |
913 | 915 |
|
914 | 916 |
///Default traits class of dijkstra() function. |
915 | 917 |
///\tparam GR The type of the digraph. |
916 |
///\tparam LM The type of the length map. |
|
917 |
template<class GR, class LM> |
|
918 |
///\tparam LEN The type of the length map. |
|
919 |
template<class GR, class LEN> |
|
918 | 920 |
struct DijkstraWizardDefaultTraits |
919 | 921 |
{ |
920 | 922 |
///The type of the digraph the algorithm runs on. |
921 | 923 |
typedef GR Digraph; |
922 | 924 |
///The type of the map that stores the arc lengths. |
923 | 925 |
|
924 | 926 |
///The type of the map that stores the arc lengths. |
925 | 927 |
///It must meet the \ref concepts::ReadMap "ReadMap" concept. |
926 |
typedef |
|
928 |
typedef LEN LengthMap; |
|
927 | 929 |
///The type of the length of the arcs. |
928 |
typedef typename |
|
930 |
typedef typename LEN::Value Value; |
|
929 | 931 |
|
930 | 932 |
/// Operation traits for Dijkstra algorithm. |
931 | 933 |
|
932 | 934 |
/// This class defines the operations that are used in the algorithm. |
933 | 935 |
/// \see DijkstraDefaultOperationTraits |
934 | 936 |
typedef DijkstraDefaultOperationTraits<Value> OperationTraits; |
935 | 937 |
|
936 | 938 |
/// The cross reference type used by the heap. |
937 | 939 |
|
938 | 940 |
/// The cross reference type used by the heap. |
939 | 941 |
/// Usually it is \c Digraph::NodeMap<int>. |
940 | 942 |
typedef typename Digraph::template NodeMap<int> HeapCrossRef; |
941 | 943 |
///Instantiates a \ref HeapCrossRef. |
942 | 944 |
|
943 | 945 |
///This function instantiates a \ref HeapCrossRef. |
944 | 946 |
/// \param g is the digraph, to which we would like to define the |
... | ... |
@@ -994,62 +996,62 @@ |
994 | 996 |
///This function instantiates a ProcessedMap. |
995 | 997 |
///\param g is the digraph, to which |
996 | 998 |
///we would like to define the ProcessedMap. |
997 | 999 |
#ifdef DOXYGEN |
998 | 1000 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
999 | 1001 |
#else |
1000 | 1002 |
static ProcessedMap *createProcessedMap(const Digraph &) |
1001 | 1003 |
#endif |
1002 | 1004 |
{ |
1003 | 1005 |
return new ProcessedMap(); |
1004 | 1006 |
} |
1005 | 1007 |
|
1006 | 1008 |
///The type of the map that stores the distances of the nodes. |
1007 | 1009 |
|
1008 | 1010 |
///The type of the map that stores the distances of the nodes. |
1009 | 1011 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
1010 |
typedef typename Digraph::template NodeMap<typename |
|
1012 |
typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap; |
|
1011 | 1013 |
///Instantiates a DistMap. |
1012 | 1014 |
|
1013 | 1015 |
///This function instantiates a DistMap. |
1014 | 1016 |
///\param g is the digraph, to which we would like to define |
1015 | 1017 |
///the DistMap |
1016 | 1018 |
static DistMap *createDistMap(const Digraph &g) |
1017 | 1019 |
{ |
1018 | 1020 |
return new DistMap(g); |
1019 | 1021 |
} |
1020 | 1022 |
|
1021 | 1023 |
///The type of the shortest paths. |
1022 | 1024 |
|
1023 | 1025 |
///The type of the shortest paths. |
1024 | 1026 |
///It must meet the \ref concepts::Path "Path" concept. |
1025 | 1027 |
typedef lemon::Path<Digraph> Path; |
1026 | 1028 |
}; |
1027 | 1029 |
|
1028 | 1030 |
/// Default traits class used by DijkstraWizard |
1029 | 1031 |
|
1030 | 1032 |
/// To make it easier to use Dijkstra algorithm |
1031 | 1033 |
/// we have created a wizard class. |
1032 | 1034 |
/// This \ref DijkstraWizard class needs default traits, |
1033 | 1035 |
/// as well as the \ref Dijkstra class. |
1034 | 1036 |
/// The \ref DijkstraWizardBase is a class to be the default traits of the |
1035 | 1037 |
/// \ref DijkstraWizard class. |
1036 |
template<class GR,class LM> |
|
1037 |
class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LM> |
|
1038 |
template<typename GR, typename LEN> |
|
1039 |
class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN> |
|
1038 | 1040 |
{ |
1039 |
typedef DijkstraWizardDefaultTraits<GR, |
|
1041 |
typedef DijkstraWizardDefaultTraits<GR,LEN> Base; |
|
1040 | 1042 |
protected: |
1041 | 1043 |
//The type of the nodes in the digraph. |
1042 | 1044 |
typedef typename Base::Digraph::Node Node; |
1043 | 1045 |
|
1044 | 1046 |
//Pointer to the digraph the algorithm runs on. |
1045 | 1047 |
void *_g; |
1046 | 1048 |
//Pointer to the length map. |
1047 | 1049 |
void *_length; |
1048 | 1050 |
//Pointer to the map of processed nodes. |
1049 | 1051 |
void *_processed; |
1050 | 1052 |
//Pointer to the map of predecessors arcs. |
1051 | 1053 |
void *_pred; |
1052 | 1054 |
//Pointer to the map of distances. |
1053 | 1055 |
void *_dist; |
1054 | 1056 |
//Pointer to the shortest path to the target node. |
1055 | 1057 |
void *_path; |
... | ... |
@@ -1057,35 +1059,35 @@ |
1057 | 1059 |
void *_di; |
1058 | 1060 |
|
1059 | 1061 |
public: |
1060 | 1062 |
/// Constructor. |
1061 | 1063 |
|
1062 | 1064 |
/// This constructor does not require parameters, therefore it initiates |
1063 | 1065 |
/// all of the attributes to \c 0. |
1064 | 1066 |
DijkstraWizardBase() : _g(0), _length(0), _processed(0), _pred(0), |
1065 | 1067 |
_dist(0), _path(0), _di(0) {} |
1066 | 1068 |
|
1067 | 1069 |
/// Constructor. |
1068 | 1070 |
|
1069 | 1071 |
/// This constructor requires two parameters, |
1070 | 1072 |
/// others are initiated to \c 0. |
1071 | 1073 |
/// \param g The digraph the algorithm runs on. |
1072 | 1074 |
/// \param l The length map. |
1073 |
DijkstraWizardBase(const GR &g,const |
|
1075 |
DijkstraWizardBase(const GR &g,const LEN &l) : |
|
1074 | 1076 |
_g(reinterpret_cast<void*>(const_cast<GR*>(&g))), |
1075 |
_length(reinterpret_cast<void*>(const_cast< |
|
1077 |
_length(reinterpret_cast<void*>(const_cast<LEN*>(&l))), |
|
1076 | 1078 |
_processed(0), _pred(0), _dist(0), _path(0), _di(0) {} |
1077 | 1079 |
|
1078 | 1080 |
}; |
1079 | 1081 |
|
1080 | 1082 |
/// Auxiliary class for the function-type interface of Dijkstra algorithm. |
1081 | 1083 |
|
1082 | 1084 |
/// This auxiliary class is created to implement the |
1083 | 1085 |
/// \ref dijkstra() "function-type interface" of \ref Dijkstra algorithm. |
1084 | 1086 |
/// It does not have own \ref run(Node) "run()" method, it uses the |
1085 | 1087 |
/// functions and features of the plain \ref Dijkstra. |
1086 | 1088 |
/// |
1087 | 1089 |
/// This class should only be used through the \ref dijkstra() function, |
1088 | 1090 |
/// which makes it easier to use the algorithm. |
1089 | 1091 |
template<class TR> |
1090 | 1092 |
class DijkstraWizard : public TR |
1091 | 1093 |
{ |
... | ... |
@@ -1268,26 +1270,26 @@ |
1268 | 1270 |
///Function-type interface for Dijkstra algorithm. |
1269 | 1271 |
/// |
1270 | 1272 |
///This function also has several \ref named-func-param "named parameters", |
1271 | 1273 |
///they are declared as the members of class \ref DijkstraWizard. |
1272 | 1274 |
///The following examples show how to use these parameters. |
1273 | 1275 |
///\code |
1274 | 1276 |
/// // Compute shortest path from node s to each node |
1275 | 1277 |
/// dijkstra(g,length).predMap(preds).distMap(dists).run(s); |
1276 | 1278 |
/// |
1277 | 1279 |
/// // Compute shortest path from s to t |
1278 | 1280 |
/// bool reached = dijkstra(g,length).path(p).dist(d).run(s,t); |
1279 | 1281 |
///\endcode |
1280 | 1282 |
///\warning Don't forget to put the \ref DijkstraWizard::run(Node) "run()" |
1281 | 1283 |
///to the end of the parameter list. |
1282 | 1284 |
///\sa DijkstraWizard |
1283 | 1285 |
///\sa Dijkstra |
1284 |
template<class GR, class LM> |
|
1285 |
DijkstraWizard<DijkstraWizardBase<GR,LM> > |
|
1286 |
|
|
1286 |
template<typename GR, typename LEN> |
|
1287 |
DijkstraWizard<DijkstraWizardBase<GR,LEN> > |
|
1288 |
dijkstra(const GR &digraph, const LEN &length) |
|
1287 | 1289 |
{ |
1288 |
return DijkstraWizard<DijkstraWizardBase<GR, |
|
1290 |
return DijkstraWizard<DijkstraWizardBase<GR,LEN> >(digraph,length); |
|
1289 | 1291 |
} |
1290 | 1292 |
|
1291 | 1293 |
} //END OF NAMESPACE LEMON |
1292 | 1294 |
|
1293 | 1295 |
#endif |
... | ... |
@@ -242,33 +242,33 @@ |
242 | 242 |
/// original graph is valid in this arc set, therefore the node |
243 | 243 |
/// objects of the original graph can be used directly with this |
244 | 244 |
/// class. The node handling functions (id handling, observing, and |
245 | 245 |
/// iterators) works equivalently as in the original graph. |
246 | 246 |
/// |
247 | 247 |
/// This implementation is based on doubly-linked lists, from each |
248 | 248 |
/// node the outgoing and the incoming arcs make up lists, therefore |
249 | 249 |
/// one arc can be erased in constant time. It also makes possible, |
250 | 250 |
/// that node can be removed from the underlying graph, in this case |
251 | 251 |
/// all arcs incident to the given node is erased from the arc set. |
252 | 252 |
/// |
253 | 253 |
/// \param GR The type of the graph which shares its node set with |
254 | 254 |
/// this class. Its interface must conform to the |
255 | 255 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
256 | 256 |
/// concept. |
257 | 257 |
/// |
258 |
/// This class |
|
258 |
/// This class fully conforms to the \ref concepts::Digraph |
|
259 | 259 |
/// "Digraph" concept. |
260 | 260 |
template <typename GR> |
261 | 261 |
class ListArcSet : public ArcSetExtender<ListArcSetBase<GR> > { |
262 | 262 |
|
263 | 263 |
public: |
264 | 264 |
|
265 | 265 |
typedef ArcSetExtender<ListArcSetBase<GR> > Parent; |
266 | 266 |
|
267 | 267 |
typedef typename Parent::Node Node; |
268 | 268 |
typedef typename Parent::Arc Arc; |
269 | 269 |
|
270 | 270 |
typedef GR Graph; |
271 | 271 |
|
272 | 272 |
|
273 | 273 |
typedef typename Parent::NodesImplBase NodesImplBase; |
274 | 274 |
|
... | ... |
@@ -323,33 +323,33 @@ |
323 | 323 |
|
324 | 324 |
NodesImpl _nodes; |
325 | 325 |
|
326 | 326 |
public: |
327 | 327 |
|
328 | 328 |
/// \brief Constructor of the ArcSet. |
329 | 329 |
/// |
330 | 330 |
/// Constructor of the ArcSet. |
331 | 331 |
ListArcSet(const GR& graph) : _nodes(graph, *this) { |
332 | 332 |
Parent::initalize(graph, _nodes); |
333 | 333 |
} |
334 | 334 |
|
335 | 335 |
/// \brief Add a new arc to the digraph. |
336 | 336 |
/// |
337 | 337 |
/// Add a new arc to the digraph with source node \c s |
338 | 338 |
/// and target node \c t. |
339 |
/// \return |
|
339 |
/// \return The new arc. |
|
340 | 340 |
Arc addArc(const Node& s, const Node& t) { |
341 | 341 |
return Parent::addArc(s, t); |
342 | 342 |
} |
343 | 343 |
|
344 | 344 |
/// \brief Erase an arc from the digraph. |
345 | 345 |
/// |
346 | 346 |
/// Erase an arc \c a from the digraph. |
347 | 347 |
void erase(const Arc& a) { |
348 | 348 |
return Parent::erase(a); |
349 | 349 |
} |
350 | 350 |
|
351 | 351 |
}; |
352 | 352 |
|
353 | 353 |
template <typename GR> |
354 | 354 |
class ListEdgeSetBase { |
355 | 355 |
public: |
... | ... |
@@ -671,33 +671,33 @@ |
671 | 671 |
/// graph is valid in this arc set, therefore the node objects of |
672 | 672 |
/// the original graph can be used directly with this class. The |
673 | 673 |
/// node handling functions (id handling, observing, and iterators) |
674 | 674 |
/// works equivalently as in the original graph. |
675 | 675 |
/// |
676 | 676 |
/// This implementation is based on doubly-linked lists, from each |
677 | 677 |
/// node the incident edges make up lists, therefore one edge can be |
678 | 678 |
/// erased in constant time. It also makes possible, that node can |
679 | 679 |
/// be removed from the underlying graph, in this case all edges |
680 | 680 |
/// incident to the given node is erased from the arc set. |
681 | 681 |
/// |
682 | 682 |
/// \param GR The type of the graph which shares its node set |
683 | 683 |
/// with this class. Its interface must conform to the |
684 | 684 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
685 | 685 |
/// concept. |
686 | 686 |
/// |
687 |
/// This class |
|
687 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
|
688 | 688 |
/// concept. |
689 | 689 |
template <typename GR> |
690 | 690 |
class ListEdgeSet : public EdgeSetExtender<ListEdgeSetBase<GR> > { |
691 | 691 |
|
692 | 692 |
public: |
693 | 693 |
|
694 | 694 |
typedef EdgeSetExtender<ListEdgeSetBase<GR> > Parent; |
695 | 695 |
|
696 | 696 |
typedef typename Parent::Node Node; |
697 | 697 |
typedef typename Parent::Arc Arc; |
698 | 698 |
typedef typename Parent::Edge Edge; |
699 | 699 |
|
700 | 700 |
typedef GR Graph; |
701 | 701 |
|
702 | 702 |
|
703 | 703 |
typedef typename Parent::NodesImplBase NodesImplBase; |
... | ... |
@@ -748,33 +748,33 @@ |
748 | 748 |
|
749 | 749 |
NodesImpl _nodes; |
750 | 750 |
|
751 | 751 |
public: |
752 | 752 |
|
753 | 753 |
/// \brief Constructor of the EdgeSet. |
754 | 754 |
/// |
755 | 755 |
/// Constructor of the EdgeSet. |
756 | 756 |
ListEdgeSet(const GR& graph) : _nodes(graph, *this) { |
757 | 757 |
Parent::initalize(graph, _nodes); |
758 | 758 |
} |
759 | 759 |
|
760 | 760 |
/// \brief Add a new edge to the graph. |
761 | 761 |
/// |
762 | 762 |
/// Add a new edge to the graph with node \c u |
763 | 763 |
/// and node \c v endpoints. |
764 |
/// \return |
|
764 |
/// \return The new edge. |
|
765 | 765 |
Edge addEdge(const Node& u, const Node& v) { |
766 | 766 |
return Parent::addEdge(u, v); |
767 | 767 |
} |
768 | 768 |
|
769 | 769 |
/// \brief Erase an edge from the graph. |
770 | 770 |
/// |
771 | 771 |
/// Erase the edge \c e from the graph. |
772 | 772 |
void erase(const Edge& e) { |
773 | 773 |
return Parent::erase(e); |
774 | 774 |
} |
775 | 775 |
|
776 | 776 |
}; |
777 | 777 |
|
778 | 778 |
template <typename GR> |
779 | 779 |
class SmartArcSetBase { |
780 | 780 |
public: |
... | ... |
@@ -939,33 +939,33 @@ |
939 | 939 |
/// |
940 | 940 |
/// \param GR The type of the graph which shares its node set with |
941 | 941 |
/// this class. Its interface must conform to the |
942 | 942 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
943 | 943 |
/// concept. |
944 | 944 |
/// |
945 | 945 |
/// This implementation is slightly faster than the \c ListArcSet, |
946 | 946 |
/// because it uses continuous storage for arcs and it uses just |
947 | 947 |
/// single-linked lists for enumerate outgoing and incoming |
948 | 948 |
/// arcs. Therefore the arcs cannot be erased from the arc sets. |
949 | 949 |
/// |
950 | 950 |
/// \warning If a node is erased from the underlying graph and this |
951 | 951 |
/// node is the source or target of one arc in the arc set, then |
952 | 952 |
/// the arc set is invalidated, and it cannot be used anymore. The |
953 | 953 |
/// validity can be checked with the \c valid() member function. |
954 | 954 |
/// |
955 |
/// This class |
|
955 |
/// This class fully conforms to the \ref concepts::Digraph |
|
956 | 956 |
/// "Digraph" concept. |
957 | 957 |
template <typename GR> |
958 | 958 |
class SmartArcSet : public ArcSetExtender<SmartArcSetBase<GR> > { |
959 | 959 |
|
960 | 960 |
public: |
961 | 961 |
|
962 | 962 |
typedef ArcSetExtender<SmartArcSetBase<GR> > Parent; |
963 | 963 |
|
964 | 964 |
typedef typename Parent::Node Node; |
965 | 965 |
typedef typename Parent::Arc Arc; |
966 | 966 |
|
967 | 967 |
typedef GR Graph; |
968 | 968 |
|
969 | 969 |
protected: |
970 | 970 |
|
971 | 971 |
typedef typename Parent::NodesImplBase NodesImplBase; |
... | ... |
@@ -1028,33 +1028,33 @@ |
1028 | 1028 |
|
1029 | 1029 |
NodesImpl _nodes; |
1030 | 1030 |
|
1031 | 1031 |
public: |
1032 | 1032 |
|
1033 | 1033 |
/// \brief Constructor of the ArcSet. |
1034 | 1034 |
/// |
1035 | 1035 |
/// Constructor of the ArcSet. |
1036 | 1036 |
SmartArcSet(const GR& graph) : _nodes(graph, *this) { |
1037 | 1037 |
Parent::initalize(graph, _nodes); |
1038 | 1038 |
} |
1039 | 1039 |
|
1040 | 1040 |
/// \brief Add a new arc to the digraph. |
1041 | 1041 |
/// |
1042 | 1042 |
/// Add a new arc to the digraph with source node \c s |
1043 | 1043 |
/// and target node \c t. |
1044 |
/// \return |
|
1044 |
/// \return The new arc. |
|
1045 | 1045 |
Arc addArc(const Node& s, const Node& t) { |
1046 | 1046 |
return Parent::addArc(s, t); |
1047 | 1047 |
} |
1048 | 1048 |
|
1049 | 1049 |
/// \brief Validity check |
1050 | 1050 |
/// |
1051 | 1051 |
/// This functions gives back false if the ArcSet is |
1052 | 1052 |
/// invalidated. It occurs when a node in the underlying graph is |
1053 | 1053 |
/// erased and it is not isolated in the ArcSet. |
1054 | 1054 |
bool valid() const { |
1055 | 1055 |
return _nodes.attached(); |
1056 | 1056 |
} |
1057 | 1057 |
|
1058 | 1058 |
}; |
1059 | 1059 |
|
1060 | 1060 |
|
... | ... |
@@ -1287,33 +1287,33 @@ |
1287 | 1287 |
/// |
1288 | 1288 |
/// \param GR The type of the graph which shares its node set |
1289 | 1289 |
/// with this class. Its interface must conform to the |
1290 | 1290 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
1291 | 1291 |
/// concept. |
1292 | 1292 |
/// |
1293 | 1293 |
/// This implementation is slightly faster than the \c ListEdgeSet, |
1294 | 1294 |
/// because it uses continuous storage for edges and it uses just |
1295 | 1295 |
/// single-linked lists for enumerate incident edges. Therefore the |
1296 | 1296 |
/// edges cannot be erased from the edge sets. |
1297 | 1297 |
/// |
1298 | 1298 |
/// \warning If a node is erased from the underlying graph and this |
1299 | 1299 |
/// node is incident to one edge in the edge set, then the edge set |
1300 | 1300 |
/// is invalidated, and it cannot be used anymore. The validity can |
1301 | 1301 |
/// be checked with the \c valid() member function. |
1302 | 1302 |
/// |
1303 |
/// This class |
|
1303 |
/// This class fully conforms to the \ref concepts::Graph |
|
1304 | 1304 |
/// "Graph" concept. |
1305 | 1305 |
template <typename GR> |
1306 | 1306 |
class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<GR> > { |
1307 | 1307 |
|
1308 | 1308 |
public: |
1309 | 1309 |
|
1310 | 1310 |
typedef EdgeSetExtender<SmartEdgeSetBase<GR> > Parent; |
1311 | 1311 |
|
1312 | 1312 |
typedef typename Parent::Node Node; |
1313 | 1313 |
typedef typename Parent::Arc Arc; |
1314 | 1314 |
typedef typename Parent::Edge Edge; |
1315 | 1315 |
|
1316 | 1316 |
typedef GR Graph; |
1317 | 1317 |
|
1318 | 1318 |
protected: |
1319 | 1319 |
|
... | ... |
@@ -1376,33 +1376,33 @@ |
1376 | 1376 |
|
1377 | 1377 |
NodesImpl _nodes; |
1378 | 1378 |
|
1379 | 1379 |
public: |
1380 | 1380 |
|
1381 | 1381 |
/// \brief Constructor of the EdgeSet. |
1382 | 1382 |
/// |
1383 | 1383 |
/// Constructor of the EdgeSet. |
1384 | 1384 |
SmartEdgeSet(const GR& graph) : _nodes(graph, *this) { |
1385 | 1385 |
Parent::initalize(graph, _nodes); |
1386 | 1386 |
} |
1387 | 1387 |
|
1388 | 1388 |
/// \brief Add a new edge to the graph. |
1389 | 1389 |
/// |
1390 | 1390 |
/// Add a new edge to the graph with node \c u |
1391 | 1391 |
/// and node \c v endpoints. |
1392 |
/// \return |
|
1392 |
/// \return The new edge. |
|
1393 | 1393 |
Edge addEdge(const Node& u, const Node& v) { |
1394 | 1394 |
return Parent::addEdge(u, v); |
1395 | 1395 |
} |
1396 | 1396 |
|
1397 | 1397 |
/// \brief Validity check |
1398 | 1398 |
/// |
1399 | 1399 |
/// This functions gives back false if the EdgeSet is |
1400 | 1400 |
/// invalidated. It occurs when a node in the underlying graph is |
1401 | 1401 |
/// erased and it is not isolated in the EdgeSet. |
1402 | 1402 |
bool valid() const { |
1403 | 1403 |
return _nodes.attached(); |
1404 | 1404 |
} |
1405 | 1405 |
|
1406 | 1406 |
}; |
1407 | 1407 |
|
1408 | 1408 |
} |
... | ... |
@@ -33,50 +33,50 @@ |
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
///Class for handling "labels" in push-relabel type algorithms. |
36 | 36 |
|
37 | 37 |
///A class for handling "labels" in push-relabel type algorithms. |
38 | 38 |
/// |
39 | 39 |
///\ingroup auxdat |
40 | 40 |
///Using this class you can assign "labels" (nonnegative integer numbers) |
41 | 41 |
///to the edges or nodes of a graph, manipulate and query them through |
42 | 42 |
///operations typically arising in "push-relabel" type algorithms. |
43 | 43 |
/// |
44 | 44 |
///Each item is either \em active or not, and you can also choose a |
45 | 45 |
///highest level active item. |
46 | 46 |
/// |
47 | 47 |
///\sa LinkedElevator |
48 | 48 |
/// |
49 |
///\param Graph Type of the underlying graph. |
|
50 |
///\param Item Type of the items the data is assigned to (Graph::Node, |
|
51 |
///Graph::Arc, Graph::Edge). |
|
52 |
template<class Graph, class Item> |
|
49 |
///\param GR Type of the underlying graph. |
|
50 |
///\param Item Type of the items the data is assigned to (\c GR::Node, |
|
51 |
///\c GR::Arc or \c GR::Edge). |
|
52 |
template<class GR, class Item> |
|
53 | 53 |
class Elevator |
54 | 54 |
{ |
55 | 55 |
public: |
56 | 56 |
|
57 | 57 |
typedef Item Key; |
58 | 58 |
typedef int Value; |
59 | 59 |
|
60 | 60 |
private: |
61 | 61 |
|
62 | 62 |
typedef Item *Vit; |
63 |
typedef typename ItemSetTraits<Graph,Item>::template Map<Vit>::Type VitMap; |
|
64 |
typedef typename ItemSetTraits<Graph,Item>::template Map<int>::Type IntMap; |
|
63 |
typedef typename ItemSetTraits<GR,Item>::template Map<Vit>::Type VitMap; |
|
64 |
typedef typename ItemSetTraits<GR,Item>::template Map<int>::Type IntMap; |
|
65 | 65 |
|
66 |
const |
|
66 |
const GR &_g; |
|
67 | 67 |
int _max_level; |
68 | 68 |
int _item_num; |
69 | 69 |
VitMap _where; |
70 | 70 |
IntMap _level; |
71 | 71 |
std::vector<Item> _items; |
72 | 72 |
std::vector<Vit> _first; |
73 | 73 |
std::vector<Vit> _last_active; |
74 | 74 |
|
75 | 75 |
int _highest_active; |
76 | 76 |
|
77 | 77 |
void copy(Item i, Vit p) |
78 | 78 |
{ |
79 | 79 |
_where.set(*p=i,p); |
80 | 80 |
} |
81 | 81 |
void copy(Vit s, Vit p) |
82 | 82 |
{ |
... | ... |
@@ -92,52 +92,52 @@ |
92 | 92 |
Item ti=*i; |
93 | 93 |
Vit ct = _where[ti]; |
94 | 94 |
_where.set(ti,_where[*i=*j]); |
95 | 95 |
_where.set(*j,ct); |
96 | 96 |
*j=ti; |
97 | 97 |
} |
98 | 98 |
|
99 | 99 |
public: |
100 | 100 |
|
101 | 101 |
///Constructor with given maximum level. |
102 | 102 |
|
103 | 103 |
///Constructor with given maximum level. |
104 | 104 |
/// |
105 | 105 |
///\param graph The underlying graph. |
106 | 106 |
///\param max_level The maximum allowed level. |
107 | 107 |
///Set the range of the possible labels to <tt>[0..max_level]</tt>. |
108 |
Elevator(const |
|
108 |
Elevator(const GR &graph,int max_level) : |
|
109 | 109 |
_g(graph), |
110 | 110 |
_max_level(max_level), |
111 | 111 |
_item_num(_max_level), |
112 | 112 |
_where(graph), |
113 | 113 |
_level(graph,0), |
114 | 114 |
_items(_max_level), |
115 | 115 |
_first(_max_level+2), |
116 | 116 |
_last_active(_max_level+2), |
117 | 117 |
_highest_active(-1) {} |
118 | 118 |
///Constructor. |
119 | 119 |
|
120 | 120 |
///Constructor. |
121 | 121 |
/// |
122 | 122 |
///\param graph The underlying graph. |
123 | 123 |
///Set the range of the possible labels to <tt>[0..max_level]</tt>, |
124 | 124 |
///where \c max_level is equal to the number of labeled items in the graph. |
125 |
Elevator(const |
|
125 |
Elevator(const GR &graph) : |
|
126 | 126 |
_g(graph), |
127 |
_max_level(countItems< |
|
127 |
_max_level(countItems<GR, Item>(graph)), |
|
128 | 128 |
_item_num(_max_level), |
129 | 129 |
_where(graph), |
130 | 130 |
_level(graph,0), |
131 | 131 |
_items(_max_level), |
132 | 132 |
_first(_max_level+2), |
133 | 133 |
_last_active(_max_level+2), |
134 | 134 |
_highest_active(-1) |
135 | 135 |
{ |
136 | 136 |
} |
137 | 137 |
|
138 | 138 |
///Activate item \c i. |
139 | 139 |
|
140 | 140 |
///Activate item \c i. |
141 | 141 |
///\pre Item \c i shouldn't be active before. |
142 | 142 |
void activate(Item i) |
143 | 143 |
{ |
... | ... |
@@ -417,33 +417,33 @@ |
417 | 417 |
///\n |
418 | 418 |
///The initialization must be started with calling \c initStart(). |
419 | 419 |
///Then the items should be listed level by level starting with the |
420 | 420 |
///lowest one (level 0) using \c initAddItem() and \c initNewLevel(). |
421 | 421 |
///Finally \c initFinish() must be called. |
422 | 422 |
///The items not listed are put on the highest level. |
423 | 423 |
///@{ |
424 | 424 |
|
425 | 425 |
///Start the initialization process. |
426 | 426 |
void initStart() |
427 | 427 |
{ |
428 | 428 |
_init_lev=0; |
429 | 429 |
_init_num=&_items[0]; |
430 | 430 |
_first[0]=&_items[0]; |
431 | 431 |
_last_active[0]=&_items[0]-1; |
432 | 432 |
Vit n=&_items[0]; |
433 |
for(typename ItemSetTraits< |
|
433 |
for(typename ItemSetTraits<GR,Item>::ItemIt i(_g);i!=INVALID;++i) |
|
434 | 434 |
{ |
435 | 435 |
*n=i; |
436 | 436 |
_where.set(i,n); |
437 | 437 |
_level.set(i,_max_level); |
438 | 438 |
++n; |
439 | 439 |
} |
440 | 440 |
} |
441 | 441 |
|
442 | 442 |
///Add an item to the current level. |
443 | 443 |
void initAddItem(Item i) |
444 | 444 |
{ |
445 | 445 |
swap(_where[i],_init_num); |
446 | 446 |
_level.set(i,_init_lev); |
447 | 447 |
++_init_num; |
448 | 448 |
} |
449 | 449 |
|
... | ... |
@@ -476,83 +476,83 @@ |
476 | 476 |
}; |
477 | 477 |
|
478 | 478 |
///Class for handling "labels" in push-relabel type algorithms. |
479 | 479 |
|
480 | 480 |
///A class for handling "labels" in push-relabel type algorithms. |
481 | 481 |
/// |
482 | 482 |
///\ingroup auxdat |
483 | 483 |
///Using this class you can assign "labels" (nonnegative integer numbers) |
484 | 484 |
///to the edges or nodes of a graph, manipulate and query them through |
485 | 485 |
///operations typically arising in "push-relabel" type algorithms. |
486 | 486 |
/// |
487 | 487 |
///Each item is either \em active or not, and you can also choose a |
488 | 488 |
///highest level active item. |
489 | 489 |
/// |
490 | 490 |
///\sa Elevator |
491 | 491 |
/// |
492 |
///\param Graph Type of the underlying graph. |
|
493 |
///\param Item Type of the items the data is assigned to (Graph::Node, |
|
494 |
///Graph::Arc, Graph::Edge). |
|
495 |
template <class Graph, class Item> |
|
492 |
///\param GR Type of the underlying graph. |
|
493 |
///\param Item Type of the items the data is assigned to (\c GR::Node, |
|
494 |
///\c GR::Arc or \c GR::Edge). |
|
495 |
template <class GR, class Item> |
|
496 | 496 |
class LinkedElevator { |
497 | 497 |
public: |
498 | 498 |
|
499 | 499 |
typedef Item Key; |
500 | 500 |
typedef int Value; |
501 | 501 |
|
502 | 502 |
private: |
503 | 503 |
|
504 |
typedef typename ItemSetTraits< |
|
504 |
typedef typename ItemSetTraits<GR,Item>:: |
|
505 | 505 |
template Map<Item>::Type ItemMap; |
506 |
typedef typename ItemSetTraits< |
|
506 |
typedef typename ItemSetTraits<GR,Item>:: |
|
507 | 507 |
template Map<int>::Type IntMap; |
508 |
typedef typename ItemSetTraits< |
|
508 |
typedef typename ItemSetTraits<GR,Item>:: |
|
509 | 509 |
template Map<bool>::Type BoolMap; |
510 | 510 |
|
511 |
const |
|
511 |
const GR &_graph; |
|
512 | 512 |
int _max_level; |
513 | 513 |
int _item_num; |
514 | 514 |
std::vector<Item> _first, _last; |
515 | 515 |
ItemMap _prev, _next; |
516 | 516 |
int _highest_active; |
517 | 517 |
IntMap _level; |
518 | 518 |
BoolMap _active; |
519 | 519 |
|
520 | 520 |
public: |
521 | 521 |
///Constructor with given maximum level. |
522 | 522 |
|
523 | 523 |
///Constructor with given maximum level. |
524 | 524 |
/// |
525 | 525 |
///\param graph The underlying graph. |
526 | 526 |
///\param max_level The maximum allowed level. |
527 | 527 |
///Set the range of the possible labels to <tt>[0..max_level]</tt>. |
528 |
LinkedElevator(const |
|
528 |
LinkedElevator(const GR& graph, int max_level) |
|
529 | 529 |
: _graph(graph), _max_level(max_level), _item_num(_max_level), |
530 | 530 |
_first(_max_level + 1), _last(_max_level + 1), |
531 | 531 |
_prev(graph), _next(graph), |
532 | 532 |
_highest_active(-1), _level(graph), _active(graph) {} |
533 | 533 |
|
534 | 534 |
///Constructor. |
535 | 535 |
|
536 | 536 |
///Constructor. |
537 | 537 |
/// |
538 | 538 |
///\param graph The underlying graph. |
539 | 539 |
///Set the range of the possible labels to <tt>[0..max_level]</tt>, |
540 | 540 |
///where \c max_level is equal to the number of labeled items in the graph. |
541 |
LinkedElevator(const Graph& graph) |
|
542 |
: _graph(graph), _max_level(countItems<Graph, Item>(graph)), |
|
541 |
LinkedElevator(const GR& graph) |
|
542 |
: _graph(graph), _max_level(countItems<GR, Item>(graph)), |
|
543 | 543 |
_item_num(_max_level), |
544 | 544 |
_first(_max_level + 1), _last(_max_level + 1), |
545 | 545 |
_prev(graph, INVALID), _next(graph, INVALID), |
546 | 546 |
_highest_active(-1), _level(graph), _active(graph) {} |
547 | 547 |
|
548 | 548 |
|
549 | 549 |
///Activate item \c i. |
550 | 550 |
|
551 | 551 |
///Activate item \c i. |
552 | 552 |
///\pre Item \c i shouldn't be active before. |
553 | 553 |
void activate(Item i) { |
554 | 554 |
_active.set(i, true); |
555 | 555 |
|
556 | 556 |
int level = _level[i]; |
557 | 557 |
if (level > _highest_active) { |
558 | 558 |
_highest_active = level; |
... | ... |
@@ -922,33 +922,33 @@ |
922 | 922 |
///Using these functions you can initialize the levels of the items. |
923 | 923 |
///\n |
924 | 924 |
///The initialization must be started with calling \c initStart(). |
925 | 925 |
///Then the items should be listed level by level starting with the |
926 | 926 |
///lowest one (level 0) using \c initAddItem() and \c initNewLevel(). |
927 | 927 |
///Finally \c initFinish() must be called. |
928 | 928 |
///The items not listed are put on the highest level. |
929 | 929 |
///@{ |
930 | 930 |
|
931 | 931 |
///Start the initialization process. |
932 | 932 |
void initStart() { |
933 | 933 |
|
934 | 934 |
for (int i = 0; i <= _max_level; ++i) { |
935 | 935 |
_first[i] = _last[i] = INVALID; |
936 | 936 |
} |
937 | 937 |
_init_level = 0; |
938 |
for(typename ItemSetTraits< |
|
938 |
for(typename ItemSetTraits<GR,Item>::ItemIt i(_graph); |
|
939 | 939 |
i != INVALID; ++i) { |
940 | 940 |
_level.set(i, _max_level); |
941 | 941 |
_active.set(i, false); |
942 | 942 |
} |
943 | 943 |
} |
944 | 944 |
|
945 | 945 |
///Add an item to the current level. |
946 | 946 |
void initAddItem(Item i) { |
947 | 947 |
_level.set(i, _init_level); |
948 | 948 |
if (_last[_init_level] == INVALID) { |
949 | 949 |
_first[_init_level] = i; |
950 | 950 |
_last[_init_level] = i; |
951 | 951 |
_prev.set(i, INVALID); |
952 | 952 |
_next.set(i, INVALID); |
953 | 953 |
} else { |
954 | 954 |
_prev.set(i, _last[_init_level]); |
... | ... |
@@ -41,55 +41,55 @@ |
41 | 41 |
///operator ++, it provides an Euler tour of a \e directed |
42 | 42 |
///graph (if there exists). |
43 | 43 |
/// |
44 | 44 |
///For example |
45 | 45 |
///if the given digraph is Euler (i.e it has only one nontrivial component |
46 | 46 |
///and the in-degree is equal to the out-degree for all nodes), |
47 | 47 |
///the following code will put the arcs of \c g |
48 | 48 |
///to the vector \c et according to an |
49 | 49 |
///Euler tour of \c g. |
50 | 50 |
///\code |
51 | 51 |
/// std::vector<ListDigraph::Arc> et; |
52 | 52 |
/// for(DiEulerIt<ListDigraph> e(g),e!=INVALID;++e) |
53 | 53 |
/// et.push_back(e); |
54 | 54 |
///\endcode |
55 | 55 |
///If \c g is not Euler then the resulted tour will not be full or closed. |
56 | 56 |
///\sa EulerIt |
57 |
template< |
|
57 |
template<typename GR> |
|
58 | 58 |
class DiEulerIt |
59 | 59 |
{ |
60 |
typedef typename Digraph::Node Node; |
|
61 |
typedef typename Digraph::NodeIt NodeIt; |
|
62 |
typedef typename Digraph::Arc Arc; |
|
63 |
typedef typename Digraph::ArcIt ArcIt; |
|
64 |
typedef typename Digraph::OutArcIt OutArcIt; |
|
65 |
typedef typename Digraph::InArcIt InArcIt; |
|
60 |
typedef typename GR::Node Node; |
|
61 |
typedef typename GR::NodeIt NodeIt; |
|
62 |
typedef typename GR::Arc Arc; |
|
63 |
typedef typename GR::ArcIt ArcIt; |
|
64 |
typedef typename GR::OutArcIt OutArcIt; |
|
65 |
typedef typename GR::InArcIt InArcIt; |
|
66 | 66 |
|
67 |
const Digraph &g; |
|
68 |
typename Digraph::template NodeMap<OutArcIt> nedge; |
|
67 |
const GR &g; |
|
68 |
typename GR::template NodeMap<OutArcIt> nedge; |
|
69 | 69 |
std::list<Arc> euler; |
70 | 70 |
|
71 | 71 |
public: |
72 | 72 |
|
73 | 73 |
///Constructor |
74 | 74 |
|
75 |
///\param |
|
75 |
///\param gr A digraph. |
|
76 | 76 |
///\param start The starting point of the tour. If it is not given |
77 | 77 |
/// the tour will start from the first node. |
78 |
DiEulerIt(const Digraph &_g,typename Digraph::Node start=INVALID) |
|
79 |
: g(_g), nedge(g) |
|
78 |
DiEulerIt(const GR &gr, typename GR::Node start = INVALID) |
|
79 |
: g(gr), nedge(g) |
|
80 | 80 |
{ |
81 | 81 |
if(start==INVALID) start=NodeIt(g); |
82 | 82 |
for(NodeIt n(g);n!=INVALID;++n) nedge[n]=OutArcIt(g,n); |
83 | 83 |
while(nedge[start]!=INVALID) { |
84 | 84 |
euler.push_back(nedge[start]); |
85 | 85 |
Node next=g.target(nedge[start]); |
86 | 86 |
++nedge[start]; |
87 | 87 |
start=next; |
88 | 88 |
} |
89 | 89 |
} |
90 | 90 |
|
91 | 91 |
///Arc Conversion |
92 | 92 |
operator Arc() { return euler.empty()?INVALID:euler.front(); } |
93 | 93 |
bool operator==(Invalid) { return euler.empty(); } |
94 | 94 |
bool operator!=(Invalid) { return !euler.empty(); } |
95 | 95 |
|
... | ... |
@@ -132,57 +132,57 @@ |
132 | 132 |
///For example |
133 | 133 |
///if the given digraph if Euler (i.e it has only one nontrivial component |
134 | 134 |
///and the degree of each node is even), |
135 | 135 |
///the following code will print the arc IDs according to an |
136 | 136 |
///Euler tour of \c g. |
137 | 137 |
///\code |
138 | 138 |
/// for(EulerIt<ListGraph> e(g),e!=INVALID;++e) { |
139 | 139 |
/// std::cout << g.id(Edge(e)) << std::eol; |
140 | 140 |
/// } |
141 | 141 |
///\endcode |
142 | 142 |
///Although the iterator provides an Euler tour of an graph, |
143 | 143 |
///it still returns Arcs in order to indicate the direction of the tour. |
144 | 144 |
///(But Arc will convert to Edges, of course). |
145 | 145 |
/// |
146 | 146 |
///If \c g is not Euler then the resulted tour will not be full or closed. |
147 | 147 |
///\sa EulerIt |
148 |
template< |
|
148 |
template<typename GR> |
|
149 | 149 |
class EulerIt |
150 | 150 |
{ |
151 |
typedef typename Digraph::Node Node; |
|
152 |
typedef typename Digraph::NodeIt NodeIt; |
|
153 |
typedef typename Digraph::Arc Arc; |
|
154 |
typedef typename Digraph::Edge Edge; |
|
155 |
typedef typename Digraph::ArcIt ArcIt; |
|
156 |
typedef typename Digraph::OutArcIt OutArcIt; |
|
157 |
typedef typename |
|
151 |
typedef typename GR::Node Node; |
|
152 |
typedef typename GR::NodeIt NodeIt; |
|
153 |
typedef typename GR::Arc Arc; |
|
154 |
typedef typename GR::Edge Edge; |
|
155 |
typedef typename GR::ArcIt ArcIt; |
|
156 |
typedef typename GR::OutArcIt OutArcIt; |
|
157 |
typedef typename GR::InArcIt InArcIt; |
|
158 | 158 |
|
159 |
const Digraph &g; |
|
160 |
typename Digraph::template NodeMap<OutArcIt> nedge; |
|
161 |
|
|
159 |
const GR &g; |
|
160 |
typename GR::template NodeMap<OutArcIt> nedge; |
|
161 |
typename GR::template EdgeMap<bool> visited; |
|
162 | 162 |
std::list<Arc> euler; |
163 | 163 |
|
164 | 164 |
public: |
165 | 165 |
|
166 | 166 |
///Constructor |
167 | 167 |
|
168 |
///\param |
|
168 |
///\param gr An graph. |
|
169 | 169 |
///\param start The starting point of the tour. If it is not given |
170 | 170 |
/// the tour will start from the first node. |
171 |
EulerIt(const Digraph &_g,typename Digraph::Node start=INVALID) |
|
172 |
: g(_g), nedge(g), visited(g,false) |
|
171 |
EulerIt(const GR &gr, typename GR::Node start = INVALID) |
|
172 |
: g(gr), nedge(g), visited(g, false) |
|
173 | 173 |
{ |
174 | 174 |
if(start==INVALID) start=NodeIt(g); |
175 | 175 |
for(NodeIt n(g);n!=INVALID;++n) nedge[n]=OutArcIt(g,n); |
176 | 176 |
while(nedge[start]!=INVALID) { |
177 | 177 |
euler.push_back(nedge[start]); |
178 | 178 |
visited[nedge[start]]=true; |
179 | 179 |
Node next=g.target(nedge[start]); |
180 | 180 |
++nedge[start]; |
181 | 181 |
start=next; |
182 | 182 |
while(nedge[start]!=INVALID && visited[nedge[start]]) ++nedge[start]; |
183 | 183 |
} |
184 | 184 |
} |
185 | 185 |
|
186 | 186 |
///Arc Conversion |
187 | 187 |
operator Arc() const { return euler.empty()?INVALID:euler.front(); } |
188 | 188 |
///Arc Conversion |
... | ... |
@@ -225,40 +225,40 @@ |
225 | 225 |
} |
226 | 226 |
}; |
227 | 227 |
|
228 | 228 |
|
229 | 229 |
///Checks if the graph is Eulerian |
230 | 230 |
|
231 | 231 |
/// \ingroup graph_prop |
232 | 232 |
///Checks if the graph is Eulerian. It works for both directed and undirected |
233 | 233 |
///graphs. |
234 | 234 |
///\note By definition, a digraph is called \e Eulerian if |
235 | 235 |
///and only if it is connected and the number of its incoming and outgoing |
236 | 236 |
///arcs are the same for each node. |
237 | 237 |
///Similarly, an undirected graph is called \e Eulerian if |
238 | 238 |
///and only if it is connected and the number of incident arcs is even |
239 | 239 |
///for each node. <em>Therefore, there are digraphs which are not Eulerian, |
240 | 240 |
///but still have an Euler tour</em>. |
241 |
template< |
|
241 |
template<typename GR> |
|
242 | 242 |
#ifdef DOXYGEN |
243 | 243 |
bool |
244 | 244 |
#else |
245 |
typename enable_if<UndirectedTagIndicator<Digraph>,bool>::type |
|
246 |
eulerian(const Digraph &g) |
|
245 |
typename enable_if<UndirectedTagIndicator<GR>,bool>::type |
|
246 |
eulerian(const GR &g) |
|
247 | 247 |
{ |
248 |
for(typename |
|
248 |
for(typename GR::NodeIt n(g);n!=INVALID;++n) |
|
249 | 249 |
if(countIncEdges(g,n)%2) return false; |
250 | 250 |
return connected(g); |
251 | 251 |
} |
252 |
template<class Digraph> |
|
253 |
typename disable_if<UndirectedTagIndicator<Digraph>,bool>::type |
|
252 |
template<class GR> |
|
253 |
typename disable_if<UndirectedTagIndicator<GR>,bool>::type |
|
254 | 254 |
#endif |
255 |
eulerian(const |
|
255 |
eulerian(const GR &g) |
|
256 | 256 |
{ |
257 |
for(typename |
|
257 |
for(typename GR::NodeIt n(g);n!=INVALID;++n) |
|
258 | 258 |
if(countInArcs(g,n)!=countOutArcs(g,n)) return false; |
259 |
return connected(Undirector<const |
|
259 |
return connected(Undirector<const GR>(g)); |
|
260 | 260 |
} |
261 | 261 |
|
262 | 262 |
} |
263 | 263 |
|
264 | 264 |
#endif |
... | ... |
@@ -51,37 +51,37 @@ |
51 | 51 |
template<class MT> |
52 | 52 |
class _NegY { |
53 | 53 |
public: |
54 | 54 |
typedef typename MT::Key Key; |
55 | 55 |
typedef typename MT::Value Value; |
56 | 56 |
const MT ↦ |
57 | 57 |
int yscale; |
58 | 58 |
_NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {} |
59 | 59 |
Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);} |
60 | 60 |
}; |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
///Default traits class of GraphToEps |
64 | 64 |
|
65 | 65 |
///Default traits class of \ref GraphToEps. |
66 | 66 |
/// |
67 |
///\c G is the type of the underlying graph. |
|
68 |
template<class G> |
|
67 |
///\param GR is the type of the underlying graph. |
|
68 |
template<class GR> |
|
69 | 69 |
struct DefaultGraphToEpsTraits |
70 | 70 |
{ |
71 |
typedef |
|
71 |
typedef GR Graph; |
|
72 | 72 |
typedef typename Graph::Node Node; |
73 | 73 |
typedef typename Graph::NodeIt NodeIt; |
74 | 74 |
typedef typename Graph::Arc Arc; |
75 | 75 |
typedef typename Graph::ArcIt ArcIt; |
76 | 76 |
typedef typename Graph::InArcIt InArcIt; |
77 | 77 |
typedef typename Graph::OutArcIt OutArcIt; |
78 | 78 |
|
79 | 79 |
|
80 | 80 |
const Graph &g; |
81 | 81 |
|
82 | 82 |
std::ostream& os; |
83 | 83 |
|
84 | 84 |
typedef ConstMap<typename Graph::Node,dim2::Point<double> > CoordsMapType; |
85 | 85 |
CoordsMapType _coords; |
86 | 86 |
ConstMap<typename Graph::Node,double > _nodeSizes; |
87 | 87 |
ConstMap<typename Graph::Node,int > _nodeShapes; |
... | ... |
@@ -126,53 +126,52 @@ |
126 | 126 |
enum NodeTextColorType |
127 | 127 |
{ DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType; |
128 | 128 |
ConstMap<typename Graph::Node,Color > _nodeTextColors; |
129 | 129 |
|
130 | 130 |
bool _autoNodeScale; |
131 | 131 |
bool _autoArcWidthScale; |
132 | 132 |
|
133 | 133 |
bool _absoluteNodeSizes; |
134 | 134 |
bool _absoluteArcWidths; |
135 | 135 |
|
136 | 136 |
bool _negY; |
137 | 137 |
|
138 | 138 |
bool _preScale; |
139 | 139 |
///Constructor |
140 | 140 |
|
141 | 141 |
///Constructor |
142 |
///\param _g Reference to the graph to be printed. |
|
143 |
///\param _os Reference to the output stream. |
|
144 |
///\param |
|
142 |
///\param gr Reference to the graph to be printed. |
|
143 |
///\param ost Reference to the output stream. |
|
145 | 144 |
///By default it is <tt>std::cout</tt>. |
146 |
///\param |
|
145 |
///\param pros If it is \c true, then the \c ostream referenced by \c os |
|
147 | 146 |
///will be explicitly deallocated by the destructor. |
148 |
DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, |
|
149 |
bool _pros=false) : |
|
150 |
|
|
147 |
DefaultGraphToEpsTraits(const GR &gr, std::ostream& ost = std::cout, |
|
148 |
bool pros = false) : |
|
149 |
g(gr), os(ost), |
|
151 | 150 |
_coords(dim2::Point<double>(1,1)), _nodeSizes(1), _nodeShapes(0), |
152 | 151 |
_nodeColors(WHITE), _arcColors(BLACK), |
153 | 152 |
_arcWidths(1.0), _arcWidthScale(0.003), |
154 | 153 |
_nodeScale(.01), _xBorder(10), _yBorder(10), _scale(1.0), |
155 | 154 |
_nodeBorderQuotient(.1), |
156 | 155 |
_drawArrows(false), _arrowLength(1), _arrowWidth(0.3), |
157 | 156 |
_showNodes(true), _showArcs(true), |
158 | 157 |
_enableParallel(false), _parArcDist(1), |
159 | 158 |
_showNodeText(false), _nodeTexts(false), _nodeTextSize(1), |
160 | 159 |
_showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0), |
161 |
_undirected(lemon::UndirectedTagIndicator<G>::value), |
|
162 |
_pleaseRemoveOsStream(_pros), _scaleToA4(false), |
|
160 |
_undirected(lemon::UndirectedTagIndicator<GR>::value), |
|
161 |
_pleaseRemoveOsStream(pros), _scaleToA4(false), |
|
163 | 162 |
_nodeTextColorType(SAME_COL), _nodeTextColors(BLACK), |
164 | 163 |
_autoNodeScale(false), |
165 | 164 |
_autoArcWidthScale(false), |
166 | 165 |
_absoluteNodeSizes(false), |
167 | 166 |
_absoluteArcWidths(false), |
168 | 167 |
_negY(false), |
169 | 168 |
_preScale(true) |
170 | 169 |
{} |
171 | 170 |
}; |
172 | 171 |
|
173 | 172 |
///Auxiliary class to implement the named parameters of \ref graphToEps() |
174 | 173 |
|
175 | 174 |
///Auxiliary class to implement the named parameters of \ref graphToEps(). |
176 | 175 |
/// |
177 | 176 |
///For detailed examples see the \ref graph_to_eps_demo.cc demo file. |
178 | 177 |
template<class T> class GraphToEps : public T |
... | ... |
@@ -1121,70 +1120,70 @@ |
1121 | 1120 |
/// |
1122 | 1121 |
///This function also has a lot of |
1123 | 1122 |
///\ref named-templ-func-param "named parameters", |
1124 | 1123 |
///they are declared as the members of class \ref GraphToEps. The following |
1125 | 1124 |
///example shows how to use these parameters. |
1126 | 1125 |
///\code |
1127 | 1126 |
/// graphToEps(g,os).scale(10).coords(coords) |
1128 | 1127 |
/// .nodeScale(2).nodeSizes(sizes) |
1129 | 1128 |
/// .arcWidthScale(.4).run(); |
1130 | 1129 |
///\endcode |
1131 | 1130 |
/// |
1132 | 1131 |
///For more detailed examples see the \ref graph_to_eps_demo.cc demo file. |
1133 | 1132 |
/// |
1134 | 1133 |
///\warning Don't forget to put the \ref GraphToEps::run() "run()" |
1135 | 1134 |
///to the end of the parameter list. |
1136 | 1135 |
///\sa GraphToEps |
1137 |
///\sa graphToEps(G &g, const char *file_name) |
|
1138 |
template<class G> |
|
1139 |
GraphToEps<DefaultGraphToEpsTraits<G> > |
|
1140 |
graphToEps(G &g, std::ostream& os=std::cout) |
|
1136 |
///\sa graphToEps(GR &g, const char *file_name) |
|
1137 |
template<class GR> |
|
1138 |
GraphToEps<DefaultGraphToEpsTraits<GR> > |
|
1139 |
graphToEps(GR &g, std::ostream& os=std::cout) |
|
1141 | 1140 |
{ |
1142 | 1141 |
return |
1143 |
GraphToEps<DefaultGraphToEpsTraits< |
|
1142 |
GraphToEps<DefaultGraphToEpsTraits<GR> >(DefaultGraphToEpsTraits<GR>(g,os)); |
|
1144 | 1143 |
} |
1145 | 1144 |
|
1146 | 1145 |
///Generates an EPS file from a graph |
1147 | 1146 |
|
1148 | 1147 |
///\ingroup eps_io |
1149 | 1148 |
///This function does the same as |
1150 |
///\ref graphToEps( |
|
1149 |
///\ref graphToEps(GR &g,std::ostream& os) |
|
1151 | 1150 |
///but it writes its output into the file \c file_name |
1152 | 1151 |
///instead of a stream. |
1153 |
///\sa graphToEps(G &g, std::ostream& os) |
|
1154 |
template<class G> |
|
1155 |
GraphToEps<DefaultGraphToEpsTraits<G> > |
|
1156 |
graphToEps(G &g,const char *file_name) |
|
1152 |
///\sa graphToEps(GR &g, std::ostream& os) |
|
1153 |
template<class GR> |
|
1154 |
GraphToEps<DefaultGraphToEpsTraits<GR> > |
|
1155 |
graphToEps(GR &g,const char *file_name) |
|
1157 | 1156 |
{ |
1158 | 1157 |
std::ostream* os = new std::ofstream(file_name); |
1159 | 1158 |
if (!(*os)) { |
1160 | 1159 |
delete os; |
1161 | 1160 |
throw IoError("Cannot write file", file_name); |
1162 | 1161 |
} |
1163 |
return GraphToEps<DefaultGraphToEpsTraits<G> > |
|
1164 |
(DefaultGraphToEpsTraits<G>(g,*os,true)); |
|
1162 |
return GraphToEps<DefaultGraphToEpsTraits<GR> > |
|
1163 |
(DefaultGraphToEpsTraits<GR>(g,*os,true)); |
|
1165 | 1164 |
} |
1166 | 1165 |
|
1167 | 1166 |
///Generates an EPS file from a graph |
1168 | 1167 |
|
1169 | 1168 |
///\ingroup eps_io |
1170 | 1169 |
///This function does the same as |
1171 |
///\ref graphToEps( |
|
1170 |
///\ref graphToEps(GR &g,std::ostream& os) |
|
1172 | 1171 |
///but it writes its output into the file \c file_name |
1173 | 1172 |
///instead of a stream. |
1174 |
///\sa graphToEps(G &g, std::ostream& os) |
|
1175 |
template<class G> |
|
1176 |
GraphToEps<DefaultGraphToEpsTraits<G> > |
|
1177 |
graphToEps(G &g,const std::string& file_name) |
|
1173 |
///\sa graphToEps(GR &g, std::ostream& os) |
|
1174 |
template<class GR> |
|
1175 |
GraphToEps<DefaultGraphToEpsTraits<GR> > |
|
1176 |
graphToEps(GR &g,const std::string& file_name) |
|
1178 | 1177 |
{ |
1179 | 1178 |
std::ostream* os = new std::ofstream(file_name.c_str()); |
1180 | 1179 |
if (!(*os)) { |
1181 | 1180 |
delete os; |
1182 | 1181 |
throw IoError("Cannot write file", file_name); |
1183 | 1182 |
} |
1184 |
return GraphToEps<DefaultGraphToEpsTraits<G> > |
|
1185 |
(DefaultGraphToEpsTraits<G>(g,*os,true)); |
|
1183 |
return GraphToEps<DefaultGraphToEpsTraits<GR> > |
|
1184 |
(DefaultGraphToEpsTraits<GR>(g,*os,true)); |
|
1186 | 1185 |
} |
1187 | 1186 |
|
1188 | 1187 |
} //END OF NAMESPACE LEMON |
1189 | 1188 |
|
1190 | 1189 |
#endif // LEMON_GRAPH_TO_EPS_H |
... | ... |
@@ -483,33 +483,33 @@ |
483 | 483 |
/// origin. |
484 | 484 |
/// |
485 | 485 |
/// \image html grid_graph.png |
486 | 486 |
/// \image latex grid_graph.eps "Grid graph" width=\textwidth |
487 | 487 |
/// |
488 | 488 |
/// A short example about the basic usage: |
489 | 489 |
///\code |
490 | 490 |
/// GridGraph graph(rows, cols); |
491 | 491 |
/// GridGraph::NodeMap<int> val(graph); |
492 | 492 |
/// for (int i = 0; i < graph.width(); ++i) { |
493 | 493 |
/// for (int j = 0; j < graph.height(); ++j) { |
494 | 494 |
/// val[graph(i, j)] = i + j; |
495 | 495 |
/// } |
496 | 496 |
/// } |
497 | 497 |
///\endcode |
498 | 498 |
/// |
499 |
/// This graph type |
|
499 |
/// This graph type fully conforms to the \ref concepts::Graph |
|
500 | 500 |
/// "Graph" concept, and it also has an important extra feature |
501 | 501 |
/// that its maps are real \ref concepts::ReferenceMap |
502 | 502 |
/// "reference map"s. |
503 | 503 |
class GridGraph : public ExtendedGridGraphBase { |
504 | 504 |
public: |
505 | 505 |
|
506 | 506 |
typedef ExtendedGridGraphBase Parent; |
507 | 507 |
|
508 | 508 |
/// \brief Map to get the indices of the nodes as dim2::Point<int>. |
509 | 509 |
/// |
510 | 510 |
/// Map to get the indices of the nodes as dim2::Point<int>. |
511 | 511 |
class IndexMap { |
512 | 512 |
public: |
513 | 513 |
/// \brief The key type of the map |
514 | 514 |
typedef GridGraph::Node Key; |
515 | 515 |
/// \brief The value type of the map |
... | ... |
@@ -44,53 +44,53 @@ |
44 | 44 |
/// \f$D=(V,A)\f$. It takes a fixed node \f$ source \in V \f$ and |
45 | 45 |
/// consists of two phases: in the first phase it determines a |
46 | 46 |
/// minimum cut with \f$ source \f$ on the source-side (i.e. a set |
47 | 47 |
/// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal |
48 | 48 |
/// out-degree) and in the second phase it determines a minimum cut |
49 | 49 |
/// with \f$ source \f$ on the sink-side (i.e. a set |
50 | 50 |
/// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal |
51 | 51 |
/// out-degree). Obviously, the smaller of these two cuts will be a |
52 | 52 |
/// minimum cut of \f$ D \f$. The algorithm is a modified |
53 | 53 |
/// push-relabel preflow algorithm and our implementation calculates |
54 | 54 |
/// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the |
55 | 55 |
/// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The |
56 | 56 |
/// purpose of such algorithm is testing network reliability. For an |
57 | 57 |
/// undirected graph you can run just the first phase of the |
58 | 58 |
/// algorithm or you can use the algorithm of Nagamochi and Ibaraki |
59 | 59 |
/// which solves the undirected problem in |
60 |
/// \f$ O(nm + n^2 \log |
|
60 |
/// \f$ O(nm + n^2 \log n) \f$ time: it is implemented in the |
|
61 | 61 |
/// NagamochiIbaraki algorithm class. |
62 | 62 |
/// |
63 |
/// \param _Digraph is the graph type of the algorithm. |
|
64 |
/// \param _CapacityMap is an edge map of capacities which should |
|
65 |
/// be any numreric type. The default type is _Digraph::ArcMap<int>. |
|
66 |
/// \param _Tolerance is the handler of the inexact computation. The |
|
67 |
/// |
|
63 |
/// \param GR The digraph class the algorithm runs on. |
|
64 |
/// \param CAP An arc map of capacities which can be any numreric type. |
|
65 |
/// The default type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
|
66 |
/// \param TOL Tolerance class for handling inexact computations. The |
|
67 |
/// default tolerance type is \ref Tolerance "Tolerance<CAP::Value>". |
|
68 | 68 |
#ifdef DOXYGEN |
69 |
template <typename |
|
69 |
template <typename GR, typename CAP, typename TOL> |
|
70 | 70 |
#else |
71 |
template <typename _Digraph, |
|
72 |
typename _CapacityMap = typename _Digraph::template ArcMap<int>, |
|
73 |
|
|
71 |
template <typename GR, |
|
72 |
typename CAP = typename GR::template ArcMap<int>, |
|
73 |
typename TOL = Tolerance<typename CAP::Value> > |
|
74 | 74 |
#endif |
75 | 75 |
class HaoOrlin { |
76 | 76 |
private: |
77 | 77 |
|
78 |
typedef _Digraph Digraph; |
|
79 |
typedef _CapacityMap CapacityMap; |
|
80 |
typedef |
|
78 |
typedef GR Digraph; |
|
79 |
typedef CAP CapacityMap; |
|
80 |
typedef TOL Tolerance; |
|
81 | 81 |
|
82 | 82 |
typedef typename CapacityMap::Value Value; |
83 | 83 |
|
84 | 84 |
TEMPLATE_GRAPH_TYPEDEFS(Digraph); |
85 | 85 |
|
86 | 86 |
const Digraph& _graph; |
87 | 87 |
const CapacityMap* _capacity; |
88 | 88 |
|
89 | 89 |
typedef typename Digraph::template ArcMap<Value> FlowMap; |
90 | 90 |
FlowMap* _flow; |
91 | 91 |
|
92 | 92 |
Node _source; |
93 | 93 |
|
94 | 94 |
int _node_num; |
95 | 95 |
|
96 | 96 |
// Bucketing structure |
... | ... |
@@ -804,33 +804,33 @@ |
804 | 804 |
deactivate(target); |
805 | 805 |
} |
806 | 806 |
|
807 | 807 |
_highest = _sets.back().begin(); |
808 | 808 |
while (_highest != _sets.back().end() && |
809 | 809 |
!(*_active)[_first[*_highest]]) { |
810 | 810 |
++_highest; |
811 | 811 |
} |
812 | 812 |
} |
813 | 813 |
} |
814 | 814 |
} |
815 | 815 |
|
816 | 816 |
public: |
817 | 817 |
|
818 | 818 |
/// \name Execution control |
819 | 819 |
/// The simplest way to execute the algorithm is to use |
820 |
/// one of the member functions called \ |
|
820 |
/// one of the member functions called \ref run(). |
|
821 | 821 |
/// \n |
822 | 822 |
/// If you need more control on the execution, |
823 | 823 |
/// first you must call \ref init(), then the \ref calculateIn() or |
824 | 824 |
/// \ref calculateOut() functions. |
825 | 825 |
|
826 | 826 |
/// @{ |
827 | 827 |
|
828 | 828 |
/// \brief Initializes the internal data structures. |
829 | 829 |
/// |
830 | 830 |
/// Initializes the internal data structures. It creates |
831 | 831 |
/// the maps, residual graph adaptors and some bucket structures |
832 | 832 |
/// for the algorithm. |
833 | 833 |
void init() { |
834 | 834 |
init(NodeIt(_graph)); |
835 | 835 |
} |
836 | 836 |
... | ... |
@@ -278,33 +278,33 @@ |
278 | 278 |
|
279 | 279 |
typedef GraphExtender<HypercubeGraphBase> ExtendedHypercubeGraphBase; |
280 | 280 |
|
281 | 281 |
/// \ingroup graphs |
282 | 282 |
/// |
283 | 283 |
/// \brief Hypercube graph class |
284 | 284 |
/// |
285 | 285 |
/// This class implements a special graph type. The nodes of the graph |
286 | 286 |
/// are indiced with integers with at most \c dim binary digits. |
287 | 287 |
/// Two nodes are connected in the graph if and only if their indices |
288 | 288 |
/// differ only on one position in the binary form. |
289 | 289 |
/// |
290 | 290 |
/// \note The type of the indices is chosen to \c int for efficiency |
291 | 291 |
/// reasons. Thus the maximum dimension of this implementation is 26 |
292 | 292 |
/// (assuming that the size of \c int is 32 bit). |
293 | 293 |
/// |
294 |
/// This graph type |
|
294 |
/// This graph type fully conforms to the \ref concepts::Graph |
|
295 | 295 |
/// "Graph" concept, and it also has an important extra feature |
296 | 296 |
/// that its maps are real \ref concepts::ReferenceMap |
297 | 297 |
/// "reference map"s. |
298 | 298 |
class HypercubeGraph : public ExtendedHypercubeGraphBase { |
299 | 299 |
public: |
300 | 300 |
|
301 | 301 |
typedef ExtendedHypercubeGraphBase Parent; |
302 | 302 |
|
303 | 303 |
/// \brief Constructs a hypercube graph with \c dim dimensions. |
304 | 304 |
/// |
305 | 305 |
/// Constructs a hypercube graph with \c dim dimensions. |
306 | 306 |
HypercubeGraph(int dim) { construct(dim); } |
307 | 307 |
|
308 | 308 |
/// \brief The number of dimensions. |
309 | 309 |
/// |
310 | 310 |
/// Gives back the number of dimensions. |
... | ... |
@@ -435,42 +435,42 @@ |
435 | 435 |
/// |
436 | 436 |
/// The \c useNodes() and \c useArcs() functions are used to tell the reader |
437 | 437 |
/// that the nodes or arcs should not be constructed (added to the |
438 | 438 |
/// graph) during the reading, but instead the label map of the items |
439 | 439 |
/// are given as a parameter of these functions. An |
440 | 440 |
/// application of these functions is multipass reading, which is |
441 | 441 |
/// important if two \c \@arcs sections must be read from the |
442 | 442 |
/// file. In this case the first phase would read the node set and one |
443 | 443 |
/// of the arc sets, while the second phase would read the second arc |
444 | 444 |
/// set into an \e ArcSet class (\c SmartArcSet or \c ListArcSet). |
445 | 445 |
/// The previously read label node map should be passed to the \c |
446 | 446 |
/// useNodes() functions. Another application of multipass reading when |
447 | 447 |
/// paths are given as a node map or an arc map. |
448 | 448 |
/// It is impossible to read this in |
449 | 449 |
/// a single pass, because the arcs are not constructed when the node |
450 | 450 |
/// maps are read. |
451 |
template <typename |
|
451 |
template <typename GR> |
|
452 | 452 |
class DigraphReader { |
453 | 453 |
public: |
454 | 454 |
|
455 |
typedef |
|
455 |
typedef GR Digraph; |
|
456 |
|
|
457 |
private: |
|
458 |
|
|
456 | 459 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
457 | 460 |
|
458 |
private: |
|
459 |
|
|
460 |
|
|
461 | 461 |
std::istream* _is; |
462 | 462 |
bool local_is; |
463 | 463 |
std::string _filename; |
464 | 464 |
|
465 | 465 |
Digraph& _digraph; |
466 | 466 |
|
467 | 467 |
std::string _nodes_caption; |
468 | 468 |
std::string _arcs_caption; |
469 | 469 |
std::string _attributes_caption; |
470 | 470 |
|
471 | 471 |
typedef std::map<std::string, Node> NodeIndex; |
472 | 472 |
NodeIndex _node_index; |
473 | 473 |
typedef std::map<std::string, Arc> ArcIndex; |
474 | 474 |
ArcIndex _arc_index; |
475 | 475 |
|
476 | 476 |
typedef std::vector<std::pair<std::string, |
... | ... |
@@ -1233,41 +1233,42 @@ |
1233 | 1233 |
|
1234 | 1234 |
/// \ingroup lemon_io |
1235 | 1235 |
/// |
1236 | 1236 |
/// \brief \ref lgf-format "LGF" reader for undirected graphs |
1237 | 1237 |
/// |
1238 | 1238 |
/// This utility reads an \ref lgf-format "LGF" file. |
1239 | 1239 |
/// |
1240 | 1240 |
/// It can be used almost the same way as \c DigraphReader. |
1241 | 1241 |
/// The only difference is that this class can handle edges and |
1242 | 1242 |
/// edge maps as well as arcs and arc maps. |
1243 | 1243 |
/// |
1244 | 1244 |
/// The columns in the \c \@edges (or \c \@arcs) section are the |
1245 | 1245 |
/// edge maps. However, if there are two maps with the same name |
1246 | 1246 |
/// prefixed with \c '+' and \c '-', then these can be read into an |
1247 | 1247 |
/// arc map. Similarly, an attribute can be read into an arc, if |
1248 | 1248 |
/// it's value is an edge label prefixed with \c '+' or \c '-'. |
1249 |
template <typename |
|
1249 |
template <typename GR> |
|
1250 | 1250 |
class GraphReader { |
1251 | 1251 |
public: |
1252 | 1252 |
|
1253 |
typedef |
|
1253 |
typedef GR Graph; |
|
1254 |
|
|
1255 |
private: |
|
1256 |
|
|
1254 | 1257 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
1255 | 1258 |
|
1256 |
private: |
|
1257 |
|
|
1258 | 1259 |
std::istream* _is; |
1259 | 1260 |
bool local_is; |
1260 | 1261 |
std::string _filename; |
1261 | 1262 |
|
1262 | 1263 |
Graph& _graph; |
1263 | 1264 |
|
1264 | 1265 |
std::string _nodes_caption; |
1265 | 1266 |
std::string _edges_caption; |
1266 | 1267 |
std::string _attributes_caption; |
1267 | 1268 |
|
1268 | 1269 |
typedef std::map<std::string, Node> NodeIndex; |
1269 | 1270 |
NodeIndex _node_index; |
1270 | 1271 |
typedef std::map<std::string, Edge> EdgeIndex; |
1271 | 1272 |
EdgeIndex _edge_index; |
1272 | 1273 |
|
1273 | 1274 |
typedef std::vector<std::pair<std::string, |
... | ... |
@@ -1343,38 +1344,38 @@ |
1343 | 1344 |
it != _edge_maps.end(); ++it) { |
1344 | 1345 |
delete it->second; |
1345 | 1346 |
} |
1346 | 1347 |
|
1347 | 1348 |
for (typename Attributes::iterator it = _attributes.begin(); |
1348 | 1349 |
it != _attributes.end(); ++it) { |
1349 | 1350 |
delete it->second; |
1350 | 1351 |
} |
1351 | 1352 |
|
1352 | 1353 |
if (local_is) { |
1353 | 1354 |
delete _is; |
1354 | 1355 |
} |
1355 | 1356 |
|
1356 | 1357 |
} |
1357 | 1358 |
|
1358 | 1359 |
private: |
1359 |
template <typename GR> |
|
1360 |
friend GraphReader<GR> graphReader(GR& graph, std::istream& is); |
|
1361 |
template <typename GR> |
|
1362 |
friend GraphReader<GR> graphReader(GR& graph, const std::string& fn); |
|
1363 |
template <typename GR> |
|
1364 |
friend GraphReader<GR> graphReader(GR& graph, const char *fn); |
|
1360 |
template <typename Graph> |
|
1361 |
friend GraphReader<Graph> graphReader(Graph& graph, std::istream& is); |
|
1362 |
template <typename Graph> |
|
1363 |
friend GraphReader<Graph> graphReader(Graph& graph, const std::string& fn); |
|
1364 |
template <typename Graph> |
|
1365 |
friend GraphReader<Graph> graphReader(Graph& graph, const char *fn); |
|
1365 | 1366 |
|
1366 | 1367 |
GraphReader(GraphReader& other) |
1367 | 1368 |
: _is(other._is), local_is(other.local_is), _graph(other._graph), |
1368 | 1369 |
_use_nodes(other._use_nodes), _use_edges(other._use_edges), |
1369 | 1370 |
_skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { |
1370 | 1371 |
|
1371 | 1372 |
other._is = 0; |
1372 | 1373 |
other.local_is = false; |
1373 | 1374 |
|
1374 | 1375 |
_node_index.swap(other._node_index); |
1375 | 1376 |
_edge_index.swap(other._edge_index); |
1376 | 1377 |
|
1377 | 1378 |
_node_maps.swap(other._node_maps); |
1378 | 1379 |
_edge_maps.swap(other._edge_maps); |
1379 | 1380 |
_attributes.swap(other._attributes); |
1380 | 1381 |
... | ... |
@@ -393,37 +393,37 @@ |
393 | 393 |
///\endcode |
394 | 394 |
/// |
395 | 395 |
/// |
396 | 396 |
/// By default, the writer does not write additional captions to the |
397 | 397 |
/// sections, but they can be give as an optional parameter of |
398 | 398 |
/// the \c nodes(), \c arcs() or \c |
399 | 399 |
/// attributes() functions. |
400 | 400 |
/// |
401 | 401 |
/// The \c skipNodes() and \c skipArcs() functions forbid the |
402 | 402 |
/// writing of the sections. If two arc sections should be written |
403 | 403 |
/// to the output, it can be done in two passes, the first pass |
404 | 404 |
/// writes the node section and the first arc section, then the |
405 | 405 |
/// second pass skips the node section and writes just the arc |
406 | 406 |
/// section to the stream. The output stream can be retrieved with |
407 | 407 |
/// the \c ostream() function, hence the second pass can append its |
408 | 408 |
/// output to the output of the first pass. |
409 |
template <typename |
|
409 |
template <typename GR> |
|
410 | 410 |
class DigraphWriter { |
411 | 411 |
public: |
412 | 412 |
|
413 |
typedef |
|
413 |
typedef GR Digraph; |
|
414 | 414 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
415 | 415 |
|
416 | 416 |
private: |
417 | 417 |
|
418 | 418 |
|
419 | 419 |
std::ostream* _os; |
420 | 420 |
bool local_os; |
421 | 421 |
|
422 | 422 |
const Digraph& _digraph; |
423 | 423 |
|
424 | 424 |
std::string _nodes_caption; |
425 | 425 |
std::string _arcs_caption; |
426 | 426 |
std::string _attributes_caption; |
427 | 427 |
|
428 | 428 |
typedef std::map<Node, std::string> NodeIndex; |
429 | 429 |
NodeIndex _node_index; |
... | ... |
@@ -961,37 +961,37 @@ |
961 | 961 |
|
962 | 962 |
/// \ingroup lemon_io |
963 | 963 |
/// |
964 | 964 |
/// \brief \ref lgf-format "LGF" writer for directed graphs |
965 | 965 |
/// |
966 | 966 |
/// This utility writes an \ref lgf-format "LGF" file. |
967 | 967 |
/// |
968 | 968 |
/// It can be used almost the same way as \c DigraphWriter. |
969 | 969 |
/// The only difference is that this class can handle edges and |
970 | 970 |
/// edge maps as well as arcs and arc maps. |
971 | 971 |
/// |
972 | 972 |
/// The arc maps are written into the file as two columns, the |
973 | 973 |
/// caption of the columns are the name of the map prefixed with \c |
974 | 974 |
/// '+' and \c '-'. The arcs are written into the \c \@attributes |
975 | 975 |
/// section as a \c '+' or a \c '-' prefix (depends on the direction |
976 | 976 |
/// of the arc) and the label of corresponding edge. |
977 |
template <typename |
|
977 |
template <typename GR> |
|
978 | 978 |
class GraphWriter { |
979 | 979 |
public: |
980 | 980 |
|
981 |
typedef |
|
981 |
typedef GR Graph; |
|
982 | 982 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
983 | 983 |
|
984 | 984 |
private: |
985 | 985 |
|
986 | 986 |
|
987 | 987 |
std::ostream* _os; |
988 | 988 |
bool local_os; |
989 | 989 |
|
990 | 990 |
const Graph& _graph; |
991 | 991 |
|
992 | 992 |
std::string _nodes_caption; |
993 | 993 |
std::string _edges_caption; |
994 | 994 |
std::string _attributes_caption; |
995 | 995 |
|
996 | 996 |
typedef std::map<Node, std::string> NodeIndex; |
997 | 997 |
NodeIndex _node_index; |
... | ... |
@@ -1060,40 +1060,40 @@ |
1060 | 1060 |
it != _edge_maps.end(); ++it) { |
1061 | 1061 |
delete it->second; |
1062 | 1062 |
} |
1063 | 1063 |
|
1064 | 1064 |
for (typename Attributes::iterator it = _attributes.begin(); |
1065 | 1065 |
it != _attributes.end(); ++it) { |
1066 | 1066 |
delete it->second; |
1067 | 1067 |
} |
1068 | 1068 |
|
1069 | 1069 |
if (local_os) { |
1070 | 1070 |
delete _os; |
1071 | 1071 |
} |
1072 | 1072 |
} |
1073 | 1073 |
|
1074 | 1074 |
private: |
1075 | 1075 |
|
1076 |
template <typename GR> |
|
1077 |
friend GraphWriter<GR> graphWriter(const GR& graph, |
|
1076 |
template <typename Graph> |
|
1077 |
friend GraphWriter<Graph> graphWriter(const Graph& graph, |
|
1078 | 1078 |
std::ostream& os); |
1079 |
template <typename GR> |
|
1080 |
friend GraphWriter<GR> graphWriter(const GR& graph, |
|
1079 |
template <typename Graph> |
|
1080 |
friend GraphWriter<Graph> graphWriter(const Graph& graph, |
|
1081 | 1081 |
const std::string& fn); |
1082 |
template <typename GR> |
|
1083 |
friend GraphWriter<GR> graphWriter(const GR& graph, |
|
1082 |
template <typename Graph> |
|
1083 |
friend GraphWriter<Graph> graphWriter(const Graph& graph, |
|
1084 | 1084 |
const char *fn); |
1085 | 1085 |
|
1086 | 1086 |
GraphWriter(GraphWriter& other) |
1087 | 1087 |
: _os(other._os), local_os(other.local_os), _graph(other._graph), |
1088 | 1088 |
_skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { |
1089 | 1089 |
|
1090 | 1090 |
other._os = 0; |
1091 | 1091 |
other.local_os = false; |
1092 | 1092 |
|
1093 | 1093 |
_node_index.swap(other._node_index); |
1094 | 1094 |
_edge_index.swap(other._edge_index); |
1095 | 1095 |
|
1096 | 1096 |
_node_maps.swap(other._node_maps); |
1097 | 1097 |
_edge_maps.swap(other._edge_maps); |
1098 | 1098 |
_attributes.swap(other._attributes); |
1099 | 1099 |
... | ... |
@@ -338,40 +338,40 @@ |
338 | 338 |
///Assignment of ListDigraph to another one is \e not allowed. |
339 | 339 |
///Use copyDigraph() instead. |
340 | 340 |
void operator=(const ListDigraph &) {} |
341 | 341 |
public: |
342 | 342 |
|
343 | 343 |
typedef ExtendedListDigraphBase Parent; |
344 | 344 |
|
345 | 345 |
/// Constructor |
346 | 346 |
|
347 | 347 |
/// Constructor. |
348 | 348 |
/// |
349 | 349 |
ListDigraph() {} |
350 | 350 |
|
351 | 351 |
///Add a new node to the digraph. |
352 | 352 |
|
353 | 353 |
///Add a new node to the digraph. |
354 |
///\return |
|
354 |
///\return The new node. |
|
355 | 355 |
Node addNode() { return Parent::addNode(); } |
356 | 356 |
|
357 | 357 |
///Add a new arc to the digraph. |
358 | 358 |
|
359 | 359 |
///Add a new arc to the digraph with source node \c s |
360 | 360 |
///and target node \c t. |
361 |
///\return |
|
361 |
///\return The new arc. |
|
362 | 362 |
Arc addArc(const Node& s, const Node& t) { |
363 | 363 |
return Parent::addArc(s, t); |
364 | 364 |
} |
365 | 365 |
|
366 | 366 |
///\brief Erase a node from the digraph. |
367 | 367 |
/// |
368 | 368 |
///Erase a node from the digraph. |
369 | 369 |
/// |
370 | 370 |
void erase(const Node& n) { Parent::erase(n); } |
371 | 371 |
|
372 | 372 |
///\brief Erase an arc from the digraph. |
373 | 373 |
/// |
374 | 374 |
///Erase an arc from the digraph. |
375 | 375 |
/// |
376 | 376 |
void erase(const Arc& a) { Parent::erase(a); } |
377 | 377 |
|
... | ... |
@@ -1195,40 +1195,40 @@ |
1195 | 1195 |
///Use copyGraph() instead. |
1196 | 1196 |
void operator=(const ListGraph &) {} |
1197 | 1197 |
public: |
1198 | 1198 |
/// Constructor |
1199 | 1199 |
|
1200 | 1200 |
/// Constructor. |
1201 | 1201 |
/// |
1202 | 1202 |
ListGraph() {} |
1203 | 1203 |
|
1204 | 1204 |
typedef ExtendedListGraphBase Parent; |
1205 | 1205 |
|
1206 | 1206 |
typedef Parent::OutArcIt IncEdgeIt; |
1207 | 1207 |
|
1208 | 1208 |
/// \brief Add a new node to the graph. |
1209 | 1209 |
/// |
1210 | 1210 |
/// Add a new node to the graph. |
1211 |
/// \return |
|
1211 |
/// \return The new node. |
|
1212 | 1212 |
Node addNode() { return Parent::addNode(); } |
1213 | 1213 |
|
1214 | 1214 |
/// \brief Add a new edge to the graph. |
1215 | 1215 |
/// |
1216 | 1216 |
/// Add a new edge to the graph with source node \c s |
1217 | 1217 |
/// and target node \c t. |
1218 |
/// \return |
|
1218 |
/// \return The new edge. |
|
1219 | 1219 |
Edge addEdge(const Node& s, const Node& t) { |
1220 | 1220 |
return Parent::addEdge(s, t); |
1221 | 1221 |
} |
1222 | 1222 |
|
1223 | 1223 |
/// \brief Erase a node from the graph. |
1224 | 1224 |
/// |
1225 | 1225 |
/// Erase a node from the graph. |
1226 | 1226 |
/// |
1227 | 1227 |
void erase(const Node& n) { Parent::erase(n); } |
1228 | 1228 |
|
1229 | 1229 |
/// \brief Erase an edge from the graph. |
1230 | 1230 |
/// |
1231 | 1231 |
/// Erase an edge from the graph. |
1232 | 1232 |
/// |
1233 | 1233 |
void erase(const Edge& e) { Parent::erase(e); } |
1234 | 1234 |
/// Node validity check |
Changeset was too big and was cut off... Show full diff
0 comments (0 inline)