gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Unify sources
0 68 0
r1.1.4 1.1
68 files changed with 641 insertions and 619 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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 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.
... ...
@@ -254,80 +254,80 @@
254 254
@defgroup algs Algorithms
255 255
\brief This group contains the several algorithms
256 256
implemented in LEMON.
257 257

	
258 258
This group contains the several algorithms
259 259
implemented in LEMON.
260 260
*/
261 261

	
262 262
/**
263 263
@defgroup search Graph Search
264 264
@ingroup algs
265 265
\brief Common graph search algorithms.
266 266

	
267 267
This group contains the common graph search algorithms, namely
268 268
\e breadth-first \e search (BFS) and \e depth-first \e search (DFS).
269 269
*/
270 270

	
271 271
/**
272 272
@defgroup shortest_path Shortest Path Algorithms
273 273
@ingroup algs
274 274
\brief Algorithms for finding shortest paths.
275 275

	
276 276
This group contains the algorithms for finding shortest paths in digraphs.
277 277

	
278
 - \ref Dijkstra Dijkstra's algorithm for finding shortest paths from a 
278
 - \ref Dijkstra Dijkstra's algorithm for finding shortest paths from a
279 279
   source node when all arc lengths are non-negative.
280 280
 - \ref Suurballe A successive shortest path algorithm for finding
281 281
   arc-disjoint paths between two nodes having minimum total length.
282 282
*/
283 283

	
284 284
/**
285 285
@defgroup max_flow Maximum Flow Algorithms
286 286
@ingroup algs
287 287
\brief Algorithms for finding maximum flows.
288 288

	
289 289
This group contains the algorithms for finding maximum flows and
290 290
feasible circulations.
291 291

	
292 292
The \e maximum \e flow \e problem is to find a flow of maximum value between
293 293
a single source and a single target. Formally, there is a \f$G=(V,A)\f$
294 294
digraph, a \f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function and
295 295
\f$s, t \in V\f$ source and target nodes.
296 296
A maximum flow is an \f$f: A\rightarrow\mathbf{R}^+_0\f$ solution of the
297 297
following optimization problem.
298 298

	
299 299
\f[ \max\sum_{sv\in A} f(sv) - \sum_{vs\in A} f(vs) \f]
300 300
\f[ \sum_{uv\in A} f(uv) = \sum_{vu\in A} f(vu)
301 301
    \quad \forall u\in V\setminus\{s,t\} \f]
302 302
\f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f]
303 303

	
304 304
\ref Preflow implements the preflow push-relabel algorithm of Goldberg and
305 305
Tarjan for solving this problem. It also provides functions to query the
306 306
minimum cut, which is the dual problem of maximum flow.
307 307

	
308 308

	
309
\ref Circulation is a preflow push-relabel algorithm implemented directly 
309
\ref Circulation is a preflow push-relabel algorithm implemented directly
310 310
for finding feasible circulations, which is a somewhat different problem,
311 311
but it is strongly related to maximum flow.
312 312
For more information, see \ref Circulation.
313 313
*/
314 314

	
315 315
/**
316 316
@defgroup min_cost_flow_algs Minimum Cost Flow Algorithms
317 317
@ingroup algs
318 318

	
319 319
\brief Algorithms for finding minimum cost flows and circulations.
320 320

	
321 321
This group contains the algorithms for finding minimum cost flows and
322 322
circulations. For more information about this problem and its dual
323 323
solution see \ref min_cost_flow "Minimum Cost Flow Problem".
324 324

	
325 325
\ref NetworkSimplex is an efficient implementation of the primal Network
326 326
Simplex algorithm for finding minimum cost flows. It also provides dual
327 327
solution (node potentials), if an optimal flow is found.
328 328
*/
329 329

	
330 330
/**
331 331
@defgroup min_cut Minimum Cut Algorithms
332 332
@ingroup algs
333 333

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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

	
23 23

	
24 24
\page lgf-format LEMON Graph Format (LGF)
25 25

	
26 26
The \e LGF is a <em>column oriented</em>
27 27
file format for storing graphs and associated data like
28 28
node and edge maps.
29 29

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
\page min_cost_flow Minimum Cost Flow Problem
23 23

	
24 24
\section mcf_def Definition (GEQ form)
25 25

	
26 26
The \e minimum \e cost \e flow \e problem is to find a feasible flow of
27 27
minimum total cost from a set of supply nodes to a set of demand nodes
28 28
in a network with capacity constraints (lower and upper bounds)
29 29
and arc costs.
... ...
@@ -60,87 +60,87 @@
60 60
\section mcf_algs Algorithms
61 61

	
62 62
LEMON contains several algorithms for solving this problem, for more
63 63
information see \ref min_cost_flow_algs "Minimum Cost Flow Algorithms".
64 64

	
65 65
A feasible solution for this problem can be found using \ref Circulation.
66 66

	
67 67

	
68 68
\section mcf_dual Dual Solution
69 69

	
70 70
The dual solution of the minimum cost flow problem is represented by
71 71
node potentials \f$\pi: V\rightarrow\mathbf{R}\f$.
72 72
An \f$f: A\rightarrow\mathbf{R}\f$ primal feasible solution is optimal
73 73
if and only if for some \f$\pi: V\rightarrow\mathbf{R}\f$ node potentials
74 74
the following \e complementary \e slackness optimality conditions hold.
75 75

	
76 76
 - For all \f$uv\in A\f$ arcs:
77 77
   - if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$;
78 78
   - if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$;
79 79
   - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
80 80
 - For all \f$u\in V\f$ nodes:
81 81
   - \f$\pi(u)<=0\f$;
82 82
   - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
83 83
     then \f$\pi(u)=0\f$.
84
 
84

	
85 85
Here \f$cost^\pi(uv)\f$ denotes the \e reduced \e cost of the arc
86 86
\f$uv\in A\f$ with respect to the potential function \f$\pi\f$, i.e.
87 87
\f[ cost^\pi(uv) = cost(uv) + \pi(u) - \pi(v).\f]
88 88

	
89 89
All algorithms provide dual solution (node potentials), as well,
90 90
if an optimal flow is found.
91 91

	
92 92

	
93 93
\section mcf_eq Equality Form
94 94

	
95 95
The above \ref mcf_def "definition" is actually more general than the
96 96
usual formulation of the minimum cost flow problem, in which strict
97 97
equalities are required in the supply/demand contraints.
98 98

	
99 99
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f]
100 100
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) =
101 101
    sup(u) \quad \forall u\in V \f]
102 102
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f]
103 103

	
104 104
However if the sum of the supply values is zero, then these two problems
105 105
are equivalent.
106 106
The \ref min_cost_flow_algs "algorithms" in LEMON support the general
107 107
form, so if you need the equality form, you have to ensure this additional
108 108
contraint manually.
109 109

	
110 110

	
111 111
\section mcf_leq Opposite Inequalites (LEQ Form)
112 112

	
113 113
Another possible definition of the minimum cost flow problem is
114 114
when there are <em>"less or equal"</em> (LEQ) supply/demand constraints,
115 115
instead of the <em>"greater or equal"</em> (GEQ) constraints.
116 116

	
117 117
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f]
118 118
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \leq
119 119
    sup(u) \quad \forall u\in V \f]
120 120
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f]
121 121

	
122
It means that the total demand must be less or equal to the 
122
It means that the total demand must be less or equal to the
123 123
total supply (i.e. \f$\sum_{u\in V} sup(u)\f$ must be zero or
124 124
positive) and all the demands have to be satisfied, but there
125 125
could be supplies that are not carried out from the supply
126 126
nodes.
127 127
The equality form is also a special case of this form, of course.
128 128

	
129 129
You could easily transform this case to the \ref mcf_def "GEQ form"
130 130
of the problem by reversing the direction of the arcs and taking the
131 131
negative of the supply values (e.g. using \ref ReverseDigraph and
132 132
\ref NegMap adaptors).
133 133
However \ref NetworkSimplex algorithm also supports this form directly
134 134
for the sake of convenience.
135 135

	
136 136
Note that the optimality conditions for this supply constraint type are
137 137
slightly differ from the conditions that are discussed for the GEQ form,
138 138
namely the potentials have to be non-negative instead of non-positive.
139 139
An \f$f: A\rightarrow\mathbf{R}\f$ feasible solution of this problem
140 140
is optimal if and only if for some \f$\pi: V\rightarrow\mathbf{R}\f$
141 141
node potentials the following conditions hold.
142 142

	
143 143
 - For all \f$uv\in A\f$ arcs:
144 144
   - if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$;
145 145
   - if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$;
146 146
   - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_ADAPTORS_H
20 20
#define LEMON_ADAPTORS_H
21 21

	
22 22
/// \ingroup graph_adaptors
23 23
/// \file
24 24
/// \brief Adaptor classes for digraphs and graphs
25 25
///
26 26
/// This file contains several useful adaptors for digraphs and graphs.
27 27

	
28 28
#include <lemon/core.h>
29 29
#include <lemon/maps.h>
... ...
@@ -397,49 +397,49 @@
397 397
  template<typename DGR>
398 398
  ReverseDigraph<const DGR> reverseDigraph(const DGR& digraph) {
399 399
    return ReverseDigraph<const DGR>(digraph);
400 400
  }
401 401

	
402 402

	
403 403
  template <typename DGR, typename NF, typename AF, bool ch = true>
404 404
  class SubDigraphBase : public DigraphAdaptorBase<DGR> {
405 405
    typedef DigraphAdaptorBase<DGR> Parent;
406 406
  public:
407 407
    typedef DGR Digraph;
408 408
    typedef NF NodeFilterMap;
409 409
    typedef AF ArcFilterMap;
410 410

	
411 411
    typedef SubDigraphBase Adaptor;
412 412
  protected:
413 413
    NF* _node_filter;
414 414
    AF* _arc_filter;
415 415
    SubDigraphBase()
416 416
      : Parent(), _node_filter(0), _arc_filter(0) { }
417 417

	
418 418
    void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) {
419 419
      Parent::initialize(digraph);
420 420
      _node_filter = &node_filter;
421
      _arc_filter = &arc_filter;      
421
      _arc_filter = &arc_filter;
422 422
    }
423 423

	
424 424
  public:
425 425

	
426 426
    typedef typename Parent::Node Node;
427 427
    typedef typename Parent::Arc Arc;
428 428

	
429 429
    void first(Node& i) const {
430 430
      Parent::first(i);
431 431
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
432 432
    }
433 433

	
434 434
    void first(Arc& i) const {
435 435
      Parent::first(i);
436 436
      while (i != INVALID && (!(*_arc_filter)[i]
437 437
                              || !(*_node_filter)[Parent::source(i)]
438 438
                              || !(*_node_filter)[Parent::target(i)]))
439 439
        Parent::next(i);
440 440
    }
441 441

	
442 442
    void firstIn(Arc& i, const Node& n) const {
443 443
      Parent::firstIn(i, n);
444 444
      while (i != INVALID && (!(*_arc_filter)[i]
445 445
                              || !(*_node_filter)[Parent::source(i)]))
... ...
@@ -484,123 +484,123 @@
484 484
    void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
485 485

	
486 486
    bool status(const Node& n) const { return (*_node_filter)[n]; }
487 487
    bool status(const Arc& a) const { return (*_arc_filter)[a]; }
488 488

	
489 489
    typedef False NodeNumTag;
490 490
    typedef False ArcNumTag;
491 491

	
492 492
    typedef FindArcTagIndicator<DGR> FindArcTag;
493 493
    Arc findArc(const Node& source, const Node& target,
494 494
                const Arc& prev = INVALID) const {
495 495
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
496 496
        return INVALID;
497 497
      }
498 498
      Arc arc = Parent::findArc(source, target, prev);
499 499
      while (arc != INVALID && !(*_arc_filter)[arc]) {
500 500
        arc = Parent::findArc(source, target, arc);
501 501
      }
502 502
      return arc;
503 503
    }
504 504

	
505 505
  public:
506 506

	
507 507
    template <typename V>
508
    class NodeMap 
509
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, 
510
	      LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
508
    class NodeMap
509
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
510
              LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
511 511
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
512
	LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
512
        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
513 513

	
514 514
    public:
515 515
      typedef V Value;
516 516

	
517 517
      NodeMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor)
518 518
        : Parent(adaptor) {}
519 519
      NodeMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor, const V& value)
520 520
        : Parent(adaptor, value) {}
521 521

	
522 522
    private:
523 523
      NodeMap& operator=(const NodeMap& cmap) {
524 524
        return operator=<NodeMap>(cmap);
525 525
      }
526 526

	
527 527
      template <typename CMap>
528 528
      NodeMap& operator=(const CMap& cmap) {
529 529
        Parent::operator=(cmap);
530 530
        return *this;
531 531
      }
532 532
    };
533 533

	
534 534
    template <typename V>
535
    class ArcMap 
535
    class ArcMap
536 536
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
537
	      LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
537
              LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
538 538
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
539 539
        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
540 540

	
541 541
    public:
542 542
      typedef V Value;
543 543

	
544 544
      ArcMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor)
545 545
        : Parent(adaptor) {}
546 546
      ArcMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor, const V& value)
547 547
        : Parent(adaptor, value) {}
548 548

	
549 549
    private:
550 550
      ArcMap& operator=(const ArcMap& cmap) {
551 551
        return operator=<ArcMap>(cmap);
552 552
      }
553 553

	
554 554
      template <typename CMap>
555 555
      ArcMap& operator=(const CMap& cmap) {
556 556
        Parent::operator=(cmap);
557 557
        return *this;
558 558
      }
559 559
    };
560 560

	
561 561
  };
562 562

	
563 563
  template <typename DGR, typename NF, typename AF>
564 564
  class SubDigraphBase<DGR, NF, AF, false>
565 565
    : public DigraphAdaptorBase<DGR> {
566 566
    typedef DigraphAdaptorBase<DGR> Parent;
567 567
  public:
568 568
    typedef DGR Digraph;
569 569
    typedef NF NodeFilterMap;
570 570
    typedef AF ArcFilterMap;
571 571

	
572 572
    typedef SubDigraphBase Adaptor;
573 573
  protected:
574 574
    NF* _node_filter;
575 575
    AF* _arc_filter;
576 576
    SubDigraphBase()
577 577
      : Parent(), _node_filter(0), _arc_filter(0) { }
578 578

	
579 579
    void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) {
580 580
      Parent::initialize(digraph);
581 581
      _node_filter = &node_filter;
582
      _arc_filter = &arc_filter;      
582
      _arc_filter = &arc_filter;
583 583
    }
584 584

	
585 585
  public:
586 586

	
587 587
    typedef typename Parent::Node Node;
588 588
    typedef typename Parent::Arc Arc;
589 589

	
590 590
    void first(Node& i) const {
591 591
      Parent::first(i);
592 592
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
593 593
    }
594 594

	
595 595
    void first(Arc& i) const {
596 596
      Parent::first(i);
597 597
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
598 598
    }
599 599

	
600 600
    void firstIn(Arc& i, const Node& n) const {
601 601
      Parent::firstIn(i, n);
602 602
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
603 603
    }
604 604

	
605 605
    void firstOut(Arc& i, const Node& n) const {
606 606
      Parent::firstOut(i, n);
... ...
@@ -627,76 +627,76 @@
627 627

	
628 628
    void status(const Node& n, bool v) const { _node_filter->set(n, v); }
629 629
    void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
630 630

	
631 631
    bool status(const Node& n) const { return (*_node_filter)[n]; }
632 632
    bool status(const Arc& a) const { return (*_arc_filter)[a]; }
633 633

	
634 634
    typedef False NodeNumTag;
635 635
    typedef False ArcNumTag;
636 636

	
637 637
    typedef FindArcTagIndicator<DGR> FindArcTag;
638 638
    Arc findArc(const Node& source, const Node& target,
639 639
                const Arc& prev = INVALID) const {
640 640
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
641 641
        return INVALID;
642 642
      }
643 643
      Arc arc = Parent::findArc(source, target, prev);
644 644
      while (arc != INVALID && !(*_arc_filter)[arc]) {
645 645
        arc = Parent::findArc(source, target, arc);
646 646
      }
647 647
      return arc;
648 648
    }
649 649

	
650 650
    template <typename V>
651
    class NodeMap 
651
    class NodeMap
652 652
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
653 653
          LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
654
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, 
654
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
655 655
        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
656 656

	
657 657
    public:
658 658
      typedef V Value;
659 659

	
660 660
      NodeMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor)
661 661
        : Parent(adaptor) {}
662 662
      NodeMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value)
663 663
        : Parent(adaptor, value) {}
664 664

	
665 665
    private:
666 666
      NodeMap& operator=(const NodeMap& cmap) {
667 667
        return operator=<NodeMap>(cmap);
668 668
      }
669 669

	
670 670
      template <typename CMap>
671 671
      NodeMap& operator=(const CMap& cmap) {
672 672
        Parent::operator=(cmap);
673 673
        return *this;
674 674
      }
675 675
    };
676 676

	
677 677
    template <typename V>
678
    class ArcMap 
678
    class ArcMap
679 679
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
680 680
          LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
681 681
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
682 682
        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
683 683

	
684 684
    public:
685 685
      typedef V Value;
686 686

	
687 687
      ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor)
688 688
        : Parent(adaptor) {}
689 689
      ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value)
690 690
        : Parent(adaptor, value) {}
691 691

	
692 692
    private:
693 693
      ArcMap& operator=(const ArcMap& cmap) {
694 694
        return operator=<ArcMap>(cmap);
695 695
      }
696 696

	
697 697
      template <typename CMap>
698 698
      ArcMap& operator=(const CMap& cmap) {
699 699
        Parent::operator=(cmap);
700 700
        return *this;
701 701
      }
702 702
    };
... ...
@@ -995,146 +995,146 @@
995 995
      if (!(*_node_filter)[u] || !(*_node_filter)[v]) {
996 996
        return INVALID;
997 997
      }
998 998
      Arc arc = Parent::findArc(u, v, prev);
999 999
      while (arc != INVALID && !(*_edge_filter)[arc]) {
1000 1000
        arc = Parent::findArc(u, v, arc);
1001 1001
      }
1002 1002
      return arc;
1003 1003
    }
1004 1004

	
1005 1005
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
1006 1006
    Edge findEdge(const Node& u, const Node& v,
1007 1007
                  const Edge& prev = INVALID) const {
1008 1008
      if (!(*_node_filter)[u] || !(*_node_filter)[v]) {
1009 1009
        return INVALID;
1010 1010
      }
1011 1011
      Edge edge = Parent::findEdge(u, v, prev);
1012 1012
      while (edge != INVALID && !(*_edge_filter)[edge]) {
1013 1013
        edge = Parent::findEdge(u, v, edge);
1014 1014
      }
1015 1015
      return edge;
1016 1016
    }
1017 1017

	
1018 1018
    template <typename V>
1019
    class NodeMap 
1019
    class NodeMap
1020 1020
      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
1021 1021
          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
1022
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
1022
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
1023 1023
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
1024 1024

	
1025 1025
    public:
1026 1026
      typedef V Value;
1027 1027

	
1028 1028
      NodeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
1029 1029
        : Parent(adaptor) {}
1030 1030
      NodeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
1031 1031
        : Parent(adaptor, value) {}
1032 1032

	
1033 1033
    private:
1034 1034
      NodeMap& operator=(const NodeMap& cmap) {
1035 1035
        return operator=<NodeMap>(cmap);
1036 1036
      }
1037 1037

	
1038 1038
      template <typename CMap>
1039 1039
      NodeMap& operator=(const CMap& cmap) {
1040 1040
        Parent::operator=(cmap);
1041 1041
        return *this;
1042 1042
      }
1043 1043
    };
1044 1044

	
1045 1045
    template <typename V>
1046
    class ArcMap 
1046
    class ArcMap
1047 1047
      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
1048 1048
          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
1049
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
1049
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
1050 1050
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
1051 1051

	
1052 1052
    public:
1053 1053
      typedef V Value;
1054 1054

	
1055 1055
      ArcMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
1056 1056
        : Parent(adaptor) {}
1057 1057
      ArcMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
1058 1058
        : Parent(adaptor, value) {}
1059 1059

	
1060 1060
    private:
1061 1061
      ArcMap& operator=(const ArcMap& cmap) {
1062 1062
        return operator=<ArcMap>(cmap);
1063 1063
      }
1064 1064

	
1065 1065
      template <typename CMap>
1066 1066
      ArcMap& operator=(const CMap& cmap) {
1067 1067
        Parent::operator=(cmap);
1068 1068
        return *this;
1069 1069
      }
1070 1070
    };
1071 1071

	
1072 1072
    template <typename V>
1073
    class EdgeMap 
1073
    class EdgeMap
1074 1074
      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
1075 1075
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
1076
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
1076
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
1077 1077
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
1078 1078

	
1079 1079
    public:
1080 1080
      typedef V Value;
1081 1081

	
1082 1082
      EdgeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
1083 1083
        : Parent(adaptor) {}
1084 1084

	
1085 1085
      EdgeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
1086 1086
        : Parent(adaptor, value) {}
1087 1087

	
1088 1088
    private:
1089 1089
      EdgeMap& operator=(const EdgeMap& cmap) {
1090 1090
        return operator=<EdgeMap>(cmap);
1091 1091
      }
1092 1092

	
1093 1093
      template <typename CMap>
1094 1094
      EdgeMap& operator=(const CMap& cmap) {
1095 1095
        Parent::operator=(cmap);
1096 1096
        return *this;
1097 1097
      }
1098 1098
    };
1099 1099

	
1100 1100
  };
1101 1101

	
1102 1102
  template <typename GR, typename NF, typename EF>
1103 1103
  class SubGraphBase<GR, NF, EF, false>
1104 1104
    : public GraphAdaptorBase<GR> {
1105 1105
    typedef GraphAdaptorBase<GR> Parent;
1106 1106
  public:
1107 1107
    typedef GR Graph;
1108 1108
    typedef NF NodeFilterMap;
1109 1109
    typedef EF EdgeFilterMap;
1110 1110

	
1111 1111
    typedef SubGraphBase Adaptor;
1112 1112
  protected:
1113 1113
    NF* _node_filter;
1114 1114
    EF* _edge_filter;
1115
    SubGraphBase() 
1116
	  : Parent(), _node_filter(0), _edge_filter(0) { }
1115
    SubGraphBase()
1116
          : Parent(), _node_filter(0), _edge_filter(0) { }
1117 1117

	
1118 1118
    void initialize(GR& graph, NF& node_filter, EF& edge_filter) {
1119 1119
      Parent::initialize(graph);
1120 1120
      _node_filter = &node_filter;
1121 1121
      _edge_filter = &edge_filter;
1122 1122
    }
1123 1123

	
1124 1124
  public:
1125 1125

	
1126 1126
    typedef typename Parent::Node Node;
1127 1127
    typedef typename Parent::Arc Arc;
1128 1128
    typedef typename Parent::Edge Edge;
1129 1129

	
1130 1130
    void first(Node& i) const {
1131 1131
      Parent::first(i);
1132 1132
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
1133 1133
    }
1134 1134

	
1135 1135
    void first(Arc& i) const {
1136 1136
      Parent::first(i);
1137 1137
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
1138 1138
    }
1139 1139

	
1140 1140
    void first(Edge& i) const {
... ...
@@ -1193,107 +1193,107 @@
1193 1193
    typedef False ArcNumTag;
1194 1194
    typedef False EdgeNumTag;
1195 1195

	
1196 1196
    typedef FindArcTagIndicator<Graph> FindArcTag;
1197 1197
    Arc findArc(const Node& u, const Node& v,
1198 1198
                const Arc& prev = INVALID) const {
1199 1199
      Arc arc = Parent::findArc(u, v, prev);
1200 1200
      while (arc != INVALID && !(*_edge_filter)[arc]) {
1201 1201
        arc = Parent::findArc(u, v, arc);
1202 1202
      }
1203 1203
      return arc;
1204 1204
    }
1205 1205

	
1206 1206
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
1207 1207
    Edge findEdge(const Node& u, const Node& v,
1208 1208
                  const Edge& prev = INVALID) const {
1209 1209
      Edge edge = Parent::findEdge(u, v, prev);
1210 1210
      while (edge != INVALID && !(*_edge_filter)[edge]) {
1211 1211
        edge = Parent::findEdge(u, v, edge);
1212 1212
      }
1213 1213
      return edge;
1214 1214
    }
1215 1215

	
1216 1216
    template <typename V>
1217
    class NodeMap 
1217
    class NodeMap
1218 1218
      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
1219 1219
          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
1220
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
1220
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
1221 1221
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
1222 1222

	
1223 1223
    public:
1224 1224
      typedef V Value;
1225 1225

	
1226 1226
      NodeMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
1227 1227
        : Parent(adaptor) {}
1228 1228
      NodeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
1229 1229
        : Parent(adaptor, value) {}
1230 1230

	
1231 1231
    private:
1232 1232
      NodeMap& operator=(const NodeMap& cmap) {
1233 1233
        return operator=<NodeMap>(cmap);
1234 1234
      }
1235 1235

	
1236 1236
      template <typename CMap>
1237 1237
      NodeMap& operator=(const CMap& cmap) {
1238 1238
        Parent::operator=(cmap);
1239 1239
        return *this;
1240 1240
      }
1241 1241
    };
1242 1242

	
1243 1243
    template <typename V>
1244
    class ArcMap 
1244
    class ArcMap
1245 1245
      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
1246 1246
          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
1247
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
1247
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
1248 1248
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
1249 1249

	
1250 1250
    public:
1251 1251
      typedef V Value;
1252 1252

	
1253 1253
      ArcMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
1254 1254
        : Parent(adaptor) {}
1255 1255
      ArcMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
1256 1256
        : Parent(adaptor, value) {}
1257 1257

	
1258 1258
    private:
1259 1259
      ArcMap& operator=(const ArcMap& cmap) {
1260 1260
        return operator=<ArcMap>(cmap);
1261 1261
      }
1262 1262

	
1263 1263
      template <typename CMap>
1264 1264
      ArcMap& operator=(const CMap& cmap) {
1265 1265
        Parent::operator=(cmap);
1266 1266
        return *this;
1267 1267
      }
1268 1268
    };
1269 1269

	
1270 1270
    template <typename V>
1271
    class EdgeMap 
1271
    class EdgeMap
1272 1272
      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
1273 1273
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
1274
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
1275
	LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
1274
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
1275
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
1276 1276

	
1277 1277
    public:
1278 1278
      typedef V Value;
1279 1279

	
1280 1280
      EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
1281 1281
        : Parent(adaptor) {}
1282 1282

	
1283 1283
      EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
1284 1284
        : Parent(adaptor, value) {}
1285 1285

	
1286 1286
    private:
1287 1287
      EdgeMap& operator=(const EdgeMap& cmap) {
1288 1288
        return operator=<EdgeMap>(cmap);
1289 1289
      }
1290 1290

	
1291 1291
      template <typename CMap>
1292 1292
      EdgeMap& operator=(const CMap& cmap) {
1293 1293
        Parent::operator=(cmap);
1294 1294
        return *this;
1295 1295
      }
1296 1296
    };
1297 1297

	
1298 1298
  };
1299 1299

	
... ...
@@ -1474,112 +1474,112 @@
1474 1474
  /// \tparam GR The type of the adapted digraph or graph.
1475 1475
  /// It must conform to the \ref concepts::Digraph "Digraph" concept
1476 1476
  /// or the \ref concepts::Graph "Graph" concept.
1477 1477
  /// It can also be specified to be \c const.
1478 1478
  /// \tparam NF The type of the node filter map.
1479 1479
  /// It must be a \c bool (or convertible) node map of the
1480 1480
  /// adapted (di)graph. The default type is
1481 1481
  /// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>".
1482 1482
  ///
1483 1483
  /// \note The \c Node and <tt>Arc/Edge</tt> types of this adaptor and the
1484 1484
  /// adapted (di)graph are convertible to each other.
1485 1485
#ifdef DOXYGEN
1486 1486
  template<typename GR, typename NF>
1487 1487
  class FilterNodes {
1488 1488
#else
1489 1489
  template<typename GR,
1490 1490
           typename NF = typename GR::template NodeMap<bool>,
1491 1491
           typename Enable = void>
1492 1492
  class FilterNodes :
1493 1493
    public DigraphAdaptorExtender<
1494 1494
      SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >,
1495 1495
                     true> > {
1496 1496
#endif
1497 1497
    typedef DigraphAdaptorExtender<
1498
      SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, 
1498
      SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >,
1499 1499
                     true> > Parent;
1500 1500

	
1501 1501
  public:
1502 1502

	
1503 1503
    typedef GR Digraph;
1504 1504
    typedef NF NodeFilterMap;
1505 1505

	
1506 1506
    typedef typename Parent::Node Node;
1507 1507

	
1508 1508
  protected:
1509 1509
    ConstMap<typename Digraph::Arc, Const<bool, true> > const_true_map;
1510 1510

	
1511 1511
    FilterNodes() : const_true_map() {}
1512 1512

	
1513 1513
  public:
1514 1514

	
1515 1515
    /// \brief Constructor
1516 1516
    ///
1517 1517
    /// Creates a subgraph for the given digraph or graph with the
1518 1518
    /// given node filter map.
1519
    FilterNodes(GR& graph, NF& node_filter) 
1519
    FilterNodes(GR& graph, NF& node_filter)
1520 1520
      : Parent(), const_true_map()
1521 1521
    {
1522 1522
      Parent::initialize(graph, node_filter, const_true_map);
1523 1523
    }
1524 1524

	
1525 1525
    /// \brief Sets the status of the given node
1526 1526
    ///
1527 1527
    /// This function sets the status of the given node.
1528 1528
    /// It is done by simply setting the assigned value of \c n
1529 1529
    /// to \c v in the node filter map.
1530 1530
    void status(const Node& n, bool v) const { Parent::status(n, v); }
1531 1531

	
1532 1532
    /// \brief Returns the status of the given node
1533 1533
    ///
1534 1534
    /// This function returns the status of the given node.
1535 1535
    /// It is \c true if the given node is enabled (i.e. not hidden).
1536 1536
    bool status(const Node& n) const { return Parent::status(n); }
1537 1537

	
1538 1538
    /// \brief Disables the given node
1539 1539
    ///
1540 1540
    /// This function disables the given node, so the iteration
1541 1541
    /// jumps over it.
1542 1542
    /// It is the same as \ref status() "status(n, false)".
1543 1543
    void disable(const Node& n) const { Parent::status(n, false); }
1544 1544

	
1545 1545
    /// \brief Enables the given node
1546 1546
    ///
1547 1547
    /// This function enables the given node.
1548 1548
    /// It is the same as \ref status() "status(n, true)".
1549 1549
    void enable(const Node& n) const { Parent::status(n, true); }
1550 1550

	
1551 1551
  };
1552 1552

	
1553 1553
  template<typename GR, typename NF>
1554 1554
  class FilterNodes<GR, NF,
1555 1555
                    typename enable_if<UndirectedTagIndicator<GR> >::type> :
1556 1556
    public GraphAdaptorExtender<
1557
      SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 
1557
      SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >,
1558 1558
                   true> > {
1559 1559

	
1560 1560
    typedef GraphAdaptorExtender<
1561
      SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 
1561
      SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >,
1562 1562
                   true> > Parent;
1563 1563

	
1564 1564
  public:
1565 1565

	
1566 1566
    typedef GR Graph;
1567 1567
    typedef NF NodeFilterMap;
1568 1568

	
1569 1569
    typedef typename Parent::Node Node;
1570 1570

	
1571 1571
  protected:
1572 1572
    ConstMap<typename GR::Edge, Const<bool, true> > const_true_map;
1573 1573

	
1574 1574
    FilterNodes() : const_true_map() {}
1575 1575

	
1576 1576
  public:
1577 1577

	
1578 1578
    FilterNodes(GR& graph, NodeFilterMap& node_filter) :
1579 1579
      Parent(), const_true_map() {
1580 1580
      Parent::initialize(graph, node_filter, const_true_map);
1581 1581
    }
1582 1582

	
1583 1583
    void status(const Node& n, bool v) const { Parent::status(n, v); }
1584 1584
    bool status(const Node& n) const { return Parent::status(n); }
1585 1585
    void disable(const Node& n) const { Parent::status(n, false); }
... ...
@@ -1621,49 +1621,49 @@
1621 1621
  ///
1622 1622
  /// \tparam DGR The type of the adapted digraph.
1623 1623
  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
1624 1624
  /// It can also be specified to be \c const.
1625 1625
  /// \tparam AF The type of the arc filter map.
1626 1626
  /// It must be a \c bool (or convertible) arc map of the
1627 1627
  /// adapted digraph. The default type is
1628 1628
  /// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>".
1629 1629
  ///
1630 1630
  /// \note The \c Node and \c Arc types of this adaptor and the adapted
1631 1631
  /// digraph are convertible to each other.
1632 1632
#ifdef DOXYGEN
1633 1633
  template<typename DGR,
1634 1634
           typename AF>
1635 1635
  class FilterArcs {
1636 1636
#else
1637 1637
  template<typename DGR,
1638 1638
           typename AF = typename DGR::template ArcMap<bool> >
1639 1639
  class FilterArcs :
1640 1640
    public DigraphAdaptorExtender<
1641 1641
      SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >,
1642 1642
                     AF, false> > {
1643 1643
#endif
1644 1644
    typedef DigraphAdaptorExtender<
1645
      SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, 
1645
      SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >,
1646 1646
                     AF, false> > Parent;
1647 1647

	
1648 1648
  public:
1649 1649

	
1650 1650
    /// The type of the adapted digraph.
1651 1651
    typedef DGR Digraph;
1652 1652
    /// The type of the arc filter map.
1653 1653
    typedef AF ArcFilterMap;
1654 1654

	
1655 1655
    typedef typename Parent::Arc Arc;
1656 1656

	
1657 1657
  protected:
1658 1658
    ConstMap<typename DGR::Node, Const<bool, true> > const_true_map;
1659 1659

	
1660 1660
    FilterArcs() : const_true_map() {}
1661 1661

	
1662 1662
  public:
1663 1663

	
1664 1664
    /// \brief Constructor
1665 1665
    ///
1666 1666
    /// Creates a subdigraph for the given digraph with the given arc
1667 1667
    /// filter map.
1668 1668
    FilterArcs(DGR& digraph, ArcFilterMap& arc_filter)
1669 1669
      : Parent(), const_true_map() {
... ...
@@ -1727,78 +1727,78 @@
1727 1727
  ///
1728 1728
  /// The adapted graph can also be modified through this adaptor
1729 1729
  /// by adding or removing nodes or edges, unless the \c GR template
1730 1730
  /// parameter is set to be \c const.
1731 1731
  ///
1732 1732
  /// \tparam GR The type of the adapted graph.
1733 1733
  /// It must conform to the \ref concepts::Graph "Graph" concept.
1734 1734
  /// It can also be specified to be \c const.
1735 1735
  /// \tparam EF The type of the edge filter map.
1736 1736
  /// It must be a \c bool (or convertible) edge map of the
1737 1737
  /// adapted graph. The default type is
1738 1738
  /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
1739 1739
  ///
1740 1740
  /// \note The \c Node, \c Edge and \c Arc types of this adaptor and the
1741 1741
  /// adapted graph are convertible to each other.
1742 1742
#ifdef DOXYGEN
1743 1743
  template<typename GR,
1744 1744
           typename EF>
1745 1745
  class FilterEdges {
1746 1746
#else
1747 1747
  template<typename GR,
1748 1748
           typename EF = typename GR::template EdgeMap<bool> >
1749 1749
  class FilterEdges :
1750 1750
    public GraphAdaptorExtender<
1751
      SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, 
1751
      SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >,
1752 1752
                   EF, false> > {
1753 1753
#endif
1754 1754
    typedef GraphAdaptorExtender<
1755
      SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, 
1755
      SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >,
1756 1756
                   EF, false> > Parent;
1757 1757

	
1758 1758
  public:
1759 1759

	
1760 1760
    /// The type of the adapted graph.
1761 1761
    typedef GR Graph;
1762 1762
    /// The type of the edge filter map.
1763 1763
    typedef EF EdgeFilterMap;
1764 1764

	
1765 1765
    typedef typename Parent::Edge Edge;
1766 1766

	
1767 1767
  protected:
1768 1768
    ConstMap<typename GR::Node, Const<bool, true> > const_true_map;
1769 1769

	
1770 1770
    FilterEdges() : const_true_map(true) {
1771 1771
      Parent::setNodeFilterMap(const_true_map);
1772 1772
    }
1773 1773

	
1774 1774
  public:
1775 1775

	
1776 1776
    /// \brief Constructor
1777 1777
    ///
1778 1778
    /// Creates a subgraph for the given graph with the given edge
1779 1779
    /// filter map.
1780
    FilterEdges(GR& graph, EF& edge_filter) 
1780
    FilterEdges(GR& graph, EF& edge_filter)
1781 1781
      : Parent(), const_true_map() {
1782 1782
      Parent::initialize(graph, const_true_map, edge_filter);
1783 1783
    }
1784 1784

	
1785 1785
    /// \brief Sets the status of the given edge
1786 1786
    ///
1787 1787
    /// This function sets the status of the given edge.
1788 1788
    /// It is done by simply setting the assigned value of \c e
1789 1789
    /// to \c v in the edge filter map.
1790 1790
    void status(const Edge& e, bool v) const { Parent::status(e, v); }
1791 1791

	
1792 1792
    /// \brief Returns the status of the given edge
1793 1793
    ///
1794 1794
    /// This function returns the status of the given edge.
1795 1795
    /// It is \c true if the given edge is enabled (i.e. not hidden).
1796 1796
    bool status(const Edge& e) const { return Parent::status(e); }
1797 1797

	
1798 1798
    /// \brief Disables the given edge
1799 1799
    ///
1800 1800
    /// This function disables the given edge in the subgraph,
1801 1801
    /// so the iteration jumps over it.
1802 1802
    /// It is the same as \ref status() "status(e, false)".
1803 1803
    void disable(const Edge& e) const { Parent::status(e, false); }
1804 1804

	
... ...
@@ -1824,49 +1824,49 @@
1824 1824
  template<typename GR, typename EF>
1825 1825
  FilterEdges<const GR, const EF>
1826 1826
  filterEdges(const GR& graph, const EF& edge_filter) {
1827 1827
    return FilterEdges<const GR, const EF>(graph, edge_filter);
1828 1828
  }
1829 1829

	
1830 1830

	
1831 1831
  template <typename DGR>
1832 1832
  class UndirectorBase {
1833 1833
  public:
1834 1834
    typedef DGR Digraph;
1835 1835
    typedef UndirectorBase Adaptor;
1836 1836

	
1837 1837
    typedef True UndirectedTag;
1838 1838

	
1839 1839
    typedef typename Digraph::Arc Edge;
1840 1840
    typedef typename Digraph::Node Node;
1841 1841

	
1842 1842
    class Arc {
1843 1843
      friend class UndirectorBase;
1844 1844
    protected:
1845 1845
      Edge _edge;
1846 1846
      bool _forward;
1847 1847

	
1848
      Arc(const Edge& edge, bool forward) 
1848
      Arc(const Edge& edge, bool forward)
1849 1849
        : _edge(edge), _forward(forward) {}
1850 1850

	
1851 1851
    public:
1852 1852
      Arc() {}
1853 1853

	
1854 1854
      Arc(Invalid) : _edge(INVALID), _forward(true) {}
1855 1855

	
1856 1856
      operator const Edge&() const { return _edge; }
1857 1857

	
1858 1858
      bool operator==(const Arc &other) const {
1859 1859
        return _forward == other._forward && _edge == other._edge;
1860 1860
      }
1861 1861
      bool operator!=(const Arc &other) const {
1862 1862
        return _forward != other._forward || _edge != other._edge;
1863 1863
      }
1864 1864
      bool operator<(const Arc &other) const {
1865 1865
        return _forward < other._forward ||
1866 1866
          (_forward == other._forward && _edge < other._edge);
1867 1867
      }
1868 1868
    };
1869 1869

	
1870 1870
    void first(Node& n) const {
1871 1871
      _digraph->first(n);
1872 1872
    }
... ...
@@ -2064,49 +2064,49 @@
2064 2064

	
2065 2065
  private:
2066 2066

	
2067 2067
    template <typename V>
2068 2068
    class ArcMapBase {
2069 2069
    private:
2070 2070

	
2071 2071
      typedef typename DGR::template ArcMap<V> MapImpl;
2072 2072

	
2073 2073
    public:
2074 2074

	
2075 2075
      typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
2076 2076

	
2077 2077
      typedef V Value;
2078 2078
      typedef Arc Key;
2079 2079
      typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReturnValue;
2080 2080
      typedef typename MapTraits<MapImpl>::ReturnValue ReturnValue;
2081 2081
      typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReference;
2082 2082
      typedef typename MapTraits<MapImpl>::ReturnValue Reference;
2083 2083

	
2084 2084
      ArcMapBase(const UndirectorBase<DGR>& adaptor) :
2085 2085
        _forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
2086 2086

	
2087 2087
      ArcMapBase(const UndirectorBase<DGR>& adaptor, const V& value)
2088
        : _forward(*adaptor._digraph, value), 
2088
        : _forward(*adaptor._digraph, value),
2089 2089
          _backward(*adaptor._digraph, value) {}
2090 2090

	
2091 2091
      void set(const Arc& a, const V& value) {
2092 2092
        if (direction(a)) {
2093 2093
          _forward.set(a, value);
2094 2094
        } else {
2095 2095
          _backward.set(a, value);
2096 2096
        }
2097 2097
      }
2098 2098

	
2099 2099
      ConstReturnValue operator[](const Arc& a) const {
2100 2100
        if (direction(a)) {
2101 2101
          return _forward[a];
2102 2102
        } else {
2103 2103
          return _backward[a];
2104 2104
        }
2105 2105
      }
2106 2106

	
2107 2107
      ReturnValue operator[](const Arc& a) {
2108 2108
        if (direction(a)) {
2109 2109
          return _forward[a];
2110 2110
        } else {
2111 2111
          return _backward[a];
2112 2112
        }
... ...
@@ -2182,49 +2182,49 @@
2182 2182
      explicit EdgeMap(const UndirectorBase<DGR>& adaptor)
2183 2183
        : Parent(*adaptor._digraph) {}
2184 2184

	
2185 2185
      EdgeMap(const UndirectorBase<DGR>& adaptor, const V& value)
2186 2186
        : Parent(*adaptor._digraph, value) {}
2187 2187

	
2188 2188
    private:
2189 2189
      EdgeMap& operator=(const EdgeMap& cmap) {
2190 2190
        return operator=<EdgeMap>(cmap);
2191 2191
      }
2192 2192

	
2193 2193
      template <typename CMap>
2194 2194
      EdgeMap& operator=(const CMap& cmap) {
2195 2195
        Parent::operator=(cmap);
2196 2196
        return *this;
2197 2197
      }
2198 2198

	
2199 2199
    };
2200 2200

	
2201 2201
    typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier;
2202 2202
    NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
2203 2203

	
2204 2204
    typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier;
2205 2205
    EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); }
2206
    
2206

	
2207 2207
    typedef EdgeNotifier ArcNotifier;
2208 2208
    ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); }
2209 2209

	
2210 2210
  protected:
2211 2211

	
2212 2212
    UndirectorBase() : _digraph(0) {}
2213 2213

	
2214 2214
    DGR* _digraph;
2215 2215

	
2216 2216
    void initialize(DGR& digraph) {
2217 2217
      _digraph = &digraph;
2218 2218
    }
2219 2219

	
2220 2220
  };
2221 2221

	
2222 2222
  /// \ingroup graph_adaptors
2223 2223
  ///
2224 2224
  /// \brief Adaptor class for viewing a digraph as an undirected graph.
2225 2225
  ///
2226 2226
  /// Undirector adaptor can be used for viewing a digraph as an undirected
2227 2227
  /// graph. All arcs of the underlying digraph are showed in the
2228 2228
  /// adaptor as an edge (and also as a pair of arcs, of course).
2229 2229
  /// This adaptor conforms to the \ref concepts::Graph "Graph" concept.
2230 2230
  ///
... ...
@@ -2686,49 +2686,49 @@
2686 2686
  /// the capacities in the flow problem. It is implicitly \c const.
2687 2687
  /// The default type is
2688 2688
  /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
2689 2689
  /// \tparam FM The type of the flow map.
2690 2690
  /// It must be an arc map of some numerical type, which defines
2691 2691
  /// the flow values in the flow problem. The default type is \c CM.
2692 2692
  /// \tparam TL The tolerance type for handling inexact computation.
2693 2693
  /// The default tolerance type depends on the value type of the
2694 2694
  /// capacity map.
2695 2695
  ///
2696 2696
  /// \note This adaptor is implemented using Undirector and FilterArcs
2697 2697
  /// adaptors.
2698 2698
  ///
2699 2699
  /// \note The \c Node type of this adaptor and the adapted digraph are
2700 2700
  /// convertible to each other, moreover the \c Arc type of the adaptor
2701 2701
  /// is convertible to the \c Arc type of the adapted digraph.
2702 2702
#ifdef DOXYGEN
2703 2703
  template<typename DGR, typename CM, typename FM, typename TL>
2704 2704
  class ResidualDigraph
2705 2705
#else
2706 2706
  template<typename DGR,
2707 2707
           typename CM = typename DGR::template ArcMap<int>,
2708 2708
           typename FM = CM,
2709 2709
           typename TL = Tolerance<typename CM::Value> >
2710
  class ResidualDigraph 
2710
  class ResidualDigraph
2711 2711
    : public SubDigraph<
2712 2712
        Undirector<const DGR>,
2713 2713
        ConstMap<typename DGR::Node, Const<bool, true> >,
2714 2714
        typename Undirector<const DGR>::template CombinedArcMap<
2715 2715
          _adaptor_bits::ResForwardFilter<const DGR, CM, FM, TL>,
2716 2716
          _adaptor_bits::ResBackwardFilter<const DGR, CM, FM, TL> > >
2717 2717
#endif
2718 2718
  {
2719 2719
  public:
2720 2720

	
2721 2721
    /// The type of the underlying digraph.
2722 2722
    typedef DGR Digraph;
2723 2723
    /// The type of the capacity map.
2724 2724
    typedef CM CapacityMap;
2725 2725
    /// The type of the flow map.
2726 2726
    typedef FM FlowMap;
2727 2727
    /// The tolerance type.
2728 2728
    typedef TL Tolerance;
2729 2729

	
2730 2730
    typedef typename CapacityMap::Value Value;
2731 2731
    typedef ResidualDigraph Adaptor;
2732 2732

	
2733 2733
  protected:
2734 2734

	
... ...
@@ -2743,49 +2743,49 @@
2743 2743
                                             FM, TL> BackwardFilter;
2744 2744

	
2745 2745
    typedef typename Undirected::
2746 2746
      template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter;
2747 2747

	
2748 2748
    typedef SubDigraph<Undirected, NodeFilter, ArcFilter> Parent;
2749 2749

	
2750 2750
    const CapacityMap* _capacity;
2751 2751
    FlowMap* _flow;
2752 2752

	
2753 2753
    Undirected _graph;
2754 2754
    NodeFilter _node_filter;
2755 2755
    ForwardFilter _forward_filter;
2756 2756
    BackwardFilter _backward_filter;
2757 2757
    ArcFilter _arc_filter;
2758 2758

	
2759 2759
  public:
2760 2760

	
2761 2761
    /// \brief Constructor
2762 2762
    ///
2763 2763
    /// Constructor of the residual digraph adaptor. The parameters are the
2764 2764
    /// digraph, the capacity map, the flow map, and a tolerance object.
2765 2765
    ResidualDigraph(const DGR& digraph, const CM& capacity,
2766 2766
                    FM& flow, const TL& tolerance = Tolerance())
2767
      : Parent(), _capacity(&capacity), _flow(&flow), 
2767
      : Parent(), _capacity(&capacity), _flow(&flow),
2768 2768
        _graph(digraph), _node_filter(),
2769 2769
        _forward_filter(capacity, flow, tolerance),
2770 2770
        _backward_filter(capacity, flow, tolerance),
2771 2771
        _arc_filter(_forward_filter, _backward_filter)
2772 2772
    {
2773 2773
      Parent::initialize(_graph, _node_filter, _arc_filter);
2774 2774
    }
2775 2775

	
2776 2776
    typedef typename Parent::Arc Arc;
2777 2777

	
2778 2778
    /// \brief Returns the residual capacity of the given arc.
2779 2779
    ///
2780 2780
    /// Returns the residual capacity of the given arc.
2781 2781
    Value residualCapacity(const Arc& a) const {
2782 2782
      if (Undirected::direction(a)) {
2783 2783
        return (*_capacity)[a] - (*_flow)[a];
2784 2784
      } else {
2785 2785
        return (*_flow)[a];
2786 2786
      }
2787 2787
    }
2788 2788

	
2789 2789
    /// \brief Augments on the given arc in the residual digraph.
2790 2790
    ///
2791 2791
    /// Augments on the given arc in the residual digraph. It increases
... ...
@@ -2825,49 +2825,49 @@
2825 2825

	
2826 2826
    /// \brief Returns the backward oriented residual arc.
2827 2827
    ///
2828 2828
    /// Returns the backward oriented residual arc related to the given
2829 2829
    /// arc of the underlying digraph.
2830 2830
    static Arc backward(const typename Digraph::Arc& a) {
2831 2831
      return Undirected::direct(a, false);
2832 2832
    }
2833 2833

	
2834 2834
    /// \brief Residual capacity map.
2835 2835
    ///
2836 2836
    /// This map adaptor class can be used for obtaining the residual
2837 2837
    /// capacities as an arc map of the residual digraph.
2838 2838
    /// Its value type is inherited from the capacity map.
2839 2839
    class ResidualCapacity {
2840 2840
    protected:
2841 2841
      const Adaptor* _adaptor;
2842 2842
    public:
2843 2843
      /// The key type of the map
2844 2844
      typedef Arc Key;
2845 2845
      /// The value type of the map
2846 2846
      typedef typename CapacityMap::Value Value;
2847 2847

	
2848 2848
      /// Constructor
2849
      ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor) 
2849
      ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor)
2850 2850
        : _adaptor(&adaptor) {}
2851 2851

	
2852 2852
      /// Returns the value associated with the given residual arc
2853 2853
      Value operator[](const Arc& a) const {
2854 2854
        return _adaptor->residualCapacity(a);
2855 2855
      }
2856 2856

	
2857 2857
    };
2858 2858

	
2859 2859
    /// \brief Returns a residual capacity map
2860 2860
    ///
2861 2861
    /// This function just returns a residual capacity map.
2862 2862
    ResidualCapacity residualCapacity() const {
2863 2863
      return ResidualCapacity(*this);
2864 2864
    }
2865 2865

	
2866 2866
  };
2867 2867

	
2868 2868
  /// \brief Returns a (read-only) Residual adaptor
2869 2869
  ///
2870 2870
  /// This function just returns a (read-only) \ref ResidualDigraph adaptor.
2871 2871
  /// \ingroup graph_adaptors
2872 2872
  /// \relates ResidualDigraph
2873 2873
    template<typename DGR, typename CM, typename FM>
... ...
@@ -3402,49 +3402,49 @@
3402 3402

	
3403 3403
    /// \brief Returns the bind arc that corresponds to the given
3404 3404
    /// original node.
3405 3405
    ///
3406 3406
    /// Returns the bind arc in the adaptor that corresponds to the given
3407 3407
    /// original node, i.e. the arc connecting the in-node and out-node
3408 3408
    /// of \c n.
3409 3409
    static Arc arc(const DigraphNode& n) {
3410 3410
      return Parent::arc(n);
3411 3411
    }
3412 3412

	
3413 3413
    /// \brief Returns the arc that corresponds to the given original arc.
3414 3414
    ///
3415 3415
    /// Returns the arc in the adaptor that corresponds to the given
3416 3416
    /// original arc.
3417 3417
    static Arc arc(const DigraphArc& a) {
3418 3418
      return Parent::arc(a);
3419 3419
    }
3420 3420

	
3421 3421
    /// \brief Node map combined from two original node maps
3422 3422
    ///
3423 3423
    /// This map adaptor class adapts two node maps of the original digraph
3424 3424
    /// to get a node map of the split digraph.
3425 3425
    /// Its value type is inherited from the first node map type (\c IN).
3426
    /// \tparam IN The type of the node map for the in-nodes. 
3426
    /// \tparam IN The type of the node map for the in-nodes.
3427 3427
    /// \tparam OUT The type of the node map for the out-nodes.
3428 3428
    template <typename IN, typename OUT>
3429 3429
    class CombinedNodeMap {
3430 3430
    public:
3431 3431

	
3432 3432
      /// The key type of the map
3433 3433
      typedef Node Key;
3434 3434
      /// The value type of the map
3435 3435
      typedef typename IN::Value Value;
3436 3436

	
3437 3437
      typedef typename MapTraits<IN>::ReferenceMapTag ReferenceMapTag;
3438 3438
      typedef typename MapTraits<IN>::ReturnValue ReturnValue;
3439 3439
      typedef typename MapTraits<IN>::ConstReturnValue ConstReturnValue;
3440 3440
      typedef typename MapTraits<IN>::ReturnValue Reference;
3441 3441
      typedef typename MapTraits<IN>::ConstReturnValue ConstReference;
3442 3442

	
3443 3443
      /// Constructor
3444 3444
      CombinedNodeMap(IN& in_map, OUT& out_map)
3445 3445
        : _in_map(in_map), _out_map(out_map) {}
3446 3446

	
3447 3447
      /// Returns the value associated with the given key.
3448 3448
      Value operator[](const Key& key) const {
3449 3449
        if (SplitNodesBase<const DGR>::inNode(key)) {
3450 3450
          return _in_map[key];
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_BIN_HEAP_H
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

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_BITS_ARRAY_MAP_H
20 20
#define LEMON_BITS_ARRAY_MAP_H
21 21

	
22 22
#include <memory>
23 23

	
24 24
#include <lemon/bits/traits.h>
25 25
#include <lemon/bits/alteration_notifier.h>
26 26
#include <lemon/concept_check.h>
27 27
#include <lemon/concepts/maps.h>
28 28

	
29 29
// \ingroup graphbits
... ...
@@ -49,49 +49,49 @@
49 49
    // The graph type.
50 50
    typedef _Graph GraphType;
51 51
    // The item type.
52 52
    typedef _Item Item;
53 53
    // The reference map tag.
54 54
    typedef True ReferenceMapTag;
55 55

	
56 56
    // The key type of the map.
57 57
    typedef _Item Key;
58 58
    // The value type of the map.
59 59
    typedef _Value Value;
60 60

	
61 61
    // The const reference type of the map.
62 62
    typedef const _Value& ConstReference;
63 63
    // The reference type of the map.
64 64
    typedef _Value& Reference;
65 65

	
66 66
    // The map type.
67 67
    typedef ArrayMap Map;
68 68

	
69 69
    // The notifier type.
70 70
    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier;
71 71

	
72 72
  private:
73
  
73

	
74 74
    // The MapBase of the Map which imlements the core regisitry function.
75 75
    typedef typename Notifier::ObserverBase Parent;
76 76

	
77 77
    typedef std::allocator<Value> Allocator;
78 78

	
79 79
  public:
80 80

	
81 81
    // \brief Graph initialized map constructor.
82 82
    //
83 83
    // Graph initialized map constructor.
84 84
    explicit ArrayMap(const GraphType& graph) {
85 85
      Parent::attach(graph.notifier(Item()));
86 86
      allocate_memory();
87 87
      Notifier* nf = Parent::notifier();
88 88
      Item it;
89 89
      for (nf->first(it); it != INVALID; nf->next(it)) {
90 90
        int id = nf->id(it);;
91 91
        allocator.construct(&(values[id]), Value());
92 92
      }
93 93
    }
94 94

	
95 95
    // \brief Constructor to use default value to initialize the map.
96 96
    //
97 97
    // It constructs a map and initialize all of the the map.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_BITS_DEFAULT_MAP_H
20 20
#define LEMON_BITS_DEFAULT_MAP_H
21 21

	
22 22
#include <lemon/config.h>
23 23
#include <lemon/bits/array_map.h>
24 24
#include <lemon/bits/vector_map.h>
25 25
//#include <lemon/bits/debug_map.h>
26 26

	
27 27
//\ingroup graphbits
28 28
//\file
29 29
//\brief Graph maps that construct and destruct their elements dynamically.
... ...
@@ -136,47 +136,47 @@
136 136

	
137 137
  // pointer
138 138
  template <typename _Graph, typename _Item, typename _Ptr>
139 139
  struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
140 140
    typedef VectorMap<_Graph, _Item, _Ptr*> Map;
141 141
  };
142 142

	
143 143
// #else
144 144

	
145 145
//   template <typename _Graph, typename _Item, typename _Value>
146 146
//   struct DefaultMapSelector {
147 147
//     typedef DebugMap<_Graph, _Item, _Value> Map;
148 148
//   };
149 149

	
150 150
// #endif
151 151

	
152 152
  // DefaultMap class
153 153
  template <typename _Graph, typename _Item, typename _Value>
154 154
  class DefaultMap
155 155
    : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
156 156
    typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
157 157

	
158 158
  public:
159 159
    typedef DefaultMap<_Graph, _Item, _Value> Map;
160
    
160

	
161 161
    typedef typename Parent::GraphType GraphType;
162 162
    typedef typename Parent::Value Value;
163 163

	
164 164
    explicit DefaultMap(const GraphType& graph) : Parent(graph) {}
165 165
    DefaultMap(const GraphType& graph, const Value& value)
166 166
      : Parent(graph, value) {}
167 167

	
168 168
    DefaultMap& operator=(const DefaultMap& cmap) {
169 169
      return operator=<DefaultMap>(cmap);
170 170
    }
171 171

	
172 172
    template <typename CMap>
173 173
    DefaultMap& operator=(const CMap& cmap) {
174 174
      Parent::operator=(cmap);
175 175
      return *this;
176 176
    }
177 177

	
178 178
  };
179 179

	
180 180
}
181 181

	
182 182
#endif
Ignore white space 6 line context
1
/* -*- C++ -*-
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library
3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#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 27
//\ingroup digraphbits
28 28
//\file
29 29
//\brief Extenders for the arc set types
... ...
@@ -42,233 +42,233 @@
42 42

	
43 43
    // Base extensions
44 44

	
45 45
    typedef typename Parent::Node Node;
46 46
    typedef typename Parent::Arc Arc;
47 47

	
48 48
    int maxId(Node) const {
49 49
      return Parent::maxNodeId();
50 50
    }
51 51

	
52 52
    int maxId(Arc) const {
53 53
      return Parent::maxArcId();
54 54
    }
55 55

	
56 56
    Node fromId(int id, Node) const {
57 57
      return Parent::nodeFromId(id);
58 58
    }
59 59

	
60 60
    Arc fromId(int id, Arc) const {
61 61
      return Parent::arcFromId(id);
62 62
    }
63 63

	
64 64
    Node oppositeNode(const Node &n, const Arc &e) const {
65 65
      if (n == Parent::source(e))
66
	return Parent::target(e);
66
        return Parent::target(e);
67 67
      else if(n==Parent::target(e))
68
	return Parent::source(e);
68
        return Parent::source(e);
69 69
      else
70
	return INVALID;
70
        return INVALID;
71 71
    }
72 72

	
73 73

	
74 74
    // Alteration notifier extensions
75 75

	
76 76
    // The arc observer registry.
77 77
    typedef AlterationNotifier<ArcSetExtender, Arc> ArcNotifier;
78 78

	
79 79
  protected:
80 80

	
81 81
    mutable ArcNotifier arc_notifier;
82 82

	
83 83
  public:
84 84

	
85 85
    using Parent::notifier;
86 86

	
87 87
    // Gives back the arc alteration notifier.
88 88
    ArcNotifier& notifier(Arc) const {
89 89
      return arc_notifier;
90 90
    }
91 91

	
92 92
    // Iterable extensions
93 93

	
94
    class NodeIt : public Node { 
94
    class NodeIt : public Node {
95 95
      const Digraph* digraph;
96 96
    public:
97 97

	
98 98
      NodeIt() {}
99 99

	
100 100
      NodeIt(Invalid i) : Node(i) { }
101 101

	
102 102
      explicit NodeIt(const Digraph& _graph) : digraph(&_graph) {
103
	_graph.first(static_cast<Node&>(*this));
103
        _graph.first(static_cast<Node&>(*this));
104 104
      }
105 105

	
106
      NodeIt(const Digraph& _graph, const Node& node) 
107
	: Node(node), digraph(&_graph) {}
106
      NodeIt(const Digraph& _graph, const Node& node)
107
        : Node(node), digraph(&_graph) {}
108 108

	
109
      NodeIt& operator++() { 
110
	digraph->next(*this);
111
	return *this; 
109
      NodeIt& operator++() {
110
        digraph->next(*this);
111
        return *this;
112 112
      }
113 113

	
114 114
    };
115 115

	
116 116

	
117
    class ArcIt : public Arc { 
117
    class ArcIt : public Arc {
118 118
      const Digraph* digraph;
119 119
    public:
120 120

	
121 121
      ArcIt() { }
122 122

	
123 123
      ArcIt(Invalid i) : Arc(i) { }
124 124

	
125 125
      explicit ArcIt(const Digraph& _graph) : digraph(&_graph) {
126
	_graph.first(static_cast<Arc&>(*this));
126
        _graph.first(static_cast<Arc&>(*this));
127 127
      }
128 128

	
129
      ArcIt(const Digraph& _graph, const Arc& e) : 
130
	Arc(e), digraph(&_graph) { }
129
      ArcIt(const Digraph& _graph, const Arc& e) :
130
        Arc(e), digraph(&_graph) { }
131 131

	
132
      ArcIt& operator++() { 
133
	digraph->next(*this);
134
	return *this; 
132
      ArcIt& operator++() {
133
        digraph->next(*this);
134
        return *this;
135 135
      }
136 136

	
137 137
    };
138 138

	
139 139

	
140
    class OutArcIt : public Arc { 
140
    class OutArcIt : public Arc {
141 141
      const Digraph* digraph;
142 142
    public:
143 143

	
144 144
      OutArcIt() { }
145 145

	
146 146
      OutArcIt(Invalid i) : Arc(i) { }
147 147

	
148
      OutArcIt(const Digraph& _graph, const Node& node) 
149
	: digraph(&_graph) {
150
	_graph.firstOut(*this, node);
148
      OutArcIt(const Digraph& _graph, const Node& node)
149
        : digraph(&_graph) {
150
        _graph.firstOut(*this, node);
151 151
      }
152 152

	
153
      OutArcIt(const Digraph& _graph, const Arc& arc) 
154
	: Arc(arc), digraph(&_graph) {}
153
      OutArcIt(const Digraph& _graph, const Arc& arc)
154
        : Arc(arc), digraph(&_graph) {}
155 155

	
156
      OutArcIt& operator++() { 
157
	digraph->nextOut(*this);
158
	return *this; 
156
      OutArcIt& operator++() {
157
        digraph->nextOut(*this);
158
        return *this;
159 159
      }
160 160

	
161 161
    };
162 162

	
163 163

	
164
    class InArcIt : public Arc { 
164
    class InArcIt : public Arc {
165 165
      const Digraph* digraph;
166 166
    public:
167 167

	
168 168
      InArcIt() { }
169 169

	
170 170
      InArcIt(Invalid i) : Arc(i) { }
171 171

	
172
      InArcIt(const Digraph& _graph, const Node& node) 
173
	: digraph(&_graph) {
174
	_graph.firstIn(*this, node);
172
      InArcIt(const Digraph& _graph, const Node& node)
173
        : digraph(&_graph) {
174
        _graph.firstIn(*this, node);
175 175
      }
176 176

	
177
      InArcIt(const Digraph& _graph, const Arc& arc) : 
178
	Arc(arc), digraph(&_graph) {}
177
      InArcIt(const Digraph& _graph, const Arc& arc) :
178
        Arc(arc), digraph(&_graph) {}
179 179

	
180
      InArcIt& operator++() { 
181
	digraph->nextIn(*this);
182
	return *this; 
180
      InArcIt& operator++() {
181
        digraph->nextIn(*this);
182
        return *this;
183 183
      }
184 184

	
185 185
    };
186 186

	
187 187
    // \brief Base node of the iterator
188 188
    //
189 189
    // Returns the base node (ie. the source in this case) of the iterator
190 190
    Node baseNode(const OutArcIt &e) const {
191 191
      return Parent::source(static_cast<const Arc&>(e));
192 192
    }
193 193
    // \brief Running node of the iterator
194 194
    //
195 195
    // Returns the running node (ie. the target in this case) of the
196 196
    // iterator
197 197
    Node runningNode(const OutArcIt &e) const {
198 198
      return Parent::target(static_cast<const Arc&>(e));
199 199
    }
200 200

	
201 201
    // \brief Base node of the iterator
202 202
    //
203 203
    // Returns the base node (ie. the target in this case) of the iterator
204 204
    Node baseNode(const InArcIt &e) const {
205 205
      return Parent::target(static_cast<const Arc&>(e));
206 206
    }
207 207
    // \brief Running node of the iterator
208 208
    //
209 209
    // Returns the running node (ie. the source in this case) of the
210 210
    // iterator
211 211
    Node runningNode(const InArcIt &e) const {
212 212
      return Parent::source(static_cast<const Arc&>(e));
213 213
    }
214 214

	
215 215
    using Parent::first;
216 216

	
217 217
    // Mappable extension
218
    
218

	
219 219
    template <typename _Value>
220
    class ArcMap 
220
    class ArcMap
221 221
      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
222 222
      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
223 223

	
224 224
    public:
225
      explicit ArcMap(const Digraph& _g) 
226
	: Parent(_g) {}
227
      ArcMap(const Digraph& _g, const _Value& _v) 
228
	: Parent(_g, _v) {}
225
      explicit ArcMap(const Digraph& _g)
226
        : Parent(_g) {}
227
      ArcMap(const Digraph& _g, const _Value& _v)
228
        : Parent(_g, _v) {}
229 229

	
230 230
      ArcMap& operator=(const ArcMap& cmap) {
231
	return operator=<ArcMap>(cmap);
231
        return operator=<ArcMap>(cmap);
232 232
      }
233 233

	
234 234
      template <typename CMap>
235 235
      ArcMap& operator=(const CMap& cmap) {
236 236
        Parent::operator=(cmap);
237
	return *this;
237
        return *this;
238 238
      }
239 239

	
240 240
    };
241 241

	
242 242

	
243 243
    // Alteration extension
244 244

	
245 245
    Arc addArc(const Node& from, const Node& to) {
246 246
      Arc arc = Parent::addArc(from, to);
247 247
      notifier(Arc()).add(arc);
248 248
      return arc;
249 249
    }
250
    
250

	
251 251
    void clear() {
252 252
      notifier(Arc()).clear();
253 253
      Parent::clear();
254 254
    }
255 255

	
256 256
    void erase(const Arc& arc) {
257 257
      notifier(Arc()).erase(arc);
258 258
      Parent::erase(arc);
259 259
    }
260 260

	
261 261
    ArcSetExtender() {
262 262
      arc_notifier.setContainer(*this);
263 263
    }
264 264

	
265 265
    ~ArcSetExtender() {
266 266
      arc_notifier.clear();
267 267
    }
268 268

	
269 269
  };
270 270

	
271 271

	
272 272
  // \ingroup digraphbits
273 273
  //
274 274
  // \brief Extender for the EdgeSets
... ...
@@ -291,337 +291,337 @@
291 291
    }
292 292

	
293 293
    int maxId(Arc) const {
294 294
      return Parent::maxArcId();
295 295
    }
296 296

	
297 297
    int maxId(Edge) const {
298 298
      return Parent::maxEdgeId();
299 299
    }
300 300

	
301 301
    Node fromId(int id, Node) const {
302 302
      return Parent::nodeFromId(id);
303 303
    }
304 304

	
305 305
    Arc fromId(int id, Arc) const {
306 306
      return Parent::arcFromId(id);
307 307
    }
308 308

	
309 309
    Edge fromId(int id, Edge) const {
310 310
      return Parent::edgeFromId(id);
311 311
    }
312 312

	
313 313
    Node oppositeNode(const Node &n, const Edge &e) const {
314 314
      if( n == Parent::u(e))
315
	return Parent::v(e);
315
        return Parent::v(e);
316 316
      else if( n == Parent::v(e))
317
	return Parent::u(e);
317
        return Parent::u(e);
318 318
      else
319
	return INVALID;
319
        return INVALID;
320 320
    }
321 321

	
322 322
    Arc oppositeArc(const Arc &e) const {
323 323
      return Parent::direct(e, !Parent::direction(e));
324 324
    }
325 325

	
326 326
    using Parent::direct;
327 327
    Arc direct(const Edge &e, const Node &s) const {
328 328
      return Parent::direct(e, Parent::u(e) == s);
329 329
    }
330 330

	
331 331
    typedef AlterationNotifier<EdgeSetExtender, Arc> ArcNotifier;
332 332
    typedef AlterationNotifier<EdgeSetExtender, Edge> EdgeNotifier;
333 333

	
334 334

	
335 335
  protected:
336 336

	
337 337
    mutable ArcNotifier arc_notifier;
338 338
    mutable EdgeNotifier edge_notifier;
339 339

	
340 340
  public:
341 341

	
342 342
    using Parent::notifier;
343
    
343

	
344 344
    ArcNotifier& notifier(Arc) const {
345 345
      return arc_notifier;
346 346
    }
347 347

	
348 348
    EdgeNotifier& notifier(Edge) const {
349 349
      return edge_notifier;
350 350
    }
351 351

	
352 352

	
353
    class NodeIt : public Node { 
353
    class NodeIt : public Node {
354 354
      const Graph* graph;
355 355
    public:
356 356

	
357 357
      NodeIt() {}
358 358

	
359 359
      NodeIt(Invalid i) : Node(i) { }
360 360

	
361 361
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
362
	_graph.first(static_cast<Node&>(*this));
362
        _graph.first(static_cast<Node&>(*this));
363 363
      }
364 364

	
365
      NodeIt(const Graph& _graph, const Node& node) 
366
	: Node(node), graph(&_graph) {}
365
      NodeIt(const Graph& _graph, const Node& node)
366
        : Node(node), graph(&_graph) {}
367 367

	
368
      NodeIt& operator++() { 
369
	graph->next(*this);
370
	return *this; 
368
      NodeIt& operator++() {
369
        graph->next(*this);
370
        return *this;
371 371
      }
372 372

	
373 373
    };
374 374

	
375 375

	
376
    class ArcIt : public Arc { 
376
    class ArcIt : public Arc {
377 377
      const Graph* graph;
378 378
    public:
379 379

	
380 380
      ArcIt() { }
381 381

	
382 382
      ArcIt(Invalid i) : Arc(i) { }
383 383

	
384 384
      explicit ArcIt(const Graph& _graph) : graph(&_graph) {
385
	_graph.first(static_cast<Arc&>(*this));
385
        _graph.first(static_cast<Arc&>(*this));
386 386
      }
387 387

	
388
      ArcIt(const Graph& _graph, const Arc& e) : 
389
	Arc(e), graph(&_graph) { }
388
      ArcIt(const Graph& _graph, const Arc& e) :
389
        Arc(e), graph(&_graph) { }
390 390

	
391
      ArcIt& operator++() { 
392
	graph->next(*this);
393
	return *this; 
391
      ArcIt& operator++() {
392
        graph->next(*this);
393
        return *this;
394 394
      }
395 395

	
396 396
    };
397 397

	
398 398

	
399
    class OutArcIt : public Arc { 
399
    class OutArcIt : public Arc {
400 400
      const Graph* graph;
401 401
    public:
402 402

	
403 403
      OutArcIt() { }
404 404

	
405 405
      OutArcIt(Invalid i) : Arc(i) { }
406 406

	
407
      OutArcIt(const Graph& _graph, const Node& node) 
408
	: graph(&_graph) {
409
	_graph.firstOut(*this, node);
407
      OutArcIt(const Graph& _graph, const Node& node)
408
        : graph(&_graph) {
409
        _graph.firstOut(*this, node);
410 410
      }
411 411

	
412
      OutArcIt(const Graph& _graph, const Arc& arc) 
413
	: Arc(arc), graph(&_graph) {}
412
      OutArcIt(const Graph& _graph, const Arc& arc)
413
        : Arc(arc), graph(&_graph) {}
414 414

	
415
      OutArcIt& operator++() { 
416
	graph->nextOut(*this);
417
	return *this; 
415
      OutArcIt& operator++() {
416
        graph->nextOut(*this);
417
        return *this;
418 418
      }
419 419

	
420 420
    };
421 421

	
422 422

	
423
    class InArcIt : public Arc { 
423
    class InArcIt : public Arc {
424 424
      const Graph* graph;
425 425
    public:
426 426

	
427 427
      InArcIt() { }
428 428

	
429 429
      InArcIt(Invalid i) : Arc(i) { }
430 430

	
431
      InArcIt(const Graph& _graph, const Node& node) 
432
	: graph(&_graph) {
433
	_graph.firstIn(*this, node);
431
      InArcIt(const Graph& _graph, const Node& node)
432
        : graph(&_graph) {
433
        _graph.firstIn(*this, node);
434 434
      }
435 435

	
436
      InArcIt(const Graph& _graph, const Arc& arc) : 
437
	Arc(arc), graph(&_graph) {}
436
      InArcIt(const Graph& _graph, const Arc& arc) :
437
        Arc(arc), graph(&_graph) {}
438 438

	
439
      InArcIt& operator++() { 
440
	graph->nextIn(*this);
441
	return *this; 
439
      InArcIt& operator++() {
440
        graph->nextIn(*this);
441
        return *this;
442 442
      }
443 443

	
444 444
    };
445 445

	
446 446

	
447
    class EdgeIt : public Parent::Edge { 
447
    class EdgeIt : public Parent::Edge {
448 448
      const Graph* graph;
449 449
    public:
450 450

	
451 451
      EdgeIt() { }
452 452

	
453 453
      EdgeIt(Invalid i) : Edge(i) { }
454 454

	
455 455
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
456
	_graph.first(static_cast<Edge&>(*this));
456
        _graph.first(static_cast<Edge&>(*this));
457 457
      }
458 458

	
459
      EdgeIt(const Graph& _graph, const Edge& e) : 
460
	Edge(e), graph(&_graph) { }
459
      EdgeIt(const Graph& _graph, const Edge& e) :
460
        Edge(e), graph(&_graph) { }
461 461

	
462
      EdgeIt& operator++() { 
463
	graph->next(*this);
464
	return *this; 
462
      EdgeIt& operator++() {
463
        graph->next(*this);
464
        return *this;
465 465
      }
466 466

	
467 467
    };
468 468

	
469 469
    class IncEdgeIt : public Parent::Edge {
470 470
      friend class EdgeSetExtender;
471 471
      const Graph* graph;
472 472
      bool direction;
473 473
    public:
474 474

	
475 475
      IncEdgeIt() { }
476 476

	
477 477
      IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
478 478

	
479 479
      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
480
	_graph.firstInc(*this, direction, n);
480
        _graph.firstInc(*this, direction, n);
481 481
      }
482 482

	
483 483
      IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n)
484
	: graph(&_graph), Edge(ue) {
485
	direction = (_graph.source(ue) == n);
484
        : graph(&_graph), Edge(ue) {
485
        direction = (_graph.source(ue) == n);
486 486
      }
487 487

	
488 488
      IncEdgeIt& operator++() {
489
	graph->nextInc(*this, direction);
490
	return *this; 
489
        graph->nextInc(*this, direction);
490
        return *this;
491 491
      }
492 492
    };
493 493

	
494 494
    // \brief Base node of the iterator
495 495
    //
496 496
    // Returns the base node (ie. the source in this case) of the iterator
497 497
    Node baseNode(const OutArcIt &e) const {
498 498
      return Parent::source(static_cast<const Arc&>(e));
499 499
    }
500 500
    // \brief Running node of the iterator
501 501
    //
502 502
    // Returns the running node (ie. the target in this case) of the
503 503
    // iterator
504 504
    Node runningNode(const OutArcIt &e) const {
505 505
      return Parent::target(static_cast<const Arc&>(e));
506 506
    }
507 507

	
508 508
    // \brief Base node of the iterator
509 509
    //
510 510
    // Returns the base node (ie. the target in this case) of the iterator
511 511
    Node baseNode(const InArcIt &e) const {
512 512
      return Parent::target(static_cast<const Arc&>(e));
513 513
    }
514 514
    // \brief Running node of the iterator
515 515
    //
516 516
    // Returns the running node (ie. the source in this case) of the
517 517
    // iterator
518 518
    Node runningNode(const InArcIt &e) const {
519 519
      return Parent::source(static_cast<const Arc&>(e));
520 520
    }
521 521

	
522 522
    // Base node of the iterator
523 523
    //
524 524
    // Returns the base node of the iterator
525 525
    Node baseNode(const IncEdgeIt &e) const {
526 526
      return e.direction ? u(e) : v(e);
527 527
    }
528 528
    // Running node of the iterator
529 529
    //
530 530
    // Returns the running node of the iterator
531 531
    Node runningNode(const IncEdgeIt &e) const {
532 532
      return e.direction ? v(e) : u(e);
533 533
    }
534 534

	
535 535

	
536 536
    template <typename _Value>
537
    class ArcMap 
537
    class ArcMap
538 538
      : public MapExtender<DefaultMap<Graph, Arc, _Value> > {
539 539
      typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
540 540

	
541 541
    public:
542
      explicit ArcMap(const Graph& _g) 
543
	: Parent(_g) {}
544
      ArcMap(const Graph& _g, const _Value& _v) 
545
	: Parent(_g, _v) {}
542
      explicit ArcMap(const Graph& _g)
543
        : Parent(_g) {}
544
      ArcMap(const Graph& _g, const _Value& _v)
545
        : Parent(_g, _v) {}
546 546

	
547 547
      ArcMap& operator=(const ArcMap& cmap) {
548
	return operator=<ArcMap>(cmap);
548
        return operator=<ArcMap>(cmap);
549 549
      }
550 550

	
551 551
      template <typename CMap>
552 552
      ArcMap& operator=(const CMap& cmap) {
553 553
        Parent::operator=(cmap);
554
	return *this;
554
        return *this;
555 555
      }
556 556

	
557 557
    };
558 558

	
559 559

	
560 560
    template <typename _Value>
561
    class EdgeMap 
561
    class EdgeMap
562 562
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
563 563
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
564 564

	
565 565
    public:
566
      explicit EdgeMap(const Graph& _g) 
567
	: Parent(_g) {}
566
      explicit EdgeMap(const Graph& _g)
567
        : Parent(_g) {}
568 568

	
569
      EdgeMap(const Graph& _g, const _Value& _v) 
570
	: Parent(_g, _v) {}
569
      EdgeMap(const Graph& _g, const _Value& _v)
570
        : Parent(_g, _v) {}
571 571

	
572 572
      EdgeMap& operator=(const EdgeMap& cmap) {
573
	return operator=<EdgeMap>(cmap);
573
        return operator=<EdgeMap>(cmap);
574 574
      }
575 575

	
576 576
      template <typename CMap>
577 577
      EdgeMap& operator=(const CMap& cmap) {
578 578
        Parent::operator=(cmap);
579
	return *this;
579
        return *this;
580 580
      }
581 581

	
582 582
    };
583 583

	
584 584

	
585 585
    // Alteration extension
586 586

	
587 587
    Edge addEdge(const Node& from, const Node& to) {
588 588
      Edge edge = Parent::addEdge(from, to);
589 589
      notifier(Edge()).add(edge);
590 590
      std::vector<Arc> arcs;
591 591
      arcs.push_back(Parent::direct(edge, true));
592 592
      arcs.push_back(Parent::direct(edge, false));
593 593
      notifier(Arc()).add(arcs);
594 594
      return edge;
595 595
    }
596
    
596

	
597 597
    void clear() {
598 598
      notifier(Arc()).clear();
599 599
      notifier(Edge()).clear();
600 600
      Parent::clear();
601 601
    }
602 602

	
603 603
    void erase(const Edge& edge) {
604 604
      std::vector<Arc> arcs;
605 605
      arcs.push_back(Parent::direct(edge, true));
606 606
      arcs.push_back(Parent::direct(edge, false));
607 607
      notifier(Arc()).erase(arcs);
608 608
      notifier(Edge()).erase(edge);
609 609
      Parent::erase(edge);
610 610
    }
611 611

	
612 612

	
613 613
    EdgeSetExtender() {
614 614
      arc_notifier.setContainer(*this);
615 615
      edge_notifier.setContainer(*this);
616 616
    }
617 617

	
618 618
    ~EdgeSetExtender() {
619 619
      edge_notifier.clear();
620 620
      arc_notifier.clear();
621 621
    }
622
    
622

	
623 623
  };
624 624

	
625 625
}
626 626

	
627 627
#endif
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H
20 20
#define LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H
21 21

	
22 22
#include <lemon/core.h>
23 23
#include <lemon/error.h>
24 24

	
25 25
namespace lemon {
26 26

	
27 27
  template <typename _Digraph>
28 28
  class DigraphAdaptorExtender : public _Digraph {
29 29
    typedef _Digraph Parent;
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_BITS_MAP_EXTENDER_H
20 20
#define LEMON_BITS_MAP_EXTENDER_H
21 21

	
22 22
#include <iterator>
23 23

	
24 24
#include <lemon/bits/traits.h>
25 25

	
26 26
#include <lemon/concept_check.h>
27 27
#include <lemon/concepts/maps.h>
28 28

	
29 29
//\file
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_BITS_PATH_DUMP_H
20 20
#define LEMON_BITS_PATH_DUMP_H
21 21

	
22 22
#include <lemon/core.h>
23 23
#include <lemon/concept_check.h>
24 24

	
25 25
namespace lemon {
26 26

	
27 27
  template <typename _Digraph, typename _PredMap>
28 28
  class PredMapPath {
29 29
  public:
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_BITS_SOLVER_BITS_H
20 20
#define LEMON_BITS_SOLVER_BITS_H
21 21

	
22 22
#include <vector>
23 23

	
24 24
namespace lemon {
25 25

	
26 26
  namespace _solver_bits {
27 27

	
28 28
    class VarIndex {
29 29
    private:
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
///\file
20 20
///\brief Some basic non-inline functions and static global data.
21 21

	
22 22
#include<lemon/bits/windows.h>
23 23

	
24 24
#ifdef WIN32
25 25
#ifndef WIN32_LEAN_AND_MEAN
26 26
#define WIN32_LEAN_AND_MEAN
27 27
#endif
28 28
#ifndef NOMINMAX
29 29
#define NOMINMAX
... ...
@@ -77,49 +77,49 @@
77 77
        cstime = 0;
78 78
      }
79 79
#else
80 80
      timeval tv;
81 81
      gettimeofday(&tv, 0);
82 82
      rtime=tv.tv_sec+double(tv.tv_usec)/1e6;
83 83

	
84 84
      tms ts;
85 85
      double tck=sysconf(_SC_CLK_TCK);
86 86
      times(&ts);
87 87
      utime=ts.tms_utime/tck;
88 88
      stime=ts.tms_stime/tck;
89 89
      cutime=ts.tms_cutime/tck;
90 90
      cstime=ts.tms_cstime/tck;
91 91
#endif
92 92
    }
93 93

	
94 94
    std::string getWinFormattedDate()
95 95
    {
96 96
      std::ostringstream os;
97 97
#ifdef WIN32
98 98
      SYSTEMTIME time;
99 99
      GetSystemTime(&time);
100 100
      char buf1[11], buf2[9], buf3[5];
101
	  if (GetDateFormat(MY_LOCALE, 0, &time,
101
          if (GetDateFormat(MY_LOCALE, 0, &time,
102 102
                        ("ddd MMM dd"), buf1, 11) &&
103 103
          GetTimeFormat(MY_LOCALE, 0, &time,
104 104
                        ("HH':'mm':'ss"), buf2, 9) &&
105 105
          GetDateFormat(MY_LOCALE, 0, &time,
106 106
                        ("yyyy"), buf3, 5)) {
107 107
        os << buf1 << ' ' << buf2 << ' ' << buf3;
108 108
      }
109 109
      else os << "unknown";
110 110
#else
111 111
      timeval tv;
112 112
      gettimeofday(&tv, 0);
113 113

	
114 114
      char cbuf[26];
115 115
      ctime_r(&tv.tv_sec,cbuf);
116 116
      os << cbuf;
117 117
#endif
118 118
      return os.str();
119 119
    }
120 120

	
121 121
    int getWinRndSeed()
122 122
    {
123 123
#ifdef WIN32
124 124
      FILETIME time;
125 125
      GetSystemTimeAsFileTime(&time);
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
// -*- C++ -*-
20 20
#ifndef LEMON_CBC_H
21 21
#define LEMON_CBC_H
22 22

	
23 23
///\file
24 24
///\brief Header of the LEMON-CBC mip solver interface.
25 25
///\ingroup lp_group
26 26

	
27 27
#include <lemon/lp_base.h>
28 28

	
29 29
class CoinModel;
... ...
@@ -99,31 +99,31 @@
99 99
    virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
100 100
    virtual void _getObjCoeffs(InsertIterator b) const;
101 101

	
102 102
    virtual void _setObjCoeff(int i, Value obj_coef);
103 103
    virtual Value _getObjCoeff(int i) const;
104 104

	
105 105
    virtual void _setSense(Sense sense);
106 106
    virtual Sense _getSense() const;
107 107

	
108 108
    virtual ColTypes _getColType(int col) const;
109 109
    virtual void _setColType(int col, ColTypes col_type);
110 110

	
111 111
    virtual SolveExitStatus _solve();
112 112
    virtual ProblemType _getType() const;
113 113
    virtual Value _getSol(int i) const;
114 114
    virtual Value _getSolValue() const;
115 115

	
116 116
    virtual void _clear();
117 117

	
118 118
    virtual void _messageLevel(MessageLevel level);
119 119
    void _applyMessageLevel();
120 120

	
121 121
    int _message_level;
122 122

	
123
    
123

	
124 124

	
125 125
  };
126 126

	
127 127
}
128 128

	
129 129
#endif
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_CIRCULATION_H
20 20
#define LEMON_CIRCULATION_H
21 21

	
22 22
#include <lemon/tolerance.h>
23 23
#include <lemon/elevator.h>
24 24
#include <limits>
25 25

	
26 26
///\ingroup max_flow
27 27
///\file
28 28
///\brief Push-relabel algorithm for finding a feasible circulation.
29 29
///
... ...
@@ -38,50 +38,50 @@
38 38
  /// \tparam UM The type of the upper bound (capacity) map.
39 39
  /// \tparam SM The type of the supply map.
40 40
  template <typename GR, typename LM,
41 41
            typename UM, typename SM>
42 42
  struct CirculationDefaultTraits {
43 43

	
44 44
    /// \brief The type of the digraph the algorithm runs on.
45 45
    typedef GR Digraph;
46 46

	
47 47
    /// \brief The type of the lower bound map.
48 48
    ///
49 49
    /// The type of the map that stores the lower bounds on the arcs.
50 50
    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
51 51
    typedef LM LowerMap;
52 52

	
53 53
    /// \brief The type of the upper bound (capacity) map.
54 54
    ///
55 55
    /// The type of the map that stores the upper bounds (capacities)
56 56
    /// on the arcs.
57 57
    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
58 58
    typedef UM UpperMap;
59 59

	
60 60
    /// \brief The type of supply map.
61 61
    ///
62
    /// The type of the map that stores the signed supply values of the 
63
    /// nodes. 
62
    /// The type of the map that stores the signed supply values of the
63
    /// nodes.
64 64
    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
65 65
    typedef SM SupplyMap;
66 66

	
67 67
    /// \brief The type of the flow and supply values.
68 68
    typedef typename SupplyMap::Value Value;
69 69

	
70 70
    /// \brief The type of the map that stores the flow values.
71 71
    ///
72 72
    /// The type of the map that stores the flow values.
73 73
    /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
74 74
    /// concept.
75 75
    typedef typename Digraph::template ArcMap<Value> FlowMap;
76 76

	
77 77
    /// \brief Instantiates a FlowMap.
78 78
    ///
79 79
    /// This function instantiates a \ref FlowMap.
80 80
    /// \param digraph The digraph for which we would like to define
81 81
    /// the flow map.
82 82
    static FlowMap* createFlowMap(const Digraph& digraph) {
83 83
      return new FlowMap(digraph);
84 84
    }
85 85

	
86 86
    /// \brief The elevator type used by the algorithm.
87 87
    ///
... ...
@@ -113,59 +113,59 @@
113 113

	
114 114
     \ingroup max_flow
115 115
     This class implements a push-relabel algorithm for the \e network
116 116
     \e circulation problem.
117 117
     It is to find a feasible circulation when lower and upper bounds
118 118
     are given for the flow values on the arcs and lower bounds are
119 119
     given for the difference between the outgoing and incoming flow
120 120
     at the nodes.
121 121

	
122 122
     The exact formulation of this problem is the following.
123 123
     Let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$
124 124
     \f$upper: A\rightarrow\mathbf{R}\cup\{\infty\}\f$ denote the lower and
125 125
     upper bounds on the arcs, for which \f$lower(uv) \leq upper(uv)\f$
126 126
     holds for all \f$uv\in A\f$, and \f$sup: V\rightarrow\mathbf{R}\f$
127 127
     denotes the signed supply values of the nodes.
128 128
     If \f$sup(u)>0\f$, then \f$u\f$ is a supply node with \f$sup(u)\f$
129 129
     supply, if \f$sup(u)<0\f$, then \f$u\f$ is a demand node with
130 130
     \f$-sup(u)\f$ demand.
131 131
     A feasible circulation is an \f$f: A\rightarrow\mathbf{R}\f$
132 132
     solution of the following problem.
133 133

	
134 134
     \f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu)
135 135
     \geq sup(u) \quad \forall u\in V, \f]
136 136
     \f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A. \f]
137
     
137

	
138 138
     The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be
139 139
     zero or negative in order to have a feasible solution (since the sum
140 140
     of the expressions on the left-hand side of the inequalities is zero).
141 141
     It means that the total demand must be greater or equal to the total
142 142
     supply and all the supplies have to be carried out from the supply nodes,
143 143
     but there could be demands that are not satisfied.
144 144
     If \f$\sum_{u\in V} sup(u)\f$ is zero, then all the supply/demand
145 145
     constraints have to be satisfied with equality, i.e. all demands
146 146
     have to be satisfied and all supplies have to be used.
147
     
147

	
148 148
     If you need the opposite inequalities in the supply/demand constraints
149 149
     (i.e. the total demand is less than the total supply and all the demands
150 150
     have to be satisfied while there could be supplies that are not used),
151 151
     then you could easily transform the problem to the above form by reversing
152 152
     the direction of the arcs and taking the negative of the supply values
153 153
     (e.g. using \ref ReverseDigraph and \ref NegMap adaptors).
154 154

	
155 155
     This algorithm either calculates a feasible circulation, or provides
156 156
     a \ref barrier() "barrier", which prooves that a feasible soultion
157 157
     cannot exist.
158 158

	
159 159
     Note that this algorithm also provides a feasible solution for the
160 160
     \ref min_cost_flow "minimum cost flow problem".
161 161

	
162 162
     \tparam GR The type of the digraph the algorithm runs on.
163 163
     \tparam LM The type of the lower bound map. The default
164 164
     map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
165 165
     \tparam UM The type of the upper bound (capacity) map.
166 166
     The default map type is \c LM.
167 167
     \tparam SM The type of the supply map. The default map type is
168 168
     \ref concepts::Digraph::NodeMap "GR::NodeMap<UM::Value>".
169 169
  */
170 170
#ifdef DOXYGEN
171 171
template< typename GR,
... ...
@@ -304,49 +304,49 @@
304 304
    /// before calling \ref run() or \ref init().
305 305
    /// \sa SetElevator
306 306
    template <typename T>
307 307
    struct SetStandardElevator
308 308
      : public Circulation<Digraph, LowerMap, UpperMap, SupplyMap,
309 309
                       SetStandardElevatorTraits<T> > {
310 310
      typedef Circulation<Digraph, LowerMap, UpperMap, SupplyMap,
311 311
                      SetStandardElevatorTraits<T> > Create;
312 312
    };
313 313

	
314 314
    /// @}
315 315

	
316 316
  protected:
317 317

	
318 318
    Circulation() {}
319 319

	
320 320
  public:
321 321

	
322 322
    /// Constructor.
323 323

	
324 324
    /// The constructor of the class.
325 325
    ///
326 326
    /// \param graph The digraph the algorithm runs on.
327 327
    /// \param lower The lower bounds for the flow values on the arcs.
328
    /// \param upper The upper bounds (capacities) for the flow values 
328
    /// \param upper The upper bounds (capacities) for the flow values
329 329
    /// on the arcs.
330 330
    /// \param supply The signed supply values of the nodes.
331 331
    Circulation(const Digraph &graph, const LowerMap &lower,
332 332
                const UpperMap &upper, const SupplyMap &supply)
333 333
      : _g(graph), _lo(&lower), _up(&upper), _supply(&supply),
334 334
        _flow(NULL), _local_flow(false), _level(NULL), _local_level(false),
335 335
        _excess(NULL) {}
336 336

	
337 337
    /// Destructor.
338 338
    ~Circulation() {
339 339
      destroyStructures();
340 340
    }
341 341

	
342 342

	
343 343
  private:
344 344

	
345 345
    bool checkBoundMaps() {
346 346
      for (ArcIt e(_g);e!=INVALID;++e) {
347 347
        if (_tol.less((*_up)[e], (*_lo)[e])) return false;
348 348
      }
349 349
      return true;
350 350
    }
351 351

	
352 352
    void createStructures() {
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <lemon/clp.h>
20 20
#include <coin/ClpSimplex.hpp>
21 21

	
22 22
namespace lemon {
23 23

	
24 24
  ClpLp::ClpLp() {
25 25
    _prob = new ClpSimplex();
26 26
    _init_temporals();
27 27
    messageLevel(MESSAGE_NOTHING);
28 28
  }
29 29

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_CLP_H
20 20
#define LEMON_CLP_H
21 21

	
22 22
///\file
23 23
///\brief Header of the LEMON-CLP lp solver interface.
24 24

	
25 25
#include <vector>
26 26
#include <string>
27 27

	
28 28
#include <lemon/lp_base.h>
29 29

	
... ...
@@ -116,48 +116,48 @@
116 116
    virtual Value _getObjCoeff(int i) const;
117 117

	
118 118
    virtual void _setSense(Sense sense);
119 119
    virtual Sense _getSense() const;
120 120

	
121 121
    virtual SolveExitStatus _solve();
122 122

	
123 123
    virtual Value _getPrimal(int i) const;
124 124
    virtual Value _getDual(int i) const;
125 125

	
126 126
    virtual Value _getPrimalValue() const;
127 127

	
128 128
    virtual Value _getPrimalRay(int i) const;
129 129
    virtual Value _getDualRay(int i) const;
130 130

	
131 131
    virtual VarStatus _getColStatus(int i) const;
132 132
    virtual VarStatus _getRowStatus(int i) const;
133 133

	
134 134
    virtual ProblemType _getPrimalType() const;
135 135
    virtual ProblemType _getDualType() const;
136 136

	
137 137
    virtual void _clear();
138 138

	
139 139
    virtual void _messageLevel(MessageLevel);
140
    
140

	
141 141
  public:
142 142

	
143 143
    ///Solves LP with primal simplex method.
144 144
    SolveExitStatus solvePrimal();
145 145

	
146 146
    ///Solves LP with dual simplex method.
147 147
    SolveExitStatus solveDual();
148 148

	
149 149
    ///Solves LP with barrier method.
150 150
    SolveExitStatus solveBarrier();
151 151

	
152 152
    ///Returns the constraint identifier understood by CLP.
153 153
    int clpRow(Row r) const { return rows(id(r)); }
154 154

	
155 155
    ///Returns the variable identifier understood by CLP.
156 156
    int clpCol(Col c) const { return cols(id(c)); }
157 157

	
158 158
  };
159 159

	
160 160
} //END OF NAMESPACE LEMON
161 161

	
162 162
#endif //LEMON_CLP_H
163 163

	
Ignore white space 48 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_CONCEPTS_DIGRAPH_H
20 20
#define LEMON_CONCEPTS_DIGRAPH_H
21 21

	
22 22
///\ingroup graph_concepts
23 23
///\file
24 24
///\brief The concept of directed graphs.
25 25

	
26 26
#include <lemon/core.h>
27 27
#include <lemon/concepts/maps.h>
28 28
#include <lemon/concept_check.h>
29 29
#include <lemon/concepts/graph_components.h>
... ...
@@ -414,49 +414,49 @@
414 414
      ///
415 415
      /// Gives back the running node of the iterator.
416 416
      /// It is always the target of the pointed arc.
417 417
      Node runningNode(const OutArcIt&) const { return INVALID; }
418 418

	
419 419
      /// \brief The opposite node on the given arc.
420 420
      ///
421 421
      /// Gives back the opposite node on the given arc.
422 422
      Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
423 423

	
424 424
      /// \brief Reference map of the nodes to type \c T.
425 425
      ///
426 426
      /// Reference map of the nodes to type \c T.
427 427
      template<class T>
428 428
      class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
429 429
      public:
430 430

	
431 431
        ///\e
432 432
        NodeMap(const Digraph&) { }
433 433
        ///\e
434 434
        NodeMap(const Digraph&, T) { }
435 435

	
436 436
      private:
437 437
        ///Copy constructor
438
        NodeMap(const NodeMap& nm) : 
438
        NodeMap(const NodeMap& nm) :
439 439
          ReferenceMap<Node, T, T&, const T&>(nm) { }
440 440
        ///Assignment operator
441 441
        template <typename CMap>
442 442
        NodeMap& operator=(const CMap&) {
443 443
          checkConcept<ReadMap<Node, T>, CMap>();
444 444
          return *this;
445 445
        }
446 446
      };
447 447

	
448 448
      /// \brief Reference map of the arcs to type \c T.
449 449
      ///
450 450
      /// Reference map of the arcs to type \c T.
451 451
      template<class T>
452 452
      class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
453 453
      public:
454 454

	
455 455
        ///\e
456 456
        ArcMap(const Digraph&) { }
457 457
        ///\e
458 458
        ArcMap(const Digraph&, T) { }
459 459
      private:
460 460
        ///Copy constructor
461 461
        ArcMap(const ArcMap& em) :
462 462
          ReferenceMap<Arc, T, T&, const T&>(em) { }
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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 23
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
24 24
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
25 25

	
26 26
#include <lemon/core.h>
27 27
#include <lemon/concepts/maps.h>
28 28

	
29 29
#include <lemon/bits/alteration_notifier.h>
30 30

	
31 31
namespace lemon {
32 32
  namespace concepts {
33 33

	
34 34
    /// \brief Concept class for \c Node, \c Arc and \c Edge types.
35 35
    ///
36 36
    /// This class describes the concept of \c Node, \c Arc and \c Edge
37 37
    /// subtypes of digraph and graph types.
38 38
    ///
39 39
    /// \note This class is a template class so that we can use it to
40 40
    /// create graph skeleton classes. The reason for this is that \c Node
41
    /// and \c Arc (or \c Edge) types should \e not derive from the same 
41
    /// and \c Arc (or \c Edge) types should \e not derive from the same
42 42
    /// base class. For \c Node you should instantiate it with character
43 43
    /// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'.
44 44
#ifndef DOXYGEN
45 45
    template <char sel = '0'>
46 46
#endif
47 47
    class GraphItem {
48 48
    public:
49 49
      /// \brief Default constructor.
50 50
      ///
51 51
      /// Default constructor.
52 52
      /// \warning The default constructor is not required to set
53 53
      /// the item to some well-defined value. So you should consider it
54 54
      /// as uninitialized.
55 55
      GraphItem() {}
56 56

	
57 57
      /// \brief Copy constructor.
58 58
      ///
59 59
      /// Copy constructor.
60 60
      GraphItem(const GraphItem &) {}
61 61

	
62 62
      /// \brief Constructor for conversion from \c INVALID.
63 63
      ///
64 64
      /// Constructor for conversion from \c INVALID.
65 65
      /// It initializes the item to be invalid.
... ...
@@ -68,82 +68,82 @@
68 68

	
69 69
      /// \brief Assignment operator.
70 70
      ///
71 71
      /// Assignment operator for the item.
72 72
      GraphItem& operator=(const GraphItem&) { return *this; }
73 73

	
74 74
      /// \brief Assignment operator for INVALID.
75 75
      ///
76 76
      /// This operator makes the item invalid.
77 77
      GraphItem& operator=(Invalid) { return *this; }
78 78

	
79 79
      /// \brief Equality operator.
80 80
      ///
81 81
      /// Equality operator.
82 82
      bool operator==(const GraphItem&) const { return false; }
83 83

	
84 84
      /// \brief Inequality operator.
85 85
      ///
86 86
      /// Inequality operator.
87 87
      bool operator!=(const GraphItem&) const { return false; }
88 88

	
89 89
      /// \brief Ordering operator.
90 90
      ///
91 91
      /// This operator defines an ordering of the items.
92
      /// It makes possible to use graph item types as key types in 
92
      /// It makes possible to use graph item types as key types in
93 93
      /// associative containers (e.g. \c std::map).
94 94
      ///
95 95
      /// \note This operator only have to define some strict ordering of
96 96
      /// the items; this order has nothing to do with the iteration
97 97
      /// ordering of the items.
98 98
      bool operator<(const GraphItem&) const { return false; }
99 99

	
100 100
      template<typename _GraphItem>
101 101
      struct Constraints {
102 102
        void constraints() {
103 103
          _GraphItem i1;
104 104
          i1=INVALID;
105 105
          _GraphItem i2 = i1;
106 106
          _GraphItem i3 = INVALID;
107 107

	
108 108
          i1 = i2 = i3;
109 109

	
110 110
          bool b;
111 111
          b = (ia == ib) && (ia != ib);
112 112
          b = (ia == INVALID) && (ib != INVALID);
113 113
          b = (ia < ib);
114 114
        }
115 115

	
116 116
        const _GraphItem &ia;
117 117
        const _GraphItem &ib;
118 118
      };
119 119
    };
120 120

	
121 121
    /// \brief Base skeleton class for directed graphs.
122 122
    ///
123 123
    /// This class describes the base interface of directed graph types.
124 124
    /// All digraph %concepts have to conform to this class.
125
    /// It just provides types for nodes and arcs and functions 
125
    /// It just provides types for nodes and arcs and functions
126 126
    /// to get the source and the target nodes of arcs.
127 127
    class BaseDigraphComponent {
128 128
    public:
129 129

	
130 130
      typedef BaseDigraphComponent Digraph;
131 131

	
132 132
      /// \brief Node class of the digraph.
133 133
      ///
134 134
      /// This class represents the nodes of the digraph.
135 135
      typedef GraphItem<'n'> Node;
136 136

	
137 137
      /// \brief Arc class of the digraph.
138 138
      ///
139 139
      /// This class represents the arcs of the digraph.
140 140
      typedef GraphItem<'a'> Arc;
141 141

	
142 142
      /// \brief Return the source node of an arc.
143 143
      ///
144 144
      /// This function returns the source node of an arc.
145 145
      Node source(const Arc&) const { return INVALID; }
146 146

	
147 147
      /// \brief Return the target node of an arc.
148 148
      ///
149 149
      /// This function returns the target node of an arc.
... ...
@@ -405,156 +405,156 @@
405 405
      ///
406 406
      /// This function returns an integer greater or equal to the
407 407
      /// maximum edge id.
408 408
      int maxEdgeId() const { return -1; }
409 409

	
410 410
      template <typename _Graph>
411 411
      struct Constraints {
412 412

	
413 413
        void constraints() {
414 414
          checkConcept<IDableDigraphComponent<Base>, _Graph >();
415 415
          typename _Graph::Edge edge;
416 416
          int ueid = graph.id(edge);
417 417
          ueid = graph.id(edge);
418 418
          edge = graph.edgeFromId(ueid);
419 419
          ueid = graph.maxEdgeId();
420 420
          ignore_unused_variable_warning(ueid);
421 421
        }
422 422

	
423 423
        const _Graph& graph;
424 424
      };
425 425
    };
426 426

	
427 427
    /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
428 428
    ///
429
    /// This class describes the concept of \c NodeIt, \c ArcIt and 
429
    /// This class describes the concept of \c NodeIt, \c ArcIt and
430 430
    /// \c EdgeIt subtypes of digraph and graph types.
431 431
    template <typename GR, typename Item>
432 432
    class GraphItemIt : public Item {
433 433
    public:
434 434
      /// \brief Default constructor.
435 435
      ///
436 436
      /// Default constructor.
437 437
      /// \warning The default constructor is not required to set
438 438
      /// the iterator to some well-defined value. So you should consider it
439 439
      /// as uninitialized.
440 440
      GraphItemIt() {}
441 441

	
442 442
      /// \brief Copy constructor.
443 443
      ///
444 444
      /// Copy constructor.
445 445
      GraphItemIt(const GraphItemIt& it) : Item(it) {}
446 446

	
447 447
      /// \brief Constructor that sets the iterator to the first item.
448 448
      ///
449 449
      /// Constructor that sets the iterator to the first item.
450 450
      explicit GraphItemIt(const GR&) {}
451 451

	
452 452
      /// \brief Constructor for conversion from \c INVALID.
453 453
      ///
454 454
      /// Constructor for conversion from \c INVALID.
455 455
      /// It initializes the iterator to be invalid.
456 456
      /// \sa Invalid for more details.
457 457
      GraphItemIt(Invalid) {}
458 458

	
459 459
      /// \brief Assignment operator.
460 460
      ///
461 461
      /// Assignment operator for the iterator.
462 462
      GraphItemIt& operator=(const GraphItemIt&) { return *this; }
463 463

	
464 464
      /// \brief Increment the iterator.
465 465
      ///
466 466
      /// This operator increments the iterator, i.e. assigns it to the
467 467
      /// next item.
468 468
      GraphItemIt& operator++() { return *this; }
469
 
469

	
470 470
      /// \brief Equality operator
471 471
      ///
472 472
      /// Equality operator.
473 473
      /// Two iterators are equal if and only if they point to the
474 474
      /// same object or both are invalid.
475 475
      bool operator==(const GraphItemIt&) const { return true;}
476 476

	
477 477
      /// \brief Inequality operator
478 478
      ///
479 479
      /// Inequality operator.
480 480
      /// Two iterators are equal if and only if they point to the
481 481
      /// same object or both are invalid.
482 482
      bool operator!=(const GraphItemIt&) const { return true;}
483 483

	
484 484
      template<typename _GraphItemIt>
485 485
      struct Constraints {
486 486
        void constraints() {
487 487
          checkConcept<GraphItem<>, _GraphItemIt>();
488 488
          _GraphItemIt it1(g);
489 489
          _GraphItemIt it2;
490 490
          _GraphItemIt it3 = it1;
491 491
          _GraphItemIt it4 = INVALID;
492 492

	
493 493
          it2 = ++it1;
494 494
          ++it2 = it1;
495 495
          ++(++it1);
496 496

	
497 497
          Item bi = it1;
498 498
          bi = it2;
499 499
        }
500 500
        const GR& g;
501 501
      };
502 502
    };
503 503

	
504
    /// \brief Concept class for \c InArcIt, \c OutArcIt and 
504
    /// \brief Concept class for \c InArcIt, \c OutArcIt and
505 505
    /// \c IncEdgeIt types.
506 506
    ///
507
    /// This class describes the concept of \c InArcIt, \c OutArcIt 
507
    /// This class describes the concept of \c InArcIt, \c OutArcIt
508 508
    /// and \c IncEdgeIt subtypes of digraph and graph types.
509 509
    ///
510 510
    /// \note Since these iterator classes do not inherit from the same
511 511
    /// base class, there is an additional template parameter (selector)
512
    /// \c sel. For \c InArcIt you should instantiate it with character 
512
    /// \c sel. For \c InArcIt you should instantiate it with character
513 513
    /// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'.
514 514
    template <typename GR,
515 515
              typename Item = typename GR::Arc,
516 516
              typename Base = typename GR::Node,
517 517
              char sel = '0'>
518 518
    class GraphIncIt : public Item {
519 519
    public:
520 520
      /// \brief Default constructor.
521 521
      ///
522 522
      /// Default constructor.
523 523
      /// \warning The default constructor is not required to set
524 524
      /// the iterator to some well-defined value. So you should consider it
525 525
      /// as uninitialized.
526 526
      GraphIncIt() {}
527 527

	
528 528
      /// \brief Copy constructor.
529 529
      ///
530 530
      /// Copy constructor.
531 531
      GraphIncIt(const GraphIncIt& it) : Item(it) {}
532 532

	
533
      /// \brief Constructor that sets the iterator to the first 
533
      /// \brief Constructor that sets the iterator to the first
534 534
      /// incoming or outgoing arc.
535 535
      ///
536
      /// Constructor that sets the iterator to the first arc 
536
      /// Constructor that sets the iterator to the first arc
537 537
      /// incoming to or outgoing from the given node.
538 538
      explicit GraphIncIt(const GR&, const Base&) {}
539 539

	
540 540
      /// \brief Constructor for conversion from \c INVALID.
541 541
      ///
542 542
      /// Constructor for conversion from \c INVALID.
543 543
      /// It initializes the iterator to be invalid.
544 544
      /// \sa Invalid for more details.
545 545
      GraphIncIt(Invalid) {}
546 546

	
547 547
      /// \brief Assignment operator.
548 548
      ///
549 549
      /// Assignment operator for the iterator.
550 550
      GraphIncIt& operator=(const GraphIncIt&) { return *this; }
551 551

	
552 552
      /// \brief Increment the iterator.
553 553
      ///
554 554
      /// This operator increments the iterator, i.e. assigns it to the
555 555
      /// next arc incoming to or outgoing from the given node.
556 556
      GraphIncIt& operator++() { return *this; }
557 557

	
558 558
      /// \brief Equality operator
559 559
      ///
560 560
      /// Equality operator.
... ...
@@ -783,58 +783,58 @@
783 783

	
784 784
      typedef IterableGraphComponent Graph;
785 785

	
786 786
      /// \name Base Iteration
787 787
      ///
788 788
      /// This interface provides functions for iteration on edges.
789 789
      ///
790 790
      /// @{
791 791

	
792 792
      using IterableDigraphComponent<Base>::first;
793 793
      using IterableDigraphComponent<Base>::next;
794 794

	
795 795
      /// \brief Return the first edge.
796 796
      ///
797 797
      /// This function gives back the first edge in the iteration order.
798 798
      void first(Edge&) const {}
799 799

	
800 800
      /// \brief Return the next edge.
801 801
      ///
802 802
      /// This function gives back the next edge in the iteration order.
803 803
      void next(Edge&) const {}
804 804

	
805 805
      /// \brief Return the first edge incident to the given node.
806 806
      ///
807
      /// This function gives back the first edge incident to the given 
807
      /// This function gives back the first edge incident to the given
808 808
      /// node. The bool parameter gives back the direction for which the
809
      /// source node of the directed arc representing the edge is the 
809
      /// source node of the directed arc representing the edge is the
810 810
      /// given node.
811 811
      void firstInc(Edge&, bool&, const Node&) const {}
812 812

	
813 813
      /// \brief Gives back the next of the edges from the
814 814
      /// given node.
815 815
      ///
816
      /// This function gives back the next edge incident to the given 
816
      /// This function gives back the next edge incident to the given
817 817
      /// node. The bool parameter should be used as \c firstInc() use it.
818 818
      void nextInc(Edge&, bool&) const {}
819 819

	
820 820
      using IterableDigraphComponent<Base>::baseNode;
821 821
      using IterableDigraphComponent<Base>::runningNode;
822 822

	
823 823
      /// @}
824 824

	
825 825
      /// \name Class Based Iteration
826 826
      ///
827 827
      /// This interface provides iterator classes for edges.
828 828
      ///
829 829
      /// @{
830 830

	
831 831
      /// \brief This iterator goes through each edge.
832 832
      ///
833 833
      /// This iterator goes through each edge.
834 834
      typedef GraphItemIt<Graph, Edge> EdgeIt;
835 835

	
836 836
      /// \brief This iterator goes trough the incident edges of a
837 837
      /// node.
838 838
      ///
839 839
      /// This iterator goes trough the incident edges of a certain
840 840
      /// node of a graph.
... ...
@@ -969,49 +969,49 @@
969 969

	
970 970
      /// \brief Return the edge alteration notifier.
971 971
      ///
972 972
      /// This function gives back the edge alteration notifier.
973 973
      EdgeNotifier& notifier(Edge) const {
974 974
        return EdgeNotifier();
975 975
      }
976 976

	
977 977
      template <typename _Graph>
978 978
      struct Constraints {
979 979
        void constraints() {
980 980
          checkConcept<AlterableDigraphComponent<Base>, _Graph>();
981 981
          typename _Graph::EdgeNotifier& uen
982 982
            = graph.notifier(typename _Graph::Edge());
983 983
          ignore_unused_variable_warning(uen);
984 984
        }
985 985

	
986 986
        const _Graph& graph;
987 987
      };
988 988
    };
989 989

	
990 990
    /// \brief Concept class for standard graph maps.
991 991
    ///
992 992
    /// This class describes the concept of standard graph maps, i.e.
993
    /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and 
993
    /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and
994 994
    /// graph types, which can be used for associating data to graph items.
995 995
    /// The standard graph maps must conform to the ReferenceMap concept.
996 996
    template <typename GR, typename K, typename V>
997 997
    class GraphMap : public ReferenceMap<K, V, V&, const V&> {
998 998
      typedef ReferenceMap<K, V, V&, const V&> Parent;
999 999

	
1000 1000
    public:
1001 1001

	
1002 1002
      /// The key type of the map.
1003 1003
      typedef K Key;
1004 1004
      /// The value type of the map.
1005 1005
      typedef V Value;
1006 1006
      /// The reference type of the map.
1007 1007
      typedef Value& Reference;
1008 1008
      /// The const reference type of the map.
1009 1009
      typedef const Value& ConstReference;
1010 1010

	
1011 1011
      // The reference map tag.
1012 1012
      typedef True ReferenceMapTag;
1013 1013

	
1014 1014
      /// \brief Construct a new map.
1015 1015
      ///
1016 1016
      /// Construct a new map for the graph.
1017 1017
      explicit GraphMap(const GR&) {}
... ...
@@ -1024,72 +1024,72 @@
1024 1024
      /// \brief Copy constructor.
1025 1025
      ///
1026 1026
      /// Copy Constructor.
1027 1027
      GraphMap(const GraphMap&) : Parent() {}
1028 1028

	
1029 1029
      /// \brief Assignment operator.
1030 1030
      ///
1031 1031
      /// Assignment operator. It does not mofify the underlying graph,
1032 1032
      /// it just iterates on the current item set and set the  map
1033 1033
      /// with the value returned by the assigned map.
1034 1034
      template <typename CMap>
1035 1035
      GraphMap& operator=(const CMap&) {
1036 1036
        checkConcept<ReadMap<Key, Value>, CMap>();
1037 1037
        return *this;
1038 1038
      }
1039 1039

	
1040 1040
    public:
1041 1041
      template<typename _Map>
1042 1042
      struct Constraints {
1043 1043
        void constraints() {
1044 1044
          checkConcept
1045 1045
            <ReferenceMap<Key, Value, Value&, const Value&>, _Map>();
1046 1046
          _Map m1(g);
1047 1047
          _Map m2(g,t);
1048
          
1048

	
1049 1049
          // Copy constructor
1050 1050
          // _Map m3(m);
1051 1051

	
1052 1052
          // Assignment operator
1053 1053
          // ReadMap<Key, Value> cmap;
1054 1054
          // m3 = cmap;
1055 1055

	
1056 1056
          ignore_unused_variable_warning(m1);
1057 1057
          ignore_unused_variable_warning(m2);
1058 1058
          // ignore_unused_variable_warning(m3);
1059 1059
        }
1060 1060

	
1061 1061
        const _Map &m;
1062 1062
        const GR &g;
1063 1063
        const typename GraphMap::Value &t;
1064 1064
      };
1065 1065

	
1066 1066
    };
1067 1067

	
1068 1068
    /// \brief Skeleton class for mappable directed graphs.
1069 1069
    ///
1070 1070
    /// This class describes the interface of mappable directed graphs.
1071
    /// It extends \ref BaseDigraphComponent with the standard digraph 
1071
    /// It extends \ref BaseDigraphComponent with the standard digraph
1072 1072
    /// map classes, namely \c NodeMap and \c ArcMap.
1073 1073
    /// This concept is part of the Digraph concept.
1074 1074
    template <typename BAS = BaseDigraphComponent>
1075 1075
    class MappableDigraphComponent : public BAS  {
1076 1076
    public:
1077 1077

	
1078 1078
      typedef BAS Base;
1079 1079
      typedef typename Base::Node Node;
1080 1080
      typedef typename Base::Arc Arc;
1081 1081

	
1082 1082
      typedef MappableDigraphComponent Digraph;
1083 1083

	
1084 1084
      /// \brief Standard graph map for the nodes.
1085 1085
      ///
1086 1086
      /// Standard graph map for the nodes.
1087 1087
      /// It conforms to the ReferenceMap concept.
1088 1088
      template <typename V>
1089 1089
      class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> {
1090 1090
        typedef GraphMap<MappableDigraphComponent, Node, V> Parent;
1091 1091

	
1092 1092
      public:
1093 1093
        /// \brief Construct a new map.
1094 1094
        ///
1095 1095
        /// Construct a new map for the digraph.
... ...
@@ -1184,49 +1184,49 @@
1184 1184
          }
1185 1185

	
1186 1186
          { // int map test
1187 1187
            typedef typename _Digraph::template ArcMap<int> IntArcMap;
1188 1188
            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
1189 1189
              IntArcMap >();
1190 1190
          } { // bool map test
1191 1191
            typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
1192 1192
            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
1193 1193
              BoolArcMap >();
1194 1194
          } { // Dummy map test
1195 1195
            typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
1196 1196
            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
1197 1197
              DummyArcMap >();
1198 1198
          }
1199 1199
        }
1200 1200

	
1201 1201
        const _Digraph& digraph;
1202 1202
      };
1203 1203
    };
1204 1204

	
1205 1205
    /// \brief Skeleton class for mappable undirected graphs.
1206 1206
    ///
1207 1207
    /// This class describes the interface of mappable undirected graphs.
1208
    /// It extends \ref MappableDigraphComponent with the standard graph 
1208
    /// It extends \ref MappableDigraphComponent with the standard graph
1209 1209
    /// map class for edges (\c EdgeMap).
1210 1210
    /// This concept is part of the Graph concept.
1211 1211
    template <typename BAS = BaseGraphComponent>
1212 1212
    class MappableGraphComponent : public MappableDigraphComponent<BAS>  {
1213 1213
    public:
1214 1214

	
1215 1215
      typedef BAS Base;
1216 1216
      typedef typename Base::Edge Edge;
1217 1217

	
1218 1218
      typedef MappableGraphComponent Graph;
1219 1219

	
1220 1220
      /// \brief Standard graph map for the edges.
1221 1221
      ///
1222 1222
      /// Standard graph map for the edges.
1223 1223
      /// It conforms to the ReferenceMap concept.
1224 1224
      template <typename V>
1225 1225
      class EdgeMap : public GraphMap<MappableGraphComponent, Edge, V> {
1226 1226
        typedef GraphMap<MappableGraphComponent, Edge, V> Parent;
1227 1227

	
1228 1228
      public:
1229 1229
        /// \brief Construct a new map.
1230 1230
        ///
1231 1231
        /// Construct a new map for the graph.
1232 1232
        explicit EdgeMap(const MappableGraphComponent& graph)
... ...
@@ -1269,176 +1269,176 @@
1269 1269
          checkConcept<MappableDigraphComponent<Base>, _Graph>();
1270 1270

	
1271 1271
          { // int map test
1272 1272
            typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
1273 1273
            checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
1274 1274
              IntEdgeMap >();
1275 1275
          } { // bool map test
1276 1276
            typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
1277 1277
            checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
1278 1278
              BoolEdgeMap >();
1279 1279
          } { // Dummy map test
1280 1280
            typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
1281 1281
            checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
1282 1282
              DummyEdgeMap >();
1283 1283
          }
1284 1284
        }
1285 1285

	
1286 1286
        const _Graph& graph;
1287 1287
      };
1288 1288
    };
1289 1289

	
1290 1290
    /// \brief Skeleton class for extendable directed graphs.
1291 1291
    ///
1292 1292
    /// This class describes the interface of extendable directed graphs.
1293
    /// It extends \ref BaseDigraphComponent with functions for adding 
1293
    /// It extends \ref BaseDigraphComponent with functions for adding
1294 1294
    /// nodes and arcs to the digraph.
1295 1295
    /// This concept requires \ref AlterableDigraphComponent.
1296 1296
    template <typename BAS = BaseDigraphComponent>
1297 1297
    class ExtendableDigraphComponent : public BAS {
1298 1298
    public:
1299 1299
      typedef BAS Base;
1300 1300

	
1301 1301
      typedef typename Base::Node Node;
1302 1302
      typedef typename Base::Arc Arc;
1303 1303

	
1304 1304
      /// \brief Add a new node to the digraph.
1305 1305
      ///
1306 1306
      /// This function adds a new node to the digraph.
1307 1307
      Node addNode() {
1308 1308
        return INVALID;
1309 1309
      }
1310 1310

	
1311 1311
      /// \brief Add a new arc connecting the given two nodes.
1312 1312
      ///
1313 1313
      /// This function adds a new arc connecting the given two nodes
1314 1314
      /// of the digraph.
1315 1315
      Arc addArc(const Node&, const Node&) {
1316 1316
        return INVALID;
1317 1317
      }
1318 1318

	
1319 1319
      template <typename _Digraph>
1320 1320
      struct Constraints {
1321 1321
        void constraints() {
1322 1322
          checkConcept<Base, _Digraph>();
1323 1323
          typename _Digraph::Node node_a, node_b;
1324 1324
          node_a = digraph.addNode();
1325 1325
          node_b = digraph.addNode();
1326 1326
          typename _Digraph::Arc arc;
1327 1327
          arc = digraph.addArc(node_a, node_b);
1328 1328
        }
1329 1329

	
1330 1330
        _Digraph& digraph;
1331 1331
      };
1332 1332
    };
1333 1333

	
1334 1334
    /// \brief Skeleton class for extendable undirected graphs.
1335 1335
    ///
1336 1336
    /// This class describes the interface of extendable undirected graphs.
1337
    /// It extends \ref BaseGraphComponent with functions for adding 
1337
    /// It extends \ref BaseGraphComponent with functions for adding
1338 1338
    /// nodes and edges to the graph.
1339 1339
    /// This concept requires \ref AlterableGraphComponent.
1340 1340
    template <typename BAS = BaseGraphComponent>
1341 1341
    class ExtendableGraphComponent : public BAS {
1342 1342
    public:
1343 1343

	
1344 1344
      typedef BAS Base;
1345 1345
      typedef typename Base::Node Node;
1346 1346
      typedef typename Base::Edge Edge;
1347 1347

	
1348 1348
      /// \brief Add a new node to the digraph.
1349 1349
      ///
1350 1350
      /// This function adds a new node to the digraph.
1351 1351
      Node addNode() {
1352 1352
        return INVALID;
1353 1353
      }
1354 1354

	
1355 1355
      /// \brief Add a new edge connecting the given two nodes.
1356 1356
      ///
1357 1357
      /// This function adds a new edge connecting the given two nodes
1358 1358
      /// of the graph.
1359 1359
      Edge addEdge(const Node&, const Node&) {
1360 1360
        return INVALID;
1361 1361
      }
1362 1362

	
1363 1363
      template <typename _Graph>
1364 1364
      struct Constraints {
1365 1365
        void constraints() {
1366 1366
          checkConcept<Base, _Graph>();
1367 1367
          typename _Graph::Node node_a, node_b;
1368 1368
          node_a = graph.addNode();
1369 1369
          node_b = graph.addNode();
1370 1370
          typename _Graph::Edge edge;
1371 1371
          edge = graph.addEdge(node_a, node_b);
1372 1372
        }
1373 1373

	
1374 1374
        _Graph& graph;
1375 1375
      };
1376 1376
    };
1377 1377

	
1378 1378
    /// \brief Skeleton class for erasable directed graphs.
1379 1379
    ///
1380 1380
    /// This class describes the interface of erasable directed graphs.
1381
    /// It extends \ref BaseDigraphComponent with functions for removing 
1381
    /// It extends \ref BaseDigraphComponent with functions for removing
1382 1382
    /// nodes and arcs from the digraph.
1383 1383
    /// This concept requires \ref AlterableDigraphComponent.
1384 1384
    template <typename BAS = BaseDigraphComponent>
1385 1385
    class ErasableDigraphComponent : public BAS {
1386 1386
    public:
1387 1387

	
1388 1388
      typedef BAS Base;
1389 1389
      typedef typename Base::Node Node;
1390 1390
      typedef typename Base::Arc Arc;
1391 1391

	
1392 1392
      /// \brief Erase a node from the digraph.
1393 1393
      ///
1394
      /// This function erases the given node from the digraph and all arcs 
1394
      /// This function erases the given node from the digraph and all arcs
1395 1395
      /// connected to the node.
1396 1396
      void erase(const Node&) {}
1397 1397

	
1398 1398
      /// \brief Erase an arc from the digraph.
1399 1399
      ///
1400 1400
      /// This function erases the given arc from the digraph.
1401 1401
      void erase(const Arc&) {}
1402 1402

	
1403 1403
      template <typename _Digraph>
1404 1404
      struct Constraints {
1405 1405
        void constraints() {
1406 1406
          checkConcept<Base, _Digraph>();
1407 1407
          const typename _Digraph::Node node(INVALID);
1408 1408
          digraph.erase(node);
1409 1409
          const typename _Digraph::Arc arc(INVALID);
1410 1410
          digraph.erase(arc);
1411 1411
        }
1412 1412

	
1413 1413
        _Digraph& digraph;
1414 1414
      };
1415 1415
    };
1416 1416

	
1417 1417
    /// \brief Skeleton class for erasable undirected graphs.
1418 1418
    ///
1419 1419
    /// This class describes the interface of erasable undirected graphs.
1420
    /// It extends \ref BaseGraphComponent with functions for removing 
1420
    /// It extends \ref BaseGraphComponent with functions for removing
1421 1421
    /// nodes and edges from the graph.
1422 1422
    /// This concept requires \ref AlterableGraphComponent.
1423 1423
    template <typename BAS = BaseGraphComponent>
1424 1424
    class ErasableGraphComponent : public BAS {
1425 1425
    public:
1426 1426

	
1427 1427
      typedef BAS Base;
1428 1428
      typedef typename Base::Node Node;
1429 1429
      typedef typename Base::Edge Edge;
1430 1430

	
1431 1431
      /// \brief Erase a node from the graph.
1432 1432
      ///
1433 1433
      /// This function erases the given node from the graph and all edges
1434 1434
      /// connected to the node.
1435 1435
      void erase(const Node&) {}
1436 1436

	
1437 1437
      /// \brief Erase an edge from the digraph.
1438 1438
      ///
1439 1439
      /// This function erases the given edge from the digraph.
1440 1440
      void erase(const Edge&) {}
1441 1441

	
1442 1442
      template <typename _Graph>
1443 1443
      struct Constraints {
1444 1444
        void constraints() {
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_CONCEPTS_MAPS_H
20 20
#define LEMON_CONCEPTS_MAPS_H
21 21

	
22 22
#include <lemon/core.h>
23 23
#include <lemon/concept_check.h>
24 24

	
25 25
///\ingroup map_concepts
26 26
///\file
27 27
///\brief The concept of maps.
28 28

	
29 29
namespace lemon {
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_CONNECTIVITY_H
20 20
#define LEMON_CONNECTIVITY_H
21 21

	
22 22
#include <lemon/dfs.h>
23 23
#include <lemon/bfs.h>
24 24
#include <lemon/core.h>
25 25
#include <lemon/maps.h>
26 26
#include <lemon/adaptors.h>
27 27

	
28 28
#include <lemon/concepts/digraph.h>
29 29
#include <lemon/concepts/graph.h>
... ...
@@ -237,49 +237,49 @@
237 237
         }
238 238
      }
239 239
    private:
240 240
      const Digraph& _digraph;
241 241
      ArcMap& _cutMap;
242 242
      int& _cutNum;
243 243

	
244 244
      typename Digraph::template NodeMap<int> _compMap;
245 245
      int _num;
246 246
    };
247 247

	
248 248
  }
249 249

	
250 250

	
251 251
  /// \ingroup graph_properties
252 252
  ///
253 253
  /// \brief Check whether a directed graph is strongly connected.
254 254
  ///
255 255
  /// This function checks whether the given directed graph is strongly
256 256
  /// connected, i.e. any two nodes of the digraph are
257 257
  /// connected with directed paths in both direction.
258 258
  ///
259 259
  /// \return \c true if the digraph is strongly connected.
260 260
  /// \note By definition, the empty digraph is strongly connected.
261
  /// 
261
  ///
262 262
  /// \see countStronglyConnectedComponents(), stronglyConnectedComponents()
263 263
  /// \see connected()
264 264
  template <typename Digraph>
265 265
  bool stronglyConnected(const Digraph& digraph) {
266 266
    checkConcept<concepts::Digraph, Digraph>();
267 267

	
268 268
    typedef typename Digraph::Node Node;
269 269
    typedef typename Digraph::NodeIt NodeIt;
270 270

	
271 271
    typename Digraph::Node source = NodeIt(digraph);
272 272
    if (source == INVALID) return true;
273 273

	
274 274
    using namespace _connectivity_bits;
275 275

	
276 276
    typedef DfsVisitor<Digraph> Visitor;
277 277
    Visitor visitor;
278 278

	
279 279
    DfsVisit<Digraph, Visitor> dfs(digraph, visitor);
280 280
    dfs.init();
281 281
    dfs.addSource(source);
282 282
    dfs.start();
283 283

	
284 284
    for (NodeIt it(digraph); it != INVALID; ++it) {
285 285
      if (!dfs.reached(it)) {
... ...
@@ -289,49 +289,49 @@
289 289

	
290 290
    typedef ReverseDigraph<const Digraph> RDigraph;
291 291
    typedef typename RDigraph::NodeIt RNodeIt;
292 292
    RDigraph rdigraph(digraph);
293 293

	
294 294
    typedef DfsVisitor<RDigraph> RVisitor;
295 295
    RVisitor rvisitor;
296 296

	
297 297
    DfsVisit<RDigraph, RVisitor> rdfs(rdigraph, rvisitor);
298 298
    rdfs.init();
299 299
    rdfs.addSource(source);
300 300
    rdfs.start();
301 301

	
302 302
    for (RNodeIt it(rdigraph); it != INVALID; ++it) {
303 303
      if (!rdfs.reached(it)) {
304 304
        return false;
305 305
      }
306 306
    }
307 307

	
308 308
    return true;
309 309
  }
310 310

	
311 311
  /// \ingroup graph_properties
312 312
  ///
313
  /// \brief Count the number of strongly connected components of a 
313
  /// \brief Count the number of strongly connected components of a
314 314
  /// directed graph
315 315
  ///
316 316
  /// This function counts the number of strongly connected components of
317 317
  /// the given directed graph.
318 318
  ///
319 319
  /// The strongly connected components are the classes of an
320 320
  /// equivalence relation on the nodes of a digraph. Two nodes are in
321 321
  /// the same class if they are connected with directed paths in both
322 322
  /// direction.
323 323
  ///
324 324
  /// \return The number of strongly connected components.
325 325
  /// \note By definition, the empty digraph has zero
326 326
  /// strongly connected components.
327 327
  ///
328 328
  /// \see stronglyConnected(), stronglyConnectedComponents()
329 329
  template <typename Digraph>
330 330
  int countStronglyConnectedComponents(const Digraph& digraph) {
331 331
    checkConcept<concepts::Digraph, Digraph>();
332 332

	
333 333
    using namespace _connectivity_bits;
334 334

	
335 335
    typedef typename Digraph::Node Node;
336 336
    typedef typename Digraph::Arc Arc;
337 337
    typedef typename Digraph::NodeIt NodeIt;
... ...
@@ -723,63 +723,63 @@
723 723
      }
724 724

	
725 725
    private:
726 726
      const Digraph& _graph;
727 727
      NodeMap& _cutMap;
728 728
      int& _cutNum;
729 729

	
730 730
      typename Digraph::template NodeMap<int> _numMap;
731 731
      typename Digraph::template NodeMap<int> _retMap;
732 732
      typename Digraph::template NodeMap<Node> _predMap;
733 733
      std::stack<Edge> _edgeStack;
734 734
      int _num;
735 735
      bool rootCut;
736 736
    };
737 737

	
738 738
  }
739 739

	
740 740
  template <typename Graph>
741 741
  int countBiNodeConnectedComponents(const Graph& graph);
742 742

	
743 743
  /// \ingroup graph_properties
744 744
  ///
745 745
  /// \brief Check whether an undirected graph is bi-node-connected.
746 746
  ///
747
  /// This function checks whether the given undirected graph is 
747
  /// This function checks whether the given undirected graph is
748 748
  /// bi-node-connected, i.e. any two edges are on same circle.
749 749
  ///
750 750
  /// \return \c true if the graph bi-node-connected.
751 751
  /// \note By definition, the empty graph is bi-node-connected.
752 752
  ///
753 753
  /// \see countBiNodeConnectedComponents(), biNodeConnectedComponents()
754 754
  template <typename Graph>
755 755
  bool biNodeConnected(const Graph& graph) {
756 756
    return countBiNodeConnectedComponents(graph) <= 1;
757 757
  }
758 758

	
759 759
  /// \ingroup graph_properties
760 760
  ///
761
  /// \brief Count the number of bi-node-connected components of an 
761
  /// \brief Count the number of bi-node-connected components of an
762 762
  /// undirected graph.
763 763
  ///
764 764
  /// This function counts the number of bi-node-connected components of
765 765
  /// the given undirected graph.
766 766
  ///
767 767
  /// The bi-node-connected components are the classes of an equivalence
768 768
  /// relation on the edges of a undirected graph. Two edges are in the
769 769
  /// same class if they are on same circle.
770 770
  ///
771 771
  /// \return The number of bi-node-connected components.
772 772
  ///
773 773
  /// \see biNodeConnected(), biNodeConnectedComponents()
774 774
  template <typename Graph>
775 775
  int countBiNodeConnectedComponents(const Graph& graph) {
776 776
    checkConcept<concepts::Graph, Graph>();
777 777
    typedef typename Graph::NodeIt NodeIt;
778 778

	
779 779
    using namespace _connectivity_bits;
780 780

	
781 781
    typedef CountBiNodeConnectedComponentsVisitor<Graph> Visitor;
782 782

	
783 783
    int compNum = 0;
784 784
    Visitor visitor(graph, compNum);
785 785

	
... ...
@@ -791,95 +791,95 @@
791 791
        dfs.addSource(it);
792 792
        dfs.start();
793 793
      }
794 794
    }
795 795
    return compNum;
796 796
  }
797 797

	
798 798
  /// \ingroup graph_properties
799 799
  ///
800 800
  /// \brief Find the bi-node-connected components of an undirected graph.
801 801
  ///
802 802
  /// This function finds the bi-node-connected components of the given
803 803
  /// undirected graph.
804 804
  ///
805 805
  /// The bi-node-connected components are the classes of an equivalence
806 806
  /// relation on the edges of a undirected graph. Two edges are in the
807 807
  /// same class if they are on same circle.
808 808
  ///
809 809
  /// \image html node_biconnected_components.png
810 810
  /// \image latex node_biconnected_components.eps "bi-node-connected components" width=\textwidth
811 811
  ///
812 812
  /// \param graph The undirected graph.
813 813
  /// \retval compMap A writable edge map. The values will be set from 0
814 814
  /// to the number of the bi-node-connected components minus one. Each
815
  /// value of the map will be set exactly once, and the values of a 
815
  /// value of the map will be set exactly once, and the values of a
816 816
  /// certain component will be set continuously.
817 817
  /// \return The number of bi-node-connected components.
818 818
  ///
819 819
  /// \see biNodeConnected(), countBiNodeConnectedComponents()
820 820
  template <typename Graph, typename EdgeMap>
821 821
  int biNodeConnectedComponents(const Graph& graph,
822 822
                                EdgeMap& compMap) {
823 823
    checkConcept<concepts::Graph, Graph>();
824 824
    typedef typename Graph::NodeIt NodeIt;
825 825
    typedef typename Graph::Edge Edge;
826 826
    checkConcept<concepts::WriteMap<Edge, int>, EdgeMap>();
827 827

	
828 828
    using namespace _connectivity_bits;
829 829

	
830 830
    typedef BiNodeConnectedComponentsVisitor<Graph, EdgeMap> Visitor;
831 831

	
832 832
    int compNum = 0;
833 833
    Visitor visitor(graph, compMap, compNum);
834 834

	
835 835
    DfsVisit<Graph, Visitor> dfs(graph, visitor);
836 836
    dfs.init();
837 837

	
838 838
    for (NodeIt it(graph); it != INVALID; ++it) {
839 839
      if (!dfs.reached(it)) {
840 840
        dfs.addSource(it);
841 841
        dfs.start();
842 842
      }
843 843
    }
844 844
    return compNum;
845 845
  }
846 846

	
847 847
  /// \ingroup graph_properties
848 848
  ///
849 849
  /// \brief Find the bi-node-connected cut nodes in an undirected graph.
850 850
  ///
851 851
  /// This function finds the bi-node-connected cut nodes in the given
852 852
  /// undirected graph.
853 853
  ///
854 854
  /// The bi-node-connected components are the classes of an equivalence
855 855
  /// relation on the edges of a undirected graph. Two edges are in the
856 856
  /// same class if they are on same circle.
857 857
  /// The bi-node-connected components are separted by the cut nodes of
858 858
  /// the components.
859 859
  ///
860 860
  /// \param graph The undirected graph.
861
  /// \retval cutMap A writable node map. The values will be set to 
861
  /// \retval cutMap A writable node map. The values will be set to
862 862
  /// \c true for the nodes that separate two or more components
863 863
  /// (exactly once for each cut node), and will not be changed for
864 864
  /// other nodes.
865 865
  /// \return The number of the cut nodes.
866 866
  ///
867 867
  /// \see biNodeConnected(), biNodeConnectedComponents()
868 868
  template <typename Graph, typename NodeMap>
869 869
  int biNodeConnectedCutNodes(const Graph& graph, NodeMap& cutMap) {
870 870
    checkConcept<concepts::Graph, Graph>();
871 871
    typedef typename Graph::Node Node;
872 872
    typedef typename Graph::NodeIt NodeIt;
873 873
    checkConcept<concepts::WriteMap<Node, bool>, NodeMap>();
874 874

	
875 875
    using namespace _connectivity_bits;
876 876

	
877 877
    typedef BiNodeConnectedCutNodesVisitor<Graph, NodeMap> Visitor;
878 878

	
879 879
    int cutNum = 0;
880 880
    Visitor visitor(graph, cutMap, cutNum);
881 881

	
882 882
    DfsVisit<Graph, Visitor> dfs(graph, visitor);
883 883
    dfs.init();
884 884

	
885 885
    for (NodeIt it(graph); it != INVALID; ++it) {
... ...
@@ -1064,49 +1064,49 @@
1064 1064
        if (_retMap[_graph.source(edge)] > _retMap[_graph.target(edge)]) {
1065 1065
          _retMap.set(_graph.source(edge), _retMap[_graph.target(edge)]);
1066 1066
        }
1067 1067
      }
1068 1068

	
1069 1069
    private:
1070 1070
      const Digraph& _graph;
1071 1071
      ArcMap& _cutMap;
1072 1072
      int& _cutNum;
1073 1073

	
1074 1074
      typename Digraph::template NodeMap<int> _numMap;
1075 1075
      typename Digraph::template NodeMap<int> _retMap;
1076 1076
      typename Digraph::template NodeMap<Arc> _predMap;
1077 1077
      int _num;
1078 1078
    };
1079 1079
  }
1080 1080

	
1081 1081
  template <typename Graph>
1082 1082
  int countBiEdgeConnectedComponents(const Graph& graph);
1083 1083

	
1084 1084
  /// \ingroup graph_properties
1085 1085
  ///
1086 1086
  /// \brief Check whether an undirected graph is bi-edge-connected.
1087 1087
  ///
1088
  /// This function checks whether the given undirected graph is 
1088
  /// This function checks whether the given undirected graph is
1089 1089
  /// bi-edge-connected, i.e. any two nodes are connected with at least
1090 1090
  /// two edge-disjoint paths.
1091 1091
  ///
1092 1092
  /// \return \c true if the graph is bi-edge-connected.
1093 1093
  /// \note By definition, the empty graph is bi-edge-connected.
1094 1094
  ///
1095 1095
  /// \see countBiEdgeConnectedComponents(), biEdgeConnectedComponents()
1096 1096
  template <typename Graph>
1097 1097
  bool biEdgeConnected(const Graph& graph) {
1098 1098
    return countBiEdgeConnectedComponents(graph) <= 1;
1099 1099
  }
1100 1100

	
1101 1101
  /// \ingroup graph_properties
1102 1102
  ///
1103 1103
  /// \brief Count the number of bi-edge-connected components of an
1104 1104
  /// undirected graph.
1105 1105
  ///
1106 1106
  /// This function counts the number of bi-edge-connected components of
1107 1107
  /// the given undirected graph.
1108 1108
  ///
1109 1109
  /// The bi-edge-connected components are the classes of an equivalence
1110 1110
  /// relation on the nodes of an undirected graph. Two nodes are in the
1111 1111
  /// same class if they are connected with at least two edge-disjoint
1112 1112
  /// paths.
... ...
@@ -1171,49 +1171,49 @@
1171 1171
    using namespace _connectivity_bits;
1172 1172

	
1173 1173
    typedef BiEdgeConnectedComponentsVisitor<Graph, NodeMap> Visitor;
1174 1174

	
1175 1175
    int compNum = 0;
1176 1176
    Visitor visitor(graph, compMap, compNum);
1177 1177

	
1178 1178
    DfsVisit<Graph, Visitor> dfs(graph, visitor);
1179 1179
    dfs.init();
1180 1180

	
1181 1181
    for (NodeIt it(graph); it != INVALID; ++it) {
1182 1182
      if (!dfs.reached(it)) {
1183 1183
        dfs.addSource(it);
1184 1184
        dfs.start();
1185 1185
      }
1186 1186
    }
1187 1187
    return compNum;
1188 1188
  }
1189 1189

	
1190 1190
  /// \ingroup graph_properties
1191 1191
  ///
1192 1192
  /// \brief Find the bi-edge-connected cut edges in an undirected graph.
1193 1193
  ///
1194 1194
  /// This function finds the bi-edge-connected cut edges in the given
1195
  /// undirected graph. 
1195
  /// undirected graph.
1196 1196
  ///
1197 1197
  /// The bi-edge-connected components are the classes of an equivalence
1198 1198
  /// relation on the nodes of an undirected graph. Two nodes are in the
1199 1199
  /// same class if they are connected with at least two edge-disjoint
1200 1200
  /// paths.
1201 1201
  /// The bi-edge-connected components are separted by the cut edges of
1202 1202
  /// the components.
1203 1203
  ///
1204 1204
  /// \param graph The undirected graph.
1205 1205
  /// \retval cutMap A writable edge map. The values will be set to \c true
1206 1206
  /// for the cut edges (exactly once for each cut edge), and will not be
1207 1207
  /// changed for other edges.
1208 1208
  /// \return The number of cut edges.
1209 1209
  ///
1210 1210
  /// \see biEdgeConnected(), biEdgeConnectedComponents()
1211 1211
  template <typename Graph, typename EdgeMap>
1212 1212
  int biEdgeConnectedCutEdges(const Graph& graph, EdgeMap& cutMap) {
1213 1213
    checkConcept<concepts::Graph, Graph>();
1214 1214
    typedef typename Graph::NodeIt NodeIt;
1215 1215
    typedef typename Graph::Edge Edge;
1216 1216
    checkConcept<concepts::WriteMap<Edge, bool>, EdgeMap>();
1217 1217

	
1218 1218
    using namespace _connectivity_bits;
1219 1219

	
... ...
@@ -1328,49 +1328,49 @@
1328 1328
      visitor(order, countNodes(digraph));
1329 1329

	
1330 1330
    DfsVisit<Digraph, TopologicalSortVisitor<Digraph, NodeMap> >
1331 1331
      dfs(digraph, visitor);
1332 1332

	
1333 1333
    dfs.init();
1334 1334
    for (NodeIt it(digraph); it != INVALID; ++it) {
1335 1335
      if (!dfs.reached(it)) {
1336 1336
        dfs.addSource(it);
1337 1337
        dfs.start();
1338 1338
      }
1339 1339
    }
1340 1340
  }
1341 1341

	
1342 1342
  /// \ingroup graph_properties
1343 1343
  ///
1344 1344
  /// \brief Sort the nodes of a DAG into topolgical order.
1345 1345
  ///
1346 1346
  /// This function sorts the nodes of the given acyclic digraph (DAG)
1347 1347
  /// into topolgical order and also checks whether the given digraph
1348 1348
  /// is DAG.
1349 1349
  ///
1350 1350
  /// \param digraph The digraph.
1351 1351
  /// \retval order A readable and writable node map. The values will be
1352
  /// set from 0 to the number of the nodes in the digraph minus one. 
1352
  /// set from 0 to the number of the nodes in the digraph minus one.
1353 1353
  /// Each value of the map will be set exactly once, and the values will
1354 1354
  /// be set descending order.
1355 1355
  /// \return \c false if the digraph is not DAG.
1356 1356
  ///
1357 1357
  /// \see dag(), topologicalSort()
1358 1358
  template <typename Digraph, typename NodeMap>
1359 1359
  bool checkedTopologicalSort(const Digraph& digraph, NodeMap& order) {
1360 1360
    using namespace _connectivity_bits;
1361 1361

	
1362 1362
    checkConcept<concepts::Digraph, Digraph>();
1363 1363
    checkConcept<concepts::ReadWriteMap<typename Digraph::Node, int>,
1364 1364
      NodeMap>();
1365 1365

	
1366 1366
    typedef typename Digraph::Node Node;
1367 1367
    typedef typename Digraph::NodeIt NodeIt;
1368 1368
    typedef typename Digraph::Arc Arc;
1369 1369

	
1370 1370
    for (NodeIt it(digraph); it != INVALID; ++it) {
1371 1371
      order.set(it, -1);
1372 1372
    }
1373 1373

	
1374 1374
    TopologicalSortVisitor<Digraph, NodeMap>
1375 1375
      visitor(order, countNodes(digraph));
1376 1376

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_CORE_H
20 20
#define LEMON_CORE_H
21 21

	
22 22
#include <vector>
23 23
#include <algorithm>
24 24

	
25 25
#include <lemon/config.h>
26 26
#include <lemon/bits/enable_if.h>
27 27
#include <lemon/bits/traits.h>
28 28
#include <lemon/assert.h>
29 29

	
... ...
@@ -1220,88 +1220,89 @@
1220 1220
  ///time bound for arc look-ups. This class also guarantees the
1221 1221
  ///optimal time bound in a constant factor for any distribution of
1222 1222
  ///queries.
1223 1223
  ///
1224 1224
  ///\tparam GR The type of the underlying digraph.
1225 1225
  ///
1226 1226
  ///\sa ArcLookUp
1227 1227
  ///\sa AllArcLookUp
1228 1228
  template <typename GR>
1229 1229
  class DynArcLookUp
1230 1230
    : protected ItemSetTraits<GR, typename GR::Arc>::ItemNotifier::ObserverBase
1231 1231
  {
1232 1232
    typedef typename ItemSetTraits<GR, typename GR::Arc>
1233 1233
    ::ItemNotifier::ObserverBase Parent;
1234 1234

	
1235 1235
    TEMPLATE_DIGRAPH_TYPEDEFS(GR);
1236 1236

	
1237 1237
  public:
1238 1238

	
1239 1239
    /// The Digraph type
1240 1240
    typedef GR Digraph;
1241 1241

	
1242 1242
  protected:
1243 1243

	
1244
    class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type {
1244
    class AutoNodeMap :
1245
      public ItemSetTraits<GR, Node>::template Map<Arc>::Type {
1245 1246
      typedef typename ItemSetTraits<GR, Node>::template Map<Arc>::Type Parent;
1246 1247

	
1247 1248
    public:
1248 1249

	
1249 1250
      AutoNodeMap(const GR& digraph) : Parent(digraph, INVALID) {}
1250 1251

	
1251 1252
      virtual void add(const Node& node) {
1252 1253
        Parent::add(node);
1253 1254
        Parent::set(node, INVALID);
1254 1255
      }
1255 1256

	
1256 1257
      virtual void add(const std::vector<Node>& nodes) {
1257 1258
        Parent::add(nodes);
1258 1259
        for (int i = 0; i < int(nodes.size()); ++i) {
1259 1260
          Parent::set(nodes[i], INVALID);
1260 1261
        }
1261 1262
      }
1262 1263

	
1263 1264
      virtual void build() {
1264 1265
        Parent::build();
1265 1266
        Node it;
1266 1267
        typename Parent::Notifier* nf = Parent::notifier();
1267 1268
        for (nf->first(it); it != INVALID; nf->next(it)) {
1268 1269
          Parent::set(it, INVALID);
1269 1270
        }
1270 1271
      }
1271 1272
    };
1272 1273

	
1273 1274
    class ArcLess {
1274 1275
      const Digraph &g;
1275 1276
    public:
1276 1277
      ArcLess(const Digraph &_g) : g(_g) {}
1277 1278
      bool operator()(Arc a,Arc b) const
1278 1279
      {
1279 1280
        return g.target(a)<g.target(b);
1280 1281
      }
1281 1282
    };
1282 1283

	
1283
  protected: 
1284
  protected:
1284 1285

	
1285 1286
    const Digraph &_g;
1286 1287
    AutoNodeMap _head;
1287 1288
    typename Digraph::template ArcMap<Arc> _parent;
1288 1289
    typename Digraph::template ArcMap<Arc> _left;
1289 1290
    typename Digraph::template ArcMap<Arc> _right;
1290 1291

	
1291 1292
  public:
1292 1293

	
1293 1294
    ///Constructor
1294 1295

	
1295 1296
    ///Constructor.
1296 1297
    ///
1297 1298
    ///It builds up the search database.
1298 1299
    DynArcLookUp(const Digraph &g)
1299 1300
      : _g(g),_head(g),_parent(g),_left(g),_right(g)
1300 1301
    {
1301 1302
      Parent::attach(_g.notifier(typename Digraph::Arc()));
1302 1303
      refresh();
1303 1304
    }
1304 1305

	
1305 1306
  protected:
1306 1307

	
1307 1308
    virtual void add(const Arc& arc) {
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20
#include <vector>
21 21
#include <cstring>
22 22

	
23 23
#include <lemon/cplex.h>
24 24

	
25 25
extern "C" {
26 26
#include <ilcplex/cplex.h>
27 27
}
28 28

	
29 29

	
... ...
@@ -435,49 +435,49 @@
435 435

	
436 436
  void CplexBase::_clear() {
437 437
    CPXfreeprob(cplexEnv(),&_prob);
438 438
    int status;
439 439
    _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
440 440
    rows.clear();
441 441
    cols.clear();
442 442
  }
443 443

	
444 444
  void CplexBase::_messageLevel(MessageLevel level) {
445 445
    switch (level) {
446 446
    case MESSAGE_NOTHING:
447 447
      _message_enabled = false;
448 448
      break;
449 449
    case MESSAGE_ERROR:
450 450
    case MESSAGE_WARNING:
451 451
    case MESSAGE_NORMAL:
452 452
    case MESSAGE_VERBOSE:
453 453
      _message_enabled = true;
454 454
      break;
455 455
    }
456 456
  }
457 457

	
458 458
  void CplexBase::_applyMessageLevel() {
459
    CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, 
459
    CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND,
460 460
                   _message_enabled ? CPX_ON : CPX_OFF);
461 461
  }
462 462

	
463 463
  // CplexLp members
464 464

	
465 465
  CplexLp::CplexLp()
466 466
    : LpBase(), LpSolver(), CplexBase() {}
467 467

	
468 468
  CplexLp::CplexLp(const CplexEnv& env)
469 469
    : LpBase(), LpSolver(), CplexBase(env) {}
470 470

	
471 471
  CplexLp::CplexLp(const CplexLp& other)
472 472
    : LpBase(), LpSolver(), CplexBase(other) {}
473 473

	
474 474
  CplexLp::~CplexLp() {}
475 475

	
476 476
  CplexLp* CplexLp::newSolver() const { return new CplexLp; }
477 477
  CplexLp* CplexLp::cloneSolver() const {return new CplexLp(*this); }
478 478

	
479 479
  const char* CplexLp::_solverName() const { return "CplexLp"; }
480 480

	
481 481
  void CplexLp::_clear_temporals() {
482 482
    _col_status.clear();
483 483
    _row_status.clear();
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_DFS_H
20 20
#define LEMON_DFS_H
21 21

	
22 22
///\ingroup search
23 23
///\file
24 24
///\brief DFS algorithm.
25 25

	
26 26
#include <lemon/list_graph.h>
27 27
#include <lemon/bits/path_dump.h>
28 28
#include <lemon/core.h>
29 29
#include <lemon/error.h>
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_DIMACS_H
20 20
#define LEMON_DIMACS_H
21 21

	
22 22
#include <iostream>
23 23
#include <string>
24 24
#include <vector>
25 25
#include <limits>
26 26
#include <lemon/maps.h>
27 27
#include <lemon/error.h>
28 28
/// \ingroup dimacs_group
29 29
/// \file
... ...
@@ -40,49 +40,49 @@
40 40
    ///\brief DIMACS file type enum
41 41
    ///
42 42
    ///DIMACS file type enum.
43 43
    enum Type {
44 44
      NONE,  ///< Undefined type.
45 45
      MIN,   ///< DIMACS file type for minimum cost flow problems.
46 46
      MAX,   ///< DIMACS file type for maximum flow problems.
47 47
      SP,    ///< DIMACS file type for shostest path problems.
48 48
      MAT    ///< DIMACS file type for plain graphs and matching problems.
49 49
    };
50 50
    ///The file type
51 51
    Type type;
52 52
    ///The number of nodes in the graph
53 53
    int nodeNum;
54 54
    ///The number of edges in the graph
55 55
    int edgeNum;
56 56
    int lineShift;
57 57
    ///Constructor. It sets the type to \c NONE.
58 58
    DimacsDescriptor() : type(NONE) {}
59 59
  };
60 60

	
61 61
  ///Discover the type of a DIMACS file
62 62

	
63 63
  ///This function starts seeking the beginning of the given file for the
64
  ///problem type and size info. 
64
  ///problem type and size info.
65 65
  ///The found data is returned in a special struct that can be evaluated
66 66
  ///and passed to the appropriate reader function.
67 67
  DimacsDescriptor dimacsType(std::istream& is)
68 68
  {
69 69
    DimacsDescriptor r;
70 70
    std::string problem,str;
71 71
    char c;
72 72
    r.lineShift=0;
73 73
    while (is >> c)
74 74
      switch(c)
75 75
        {
76 76
        case 'p':
77 77
          if(is >> problem >> r.nodeNum >> r.edgeNum)
78 78
            {
79 79
              getline(is, str);
80 80
              r.lineShift++;
81 81
              if(problem=="min") r.type=DimacsDescriptor::MIN;
82 82
              else if(problem=="max") r.type=DimacsDescriptor::MAX;
83 83
              else if(problem=="sp") r.type=DimacsDescriptor::SP;
84 84
              else if(problem=="mat") r.type=DimacsDescriptor::MAT;
85 85
              else throw FormatError("Unknown problem type");
86 86
              return r;
87 87
            }
88 88
          else
... ...
@@ -191,74 +191,74 @@
191 191
                   Digraph &g,
192 192
                   CapacityMap& capacity,
193 193
                   typename Digraph::Node &s,
194 194
                   typename Digraph::Node &t,
195 195
                   typename CapacityMap::Value infty = 0,
196 196
                   DimacsDescriptor desc=DimacsDescriptor()) {
197 197
    g.clear();
198 198
    s=t=INVALID;
199 199
    std::vector<typename Digraph::Node> nodes;
200 200
    typename Digraph::Arc e;
201 201
    char c, d;
202 202
    int i, j;
203 203
    typename CapacityMap::Value _cap;
204 204
    std::string str;
205 205
    nodes.resize(desc.nodeNum + 1);
206 206
    for (int k = 1; k <= desc.nodeNum; ++k) {
207 207
      nodes[k] = g.addNode();
208 208
    }
209 209
    typedef typename CapacityMap::Value Capacity;
210 210

	
211 211
    if(infty==0)
212 212
      infty = std::numeric_limits<Capacity>::has_infinity ?
213 213
        std::numeric_limits<Capacity>::infinity() :
214 214
        std::numeric_limits<Capacity>::max();
215
 
215

	
216 216
    while (is >> c) {
217 217
      switch (c) {
218 218
      case 'c': // comment line
219 219
        getline(is, str);
220 220
        break;
221 221
      case 'n': // node definition line
222 222
        if (desc.type==DimacsDescriptor::SP) { // shortest path problem
223 223
          is >> i;
224 224
          getline(is, str);
225 225
          s = nodes[i];
226 226
        }
227 227
        if (desc.type==DimacsDescriptor::MAX) { // max flow problem
228 228
          is >> i >> d;
229 229
          getline(is, str);
230 230
          if (d == 's') s = nodes[i];
231 231
          if (d == 't') t = nodes[i];
232 232
        }
233 233
        break;
234 234
      case 'a': // arc definition line
235 235
        if (desc.type==DimacsDescriptor::SP) {
236 236
          is >> i >> j >> _cap;
237 237
          getline(is, str);
238 238
          e = g.addArc(nodes[i], nodes[j]);
239 239
          capacity.set(e, _cap);
240
        } 
240
        }
241 241
        else if (desc.type==DimacsDescriptor::MAX) {
242 242
          is >> i >> j >> _cap;
243 243
          getline(is, str);
244 244
          e = g.addArc(nodes[i], nodes[j]);
245 245
          if (_cap >= 0)
246 246
            capacity.set(e, _cap);
247 247
          else
248 248
            capacity.set(e, infty);
249 249
        }
250 250
        else {
251 251
          is >> i >> j;
252 252
          getline(is, str);
253 253
          g.addArc(nodes[i], nodes[j]);
254 254
        }
255 255
        break;
256 256
      }
257 257
    }
258 258
  }
259 259

	
260 260
  /// \brief DIMACS maximum flow reader function.
261 261
  ///
262 262
  /// This function reads a maximum flow instance from DIMACS format,
263 263
  /// i.e. from a DIMACS file having a line starting with
264 264
  /// \code
... ...
@@ -341,79 +341,79 @@
341 341
                     CapacityMap& capacity,
342 342
                     typename CapacityMap::Value infty = 0,
343 343
                     DimacsDescriptor desc=DimacsDescriptor()) {
344 344
    typename Digraph::Node u,v;
345 345
    if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is);
346 346
    if(desc.type!=DimacsDescriptor::MAX || desc.type!=DimacsDescriptor::SP)
347 347
      throw FormatError("Problem type mismatch");
348 348
    _readDimacs(is, g, capacity, u, v, infty, desc);
349 349
  }
350 350

	
351 351
  template<typename Graph>
352 352
  typename enable_if<lemon::UndirectedTagIndicator<Graph>,void>::type
353 353
  _addArcEdge(Graph &g, typename Graph::Node s, typename Graph::Node t,
354 354
              dummy<0> = 0)
355 355
  {
356 356
    g.addEdge(s,t);
357 357
  }
358 358
  template<typename Graph>
359 359
  typename disable_if<lemon::UndirectedTagIndicator<Graph>,void>::type
360 360
  _addArcEdge(Graph &g, typename Graph::Node s, typename Graph::Node t,
361 361
              dummy<1> = 1)
362 362
  {
363 363
    g.addArc(s,t);
364 364
  }
365
  
365

	
366 366
  /// \brief DIMACS plain (di)graph reader function.
367 367
  ///
368 368
  /// This function reads a plain (di)graph without any designated nodes
369
  /// and maps (e.g. a matching instance) from DIMACS format, i.e. from 
369
  /// and maps (e.g. a matching instance) from DIMACS format, i.e. from
370 370
  /// DIMACS files having a line starting with
371 371
  /// \code
372 372
  ///   p mat
373 373
  /// \endcode
374 374
  /// At the beginning, \c g is cleared by \c g.clear().
375 375
  ///
376 376
  /// If the file type was previously evaluated by dimacsType(), then
377 377
  /// the descriptor struct should be given by the \c dest parameter.
378 378
  template<typename Graph>
379 379
  void readDimacsMat(std::istream& is, Graph &g,
380 380
                     DimacsDescriptor desc=DimacsDescriptor())
381 381
  {
382 382
    if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is);
383 383
    if(desc.type!=DimacsDescriptor::MAT)
384 384
      throw FormatError("Problem type mismatch");
385 385

	
386 386
    g.clear();
387 387
    std::vector<typename Graph::Node> nodes;
388 388
    char c;
389 389
    int i, j;
390 390
    std::string str;
391 391
    nodes.resize(desc.nodeNum + 1);
392 392
    for (int k = 1; k <= desc.nodeNum; ++k) {
393 393
      nodes[k] = g.addNode();
394 394
    }
395
    
395

	
396 396
    while (is >> c) {
397 397
      switch (c) {
398 398
      case 'c': // comment line
399 399
        getline(is, str);
400 400
        break;
401 401
      case 'n': // node definition line
402 402
        break;
403 403
      case 'a': // arc definition line
404 404
        is >> i >> j;
405 405
        getline(is, str);
406 406
        _addArcEdge(g,nodes[i], nodes[j]);
407 407
        break;
408 408
      }
409 409
    }
410 410
  }
411 411

	
412 412
  /// DIMACS plain digraph writer function.
413 413
  ///
414 414
  /// This function writes a digraph without any designated nodes and
415 415
  /// maps into DIMACS format, i.e. into DIMACS file having a line
416 416
  /// starting with
417 417
  /// \code
418 418
  ///   p mat
419 419
  /// \endcode
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_EDGE_SET_H
20 20
#define LEMON_EDGE_SET_H
21 21

	
22 22
#include <lemon/core.h>
23 23
#include <lemon/bits/edge_set_extender.h>
24 24

	
25 25
/// \ingroup graphs
26 26
/// \file
27 27
/// \brief ArcSet and EdgeSet classes.
28 28
///
29 29
/// Graphs which use another graph's node-set as own.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_EULER_H
20 20
#define LEMON_EULER_H
21 21

	
22 22
#include<lemon/core.h>
23 23
#include<lemon/adaptors.h>
24 24
#include<lemon/connectivity.h>
25 25
#include <list>
26 26

	
27 27
/// \ingroup graph_properties
28 28
/// \file
29
/// \brief Euler tour iterators and a function for checking the \e Eulerian 
29
/// \brief Euler tour iterators and a function for checking the \e Eulerian
30 30
/// property.
31 31
///
32 32
///This file provides Euler tour iterators and a function to check
33 33
///if a (di)graph is \e Eulerian.
34 34

	
35 35
namespace lemon {
36 36

	
37 37
  ///Euler tour iterator for digraphs.
38 38

	
39 39
  /// \ingroup graph_prop
40 40
  ///This iterator provides an Euler tour (Eulerian circuit) of a \e directed
41 41
  ///graph (if there exists) and it converts to the \c Arc type of the digraph.
42 42
  ///
43 43
  ///For example, if the given digraph has an Euler tour (i.e it has only one
44
  ///non-trivial component and the in-degree is equal to the out-degree 
44
  ///non-trivial component and the in-degree is equal to the out-degree
45 45
  ///for all nodes), then the following code will put the arcs of \c g
46 46
  ///to the vector \c et according to an Euler tour of \c g.
47 47
  ///\code
48 48
  ///  std::vector<ListDigraph::Arc> et;
49 49
  ///  for(DiEulerIt<ListDigraph> e(g); e!=INVALID; ++e)
50 50
  ///    et.push_back(e);
51 51
  ///\endcode
52 52
  ///If \c g has no Euler tour, then the resulted walk will not be closed
53 53
  ///or not contain all arcs.
54 54
  ///\sa EulerIt
55 55
  template<typename GR>
56 56
  class DiEulerIt
57 57
  {
58 58
    typedef typename GR::Node Node;
59 59
    typedef typename GR::NodeIt NodeIt;
60 60
    typedef typename GR::Arc Arc;
61 61
    typedef typename GR::ArcIt ArcIt;
62 62
    typedef typename GR::OutArcIt OutArcIt;
63 63
    typedef typename GR::InArcIt InArcIt;
64 64

	
65 65
    const GR &g;
66 66
    typename GR::template NodeMap<OutArcIt> narc;
67 67
    std::list<Arc> euler;
68 68

	
... ...
@@ -117,58 +117,58 @@
117 117
      return *this;
118 118
    }
119 119
    ///Postfix incrementation
120 120

	
121 121
    /// Postfix incrementation.
122 122
    ///
123 123
    ///\warning This incrementation
124 124
    ///returns an \c Arc, not a \ref DiEulerIt, as one may
125 125
    ///expect.
126 126
    Arc operator++(int)
127 127
    {
128 128
      Arc e=*this;
129 129
      ++(*this);
130 130
      return e;
131 131
    }
132 132
  };
133 133

	
134 134
  ///Euler tour iterator for graphs.
135 135

	
136 136
  /// \ingroup graph_properties
137 137
  ///This iterator provides an Euler tour (Eulerian circuit) of an
138 138
  ///\e undirected graph (if there exists) and it converts to the \c Arc
139 139
  ///and \c Edge types of the graph.
140 140
  ///
141
  ///For example, if the given graph has an Euler tour (i.e it has only one 
141
  ///For example, if the given graph has an Euler tour (i.e it has only one
142 142
  ///non-trivial component and the degree of each node is even),
143 143
  ///the following code will print the arc IDs according to an
144 144
  ///Euler tour of \c g.
145 145
  ///\code
146 146
  ///  for(EulerIt<ListGraph> e(g); e!=INVALID; ++e) {
147 147
  ///    std::cout << g.id(Edge(e)) << std::eol;
148 148
  ///  }
149 149
  ///\endcode
150
  ///Although this iterator is for undirected graphs, it still returns 
150
  ///Although this iterator is for undirected graphs, it still returns
151 151
  ///arcs in order to indicate the direction of the tour.
152 152
  ///(But arcs convert to edges, of course.)
153 153
  ///
154 154
  ///If \c g has no Euler tour, then the resulted walk will not be closed
155 155
  ///or not contain all edges.
156 156
  template<typename GR>
157 157
  class EulerIt
158 158
  {
159 159
    typedef typename GR::Node Node;
160 160
    typedef typename GR::NodeIt NodeIt;
161 161
    typedef typename GR::Arc Arc;
162 162
    typedef typename GR::Edge Edge;
163 163
    typedef typename GR::ArcIt ArcIt;
164 164
    typedef typename GR::OutArcIt OutArcIt;
165 165
    typedef typename GR::InArcIt InArcIt;
166 166

	
167 167
    const GR &g;
168 168
    typename GR::template NodeMap<OutArcIt> narc;
169 169
    typename GR::template EdgeMap<bool> visited;
170 170
    std::list<Arc> euler;
171 171

	
172 172
  public:
173 173

	
174 174
    ///Constructor
... ...
@@ -212,49 +212,49 @@
212 212
    ///Next arc of the tour
213 213
    ///
214 214
    EulerIt &operator++() {
215 215
      Node s=g.target(euler.front());
216 216
      euler.pop_front();
217 217
      typename std::list<Arc>::iterator next=euler.begin();
218 218
      while(narc[s]!=INVALID) {
219 219
        while(narc[s]!=INVALID && visited[narc[s]]) ++narc[s];
220 220
        if(narc[s]==INVALID) break;
221 221
        else {
222 222
          euler.insert(next,narc[s]);
223 223
          visited[narc[s]]=true;
224 224
          Node n=g.target(narc[s]);
225 225
          ++narc[s];
226 226
          s=n;
227 227
        }
228 228
      }
229 229
      return *this;
230 230
    }
231 231

	
232 232
    ///Postfix incrementation
233 233

	
234 234
    /// Postfix incrementation.
235 235
    ///
236
    ///\warning This incrementation returns an \c Arc (which converts to 
236
    ///\warning This incrementation returns an \c Arc (which converts to
237 237
    ///an \c Edge), not an \ref EulerIt, as one may expect.
238 238
    Arc operator++(int)
239 239
    {
240 240
      Arc e=*this;
241 241
      ++(*this);
242 242
      return e;
243 243
    }
244 244
  };
245 245

	
246 246

	
247 247
  ///Check if the given graph is Eulerian
248 248

	
249 249
  /// \ingroup graph_properties
250 250
  ///This function checks if the given graph is Eulerian.
251 251
  ///It works for both directed and undirected graphs.
252 252
  ///
253 253
  ///By definition, a digraph is called \e Eulerian if
254 254
  ///and only if it is connected and the number of incoming and outgoing
255 255
  ///arcs are the same for each node.
256 256
  ///Similarly, an undirected graph is called \e Eulerian if
257 257
  ///and only if it is connected and the number of incident edges is even
258 258
  ///for each node.
259 259
  ///
260 260
  ///\note There are (di)graphs that are not Eulerian, but still have an
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_GLPK_H
20 20
#define LEMON_GLPK_H
21 21

	
22 22
///\file
23 23
///\brief Header of the LEMON-GLPK lp solver interface.
24 24
///\ingroup lp_group
25 25

	
26 26
#include <lemon/lp_base.h>
27 27

	
28 28
namespace lemon {
29 29

	
30 30
  namespace _solver_bits {
31 31
    class VoidPtr {
32 32
    private:
33
      void *_ptr;      
33
      void *_ptr;
34 34
    public:
35 35
      VoidPtr() : _ptr(0) {}
36 36

	
37 37
      template <typename T>
38 38
      VoidPtr(T* ptr) : _ptr(reinterpret_cast<void*>(ptr)) {}
39 39

	
40 40
      template <typename T>
41
      VoidPtr& operator=(T* ptr) { 
42
        _ptr = reinterpret_cast<void*>(ptr); 
41
      VoidPtr& operator=(T* ptr) {
42
        _ptr = reinterpret_cast<void*>(ptr);
43 43
        return *this;
44 44
      }
45 45

	
46 46
      template <typename T>
47 47
      operator T*() const { return reinterpret_cast<T*>(_ptr); }
48 48
    };
49 49
  }
50 50

	
51 51
  /// \brief Base interface for the GLPK LP and MIP solver
52 52
  ///
53 53
  /// This class implements the common interface of the GLPK LP and MIP solver.
54 54
  /// \ingroup lp_group
55 55
  class GlpkBase : virtual public LpBase {
56 56
  protected:
57 57

	
58 58
    _solver_bits::VoidPtr lp;
59 59

	
60 60
    GlpkBase();
61 61
    GlpkBase(const GlpkBase&);
62 62
    virtual ~GlpkBase();
63 63

	
64 64
  protected:
65 65

	
66 66
    virtual int _addCol();
... ...
@@ -102,55 +102,55 @@
102 102
    virtual Value _getRowUpperBound(int i) const;
103 103

	
104 104
    virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
105 105
    virtual void _getObjCoeffs(InsertIterator b) const;
106 106

	
107 107
    virtual void _setObjCoeff(int i, Value obj_coef);
108 108
    virtual Value _getObjCoeff(int i) const;
109 109

	
110 110
    virtual void _setSense(Sense);
111 111
    virtual Sense _getSense() const;
112 112

	
113 113
    virtual void _clear();
114 114

	
115 115
    virtual void _messageLevel(MessageLevel level);
116 116

	
117 117
  private:
118 118

	
119 119
    static void freeEnv();
120 120

	
121 121
    struct FreeEnvHelper {
122 122
      ~FreeEnvHelper() {
123 123
        freeEnv();
124 124
      }
125 125
    };
126
    
126

	
127 127
    static FreeEnvHelper freeEnvHelper;
128 128

	
129 129
  protected:
130
    
130

	
131 131
    int _message_level;
132
    
132

	
133 133
  public:
134 134

	
135 135
    ///Pointer to the underlying GLPK data structure.
136 136
    _solver_bits::VoidPtr lpx() {return lp;}
137 137
    ///Const pointer to the underlying GLPK data structure.
138 138
    _solver_bits::VoidPtr lpx() const {return lp;}
139 139

	
140 140
    ///Returns the constraint identifier understood by GLPK.
141 141
    int lpxRow(Row r) const { return rows(id(r)); }
142 142

	
143 143
    ///Returns the variable identifier understood by GLPK.
144 144
    int lpxCol(Col c) const { return cols(id(c)); }
145 145

	
146 146
  };
147 147

	
148 148
  /// \brief Interface for the GLPK LP solver
149 149
  ///
150 150
  /// This class implements an interface for the GLPK LP solver.
151 151
  ///\ingroup lp_group
152 152
  class GlpkLp : public LpSolver, public GlpkBase {
153 153
  public:
154 154

	
155 155
    ///\e
156 156
    GlpkLp();
Ignore white space 6 line context
1
/* -*- C++ -*-
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library
3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_GOMORY_HU_TREE_H
20 20
#define LEMON_GOMORY_HU_TREE_H
21 21

	
22 22
#include <limits>
23 23

	
24 24
#include <lemon/core.h>
25 25
#include <lemon/preflow.h>
26 26
#include <lemon/concept_check.h>
27 27
#include <lemon/concepts/maps.h>
28 28

	
29 29
/// \ingroup min_cut
30
/// \file 
30
/// \file
31 31
/// \brief Gomory-Hu cut tree in graphs.
32 32

	
33 33
namespace lemon {
34 34

	
35 35
  /// \ingroup min_cut
36 36
  ///
37 37
  /// \brief Gomory-Hu cut tree algorithm
38 38
  ///
39 39
  /// The Gomory-Hu tree is a tree on the node set of a given graph, but it
40 40
  /// may contain edges which are not in the original graph. It has the
41
  /// property that the minimum capacity edge of the path between two nodes 
41
  /// property that the minimum capacity edge of the path between two nodes
42 42
  /// in this tree has the same weight as the minimum cut in the graph
43 43
  /// between these nodes. Moreover the components obtained by removing
44 44
  /// this edge from the tree determine the corresponding minimum cut.
45 45
  /// Therefore once this tree is computed, the minimum cut between any pair
46 46
  /// of nodes can easily be obtained.
47
  /// 
47
  ///
48 48
  /// The algorithm calculates \e n-1 distinct minimum cuts (currently with
49 49
  /// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{e})\f$ overall
50 50
  /// time complexity. It calculates a rooted Gomory-Hu tree.
51 51
  /// The structure of the tree and the edge weights can be
52 52
  /// obtained using \c predNode(), \c predValue() and \c rootDist().
53 53
  /// The functions \c minCutMap() and \c minCutValue() calculate
54 54
  /// the minimum cut and the minimum cut value between any two nodes
55 55
  /// in the graph. You can also list (iterate on) the nodes and the
56 56
  /// edges of the cuts using \c MinCutNodeIt and \c MinCutEdgeIt.
57 57
  ///
58 58
  /// \tparam GR The type of the undirected graph the algorithm runs on.
59 59
  /// \tparam CAP The type of the edge map containing the capacities.
60 60
  /// The default map type is \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>".
61 61
#ifdef DOXYGEN
62 62
  template <typename GR,
63
	    typename CAP>
63
            typename CAP>
64 64
#else
65 65
  template <typename GR,
66
	    typename CAP = typename GR::template EdgeMap<int> >
66
            typename CAP = typename GR::template EdgeMap<int> >
67 67
#endif
68 68
  class GomoryHu {
69 69
  public:
70 70

	
71 71
    /// The graph type of the algorithm
72 72
    typedef GR Graph;
73 73
    /// The capacity map type of the algorithm
74 74
    typedef CAP Capacity;
75 75
    /// The value type of capacities
76 76
    typedef typename Capacity::Value Value;
77
    
77

	
78 78
  private:
79 79

	
80 80
    TEMPLATE_GRAPH_TYPEDEFS(Graph);
81 81

	
82 82
    const Graph& _graph;
83 83
    const Capacity& _capacity;
84 84

	
85 85
    Node _root;
86 86
    typename Graph::template NodeMap<Node>* _pred;
87 87
    typename Graph::template NodeMap<Value>* _weight;
88 88
    typename Graph::template NodeMap<int>* _order;
89 89

	
90 90
    void createStructures() {
91 91
      if (!_pred) {
92
	_pred = new typename Graph::template NodeMap<Node>(_graph);
92
        _pred = new typename Graph::template NodeMap<Node>(_graph);
93 93
      }
94 94
      if (!_weight) {
95
	_weight = new typename Graph::template NodeMap<Value>(_graph);
95
        _weight = new typename Graph::template NodeMap<Value>(_graph);
96 96
      }
97 97
      if (!_order) {
98
	_order = new typename Graph::template NodeMap<int>(_graph);
98
        _order = new typename Graph::template NodeMap<int>(_graph);
99 99
      }
100 100
    }
101 101

	
102 102
    void destroyStructures() {
103 103
      if (_pred) {
104
	delete _pred;
104
        delete _pred;
105 105
      }
106 106
      if (_weight) {
107
	delete _weight;
107
        delete _weight;
108 108
      }
109 109
      if (_order) {
110
	delete _order;
110
        delete _order;
111 111
      }
112 112
    }
113
  
113

	
114 114
  public:
115 115

	
116 116
    /// \brief Constructor
117 117
    ///
118 118
    /// Constructor.
119 119
    /// \param graph The undirected graph the algorithm runs on.
120 120
    /// \param capacity The edge capacity map.
121
    GomoryHu(const Graph& graph, const Capacity& capacity) 
121
    GomoryHu(const Graph& graph, const Capacity& capacity)
122 122
      : _graph(graph), _capacity(capacity),
123
	_pred(0), _weight(0), _order(0) 
123
        _pred(0), _weight(0), _order(0)
124 124
    {
125 125
      checkConcept<concepts::ReadMap<Edge, Value>, Capacity>();
126 126
    }
127 127

	
128 128

	
129 129
    /// \brief Destructor
130 130
    ///
131 131
    /// Destructor.
132 132
    ~GomoryHu() {
133 133
      destroyStructures();
134 134
    }
135 135

	
136 136
  private:
137
  
137

	
138 138
    // Initialize the internal data structures
139 139
    void init() {
140 140
      createStructures();
141 141

	
142 142
      _root = NodeIt(_graph);
143 143
      for (NodeIt n(_graph); n != INVALID; ++n) {
144 144
        (*_pred)[n] = _root;
145 145
        (*_order)[n] = -1;
146 146
      }
147 147
      (*_pred)[_root] = INVALID;
148
      (*_weight)[_root] = std::numeric_limits<Value>::max(); 
148
      (*_weight)[_root] = std::numeric_limits<Value>::max();
149 149
    }
150 150

	
151 151

	
152 152
    // Start the algorithm
153 153
    void start() {
154 154
      Preflow<Graph, Capacity> fa(_graph, _capacity, _root, INVALID);
155 155

	
156 156
      for (NodeIt n(_graph); n != INVALID; ++n) {
157
	if (n == _root) continue;
157
        if (n == _root) continue;
158 158

	
159
	Node pn = (*_pred)[n];
160
	fa.source(n);
161
	fa.target(pn);
159
        Node pn = (*_pred)[n];
160
        fa.source(n);
161
        fa.target(pn);
162 162

	
163
	fa.runMinCut();
163
        fa.runMinCut();
164 164

	
165
	(*_weight)[n] = fa.flowValue();
165
        (*_weight)[n] = fa.flowValue();
166 166

	
167
	for (NodeIt nn(_graph); nn != INVALID; ++nn) {
168
	  if (nn != n && fa.minCut(nn) && (*_pred)[nn] == pn) {
169
	    (*_pred)[nn] = n;
170
	  }
171
	}
172
	if ((*_pred)[pn] != INVALID && fa.minCut((*_pred)[pn])) {
173
	  (*_pred)[n] = (*_pred)[pn];
174
	  (*_pred)[pn] = n;
175
	  (*_weight)[n] = (*_weight)[pn];
176
	  (*_weight)[pn] = fa.flowValue();
177
	}
167
        for (NodeIt nn(_graph); nn != INVALID; ++nn) {
168
          if (nn != n && fa.minCut(nn) && (*_pred)[nn] == pn) {
169
            (*_pred)[nn] = n;
170
          }
171
        }
172
        if ((*_pred)[pn] != INVALID && fa.minCut((*_pred)[pn])) {
173
          (*_pred)[n] = (*_pred)[pn];
174
          (*_pred)[pn] = n;
175
          (*_weight)[n] = (*_weight)[pn];
176
          (*_weight)[pn] = fa.flowValue();
177
        }
178 178
      }
179 179

	
180 180
      (*_order)[_root] = 0;
181 181
      int index = 1;
182 182

	
183 183
      for (NodeIt n(_graph); n != INVALID; ++n) {
184
	std::vector<Node> st;
185
	Node nn = n;
186
	while ((*_order)[nn] == -1) {
187
	  st.push_back(nn);
188
	  nn = (*_pred)[nn];
189
	}
190
	while (!st.empty()) {
191
	  (*_order)[st.back()] = index++;
192
	  st.pop_back();
193
	}
184
        std::vector<Node> st;
185
        Node nn = n;
186
        while ((*_order)[nn] == -1) {
187
          st.push_back(nn);
188
          nn = (*_pred)[nn];
189
        }
190
        while (!st.empty()) {
191
          (*_order)[st.back()] = index++;
192
          st.pop_back();
193
        }
194 194
      }
195 195
    }
196 196

	
197 197
  public:
198 198

	
199 199
    ///\name Execution Control
200
 
200

	
201 201
    ///@{
202 202

	
203 203
    /// \brief Run the Gomory-Hu algorithm.
204 204
    ///
205 205
    /// This function runs the Gomory-Hu algorithm.
206 206
    void run() {
207 207
      init();
208 208
      start();
209 209
    }
210
    
210

	
211 211
    /// @}
212 212

	
213 213
    ///\name Query Functions
214 214
    ///The results of the algorithm can be obtained using these
215 215
    ///functions.\n
216 216
    ///\ref run() should be called before using them.\n
217 217
    ///See also \ref MinCutNodeIt and \ref MinCutEdgeIt.
218 218

	
219 219
    ///@{
220 220

	
221 221
    /// \brief Return the predecessor node in the Gomory-Hu tree.
222 222
    ///
223 223
    /// This function returns the predecessor node of the given node
224 224
    /// in the Gomory-Hu tree.
225 225
    /// If \c node is the root of the tree, then it returns \c INVALID.
226 226
    ///
227 227
    /// \pre \ref run() must be called before using this function.
228 228
    Node predNode(const Node& node) const {
229 229
      return (*_pred)[node];
230 230
    }
231 231

	
232 232
    /// \brief Return the weight of the predecessor edge in the
233 233
    /// Gomory-Hu tree.
234 234
    ///
235
    /// This function returns the weight of the predecessor edge of the 
235
    /// This function returns the weight of the predecessor edge of the
236 236
    /// given node in the Gomory-Hu tree.
237 237
    /// If \c node is the root of the tree, the result is undefined.
238 238
    ///
239 239
    /// \pre \ref run() must be called before using this function.
240 240
    Value predValue(const Node& node) const {
241 241
      return (*_weight)[node];
242 242
    }
243 243

	
244 244
    /// \brief Return the distance from the root node in the Gomory-Hu tree.
245 245
    ///
246 246
    /// This function returns the distance of the given node from the root
247 247
    /// node in the Gomory-Hu tree.
248 248
    ///
249 249
    /// \pre \ref run() must be called before using this function.
250 250
    int rootDist(const Node& node) const {
251 251
      return (*_order)[node];
252 252
    }
253 253

	
254 254
    /// \brief Return the minimum cut value between two nodes
255 255
    ///
256 256
    /// This function returns the minimum cut value between the nodes
257
    /// \c s and \c t. 
257
    /// \c s and \c t.
258 258
    /// It finds the nearest common ancestor of the given nodes in the
259 259
    /// Gomory-Hu tree and calculates the minimum weight edge on the
260 260
    /// paths to the ancestor.
261 261
    ///
262 262
    /// \pre \ref run() must be called before using this function.
263 263
    Value minCutValue(const Node& s, const Node& t) const {
264 264
      Node sn = s, tn = t;
265 265
      Value value = std::numeric_limits<Value>::max();
266
      
266

	
267 267
      while (sn != tn) {
268
	if ((*_order)[sn] < (*_order)[tn]) {
269
	  if ((*_weight)[tn] <= value) value = (*_weight)[tn];
270
	  tn = (*_pred)[tn];
271
	} else {
272
	  if ((*_weight)[sn] <= value) value = (*_weight)[sn];
273
	  sn = (*_pred)[sn];
274
	}
268
        if ((*_order)[sn] < (*_order)[tn]) {
269
          if ((*_weight)[tn] <= value) value = (*_weight)[tn];
270
          tn = (*_pred)[tn];
271
        } else {
272
          if ((*_weight)[sn] <= value) value = (*_weight)[sn];
273
          sn = (*_pred)[sn];
274
        }
275 275
      }
276 276
      return value;
277 277
    }
278 278

	
279 279
    /// \brief Return the minimum cut between two nodes
280 280
    ///
281 281
    /// This function returns the minimum cut between the nodes \c s and \c t
282 282
    /// in the \c cutMap parameter by setting the nodes in the component of
283 283
    /// \c s to \c true and the other nodes to \c false.
284 284
    ///
285 285
    /// For higher level interfaces see MinCutNodeIt and MinCutEdgeIt.
286 286
    ///
287 287
    /// \param s The base node.
288 288
    /// \param t The node you want to separate from node \c s.
289 289
    /// \param cutMap The cut will be returned in this map.
290 290
    /// It must be a \c bool (or convertible) \ref concepts::ReadWriteMap
291 291
    /// "ReadWriteMap" on the graph nodes.
292 292
    ///
293 293
    /// \return The value of the minimum cut between \c s and \c t.
294 294
    ///
295 295
    /// \pre \ref run() must be called before using this function.
296 296
    template <typename CutMap>
297
    Value minCutMap(const Node& s, ///< 
297
    Value minCutMap(const Node& s, ///<
298 298
                    const Node& t,
299
                    ///< 
299
                    ///<
300 300
                    CutMap& cutMap
301
                    ///< 
301
                    ///<
302 302
                    ) const {
303 303
      Node sn = s, tn = t;
304 304
      bool s_root=false;
305 305
      Node rn = INVALID;
306 306
      Value value = std::numeric_limits<Value>::max();
307
      
307

	
308 308
      while (sn != tn) {
309
	if ((*_order)[sn] < (*_order)[tn]) {
310
	  if ((*_weight)[tn] <= value) {
311
	    rn = tn;
309
        if ((*_order)[sn] < (*_order)[tn]) {
310
          if ((*_weight)[tn] <= value) {
311
            rn = tn;
312 312
            s_root = false;
313
	    value = (*_weight)[tn];
314
	  }
315
	  tn = (*_pred)[tn];
316
	} else {
317
	  if ((*_weight)[sn] <= value) {
318
	    rn = sn;
313
            value = (*_weight)[tn];
314
          }
315
          tn = (*_pred)[tn];
316
        } else {
317
          if ((*_weight)[sn] <= value) {
318
            rn = sn;
319 319
            s_root = true;
320
	    value = (*_weight)[sn];
321
	  }
322
	  sn = (*_pred)[sn];
323
	}
320
            value = (*_weight)[sn];
321
          }
322
          sn = (*_pred)[sn];
323
        }
324 324
      }
325 325

	
326 326
      typename Graph::template NodeMap<bool> reached(_graph, false);
327 327
      reached[_root] = true;
328 328
      cutMap.set(_root, !s_root);
329 329
      reached[rn] = true;
330 330
      cutMap.set(rn, s_root);
331 331

	
332 332
      std::vector<Node> st;
333 333
      for (NodeIt n(_graph); n != INVALID; ++n) {
334
	st.clear();
334
        st.clear();
335 335
        Node nn = n;
336
	while (!reached[nn]) {
337
	  st.push_back(nn);
338
	  nn = (*_pred)[nn];
339
	}
340
	while (!st.empty()) {
341
	  cutMap.set(st.back(), cutMap[nn]);
342
	  st.pop_back();
343
	}
336
        while (!reached[nn]) {
337
          st.push_back(nn);
338
          nn = (*_pred)[nn];
339
        }
340
        while (!st.empty()) {
341
          cutMap.set(st.back(), cutMap[nn]);
342
          st.pop_back();
343
        }
344 344
      }
345
      
345

	
346 346
      return value;
347 347
    }
348 348

	
349 349
    ///@}
350 350

	
351 351
    friend class MinCutNodeIt;
352 352

	
353 353
    /// Iterate on the nodes of a minimum cut
354
    
354

	
355 355
    /// This iterator class lists the nodes of a minimum cut found by
356 356
    /// GomoryHu. Before using it, you must allocate a GomoryHu class
357 357
    /// and call its \ref GomoryHu::run() "run()" method.
358 358
    ///
359 359
    /// This example counts the nodes in the minimum cut separating \c s from
360 360
    /// \c t.
361 361
    /// \code
362 362
    /// GomoruHu<Graph> gom(g, capacities);
363 363
    /// gom.run();
364 364
    /// int cnt=0;
365 365
    /// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
366 366
    /// \endcode
367 367
    class MinCutNodeIt
368 368
    {
369 369
      bool _side;
370 370
      typename Graph::NodeIt _node_it;
371 371
      typename Graph::template NodeMap<bool> _cut;
372 372
    public:
373 373
      /// Constructor
374 374

	
375 375
      /// Constructor.
376 376
      ///
377 377
      MinCutNodeIt(GomoryHu const &gomory,
378 378
                   ///< The GomoryHu class. You must call its
... ...
@@ -423,86 +423,86 @@
423 423
      bool operator!=(Invalid) { return _node_it!=INVALID; }
424 424
      /// Next node
425 425

	
426 426
      /// Next node.
427 427
      ///
428 428
      MinCutNodeIt &operator++()
429 429
      {
430 430
        for(++_node_it;_node_it!=INVALID&&_cut[_node_it]!=_side;++_node_it) {}
431 431
        return *this;
432 432
      }
433 433
      /// Postfix incrementation
434 434

	
435 435
      /// Postfix incrementation.
436 436
      ///
437 437
      /// \warning This incrementation
438 438
      /// returns a \c Node, not a \c MinCutNodeIt, as one may
439 439
      /// expect.
440 440
      typename Graph::Node operator++(int)
441 441
      {
442 442
        typename Graph::Node n=*this;
443 443
        ++(*this);
444 444
        return n;
445 445
      }
446 446
    };
447
    
447

	
448 448
    friend class MinCutEdgeIt;
449
    
449

	
450 450
    /// Iterate on the edges of a minimum cut
451
    
451

	
452 452
    /// This iterator class lists the edges of a minimum cut found by
453 453
    /// GomoryHu. Before using it, you must allocate a GomoryHu class
454 454
    /// and call its \ref GomoryHu::run() "run()" method.
455 455
    ///
456 456
    /// This example computes the value of the minimum cut separating \c s from
457 457
    /// \c t.
458 458
    /// \code
459 459
    /// GomoruHu<Graph> gom(g, capacities);
460 460
    /// gom.run();
461 461
    /// int value=0;
462 462
    /// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
463 463
    ///   value+=capacities[e];
464 464
    /// \endcode
465 465
    /// The result will be the same as the value returned by
466 466
    /// \ref GomoryHu::minCutValue() "gom.minCutValue(s,t)".
467 467
    class MinCutEdgeIt
468 468
    {
469 469
      bool _side;
470 470
      const Graph &_graph;
471 471
      typename Graph::NodeIt _node_it;
472 472
      typename Graph::OutArcIt _arc_it;
473 473
      typename Graph::template NodeMap<bool> _cut;
474 474
      void step()
475 475
      {
476 476
        ++_arc_it;
477 477
        while(_node_it!=INVALID && _arc_it==INVALID)
478 478
          {
479 479
            for(++_node_it;_node_it!=INVALID&&!_cut[_node_it];++_node_it) {}
480 480
            if(_node_it!=INVALID)
481 481
              _arc_it=typename Graph::OutArcIt(_graph,_node_it);
482 482
          }
483 483
      }
484
      
484

	
485 485
    public:
486 486
      /// Constructor
487 487

	
488 488
      /// Constructor.
489 489
      ///
490 490
      MinCutEdgeIt(GomoryHu const &gomory,
491 491
                   ///< The GomoryHu class. You must call its
492 492
                   ///  run() method
493 493
                   ///  before initializing this iterator.
494 494
                   const Node& s,  ///< The base node.
495 495
                   const Node& t,
496 496
                   ///< The node you want to separate from node \c s.
497 497
                   bool side=true
498 498
                   ///< If it is \c true (default) then the listed arcs
499 499
                   ///  will be oriented from the
500 500
                   ///  nodes of the component containing \c s,
501 501
                   ///  otherwise they will be oriented in the opposite
502 502
                   ///  direction.
503 503
                   )
504 504
        : _graph(gomory._graph), _cut(_graph)
505 505
      {
506 506
        gomory.minCutMap(s,t,_cut);
507 507
        if(!side)
508 508
          for(typename Graph::NodeIt n(_graph);n!=INVALID;++n)
... ...
@@ -529,42 +529,42 @@
529 529
      {
530 530
        return _arc_it;
531 531
      }
532 532
      /// Conversion to \c Edge
533 533

	
534 534
      /// Conversion to \c Edge.
535 535
      ///
536 536
      operator typename Graph::Edge() const
537 537
      {
538 538
        return _arc_it;
539 539
      }
540 540
      bool operator==(Invalid) { return _node_it==INVALID; }
541 541
      bool operator!=(Invalid) { return _node_it!=INVALID; }
542 542
      /// Next edge
543 543

	
544 544
      /// Next edge.
545 545
      ///
546 546
      MinCutEdgeIt &operator++()
547 547
      {
548 548
        step();
549 549
        while(_arc_it!=INVALID && _cut[_graph.target(_arc_it)]) step();
550 550
        return *this;
551 551
      }
552 552
      /// Postfix incrementation
553
      
553

	
554 554
      /// Postfix incrementation.
555 555
      ///
556 556
      /// \warning This incrementation
557 557
      /// returns an \c Arc, not a \c MinCutEdgeIt, as one may expect.
558 558
      typename Graph::Arc operator++(int)
559 559
      {
560 560
        typename Graph::Arc e=*this;
561 561
        ++(*this);
562 562
        return e;
563 563
      }
564 564
    };
565 565

	
566 566
  };
567 567

	
568 568
}
569 569

	
570 570
#endif
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_GRAPH_TO_EPS_H
20 20
#define LEMON_GRAPH_TO_EPS_H
21 21

	
22 22
#include<iostream>
23 23
#include<fstream>
24 24
#include<sstream>
25 25
#include<algorithm>
26 26
#include<vector>
27 27

	
28 28
#ifndef WIN32
29 29
#include<sys/time.h>
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_HAO_ORLIN_H
20 20
#define LEMON_HAO_ORLIN_H
21 21

	
22 22
#include <vector>
23 23
#include <list>
24 24
#include <limits>
25 25

	
26 26
#include <lemon/maps.h>
27 27
#include <lemon/core.h>
28 28
#include <lemon/tolerance.h>
29 29

	
30 30
/// \file
31 31
/// \ingroup min_cut
32 32
/// \brief Implementation of the Hao-Orlin algorithm.
33 33
///
34
/// Implementation of the Hao-Orlin algorithm for finding a minimum cut 
34
/// Implementation of the Hao-Orlin algorithm for finding a minimum cut
35 35
/// in a digraph.
36 36

	
37 37
namespace lemon {
38 38

	
39 39
  /// \ingroup min_cut
40 40
  ///
41 41
  /// \brief Hao-Orlin algorithm for finding a minimum cut in a digraph.
42 42
  ///
43 43
  /// This class implements the Hao-Orlin algorithm for finding a minimum
44
  /// value cut in a directed graph \f$D=(V,A)\f$. 
44
  /// value cut in a directed graph \f$D=(V,A)\f$.
45 45
  /// It takes a fixed node \f$ source \in V \f$ and
46 46
  /// consists of two phases: in the first phase it determines a
47 47
  /// minimum cut with \f$ source \f$ on the source-side (i.e. a set
48 48
  /// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal outgoing
49 49
  /// capacity) and in the second phase it determines a minimum cut
50 50
  /// with \f$ source \f$ on the sink-side (i.e. a set
51 51
  /// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal outgoing
52 52
  /// capacity). Obviously, the smaller of these two cuts will be a
53 53
  /// minimum cut of \f$ D \f$. The algorithm is a modified
54 54
  /// preflow push-relabel algorithm. Our implementation calculates
55 55
  /// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the
56 56
  /// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The
57 57
  /// purpose of such algorithm is e.g. testing network reliability.
58 58
  ///
59 59
  /// For an undirected graph you can run just the first phase of the
60 60
  /// algorithm or you can use the algorithm of Nagamochi and Ibaraki,
61
  /// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$ 
61
  /// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$
62 62
  /// time. It is implemented in the NagamochiIbaraki algorithm class.
63 63
  ///
64 64
  /// \tparam GR The type of the digraph the algorithm runs on.
65 65
  /// \tparam CAP The type of the arc map containing the capacities,
66 66
  /// which can be any numreric type. The default map type is
67 67
  /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
68 68
  /// \tparam TOL Tolerance class for handling inexact computations. The
69 69
  /// default tolerance type is \ref Tolerance "Tolerance<CAP::Value>".
70 70
#ifdef DOXYGEN
71 71
  template <typename GR, typename CAP, typename TOL>
72 72
#else
73 73
  template <typename GR,
74 74
            typename CAP = typename GR::template ArcMap<int>,
75 75
            typename TOL = Tolerance<typename CAP::Value> >
76 76
#endif
77 77
  class HaoOrlin {
78 78
  public:
79
   
79

	
80 80
    /// The digraph type of the algorithm
81 81
    typedef GR Digraph;
82 82
    /// The capacity map type of the algorithm
83 83
    typedef CAP CapacityMap;
84 84
    /// The tolerance type of the algorithm
85 85
    typedef TOL Tolerance;
86 86

	
87 87
  private:
88 88

	
89 89
    typedef typename CapacityMap::Value Value;
90 90

	
91 91
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
92 92

	
93 93
    const Digraph& _graph;
94 94
    const CapacityMap* _capacity;
95 95

	
96 96
    typedef typename Digraph::template ArcMap<Value> FlowMap;
97 97
    FlowMap* _flow;
98 98

	
99 99
    Node _source;
100 100

	
101 101
    int _node_num;
102 102

	
103 103
    // Bucketing structure
... ...
@@ -826,49 +826,49 @@
826 826

	
827 827
    /// \name Execution Control
828 828
    /// The simplest way to execute the algorithm is to use
829 829
    /// one of the member functions called \ref run().
830 830
    /// \n
831 831
    /// If you need better control on the execution,
832 832
    /// you have to call one of the \ref init() functions first, then
833 833
    /// \ref calculateOut() and/or \ref calculateIn().
834 834

	
835 835
    /// @{
836 836

	
837 837
    /// \brief Initialize the internal data structures.
838 838
    ///
839 839
    /// This function initializes the internal data structures. It creates
840 840
    /// the maps and some bucket structures for the algorithm.
841 841
    /// The first node is used as the source node for the push-relabel
842 842
    /// algorithm.
843 843
    void init() {
844 844
      init(NodeIt(_graph));
845 845
    }
846 846

	
847 847
    /// \brief Initialize the internal data structures.
848 848
    ///
849 849
    /// This function initializes the internal data structures. It creates
850
    /// the maps and some bucket structures for the algorithm. 
850
    /// the maps and some bucket structures for the algorithm.
851 851
    /// The given node is used as the source node for the push-relabel
852 852
    /// algorithm.
853 853
    void init(const Node& source) {
854 854
      _source = source;
855 855

	
856 856
      _node_num = countNodes(_graph);
857 857

	
858 858
      _first.resize(_node_num);
859 859
      _last.resize(_node_num);
860 860

	
861 861
      _dormant.resize(_node_num);
862 862

	
863 863
      if (!_flow) {
864 864
        _flow = new FlowMap(_graph);
865 865
      }
866 866
      if (!_next) {
867 867
        _next = new typename Digraph::template NodeMap<Node>(_graph);
868 868
      }
869 869
      if (!_prev) {
870 870
        _prev = new typename Digraph::template NodeMap<Node>(_graph);
871 871
      }
872 872
      if (!_active) {
873 873
        _active = new typename Digraph::template NodeMap<bool>(_graph);
874 874
      }
... ...
@@ -906,83 +906,83 @@
906 906
    ///
907 907
    /// This function calculates a minimum cut with \f$ source \f$ on the
908 908
    /// sink-side (i.e. a set \f$ X\subsetneq V \f$ with
909 909
    /// \f$ source \notin X \f$ and minimal outgoing capacity).
910 910
    ///
911 911
    /// \pre \ref init() must be called before using this function.
912 912
    void calculateIn() {
913 913
      findMinCutIn();
914 914
    }
915 915

	
916 916

	
917 917
    /// \brief Run the algorithm.
918 918
    ///
919 919
    /// This function runs the algorithm. It finds nodes \c source and
920 920
    /// \c target arbitrarily and then calls \ref init(), \ref calculateOut()
921 921
    /// and \ref calculateIn().
922 922
    void run() {
923 923
      init();
924 924
      calculateOut();
925 925
      calculateIn();
926 926
    }
927 927

	
928 928
    /// \brief Run the algorithm.
929 929
    ///
930
    /// This function runs the algorithm. It uses the given \c source node, 
930
    /// This function runs the algorithm. It uses the given \c source node,
931 931
    /// finds a proper \c target node and then calls the \ref init(),
932 932
    /// \ref calculateOut() and \ref calculateIn().
933 933
    void run(const Node& s) {
934 934
      init(s);
935 935
      calculateOut();
936 936
      calculateIn();
937 937
    }
938 938

	
939 939
    /// @}
940 940

	
941 941
    /// \name Query Functions
942 942
    /// The result of the %HaoOrlin algorithm
943 943
    /// can be obtained using these functions.\n
944
    /// \ref run(), \ref calculateOut() or \ref calculateIn() 
944
    /// \ref run(), \ref calculateOut() or \ref calculateIn()
945 945
    /// should be called before using them.
946 946

	
947 947
    /// @{
948 948

	
949 949
    /// \brief Return the value of the minimum cut.
950 950
    ///
951 951
    /// This function returns the value of the minimum cut.
952 952
    ///
953
    /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 
953
    /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
954 954
    /// must be called before using this function.
955 955
    Value minCutValue() const {
956 956
      return _min_cut;
957 957
    }
958 958

	
959 959

	
960 960
    /// \brief Return a minimum cut.
961 961
    ///
962 962
    /// This function sets \c cutMap to the characteristic vector of a
963 963
    /// minimum value cut: it will give a non-empty set \f$ X\subsetneq V \f$
964 964
    /// with minimal outgoing capacity (i.e. \c cutMap will be \c true exactly
965 965
    /// for the nodes of \f$ X \f$).
966 966
    ///
967 967
    /// \param cutMap A \ref concepts::WriteMap "writable" node map with
968 968
    /// \c bool (or convertible) value type.
969 969
    ///
970 970
    /// \return The value of the minimum cut.
971 971
    ///
972
    /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 
972
    /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
973 973
    /// must be called before using this function.
974 974
    template <typename CutMap>
975 975
    Value minCutMap(CutMap& cutMap) const {
976 976
      for (NodeIt it(_graph); it != INVALID; ++it) {
977 977
        cutMap.set(it, (*_min_cut_map)[it]);
978 978
      }
979 979
      return _min_cut;
980 980
    }
981 981

	
982 982
    /// @}
983 983

	
984 984
  }; //class HaoOrlin
985 985

	
986 986
} //namespace lemon
987 987

	
988 988
#endif //LEMON_HAO_ORLIN_H
Ignore white space 6 line context
... ...
@@ -541,49 +541,49 @@
541 541
        delete it->second;
542 542
      }
543 543

	
544 544
      for (typename ArcMaps::iterator it = _arc_maps.begin();
545 545
           it != _arc_maps.end(); ++it) {
546 546
        delete it->second;
547 547
      }
548 548

	
549 549
      for (typename Attributes::iterator it = _attributes.begin();
550 550
           it != _attributes.end(); ++it) {
551 551
        delete it->second;
552 552
      }
553 553

	
554 554
      if (local_is) {
555 555
        delete _is;
556 556
      }
557 557

	
558 558
    }
559 559

	
560 560
  private:
561 561

	
562 562
    template <typename TDGR>
563 563
    friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is);
564 564
    template <typename TDGR>
565
    friend DigraphReader<TDGR> digraphReader(TDGR& digraph, 
565
    friend DigraphReader<TDGR> digraphReader(TDGR& digraph,
566 566
                                             const std::string& fn);
567 567
    template <typename TDGR>
568 568
    friend DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn);
569 569

	
570 570
    DigraphReader(DigraphReader& other)
571 571
      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
572 572
        _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
573 573
        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
574 574

	
575 575
      other._is = 0;
576 576
      other.local_is = false;
577 577

	
578 578
      _node_index.swap(other._node_index);
579 579
      _arc_index.swap(other._arc_index);
580 580

	
581 581
      _node_maps.swap(other._node_maps);
582 582
      _arc_maps.swap(other._arc_maps);
583 583
      _attributes.swap(other._attributes);
584 584

	
585 585
      _nodes_caption = other._nodes_caption;
586 586
      _arcs_caption = other._arcs_caption;
587 587
      _attributes_caption = other._attributes_caption;
588 588

	
589 589
    }
... ...
@@ -1173,56 +1173,56 @@
1173 1173
        } catch (FormatError& error) {
1174 1174
          error.line(line_num);
1175 1175
          error.file(_filename);
1176 1176
          throw;
1177 1177
        }
1178 1178
      }
1179 1179

	
1180 1180
      if (!nodes_done) {
1181 1181
        throw FormatError("Section @nodes not found");
1182 1182
      }
1183 1183

	
1184 1184
      if (!arcs_done) {
1185 1185
        throw FormatError("Section @arcs not found");
1186 1186
      }
1187 1187

	
1188 1188
      if (!attributes_done && !_attributes.empty()) {
1189 1189
        throw FormatError("Section @attributes not found");
1190 1190
      }
1191 1191

	
1192 1192
    }
1193 1193

	
1194 1194
    /// @}
1195 1195

	
1196 1196
  };
1197
  
1197

	
1198 1198
  /// \ingroup lemon_io
1199 1199
  ///
1200 1200
  /// \brief Return a \ref DigraphReader class
1201 1201
  ///
1202 1202
  /// This function just returns a \ref DigraphReader class.
1203 1203
  ///
1204
  /// With this function a digraph can be read from an 
1204
  /// With this function a digraph can be read from an
1205 1205
  /// \ref lgf-format "LGF" file or input stream with several maps and
1206 1206
  /// attributes. For example, there is network flow problem on a
1207 1207
  /// digraph, i.e. a digraph with a \e capacity map on the arcs and
1208 1208
  /// \e source and \e target nodes. This digraph can be read with the
1209 1209
  /// following code:
1210 1210
  ///
1211 1211
  ///\code
1212 1212
  ///ListDigraph digraph;
1213 1213
  ///ListDigraph::ArcMap<int> cm(digraph);
1214 1214
  ///ListDigraph::Node src, trg;
1215 1215
  ///digraphReader(digraph, std::cin).
1216 1216
  ///  arcMap("capacity", cap).
1217 1217
  ///  node("source", src).
1218 1218
  ///  node("target", trg).
1219 1219
  ///  run();
1220 1220
  ///\endcode
1221 1221
  ///
1222 1222
  /// For a complete documentation, please see the \ref DigraphReader
1223 1223
  /// class documentation.
1224 1224
  /// \warning Don't forget to put the \ref DigraphReader::run() "run()"
1225 1225
  /// to the end of the parameter list.
1226 1226
  /// \relates DigraphReader
1227 1227
  /// \sa digraphReader(TDGR& digraph, const std::string& fn)
1228 1228
  /// \sa digraphReader(TDGR& digraph, const char* fn)
... ...
@@ -1235,49 +1235,49 @@
1235 1235
  /// \brief Return a \ref DigraphReader class
1236 1236
  ///
1237 1237
  /// This function just returns a \ref DigraphReader class.
1238 1238
  /// \relates DigraphReader
1239 1239
  /// \sa digraphReader(TDGR& digraph, std::istream& is)
1240 1240
  template <typename TDGR>
1241 1241
  DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn) {
1242 1242
    DigraphReader<TDGR> tmp(digraph, fn);
1243 1243
    return tmp;
1244 1244
  }
1245 1245

	
1246 1246
  /// \brief Return a \ref DigraphReader class
1247 1247
  ///
1248 1248
  /// This function just returns a \ref DigraphReader class.
1249 1249
  /// \relates DigraphReader
1250 1250
  /// \sa digraphReader(TDGR& digraph, std::istream& is)
1251 1251
  template <typename TDGR>
1252 1252
  DigraphReader<TDGR> digraphReader(TDGR& digraph, const char* fn) {
1253 1253
    DigraphReader<TDGR> tmp(digraph, fn);
1254 1254
    return tmp;
1255 1255
  }
1256 1256

	
1257 1257
  template <typename GR>
1258 1258
  class GraphReader;
1259
 
1259

	
1260 1260
  template <typename TGR>
1261 1261
  GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin);
1262 1262
  template <typename TGR>
1263 1263
  GraphReader<TGR> graphReader(TGR& graph, const std::string& fn);
1264 1264
  template <typename TGR>
1265 1265
  GraphReader<TGR> graphReader(TGR& graph, const char *fn);
1266 1266

	
1267 1267
  /// \ingroup lemon_io
1268 1268
  ///
1269 1269
  /// \brief \ref lgf-format "LGF" reader for undirected graphs
1270 1270
  ///
1271 1271
  /// This utility reads an \ref lgf-format "LGF" file.
1272 1272
  ///
1273 1273
  /// It can be used almost the same way as \c DigraphReader.
1274 1274
  /// The only difference is that this class can handle edges and
1275 1275
  /// edge maps as well as arcs and arc maps.
1276 1276
  ///
1277 1277
  /// The columns in the \c \@edges (or \c \@arcs) section are the
1278 1278
  /// edge maps. However, if there are two maps with the same name
1279 1279
  /// prefixed with \c '+' and \c '-', then these can be read into an
1280 1280
  /// arc map.  Similarly, an attribute can be read into an arc, if
1281 1281
  /// it's value is an edge label prefixed with \c '+' or \c '-'.
1282 1282
  template <typename GR>
1283 1283
  class GraphReader {
... ...
@@ -1372,49 +1372,49 @@
1372 1372
           it != _node_maps.end(); ++it) {
1373 1373
        delete it->second;
1374 1374
      }
1375 1375

	
1376 1376
      for (typename EdgeMaps::iterator it = _edge_maps.begin();
1377 1377
           it != _edge_maps.end(); ++it) {
1378 1378
        delete it->second;
1379 1379
      }
1380 1380

	
1381 1381
      for (typename Attributes::iterator it = _attributes.begin();
1382 1382
           it != _attributes.end(); ++it) {
1383 1383
        delete it->second;
1384 1384
      }
1385 1385

	
1386 1386
      if (local_is) {
1387 1387
        delete _is;
1388 1388
      }
1389 1389

	
1390 1390
    }
1391 1391

	
1392 1392
  private:
1393 1393
    template <typename TGR>
1394 1394
    friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is);
1395 1395
    template <typename TGR>
1396
    friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); 
1396
    friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn);
1397 1397
    template <typename TGR>
1398 1398
    friend GraphReader<TGR> graphReader(TGR& graph, const char *fn);
1399 1399

	
1400 1400
    GraphReader(GraphReader& other)
1401 1401
      : _is(other._is), local_is(other.local_is), _graph(other._graph),
1402 1402
        _use_nodes(other._use_nodes), _use_edges(other._use_edges),
1403 1403
        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1404 1404

	
1405 1405
      other._is = 0;
1406 1406
      other.local_is = false;
1407 1407

	
1408 1408
      _node_index.swap(other._node_index);
1409 1409
      _edge_index.swap(other._edge_index);
1410 1410

	
1411 1411
      _node_maps.swap(other._node_maps);
1412 1412
      _edge_maps.swap(other._edge_maps);
1413 1413
      _attributes.swap(other._attributes);
1414 1414

	
1415 1415
      _nodes_caption = other._nodes_caption;
1416 1416
      _edges_caption = other._edges_caption;
1417 1417
      _attributes_caption = other._attributes_caption;
1418 1418

	
1419 1419
    }
1420 1420

	
... ...
@@ -2056,51 +2056,51 @@
2056 2056
      }
2057 2057

	
2058 2058
      if (!nodes_done) {
2059 2059
        throw FormatError("Section @nodes not found");
2060 2060
      }
2061 2061

	
2062 2062
      if (!edges_done) {
2063 2063
        throw FormatError("Section @edges not found");
2064 2064
      }
2065 2065

	
2066 2066
      if (!attributes_done && !_attributes.empty()) {
2067 2067
        throw FormatError("Section @attributes not found");
2068 2068
      }
2069 2069

	
2070 2070
    }
2071 2071

	
2072 2072
    /// @}
2073 2073

	
2074 2074
  };
2075 2075

	
2076 2076
  /// \ingroup lemon_io
2077 2077
  ///
2078 2078
  /// \brief Return a \ref GraphReader class
2079 2079
  ///
2080
  /// This function just returns a \ref GraphReader class. 
2080
  /// This function just returns a \ref GraphReader class.
2081 2081
  ///
2082
  /// With this function a graph can be read from an 
2082
  /// With this function a graph can be read from an
2083 2083
  /// \ref lgf-format "LGF" file or input stream with several maps and
2084 2084
  /// attributes. For example, there is weighted matching problem on a
2085 2085
  /// graph, i.e. a graph with a \e weight map on the edges. This
2086 2086
  /// graph can be read with the following code:
2087 2087
  ///
2088 2088
  ///\code
2089 2089
  ///ListGraph graph;
2090 2090
  ///ListGraph::EdgeMap<int> weight(graph);
2091 2091
  ///graphReader(graph, std::cin).
2092 2092
  ///  edgeMap("weight", weight).
2093 2093
  ///  run();
2094 2094
  ///\endcode
2095 2095
  ///
2096 2096
  /// For a complete documentation, please see the \ref GraphReader
2097 2097
  /// class documentation.
2098 2098
  /// \warning Don't forget to put the \ref GraphReader::run() "run()"
2099 2099
  /// to the end of the parameter list.
2100 2100
  /// \relates GraphReader
2101 2101
  /// \sa graphReader(TGR& graph, const std::string& fn)
2102 2102
  /// \sa graphReader(TGR& graph, const char* fn)
2103 2103
  template <typename TGR>
2104 2104
  GraphReader<TGR> graphReader(TGR& graph, std::istream& is) {
2105 2105
    GraphReader<TGR> tmp(graph, is);
2106 2106
    return tmp;
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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 lemon_io
20 20
///\file
21 21
///\brief \ref lgf-format "LEMON Graph Format" writer.
22 22

	
23 23

	
24 24
#ifndef LEMON_LGF_WRITER_H
25 25
#define LEMON_LGF_WRITER_H
26 26

	
27 27
#include <iostream>
28 28
#include <fstream>
29 29
#include <sstream>
... ...
@@ -330,49 +330,49 @@
330 330
    };
331 331

	
332 332
    template <typename Functor>
333 333
    class StreamSection : public Section {
334 334
    private:
335 335

	
336 336
      Functor _functor;
337 337

	
338 338
    public:
339 339

	
340 340
      StreamSection(const Functor& functor) : _functor(functor) {}
341 341
      virtual ~StreamSection() {}
342 342

	
343 343
      virtual void process(std::ostream& os) {
344 344
        _functor(os);
345 345
      }
346 346
    };
347 347

	
348 348
  }
349 349

	
350 350
  template <typename DGR>
351 351
  class DigraphWriter;
352 352

	
353 353
  template <typename TDGR>
354
  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 
354
  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
355 355
                                   std::ostream& os = std::cout);
356 356
  template <typename TDGR>
357 357
  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const std::string& fn);
358 358

	
359 359
  template <typename TDGR>
360 360
  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const char* fn);
361 361

	
362 362

	
363 363
  /// \ingroup lemon_io
364 364
  ///
365 365
  /// \brief \ref lgf-format "LGF" writer for directed graphs
366 366
  ///
367 367
  /// This utility writes an \ref lgf-format "LGF" file.
368 368
  ///
369 369
  /// The writing method does a batch processing. The user creates a
370 370
  /// writer object, then various writing rules can be added to the
371 371
  /// writer, and eventually the writing is executed with the \c run()
372 372
  /// member function. A map writing rule can be added to the writer
373 373
  /// with the \c nodeMap() or \c arcMap() members. An optional
374 374
  /// converter parameter can also be added as a standard functor
375 375
  /// converting from the value type of the map to \c std::string. If it
376 376
  /// is set, it will determine how the value type of the map is written to
377 377
  /// the output stream. If the functor is not set, then a default
378 378
  /// conversion will be used. The \c attribute(), \c node() and \c
... ...
@@ -483,49 +483,49 @@
483 483
    ~DigraphWriter() {
484 484
      for (typename NodeMaps::iterator it = _node_maps.begin();
485 485
           it != _node_maps.end(); ++it) {
486 486
        delete it->second;
487 487
      }
488 488

	
489 489
      for (typename ArcMaps::iterator it = _arc_maps.begin();
490 490
           it != _arc_maps.end(); ++it) {
491 491
        delete it->second;
492 492
      }
493 493

	
494 494
      for (typename Attributes::iterator it = _attributes.begin();
495 495
           it != _attributes.end(); ++it) {
496 496
        delete it->second;
497 497
      }
498 498

	
499 499
      if (local_os) {
500 500
        delete _os;
501 501
      }
502 502
    }
503 503

	
504 504
  private:
505 505

	
506 506
    template <typename TDGR>
507
    friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 
507
    friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
508 508
                                             std::ostream& os);
509 509
    template <typename TDGR>
510 510
    friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
511 511
                                             const std::string& fn);
512 512
    template <typename TDGR>
513 513
    friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
514 514
                                             const char *fn);
515 515

	
516 516
    DigraphWriter(DigraphWriter& other)
517 517
      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
518 518
        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
519 519

	
520 520
      other._os = 0;
521 521
      other.local_os = false;
522 522

	
523 523
      _node_index.swap(other._node_index);
524 524
      _arc_index.swap(other._arc_index);
525 525

	
526 526
      _node_maps.swap(other._node_maps);
527 527
      _arc_maps.swap(other._arc_maps);
528 528
      _attributes.swap(other._attributes);
529 529

	
530 530
      _nodes_caption = other._nodes_caption;
531 531
      _arcs_caption = other._arcs_caption;
... ...
@@ -896,89 +896,89 @@
896 896
        createNodeIndex();
897 897
      }
898 898
      if (!_skip_arcs) {
899 899
        writeArcs();
900 900
      } else {
901 901
        createArcIndex();
902 902
      }
903 903
      writeAttributes();
904 904
    }
905 905

	
906 906
    /// \brief Give back the stream of the writer
907 907
    ///
908 908
    /// Give back the stream of the writer.
909 909
    std::ostream& ostream() {
910 910
      return *_os;
911 911
    }
912 912

	
913 913
    /// @}
914 914
  };
915 915

	
916 916
  /// \ingroup lemon_io
917 917
  ///
918 918
  /// \brief Return a \ref DigraphWriter class
919 919
  ///
920
  /// This function just returns a \ref DigraphWriter class. 
920
  /// This function just returns a \ref DigraphWriter class.
921 921
  ///
922 922
  /// With this function a digraph can be write to a file or output
923 923
  /// stream in \ref lgf-format "LGF" format with several maps and
924 924
  /// attributes. For example, with the following code a network flow
925 925
  /// problem can be written to the standard output, i.e. a digraph
926 926
  /// with a \e capacity map on the arcs and \e source and \e target
927 927
  /// nodes:
928 928
  ///
929 929
  ///\code
930 930
  ///ListDigraph digraph;
931 931
  ///ListDigraph::ArcMap<int> cap(digraph);
932 932
  ///ListDigraph::Node src, trg;
933 933
  ///  // Setting the capacity map and source and target nodes
934 934
  ///digraphWriter(digraph, std::cout).
935 935
  ///  arcMap("capacity", cap).
936 936
  ///  node("source", src).
937 937
  ///  node("target", trg).
938 938
  ///  run();
939 939
  ///\endcode
940 940
  ///
941 941
  /// For a complete documentation, please see the \ref DigraphWriter
942 942
  /// class documentation.
943 943
  /// \warning Don't forget to put the \ref DigraphWriter::run() "run()"
944 944
  /// to the end of the parameter list.
945 945
  /// \relates DigraphWriter
946 946
  /// \sa digraphWriter(const TDGR& digraph, const std::string& fn)
947 947
  /// \sa digraphWriter(const TDGR& digraph, const char* fn)
948 948
  template <typename TDGR>
949 949
  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, std::ostream& os) {
950 950
    DigraphWriter<TDGR> tmp(digraph, os);
951 951
    return tmp;
952 952
  }
953 953

	
954 954
  /// \brief Return a \ref DigraphWriter class
955 955
  ///
956 956
  /// This function just returns a \ref DigraphWriter class.
957 957
  /// \relates DigraphWriter
958 958
  /// \sa digraphWriter(const TDGR& digraph, std::ostream& os)
959 959
  template <typename TDGR>
960
  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 
960
  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
961 961
                                    const std::string& fn) {
962 962
    DigraphWriter<TDGR> tmp(digraph, fn);
963 963
    return tmp;
964 964
  }
965 965

	
966 966
  /// \brief Return a \ref DigraphWriter class
967 967
  ///
968 968
  /// This function just returns a \ref DigraphWriter class.
969 969
  /// \relates DigraphWriter
970 970
  /// \sa digraphWriter(const TDGR& digraph, std::ostream& os)
971 971
  template <typename TDGR>
972 972
  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const char* fn) {
973 973
    DigraphWriter<TDGR> tmp(digraph, fn);
974 974
    return tmp;
975 975
  }
976 976

	
977 977
  template <typename GR>
978 978
  class GraphWriter;
979 979

	
980 980
  template <typename TGR>
981 981
  GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os = std::cout);
982 982
  template <typename TGR>
983 983
  GraphWriter<TGR> graphWriter(const TGR& graph, const std::string& fn);
984 984
  template <typename TGR>
... ...
@@ -1080,53 +1080,53 @@
1080 1080
           it != _node_maps.end(); ++it) {
1081 1081
        delete it->second;
1082 1082
      }
1083 1083

	
1084 1084
      for (typename EdgeMaps::iterator it = _edge_maps.begin();
1085 1085
           it != _edge_maps.end(); ++it) {
1086 1086
        delete it->second;
1087 1087
      }
1088 1088

	
1089 1089
      for (typename Attributes::iterator it = _attributes.begin();
1090 1090
           it != _attributes.end(); ++it) {
1091 1091
        delete it->second;
1092 1092
      }
1093 1093

	
1094 1094
      if (local_os) {
1095 1095
        delete _os;
1096 1096
      }
1097 1097
    }
1098 1098

	
1099 1099
  private:
1100 1100

	
1101 1101
    template <typename TGR>
1102 1102
    friend GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os);
1103 1103
    template <typename TGR>
1104
    friend GraphWriter<TGR> graphWriter(const TGR& graph, 
1104
    friend GraphWriter<TGR> graphWriter(const TGR& graph,
1105 1105
                                        const std::string& fn);
1106 1106
    template <typename TGR>
1107 1107
    friend GraphWriter<TGR> graphWriter(const TGR& graph, const char *fn);
1108
    
1108

	
1109 1109
    GraphWriter(GraphWriter& other)
1110 1110
      : _os(other._os), local_os(other.local_os), _graph(other._graph),
1111 1111
        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1112 1112

	
1113 1113
      other._os = 0;
1114 1114
      other.local_os = false;
1115 1115

	
1116 1116
      _node_index.swap(other._node_index);
1117 1117
      _edge_index.swap(other._edge_index);
1118 1118

	
1119 1119
      _node_maps.swap(other._node_maps);
1120 1120
      _edge_maps.swap(other._edge_maps);
1121 1121
      _attributes.swap(other._attributes);
1122 1122

	
1123 1123
      _nodes_caption = other._nodes_caption;
1124 1124
      _edges_caption = other._edges_caption;
1125 1125
      _attributes_caption = other._attributes_caption;
1126 1126
    }
1127 1127

	
1128 1128
    GraphWriter& operator=(const GraphWriter&);
1129 1129

	
1130 1130
  public:
1131 1131

	
1132 1132
    /// \name Writing Rules
... ...
@@ -1535,49 +1535,49 @@
1535 1535
        createNodeIndex();
1536 1536
      }
1537 1537
      if (!_skip_edges) {
1538 1538
        writeEdges();
1539 1539
      } else {
1540 1540
        createEdgeIndex();
1541 1541
      }
1542 1542
      writeAttributes();
1543 1543
    }
1544 1544

	
1545 1545
    /// \brief Give back the stream of the writer
1546 1546
    ///
1547 1547
    /// Give back the stream of the writer
1548 1548
    std::ostream& ostream() {
1549 1549
      return *_os;
1550 1550
    }
1551 1551

	
1552 1552
    /// @}
1553 1553
  };
1554 1554

	
1555 1555
  /// \ingroup lemon_io
1556 1556
  ///
1557 1557
  /// \brief Return a \ref GraphWriter class
1558 1558
  ///
1559
  /// This function just returns a \ref GraphWriter class. 
1559
  /// This function just returns a \ref GraphWriter class.
1560 1560
  ///
1561 1561
  /// With this function a graph can be write to a file or output
1562 1562
  /// stream in \ref lgf-format "LGF" format with several maps and
1563 1563
  /// attributes. For example, with the following code a weighted
1564 1564
  /// matching problem can be written to the standard output, i.e. a
1565 1565
  /// graph with a \e weight map on the edges:
1566 1566
  ///
1567 1567
  ///\code
1568 1568
  ///ListGraph graph;
1569 1569
  ///ListGraph::EdgeMap<int> weight(graph);
1570 1570
  ///  // Setting the weight map
1571 1571
  ///graphWriter(graph, std::cout).
1572 1572
  ///  edgeMap("weight", weight).
1573 1573
  ///  run();
1574 1574
  ///\endcode
1575 1575
  ///
1576 1576
  /// For a complete documentation, please see the \ref GraphWriter
1577 1577
  /// class documentation.
1578 1578
  /// \warning Don't forget to put the \ref GraphWriter::run() "run()"
1579 1579
  /// to the end of the parameter list.
1580 1580
  /// \relates GraphWriter
1581 1581
  /// \sa graphWriter(const TGR& graph, const std::string& fn)
1582 1582
  /// \sa graphWriter(const TGR& graph, const char* fn)
1583 1583
  template <typename TGR>
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_LP_H
20 20
#define LEMON_LP_H
21 21

	
22 22
#include<lemon/config.h>
23 23

	
24 24

	
25 25
#ifdef LEMON_HAVE_GLPK
26 26
#include <lemon/glpk.h>
27 27
#elif LEMON_HAVE_CPLEX
28 28
#include <lemon/cplex.h>
29 29
#elif LEMON_HAVE_SOPLEX
... ...
@@ -63,31 +63,31 @@
63 63
#define LEMON_DEFAULT_MIP SOLVER
64 64
  ///The default MIP solver.
65 65

	
66 66
  ///The default MIP solver.
67 67
  ///\ingroup lp_group
68 68
  ///
69 69
  ///Currently, it is either \c GlpkMip or \c CplexMip
70 70
  typedef GlpkMip Mip;
71 71
#else
72 72
#ifdef LEMON_HAVE_GLPK
73 73
# define LEMON_DEFAULT_LP GLPK
74 74
  typedef GlpkLp Lp;
75 75
# define LEMON_DEFAULT_MIP GLPK
76 76
  typedef GlpkMip Mip;
77 77
#elif LEMON_HAVE_CPLEX
78 78
# define LEMON_DEFAULT_LP CPLEX
79 79
  typedef CplexLp Lp;
80 80
# define LEMON_DEFAULT_MIP CPLEX
81 81
  typedef CplexMip Mip;
82 82
#elif LEMON_HAVE_SOPLEX
83 83
# define DEFAULT_LP SOPLEX
84 84
  typedef SoplexLp Lp;
85 85
#elif LEMON_HAVE_CLP
86 86
# define DEFAULT_LP CLP
87
  typedef ClpLp Lp;  
87
  typedef ClpLp Lp;
88 88
#endif
89 89
#endif
90 90

	
91 91
} //namespace lemon
92 92

	
93 93
#endif //LEMON_LP_H
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
///\file
20 20
///\brief The implementation of the LP solver interface.
21 21

	
22 22
#include <lemon/lp_base.h>
23 23
namespace lemon {
24 24

	
25 25
  const LpBase::Value LpBase::INF =
26 26
    std::numeric_limits<LpBase::Value>::infinity();
27 27
  const LpBase::Value LpBase::NaN =
28 28
    std::numeric_limits<LpBase::Value>::quiet_NaN();
29 29

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_LP_BASE_H
20 20
#define LEMON_LP_BASE_H
21 21

	
22 22
#include<iostream>
23 23
#include<vector>
24 24
#include<map>
25 25
#include<limits>
26 26
#include<lemon/math.h>
27 27

	
28 28
#include<lemon/error.h>
29 29
#include<lemon/assert.h>
... ...
@@ -61,236 +61,236 @@
61 61
      UNSOLVED = 1
62 62
    };
63 63

	
64 64
    ///Direction of the optimization
65 65
    enum Sense {
66 66
      /// Minimization
67 67
      MIN,
68 68
      /// Maximization
69 69
      MAX
70 70
    };
71 71

	
72 72
    ///Enum for \c messageLevel() parameter
73 73
    enum MessageLevel {
74 74
      /// No output (default value).
75 75
      MESSAGE_NOTHING,
76 76
      /// Error messages only.
77 77
      MESSAGE_ERROR,
78 78
      /// Warnings.
79 79
      MESSAGE_WARNING,
80 80
      /// Normal output.
81 81
      MESSAGE_NORMAL,
82 82
      /// Verbose output.
83 83
      MESSAGE_VERBOSE
84 84
    };
85
    
85

	
86 86

	
87 87
    ///The floating point type used by the solver
88 88
    typedef double Value;
89 89
    ///The infinity constant
90 90
    static const Value INF;
91 91
    ///The not a number constant
92 92
    static const Value NaN;
93 93

	
94 94
    friend class Col;
95 95
    friend class ColIt;
96 96
    friend class Row;
97 97
    friend class RowIt;
98 98

	
99 99
    ///Refer to a column of the LP.
100 100

	
101 101
    ///This type is used to refer to a column of the LP.
102 102
    ///
103 103
    ///Its value remains valid and correct even after the addition or erase of
104 104
    ///other columns.
105 105
    ///
106 106
    ///\note This class is similar to other Item types in LEMON, like
107 107
    ///Node and Arc types in digraph.
108 108
    class Col {
109 109
      friend class LpBase;
110 110
    protected:
111 111
      int _id;
112 112
      explicit Col(int id) : _id(id) {}
113 113
    public:
114 114
      typedef Value ExprValue;
115 115
      typedef True LpCol;
116 116
      /// Default constructor
117
      
117

	
118 118
      /// \warning The default constructor sets the Col to an
119 119
      /// undefined value.
120 120
      Col() {}
121 121
      /// Invalid constructor \& conversion.
122
      
122

	
123 123
      /// This constructor initializes the Col to be invalid.
124
      /// \sa Invalid for more details.      
124
      /// \sa Invalid for more details.
125 125
      Col(const Invalid&) : _id(-1) {}
126 126
      /// Equality operator
127 127

	
128 128
      /// Two \ref Col "Col"s are equal if and only if they point to
129 129
      /// the same LP column or both are invalid.
130 130
      bool operator==(Col c) const  {return _id == c._id;}
131 131
      /// Inequality operator
132 132

	
133 133
      /// \sa operator==(Col c)
134 134
      ///
135 135
      bool operator!=(Col c) const  {return _id != c._id;}
136 136
      /// Artificial ordering operator.
137 137

	
138 138
      /// To allow the use of this object in std::map or similar
139 139
      /// associative container we require this.
140 140
      ///
141 141
      /// \note This operator only have to define some strict ordering of
142 142
      /// the items; this order has nothing to do with the iteration
143 143
      /// ordering of the items.
144 144
      bool operator<(Col c) const  {return _id < c._id;}
145 145
    };
146 146

	
147 147
    ///Iterator for iterate over the columns of an LP problem
148 148

	
149 149
    /// Its usage is quite simple, for example you can count the number
150 150
    /// of columns in an LP \c lp:
151 151
    ///\code
152 152
    /// int count=0;
153 153
    /// for (LpBase::ColIt c(lp); c!=INVALID; ++c) ++count;
154 154
    ///\endcode
155 155
    class ColIt : public Col {
156 156
      const LpBase *_solver;
157 157
    public:
158 158
      /// Default constructor
159
      
159

	
160 160
      /// \warning The default constructor sets the iterator
161 161
      /// to an undefined value.
162 162
      ColIt() {}
163 163
      /// Sets the iterator to the first Col
164
      
164

	
165 165
      /// Sets the iterator to the first Col.
166 166
      ///
167 167
      ColIt(const LpBase &solver) : _solver(&solver)
168 168
      {
169 169
        _solver->cols.firstItem(_id);
170 170
      }
171 171
      /// Invalid constructor \& conversion
172
      
172

	
173 173
      /// Initialize the iterator to be invalid.
174 174
      /// \sa Invalid for more details.
175 175
      ColIt(const Invalid&) : Col(INVALID) {}
176 176
      /// Next column
177
      
177

	
178 178
      /// Assign the iterator to the next column.
179 179
      ///
180 180
      ColIt &operator++()
181 181
      {
182 182
        _solver->cols.nextItem(_id);
183 183
        return *this;
184 184
      }
185 185
    };
186 186

	
187 187
    /// \brief Returns the ID of the column.
188 188
    static int id(const Col& col) { return col._id; }
189 189
    /// \brief Returns the column with the given ID.
190 190
    ///
191 191
    /// \pre The argument should be a valid column ID in the LP problem.
192 192
    static Col colFromId(int id) { return Col(id); }
193 193

	
194 194
    ///Refer to a row of the LP.
195 195

	
196 196
    ///This type is used to refer to a row of the LP.
197 197
    ///
198 198
    ///Its value remains valid and correct even after the addition or erase of
199 199
    ///other rows.
200 200
    ///
201 201
    ///\note This class is similar to other Item types in LEMON, like
202 202
    ///Node and Arc types in digraph.
203 203
    class Row {
204 204
      friend class LpBase;
205 205
    protected:
206 206
      int _id;
207 207
      explicit Row(int id) : _id(id) {}
208 208
    public:
209 209
      typedef Value ExprValue;
210 210
      typedef True LpRow;
211 211
      /// Default constructor
212
      
212

	
213 213
      /// \warning The default constructor sets the Row to an
214 214
      /// undefined value.
215 215
      Row() {}
216 216
      /// Invalid constructor \& conversion.
217
      
217

	
218 218
      /// This constructor initializes the Row to be invalid.
219
      /// \sa Invalid for more details.      
219
      /// \sa Invalid for more details.
220 220
      Row(const Invalid&) : _id(-1) {}
221 221
      /// Equality operator
222 222

	
223 223
      /// Two \ref Row "Row"s are equal if and only if they point to
224 224
      /// the same LP row or both are invalid.
225 225
      bool operator==(Row r) const  {return _id == r._id;}
226 226
      /// Inequality operator
227
      
227

	
228 228
      /// \sa operator==(Row r)
229 229
      ///
230 230
      bool operator!=(Row r) const  {return _id != r._id;}
231 231
      /// Artificial ordering operator.
232 232

	
233 233
      /// To allow the use of this object in std::map or similar
234 234
      /// associative container we require this.
235 235
      ///
236 236
      /// \note This operator only have to define some strict ordering of
237 237
      /// the items; this order has nothing to do with the iteration
238 238
      /// ordering of the items.
239 239
      bool operator<(Row r) const  {return _id < r._id;}
240 240
    };
241 241

	
242 242
    ///Iterator for iterate over the rows of an LP problem
243 243

	
244 244
    /// Its usage is quite simple, for example you can count the number
245 245
    /// of rows in an LP \c lp:
246 246
    ///\code
247 247
    /// int count=0;
248 248
    /// for (LpBase::RowIt c(lp); c!=INVALID; ++c) ++count;
249 249
    ///\endcode
250 250
    class RowIt : public Row {
251 251
      const LpBase *_solver;
252 252
    public:
253 253
      /// Default constructor
254
      
254

	
255 255
      /// \warning The default constructor sets the iterator
256 256
      /// to an undefined value.
257 257
      RowIt() {}
258 258
      /// Sets the iterator to the first Row
259
      
259

	
260 260
      /// Sets the iterator to the first Row.
261 261
      ///
262 262
      RowIt(const LpBase &solver) : _solver(&solver)
263 263
      {
264 264
        _solver->rows.firstItem(_id);
265 265
      }
266 266
      /// Invalid constructor \& conversion
267
      
267

	
268 268
      /// Initialize the iterator to be invalid.
269 269
      /// \sa Invalid for more details.
270 270
      RowIt(const Invalid&) : Row(INVALID) {}
271 271
      /// Next row
272
      
272

	
273 273
      /// Assign the iterator to the next row.
274 274
      ///
275 275
      RowIt &operator++()
276 276
      {
277 277
        _solver->rows.nextItem(_id);
278 278
        return *this;
279 279
      }
280 280
    };
281 281

	
282 282
    /// \brief Returns the ID of the row.
283 283
    static int id(const Row& row) { return row._id; }
284 284
    /// \brief Returns the row with the given ID.
285 285
    ///
286 286
    /// \pre The argument should be a valid row ID in the LP problem.
287 287
    static Row rowFromId(int id) { return Row(id); }
288 288

	
289 289
  public:
290 290

	
291 291
    ///Linear expression of variables and a constant component
292 292

	
293 293
    ///This data structure stores a linear expression of the variables
294 294
    ///(\ref Col "Col"s) and also has a constant component.
295 295
    ///
296 296
    ///There are several ways to access and modify the contents of this
... ...
@@ -326,49 +326,49 @@
326 326
    ///- The constant member can be set and read by dereference
327 327
    ///  operator (unary *)
328 328
    ///
329 329
    ///\code
330 330
    ///*e=12;
331 331
    ///double c=*e;
332 332
    ///\endcode
333 333
    ///
334 334
    ///\sa Constr
335 335
    class Expr {
336 336
      friend class LpBase;
337 337
    public:
338 338
      /// The key type of the expression
339 339
      typedef LpBase::Col Key;
340 340
      /// The value type of the expression
341 341
      typedef LpBase::Value Value;
342 342

	
343 343
    protected:
344 344
      Value const_comp;
345 345
      std::map<int, Value> comps;
346 346

	
347 347
    public:
348 348
      typedef True SolverExpr;
349 349
      /// Default constructor
350
      
350

	
351 351
      /// Construct an empty expression, the coefficients and
352 352
      /// the constant component are initialized to zero.
353 353
      Expr() : const_comp(0) {}
354 354
      /// Construct an expression from a column
355 355

	
356 356
      /// Construct an expression, which has a term with \c c variable
357 357
      /// and 1.0 coefficient.
358 358
      Expr(const Col &c) : const_comp(0) {
359 359
        typedef std::map<int, Value>::value_type pair_type;
360 360
        comps.insert(pair_type(id(c), 1));
361 361
      }
362 362
      /// Construct an expression from a constant
363 363

	
364 364
      /// Construct an expression, which's constant component is \c v.
365 365
      ///
366 366
      Expr(const Value &v) : const_comp(v) {}
367 367
      /// Returns the coefficient of the column
368 368
      Value operator[](const Col& c) const {
369 369
        std::map<int, Value>::const_iterator it=comps.find(id(c));
370 370
        if (it != comps.end()) {
371 371
          return it->second;
372 372
        } else {
373 373
          return 0;
374 374
        }
... ...
@@ -427,125 +427,125 @@
427 427
        for (std::map<int, Value>::const_iterator it=e.comps.begin();
428 428
             it!=e.comps.end(); ++it)
429 429
          comps[it->first]-=it->second;
430 430
        const_comp-=e.const_comp;
431 431
        return *this;
432 432
      }
433 433
      ///Multiply with a constant
434 434
      Expr &operator*=(const Value &v) {
435 435
        for (std::map<int, Value>::iterator it=comps.begin();
436 436
             it!=comps.end(); ++it)
437 437
          it->second*=v;
438 438
        const_comp*=v;
439 439
        return *this;
440 440
      }
441 441
      ///Division with a constant
442 442
      Expr &operator/=(const Value &c) {
443 443
        for (std::map<int, Value>::iterator it=comps.begin();
444 444
             it!=comps.end(); ++it)
445 445
          it->second/=c;
446 446
        const_comp/=c;
447 447
        return *this;
448 448
      }
449 449

	
450 450
      ///Iterator over the expression
451
      
452
      ///The iterator iterates over the terms of the expression. 
453
      /// 
451

	
452
      ///The iterator iterates over the terms of the expression.
453
      ///
454 454
      ///\code
455 455
      ///double s=0;
456 456
      ///for(LpBase::Expr::CoeffIt i(e);i!=INVALID;++i)
457 457
      ///  s+= *i * primal(i);
458 458
      ///\endcode
459 459
      class CoeffIt {
460 460
      private:
461 461

	
462 462
        std::map<int, Value>::iterator _it, _end;
463 463

	
464 464
      public:
465 465

	
466 466
        /// Sets the iterator to the first term
467
        
467

	
468 468
        /// Sets the iterator to the first term of the expression.
469 469
        ///
470 470
        CoeffIt(Expr& e)
471 471
          : _it(e.comps.begin()), _end(e.comps.end()){}
472 472

	
473 473
        /// Convert the iterator to the column of the term
474 474
        operator Col() const {
475 475
          return colFromId(_it->first);
476 476
        }
477 477

	
478 478
        /// Returns the coefficient of the term
479 479
        Value& operator*() { return _it->second; }
480 480

	
481 481
        /// Returns the coefficient of the term
482 482
        const Value& operator*() const { return _it->second; }
483 483
        /// Next term
484
        
484

	
485 485
        /// Assign the iterator to the next term.
486 486
        ///
487 487
        CoeffIt& operator++() { ++_it; return *this; }
488 488

	
489 489
        /// Equality operator
490 490
        bool operator==(Invalid) const { return _it == _end; }
491 491
        /// Inequality operator
492 492
        bool operator!=(Invalid) const { return _it != _end; }
493 493
      };
494 494

	
495 495
      /// Const iterator over the expression
496
      
497
      ///The iterator iterates over the terms of the expression. 
498
      /// 
496

	
497
      ///The iterator iterates over the terms of the expression.
498
      ///
499 499
      ///\code
500 500
      ///double s=0;
501 501
      ///for(LpBase::Expr::ConstCoeffIt i(e);i!=INVALID;++i)
502 502
      ///  s+=*i * primal(i);
503 503
      ///\endcode
504 504
      class ConstCoeffIt {
505 505
      private:
506 506

	
507 507
        std::map<int, Value>::const_iterator _it, _end;
508 508

	
509 509
      public:
510 510

	
511 511
        /// Sets the iterator to the first term
512
        
512

	
513 513
        /// Sets the iterator to the first term of the expression.
514 514
        ///
515 515
        ConstCoeffIt(const Expr& e)
516 516
          : _it(e.comps.begin()), _end(e.comps.end()){}
517 517

	
518 518
        /// Convert the iterator to the column of the term
519 519
        operator Col() const {
520 520
          return colFromId(_it->first);
521 521
        }
522 522

	
523 523
        /// Returns the coefficient of the term
524 524
        const Value& operator*() const { return _it->second; }
525 525

	
526 526
        /// Next term
527
        
527

	
528 528
        /// Assign the iterator to the next term.
529 529
        ///
530 530
        ConstCoeffIt& operator++() { ++_it; return *this; }
531 531

	
532 532
        /// Equality operator
533 533
        bool operator==(Invalid) const { return _it == _end; }
534 534
        /// Inequality operator
535 535
        bool operator!=(Invalid) const { return _it != _end; }
536 536
      };
537 537

	
538 538
    };
539 539

	
540 540
    ///Linear constraint
541 541

	
542 542
    ///This data stucture represents a linear constraint in the LP.
543 543
    ///Basically it is a linear expression with a lower or an upper bound
544 544
    ///(or both). These parts of the constraint can be obtained by the member
545 545
    ///functions \ref expr(), \ref lowerBound() and \ref upperBound(),
546 546
    ///respectively.
547 547
    ///There are two ways to construct a constraint.
548 548
    ///- You can set the linear expression and the bounds directly
549 549
    ///  by the functions above.
550 550
    ///- The operators <tt>\<=</tt>, <tt>==</tt> and  <tt>\>=</tt>
551 551
    ///  are defined between expressions, or even between constraints whenever
... ...
@@ -652,210 +652,210 @@
652 652
    ///are valid \ref DualExpr dual expressions.
653 653
    ///The usual assignment operations are also defined.
654 654
    ///\code
655 655
    ///e=v+w;
656 656
    ///e+=2*v-3.12*(v-w/2);
657 657
    ///e*=3.4;
658 658
    ///e/=5;
659 659
    ///\endcode
660 660
    ///
661 661
    ///\sa Expr
662 662
    class DualExpr {
663 663
      friend class LpBase;
664 664
    public:
665 665
      /// The key type of the expression
666 666
      typedef LpBase::Row Key;
667 667
      /// The value type of the expression
668 668
      typedef LpBase::Value Value;
669 669

	
670 670
    protected:
671 671
      std::map<int, Value> comps;
672 672

	
673 673
    public:
674 674
      typedef True SolverExpr;
675 675
      /// Default constructor
676
      
676

	
677 677
      /// Construct an empty expression, the coefficients are
678 678
      /// initialized to zero.
679 679
      DualExpr() {}
680 680
      /// Construct an expression from a row
681 681

	
682 682
      /// Construct an expression, which has a term with \c r dual
683 683
      /// variable and 1.0 coefficient.
684 684
      DualExpr(const Row &r) {
685 685
        typedef std::map<int, Value>::value_type pair_type;
686 686
        comps.insert(pair_type(id(r), 1));
687 687
      }
688 688
      /// Returns the coefficient of the row
689 689
      Value operator[](const Row& r) const {
690 690
        std::map<int, Value>::const_iterator it = comps.find(id(r));
691 691
        if (it != comps.end()) {
692 692
          return it->second;
693 693
        } else {
694 694
          return 0;
695 695
        }
696 696
      }
697 697
      /// Returns the coefficient of the row
698 698
      Value& operator[](const Row& r) {
699 699
        return comps[id(r)];
700 700
      }
701 701
      /// Sets the coefficient of the row
702 702
      void set(const Row &r, const Value &v) {
703 703
        if (v != 0.0) {
704 704
          typedef std::map<int, Value>::value_type pair_type;
705 705
          comps.insert(pair_type(id(r), v));
706 706
        } else {
707 707
          comps.erase(id(r));
708 708
        }
709 709
      }
710 710
      /// \brief Removes the coefficients which's absolute value does
711
      /// not exceed \c epsilon. 
711
      /// not exceed \c epsilon.
712 712
      void simplify(Value epsilon = 0.0) {
713 713
        std::map<int, Value>::iterator it=comps.begin();
714 714
        while (it != comps.end()) {
715 715
          std::map<int, Value>::iterator jt=it;
716 716
          ++jt;
717 717
          if (std::fabs((*it).second) <= epsilon) comps.erase(it);
718 718
          it=jt;
719 719
        }
720 720
      }
721 721

	
722 722
      void simplify(Value epsilon = 0.0) const {
723 723
        const_cast<DualExpr*>(this)->simplify(epsilon);
724 724
      }
725 725

	
726 726
      ///Sets all coefficients to 0.
727 727
      void clear() {
728 728
        comps.clear();
729 729
      }
730 730
      ///Compound assignment
731 731
      DualExpr &operator+=(const DualExpr &e) {
732 732
        for (std::map<int, Value>::const_iterator it=e.comps.begin();
733 733
             it!=e.comps.end(); ++it)
734 734
          comps[it->first]+=it->second;
735 735
        return *this;
736 736
      }
737 737
      ///Compound assignment
738 738
      DualExpr &operator-=(const DualExpr &e) {
739 739
        for (std::map<int, Value>::const_iterator it=e.comps.begin();
740 740
             it!=e.comps.end(); ++it)
741 741
          comps[it->first]-=it->second;
742 742
        return *this;
743 743
      }
744 744
      ///Multiply with a constant
745 745
      DualExpr &operator*=(const Value &v) {
746 746
        for (std::map<int, Value>::iterator it=comps.begin();
747 747
             it!=comps.end(); ++it)
748 748
          it->second*=v;
749 749
        return *this;
750 750
      }
751 751
      ///Division with a constant
752 752
      DualExpr &operator/=(const Value &v) {
753 753
        for (std::map<int, Value>::iterator it=comps.begin();
754 754
             it!=comps.end(); ++it)
755 755
          it->second/=v;
756 756
        return *this;
757 757
      }
758 758

	
759 759
      ///Iterator over the expression
760
      
761
      ///The iterator iterates over the terms of the expression. 
762
      /// 
760

	
761
      ///The iterator iterates over the terms of the expression.
762
      ///
763 763
      ///\code
764 764
      ///double s=0;
765 765
      ///for(LpBase::DualExpr::CoeffIt i(e);i!=INVALID;++i)
766 766
      ///  s+= *i * dual(i);
767 767
      ///\endcode
768 768
      class CoeffIt {
769 769
      private:
770 770

	
771 771
        std::map<int, Value>::iterator _it, _end;
772 772

	
773 773
      public:
774 774

	
775 775
        /// Sets the iterator to the first term
776
        
776

	
777 777
        /// Sets the iterator to the first term of the expression.
778 778
        ///
779 779
        CoeffIt(DualExpr& e)
780 780
          : _it(e.comps.begin()), _end(e.comps.end()){}
781 781

	
782 782
        /// Convert the iterator to the row of the term
783 783
        operator Row() const {
784 784
          return rowFromId(_it->first);
785 785
        }
786 786

	
787 787
        /// Returns the coefficient of the term
788 788
        Value& operator*() { return _it->second; }
789 789

	
790 790
        /// Returns the coefficient of the term
791 791
        const Value& operator*() const { return _it->second; }
792 792

	
793 793
        /// Next term
794
        
794

	
795 795
        /// Assign the iterator to the next term.
796 796
        ///
797 797
        CoeffIt& operator++() { ++_it; return *this; }
798 798

	
799 799
        /// Equality operator
800 800
        bool operator==(Invalid) const { return _it == _end; }
801 801
        /// Inequality operator
802 802
        bool operator!=(Invalid) const { return _it != _end; }
803 803
      };
804 804

	
805 805
      ///Iterator over the expression
806
      
807
      ///The iterator iterates over the terms of the expression. 
808
      /// 
806

	
807
      ///The iterator iterates over the terms of the expression.
808
      ///
809 809
      ///\code
810 810
      ///double s=0;
811 811
      ///for(LpBase::DualExpr::ConstCoeffIt i(e);i!=INVALID;++i)
812 812
      ///  s+= *i * dual(i);
813 813
      ///\endcode
814 814
      class ConstCoeffIt {
815 815
      private:
816 816

	
817 817
        std::map<int, Value>::const_iterator _it, _end;
818 818

	
819 819
      public:
820 820

	
821 821
        /// Sets the iterator to the first term
822
        
822

	
823 823
        /// Sets the iterator to the first term of the expression.
824 824
        ///
825 825
        ConstCoeffIt(const DualExpr& e)
826 826
          : _it(e.comps.begin()), _end(e.comps.end()){}
827 827

	
828 828
        /// Convert the iterator to the row of the term
829 829
        operator Row() const {
830 830
          return rowFromId(_it->first);
831 831
        }
832 832

	
833 833
        /// Returns the coefficient of the term
834 834
        const Value& operator*() const { return _it->second; }
835 835

	
836 836
        /// Next term
837
        
837

	
838 838
        /// Assign the iterator to the next term.
839 839
        ///
840 840
        ConstCoeffIt& operator++() { ++_it; return *this; }
841 841

	
842 842
        /// Equality operator
843 843
        bool operator==(Invalid) const { return _it == _end; }
844 844
        /// Inequality operator
845 845
        bool operator!=(Invalid) const { return _it != _end; }
846 846
      };
847 847
    };
848 848

	
849 849

	
850 850
  protected:
851 851

	
852 852
    class InsertIterator {
853 853
    private:
854 854

	
855 855
      std::map<int, Value>& _host;
856 856
      const _solver_bits::VarIndex& _index;
857 857

	
858 858
    public:
859 859

	
860 860
      typedef std::output_iterator_tag iterator_category;
861 861
      typedef void difference_type;
... ...
@@ -1782,52 +1782,52 @@
1782 1782
  /// descendants as a concrete implementation, or the \c Lp
1783 1783
  /// default LP solver. However, if you would like to handle LP
1784 1784
  /// solvers as reference or pointer in a generic way, you can use
1785 1785
  /// this class directly.
1786 1786
  class LpSolver : virtual public LpBase {
1787 1787
  public:
1788 1788

	
1789 1789
    /// The problem types for primal and dual problems
1790 1790
    enum ProblemType {
1791 1791
      /// = 0. Feasible solution hasn't been found (but may exist).
1792 1792
      UNDEFINED = 0,
1793 1793
      /// = 1. The problem has no feasible solution.
1794 1794
      INFEASIBLE = 1,
1795 1795
      /// = 2. Feasible solution found.
1796 1796
      FEASIBLE = 2,
1797 1797
      /// = 3. Optimal solution exists and found.
1798 1798
      OPTIMAL = 3,
1799 1799
      /// = 4. The cost function is unbounded.
1800 1800
      UNBOUNDED = 4
1801 1801
    };
1802 1802

	
1803 1803
    ///The basis status of variables
1804 1804
    enum VarStatus {
1805 1805
      /// The variable is in the basis
1806
      BASIC, 
1806
      BASIC,
1807 1807
      /// The variable is free, but not basic
1808 1808
      FREE,
1809
      /// The variable has active lower bound 
1809
      /// The variable has active lower bound
1810 1810
      LOWER,
1811 1811
      /// The variable has active upper bound
1812 1812
      UPPER,
1813 1813
      /// The variable is non-basic and fixed
1814 1814
      FIXED
1815 1815
    };
1816 1816

	
1817 1817
  protected:
1818 1818

	
1819 1819
    virtual SolveExitStatus _solve() = 0;
1820 1820

	
1821 1821
    virtual Value _getPrimal(int i) const = 0;
1822 1822
    virtual Value _getDual(int i) const = 0;
1823 1823

	
1824 1824
    virtual Value _getPrimalRay(int i) const = 0;
1825 1825
    virtual Value _getDualRay(int i) const = 0;
1826 1826

	
1827 1827
    virtual Value _getPrimalValue() const = 0;
1828 1828

	
1829 1829
    virtual VarStatus _getColStatus(int i) const = 0;
1830 1830
    virtual VarStatus _getRowStatus(int i) const = 0;
1831 1831

	
1832 1832
    virtual ProblemType _getPrimalType() const = 0;
1833 1833
    virtual ProblemType _getDualType() const = 0;
... ...
@@ -1864,83 +1864,83 @@
1864 1864
    /// The type of the dual problem
1865 1865
    ProblemType dualType() const {
1866 1866
      return _getDualType();
1867 1867
    }
1868 1868

	
1869 1869
    /// Return the primal value of the column
1870 1870

	
1871 1871
    /// Return the primal value of the column.
1872 1872
    /// \pre The problem is solved.
1873 1873
    Value primal(Col c) const { return _getPrimal(cols(id(c))); }
1874 1874

	
1875 1875
    /// Return the primal value of the expression
1876 1876

	
1877 1877
    /// Return the primal value of the expression, i.e. the dot
1878 1878
    /// product of the primal solution and the expression.
1879 1879
    /// \pre The problem is solved.
1880 1880
    Value primal(const Expr& e) const {
1881 1881
      double res = *e;
1882 1882
      for (Expr::ConstCoeffIt c(e); c != INVALID; ++c) {
1883 1883
        res += *c * primal(c);
1884 1884
      }
1885 1885
      return res;
1886 1886
    }
1887 1887
    /// Returns a component of the primal ray
1888
    
1888

	
1889 1889
    /// The primal ray is solution of the modified primal problem,
1890 1890
    /// where we change each finite bound to 0, and we looking for a
1891 1891
    /// negative objective value in case of minimization, and positive
1892 1892
    /// objective value for maximization. If there is such solution,
1893 1893
    /// that proofs the unsolvability of the dual problem, and if a
1894 1894
    /// feasible primal solution exists, then the unboundness of
1895 1895
    /// primal problem.
1896 1896
    ///
1897 1897
    /// \pre The problem is solved and the dual problem is infeasible.
1898 1898
    /// \note Some solvers does not provide primal ray calculation
1899 1899
    /// functions.
1900 1900
    Value primalRay(Col c) const { return _getPrimalRay(cols(id(c))); }
1901 1901

	
1902 1902
    /// Return the dual value of the row
1903 1903

	
1904 1904
    /// Return the dual value of the row.
1905 1905
    /// \pre The problem is solved.
1906 1906
    Value dual(Row r) const { return _getDual(rows(id(r))); }
1907 1907

	
1908 1908
    /// Return the dual value of the dual expression
1909 1909

	
1910 1910
    /// Return the dual value of the dual expression, i.e. the dot
1911 1911
    /// product of the dual solution and the dual expression.
1912 1912
    /// \pre The problem is solved.
1913 1913
    Value dual(const DualExpr& e) const {
1914 1914
      double res = 0.0;
1915 1915
      for (DualExpr::ConstCoeffIt r(e); r != INVALID; ++r) {
1916 1916
        res += *r * dual(r);
1917 1917
      }
1918 1918
      return res;
1919 1919
    }
1920 1920

	
1921 1921
    /// Returns a component of the dual ray
1922
    
1922

	
1923 1923
    /// The dual ray is solution of the modified primal problem, where
1924 1924
    /// we change each finite bound to 0 (i.e. the objective function
1925 1925
    /// coefficients in the primal problem), and we looking for a
1926 1926
    /// ositive objective value. If there is such solution, that
1927 1927
    /// proofs the unsolvability of the primal problem, and if a
1928 1928
    /// feasible dual solution exists, then the unboundness of
1929 1929
    /// dual problem.
1930 1930
    ///
1931 1931
    /// \pre The problem is solved and the primal problem is infeasible.
1932 1932
    /// \note Some solvers does not provide dual ray calculation
1933 1933
    /// functions.
1934 1934
    Value dualRay(Row r) const { return _getDualRay(rows(id(r))); }
1935 1935

	
1936 1936
    /// Return the basis status of the column
1937 1937

	
1938 1938
    /// \see VarStatus
1939 1939
    VarStatus colStatus(Col c) const { return _getColStatus(cols(id(c))); }
1940 1940

	
1941 1941
    /// Return the basis status of the row
1942 1942

	
1943 1943
    /// \see VarStatus
1944 1944
    VarStatus rowStatus(Row r) const { return _getRowStatus(rows(id(r))); }
1945 1945

	
1946 1946
    ///The value of the objective function
... ...
@@ -2040,49 +2040,49 @@
2040 2040
    /// The type of the MIP problem
2041 2041
    ProblemType type() const {
2042 2042
      return _getType();
2043 2043
    }
2044 2044

	
2045 2045
    /// Return the value of the row in the solution
2046 2046

	
2047 2047
    ///  Return the value of the row in the solution.
2048 2048
    /// \pre The problem is solved.
2049 2049
    Value sol(Col c) const { return _getSol(cols(id(c))); }
2050 2050

	
2051 2051
    /// Return the value of the expression in the solution
2052 2052

	
2053 2053
    /// Return the value of the expression in the solution, i.e. the
2054 2054
    /// dot product of the solution and the expression.
2055 2055
    /// \pre The problem is solved.
2056 2056
    Value sol(const Expr& e) const {
2057 2057
      double res = *e;
2058 2058
      for (Expr::ConstCoeffIt c(e); c != INVALID; ++c) {
2059 2059
        res += *c * sol(c);
2060 2060
      }
2061 2061
      return res;
2062 2062
    }
2063 2063
    ///The value of the objective function
2064
    
2064

	
2065 2065
    ///\return
2066 2066
    ///- \ref INF or -\ref INF means either infeasibility or unboundedness
2067 2067
    /// of the problem, depending on whether we minimize or maximize.
2068 2068
    ///- \ref NaN if no primal solution is found.
2069 2069
    ///- The (finite) objective value if an optimal solution is found.
2070 2070
    Value solValue() const { return _getSolValue()+obj_const_comp;}
2071 2071
    ///@}
2072 2072

	
2073 2073
  protected:
2074 2074

	
2075 2075
    virtual SolveExitStatus _solve() = 0;
2076 2076
    virtual ColTypes _getColType(int col) const = 0;
2077 2077
    virtual void _setColType(int col, ColTypes col_type) = 0;
2078 2078
    virtual ProblemType _getType() const = 0;
2079 2079
    virtual Value _getSol(int i) const = 0;
2080 2080
    virtual Value _getSolValue() const = 0;
2081 2081

	
2082 2082
  };
2083 2083

	
2084 2084

	
2085 2085

	
2086 2086
} //namespace lemon
2087 2087

	
2088 2088
#endif //LEMON_LP_BASE_H
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <lemon/lp_skeleton.h>
20 20

	
21 21
///\file
22 22
///\brief A skeleton file to implement LP solver interfaces
23 23
namespace lemon {
24 24

	
25 25
  int SkeletonSolverBase::_addCol()
26 26
  {
27 27
    return ++col_num;
28 28
  }
29 29

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_LP_SKELETON_H
20 20
#define LEMON_LP_SKELETON_H
21 21

	
22 22
#include <lemon/lp_base.h>
23 23

	
24 24
///\file
25 25
///\brief Skeleton file to implement LP/MIP solver interfaces
26
///  
26
///
27 27
///The classes in this file do nothing, but they can serve as skeletons when
28 28
///implementing an interface to new solvers.
29 29
namespace lemon {
30 30

	
31 31
  ///A skeleton class to implement LP/MIP solver base interface
32
  
32

	
33 33
  ///This class does nothing, but it can serve as a skeleton when
34 34
  ///implementing an interface to new solvers.
35 35
  class SkeletonSolverBase : public virtual LpBase {
36 36
    int col_num,row_num;
37 37

	
38 38
  protected:
39 39

	
40 40
    SkeletonSolverBase()
41 41
      : col_num(-1), row_num(-1) {}
42 42

	
43 43
    /// \e
44 44
    virtual int _addCol();
45 45
    /// \e
46 46
    virtual int _addRow();
47 47
    /// \e
48 48
    virtual void _eraseCol(int i);
49 49
    /// \e
50 50
    virtual void _eraseRow(int i);
51 51

	
52 52
    /// \e
53 53
    virtual void _getColName(int col, std::string& name) const;
54 54
    /// \e
55 55
    virtual void _setColName(int col, const std::string& name);
56 56
    /// \e
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_MAPS_H
20 20
#define LEMON_MAPS_H
21 21

	
22 22
#include <iterator>
23 23
#include <functional>
24 24
#include <vector>
25 25

	
26 26
#include <lemon/core.h>
27 27

	
28 28
///\file
29 29
///\ingroup maps
... ...
@@ -1797,49 +1797,49 @@
1797 1797
  ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
1798 1798
  /// \endcode
1799 1799
  ///
1800 1800
  /// \note The container of the iterator must contain enough space
1801 1801
  /// for the elements or the iterator should be an inserter iterator.
1802 1802
  ///
1803 1803
  /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so
1804 1804
  /// it cannot be used when a readable map is needed, for example as
1805 1805
  /// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms.
1806 1806
  ///
1807 1807
  /// \relates LoggerBoolMap
1808 1808
  template<typename Iterator>
1809 1809
  inline LoggerBoolMap<Iterator> loggerBoolMap(Iterator it) {
1810 1810
    return LoggerBoolMap<Iterator>(it);
1811 1811
  }
1812 1812

	
1813 1813
  /// @}
1814 1814

	
1815 1815
  /// \addtogroup graph_maps
1816 1816
  /// @{
1817 1817

	
1818 1818
  /// \brief Provides an immutable and unique id for each item in a graph.
1819 1819
  ///
1820 1820
  /// IdMap provides a unique and immutable id for each item of the
1821
  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is 
1821
  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
1822 1822
  ///  - \b unique: different items get different ids,
1823 1823
  ///  - \b immutable: the id of an item does not change (even if you
1824 1824
  ///    delete other nodes).
1825 1825
  ///
1826 1826
  /// Using this map you get access (i.e. can read) the inner id values of
1827 1827
  /// the items stored in the graph, which is returned by the \c id()
1828 1828
  /// function of the graph. This map can be inverted with its member
1829 1829
  /// class \c InverseMap or with the \c operator() member.
1830 1830
  ///
1831 1831
  /// \tparam GR The graph type.
1832 1832
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1833 1833
  /// \c GR::Edge).
1834 1834
  ///
1835 1835
  /// \see RangeIdMap
1836 1836
  template <typename GR, typename K>
1837 1837
  class IdMap : public MapBase<K, int> {
1838 1838
  public:
1839 1839
    /// The graph type of IdMap.
1840 1840
    typedef GR Graph;
1841 1841
    typedef GR Digraph;
1842 1842
    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
1843 1843
    typedef K Item;
1844 1844
    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
1845 1845
    typedef K Key;
... ...
@@ -2252,49 +2252,49 @@
2252 2252
    unsigned int size() const {
2253 2253
      return _inv_map.size();
2254 2254
    }
2255 2255

	
2256 2256
    /// \brief Swaps the position of the two items in the map.
2257 2257
    ///
2258 2258
    /// Swaps the position of the two items in the map.
2259 2259
    void swap(const Item& p, const Item& q) {
2260 2260
      int pi = Map::operator[](p);
2261 2261
      int qi = Map::operator[](q);
2262 2262
      Map::set(p, qi);
2263 2263
      _inv_map[qi] = p;
2264 2264
      Map::set(q, pi);
2265 2265
      _inv_map[pi] = q;
2266 2266
    }
2267 2267

	
2268 2268
    /// \brief Gives back the \e RangeId of the item
2269 2269
    ///
2270 2270
    /// Gives back the \e RangeId of the item.
2271 2271
    int operator[](const Item& item) const {
2272 2272
      return Map::operator[](item);
2273 2273
    }
2274 2274

	
2275 2275
    /// \brief Gives back the item belonging to a \e RangeId
2276
    /// 
2276
    ///
2277 2277
    /// Gives back the item belonging to a \e RangeId.
2278 2278
    Item operator()(int id) const {
2279 2279
      return _inv_map[id];
2280 2280
    }
2281 2281

	
2282 2282
  private:
2283 2283

	
2284 2284
    typedef std::vector<Item> Container;
2285 2285
    Container _inv_map;
2286 2286

	
2287 2287
  public:
2288 2288

	
2289 2289
    /// \brief The inverse map type of RangeIdMap.
2290 2290
    ///
2291 2291
    /// The inverse map type of RangeIdMap.
2292 2292
    class InverseMap {
2293 2293
    public:
2294 2294
      /// \brief Constructor
2295 2295
      ///
2296 2296
      /// Constructor of the InverseMap.
2297 2297
      explicit InverseMap(const RangeIdMap& inverted)
2298 2298
        : _inverted(inverted) {}
2299 2299

	
2300 2300

	
... ...
@@ -2478,65 +2478,65 @@
2478 2478
    Value operator[](const Key& key) const {
2479 2479
      return _graph.direct(key, false);
2480 2480
    }
2481 2481

	
2482 2482
  private:
2483 2483
    const GR& _graph;
2484 2484
  };
2485 2485

	
2486 2486
  /// \brief Returns a \c BackwardMap class
2487 2487

	
2488 2488
  /// This function just returns a \c BackwardMap class.
2489 2489
  /// \relates BackwardMap
2490 2490
  template <typename GR>
2491 2491
  inline BackwardMap<GR> backwardMap(const GR& graph) {
2492 2492
    return BackwardMap<GR>(graph);
2493 2493
  }
2494 2494

	
2495 2495
  /// \brief Map of the in-degrees of nodes in a digraph.
2496 2496
  ///
2497 2497
  /// This map returns the in-degree of a node. Once it is constructed,
2498 2498
  /// the degrees are stored in a standard \c NodeMap, so each query is done
2499 2499
  /// in constant time. On the other hand, the values are updated automatically
2500 2500
  /// whenever the digraph changes.
2501 2501
  ///
2502
  /// \warning Besides \c addNode() and \c addArc(), a digraph structure 
2502
  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
2503 2503
  /// may provide alternative ways to modify the digraph.
2504 2504
  /// The correct behavior of InDegMap is not guarantied if these additional
2505 2505
  /// features are used. For example the functions
2506 2506
  /// \ref ListDigraph::changeSource() "changeSource()",
2507 2507
  /// \ref ListDigraph::changeTarget() "changeTarget()" and
2508 2508
  /// \ref ListDigraph::reverseArc() "reverseArc()"
2509 2509
  /// of \ref ListDigraph will \e not update the degree values correctly.
2510 2510
  ///
2511 2511
  /// \sa OutDegMap
2512 2512
  template <typename GR>
2513 2513
  class InDegMap
2514 2514
    : protected ItemSetTraits<GR, typename GR::Arc>
2515 2515
      ::ItemNotifier::ObserverBase {
2516 2516

	
2517 2517
  public:
2518
    
2518

	
2519 2519
    /// The graph type of InDegMap
2520 2520
    typedef GR Graph;
2521 2521
    typedef GR Digraph;
2522 2522
    /// The key type
2523 2523
    typedef typename Digraph::Node Key;
2524 2524
    /// The value type
2525 2525
    typedef int Value;
2526 2526

	
2527 2527
    typedef typename ItemSetTraits<Digraph, typename Digraph::Arc>
2528 2528
    ::ItemNotifier::ObserverBase Parent;
2529 2529

	
2530 2530
  private:
2531 2531

	
2532 2532
    class AutoNodeMap
2533 2533
      : public ItemSetTraits<Digraph, Key>::template Map<int>::Type {
2534 2534
    public:
2535 2535

	
2536 2536
      typedef typename ItemSetTraits<Digraph, Key>::
2537 2537
      template Map<int>::Type Parent;
2538 2538

	
2539 2539
      AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {}
2540 2540

	
2541 2541
      virtual void add(const Key& key) {
2542 2542
        Parent::add(key);
... ...
@@ -2608,49 +2608,49 @@
2608 2608
    virtual void build() {
2609 2609
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
2610 2610
        _deg[it] = countInArcs(_digraph, it);
2611 2611
      }
2612 2612
    }
2613 2613

	
2614 2614
    virtual void clear() {
2615 2615
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
2616 2616
        _deg[it] = 0;
2617 2617
      }
2618 2618
    }
2619 2619
  private:
2620 2620

	
2621 2621
    const Digraph& _digraph;
2622 2622
    AutoNodeMap _deg;
2623 2623
  };
2624 2624

	
2625 2625
  /// \brief Map of the out-degrees of nodes in a digraph.
2626 2626
  ///
2627 2627
  /// This map returns the out-degree of a node. Once it is constructed,
2628 2628
  /// the degrees are stored in a standard \c NodeMap, so each query is done
2629 2629
  /// in constant time. On the other hand, the values are updated automatically
2630 2630
  /// whenever the digraph changes.
2631 2631
  ///
2632
  /// \warning Besides \c addNode() and \c addArc(), a digraph structure 
2632
  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
2633 2633
  /// may provide alternative ways to modify the digraph.
2634 2634
  /// The correct behavior of OutDegMap is not guarantied if these additional
2635 2635
  /// features are used. For example the functions
2636 2636
  /// \ref ListDigraph::changeSource() "changeSource()",
2637 2637
  /// \ref ListDigraph::changeTarget() "changeTarget()" and
2638 2638
  /// \ref ListDigraph::reverseArc() "reverseArc()"
2639 2639
  /// of \ref ListDigraph will \e not update the degree values correctly.
2640 2640
  ///
2641 2641
  /// \sa InDegMap
2642 2642
  template <typename GR>
2643 2643
  class OutDegMap
2644 2644
    : protected ItemSetTraits<GR, typename GR::Arc>
2645 2645
      ::ItemNotifier::ObserverBase {
2646 2646

	
2647 2647
  public:
2648 2648

	
2649 2649
    /// The graph type of OutDegMap
2650 2650
    typedef GR Graph;
2651 2651
    typedef GR Digraph;
2652 2652
    /// The key type
2653 2653
    typedef typename Digraph::Node Key;
2654 2654
    /// The value type
2655 2655
    typedef int Value;
2656 2656

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_MAX_MATCHING_H
20 20
#define LEMON_MAX_MATCHING_H
21 21

	
22 22
#include <vector>
23 23
#include <queue>
24 24
#include <set>
25 25
#include <limits>
26 26

	
27 27
#include <lemon/core.h>
28 28
#include <lemon/unionfind.h>
29 29
#include <lemon/bin_heap.h>
30 30
#include <lemon/maps.h>
31 31

	
32 32
///\ingroup matching
33 33
///\file
34 34
///\brief Maximum matching algorithms in general graphs.
35 35

	
36 36
namespace lemon {
37 37

	
38 38
  /// \ingroup matching
39 39
  ///
40 40
  /// \brief Maximum cardinality matching in general graphs
41 41
  ///
42 42
  /// This class implements Edmonds' alternating forest matching algorithm
43 43
  /// for finding a maximum cardinality matching in a general undirected graph.
44
  /// It can be started from an arbitrary initial matching 
44
  /// It can be started from an arbitrary initial matching
45 45
  /// (the default is the empty one).
46 46
  ///
47 47
  /// The dual solution of the problem is a map of the nodes to
48 48
  /// \ref MaxMatching::Status "Status", having values \c EVEN (or \c D),
49 49
  /// \c ODD (or \c A) and \c MATCHED (or \c C) defining the Gallai-Edmonds
50 50
  /// decomposition of the graph. The nodes in \c EVEN/D induce a subgraph
51 51
  /// with factor-critical components, the nodes in \c ODD/A form the
52 52
  /// canonical barrier, and the nodes in \c MATCHED/C induce a graph having
53 53
  /// a perfect matching. The number of the factor-critical components
54 54
  /// minus the number of barrier nodes is a lower bound on the
55 55
  /// unmatched nodes, and the matching is optimal if and only if this bound is
56 56
  /// tight. This decomposition can be obtained using \ref status() or
57 57
  /// \ref statusMap() after running the algorithm.
58 58
  ///
59 59
  /// \tparam GR The undirected graph type the algorithm runs on.
60 60
  template <typename GR>
61 61
  class MaxMatching {
62 62
  public:
63 63

	
64 64
    /// The graph type of the algorithm
65 65
    typedef GR Graph;
66 66
    /// The type of the matching map
67 67
    typedef typename Graph::template NodeMap<typename Graph::Arc>
68 68
    MatchingMap;
69 69

	
70 70
    ///\brief Status constants for Gallai-Edmonds decomposition.
71 71
    ///
72
    ///These constants are used for indicating the Gallai-Edmonds 
72
    ///These constants are used for indicating the Gallai-Edmonds
73 73
    ///decomposition of a graph. The nodes with status \c EVEN (or \c D)
74 74
    ///induce a subgraph with factor-critical components, the nodes with
75 75
    ///status \c ODD (or \c A) form the canonical barrier, and the nodes
76
    ///with status \c MATCHED (or \c C) induce a subgraph having a 
76
    ///with status \c MATCHED (or \c C) induce a subgraph having a
77 77
    ///perfect matching.
78 78
    enum Status {
79 79
      EVEN = 1,       ///< = 1. (\c D is an alias for \c EVEN.)
80 80
      D = 1,
81 81
      MATCHED = 0,    ///< = 0. (\c C is an alias for \c MATCHED.)
82 82
      C = 0,
83 83
      ODD = -1,       ///< = -1. (\c A is an alias for \c ODD.)
84 84
      A = -1,
85 85
      UNMATCHED = -2  ///< = -2.
86 86
    };
87 87

	
88 88
    /// The type of the status map
89 89
    typedef typename Graph::template NodeMap<Status> StatusMap;
90 90

	
91 91
  private:
92 92

	
93 93
    TEMPLATE_GRAPH_TYPEDEFS(Graph);
94 94

	
95 95
    typedef UnionFindEnum<IntNodeMap> BlossomSet;
96 96
    typedef ExtendFindEnum<IntNodeMap> TreeSet;
97 97
    typedef RangeMap<Node> NodeIntMap;
98 98
    typedef MatchingMap EarMap;
99 99
    typedef std::vector<Node> NodeQueue;
100 100

	
... ...
@@ -491,219 +491,219 @@
491 491
          (*_matching)[v] = _graph.direct(e, false);
492 492
          (*_status)[v] = MATCHED;
493 493
        }
494 494
      }
495 495
      return true;
496 496
    }
497 497

	
498 498
    /// \brief Start Edmonds' algorithm
499 499
    ///
500 500
    /// This function runs the original Edmonds' algorithm.
501 501
    ///
502 502
    /// \pre \ref init(), \ref greedyInit() or \ref matchingInit() must be
503 503
    /// called before using this function.
504 504
    void startSparse() {
505 505
      for(NodeIt n(_graph); n != INVALID; ++n) {
506 506
        if ((*_status)[n] == UNMATCHED) {
507 507
          (*_blossom_rep)[_blossom_set->insert(n)] = n;
508 508
          _tree_set->insert(n);
509 509
          (*_status)[n] = EVEN;
510 510
          processSparse(n);
511 511
        }
512 512
      }
513 513
    }
514 514

	
515
    /// \brief Start Edmonds' algorithm with a heuristic improvement 
515
    /// \brief Start Edmonds' algorithm with a heuristic improvement
516 516
    /// for dense graphs
517 517
    ///
518 518
    /// This function runs Edmonds' algorithm with a heuristic of postponing
519 519
    /// shrinks, therefore resulting in a faster algorithm for dense graphs.
520 520
    ///
521 521
    /// \pre \ref init(), \ref greedyInit() or \ref matchingInit() must be
522 522
    /// called before using this function.
523 523
    void startDense() {
524 524
      for(NodeIt n(_graph); n != INVALID; ++n) {
525 525
        if ((*_status)[n] == UNMATCHED) {
526 526
          (*_blossom_rep)[_blossom_set->insert(n)] = n;
527 527
          _tree_set->insert(n);
528 528
          (*_status)[n] = EVEN;
529 529
          processDense(n);
530 530
        }
531 531
      }
532 532
    }
533 533

	
534 534

	
535 535
    /// \brief Run Edmonds' algorithm
536 536
    ///
537
    /// This function runs Edmonds' algorithm. An additional heuristic of 
538
    /// postponing shrinks is used for relatively dense graphs 
537
    /// This function runs Edmonds' algorithm. An additional heuristic of
538
    /// postponing shrinks is used for relatively dense graphs
539 539
    /// (for which <tt>m>=2*n</tt> holds).
540 540
    void run() {
541 541
      if (countEdges(_graph) < 2 * countNodes(_graph)) {
542 542
        greedyInit();
543 543
        startSparse();
544 544
      } else {
545 545
        init();
546 546
        startDense();
547 547
      }
548 548
    }
549 549

	
550 550
    /// @}
551 551

	
552 552
    /// \name Primal Solution
553 553
    /// Functions to get the primal solution, i.e. the maximum matching.
554 554

	
555 555
    /// @{
556 556

	
557 557
    /// \brief Return the size (cardinality) of the matching.
558 558
    ///
559
    /// This function returns the size (cardinality) of the current matching. 
559
    /// This function returns the size (cardinality) of the current matching.
560 560
    /// After run() it returns the size of the maximum matching in the graph.
561 561
    int matchingSize() const {
562 562
      int size = 0;
563 563
      for (NodeIt n(_graph); n != INVALID; ++n) {
564 564
        if ((*_matching)[n] != INVALID) {
565 565
          ++size;
566 566
        }
567 567
      }
568 568
      return size / 2;
569 569
    }
570 570

	
571 571
    /// \brief Return \c true if the given edge is in the matching.
572 572
    ///
573
    /// This function returns \c true if the given edge is in the current 
573
    /// This function returns \c true if the given edge is in the current
574 574
    /// matching.
575 575
    bool matching(const Edge& edge) const {
576 576
      return edge == (*_matching)[_graph.u(edge)];
577 577
    }
578 578

	
579 579
    /// \brief Return the matching arc (or edge) incident to the given node.
580 580
    ///
581 581
    /// This function returns the matching arc (or edge) incident to the
582
    /// given node in the current matching or \c INVALID if the node is 
582
    /// given node in the current matching or \c INVALID if the node is
583 583
    /// not covered by the matching.
584 584
    Arc matching(const Node& n) const {
585 585
      return (*_matching)[n];
586 586
    }
587 587

	
588 588
    /// \brief Return a const reference to the matching map.
589 589
    ///
590 590
    /// This function returns a const reference to a node map that stores
591 591
    /// the matching arc (or edge) incident to each node.
592 592
    const MatchingMap& matchingMap() const {
593 593
      return *_matching;
594 594
    }
595 595

	
596 596
    /// \brief Return the mate of the given node.
597 597
    ///
598
    /// This function returns the mate of the given node in the current 
598
    /// This function returns the mate of the given node in the current
599 599
    /// matching or \c INVALID if the node is not covered by the matching.
600 600
    Node mate(const Node& n) const {
601 601
      return (*_matching)[n] != INVALID ?
602 602
        _graph.target((*_matching)[n]) : INVALID;
603 603
    }
604 604

	
605 605
    /// @}
606 606

	
607 607
    /// \name Dual Solution
608
    /// Functions to get the dual solution, i.e. the Gallai-Edmonds 
608
    /// Functions to get the dual solution, i.e. the Gallai-Edmonds
609 609
    /// decomposition.
610 610

	
611 611
    /// @{
612 612

	
613 613
    /// \brief Return the status of the given node in the Edmonds-Gallai
614 614
    /// decomposition.
615 615
    ///
616 616
    /// This function returns the \ref Status "status" of the given node
617 617
    /// in the Edmonds-Gallai decomposition.
618 618
    Status status(const Node& n) const {
619 619
      return (*_status)[n];
620 620
    }
621 621

	
622 622
    /// \brief Return a const reference to the status map, which stores
623 623
    /// the Edmonds-Gallai decomposition.
624 624
    ///
625 625
    /// This function returns a const reference to a node map that stores the
626 626
    /// \ref Status "status" of each node in the Edmonds-Gallai decomposition.
627 627
    const StatusMap& statusMap() const {
628 628
      return *_status;
629 629
    }
630 630

	
631 631
    /// \brief Return \c true if the given node is in the barrier.
632 632
    ///
633 633
    /// This function returns \c true if the given node is in the barrier.
634 634
    bool barrier(const Node& n) const {
635 635
      return (*_status)[n] == ODD;
636 636
    }
637 637

	
638 638
    /// @}
639 639

	
640 640
  };
641 641

	
642 642
  /// \ingroup matching
643 643
  ///
644 644
  /// \brief Weighted matching in general graphs
645 645
  ///
646 646
  /// This class provides an efficient implementation of Edmond's
647 647
  /// maximum weighted matching algorithm. The implementation is based
648 648
  /// on extensive use of priority queues and provides
649 649
  /// \f$O(nm\log n)\f$ time complexity.
650 650
  ///
651
  /// The maximum weighted matching problem is to find a subset of the 
652
  /// edges in an undirected graph with maximum overall weight for which 
651
  /// The maximum weighted matching problem is to find a subset of the
652
  /// edges in an undirected graph with maximum overall weight for which
653 653
  /// each node has at most one incident edge.
654 654
  /// It can be formulated with the following linear program.
655 655
  /// \f[ \sum_{e \in \delta(u)}x_e \le 1 \quad \forall u\in V\f]
656 656
  /** \f[ \sum_{e \in \gamma(B)}x_e \le \frac{\vert B \vert - 1}{2}
657 657
      \quad \forall B\in\mathcal{O}\f] */
658 658
  /// \f[x_e \ge 0\quad \forall e\in E\f]
659 659
  /// \f[\max \sum_{e\in E}x_ew_e\f]
660 660
  /// where \f$\delta(X)\f$ is the set of edges incident to a node in
661 661
  /// \f$X\f$, \f$\gamma(X)\f$ is the set of edges with both ends in
662 662
  /// \f$X\f$ and \f$\mathcal{O}\f$ is the set of odd cardinality
663 663
  /// subsets of the nodes.
664 664
  ///
665 665
  /// The algorithm calculates an optimal matching and a proof of the
666 666
  /// optimality. The solution of the dual problem can be used to check
667 667
  /// the result of the algorithm. The dual linear problem is the
668 668
  /// following.
669 669
  /** \f[ y_u + y_v + \sum_{B \in \mathcal{O}, uv \in \gamma(B)}
670 670
      z_B \ge w_{uv} \quad \forall uv\in E\f] */
671 671
  /// \f[y_u \ge 0 \quad \forall u \in V\f]
672 672
  /// \f[z_B \ge 0 \quad \forall B \in \mathcal{O}\f]
673 673
  /** \f[\min \sum_{u \in V}y_u + \sum_{B \in \mathcal{O}}
674 674
      \frac{\vert B \vert - 1}{2}z_B\f] */
675 675
  ///
676
  /// The algorithm can be executed with the run() function. 
676
  /// The algorithm can be executed with the run() function.
677 677
  /// After it the matching (the primal solution) and the dual solution
678
  /// can be obtained using the query functions and the 
679
  /// \ref MaxWeightedMatching::BlossomIt "BlossomIt" nested class, 
680
  /// which is able to iterate on the nodes of a blossom. 
678
  /// can be obtained using the query functions and the
679
  /// \ref MaxWeightedMatching::BlossomIt "BlossomIt" nested class,
680
  /// which is able to iterate on the nodes of a blossom.
681 681
  /// If the value type is integer, then the dual solution is multiplied
682 682
  /// by \ref MaxWeightedMatching::dualScale "4".
683 683
  ///
684 684
  /// \tparam GR The undirected graph type the algorithm runs on.
685
  /// \tparam WM The type edge weight map. The default type is 
685
  /// \tparam WM The type edge weight map. The default type is
686 686
  /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>".
687 687
#ifdef DOXYGEN
688 688
  template <typename GR, typename WM>
689 689
#else
690 690
  template <typename GR,
691 691
            typename WM = typename GR::template EdgeMap<int> >
692 692
#endif
693 693
  class MaxWeightedMatching {
694 694
  public:
695 695

	
696 696
    /// The graph type of the algorithm
697 697
    typedef GR Graph;
698 698
    /// The type of the edge weight map
699 699
    typedef WM WeightMap;
700 700
    /// The value type of the edge weights
701 701
    typedef typename WeightMap::Value Value;
702 702

	
703 703
    /// The type of the matching map
704 704
    typedef typename Graph::template NodeMap<typename Graph::Arc>
705 705
    MatchingMap;
706 706

	
707 707
    /// \brief Scaling factor for dual solution
708 708
    ///
709 709
    /// Scaling factor for dual solution. It is equal to 4 or 1
... ...
@@ -1699,49 +1699,49 @@
1699 1699
    ///@{
1700 1700

	
1701 1701
    /// \brief Initialize the algorithm
1702 1702
    ///
1703 1703
    /// This function initializes the algorithm.
1704 1704
    void init() {
1705 1705
      createStructures();
1706 1706

	
1707 1707
      _blossom_node_list.clear();
1708 1708
      _blossom_potential.clear();
1709 1709

	
1710 1710
      for (ArcIt e(_graph); e != INVALID; ++e) {
1711 1711
        (*_node_heap_index)[e] = BinHeap<Value, IntArcMap>::PRE_HEAP;
1712 1712
      }
1713 1713
      for (NodeIt n(_graph); n != INVALID; ++n) {
1714 1714
        (*_delta1_index)[n] = _delta1->PRE_HEAP;
1715 1715
      }
1716 1716
      for (EdgeIt e(_graph); e != INVALID; ++e) {
1717 1717
        (*_delta3_index)[e] = _delta3->PRE_HEAP;
1718 1718
      }
1719 1719
      for (int i = 0; i < _blossom_num; ++i) {
1720 1720
        (*_delta2_index)[i] = _delta2->PRE_HEAP;
1721 1721
        (*_delta4_index)[i] = _delta4->PRE_HEAP;
1722 1722
      }
1723
      
1723

	
1724 1724
      _delta1->clear();
1725 1725
      _delta2->clear();
1726 1726
      _delta3->clear();
1727 1727
      _delta4->clear();
1728 1728
      _blossom_set->clear();
1729 1729
      _tree_set->clear();
1730 1730

	
1731 1731
      int index = 0;
1732 1732
      for (NodeIt n(_graph); n != INVALID; ++n) {
1733 1733
        Value max = 0;
1734 1734
        for (OutArcIt e(_graph, n); e != INVALID; ++e) {
1735 1735
          if (_graph.target(e) == n) continue;
1736 1736
          if ((dualScale * _weight[e]) / 2 > max) {
1737 1737
            max = (dualScale * _weight[e]) / 2;
1738 1738
          }
1739 1739
        }
1740 1740
        (*_node_index)[n] = index;
1741 1741
        (*_node_data)[index].heap_index.clear();
1742 1742
        (*_node_data)[index].heap.clear();
1743 1743
        (*_node_data)[index].pot = max;
1744 1744
        _delta1->push(n, max);
1745 1745
        int blossom =
1746 1746
          _blossom_set->insert(n, std::numeric_limits<Value>::max());
1747 1747

	
... ...
@@ -1847,138 +1847,138 @@
1847 1847
          splitBlossom(_delta4->top());
1848 1848
          break;
1849 1849
        }
1850 1850
      }
1851 1851
      extractMatching();
1852 1852
    }
1853 1853

	
1854 1854
    /// \brief Run the algorithm.
1855 1855
    ///
1856 1856
    /// This method runs the \c %MaxWeightedMatching algorithm.
1857 1857
    ///
1858 1858
    /// \note mwm.run() is just a shortcut of the following code.
1859 1859
    /// \code
1860 1860
    ///   mwm.init();
1861 1861
    ///   mwm.start();
1862 1862
    /// \endcode
1863 1863
    void run() {
1864 1864
      init();
1865 1865
      start();
1866 1866
    }
1867 1867

	
1868 1868
    /// @}
1869 1869

	
1870 1870
    /// \name Primal Solution
1871
    /// Functions to get the primal solution, i.e. the maximum weighted 
1871
    /// Functions to get the primal solution, i.e. the maximum weighted
1872 1872
    /// matching.\n
1873 1873
    /// Either \ref run() or \ref start() function should be called before
1874 1874
    /// using them.
1875 1875

	
1876 1876
    /// @{
1877 1877

	
1878 1878
    /// \brief Return the weight of the matching.
1879 1879
    ///
1880 1880
    /// This function returns the weight of the found matching.
1881 1881
    ///
1882 1882
    /// \pre Either run() or start() must be called before using this function.
1883 1883
    Value matchingWeight() const {
1884 1884
      Value sum = 0;
1885 1885
      for (NodeIt n(_graph); n != INVALID; ++n) {
1886 1886
        if ((*_matching)[n] != INVALID) {
1887 1887
          sum += _weight[(*_matching)[n]];
1888 1888
        }
1889 1889
      }
1890 1890
      return sum /= 2;
1891 1891
    }
1892 1892

	
1893 1893
    /// \brief Return the size (cardinality) of the matching.
1894 1894
    ///
1895 1895
    /// This function returns the size (cardinality) of the found matching.
1896 1896
    ///
1897 1897
    /// \pre Either run() or start() must be called before using this function.
1898 1898
    int matchingSize() const {
1899 1899
      int num = 0;
1900 1900
      for (NodeIt n(_graph); n != INVALID; ++n) {
1901 1901
        if ((*_matching)[n] != INVALID) {
1902 1902
          ++num;
1903 1903
        }
1904 1904
      }
1905 1905
      return num /= 2;
1906 1906
    }
1907 1907

	
1908 1908
    /// \brief Return \c true if the given edge is in the matching.
1909 1909
    ///
1910
    /// This function returns \c true if the given edge is in the found 
1910
    /// This function returns \c true if the given edge is in the found
1911 1911
    /// matching.
1912 1912
    ///
1913 1913
    /// \pre Either run() or start() must be called before using this function.
1914 1914
    bool matching(const Edge& edge) const {
1915 1915
      return edge == (*_matching)[_graph.u(edge)];
1916 1916
    }
1917 1917

	
1918 1918
    /// \brief Return the matching arc (or edge) incident to the given node.
1919 1919
    ///
1920 1920
    /// This function returns the matching arc (or edge) incident to the
1921
    /// given node in the found matching or \c INVALID if the node is 
1921
    /// given node in the found matching or \c INVALID if the node is
1922 1922
    /// not covered by the matching.
1923 1923
    ///
1924 1924
    /// \pre Either run() or start() must be called before using this function.
1925 1925
    Arc matching(const Node& node) const {
1926 1926
      return (*_matching)[node];
1927 1927
    }
1928 1928

	
1929 1929
    /// \brief Return a const reference to the matching map.
1930 1930
    ///
1931 1931
    /// This function returns a const reference to a node map that stores
1932 1932
    /// the matching arc (or edge) incident to each node.
1933 1933
    const MatchingMap& matchingMap() const {
1934 1934
      return *_matching;
1935 1935
    }
1936 1936

	
1937 1937
    /// \brief Return the mate of the given node.
1938 1938
    ///
1939
    /// This function returns the mate of the given node in the found 
1939
    /// This function returns the mate of the given node in the found
1940 1940
    /// matching or \c INVALID if the node is not covered by the matching.
1941 1941
    ///
1942 1942
    /// \pre Either run() or start() must be called before using this function.
1943 1943
    Node mate(const Node& node) const {
1944 1944
      return (*_matching)[node] != INVALID ?
1945 1945
        _graph.target((*_matching)[node]) : INVALID;
1946 1946
    }
1947 1947

	
1948 1948
    /// @}
1949 1949

	
1950 1950
    /// \name Dual Solution
1951 1951
    /// Functions to get the dual solution.\n
1952 1952
    /// Either \ref run() or \ref start() function should be called before
1953 1953
    /// using them.
1954 1954

	
1955 1955
    /// @{
1956 1956

	
1957 1957
    /// \brief Return the value of the dual solution.
1958 1958
    ///
1959
    /// This function returns the value of the dual solution. 
1960
    /// It should be equal to the primal value scaled by \ref dualScale 
1959
    /// This function returns the value of the dual solution.
1960
    /// It should be equal to the primal value scaled by \ref dualScale
1961 1961
    /// "dual scale".
1962 1962
    ///
1963 1963
    /// \pre Either run() or start() must be called before using this function.
1964 1964
    Value dualValue() const {
1965 1965
      Value sum = 0;
1966 1966
      for (NodeIt n(_graph); n != INVALID; ++n) {
1967 1967
        sum += nodeValue(n);
1968 1968
      }
1969 1969
      for (int i = 0; i < blossomNum(); ++i) {
1970 1970
        sum += blossomValue(i) * (blossomSize(i) / 2);
1971 1971
      }
1972 1972
      return sum;
1973 1973
    }
1974 1974

	
1975 1975
    /// \brief Return the dual value (potential) of the given node.
1976 1976
    ///
1977 1977
    /// This function returns the dual value (potential) of the given node.
1978 1978
    ///
1979 1979
    /// \pre Either run() or start() must be called before using this function.
1980 1980
    Value nodeValue(const Node& n) const {
1981 1981
      return (*_node_potential)[n];
1982 1982
    }
1983 1983

	
1984 1984
    /// \brief Return the number of the blossoms in the basis.
... ...
@@ -1991,61 +1991,61 @@
1991 1991
      return _blossom_potential.size();
1992 1992
    }
1993 1993

	
1994 1994
    /// \brief Return the number of the nodes in the given blossom.
1995 1995
    ///
1996 1996
    /// This function returns the number of the nodes in the given blossom.
1997 1997
    ///
1998 1998
    /// \pre Either run() or start() must be called before using this function.
1999 1999
    /// \see BlossomIt
2000 2000
    int blossomSize(int k) const {
2001 2001
      return _blossom_potential[k].end - _blossom_potential[k].begin;
2002 2002
    }
2003 2003

	
2004 2004
    /// \brief Return the dual value (ptential) of the given blossom.
2005 2005
    ///
2006 2006
    /// This function returns the dual value (ptential) of the given blossom.
2007 2007
    ///
2008 2008
    /// \pre Either run() or start() must be called before using this function.
2009 2009
    Value blossomValue(int k) const {
2010 2010
      return _blossom_potential[k].value;
2011 2011
    }
2012 2012

	
2013 2013
    /// \brief Iterator for obtaining the nodes of a blossom.
2014 2014
    ///
2015
    /// This class provides an iterator for obtaining the nodes of the 
2015
    /// This class provides an iterator for obtaining the nodes of the
2016 2016
    /// given blossom. It lists a subset of the nodes.
2017
    /// Before using this iterator, you must allocate a 
2017
    /// Before using this iterator, you must allocate a
2018 2018
    /// MaxWeightedMatching class and execute it.
2019 2019
    class BlossomIt {
2020 2020
    public:
2021 2021

	
2022 2022
      /// \brief Constructor.
2023 2023
      ///
2024 2024
      /// Constructor to get the nodes of the given variable.
2025 2025
      ///
2026
      /// \pre Either \ref MaxWeightedMatching::run() "algorithm.run()" or 
2027
      /// \ref MaxWeightedMatching::start() "algorithm.start()" must be 
2026
      /// \pre Either \ref MaxWeightedMatching::run() "algorithm.run()" or
2027
      /// \ref MaxWeightedMatching::start() "algorithm.start()" must be
2028 2028
      /// called before initializing this iterator.
2029 2029
      BlossomIt(const MaxWeightedMatching& algorithm, int variable)
2030 2030
        : _algorithm(&algorithm)
2031 2031
      {
2032 2032
        _index = _algorithm->_blossom_potential[variable].begin;
2033 2033
        _last = _algorithm->_blossom_potential[variable].end;
2034 2034
      }
2035 2035

	
2036 2036
      /// \brief Conversion to \c Node.
2037 2037
      ///
2038 2038
      /// Conversion to \c Node.
2039 2039
      operator Node() const {
2040 2040
        return _algorithm->_blossom_node_list[_index];
2041 2041
      }
2042 2042

	
2043 2043
      /// \brief Increment operator.
2044 2044
      ///
2045 2045
      /// Increment operator.
2046 2046
      BlossomIt& operator++() {
2047 2047
        ++_index;
2048 2048
        return *this;
2049 2049
      }
2050 2050

	
2051 2051
      /// \brief Validity checking
... ...
@@ -2056,82 +2056,82 @@
2056 2056
      /// \brief Validity checking
2057 2057
      ///
2058 2058
      /// Checks whether the iterator is valid.
2059 2059
      bool operator!=(Invalid) const { return _index != _last; }
2060 2060

	
2061 2061
    private:
2062 2062
      const MaxWeightedMatching* _algorithm;
2063 2063
      int _last;
2064 2064
      int _index;
2065 2065
    };
2066 2066

	
2067 2067
    /// @}
2068 2068

	
2069 2069
  };
2070 2070

	
2071 2071
  /// \ingroup matching
2072 2072
  ///
2073 2073
  /// \brief Weighted perfect matching in general graphs
2074 2074
  ///
2075 2075
  /// This class provides an efficient implementation of Edmond's
2076 2076
  /// maximum weighted perfect matching algorithm. The implementation
2077 2077
  /// is based on extensive use of priority queues and provides
2078 2078
  /// \f$O(nm\log n)\f$ time complexity.
2079 2079
  ///
2080
  /// The maximum weighted perfect matching problem is to find a subset of 
2081
  /// the edges in an undirected graph with maximum overall weight for which 
2080
  /// The maximum weighted perfect matching problem is to find a subset of
2081
  /// the edges in an undirected graph with maximum overall weight for which
2082 2082
  /// each node has exactly one incident edge.
2083 2083
  /// It can be formulated with the following linear program.
2084 2084
  /// \f[ \sum_{e \in \delta(u)}x_e = 1 \quad \forall u\in V\f]
2085 2085
  /** \f[ \sum_{e \in \gamma(B)}x_e \le \frac{\vert B \vert - 1}{2}
2086 2086
      \quad \forall B\in\mathcal{O}\f] */
2087 2087
  /// \f[x_e \ge 0\quad \forall e\in E\f]
2088 2088
  /// \f[\max \sum_{e\in E}x_ew_e\f]
2089 2089
  /// where \f$\delta(X)\f$ is the set of edges incident to a node in
2090 2090
  /// \f$X\f$, \f$\gamma(X)\f$ is the set of edges with both ends in
2091 2091
  /// \f$X\f$ and \f$\mathcal{O}\f$ is the set of odd cardinality
2092 2092
  /// subsets of the nodes.
2093 2093
  ///
2094 2094
  /// The algorithm calculates an optimal matching and a proof of the
2095 2095
  /// optimality. The solution of the dual problem can be used to check
2096 2096
  /// the result of the algorithm. The dual linear problem is the
2097 2097
  /// following.
2098 2098
  /** \f[ y_u + y_v + \sum_{B \in \mathcal{O}, uv \in \gamma(B)}z_B \ge
2099 2099
      w_{uv} \quad \forall uv\in E\f] */
2100 2100
  /// \f[z_B \ge 0 \quad \forall B \in \mathcal{O}\f]
2101 2101
  /** \f[\min \sum_{u \in V}y_u + \sum_{B \in \mathcal{O}}
2102 2102
      \frac{\vert B \vert - 1}{2}z_B\f] */
2103 2103
  ///
2104
  /// The algorithm can be executed with the run() function. 
2104
  /// The algorithm can be executed with the run() function.
2105 2105
  /// After it the matching (the primal solution) and the dual solution
2106
  /// can be obtained using the query functions and the 
2107
  /// \ref MaxWeightedPerfectMatching::BlossomIt "BlossomIt" nested class, 
2108
  /// which is able to iterate on the nodes of a blossom. 
2106
  /// can be obtained using the query functions and the
2107
  /// \ref MaxWeightedPerfectMatching::BlossomIt "BlossomIt" nested class,
2108
  /// which is able to iterate on the nodes of a blossom.
2109 2109
  /// If the value type is integer, then the dual solution is multiplied
2110 2110
  /// by \ref MaxWeightedMatching::dualScale "4".
2111 2111
  ///
2112 2112
  /// \tparam GR The undirected graph type the algorithm runs on.
2113
  /// \tparam WM The type edge weight map. The default type is 
2113
  /// \tparam WM The type edge weight map. The default type is
2114 2114
  /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>".
2115 2115
#ifdef DOXYGEN
2116 2116
  template <typename GR, typename WM>
2117 2117
#else
2118 2118
  template <typename GR,
2119 2119
            typename WM = typename GR::template EdgeMap<int> >
2120 2120
#endif
2121 2121
  class MaxWeightedPerfectMatching {
2122 2122
  public:
2123 2123

	
2124 2124
    /// The graph type of the algorithm
2125 2125
    typedef GR Graph;
2126 2126
    /// The type of the edge weight map
2127 2127
    typedef WM WeightMap;
2128 2128
    /// The value type of the edge weights
2129 2129
    typedef typename WeightMap::Value Value;
2130 2130

	
2131 2131
    /// \brief Scaling factor for dual solution
2132 2132
    ///
2133 2133
    /// Scaling factor for dual solution, it is equal to 4 or 1
2134 2134
    /// according to the value type.
2135 2135
    static const int dualScale =
2136 2136
      std::numeric_limits<Value>::is_integer ? 4 : 1;
2137 2137

	
... ...
@@ -3094,122 +3094,122 @@
3094 3094
          break;
3095 3095
        }
3096 3096
      }
3097 3097
      extractMatching();
3098 3098
      return true;
3099 3099
    }
3100 3100

	
3101 3101
    /// \brief Run the algorithm.
3102 3102
    ///
3103 3103
    /// This method runs the \c %MaxWeightedPerfectMatching algorithm.
3104 3104
    ///
3105 3105
    /// \note mwpm.run() is just a shortcut of the following code.
3106 3106
    /// \code
3107 3107
    ///   mwpm.init();
3108 3108
    ///   mwpm.start();
3109 3109
    /// \endcode
3110 3110
    bool run() {
3111 3111
      init();
3112 3112
      return start();
3113 3113
    }
3114 3114

	
3115 3115
    /// @}
3116 3116

	
3117 3117
    /// \name Primal Solution
3118
    /// Functions to get the primal solution, i.e. the maximum weighted 
3118
    /// Functions to get the primal solution, i.e. the maximum weighted
3119 3119
    /// perfect matching.\n
3120 3120
    /// Either \ref run() or \ref start() function should be called before
3121 3121
    /// using them.
3122 3122

	
3123 3123
    /// @{
3124 3124

	
3125 3125
    /// \brief Return the weight of the matching.
3126 3126
    ///
3127 3127
    /// This function returns the weight of the found matching.
3128 3128
    ///
3129 3129
    /// \pre Either run() or start() must be called before using this function.
3130 3130
    Value matchingWeight() const {
3131 3131
      Value sum = 0;
3132 3132
      for (NodeIt n(_graph); n != INVALID; ++n) {
3133 3133
        if ((*_matching)[n] != INVALID) {
3134 3134
          sum += _weight[(*_matching)[n]];
3135 3135
        }
3136 3136
      }
3137 3137
      return sum /= 2;
3138 3138
    }
3139 3139

	
3140 3140
    /// \brief Return \c true if the given edge is in the matching.
3141 3141
    ///
3142
    /// This function returns \c true if the given edge is in the found 
3142
    /// This function returns \c true if the given edge is in the found
3143 3143
    /// matching.
3144 3144
    ///
3145 3145
    /// \pre Either run() or start() must be called before using this function.
3146 3146
    bool matching(const Edge& edge) const {
3147 3147
      return static_cast<const Edge&>((*_matching)[_graph.u(edge)]) == edge;
3148 3148
    }
3149 3149

	
3150 3150
    /// \brief Return the matching arc (or edge) incident to the given node.
3151 3151
    ///
3152 3152
    /// This function returns the matching arc (or edge) incident to the
3153
    /// given node in the found matching or \c INVALID if the node is 
3153
    /// given node in the found matching or \c INVALID if the node is
3154 3154
    /// not covered by the matching.
3155 3155
    ///
3156 3156
    /// \pre Either run() or start() must be called before using this function.
3157 3157
    Arc matching(const Node& node) const {
3158 3158
      return (*_matching)[node];
3159 3159
    }
3160 3160

	
3161 3161
    /// \brief Return a const reference to the matching map.
3162 3162
    ///
3163 3163
    /// This function returns a const reference to a node map that stores
3164 3164
    /// the matching arc (or edge) incident to each node.
3165 3165
    const MatchingMap& matchingMap() const {
3166 3166
      return *_matching;
3167 3167
    }
3168 3168

	
3169 3169
    /// \brief Return the mate of the given node.
3170 3170
    ///
3171
    /// This function returns the mate of the given node in the found 
3171
    /// This function returns the mate of the given node in the found
3172 3172
    /// matching or \c INVALID if the node is not covered by the matching.
3173 3173
    ///
3174 3174
    /// \pre Either run() or start() must be called before using this function.
3175 3175
    Node mate(const Node& node) const {
3176 3176
      return _graph.target((*_matching)[node]);
3177 3177
    }
3178 3178

	
3179 3179
    /// @}
3180 3180

	
3181 3181
    /// \name Dual Solution
3182 3182
    /// Functions to get the dual solution.\n
3183 3183
    /// Either \ref run() or \ref start() function should be called before
3184 3184
    /// using them.
3185 3185

	
3186 3186
    /// @{
3187 3187

	
3188 3188
    /// \brief Return the value of the dual solution.
3189 3189
    ///
3190
    /// This function returns the value of the dual solution. 
3191
    /// It should be equal to the primal value scaled by \ref dualScale 
3190
    /// This function returns the value of the dual solution.
3191
    /// It should be equal to the primal value scaled by \ref dualScale
3192 3192
    /// "dual scale".
3193 3193
    ///
3194 3194
    /// \pre Either run() or start() must be called before using this function.
3195 3195
    Value dualValue() const {
3196 3196
      Value sum = 0;
3197 3197
      for (NodeIt n(_graph); n != INVALID; ++n) {
3198 3198
        sum += nodeValue(n);
3199 3199
      }
3200 3200
      for (int i = 0; i < blossomNum(); ++i) {
3201 3201
        sum += blossomValue(i) * (blossomSize(i) / 2);
3202 3202
      }
3203 3203
      return sum;
3204 3204
    }
3205 3205

	
3206 3206
    /// \brief Return the dual value (potential) of the given node.
3207 3207
    ///
3208 3208
    /// This function returns the dual value (potential) of the given node.
3209 3209
    ///
3210 3210
    /// \pre Either run() or start() must be called before using this function.
3211 3211
    Value nodeValue(const Node& n) const {
3212 3212
      return (*_node_potential)[n];
3213 3213
    }
3214 3214

	
3215 3215
    /// \brief Return the number of the blossoms in the basis.
... ...
@@ -3222,61 +3222,61 @@
3222 3222
      return _blossom_potential.size();
3223 3223
    }
3224 3224

	
3225 3225
    /// \brief Return the number of the nodes in the given blossom.
3226 3226
    ///
3227 3227
    /// This function returns the number of the nodes in the given blossom.
3228 3228
    ///
3229 3229
    /// \pre Either run() or start() must be called before using this function.
3230 3230
    /// \see BlossomIt
3231 3231
    int blossomSize(int k) const {
3232 3232
      return _blossom_potential[k].end - _blossom_potential[k].begin;
3233 3233
    }
3234 3234

	
3235 3235
    /// \brief Return the dual value (ptential) of the given blossom.
3236 3236
    ///
3237 3237
    /// This function returns the dual value (ptential) of the given blossom.
3238 3238
    ///
3239 3239
    /// \pre Either run() or start() must be called before using this function.
3240 3240
    Value blossomValue(int k) const {
3241 3241
      return _blossom_potential[k].value;
3242 3242
    }
3243 3243

	
3244 3244
    /// \brief Iterator for obtaining the nodes of a blossom.
3245 3245
    ///
3246
    /// This class provides an iterator for obtaining the nodes of the 
3246
    /// This class provides an iterator for obtaining the nodes of the
3247 3247
    /// given blossom. It lists a subset of the nodes.
3248
    /// Before using this iterator, you must allocate a 
3248
    /// Before using this iterator, you must allocate a
3249 3249
    /// MaxWeightedPerfectMatching class and execute it.
3250 3250
    class BlossomIt {
3251 3251
    public:
3252 3252

	
3253 3253
      /// \brief Constructor.
3254 3254
      ///
3255 3255
      /// Constructor to get the nodes of the given variable.
3256 3256
      ///
3257
      /// \pre Either \ref MaxWeightedPerfectMatching::run() "algorithm.run()" 
3258
      /// or \ref MaxWeightedPerfectMatching::start() "algorithm.start()" 
3257
      /// \pre Either \ref MaxWeightedPerfectMatching::run() "algorithm.run()"
3258
      /// or \ref MaxWeightedPerfectMatching::start() "algorithm.start()"
3259 3259
      /// must be called before initializing this iterator.
3260 3260
      BlossomIt(const MaxWeightedPerfectMatching& algorithm, int variable)
3261 3261
        : _algorithm(&algorithm)
3262 3262
      {
3263 3263
        _index = _algorithm->_blossom_potential[variable].begin;
3264 3264
        _last = _algorithm->_blossom_potential[variable].end;
3265 3265
      }
3266 3266

	
3267 3267
      /// \brief Conversion to \c Node.
3268 3268
      ///
3269 3269
      /// Conversion to \c Node.
3270 3270
      operator Node() const {
3271 3271
        return _algorithm->_blossom_node_list[_index];
3272 3272
      }
3273 3273

	
3274 3274
      /// \brief Increment operator.
3275 3275
      ///
3276 3276
      /// Increment operator.
3277 3277
      BlossomIt& operator++() {
3278 3278
        ++_index;
3279 3279
        return *this;
3280 3280
      }
3281 3281

	
3282 3282
      /// \brief Validity checking
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_MATH_H
20 20
#define LEMON_MATH_H
21 21

	
22 22
///\ingroup misc
23 23
///\file
24 24
///\brief Some extensions to the standard \c cmath library.
25 25
///
26 26
///Some extensions to the standard \c cmath library.
27 27
///
28 28
///This file includes the standard math library (cmath).
29 29

	
... ...
@@ -35,38 +35,38 @@
35 35
  /// @{
36 36

	
37 37
  /// The Euler constant
38 38
  const long double E       = 2.7182818284590452353602874713526625L;
39 39
  /// log_2(e)
40 40
  const long double LOG2E   = 1.4426950408889634073599246810018921L;
41 41
  /// log_10(e)
42 42
  const long double LOG10E  = 0.4342944819032518276511289189166051L;
43 43
  /// ln(2)
44 44
  const long double LN2     = 0.6931471805599453094172321214581766L;
45 45
  /// ln(10)
46 46
  const long double LN10    = 2.3025850929940456840179914546843642L;
47 47
  /// pi
48 48
  const long double PI      = 3.1415926535897932384626433832795029L;
49 49
  /// pi/2
50 50
  const long double PI_2    = 1.5707963267948966192313216916397514L;
51 51
  /// pi/4
52 52
  const long double PI_4    = 0.7853981633974483096156608458198757L;
53 53
  /// sqrt(2)
54 54
  const long double SQRT2   = 1.4142135623730950488016887242096981L;
55 55
  /// 1/sqrt(2)
56 56
  const long double SQRT1_2 = 0.7071067811865475244008443621048490L;
57 57

	
58 58
  ///Check whether the parameter is NaN or not
59
  
59

	
60 60
  ///This function checks whether the parameter is NaN or not.
61 61
  ///Is should be equivalent with std::isnan(), but it is not
62 62
  ///provided by all compilers.
63 63
  inline bool isNaN(double v)
64 64
    {
65 65
      return v!=v;
66 66
    }
67 67

	
68 68
  /// @}
69 69

	
70 70
} //namespace lemon
71 71

	
72 72
#endif //LEMON_TOLERANCE_H
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_MIN_COST_ARBORESCENCE_H
20 20
#define LEMON_MIN_COST_ARBORESCENCE_H
21 21

	
22 22
///\ingroup spantree
23 23
///\file
24 24
///\brief Minimum Cost Arborescence algorithm.
25 25

	
26 26
#include <vector>
27 27

	
28 28
#include <lemon/list_graph.h>
29 29
#include <lemon/bin_heap.h>
... ...
@@ -106,50 +106,50 @@
106 106
  /// The algorithm also provides an optimal dual solution, therefore
107 107
  /// the optimality of the solution can be checked.
108 108
  ///
109 109
  /// \param GR The digraph type the algorithm runs on.
110 110
  /// \param CM A read-only arc map storing the costs of the
111 111
  /// arcs. It is read once for each arc, so the map may involve in
112 112
  /// relatively time consuming process to compute the arc costs if
113 113
  /// it is necessary. The default map type is \ref
114 114
  /// concepts::Digraph::ArcMap "Digraph::ArcMap<int>".
115 115
  /// \param TR Traits class to set various data types used
116 116
  /// by the algorithm. The default traits class is
117 117
  /// \ref MinCostArborescenceDefaultTraits
118 118
  /// "MinCostArborescenceDefaultTraits<GR, CM>".
119 119
#ifndef DOXYGEN
120 120
  template <typename GR,
121 121
            typename CM = typename GR::template ArcMap<int>,
122 122
            typename TR =
123 123
              MinCostArborescenceDefaultTraits<GR, CM> >
124 124
#else
125 125
  template <typename GR, typename CM, typedef TR>
126 126
#endif
127 127
  class MinCostArborescence {
128 128
  public:
129 129

	
130
    /// \brief The \ref MinCostArborescenceDefaultTraits "traits class" 
131
    /// of the algorithm. 
130
    /// \brief The \ref MinCostArborescenceDefaultTraits "traits class"
131
    /// of the algorithm.
132 132
    typedef TR Traits;
133 133
    /// The type of the underlying digraph.
134 134
    typedef typename Traits::Digraph Digraph;
135 135
    /// The type of the map that stores the arc costs.
136 136
    typedef typename Traits::CostMap CostMap;
137 137
    ///The type of the costs of the arcs.
138 138
    typedef typename Traits::Value Value;
139 139
    ///The type of the predecessor map.
140 140
    typedef typename Traits::PredMap PredMap;
141 141
    ///The type of the map that stores which arcs are in the arborescence.
142 142
    typedef typename Traits::ArborescenceMap ArborescenceMap;
143 143

	
144 144
    typedef MinCostArborescence Create;
145 145

	
146 146
  private:
147 147

	
148 148
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
149 149

	
150 150
    struct CostArc {
151 151

	
152 152
      Arc arc;
153 153
      Value value;
154 154

	
155 155
      CostArc() {}
... ...
@@ -414,49 +414,49 @@
414 414
    /// and its value type must be \c bool (or convertible).
415 415
    /// Initially it will be set to \c false on each arc,
416 416
    /// then it will be set on each arborescence arc once.
417 417
    template <class T>
418 418
    struct SetArborescenceMap
419 419
      : public MinCostArborescence<Digraph, CostMap,
420 420
                                   SetArborescenceMapTraits<T> > {
421 421
    };
422 422

	
423 423
    template <class T>
424 424
    struct SetPredMapTraits : public Traits {
425 425
      typedef T PredMap;
426 426
      static PredMap *createPredMap(const Digraph &)
427 427
      {
428 428
        LEMON_ASSERT(false, "PredMap is not initialized");
429 429
        return 0; // ignore warnings
430 430
      }
431 431
    };
432 432

	
433 433
    /// \brief \ref named-templ-param "Named parameter" for
434 434
    /// setting \c PredMap type
435 435
    ///
436 436
    /// \ref named-templ-param "Named parameter" for setting
437 437
    /// \c PredMap type.
438
    /// It must meet the \ref concepts::WriteMap "WriteMap" concept, 
438
    /// It must meet the \ref concepts::WriteMap "WriteMap" concept,
439 439
    /// and its value type must be the \c Arc type of the digraph.
440 440
    template <class T>
441 441
    struct SetPredMap
442 442
      : public MinCostArborescence<Digraph, CostMap, SetPredMapTraits<T> > {
443 443
    };
444 444

	
445 445
    /// @}
446 446

	
447 447
    /// \brief Constructor.
448 448
    ///
449 449
    /// \param digraph The digraph the algorithm will run on.
450 450
    /// \param cost The cost map used by the algorithm.
451 451
    MinCostArborescence(const Digraph& digraph, const CostMap& cost)
452 452
      : _digraph(&digraph), _cost(&cost), _pred(0), local_pred(false),
453 453
        _arborescence(0), local_arborescence(false),
454 454
        _arc_order(0), _node_order(0), _cost_arcs(0),
455 455
        _heap_cross_ref(0), _heap(0) {}
456 456

	
457 457
    /// \brief Destructor.
458 458
    ~MinCostArborescence() {
459 459
      destroyStructures();
460 460
    }
461 461

	
462 462
    /// \brief Sets the arborescence map.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_NETWORK_SIMPLEX_H
20 20
#define LEMON_NETWORK_SIMPLEX_H
21 21

	
22 22
/// \ingroup min_cost_flow_algs
23 23
///
24 24
/// \file
25 25
/// \brief Network Simplex algorithm for finding a minimum cost flow.
26 26

	
27 27
#include <vector>
28 28
#include <limits>
29 29
#include <algorithm>
... ...
@@ -74,110 +74,110 @@
74 74

	
75 75
    /// The type of the flow amounts, capacity bounds and supply values
76 76
    typedef V Value;
77 77
    /// The type of the arc costs
78 78
    typedef C Cost;
79 79

	
80 80
  public:
81 81

	
82 82
    /// \brief Problem type constants for the \c run() function.
83 83
    ///
84 84
    /// Enum type containing the problem type constants that can be
85 85
    /// returned by the \ref run() function of the algorithm.
86 86
    enum ProblemType {
87 87
      /// The problem has no feasible solution (flow).
88 88
      INFEASIBLE,
89 89
      /// The problem has optimal solution (i.e. it is feasible and
90 90
      /// bounded), and the algorithm has found optimal flow and node
91 91
      /// potentials (primal and dual solutions).
92 92
      OPTIMAL,
93 93
      /// The objective function of the problem is unbounded, i.e.
94 94
      /// there is a directed cycle having negative total cost and
95 95
      /// infinite upper bound.
96 96
      UNBOUNDED
97 97
    };
98
    
98

	
99 99
    /// \brief Constants for selecting the type of the supply constraints.
100 100
    ///
101 101
    /// Enum type containing constants for selecting the supply type,
102 102
    /// i.e. the direction of the inequalities in the supply/demand
103 103
    /// constraints of the \ref min_cost_flow "minimum cost flow problem".
104 104
    ///
105 105
    /// The default supply type is \c GEQ, the \c LEQ type can be
106 106
    /// selected using \ref supplyType().
107 107
    /// The equality form is a special case of both supply types.
108 108
    enum SupplyType {
109 109
      /// This option means that there are <em>"greater or equal"</em>
110 110
      /// supply/demand constraints in the definition of the problem.
111 111
      GEQ,
112 112
      /// This option means that there are <em>"less or equal"</em>
113 113
      /// supply/demand constraints in the definition of the problem.
114 114
      LEQ
115 115
    };
116
    
116

	
117 117
    /// \brief Constants for selecting the pivot rule.
118 118
    ///
119 119
    /// Enum type containing constants for selecting the pivot rule for
120 120
    /// the \ref run() function.
121 121
    ///
122 122
    /// \ref NetworkSimplex provides five different pivot rule
123 123
    /// implementations that significantly affect the running time
124 124
    /// of the algorithm.
125 125
    /// By default \ref BLOCK_SEARCH "Block Search" is used, which
126 126
    /// proved to be the most efficient and the most robust on various
127 127
    /// test inputs according to our benchmark tests.
128 128
    /// However another pivot rule can be selected using the \ref run()
129 129
    /// function with the proper parameter.
130 130
    enum PivotRule {
131 131

	
132 132
      /// The First Eligible pivot rule.
133 133
      /// The next eligible arc is selected in a wraparound fashion
134 134
      /// in every iteration.
135 135
      FIRST_ELIGIBLE,
136 136

	
137 137
      /// The Best Eligible pivot rule.
138 138
      /// The best eligible arc is selected in every iteration.
139 139
      BEST_ELIGIBLE,
140 140

	
141 141
      /// The Block Search pivot rule.
142 142
      /// A specified number of arcs are examined in every iteration
143 143
      /// in a wraparound fashion and the best eligible arc is selected
144 144
      /// from this block.
145 145
      BLOCK_SEARCH,
146 146

	
147 147
      /// The Candidate List pivot rule.
148 148
      /// In a major iteration a candidate list is built from eligible arcs
149 149
      /// in a wraparound fashion and in the following minor iterations
150 150
      /// the best eligible arc is selected from this list.
151 151
      CANDIDATE_LIST,
152 152

	
153 153
      /// The Altering Candidate List pivot rule.
154 154
      /// It is a modified version of the Candidate List method.
155 155
      /// It keeps only the several best eligible arcs from the former
156 156
      /// candidate list and extends this list in every iteration.
157 157
      ALTERING_LIST
158 158
    };
159
    
159

	
160 160
  private:
161 161

	
162 162
    TEMPLATE_DIGRAPH_TYPEDEFS(GR);
163 163

	
164 164
    typedef std::vector<Arc> ArcVector;
165 165
    typedef std::vector<Node> NodeVector;
166 166
    typedef std::vector<int> IntVector;
167 167
    typedef std::vector<bool> BoolVector;
168 168
    typedef std::vector<Value> ValueVector;
169 169
    typedef std::vector<Cost> CostVector;
170 170

	
171 171
    // State constants for arcs
172 172
    enum ArcStateEnum {
173 173
      STATE_UPPER = -1,
174 174
      STATE_TREE  =  0,
175 175
      STATE_LOWER =  1
176 176
    };
177 177

	
178 178
  private:
179 179

	
180 180
    // Data related to the underlying digraph
181 181
    const GR &_graph;
182 182
    int _node_num;
183 183
    int _arc_num;
... ...
@@ -202,49 +202,49 @@
202 202
    CostVector _cost;
203 203
    ValueVector _supply;
204 204
    ValueVector _flow;
205 205
    CostVector _pi;
206 206

	
207 207
    // Data for storing the spanning tree structure
208 208
    IntVector _parent;
209 209
    IntVector _pred;
210 210
    IntVector _thread;
211 211
    IntVector _rev_thread;
212 212
    IntVector _succ_num;
213 213
    IntVector _last_succ;
214 214
    IntVector _dirty_revs;
215 215
    BoolVector _forward;
216 216
    IntVector _state;
217 217
    int _root;
218 218

	
219 219
    // Temporary data used in the current pivot iteration
220 220
    int in_arc, join, u_in, v_in, u_out, v_out;
221 221
    int first, second, right, last;
222 222
    int stem, par_stem, new_stem;
223 223
    Value delta;
224 224

	
225 225
  public:
226
  
226

	
227 227
    /// \brief Constant for infinite upper bounds (capacities).
228 228
    ///
229 229
    /// Constant for infinite upper bounds (capacities).
230 230
    /// It is \c std::numeric_limits<Value>::infinity() if available,
231 231
    /// \c std::numeric_limits<Value>::max() otherwise.
232 232
    const Value INF;
233 233

	
234 234
  private:
235 235

	
236 236
    // Implementation of the First Eligible pivot rule
237 237
    class FirstEligiblePivotRule
238 238
    {
239 239
    private:
240 240

	
241 241
      // References to the NetworkSimplex class
242 242
      const IntVector  &_source;
243 243
      const IntVector  &_target;
244 244
      const CostVector &_cost;
245 245
      const IntVector  &_state;
246 246
      const CostVector &_pi;
247 247
      int &_in_arc;
248 248
      int _search_arc_num;
249 249

	
250 250
      // Pivot rule data
... ...
@@ -623,89 +623,89 @@
623 623
        _curr_length = std::min(_head_length, _curr_length - 1);
624 624
        return true;
625 625
      }
626 626

	
627 627
    }; //class AlteringListPivotRule
628 628

	
629 629
  public:
630 630

	
631 631
    /// \brief Constructor.
632 632
    ///
633 633
    /// The constructor of the class.
634 634
    ///
635 635
    /// \param graph The digraph the algorithm runs on.
636 636
    NetworkSimplex(const GR& graph) :
637 637
      _graph(graph), _node_id(graph), _arc_id(graph),
638 638
      INF(std::numeric_limits<Value>::has_infinity ?
639 639
          std::numeric_limits<Value>::infinity() :
640 640
          std::numeric_limits<Value>::max())
641 641
    {
642 642
      // Check the value types
643 643
      LEMON_ASSERT(std::numeric_limits<Value>::is_signed,
644 644
        "The flow type of NetworkSimplex must be signed");
645 645
      LEMON_ASSERT(std::numeric_limits<Cost>::is_signed,
646 646
        "The cost type of NetworkSimplex must be signed");
647
        
647

	
648 648
      // Resize vectors
649 649
      _node_num = countNodes(_graph);
650 650
      _arc_num = countArcs(_graph);
651 651
      int all_node_num = _node_num + 1;
652 652
      int max_arc_num = _arc_num + 2 * _node_num;
653 653

	
654 654
      _source.resize(max_arc_num);
655 655
      _target.resize(max_arc_num);
656 656

	
657 657
      _lower.resize(_arc_num);
658 658
      _upper.resize(_arc_num);
659 659
      _cap.resize(max_arc_num);
660 660
      _cost.resize(max_arc_num);
661 661
      _supply.resize(all_node_num);
662 662
      _flow.resize(max_arc_num);
663 663
      _pi.resize(all_node_num);
664 664

	
665 665
      _parent.resize(all_node_num);
666 666
      _pred.resize(all_node_num);
667 667
      _forward.resize(all_node_num);
668 668
      _thread.resize(all_node_num);
669 669
      _rev_thread.resize(all_node_num);
670 670
      _succ_num.resize(all_node_num);
671 671
      _last_succ.resize(all_node_num);
672 672
      _state.resize(max_arc_num);
673 673

	
674 674
      // Copy the graph (store the arcs in a mixed order)
675 675
      int i = 0;
676 676
      for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
677 677
        _node_id[n] = i;
678 678
      }
679 679
      int k = std::max(int(std::sqrt(double(_arc_num))), 10);
680 680
      i = 0;
681 681
      for (ArcIt a(_graph); a != INVALID; ++a) {
682 682
        _arc_id[a] = i;
683 683
        _source[i] = _node_id[_graph.source(a)];
684 684
        _target[i] = _node_id[_graph.target(a)];
685 685
        if ((i += k) >= _arc_num) i = (i % k) + 1;
686 686
      }
687
      
687

	
688 688
      // Initialize maps
689 689
      for (int i = 0; i != _node_num; ++i) {
690 690
        _supply[i] = 0;
691 691
      }
692 692
      for (int i = 0; i != _arc_num; ++i) {
693 693
        _lower[i] = 0;
694 694
        _upper[i] = INF;
695 695
        _cost[i] = 1;
696 696
      }
697 697
      _have_lower = false;
698 698
      _stype = GEQ;
699 699
    }
700 700

	
701 701
    /// \name Parameters
702 702
    /// The parameters of the algorithm can be specified using these
703 703
    /// functions.
704 704

	
705 705
    /// @{
706 706

	
707 707
    /// \brief Set the lower bounds on the arcs.
708 708
    ///
709 709
    /// This function sets the lower bounds on the arcs.
710 710
    /// If it is not used before calling \ref run(), the lower bounds
711 711
    /// will be set to zero on all arcs.
... ...
@@ -788,75 +788,75 @@
788 788
    /// This function sets a single source node and a single target node
789 789
    /// and the required flow value.
790 790
    /// If neither this function nor \ref supplyMap() is used before
791 791
    /// calling \ref run(), the supply of each node will be set to zero.
792 792
    /// (It makes sense only if non-zero lower bounds are given.)
793 793
    ///
794 794
    /// Using this function has the same effect as using \ref supplyMap()
795 795
    /// with such a map in which \c k is assigned to \c s, \c -k is
796 796
    /// assigned to \c t and all other nodes have zero supply value.
797 797
    ///
798 798
    /// \param s The source node.
799 799
    /// \param t The target node.
800 800
    /// \param k The required amount of flow from node \c s to node \c t
801 801
    /// (i.e. the supply of \c s and the demand of \c t).
802 802
    ///
803 803
    /// \return <tt>(*this)</tt>
804 804
    NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
805 805
      for (int i = 0; i != _node_num; ++i) {
806 806
        _supply[i] = 0;
807 807
      }
808 808
      _supply[_node_id[s]] =  k;
809 809
      _supply[_node_id[t]] = -k;
810 810
      return *this;
811 811
    }
812
    
812

	
813 813
    /// \brief Set the type of the supply constraints.
814 814
    ///
815 815
    /// This function sets the type of the supply/demand constraints.
816 816
    /// If it is not used before calling \ref run(), the \ref GEQ supply
817 817
    /// type will be used.
818 818
    ///
819 819
    /// For more information see \ref SupplyType.
820 820
    ///
821 821
    /// \return <tt>(*this)</tt>
822 822
    NetworkSimplex& supplyType(SupplyType supply_type) {
823 823
      _stype = supply_type;
824 824
      return *this;
825 825
    }
826 826

	
827 827
    /// @}
828 828

	
829 829
    /// \name Execution Control
830 830
    /// The algorithm can be executed using \ref run().
831 831

	
832 832
    /// @{
833 833

	
834 834
    /// \brief Run the algorithm.
835 835
    ///
836 836
    /// This function runs the algorithm.
837 837
    /// The paramters can be specified using functions \ref lowerMap(),
838
    /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(), 
838
    /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(),
839 839
    /// \ref supplyType().
840 840
    /// For example,
841 841
    /// \code
842 842
    ///   NetworkSimplex<ListDigraph> ns(graph);
843 843
    ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
844 844
    ///     .supplyMap(sup).run();
845 845
    /// \endcode
846 846
    ///
847 847
    /// This function can be called more than once. All the parameters
848 848
    /// that have been given are kept for the next call, unless
849 849
    /// \ref reset() is called, thus only the modified parameters
850 850
    /// have to be set again. See \ref reset() for examples.
851 851
    /// However the underlying digraph must not be modified after this
852 852
    /// class have been constructed, since it copies and extends the graph.
853 853
    ///
854 854
    /// \param pivot_rule The pivot rule that will be used during the
855 855
    /// algorithm. For more information see \ref PivotRule.
856 856
    ///
857 857
    /// \return \c INFEASIBLE if no feasible flow exists,
858 858
    /// \n \c OPTIMAL if the problem has optimal solution
859 859
    /// (i.e. it is feasible and bounded), and the algorithm has found
860 860
    /// optimal flow and node potentials (primal and dual solutions),
861 861
    /// \n \c UNBOUNDED if the objective function of the problem is
862 862
    /// unbounded, i.e. there is a directed cycle having negative total
... ...
@@ -1033,49 +1033,49 @@
1033 1033
        }
1034 1034
      } else {
1035 1035
        for (int i = 0; i != _arc_num; ++i) {
1036 1036
          _cap[i] = _upper[i];
1037 1037
        }
1038 1038
      }
1039 1039

	
1040 1040
      // Initialize artifical cost
1041 1041
      Cost ART_COST;
1042 1042
      if (std::numeric_limits<Cost>::is_exact) {
1043 1043
        ART_COST = std::numeric_limits<Cost>::max() / 2 + 1;
1044 1044
      } else {
1045 1045
        ART_COST = 0;
1046 1046
        for (int i = 0; i != _arc_num; ++i) {
1047 1047
          if (_cost[i] > ART_COST) ART_COST = _cost[i];
1048 1048
        }
1049 1049
        ART_COST = (ART_COST + 1) * _node_num;
1050 1050
      }
1051 1051

	
1052 1052
      // Initialize arc maps
1053 1053
      for (int i = 0; i != _arc_num; ++i) {
1054 1054
        _flow[i] = 0;
1055 1055
        _state[i] = STATE_LOWER;
1056 1056
      }
1057
      
1057

	
1058 1058
      // Set data for the artificial root node
1059 1059
      _root = _node_num;
1060 1060
      _parent[_root] = -1;
1061 1061
      _pred[_root] = -1;
1062 1062
      _thread[_root] = 0;
1063 1063
      _rev_thread[0] = _root;
1064 1064
      _succ_num[_root] = _node_num + 1;
1065 1065
      _last_succ[_root] = _root - 1;
1066 1066
      _supply[_root] = -_sum_supply;
1067 1067
      _pi[_root] = 0;
1068 1068

	
1069 1069
      // Add artificial arcs and initialize the spanning tree data structure
1070 1070
      if (_sum_supply == 0) {
1071 1071
        // EQ supply constraints
1072 1072
        _search_arc_num = _arc_num;
1073 1073
        _all_arc_num = _arc_num + _node_num;
1074 1074
        for (int u = 0, e = _arc_num; u != _node_num; ++u, ++e) {
1075 1075
          _parent[u] = _root;
1076 1076
          _pred[u] = e;
1077 1077
          _thread[u] = u + 1;
1078 1078
          _rev_thread[u + 1] = u;
1079 1079
          _succ_num[u] = 1;
1080 1080
          _last_succ[u] = u;
1081 1081
          _cap[e] = INF;
... ...
@@ -1207,49 +1207,49 @@
1207 1207
        second = _target[in_arc];
1208 1208
      } else {
1209 1209
        first  = _target[in_arc];
1210 1210
        second = _source[in_arc];
1211 1211
      }
1212 1212
      delta = _cap[in_arc];
1213 1213
      int result = 0;
1214 1214
      Value d;
1215 1215
      int e;
1216 1216

	
1217 1217
      // Search the cycle along the path form the first node to the root
1218 1218
      for (int u = first; u != join; u = _parent[u]) {
1219 1219
        e = _pred[u];
1220 1220
        d = _forward[u] ?
1221 1221
          _flow[e] : (_cap[e] == INF ? INF : _cap[e] - _flow[e]);
1222 1222
        if (d < delta) {
1223 1223
          delta = d;
1224 1224
          u_out = u;
1225 1225
          result = 1;
1226 1226
        }
1227 1227
      }
1228 1228
      // Search the cycle along the path form the second node to the root
1229 1229
      for (int u = second; u != join; u = _parent[u]) {
1230 1230
        e = _pred[u];
1231
        d = _forward[u] ? 
1231
        d = _forward[u] ?
1232 1232
          (_cap[e] == INF ? INF : _cap[e] - _flow[e]) : _flow[e];
1233 1233
        if (d <= delta) {
1234 1234
          delta = d;
1235 1235
          u_out = u;
1236 1236
          result = 2;
1237 1237
        }
1238 1238
      }
1239 1239

	
1240 1240
      if (result == 1) {
1241 1241
        u_in = first;
1242 1242
        v_in = second;
1243 1243
      } else {
1244 1244
        u_in = second;
1245 1245
        v_in = first;
1246 1246
      }
1247 1247
      return result != 0;
1248 1248
    }
1249 1249

	
1250 1250
    // Change _flow and _state vectors
1251 1251
    void changeFlow(bool change) {
1252 1252
      // Augment along the cycle
1253 1253
      if (delta > 0) {
1254 1254
        Value val = _state[in_arc] * delta;
1255 1255
        _flow[in_arc] += val;
... ...
@@ -1414,66 +1414,66 @@
1414 1414
          return start<BlockSearchPivotRule>();
1415 1415
        case CANDIDATE_LIST:
1416 1416
          return start<CandidateListPivotRule>();
1417 1417
        case ALTERING_LIST:
1418 1418
          return start<AlteringListPivotRule>();
1419 1419
      }
1420 1420
      return INFEASIBLE; // avoid warning
1421 1421
    }
1422 1422

	
1423 1423
    template <typename PivotRuleImpl>
1424 1424
    ProblemType start() {
1425 1425
      PivotRuleImpl pivot(*this);
1426 1426

	
1427 1427
      // Execute the Network Simplex algorithm
1428 1428
      while (pivot.findEnteringArc()) {
1429 1429
        findJoinNode();
1430 1430
        bool change = findLeavingArc();
1431 1431
        if (delta >= INF) return UNBOUNDED;
1432 1432
        changeFlow(change);
1433 1433
        if (change) {
1434 1434
          updateTreeStructure();
1435 1435
          updatePotential();
1436 1436
        }
1437 1437
      }
1438
      
1438

	
1439 1439
      // Check feasibility
1440 1440
      for (int e = _search_arc_num; e != _all_arc_num; ++e) {
1441 1441
        if (_flow[e] != 0) return INFEASIBLE;
1442 1442
      }
1443 1443

	
1444 1444
      // Transform the solution and the supply map to the original form
1445 1445
      if (_have_lower) {
1446 1446
        for (int i = 0; i != _arc_num; ++i) {
1447 1447
          Value c = _lower[i];
1448 1448
          if (c != 0) {
1449 1449
            _flow[i] += c;
1450 1450
            _supply[_source[i]] += c;
1451 1451
            _supply[_target[i]] -= c;
1452 1452
          }
1453 1453
        }
1454 1454
      }
1455
      
1455

	
1456 1456
      // Shift potentials to meet the requirements of the GEQ/LEQ type
1457 1457
      // optimality conditions
1458 1458
      if (_sum_supply == 0) {
1459 1459
        if (_stype == GEQ) {
1460 1460
          Cost max_pot = -std::numeric_limits<Cost>::max();
1461 1461
          for (int i = 0; i != _node_num; ++i) {
1462 1462
            if (_pi[i] > max_pot) max_pot = _pi[i];
1463 1463
          }
1464 1464
          if (max_pot > 0) {
1465 1465
            for (int i = 0; i != _node_num; ++i)
1466 1466
              _pi[i] -= max_pot;
1467 1467
          }
1468 1468
        } else {
1469 1469
          Cost min_pot = std::numeric_limits<Cost>::max();
1470 1470
          for (int i = 0; i != _node_num; ++i) {
1471 1471
            if (_pi[i] < min_pot) min_pot = _pi[i];
1472 1472
          }
1473 1473
          if (min_pot < 0) {
1474 1474
            for (int i = 0; i != _node_num; ++i)
1475 1475
              _pi[i] -= min_pot;
1476 1476
          }
1477 1477
        }
1478 1478
      }
1479 1479

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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 paths
20 20
///\file
21 21
///\brief Classes for representing paths in digraphs.
22 22
///
23 23

	
24 24
#ifndef LEMON_PATH_H
25 25
#define LEMON_PATH_H
26 26

	
27 27
#include <vector>
28 28
#include <algorithm>
29 29

	
... ...
@@ -945,62 +945,62 @@
945 945
        to.clear();
946 946
        to.build(from);
947 947
      }
948 948
    };
949 949

	
950 950
    template <typename From, typename To,
951 951
              bool buildEnable = BuildTagIndicator<To>::value>
952 952
    struct PathCopySelectorBackward {
953 953
      static void copy(const From& from, To& to) {
954 954
        to.clear();
955 955
        for (typename From::RevArcIt it(from); it != INVALID; ++it) {
956 956
          to.addFront(it);
957 957
        }
958 958
      }
959 959
    };
960 960

	
961 961
    template <typename From, typename To>
962 962
    struct PathCopySelectorBackward<From, To, true> {
963 963
      static void copy(const From& from, To& to) {
964 964
        to.clear();
965 965
        to.buildRev(from);
966 966
      }
967 967
    };
968 968

	
969
    
969

	
970 970
    template <typename From, typename To,
971 971
              bool revEnable = RevPathTagIndicator<From>::value>
972 972
    struct PathCopySelector {
973 973
      static void copy(const From& from, To& to) {
974 974
        PathCopySelectorForward<From, To>::copy(from, to);
975
      }      
975
      }
976 976
    };
977 977

	
978 978
    template <typename From, typename To>
979 979
    struct PathCopySelector<From, To, true> {
980 980
      static void copy(const From& from, To& to) {
981 981
        PathCopySelectorBackward<From, To>::copy(from, to);
982
      }      
982
      }
983 983
    };
984 984

	
985 985
  }
986 986

	
987 987

	
988 988
  /// \brief Make a copy of a path.
989 989
  ///
990 990
  /// This function makes a copy of a path.
991 991
  template <typename From, typename To>
992 992
  void pathCopy(const From& from, To& to) {
993 993
    checkConcept<concepts::PathDumper<typename From::Digraph>, From>();
994 994
    _path_bits::PathCopySelector<From, To>::copy(from, to);
995 995
  }
996 996

	
997 997
  /// \brief Deprecated version of \ref pathCopy().
998 998
  ///
999 999
  /// Deprecated version of \ref pathCopy() (only for reverse compatibility).
1000 1000
  template <typename To, typename From>
1001 1001
  void copyPath(To& to, const From& from) {
1002 1002
    pathCopy(from, to);
1003 1003
  }
1004 1004

	
1005 1005
  /// \brief Check the consistency of a path.
1006 1006
  ///
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_PREFLOW_H
20 20
#define LEMON_PREFLOW_H
21 21

	
22 22
#include <lemon/tolerance.h>
23 23
#include <lemon/elevator.h>
24 24

	
25 25
/// \file
26 26
/// \ingroup max_flow
27 27
/// \brief Implementation of the preflow algorithm.
28 28

	
29 29
namespace lemon {
... ...
@@ -515,80 +515,80 @@
515 515
          }
516 516
        }
517 517
        queue.swap(nqueue);
518 518
      }
519 519
      _level->initFinish();
520 520

	
521 521
      for (OutArcIt e(_graph, _source); e != INVALID; ++e) {
522 522
        Value rem = (*_capacity)[e] - (*_flow)[e];
523 523
        if (_tolerance.positive(rem)) {
524 524
          Node u = _graph.target(e);
525 525
          if ((*_level)[u] == _level->maxLevel()) continue;
526 526
          _flow->set(e, (*_capacity)[e]);
527 527
          (*_excess)[u] += rem;
528 528
        }
529 529
      }
530 530
      for (InArcIt e(_graph, _source); e != INVALID; ++e) {
531 531
        Value rem = (*_flow)[e];
532 532
        if (_tolerance.positive(rem)) {
533 533
          Node v = _graph.source(e);
534 534
          if ((*_level)[v] == _level->maxLevel()) continue;
535 535
          _flow->set(e, 0);
536 536
          (*_excess)[v] += rem;
537 537
        }
538 538
      }
539
      for (NodeIt n(_graph); n != INVALID; ++n) 
539
      for (NodeIt n(_graph); n != INVALID; ++n)
540 540
        if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n]))
541 541
          _level->activate(n);
542
          
542

	
543 543
      return true;
544 544
    }
545 545

	
546 546
    /// \brief Starts the first phase of the preflow algorithm.
547 547
    ///
548 548
    /// The preflow algorithm consists of two phases, this method runs
549 549
    /// the first phase. After the first phase the maximum flow value
550 550
    /// and a minimum value cut can already be computed, although a
551 551
    /// maximum flow is not yet obtained. So after calling this method
552 552
    /// \ref flowValue() returns the value of a maximum flow and \ref
553 553
    /// minCut() returns a minimum cut.
554 554
    /// \pre One of the \ref init() functions must be called before
555 555
    /// using this function.
556 556
    void startFirstPhase() {
557 557
      _phase = true;
558 558

	
559 559
      while (true) {
560 560
        int num = _node_num;
561 561

	
562 562
        Node n = INVALID;
563 563
        int level = -1;
564 564

	
565 565
        while (num > 0) {
566 566
          n = _level->highestActive();
567 567
          if (n == INVALID) goto first_phase_done;
568 568
          level = _level->highestActiveLevel();
569 569
          --num;
570
          
570

	
571 571
          Value excess = (*_excess)[n];
572 572
          int new_level = _level->maxLevel();
573 573

	
574 574
          for (OutArcIt e(_graph, n); e != INVALID; ++e) {
575 575
            Value rem = (*_capacity)[e] - (*_flow)[e];
576 576
            if (!_tolerance.positive(rem)) continue;
577 577
            Node v = _graph.target(e);
578 578
            if ((*_level)[v] < level) {
579 579
              if (!_level->active(v) && v != _target) {
580 580
                _level->activate(v);
581 581
              }
582 582
              if (!_tolerance.less(rem, excess)) {
583 583
                _flow->set(e, (*_flow)[e] + excess);
584 584
                (*_excess)[v] += excess;
585 585
                excess = 0;
586 586
                goto no_more_push_1;
587 587
              } else {
588 588
                excess -= rem;
589 589
                (*_excess)[v] += rem;
590 590
                _flow->set(e, (*_capacity)[e]);
591 591
              }
592 592
            } else if (new_level > (*_level)[v]) {
593 593
              new_level = (*_level)[v];
594 594
            }
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20
#include <lemon/soplex.h>
21 21

	
22 22
#include <soplex.h>
23 23
#include <spxout.h>
24 24

	
25 25

	
26 26
///\file
27 27
///\brief Implementation of the LEMON-SOPLEX lp solver interface.
28 28
namespace lemon {
29 29

	
... ...
@@ -253,49 +253,49 @@
253 253
    }
254 254
  }
255 255

	
256 256
  void SoplexLp::_getObjCoeffs(InsertIterator b) const {
257 257
    for (int j = 0; j < soplex->nCols(); ++j) {
258 258
      Value coef = soplex->obj(j);
259 259
      if (coef != 0.0) {
260 260
        *b = std::make_pair(j, coef);
261 261
        ++b;
262 262
      }
263 263
    }
264 264
  }
265 265

	
266 266
  void SoplexLp::_setObjCoeff(int i, Value obj_coef) {
267 267
    soplex->changeObj(i, obj_coef);
268 268
  }
269 269

	
270 270
  SoplexLp::Value SoplexLp::_getObjCoeff(int i) const {
271 271
    return soplex->obj(i);
272 272
  }
273 273

	
274 274
  SoplexLp::SolveExitStatus SoplexLp::_solve() {
275 275

	
276 276
    _clear_temporals();
277
    
277

	
278 278
    _applyMessageLevel();
279 279

	
280 280
    soplex::SPxSolver::Status status = soplex->solve();
281 281

	
282 282
    switch (status) {
283 283
    case soplex::SPxSolver::OPTIMAL:
284 284
    case soplex::SPxSolver::INFEASIBLE:
285 285
    case soplex::SPxSolver::UNBOUNDED:
286 286
      return SOLVED;
287 287
    default:
288 288
      return UNSOLVED;
289 289
    }
290 290
  }
291 291

	
292 292
  SoplexLp::Value SoplexLp::_getPrimal(int i) const {
293 293
    if (_primal_values.empty()) {
294 294
      _primal_values.resize(soplex->nCols());
295 295
      soplex::Vector pv(_primal_values.size(), &_primal_values.front());
296 296
      soplex->getPrimal(pv);
297 297
    }
298 298
    return _primal_values[i];
299 299
  }
300 300

	
301 301
  SoplexLp::Value SoplexLp::_getDual(int i) const {
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_SOPLEX_H
20 20
#define LEMON_SOPLEX_H
21 21

	
22 22
///\file
23 23
///\brief Header of the LEMON-SOPLEX lp solver interface.
24 24

	
25 25
#include <vector>
26 26
#include <string>
27 27

	
28 28
#include <lemon/lp_base.h>
29 29

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_SUURBALLE_H
20 20
#define LEMON_SUURBALLE_H
21 21

	
22 22
///\ingroup shortest_path
23 23
///\file
24 24
///\brief An algorithm for finding arc-disjoint paths between two
25 25
/// nodes having minimum total length.
26 26

	
27 27
#include <vector>
28 28
#include <limits>
29 29
#include <lemon/bin_heap.h>
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#ifndef LEMON_UNION_FIND_H
20 20
#define LEMON_UNION_FIND_H
21 21

	
22 22
//!\ingroup auxdat
23 23
//!\file
24 24
//!\brief Union-Find data structures.
25 25
//!
26 26

	
27 27
#include <vector>
28 28
#include <list>
29 29
#include <utility>
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <lemon/concepts/digraph.h>
20 20
#include <lemon/smart_graph.h>
21 21
#include <lemon/list_graph.h>
22 22
#include <lemon/lgf_reader.h>
23 23
#include <lemon/bfs.h>
24 24
#include <lemon/path.h>
25 25

	
26 26
#include "graph_test.h"
27 27
#include "test_tools.h"
28 28

	
29 29
using namespace lemon;
... ...
@@ -62,94 +62,94 @@
62 62
  Arc e;
63 63
  int l, i;
64 64
  bool b;
65 65
  BType::DistMap d(G);
66 66
  BType::PredMap p(G);
67 67
  Path<Digraph> pp;
68 68
  concepts::ReadMap<Node,bool> nm;
69 69

	
70 70
  {
71 71
    BType bfs_test(G);
72 72
    const BType& const_bfs_test = bfs_test;
73 73

	
74 74
    bfs_test.run(s);
75 75
    bfs_test.run(s,t);
76 76
    bfs_test.run();
77 77

	
78 78
    bfs_test.init();
79 79
    bfs_test.addSource(s);
80 80
    n = bfs_test.processNextNode();
81 81
    n = bfs_test.processNextNode(t, b);
82 82
    n = bfs_test.processNextNode(nm, n);
83 83
    n = const_bfs_test.nextNode();
84 84
    b = const_bfs_test.emptyQueue();
85 85
    i = const_bfs_test.queueSize();
86
    
86

	
87 87
    bfs_test.start();
88 88
    bfs_test.start(t);
89 89
    bfs_test.start(nm);
90 90

	
91 91
    l  = const_bfs_test.dist(t);
92 92
    e  = const_bfs_test.predArc(t);
93 93
    s  = const_bfs_test.predNode(t);
94 94
    b  = const_bfs_test.reached(t);
95 95
    d  = const_bfs_test.distMap();
96 96
    p  = const_bfs_test.predMap();
97 97
    pp = const_bfs_test.path(t);
98 98
  }
99 99
  {
100 100
    BType
101 101
      ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
102 102
      ::SetDistMap<concepts::ReadWriteMap<Node,int> >
103 103
      ::SetReachedMap<concepts::ReadWriteMap<Node,bool> >
104 104
      ::SetStandardProcessedMap
105 105
      ::SetProcessedMap<concepts::WriteMap<Node,bool> >
106 106
      ::Create bfs_test(G);
107
      
107

	
108 108
    concepts::ReadWriteMap<Node,Arc> pred_map;
109 109
    concepts::ReadWriteMap<Node,int> dist_map;
110 110
    concepts::ReadWriteMap<Node,bool> reached_map;
111 111
    concepts::WriteMap<Node,bool> processed_map;
112
    
112

	
113 113
    bfs_test
114 114
      .predMap(pred_map)
115 115
      .distMap(dist_map)
116 116
      .reachedMap(reached_map)
117 117
      .processedMap(processed_map);
118 118

	
119 119
    bfs_test.run(s);
120 120
    bfs_test.run(s,t);
121 121
    bfs_test.run();
122
    
122

	
123 123
    bfs_test.init();
124 124
    bfs_test.addSource(s);
125 125
    n = bfs_test.processNextNode();
126 126
    n = bfs_test.processNextNode(t, b);
127 127
    n = bfs_test.processNextNode(nm, n);
128 128
    n = bfs_test.nextNode();
129 129
    b = bfs_test.emptyQueue();
130 130
    i = bfs_test.queueSize();
131
    
131

	
132 132
    bfs_test.start();
133 133
    bfs_test.start(t);
134 134
    bfs_test.start(nm);
135 135

	
136 136
    l  = bfs_test.dist(t);
137 137
    e  = bfs_test.predArc(t);
138 138
    s  = bfs_test.predNode(t);
139 139
    b  = bfs_test.reached(t);
140 140
    pp = bfs_test.path(t);
141 141
  }
142 142
}
143 143

	
144 144
void checkBfsFunctionCompile()
145 145
{
146 146
  typedef int VType;
147 147
  typedef concepts::Digraph Digraph;
148 148
  typedef Digraph::Arc Arc;
149 149
  typedef Digraph::Node Node;
150 150

	
151 151
  Digraph g;
152 152
  bool b;
153 153
  bfs(g).run(Node());
154 154
  b=bfs(g).run(Node(),Node());
155 155
  bfs(g).run();
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20

	
21 21
#include "test_tools.h"
22 22
#include <lemon/list_graph.h>
23 23
#include <lemon/circulation.h>
24 24
#include <lemon/lgf_reader.h>
25 25
#include <lemon/concepts/digraph.h>
26 26
#include <lemon/concepts/maps.h>
27 27

	
28 28
using namespace lemon;
29 29

	
... ...
@@ -60,65 +60,65 @@
60 60
  typedef concepts::ReadMap<Node,VType> SupplyMap;
61 61
  typedef concepts::ReadWriteMap<Arc,VType> FlowMap;
62 62
  typedef concepts::WriteMap<Node,bool> BarrierMap;
63 63

	
64 64
  typedef Elevator<Digraph, Digraph::Node> Elev;
65 65
  typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev;
66 66

	
67 67
  Digraph g;
68 68
  Node n;
69 69
  Arc a;
70 70
  CapMap lcap, ucap;
71 71
  SupplyMap supply;
72 72
  FlowMap flow;
73 73
  BarrierMap bar;
74 74
  VType v;
75 75
  bool b;
76 76

	
77 77
  typedef Circulation<Digraph, CapMap, CapMap, SupplyMap>
78 78
            ::SetFlowMap<FlowMap>
79 79
            ::SetElevator<Elev>
80 80
            ::SetStandardElevator<LinkedElev>
81 81
            ::Create CirculationType;
82 82
  CirculationType circ_test(g, lcap, ucap, supply);
83 83
  const CirculationType& const_circ_test = circ_test;
84
   
84

	
85 85
  circ_test
86 86
    .lowerMap(lcap)
87 87
    .upperMap(ucap)
88 88
    .supplyMap(supply)
89 89
    .flowMap(flow);
90 90

	
91 91
  circ_test.init();
92 92
  circ_test.greedyInit();
93 93
  circ_test.start();
94 94
  circ_test.run();
95 95

	
96 96
  v = const_circ_test.flow(a);
97 97
  const FlowMap& fm = const_circ_test.flowMap();
98 98
  b = const_circ_test.barrier(n);
99 99
  const_circ_test.barrierMap(bar);
100
  
100

	
101 101
  ignore_unused_variable_warning(fm);
102 102
}
103 103

	
104 104
template <class G, class LM, class UM, class DM>
105 105
void checkCirculation(const G& g, const LM& lm, const UM& um,
106 106
                      const DM& dm, bool find)
107 107
{
108 108
  Circulation<G, LM, UM, DM> circ(g, lm, um, dm);
109 109
  bool ret = circ.run();
110 110
  if (find) {
111 111
    check(ret, "A feasible solution should have been found.");
112 112
    check(circ.checkFlow(), "The found flow is corrupt.");
113 113
    check(!circ.checkBarrier(), "A barrier should not have been found.");
114 114
  } else {
115 115
    check(!ret, "A feasible solution should not have been found.");
116 116
    check(circ.checkBarrier(), "The found barrier is corrupt.");
117 117
  }
118 118
}
119 119

	
120 120
int main (int, char*[])
121 121
{
122 122
  typedef ListDigraph Digraph;
123 123
  DIGRAPH_TYPEDEFS(Digraph);
124 124

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <lemon/connectivity.h>
20 20
#include <lemon/list_graph.h>
21 21
#include <lemon/adaptors.h>
22 22

	
23 23
#include "test_tools.h"
24 24

	
25 25
using namespace lemon;
26 26

	
27 27

	
28 28
int main()
29 29
{
30 30
  typedef ListDigraph Digraph;
31 31
  typedef Undirector<Digraph> Graph;
32
  
32

	
33 33
  {
34 34
    Digraph d;
35 35
    Digraph::NodeMap<int> order(d);
36 36
    Graph g(d);
37
    
37

	
38 38
    check(stronglyConnected(d), "The empty digraph is strongly connected");
39 39
    check(countStronglyConnectedComponents(d) == 0,
40 40
          "The empty digraph has 0 strongly connected component");
41 41
    check(connected(g), "The empty graph is connected");
42 42
    check(countConnectedComponents(g) == 0,
43 43
          "The empty graph has 0 connected component");
44 44

	
45 45
    check(biNodeConnected(g), "The empty graph is bi-node-connected");
46 46
    check(countBiNodeConnectedComponents(g) == 0,
47 47
          "The empty graph has 0 bi-node-connected component");
48 48
    check(biEdgeConnected(g), "The empty graph is bi-edge-connected");
49 49
    check(countBiEdgeConnectedComponents(g) == 0,
50 50
          "The empty graph has 0 bi-edge-connected component");
51
          
51

	
52 52
    check(dag(d), "The empty digraph is DAG.");
53 53
    check(checkedTopologicalSort(d, order), "The empty digraph is DAG.");
54 54
    check(loopFree(d), "The empty digraph is loop-free.");
55 55
    check(parallelFree(d), "The empty digraph is parallel-free.");
56 56
    check(simpleGraph(d), "The empty digraph is simple.");
57 57

	
58 58
    check(acyclic(g), "The empty graph is acyclic.");
59 59
    check(tree(g), "The empty graph is tree.");
60 60
    check(bipartite(g), "The empty graph is bipartite.");
61 61
    check(loopFree(g), "The empty graph is loop-free.");
62 62
    check(parallelFree(g), "The empty graph is parallel-free.");
63 63
    check(simpleGraph(g), "The empty graph is simple.");
64 64
  }
65 65

	
66 66
  {
67 67
    Digraph d;
68 68
    Digraph::NodeMap<int> order(d);
69 69
    Graph g(d);
70 70
    Digraph::Node n = d.addNode();
71 71

	
72 72
    check(stronglyConnected(d), "This digraph is strongly connected");
73 73
    check(countStronglyConnectedComponents(d) == 1,
74 74
          "This digraph has 1 strongly connected component");
75 75
    check(connected(g), "This graph is connected");
76 76
    check(countConnectedComponents(g) == 1,
77 77
          "This graph has 1 connected component");
78 78

	
79 79
    check(biNodeConnected(g), "This graph is bi-node-connected");
80 80
    check(countBiNodeConnectedComponents(g) == 0,
81 81
          "This graph has 0 bi-node-connected component");
82 82
    check(biEdgeConnected(g), "This graph is bi-edge-connected");
83 83
    check(countBiEdgeConnectedComponents(g) == 1,
84 84
          "This graph has 1 bi-edge-connected component");
85
          
85

	
86 86
    check(dag(d), "This digraph is DAG.");
87 87
    check(checkedTopologicalSort(d, order), "This digraph is DAG.");
88 88
    check(loopFree(d), "This digraph is loop-free.");
89 89
    check(parallelFree(d), "This digraph is parallel-free.");
90 90
    check(simpleGraph(d), "This digraph is simple.");
91 91

	
92 92
    check(acyclic(g), "This graph is acyclic.");
93 93
    check(tree(g), "This graph is tree.");
94 94
    check(bipartite(g), "This graph is bipartite.");
95 95
    check(loopFree(g), "This graph is loop-free.");
96 96
    check(parallelFree(g), "This graph is parallel-free.");
97 97
    check(simpleGraph(g), "This graph is simple.");
98 98
  }
99 99

	
100 100
  {
101 101
    Digraph d;
102 102
    Digraph::NodeMap<int> order(d);
103 103
    Graph g(d);
104
    
104

	
105 105
    Digraph::Node n1 = d.addNode();
106 106
    Digraph::Node n2 = d.addNode();
107 107
    Digraph::Node n3 = d.addNode();
108 108
    Digraph::Node n4 = d.addNode();
109 109
    Digraph::Node n5 = d.addNode();
110 110
    Digraph::Node n6 = d.addNode();
111
    
111

	
112 112
    d.addArc(n1, n3);
113 113
    d.addArc(n3, n2);
114 114
    d.addArc(n2, n1);
115 115
    d.addArc(n4, n2);
116 116
    d.addArc(n4, n3);
117 117
    d.addArc(n5, n6);
118 118
    d.addArc(n6, n5);
119 119

	
120 120
    check(!stronglyConnected(d), "This digraph is not strongly connected");
121 121
    check(countStronglyConnectedComponents(d) == 3,
122 122
          "This digraph has 3 strongly connected components");
123 123
    check(!connected(g), "This graph is not connected");
124 124
    check(countConnectedComponents(g) == 2,
125 125
          "This graph has 2 connected components");
126 126

	
127 127
    check(!dag(d), "This digraph is not DAG.");
128 128
    check(!checkedTopologicalSort(d, order), "This digraph is not DAG.");
129 129
    check(loopFree(d), "This digraph is loop-free.");
130 130
    check(parallelFree(d), "This digraph is parallel-free.");
131 131
    check(simpleGraph(d), "This digraph is simple.");
132 132

	
133 133
    check(!acyclic(g), "This graph is not acyclic.");
134 134
    check(!tree(g), "This graph is not tree.");
135 135
    check(!bipartite(g), "This graph is not bipartite.");
136 136
    check(loopFree(g), "This graph is loop-free.");
137 137
    check(!parallelFree(g), "This graph is not parallel-free.");
138 138
    check(!simpleGraph(g), "This graph is not simple.");
139
    
139

	
140 140
    d.addArc(n3, n3);
141
    
141

	
142 142
    check(!loopFree(d), "This digraph is not loop-free.");
143 143
    check(!loopFree(g), "This graph is not loop-free.");
144 144
    check(!simpleGraph(d), "This digraph is not simple.");
145
    
145

	
146 146
    d.addArc(n3, n2);
147
    
147

	
148 148
    check(!parallelFree(d), "This digraph is not parallel-free.");
149 149
  }
150
  
150

	
151 151
  {
152 152
    Digraph d;
153 153
    Digraph::ArcMap<bool> cutarcs(d, false);
154 154
    Graph g(d);
155
    
155

	
156 156
    Digraph::Node n1 = d.addNode();
157 157
    Digraph::Node n2 = d.addNode();
158 158
    Digraph::Node n3 = d.addNode();
159 159
    Digraph::Node n4 = d.addNode();
160 160
    Digraph::Node n5 = d.addNode();
161 161
    Digraph::Node n6 = d.addNode();
162 162
    Digraph::Node n7 = d.addNode();
163 163
    Digraph::Node n8 = d.addNode();
164 164

	
165 165
    d.addArc(n1, n2);
166 166
    d.addArc(n5, n1);
167 167
    d.addArc(n2, n8);
168 168
    d.addArc(n8, n5);
169 169
    d.addArc(n6, n4);
170 170
    d.addArc(n4, n6);
171 171
    d.addArc(n2, n5);
172 172
    d.addArc(n1, n8);
173 173
    d.addArc(n6, n7);
174 174
    d.addArc(n7, n6);
175
   
175

	
176 176
    check(!stronglyConnected(d), "This digraph is not strongly connected");
177 177
    check(countStronglyConnectedComponents(d) == 3,
178 178
          "This digraph has 3 strongly connected components");
179 179
    Digraph::NodeMap<int> scomp1(d);
180 180
    check(stronglyConnectedComponents(d, scomp1) == 3,
181 181
          "This digraph has 3 strongly connected components");
182 182
    check(scomp1[n1] != scomp1[n3] && scomp1[n1] != scomp1[n4] &&
183 183
          scomp1[n3] != scomp1[n4], "Wrong stronglyConnectedComponents()");
184 184
    check(scomp1[n1] == scomp1[n2] && scomp1[n1] == scomp1[n5] &&
185 185
          scomp1[n1] == scomp1[n8], "Wrong stronglyConnectedComponents()");
186 186
    check(scomp1[n4] == scomp1[n6] && scomp1[n4] == scomp1[n7],
187 187
          "Wrong stronglyConnectedComponents()");
188 188
    Digraph::ArcMap<bool> scut1(d, false);
189 189
    check(stronglyConnectedCutArcs(d, scut1) == 0,
190 190
          "This digraph has 0 strongly connected cut arc.");
191 191
    for (Digraph::ArcIt a(d); a != INVALID; ++a) {
192 192
      check(!scut1[a], "Wrong stronglyConnectedCutArcs()");
193 193
    }
194 194

	
195 195
    check(!connected(g), "This graph is not connected");
196 196
    check(countConnectedComponents(g) == 3,
197 197
          "This graph has 3 connected components");
198 198
    Graph::NodeMap<int> comp(g);
199 199
    check(connectedComponents(g, comp) == 3,
... ...
@@ -214,84 +214,84 @@
214 214
    check(!stronglyConnected(d), "This digraph is not strongly connected");
215 215
    check(countStronglyConnectedComponents(d) == 3,
216 216
          "This digraph has 3 strongly connected components");
217 217
    Digraph::NodeMap<int> scomp2(d);
218 218
    check(stronglyConnectedComponents(d, scomp2) == 3,
219 219
          "This digraph has 3 strongly connected components");
220 220
    check(scomp2[n3] == 0, "Wrong stronglyConnectedComponents()");
221 221
    check(scomp2[n1] == 1 && scomp2[n2] == 1 && scomp2[n5] == 1 &&
222 222
          scomp2[n8] == 1, "Wrong stronglyConnectedComponents()");
223 223
    check(scomp2[n4] == 2 && scomp2[n6] == 2 && scomp2[n7] == 2,
224 224
          "Wrong stronglyConnectedComponents()");
225 225
    Digraph::ArcMap<bool> scut2(d, false);
226 226
    check(stronglyConnectedCutArcs(d, scut2) == 5,
227 227
          "This digraph has 5 strongly connected cut arcs.");
228 228
    for (Digraph::ArcIt a(d); a != INVALID; ++a) {
229 229
      check(scut2[a] == cutarcs[a], "Wrong stronglyConnectedCutArcs()");
230 230
    }
231 231
  }
232 232

	
233 233
  {
234 234
    // DAG example for topological sort from the book New Algorithms
235 235
    // (T. H. Cormen, C. E. Leiserson, R. L. Rivest, C. Stein)
236 236
    Digraph d;
237 237
    Digraph::NodeMap<int> order(d);
238
    
238

	
239 239
    Digraph::Node belt = d.addNode();
240 240
    Digraph::Node trousers = d.addNode();
241 241
    Digraph::Node necktie = d.addNode();
242 242
    Digraph::Node coat = d.addNode();
243 243
    Digraph::Node socks = d.addNode();
244 244
    Digraph::Node shirt = d.addNode();
245 245
    Digraph::Node shoe = d.addNode();
246 246
    Digraph::Node watch = d.addNode();
247 247
    Digraph::Node pants = d.addNode();
248 248

	
249 249
    d.addArc(socks, shoe);
250 250
    d.addArc(pants, shoe);
251 251
    d.addArc(pants, trousers);
252 252
    d.addArc(trousers, shoe);
253 253
    d.addArc(trousers, belt);
254 254
    d.addArc(belt, coat);
255 255
    d.addArc(shirt, belt);
256 256
    d.addArc(shirt, necktie);
257 257
    d.addArc(necktie, coat);
258
    
258

	
259 259
    check(dag(d), "This digraph is DAG.");
260 260
    topologicalSort(d, order);
261 261
    for (Digraph::ArcIt a(d); a != INVALID; ++a) {
262 262
      check(order[d.source(a)] < order[d.target(a)],
263 263
            "Wrong topologicalSort()");
264 264
    }
265 265
  }
266 266

	
267 267
  {
268 268
    ListGraph g;
269 269
    ListGraph::NodeMap<bool> map(g);
270
    
270

	
271 271
    ListGraph::Node n1 = g.addNode();
272 272
    ListGraph::Node n2 = g.addNode();
273 273
    ListGraph::Node n3 = g.addNode();
274 274
    ListGraph::Node n4 = g.addNode();
275 275
    ListGraph::Node n5 = g.addNode();
276 276
    ListGraph::Node n6 = g.addNode();
277 277
    ListGraph::Node n7 = g.addNode();
278 278

	
279 279
    g.addEdge(n1, n3);
280 280
    g.addEdge(n1, n4);
281 281
    g.addEdge(n2, n5);
282 282
    g.addEdge(n3, n6);
283 283
    g.addEdge(n4, n6);
284 284
    g.addEdge(n4, n7);
285 285
    g.addEdge(n5, n7);
286
   
286

	
287 287
    check(bipartite(g), "This graph is bipartite");
288 288
    check(bipartitePartitions(g, map), "This graph is bipartite");
289
    
289

	
290 290
    check(map[n1] == map[n2] && map[n1] == map[n6] && map[n1] == map[n7],
291 291
          "Wrong bipartitePartitions()");
292 292
    check(map[n3] == map[n4] && map[n3] == map[n5],
293 293
          "Wrong bipartitePartitions()");
294 294
  }
295 295

	
296 296
  return 0;
297 297
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <lemon/concepts/digraph.h>
20 20
#include <lemon/smart_graph.h>
21 21
#include <lemon/list_graph.h>
22 22
#include <lemon/lgf_reader.h>
23 23
#include <lemon/dfs.h>
24 24
#include <lemon/path.h>
25 25

	
26 26
#include "graph_test.h"
27 27
#include "test_tools.h"
28 28

	
29 29
using namespace lemon;
... ...
@@ -65,92 +65,92 @@
65 65
  Digraph G;
66 66
  Node s, t;
67 67
  Arc e;
68 68
  int l, i;
69 69
  bool b;
70 70
  DType::DistMap d(G);
71 71
  DType::PredMap p(G);
72 72
  Path<Digraph> pp;
73 73
  concepts::ReadMap<Arc,bool> am;
74 74

	
75 75
  {
76 76
    DType dfs_test(G);
77 77
    const DType& const_dfs_test = dfs_test;
78 78

	
79 79
    dfs_test.run(s);
80 80
    dfs_test.run(s,t);
81 81
    dfs_test.run();
82 82

	
83 83
    dfs_test.init();
84 84
    dfs_test.addSource(s);
85 85
    e = dfs_test.processNextArc();
86 86
    e = const_dfs_test.nextArc();
87 87
    b = const_dfs_test.emptyQueue();
88 88
    i = const_dfs_test.queueSize();
89
    
89

	
90 90
    dfs_test.start();
91 91
    dfs_test.start(t);
92 92
    dfs_test.start(am);
93 93

	
94 94
    l  = const_dfs_test.dist(t);
95 95
    e  = const_dfs_test.predArc(t);
96 96
    s  = const_dfs_test.predNode(t);
97 97
    b  = const_dfs_test.reached(t);
98 98
    d  = const_dfs_test.distMap();
99 99
    p  = const_dfs_test.predMap();
100 100
    pp = const_dfs_test.path(t);
101 101
  }
102 102
  {
103 103
    DType
104 104
      ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
105 105
      ::SetDistMap<concepts::ReadWriteMap<Node,int> >
106 106
      ::SetReachedMap<concepts::ReadWriteMap<Node,bool> >
107 107
      ::SetStandardProcessedMap
108 108
      ::SetProcessedMap<concepts::WriteMap<Node,bool> >
109 109
      ::Create dfs_test(G);
110 110

	
111 111
    concepts::ReadWriteMap<Node,Arc> pred_map;
112 112
    concepts::ReadWriteMap<Node,int> dist_map;
113 113
    concepts::ReadWriteMap<Node,bool> reached_map;
114 114
    concepts::WriteMap<Node,bool> processed_map;
115
    
115

	
116 116
    dfs_test
117 117
      .predMap(pred_map)
118 118
      .distMap(dist_map)
119 119
      .reachedMap(reached_map)
120 120
      .processedMap(processed_map);
121 121

	
122 122
    dfs_test.run(s);
123 123
    dfs_test.run(s,t);
124 124
    dfs_test.run();
125 125
    dfs_test.init();
126 126

	
127 127
    dfs_test.addSource(s);
128 128
    e = dfs_test.processNextArc();
129 129
    e = dfs_test.nextArc();
130 130
    b = dfs_test.emptyQueue();
131 131
    i = dfs_test.queueSize();
132
    
132

	
133 133
    dfs_test.start();
134 134
    dfs_test.start(t);
135 135
    dfs_test.start(am);
136 136

	
137 137
    l  = dfs_test.dist(t);
138 138
    e  = dfs_test.predArc(t);
139 139
    s  = dfs_test.predNode(t);
140 140
    b  = dfs_test.reached(t);
141 141
    pp = dfs_test.path(t);
142 142
  }
143 143
}
144 144

	
145 145
void checkDfsFunctionCompile()
146 146
{
147 147
  typedef int VType;
148 148
  typedef concepts::Digraph Digraph;
149 149
  typedef Digraph::Arc Arc;
150 150
  typedef Digraph::Node Node;
151 151

	
152 152
  Digraph g;
153 153
  bool b;
154 154
  dfs(g).run(Node());
155 155
  b=dfs(g).run(Node(),Node());
156 156
  dfs(g).run();
... ...
@@ -198,37 +198,37 @@
198 198
  Path<Digraph> p = dfs_test.path(t);
199 199
  check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
200 200
  check(checkPath(G, p),"path() found a wrong path.");
201 201
  check(pathSource(G, p) == s,"path() found a wrong path.");
202 202
  check(pathTarget(G, p) == t,"path() found a wrong path.");
203 203

	
204 204
  for(NodeIt v(G); v!=INVALID; ++v) {
205 205
    if (dfs_test.reached(v)) {
206 206
      check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
207 207
      if (dfs_test.predArc(v)!=INVALID ) {
208 208
        Arc e=dfs_test.predArc(v);
209 209
        Node u=G.source(e);
210 210
        check(u==dfs_test.predNode(v),"Wrong tree.");
211 211
        check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
212 212
              "Wrong distance. (" << dfs_test.dist(u) << "->"
213 213
              << dfs_test.dist(v) << ")");
214 214
      }
215 215
    }
216 216
  }
217 217

	
218 218
  {
219 219
  Dfs<Digraph> dfs(G);
220 220
  check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6.");
221 221
  }
222
  
222

	
223 223
  {
224 224
    NullMap<Node,Arc> myPredMap;
225 225
    dfs(G).predMap(myPredMap).run(s);
226 226
  }
227 227
}
228 228

	
229 229
int main()
230 230
{
231 231
  checkDfs<ListDigraph>();
232 232
  checkDfs<SmartDigraph>();
233 233
  return 0;
234 234
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <lemon/concepts/digraph.h>
20 20
#include <lemon/smart_graph.h>
21 21
#include <lemon/list_graph.h>
22 22
#include <lemon/lgf_reader.h>
23 23
#include <lemon/dijkstra.h>
24 24
#include <lemon/path.h>
25 25
#include <lemon/bin_heap.h>
26 26

	
27 27
#include "graph_test.h"
28 28
#include "test_tools.h"
29 29

	
... ...
@@ -64,100 +64,100 @@
64 64
  Arc e;
65 65
  VType l;
66 66
  int i;
67 67
  bool b;
68 68
  DType::DistMap d(G);
69 69
  DType::PredMap p(G);
70 70
  LengthMap length;
71 71
  Path<Digraph> pp;
72 72
  concepts::ReadMap<Node,bool> nm;
73 73

	
74 74
  {
75 75
    DType dijkstra_test(G,length);
76 76
    const DType& const_dijkstra_test = dijkstra_test;
77 77

	
78 78
    dijkstra_test.run(s);
79 79
    dijkstra_test.run(s,t);
80 80

	
81 81
    dijkstra_test.init();
82 82
    dijkstra_test.addSource(s);
83 83
    dijkstra_test.addSource(s, 1);
84 84
    n = dijkstra_test.processNextNode();
85 85
    n = const_dijkstra_test.nextNode();
86 86
    b = const_dijkstra_test.emptyQueue();
87 87
    i = const_dijkstra_test.queueSize();
88
    
88

	
89 89
    dijkstra_test.start();
90 90
    dijkstra_test.start(t);
91 91
    dijkstra_test.start(nm);
92 92

	
93 93
    l  = const_dijkstra_test.dist(t);
94 94
    e  = const_dijkstra_test.predArc(t);
95 95
    s  = const_dijkstra_test.predNode(t);
96 96
    b  = const_dijkstra_test.reached(t);
97 97
    b  = const_dijkstra_test.processed(t);
98 98
    d  = const_dijkstra_test.distMap();
99 99
    p  = const_dijkstra_test.predMap();
100 100
    pp = const_dijkstra_test.path(t);
101 101
    l  = const_dijkstra_test.currentDist(t);
102 102
  }
103 103
  {
104 104
    DType
105 105
      ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
106 106
      ::SetDistMap<concepts::ReadWriteMap<Node,VType> >
107 107
      ::SetStandardProcessedMap
108 108
      ::SetProcessedMap<concepts::WriteMap<Node,bool> >
109 109
      ::SetOperationTraits<DijkstraDefaultOperationTraits<VType> >
110 110
      ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > >
111 111
      ::SetStandardHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > >
112
      ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >, 
112
      ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >,
113 113
                concepts::ReadWriteMap<Node,int> >
114 114
      ::Create dijkstra_test(G,length);
115 115

	
116 116
    LengthMap length_map;
117 117
    concepts::ReadWriteMap<Node,Arc> pred_map;
118 118
    concepts::ReadWriteMap<Node,VType> dist_map;
119 119
    concepts::WriteMap<Node,bool> processed_map;
120 120
    concepts::ReadWriteMap<Node,int> heap_cross_ref;
121 121
    BinHeap<VType, concepts::ReadWriteMap<Node,int> > heap(heap_cross_ref);
122
    
122

	
123 123
    dijkstra_test
124 124
      .lengthMap(length_map)
125 125
      .predMap(pred_map)
126 126
      .distMap(dist_map)
127 127
      .processedMap(processed_map)
128 128
      .heap(heap, heap_cross_ref);
129 129

	
130 130
    dijkstra_test.run(s);
131 131
    dijkstra_test.run(s,t);
132 132

	
133 133
    dijkstra_test.addSource(s);
134 134
    dijkstra_test.addSource(s, 1);
135 135
    n = dijkstra_test.processNextNode();
136 136
    n = dijkstra_test.nextNode();
137 137
    b = dijkstra_test.emptyQueue();
138 138
    i = dijkstra_test.queueSize();
139
    
139

	
140 140
    dijkstra_test.start();
141 141
    dijkstra_test.start(t);
142 142
    dijkstra_test.start(nm);
143 143

	
144 144
    l  = dijkstra_test.dist(t);
145 145
    e  = dijkstra_test.predArc(t);
146 146
    s  = dijkstra_test.predNode(t);
147 147
    b  = dijkstra_test.reached(t);
148 148
    b  = dijkstra_test.processed(t);
149 149
    pp = dijkstra_test.path(t);
150 150
    l  = dijkstra_test.currentDist(t);
151 151
  }
152 152

	
153 153
}
154 154

	
155 155
void checkDijkstraFunctionCompile()
156 156
{
157 157
  typedef int VType;
158 158
  typedef concepts::Digraph Digraph;
159 159
  typedef Digraph::Arc Arc;
160 160
  typedef Digraph::Node Node;
161 161
  typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap;
162 162

	
163 163
  Digraph g;
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20
#include <vector>
21 21

	
22 22
#include <lemon/concepts/digraph.h>
23 23
#include <lemon/concepts/graph.h>
24 24
#include <lemon/concept_check.h>
25 25

	
26 26
#include <lemon/list_graph.h>
27 27

	
28 28
#include <lemon/edge_set.h>
29 29

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <lemon/euler.h>
20 20
#include <lemon/list_graph.h>
21 21
#include <lemon/adaptors.h>
22 22
#include "test_tools.h"
23 23

	
24 24
using namespace lemon;
25 25

	
26 26
template <typename Digraph>
27 27
void checkDiEulerIt(const Digraph& g,
28 28
                    const typename Digraph::Node& start = INVALID)
29 29
{
... ...
@@ -64,160 +64,160 @@
64 64
  typename Graph::Node lastNode = g.target(typename Graph::Arc(e));
65 65
  if (start != INVALID) {
66 66
    check(firstNode == start, "checkEulerIt: Wrong first node");
67 67
  }
68 68

	
69 69
  for (; e != INVALID; ++e) {
70 70
    if (e != INVALID) lastNode = g.target(typename Graph::Arc(e));
71 71
    ++visitationNumber[e];
72 72
  }
73 73

	
74 74
  check(firstNode == lastNode,
75 75
      "checkEulerIt: First and last nodes are not the same");
76 76

	
77 77
  for (typename Graph::EdgeIt e(g); e != INVALID; ++e)
78 78
  {
79 79
    check(visitationNumber[e] == 1,
80 80
        "checkEulerIt: Not visited or multiple times visited edge found");
81 81
  }
82 82
}
83 83

	
84 84
int main()
85 85
{
86 86
  typedef ListDigraph Digraph;
87 87
  typedef Undirector<Digraph> Graph;
88
  
88

	
89 89
  {
90 90
    Digraph d;
91 91
    Graph g(d);
92
    
92

	
93 93
    checkDiEulerIt(d);
94 94
    checkDiEulerIt(g);
95 95
    checkEulerIt(g);
96 96

	
97 97
    check(eulerian(d), "This graph is Eulerian");
98 98
    check(eulerian(g), "This graph is Eulerian");
99 99
  }
100 100
  {
101 101
    Digraph d;
102 102
    Graph g(d);
103 103
    Digraph::Node n = d.addNode();
104 104

	
105 105
    checkDiEulerIt(d);
106 106
    checkDiEulerIt(g);
107 107
    checkEulerIt(g);
108 108

	
109 109
    check(eulerian(d), "This graph is Eulerian");
110 110
    check(eulerian(g), "This graph is Eulerian");
111 111
  }
112 112
  {
113 113
    Digraph d;
114 114
    Graph g(d);
115 115
    Digraph::Node n = d.addNode();
116 116
    d.addArc(n, n);
117 117

	
118 118
    checkDiEulerIt(d);
119 119
    checkDiEulerIt(g);
120 120
    checkEulerIt(g);
121 121

	
122 122
    check(eulerian(d), "This graph is Eulerian");
123 123
    check(eulerian(g), "This graph is Eulerian");
124 124
  }
125 125
  {
126 126
    Digraph d;
127 127
    Graph g(d);
128 128
    Digraph::Node n1 = d.addNode();
129 129
    Digraph::Node n2 = d.addNode();
130 130
    Digraph::Node n3 = d.addNode();
131
    
131

	
132 132
    d.addArc(n1, n2);
133 133
    d.addArc(n2, n1);
134 134
    d.addArc(n2, n3);
135 135
    d.addArc(n3, n2);
136 136

	
137 137
    checkDiEulerIt(d);
138 138
    checkDiEulerIt(d, n2);
139 139
    checkDiEulerIt(g);
140 140
    checkDiEulerIt(g, n2);
141 141
    checkEulerIt(g);
142 142
    checkEulerIt(g, n2);
143 143

	
144 144
    check(eulerian(d), "This graph is Eulerian");
145 145
    check(eulerian(g), "This graph is Eulerian");
146 146
  }
147 147
  {
148 148
    Digraph d;
149 149
    Graph g(d);
150 150
    Digraph::Node n1 = d.addNode();
151 151
    Digraph::Node n2 = d.addNode();
152 152
    Digraph::Node n3 = d.addNode();
153 153
    Digraph::Node n4 = d.addNode();
154 154
    Digraph::Node n5 = d.addNode();
155 155
    Digraph::Node n6 = d.addNode();
156
    
156

	
157 157
    d.addArc(n1, n2);
158 158
    d.addArc(n2, n4);
159 159
    d.addArc(n1, n3);
160 160
    d.addArc(n3, n4);
161 161
    d.addArc(n4, n1);
162 162
    d.addArc(n3, n5);
163 163
    d.addArc(n5, n2);
164 164
    d.addArc(n4, n6);
165 165
    d.addArc(n2, n6);
166 166
    d.addArc(n6, n1);
167 167
    d.addArc(n6, n3);
168 168

	
169 169
    checkDiEulerIt(d);
170 170
    checkDiEulerIt(d, n1);
171 171
    checkDiEulerIt(d, n5);
172 172

	
173 173
    checkDiEulerIt(g);
174 174
    checkDiEulerIt(g, n1);
175 175
    checkDiEulerIt(g, n5);
176 176
    checkEulerIt(g);
177 177
    checkEulerIt(g, n1);
178 178
    checkEulerIt(g, n5);
179 179

	
180 180
    check(eulerian(d), "This graph is Eulerian");
181 181
    check(eulerian(g), "This graph is Eulerian");
182 182
  }
183 183
  {
184 184
    Digraph d;
185 185
    Graph g(d);
186 186
    Digraph::Node n0 = d.addNode();
187 187
    Digraph::Node n1 = d.addNode();
188 188
    Digraph::Node n2 = d.addNode();
189 189
    Digraph::Node n3 = d.addNode();
190 190
    Digraph::Node n4 = d.addNode();
191 191
    Digraph::Node n5 = d.addNode();
192
    
192

	
193 193
    d.addArc(n1, n2);
194 194
    d.addArc(n2, n3);
195 195
    d.addArc(n3, n1);
196 196

	
197 197
    checkDiEulerIt(d);
198 198
    checkDiEulerIt(d, n2);
199 199

	
200 200
    checkDiEulerIt(g);
201 201
    checkDiEulerIt(g, n2);
202 202
    checkEulerIt(g);
203 203
    checkEulerIt(g, n2);
204 204

	
205 205
    check(!eulerian(d), "This graph is not Eulerian");
206 206
    check(!eulerian(g), "This graph is not Eulerian");
207 207
  }
208 208
  {
209 209
    Digraph d;
210 210
    Graph g(d);
211 211
    Digraph::Node n1 = d.addNode();
212 212
    Digraph::Node n2 = d.addNode();
213 213
    Digraph::Node n3 = d.addNode();
214
    
214

	
215 215
    d.addArc(n1, n2);
216 216
    d.addArc(n2, n3);
217 217

	
218 218
    check(!eulerian(d), "This graph is not Eulerian");
219 219
    check(!eulerian(g), "This graph is not Eulerian");
220 220
  }
221 221

	
222 222
  return 0;
223 223
}
Ignore white space 6 line context
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library.
4
 *
5
 * Copyright (C) 2003-2011
6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
 *
9
 * Permission to use, modify and distribute this software is granted
10
 * provided that this copyright notice appears in all copies. For
11
 * precise terms see the accompanying LICENSE file.
12
 *
13
 * This software is provided "AS IS" with no warranty of any kind,
14
 * express or implied, and with no claim as to its suitability for any
15
 * purpose.
16
 *
17
 */
18

	
1 19
#include <iostream>
2 20

	
3 21
#include "test_tools.h"
4 22
#include <lemon/smart_graph.h>
5 23
#include <lemon/concepts/graph.h>
6 24
#include <lemon/concepts/maps.h>
7 25
#include <lemon/lgf_reader.h>
8 26
#include <lemon/gomory_hu.h>
9 27
#include <cstdlib>
10 28

	
11 29
using namespace std;
12 30
using namespace lemon;
13 31

	
14 32
typedef SmartGraph Graph;
15 33

	
16 34
char test_lgf[] =
17 35
  "@nodes\n"
18 36
  "label\n"
19 37
  "0\n"
20 38
  "1\n"
21 39
  "2\n"
22 40
  "3\n"
23 41
  "4\n"
24 42
  "@arcs\n"
25 43
  "     label capacity\n"
26 44
  "0 1  0     1\n"
27 45
  "1 2  1     1\n"
28 46
  "2 3  2     1\n"
29 47
  "0 3  4     5\n"
30 48
  "0 3  5     10\n"
31 49
  "0 3  6     7\n"
32 50
  "4 2  7     1\n"
33 51
  "@attributes\n"
34 52
  "source 0\n"
35 53
  "target 3\n";
36
  
54

	
37 55
void checkGomoryHuCompile()
38 56
{
39 57
  typedef int Value;
40 58
  typedef concepts::Graph Graph;
41 59

	
42 60
  typedef Graph::Node Node;
43 61
  typedef Graph::Edge Edge;
44 62
  typedef concepts::ReadMap<Edge, Value> CapMap;
45 63
  typedef concepts::ReadWriteMap<Node, bool> CutMap;
46 64

	
47 65
  Graph g;
48 66
  Node n;
49 67
  CapMap cap;
50 68
  CutMap cut;
51 69
  Value v;
52 70
  int d;
53 71

	
54 72
  GomoryHu<Graph, CapMap> gh_test(g, cap);
55 73
  const GomoryHu<Graph, CapMap>&
56 74
    const_gh_test = gh_test;
57 75

	
58 76
  gh_test.run();
59 77

	
60 78
  n = const_gh_test.predNode(n);
61 79
  v = const_gh_test.predValue(n);
62 80
  d = const_gh_test.rootDist(n);
63 81
  v = const_gh_test.minCutValue(n, n);
64 82
  v = const_gh_test.minCutMap(n, n, cut);
65 83
}
66 84

	
67 85
GRAPH_TYPEDEFS(Graph);
68 86
typedef Graph::EdgeMap<int> IntEdgeMap;
69 87
typedef Graph::NodeMap<bool> BoolNodeMap;
70 88

	
71 89
int cutValue(const Graph& graph, const BoolNodeMap& cut,
72
	     const IntEdgeMap& capacity) {
90
             const IntEdgeMap& capacity) {
73 91

	
74 92
  int sum = 0;
75 93
  for (EdgeIt e(graph); e != INVALID; ++e) {
76 94
    Node s = graph.u(e);
77 95
    Node t = graph.v(e);
78 96

	
79 97
    if (cut[s] != cut[t]) {
80 98
      sum += capacity[e];
81 99
    }
82 100
  }
83 101
  return sum;
84 102
}
85 103

	
86 104

	
87 105
int main() {
88 106
  Graph graph;
89 107
  IntEdgeMap capacity(graph);
90 108

	
91 109
  std::istringstream input(test_lgf);
92 110
  GraphReader<Graph>(graph, input).
93 111
    edgeMap("capacity", capacity).run();
94 112

	
95 113
  GomoryHu<Graph> ght(graph, capacity);
96 114
  ght.run();
97 115

	
98 116
  for (NodeIt u(graph); u != INVALID; ++u) {
99 117
    for (NodeIt v(graph); v != u; ++v) {
100 118
      Preflow<Graph, IntEdgeMap> pf(graph, capacity, u, v);
101 119
      pf.runMinCut();
102 120
      BoolNodeMap cm(graph);
103 121
      ght.minCutMap(u, v, cm);
104 122
      check(pf.flowValue() == ght.minCutValue(u, v), "Wrong cut 1");
105 123
      check(cm[u] != cm[v], "Wrong cut 2");
106 124
      check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 3");
107 125

	
108 126
      int sum=0;
109 127
      for(GomoryHu<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a)
110
        sum+=capacity[a]; 
128
        sum+=capacity[a];
111 129
      check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt");
112 130

	
113 131
      sum=0;
114 132
      for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,true);n!=INVALID;++n)
115 133
        sum++;
116 134
      for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,false);n!=INVALID;++n)
117 135
        sum++;
118 136
      check(sum == countNodes(graph), "Problem with MinCutNodeIt");
119 137
    }
120 138
  }
121
  
139

	
122 140
  return 0;
123 141
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <lemon/smart_graph.h>
20 20
#include <lemon/list_graph.h>
21 21
#include <lemon/lgf_reader.h>
22 22
#include <lemon/error.h>
23 23

	
24 24
#include "test_tools.h"
25 25

	
26 26
using namespace std;
27 27
using namespace lemon;
28 28

	
29 29
void digraph_copy_test() {
... ...
@@ -49,77 +49,77 @@
49 49
      SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]);
50 50
      fam[arc] = i + j * j;
51 51
      if (i == 0 && j == 0) fa = arc;
52 52
    }
53 53
  }
54 54

	
55 55
  // Test digraph copy
56 56
  ListDigraph to;
57 57
  ListDigraph::NodeMap<int> tnm(to);
58 58
  ListDigraph::ArcMap<int> tam(to);
59 59
  ListDigraph::Node tn;
60 60
  ListDigraph::Arc ta;
61 61

	
62 62
  SmartDigraph::NodeMap<ListDigraph::Node> nr(from);
63 63
  SmartDigraph::ArcMap<ListDigraph::Arc> er(from);
64 64

	
65 65
  ListDigraph::NodeMap<SmartDigraph::Node> ncr(to);
66 66
  ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to);
67 67

	
68 68
  digraphCopy(from, to).
69 69
    nodeMap(fnm, tnm).arcMap(fam, tam).
70 70
    nodeRef(nr).arcRef(er).
71 71
    nodeCrossRef(ncr).arcCrossRef(ecr).
72 72
    node(fn, tn).arc(fa, ta).run();
73
  
73

	
74 74
  check(countNodes(from) == countNodes(to), "Wrong copy.");
75 75
  check(countArcs(from) == countArcs(to), "Wrong copy.");
76 76

	
77 77
  for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
78 78
    check(ncr[nr[it]] == it, "Wrong copy.");
79 79
    check(fnm[it] == tnm[nr[it]], "Wrong copy.");
80 80
  }
81 81

	
82 82
  for (SmartDigraph::ArcIt it(from); it != INVALID; ++it) {
83 83
    check(ecr[er[it]] == it, "Wrong copy.");
84 84
    check(fam[it] == tam[er[it]], "Wrong copy.");
85 85
    check(nr[from.source(it)] == to.source(er[it]), "Wrong copy.");
86 86
    check(nr[from.target(it)] == to.target(er[it]), "Wrong copy.");
87 87
  }
88 88

	
89 89
  for (ListDigraph::NodeIt it(to); it != INVALID; ++it) {
90 90
    check(nr[ncr[it]] == it, "Wrong copy.");
91 91
  }
92 92

	
93 93
  for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
94 94
    check(er[ecr[it]] == it, "Wrong copy.");
95 95
  }
96 96
  check(tn == nr[fn], "Wrong copy.");
97 97
  check(ta == er[fa], "Wrong copy.");
98 98

	
99 99
  // Test repeated copy
100 100
  digraphCopy(from, to).run();
101
  
101

	
102 102
  check(countNodes(from) == countNodes(to), "Wrong copy.");
103 103
  check(countArcs(from) == countArcs(to), "Wrong copy.");
104 104
}
105 105

	
106 106
void graph_copy_test() {
107 107
  const int nn = 10;
108 108

	
109 109
  // Build a graph
110 110
  SmartGraph from;
111 111
  SmartGraph::NodeMap<int> fnm(from);
112 112
  SmartGraph::ArcMap<int> fam(from);
113 113
  SmartGraph::EdgeMap<int> fem(from);
114 114
  SmartGraph::Node fn = INVALID;
115 115
  SmartGraph::Arc fa = INVALID;
116 116
  SmartGraph::Edge fe = INVALID;
117 117

	
118 118
  std::vector<SmartGraph::Node> fnv;
119 119
  for (int i = 0; i < nn; ++i) {
120 120
    SmartGraph::Node node = from.addNode();
121 121
    fnv.push_back(node);
122 122
    fnm[node] = i * i;
123 123
    if (i == 0) fn = node;
124 124
  }
125 125

	
... ...
@@ -179,37 +179,37 @@
179 179
    check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]),
180 180
          "Wrong copy.");
181 181
    check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]),
182 182
          "Wrong copy.");
183 183
    check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
184 184
          "Wrong copy.");
185 185
  }
186 186

	
187 187
  for (ListGraph::NodeIt it(to); it != INVALID; ++it) {
188 188
    check(nr[ncr[it]] == it, "Wrong copy.");
189 189
  }
190 190

	
191 191
  for (ListGraph::ArcIt it(to); it != INVALID; ++it) {
192 192
    check(ar[acr[it]] == it, "Wrong copy.");
193 193
  }
194 194
  for (ListGraph::EdgeIt it(to); it != INVALID; ++it) {
195 195
    check(er[ecr[it]] == it, "Wrong copy.");
196 196
  }
197 197
  check(tn == nr[fn], "Wrong copy.");
198 198
  check(ta == ar[fa], "Wrong copy.");
199 199
  check(te == er[fe], "Wrong copy.");
200 200

	
201 201
  // Test repeated copy
202 202
  graphCopy(from, to).run();
203
  
203

	
204 204
  check(countNodes(from) == countNodes(to), "Wrong copy.");
205 205
  check(countEdges(from) == countEdges(to), "Wrong copy.");
206 206
  check(countArcs(from) == countArcs(to), "Wrong copy.");
207 207
}
208 208

	
209 209

	
210 210
int main() {
211 211
  digraph_copy_test();
212 212
  graph_copy_test();
213 213

	
214 214
  return 0;
215 215
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <sstream>
20 20

	
21 21
#include <lemon/smart_graph.h>
22 22
#include <lemon/adaptors.h>
23 23
#include <lemon/concepts/digraph.h>
24 24
#include <lemon/concepts/maps.h>
25 25
#include <lemon/lgf_reader.h>
26 26
#include <lemon/hao_orlin.h>
27 27

	
28 28
#include "test_tools.h"
29 29

	
... ...
@@ -62,102 +62,102 @@
62 62
  typedef concepts::WriteMap<Node, bool> CutMap;
63 63

	
64 64
  Digraph g;
65 65
  Node n;
66 66
  CapMap cap;
67 67
  CutMap cut;
68 68
  Value v;
69 69

	
70 70
  HaoOrlin<Digraph, CapMap> ho_test(g, cap);
71 71
  const HaoOrlin<Digraph, CapMap>&
72 72
    const_ho_test = ho_test;
73 73

	
74 74
  ho_test.init();
75 75
  ho_test.init(n);
76 76
  ho_test.calculateOut();
77 77
  ho_test.calculateIn();
78 78
  ho_test.run();
79 79
  ho_test.run(n);
80 80

	
81 81
  v = const_ho_test.minCutValue();
82 82
  v = const_ho_test.minCutMap(cut);
83 83
}
84 84

	
85 85
template <typename Graph, typename CapMap, typename CutMap>
86
typename CapMap::Value 
86
typename CapMap::Value
87 87
  cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
88 88
{
89 89
  typename CapMap::Value sum = 0;
90 90
  for (typename Graph::ArcIt a(graph); a != INVALID; ++a) {
91 91
    if (cut[graph.source(a)] && !cut[graph.target(a)])
92 92
      sum += cap[a];
93 93
  }
94 94
  return sum;
95 95
}
96 96

	
97 97
int main() {
98 98
  SmartDigraph graph;
99 99
  SmartDigraph::ArcMap<int> cap1(graph), cap2(graph), cap3(graph);
100 100
  SmartDigraph::NodeMap<bool> cut(graph);
101 101

	
102 102
  istringstream input(lgf);
103 103
  digraphReader(graph, input)
104 104
    .arcMap("cap1", cap1)
105 105
    .arcMap("cap2", cap2)
106 106
    .arcMap("cap3", cap3)
107 107
    .run();
108 108

	
109 109
  {
110 110
    HaoOrlin<SmartDigraph> ho(graph, cap1);
111 111
    ho.run();
112 112
    ho.minCutMap(cut);
113
    
113

	
114 114
    check(ho.minCutValue() == 1, "Wrong cut value");
115 115
    check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
116 116
  }
117 117
  {
118 118
    HaoOrlin<SmartDigraph> ho(graph, cap2);
119 119
    ho.run();
120 120
    ho.minCutMap(cut);
121 121

	
122 122
    check(ho.minCutValue() == 1, "Wrong cut value");
123 123
    check(ho.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
124 124
  }
125 125
  {
126 126
    HaoOrlin<SmartDigraph> ho(graph, cap3);
127 127
    ho.run();
128 128
    ho.minCutMap(cut);
129
    
129

	
130 130
    check(ho.minCutValue() == 1, "Wrong cut value");
131 131
    check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
132 132
  }
133
  
133

	
134 134
  typedef Undirector<SmartDigraph> UGraph;
135 135
  UGraph ugraph(graph);
136
  
136

	
137 137
  {
138 138
    HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1);
139 139
    ho.run();
140 140
    ho.minCutMap(cut);
141
    
141

	
142 142
    check(ho.minCutValue() == 2, "Wrong cut value");
143 143
    check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value");
144 144
  }
145 145
  {
146 146
    HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap2);
147 147
    ho.run();
148 148
    ho.minCutMap(cut);
149
    
149

	
150 150
    check(ho.minCutValue() == 5, "Wrong cut value");
151 151
    check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value");
152 152
  }
153 153
  {
154 154
    HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap3);
155 155
    ho.run();
156 156
    ho.minCutMap(cut);
157
    
157

	
158 158
    check(ho.minCutValue() == 5, "Wrong cut value");
159 159
    check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value");
160 160
  }
161 161

	
162 162
  return 0;
163 163
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20
#include <fstream>
21 21
#include <string>
22 22
#include <vector>
23 23

	
24 24
#include <lemon/concept_check.h>
25 25
#include <lemon/concepts/heap.h>
26 26

	
27 27
#include <lemon/smart_graph.h>
28 28

	
29 29
#include <lemon/lgf_reader.h>
Ignore white space 6 line context
... ...
@@ -42,125 +42,125 @@
42 42
  "1\n"
43 43
  "@arcs\n"
44 44
  "     -\n"
45 45
  "0 1\n";
46 46

	
47 47
char test_lgf_bad1[] =
48 48
  "@nodes\n"
49 49
  "label\n"
50 50
  "0\n"
51 51
  "1\n"
52 52
  "@arcs\n"
53 53
  "     - another\n"
54 54
  "0 1\n";
55 55

	
56 56
char test_lgf_bad2[] =
57 57
  "@nodes\n"
58 58
  "label\n"
59 59
  "0\n"
60 60
  "1\n"
61 61
  "@arcs\n"
62 62
  "     label -\n"
63 63
  "0 1\n";
64 64

	
65 65

	
66
int main() 
66
int main()
67 67
{
68 68
  {
69
    ListDigraph d; 
69
    ListDigraph d;
70 70
    ListDigraph::Node s,t;
71 71
    ListDigraph::ArcMap<int> label(d);
72 72
    std::istringstream input(test_lgf);
73 73
    digraphReader(d, input).
74 74
      node("source", s).
75 75
      node("target", t).
76 76
      arcMap("label", label).
77 77
      run();
78 78
    check(countNodes(d) == 2,"There should be 2 nodes");
79 79
    check(countArcs(d) == 2,"There should be 2 arcs");
80 80
  }
81 81
  {
82 82
    ListGraph g;
83 83
    ListGraph::Node s,t;
84 84
    ListGraph::EdgeMap<int> label(g);
85 85
    std::istringstream input(test_lgf);
86 86
    graphReader(g, input).
87 87
      node("source", s).
88 88
      node("target", t).
89 89
      edgeMap("label", label).
90 90
      run();
91 91
    check(countNodes(g) == 2,"There should be 2 nodes");
92 92
    check(countEdges(g) == 2,"There should be 2 arcs");
93 93
  }
94 94

	
95 95
  {
96
    ListDigraph d; 
96
    ListDigraph d;
97 97
    std::istringstream input(test_lgf_nomap);
98 98
    digraphReader(d, input).
99 99
      run();
100 100
    check(countNodes(d) == 2,"There should be 2 nodes");
101 101
    check(countArcs(d) == 1,"There should be 1 arc");
102 102
  }
103 103
  {
104 104
    ListGraph g;
105 105
    std::istringstream input(test_lgf_nomap);
106 106
    graphReader(g, input).
107 107
      run();
108 108
    check(countNodes(g) == 2,"There should be 2 nodes");
109 109
    check(countEdges(g) == 1,"There should be 1 edge");
110 110
  }
111 111

	
112 112
  {
113
    ListDigraph d; 
113
    ListDigraph d;
114 114
    std::istringstream input(test_lgf_bad1);
115 115
    bool ok=false;
116 116
    try {
117 117
      digraphReader(d, input).
118 118
        run();
119 119
    }
120
    catch (FormatError& error) 
120
    catch (FormatError& error)
121 121
      {
122 122
        ok = true;
123 123
      }
124 124
    check(ok,"FormatError exception should have occured");
125 125
  }
126 126
  {
127 127
    ListGraph g;
128 128
    std::istringstream input(test_lgf_bad1);
129 129
    bool ok=false;
130 130
    try {
131 131
      graphReader(g, input).
132 132
        run();
133 133
    }
134 134
    catch (FormatError& error)
135 135
      {
136 136
        ok = true;
137 137
      }
138 138
    check(ok,"FormatError exception should have occured");
139 139
  }
140 140

	
141 141
  {
142
    ListDigraph d; 
142
    ListDigraph d;
143 143
    std::istringstream input(test_lgf_bad2);
144 144
    bool ok=false;
145 145
    try {
146 146
      digraphReader(d, input).
147 147
        run();
148 148
    }
149 149
    catch (FormatError& error)
150 150
      {
151 151
        ok = true;
152 152
      }
153 153
    check(ok,"FormatError exception should have occured");
154 154
  }
155 155
  {
156 156
    ListGraph g;
157 157
    std::istringstream input(test_lgf_bad2);
158 158
    bool ok=false;
159 159
    try {
160 160
      graphReader(g, input).
161 161
        run();
162 162
    }
163 163
    catch (FormatError& error)
164 164
      {
165 165
        ok = true;
166 166
      }
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <deque>
20 20
#include <set>
21 21

	
22 22
#include <lemon/concept_check.h>
23 23
#include <lemon/concepts/maps.h>
24 24
#include <lemon/maps.h>
25 25
#include <lemon/list_graph.h>
26 26

	
27 27
#include "test_tools.h"
28 28

	
29 29
using namespace lemon;
... ...
@@ -49,50 +49,52 @@
49 49
  F& operator=(const F&);
50 50
};
51 51

	
52 52
int func(A) { return 3; }
53 53

	
54 54
int binc(int a, B) { return a+1; }
55 55

	
56 56
typedef ReadMap<A, double> DoubleMap;
57 57
typedef ReadWriteMap<A, double> DoubleWriteMap;
58 58
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
59 59

	
60 60
typedef ReadMap<A, bool> BoolMap;
61 61
typedef ReadWriteMap<A, bool> BoolWriteMap;
62 62
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
63 63

	
64 64
int main()
65 65
{
66 66
  // Map concepts
67 67
  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
68 68
  checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
69 69
  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
70 70
  checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
71 71
  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
72 72
  checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
73
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
74
  checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
73
  checkConcept<ReferenceMap<A,B,B&,const B&>,
74
               ReferenceMap<A,B,B&,const B&> >();
75
  checkConcept<ReferenceMap<A,C,C&,const C&>,
76
               ReferenceMap<A,C,C&,const C&> >();
75 77

	
76 78
  // NullMap
77 79
  {
78 80
    checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
79 81
    NullMap<A,B> map1;
80 82
    NullMap<A,B> map2 = map1;
81 83
    map1 = nullMap<A,B>();
82 84
  }
83 85

	
84 86
  // ConstMap
85 87
  {
86 88
    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
87 89
    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
88 90
    ConstMap<A,B> map1;
89 91
    ConstMap<A,B> map2 = B();
90 92
    ConstMap<A,B> map3 = map1;
91 93
    map1 = constMap<A>(B());
92 94
    map1 = constMap<A,B>();
93 95
    map1.setAll(B());
94 96
    ConstMap<A,C> map4(C(1));
95 97
    ConstMap<A,C> map5 = map4;
96 98
    map4 = constMap<A>(C(2));
97 99
    map4.setAll(C(3));
98 100

	
... ...
@@ -179,49 +181,50 @@
179 181
    check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
180 182
          "Something is wrong with ComposeMap")
181 183
  }
182 184

	
183 185
  // CombineMap
184 186
  {
185 187
    typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
186 188
    checkConcept<ReadMap<A,double>, CombMap>();
187 189
    CombMap map1 = CombMap(DoubleMap(), DoubleMap());
188 190
    CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
189 191

	
190 192
    check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
191 193
          "Something is wrong with CombineMap");
192 194
  }
193 195

	
194 196
  // FunctorToMap, MapToFunctor
195 197
  {
196 198
    checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
197 199
    checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
198 200
    FunctorToMap<F> map1;
199 201
    FunctorToMap<F> map2 = FunctorToMap<F>(F());
200 202
    B b = functorToMap(F())[A()];
201 203

	
202 204
    checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
203
    MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
205
    MapToFunctor<ReadMap<A,B> > map =
206
      MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
204 207

	
205 208
    check(functorToMap(&func)[A()] == 3,
206 209
          "Something is wrong with FunctorToMap");
207 210
    check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
208 211
          "Something is wrong with MapToFunctor");
209 212
    check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
210 213
          mapToFunctor(functorToMap(&func))[A()] == 3,
211 214
          "Something is wrong with FunctorToMap or MapToFunctor");
212 215
    check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
213 216
          "Something is wrong with FunctorToMap or MapToFunctor");
214 217
  }
215 218

	
216 219
  // ConvertMap
217 220
  {
218 221
    checkConcept<ReadMap<double,double>,
219 222
      ConvertMap<ReadMap<double, int>, double> >();
220 223
    ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
221 224
    ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
222 225
  }
223 226

	
224 227
  // ForkMap
225 228
  {
226 229
    checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
227 230

	
... ...
@@ -328,61 +331,61 @@
328 331

	
329 332
  // LoggerBoolMap
330 333
  {
331 334
    typedef std::vector<int> vec;
332 335
    vec v1;
333 336
    vec v2(10);
334 337
    LoggerBoolMap<std::back_insert_iterator<vec> >
335 338
      map1(std::back_inserter(v1));
336 339
    LoggerBoolMap<vec::iterator> map2(v2.begin());
337 340
    map1.set(10, false);
338 341
    map1.set(20, true);   map2.set(20, true);
339 342
    map1.set(30, false);  map2.set(40, false);
340 343
    map1.set(50, true);   map2.set(50, true);
341 344
    map1.set(60, true);   map2.set(60, true);
342 345
    check(v1.size() == 3 && v2.size() == 10 &&
343 346
          v1[0]==20 && v1[1]==50 && v1[2]==60 &&
344 347
          v2[0]==20 && v2[1]==50 && v2[2]==60,
345 348
          "Something is wrong with LoggerBoolMap");
346 349

	
347 350
    int i = 0;
348 351
    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
349 352
          it != map2.end(); ++it )
350 353
      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
351 354
  }
352
  
355

	
353 356
  // CrossRefMap
354 357
  {
355 358
    typedef ListDigraph Graph;
356 359
    DIGRAPH_TYPEDEFS(Graph);
357 360

	
358 361
    checkConcept<ReadWriteMap<Node, int>,
359 362
                 CrossRefMap<Graph, Node, int> >();
360
    
363

	
361 364
    Graph gr;
362 365
    typedef CrossRefMap<Graph, Node, char> CRMap;
363 366
    typedef CRMap::ValueIterator ValueIt;
364 367
    CRMap map(gr);
365
    
368

	
366 369
    Node n0 = gr.addNode();
367 370
    Node n1 = gr.addNode();
368 371
    Node n2 = gr.addNode();
369
    
372

	
370 373
    map.set(n0, 'A');
371 374
    map.set(n1, 'B');
372 375
    map.set(n2, 'C');
373 376
    map.set(n2, 'A');
374 377
    map.set(n0, 'C');
375 378

	
376 379
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
377 380
          "Wrong CrossRefMap");
378 381
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
379 382
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
380 383
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
381 384

	
382 385
    ValueIt it = map.beginValue();
383 386
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
384 387
          it == map.endValue(), "Wrong value iterator");
385 388
  }
386 389

	
387 390
  return 0;
388 391
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20
#include <sstream>
21 21
#include <vector>
22 22
#include <queue>
23 23
#include <cstdlib>
24 24

	
25 25
#include <lemon/matching.h>
26 26
#include <lemon/smart_graph.h>
27 27
#include <lemon/concepts/graph.h>
28 28
#include <lemon/concepts/maps.h>
29 29
#include <lemon/lgf_reader.h>
... ...
@@ -113,130 +113,130 @@
113 113
};
114 114

	
115 115
void checkMaxMatchingCompile()
116 116
{
117 117
  typedef concepts::Graph Graph;
118 118
  typedef Graph::Node Node;
119 119
  typedef Graph::Edge Edge;
120 120
  typedef Graph::EdgeMap<bool> MatMap;
121 121

	
122 122
  Graph g;
123 123
  Node n;
124 124
  Edge e;
125 125
  MatMap mat(g);
126 126

	
127 127
  MaxMatching<Graph> mat_test(g);
128 128
  const MaxMatching<Graph>&
129 129
    const_mat_test = mat_test;
130 130

	
131 131
  mat_test.init();
132 132
  mat_test.greedyInit();
133 133
  mat_test.matchingInit(mat);
134 134
  mat_test.startSparse();
135 135
  mat_test.startDense();
136 136
  mat_test.run();
137
  
137

	
138 138
  const_mat_test.matchingSize();
139 139
  const_mat_test.matching(e);
140 140
  const_mat_test.matching(n);
141 141
  const MaxMatching<Graph>::MatchingMap& mmap =
142 142
    const_mat_test.matchingMap();
143 143
  e = mmap[n];
144 144
  const_mat_test.mate(n);
145 145

	
146
  MaxMatching<Graph>::Status stat = 
146
  MaxMatching<Graph>::Status stat =
147 147
    const_mat_test.status(n);
148 148
  const MaxMatching<Graph>::StatusMap& smap =
149 149
    const_mat_test.statusMap();
150 150
  stat = smap[n];
151 151
  const_mat_test.barrier(n);
152 152
}
153 153

	
154 154
void checkMaxWeightedMatchingCompile()
155 155
{
156 156
  typedef concepts::Graph Graph;
157 157
  typedef Graph::Node Node;
158 158
  typedef Graph::Edge Edge;
159 159
  typedef Graph::EdgeMap<int> WeightMap;
160 160

	
161 161
  Graph g;
162 162
  Node n;
163 163
  Edge e;
164 164
  WeightMap w(g);
165 165

	
166 166
  MaxWeightedMatching<Graph> mat_test(g, w);
167 167
  const MaxWeightedMatching<Graph>&
168 168
    const_mat_test = mat_test;
169 169

	
170 170
  mat_test.init();
171 171
  mat_test.start();
172 172
  mat_test.run();
173
  
173

	
174 174
  const_mat_test.matchingWeight();
175 175
  const_mat_test.matchingSize();
176 176
  const_mat_test.matching(e);
177 177
  const_mat_test.matching(n);
178 178
  const MaxWeightedMatching<Graph>::MatchingMap& mmap =
179 179
    const_mat_test.matchingMap();
180 180
  e = mmap[n];
181 181
  const_mat_test.mate(n);
182
  
182

	
183 183
  int k = 0;
184 184
  const_mat_test.dualValue();
185 185
  const_mat_test.nodeValue(n);
186 186
  const_mat_test.blossomNum();
187 187
  const_mat_test.blossomSize(k);
188 188
  const_mat_test.blossomValue(k);
189 189
}
190 190

	
191 191
void checkMaxWeightedPerfectMatchingCompile()
192 192
{
193 193
  typedef concepts::Graph Graph;
194 194
  typedef Graph::Node Node;
195 195
  typedef Graph::Edge Edge;
196 196
  typedef Graph::EdgeMap<int> WeightMap;
197 197

	
198 198
  Graph g;
199 199
  Node n;
200 200
  Edge e;
201 201
  WeightMap w(g);
202 202

	
203 203
  MaxWeightedPerfectMatching<Graph> mat_test(g, w);
204 204
  const MaxWeightedPerfectMatching<Graph>&
205 205
    const_mat_test = mat_test;
206 206

	
207 207
  mat_test.init();
208 208
  mat_test.start();
209 209
  mat_test.run();
210
  
210

	
211 211
  const_mat_test.matchingWeight();
212 212
  const_mat_test.matching(e);
213 213
  const_mat_test.matching(n);
214 214
  const MaxWeightedPerfectMatching<Graph>::MatchingMap& mmap =
215 215
    const_mat_test.matchingMap();
216 216
  e = mmap[n];
217 217
  const_mat_test.mate(n);
218
  
218

	
219 219
  int k = 0;
220 220
  const_mat_test.dualValue();
221 221
  const_mat_test.nodeValue(n);
222 222
  const_mat_test.blossomNum();
223 223
  const_mat_test.blossomSize(k);
224 224
  const_mat_test.blossomValue(k);
225 225
}
226 226

	
227 227
void checkMatching(const SmartGraph& graph,
228 228
                   const MaxMatching<SmartGraph>& mm) {
229 229
  int num = 0;
230 230

	
231 231
  IntNodeMap comp_index(graph);
232 232
  UnionFind<IntNodeMap> comp(comp_index);
233 233

	
234 234
  int barrier_num = 0;
235 235

	
236 236
  for (NodeIt n(graph); n != INVALID; ++n) {
237 237
    check(mm.status(n) == MaxMatching<SmartGraph>::EVEN ||
238 238
          mm.matching(n) != INVALID, "Wrong Gallai-Edmonds decomposition");
239 239
    if (mm.status(n) == MaxMatching<SmartGraph>::ODD) {
240 240
      ++barrier_num;
241 241
    } else {
242 242
      comp.insert(n);
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20
#include <set>
21 21
#include <vector>
22 22
#include <iterator>
23 23

	
24 24
#include <lemon/smart_graph.h>
25 25
#include <lemon/min_cost_arborescence.h>
26 26
#include <lemon/lgf_reader.h>
27 27
#include <lemon/concepts/digraph.h>
28 28

	
29 29
#include "test_tools.h"
... ...
@@ -89,64 +89,64 @@
89 89
  Digraph g;
90 90
  Node s, n;
91 91
  Arc e;
92 92
  VType c;
93 93
  bool b;
94 94
  int i;
95 95
  CostMap cost;
96 96
  ArbMap arb;
97 97
  PredMap pred;
98 98

	
99 99
  MinCostArbType mcarb_test(g, cost);
100 100
  const MinCostArbType& const_mcarb_test = mcarb_test;
101 101

	
102 102
  mcarb_test
103 103
    .arborescenceMap(arb)
104 104
    .predMap(pred)
105 105
    .run(s);
106 106

	
107 107
  mcarb_test.init();
108 108
  mcarb_test.addSource(s);
109 109
  mcarb_test.start();
110 110
  n = mcarb_test.processNextNode();
111 111
  b = const_mcarb_test.emptyQueue();
112 112
  i = const_mcarb_test.queueSize();
113
  
113

	
114 114
  c = const_mcarb_test.arborescenceCost();
115 115
  b = const_mcarb_test.arborescence(e);
116 116
  e = const_mcarb_test.pred(n);
117 117
  const MinCostArbType::ArborescenceMap &am =
118 118
    const_mcarb_test.arborescenceMap();
119 119
  const MinCostArbType::PredMap &pm =
120 120
    const_mcarb_test.predMap();
121 121
  b = const_mcarb_test.reached(n);
122 122
  b = const_mcarb_test.processed(n);
123
  
123

	
124 124
  i = const_mcarb_test.dualNum();
125 125
  c = const_mcarb_test.dualValue();
126 126
  i = const_mcarb_test.dualSize(i);
127 127
  c = const_mcarb_test.dualValue(i);
128
  
128

	
129 129
  ignore_unused_variable_warning(am);
130 130
  ignore_unused_variable_warning(pm);
131 131
}
132 132

	
133 133
int main() {
134 134
  typedef SmartDigraph Digraph;
135 135
  DIGRAPH_TYPEDEFS(Digraph);
136 136

	
137 137
  typedef Digraph::ArcMap<double> CostMap;
138 138

	
139 139
  Digraph digraph;
140 140
  CostMap cost(digraph);
141 141
  Node source;
142 142

	
143 143
  std::istringstream is(test_lgf);
144 144
  digraphReader(digraph, is).
145 145
    arcMap("cost", cost).
146 146
    node("source", source).run();
147 147

	
148 148
  MinCostArborescence<Digraph, CostMap> mca(digraph, cost);
149 149
  mca.run(source);
150 150

	
151 151
  vector<pair<double, set<Node> > > dualSolution(mca.dualNum());
152 152

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20
#include <fstream>
21 21
#include <limits>
22 22

	
23 23
#include <lemon/list_graph.h>
24 24
#include <lemon/lgf_reader.h>
25 25

	
26 26
#include <lemon/network_simplex.h>
27 27

	
28 28
#include <lemon/concepts/digraph.h>
29 29
#include <lemon/concept_check.h>
30 30

	
31 31
#include "test_tools.h"
32 32

	
33 33
using namespace lemon;
34 34

	
35 35
char test_lgf[] =
36 36
  "@nodes\n"
37 37
  "label  sup1 sup2 sup3 sup4 sup5 sup6\n"
38 38
  "    1    20   27    0   30   20   30\n"
39 39
  "    2    -4    0    0    0   -8   -3\n"
40 40
  "    3     0    0    0    0    0    0\n"
41 41
  "    4     0    0    0    0    0    0\n"
42 42
  "    5     9    0    0    0    6   11\n"
43 43
  "    6    -6    0    0    0   -5   -6\n"
44 44
  "    7     0    0    0    0    0    0\n"
45 45
  "    8     0    0    0    0    0    3\n"
46 46
  "    9     3    0    0    0    0    0\n"
47 47
  "   10    -2    0    0    0   -7   -2\n"
48 48
  "   11     0    0    0    0  -10    0\n"
49 49
  "   12   -20  -27    0  -30  -30  -20\n"
50
  "\n"                
50
  "\n"
51 51
  "@arcs\n"
52 52
  "       cost  cap low1 low2 low3\n"
53 53
  " 1  2    70   11    0    8    8\n"
54 54
  " 1  3   150    3    0    1    0\n"
55 55
  " 1  4    80   15    0    2    2\n"
56 56
  " 2  8    80   12    0    0    0\n"
57 57
  " 3  5   140    5    0    3    1\n"
58 58
  " 4  6    60   10    0    1    0\n"
59 59
  " 4  7    80    2    0    0    0\n"
60 60
  " 4  8   110    3    0    0    0\n"
61 61
  " 5  7    60   14    0    0    0\n"
62 62
  " 5 11   120   12    0    0    0\n"
63 63
  " 6  3     0    3    0    0    0\n"
64 64
  " 6  9   140    4    0    0    0\n"
65 65
  " 6 10    90    8    0    0    0\n"
66 66
  " 7  1    30    5    0    0   -5\n"
67 67
  " 8 12    60   16    0    4    3\n"
68 68
  " 9 12    50    6    0    0    0\n"
69 69
  "10 12    70   13    0    5    2\n"
70 70
  "10  2   100    7    0    0    0\n"
71 71
  "10  7    60   10    0    0   -3\n"
72 72
  "11 10    20   14    0    6  -20\n"
73 73
  "12 11    30   10    0    0  -10\n"
74 74
  "\n"
75 75
  "@attributes\n"
76 76
  "source 1\n"
77 77
  "target 12\n";
78 78

	
79 79

	
80 80
enum SupplyType {
81 81
  EQ,
82 82
  GEQ,
83 83
  LEQ
84 84
};
85 85

	
86 86
// Check the interface of an MCF algorithm
87 87
template <typename GR, typename Value, typename Cost>
88 88
class McfClassConcept
89 89
{
90 90
public:
91 91

	
92 92
  template <typename MCF>
93 93
  struct Constraints {
94 94
    void constraints() {
95 95
      checkConcept<concepts::Digraph, GR>();
96
      
96

	
97 97
      const Constraints& me = *this;
98 98

	
99 99
      MCF mcf(me.g);
100 100
      const MCF& const_mcf = mcf;
101 101

	
102 102
      b = mcf.reset()
103 103
             .lowerMap(me.lower)
104 104
             .upperMap(me.upper)
105 105
             .costMap(me.cost)
106 106
             .supplyMap(me.sup)
107 107
             .stSupply(me.n, me.n, me.k)
108 108
             .run();
109 109

	
110 110
      c = const_mcf.totalCost();
111 111
      x = const_mcf.template totalCost<double>();
112 112
      v = const_mcf.flow(me.a);
113 113
      c = const_mcf.potential(me.n);
114 114
      const_mcf.flowMap(fm);
115 115
      const_mcf.potentialMap(pm);
116 116
    }
117 117

	
118 118
    typedef typename GR::Node Node;
119 119
    typedef typename GR::Arc Arc;
120 120
    typedef concepts::ReadMap<Node, Value> NM;
121 121
    typedef concepts::ReadMap<Arc, Value> VAM;
122 122
    typedef concepts::ReadMap<Arc, Cost> CAM;
123 123
    typedef concepts::WriteMap<Arc, Value> FlowMap;
124 124
    typedef concepts::WriteMap<Node, Cost> PotMap;
125
  
125

	
126 126
    GR g;
127 127
    VAM lower;
128 128
    VAM upper;
129 129
    CAM cost;
130 130
    NM sup;
131 131
    Node n;
132 132
    Arc a;
133 133
    Value k;
134 134

	
135 135
    FlowMap fm;
136 136
    PotMap pm;
137 137
    bool b;
138 138
    double x;
139 139
    typename MCF::Value v;
140 140
    typename MCF::Cost c;
141 141
  };
142 142

	
143 143
};
144 144

	
145 145

	
146 146
// Check the feasibility of the given flow (primal soluiton)
147 147
template < typename GR, typename LM, typename UM,
148 148
           typename SM, typename FM >
149 149
bool checkFlow( const GR& gr, const LM& lower, const UM& upper,
... ...
@@ -155,109 +155,109 @@
155 155
  for (ArcIt e(gr); e != INVALID; ++e) {
156 156
    if (flow[e] < lower[e] || flow[e] > upper[e]) return false;
157 157
  }
158 158

	
159 159
  for (NodeIt n(gr); n != INVALID; ++n) {
160 160
    typename SM::Value sum = 0;
161 161
    for (OutArcIt e(gr, n); e != INVALID; ++e)
162 162
      sum += flow[e];
163 163
    for (InArcIt e(gr, n); e != INVALID; ++e)
164 164
      sum -= flow[e];
165 165
    bool b = (type ==  EQ && sum == supply[n]) ||
166 166
             (type == GEQ && sum >= supply[n]) ||
167 167
             (type == LEQ && sum <= supply[n]);
168 168
    if (!b) return false;
169 169
  }
170 170

	
171 171
  return true;
172 172
}
173 173

	
174 174
// Check the feasibility of the given potentials (dual soluiton)
175 175
// using the "Complementary Slackness" optimality condition
176 176
template < typename GR, typename LM, typename UM,
177 177
           typename CM, typename SM, typename FM, typename PM >
178 178
bool checkPotential( const GR& gr, const LM& lower, const UM& upper,
179
                     const CM& cost, const SM& supply, const FM& flow, 
179
                     const CM& cost, const SM& supply, const FM& flow,
180 180
                     const PM& pi, SupplyType type )
181 181
{
182 182
  TEMPLATE_DIGRAPH_TYPEDEFS(GR);
183 183

	
184 184
  bool opt = true;
185 185
  for (ArcIt e(gr); opt && e != INVALID; ++e) {
186 186
    typename CM::Value red_cost =
187 187
      cost[e] + pi[gr.source(e)] - pi[gr.target(e)];
188 188
    opt = red_cost == 0 ||
189 189
          (red_cost > 0 && flow[e] == lower[e]) ||
190 190
          (red_cost < 0 && flow[e] == upper[e]);
191 191
  }
192
  
192

	
193 193
  for (NodeIt n(gr); opt && n != INVALID; ++n) {
194 194
    typename SM::Value sum = 0;
195 195
    for (OutArcIt e(gr, n); e != INVALID; ++e)
196 196
      sum += flow[e];
197 197
    for (InArcIt e(gr, n); e != INVALID; ++e)
198 198
      sum -= flow[e];
199 199
    if (type != LEQ) {
200 200
      opt = (pi[n] <= 0) && (sum == supply[n] || pi[n] == 0);
201 201
    } else {
202 202
      opt = (pi[n] >= 0) && (sum == supply[n] || pi[n] == 0);
203 203
    }
204 204
  }
205
  
205

	
206 206
  return opt;
207 207
}
208 208

	
209 209
// Check whether the dual cost is equal to the primal cost
210 210
template < typename GR, typename LM, typename UM,
211 211
           typename CM, typename SM, typename PM >
212 212
bool checkDualCost( const GR& gr, const LM& lower, const UM& upper,
213 213
                    const CM& cost, const SM& supply, const PM& pi,
214 214
                    typename CM::Value total )
215 215
{
216 216
  TEMPLATE_DIGRAPH_TYPEDEFS(GR);
217 217

	
218 218
  typename CM::Value dual_cost = 0;
219 219
  SM red_supply(gr);
220 220
  for (NodeIt n(gr); n != INVALID; ++n) {
221 221
    red_supply[n] = supply[n];
222 222
  }
223 223
  for (ArcIt a(gr); a != INVALID; ++a) {
224 224
    if (lower[a] != 0) {
225 225
      dual_cost += lower[a] * cost[a];
226 226
      red_supply[gr.source(a)] -= lower[a];
227 227
      red_supply[gr.target(a)] += lower[a];
228 228
    }
229 229
  }
230
  
230

	
231 231
  for (NodeIt n(gr); n != INVALID; ++n) {
232 232
    dual_cost -= red_supply[n] * pi[n];
233 233
  }
234 234
  for (ArcIt a(gr); a != INVALID; ++a) {
235 235
    typename CM::Value red_cost =
236 236
      cost[a] + pi[gr.source(a)] - pi[gr.target(a)];
237 237
    dual_cost -= (upper[a] - lower[a]) * std::max(-red_cost, 0);
238 238
  }
239
  
239

	
240 240
  return dual_cost == total;
241 241
}
242 242

	
243 243
// Run a minimum cost flow algorithm and check the results
244 244
template < typename MCF, typename GR,
245 245
           typename LM, typename UM,
246 246
           typename CM, typename SM,
247 247
           typename PT >
248 248
void checkMcf( const MCF& mcf, PT mcf_result,
249 249
               const GR& gr, const LM& lower, const UM& upper,
250 250
               const CM& cost, const SM& supply,
251 251
               PT result, bool optimal, typename CM::Value total,
252 252
               const std::string &test_id = "",
253 253
               SupplyType type = EQ )
254 254
{
255 255
  check(mcf_result == result, "Wrong result " + test_id);
256 256
  if (optimal) {
257 257
    typename GR::template ArcMap<typename SM::Value> flow(gr);
258 258
    typename GR::template NodeMap<typename CM::Value> pi(gr);
259 259
    mcf.flowMap(flow);
260 260
    mcf.potentialMap(pi);
261 261
    check(checkFlow(gr, lower, upper, supply, flow, type),
262 262
          "The flow is not feasible " + test_id);
263 263
    check(mcf.totalCost() == total, "The flow is not optimal " + test_id);
... ...
@@ -287,79 +287,79 @@
287 287

	
288 288
  // Read the test digraph
289 289
  Digraph gr;
290 290
  Digraph::ArcMap<int> c(gr), l1(gr), l2(gr), l3(gr), u(gr);
291 291
  Digraph::NodeMap<int> s1(gr), s2(gr), s3(gr), s4(gr), s5(gr), s6(gr);
292 292
  ConstMap<Arc, int> cc(1), cu(std::numeric_limits<int>::max());
293 293
  Node v, w;
294 294

	
295 295
  std::istringstream input(test_lgf);
296 296
  DigraphReader<Digraph>(gr, input)
297 297
    .arcMap("cost", c)
298 298
    .arcMap("cap", u)
299 299
    .arcMap("low1", l1)
300 300
    .arcMap("low2", l2)
301 301
    .arcMap("low3", l3)
302 302
    .nodeMap("sup1", s1)
303 303
    .nodeMap("sup2", s2)
304 304
    .nodeMap("sup3", s3)
305 305
    .nodeMap("sup4", s4)
306 306
    .nodeMap("sup5", s5)
307 307
    .nodeMap("sup6", s6)
308 308
    .node("source", v)
309 309
    .node("target", w)
310 310
    .run();
311
  
311

	
312 312
  // Build test digraphs with negative costs
313 313
  Digraph neg_gr;
314 314
  Node n1 = neg_gr.addNode();
315 315
  Node n2 = neg_gr.addNode();
316 316
  Node n3 = neg_gr.addNode();
317 317
  Node n4 = neg_gr.addNode();
318 318
  Node n5 = neg_gr.addNode();
319 319
  Node n6 = neg_gr.addNode();
320 320
  Node n7 = neg_gr.addNode();
321
  
321

	
322 322
  Arc a1 = neg_gr.addArc(n1, n2);
323 323
  Arc a2 = neg_gr.addArc(n1, n3);
324 324
  Arc a3 = neg_gr.addArc(n2, n4);
325 325
  Arc a4 = neg_gr.addArc(n3, n4);
326 326
  Arc a5 = neg_gr.addArc(n3, n2);
327 327
  Arc a6 = neg_gr.addArc(n5, n3);
328 328
  Arc a7 = neg_gr.addArc(n5, n6);
329 329
  Arc a8 = neg_gr.addArc(n6, n7);
330 330
  Arc a9 = neg_gr.addArc(n7, n5);
331
  
331

	
332 332
  Digraph::ArcMap<int> neg_c(neg_gr), neg_l1(neg_gr, 0), neg_l2(neg_gr, 0);
333 333
  ConstMap<Arc, int> neg_u1(std::numeric_limits<int>::max()), neg_u2(5000);
334 334
  Digraph::NodeMap<int> neg_s(neg_gr, 0);
335
  
335

	
336 336
  neg_l2[a7] =  1000;
337 337
  neg_l2[a8] = -1000;
338
  
338

	
339 339
  neg_s[n1] =  100;
340 340
  neg_s[n4] = -100;
341
  
341

	
342 342
  neg_c[a1] =  100;
343 343
  neg_c[a2] =   30;
344 344
  neg_c[a3] =   20;
345 345
  neg_c[a4] =   80;
346 346
  neg_c[a5] =   50;
347 347
  neg_c[a6] =   10;
348 348
  neg_c[a7] =   80;
349 349
  neg_c[a8] =   30;
350 350
  neg_c[a9] = -120;
351 351

	
352 352
  Digraph negs_gr;
353 353
  Digraph::NodeMap<int> negs_s(negs_gr);
354 354
  Digraph::ArcMap<int> negs_c(negs_gr);
355 355
  ConstMap<Arc, int> negs_l(0), negs_u(1000);
356 356
  n1 = negs_gr.addNode();
357 357
  n2 = negs_gr.addNode();
358 358
  negs_s[n1] = 100;
359 359
  negs_s[n2] = -300;
360 360
  negs_c[negs_gr.addArc(n1, n2)] = -1;
361 361

	
362 362

	
363 363
  // A. Test NetworkSimplex with the default pivot rule
364 364
  {
365 365
    NetworkSimplex<Digraph> mcf(gr);
... ...
@@ -401,49 +401,49 @@
401 401
             gr, l2, u, c, s6, mcf.INFEASIBLE, false,  0, "#A12", GEQ);
402 402

	
403 403
    // Check the LEQ form
404 404
    mcf.reset().supplyType(mcf.LEQ);
405 405
    mcf.upperMap(u).costMap(c).supplyMap(s6);
406 406
    checkMcf(mcf, mcf.run(),
407 407
             gr, l1, u, c, s6, mcf.OPTIMAL, true,   5080, "#A13", LEQ);
408 408
    checkMcf(mcf, mcf.lowerMap(l2).run(),
409 409
             gr, l2, u, c, s6, mcf.OPTIMAL, true,   5930, "#A14", LEQ);
410 410
    mcf.supplyMap(s5);
411 411
    checkMcf(mcf, mcf.run(),
412 412
             gr, l2, u, c, s5, mcf.INFEASIBLE, false,  0, "#A15", LEQ);
413 413

	
414 414
    // Check negative costs
415 415
    NetworkSimplex<Digraph> neg_mcf(neg_gr);
416 416
    neg_mcf.lowerMap(neg_l1).costMap(neg_c).supplyMap(neg_s);
417 417
    checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l1, neg_u1,
418 418
      neg_c, neg_s, neg_mcf.UNBOUNDED, false,    0, "#A16");
419 419
    neg_mcf.upperMap(neg_u2);
420 420
    checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l1, neg_u2,
421 421
      neg_c, neg_s, neg_mcf.OPTIMAL, true,  -40000, "#A17");
422 422
    neg_mcf.reset().lowerMap(neg_l2).costMap(neg_c).supplyMap(neg_s);
423 423
    checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l2, neg_u1,
424 424
      neg_c, neg_s, neg_mcf.UNBOUNDED, false,    0, "#A18");
425
      
425

	
426 426
    NetworkSimplex<Digraph> negs_mcf(negs_gr);
427 427
    negs_mcf.costMap(negs_c).supplyMap(negs_s);
428 428
    checkMcf(negs_mcf, negs_mcf.run(), negs_gr, negs_l, negs_u,
429 429
      negs_c, negs_s, negs_mcf.OPTIMAL, true, -300, "#A19", GEQ);
430 430
  }
431 431

	
432 432
  // B. Test NetworkSimplex with each pivot rule
433 433
  {
434 434
    NetworkSimplex<Digraph> mcf(gr);
435 435
    mcf.supplyMap(s1).costMap(c).upperMap(u).lowerMap(l2);
436 436

	
437 437
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::FIRST_ELIGIBLE),
438 438
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B1");
439 439
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BEST_ELIGIBLE),
440 440
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B2");
441 441
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BLOCK_SEARCH),
442 442
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B3");
443 443
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::CANDIDATE_LIST),
444 444
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B4");
445 445
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::ALTERING_LIST),
446 446
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B5");
447 447
  }
448 448

	
449 449
  return 0;
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20

	
21 21
#include "test_tools.h"
22 22
#include <lemon/smart_graph.h>
23 23
#include <lemon/preflow.h>
24 24
#include <lemon/concepts/digraph.h>
25 25
#include <lemon/concepts/maps.h>
26 26
#include <lemon/lgf_reader.h>
27 27
#include <lemon/elevator.h>
28 28

	
29 29
using namespace lemon;
... ...
@@ -92,90 +92,90 @@
92 92
            ::SetElevator<Elev>
93 93
            ::SetStandardElevator<LinkedElev>
94 94
            ::Create PreflowType;
95 95
  PreflowType preflow_test(g, cap, n, n);
96 96
  const PreflowType& const_preflow_test = preflow_test;
97 97

	
98 98
  preflow_test
99 99
    .capacityMap(cap)
100 100
    .flowMap(flow)
101 101
    .source(n)
102 102
    .target(n);
103 103

	
104 104
  preflow_test.init();
105 105
  preflow_test.init(cap);
106 106
  preflow_test.startFirstPhase();
107 107
  preflow_test.startSecondPhase();
108 108
  preflow_test.run();
109 109
  preflow_test.runMinCut();
110 110

	
111 111
  v = const_preflow_test.flowValue();
112 112
  v = const_preflow_test.flow(e);
113 113
  const FlowMap& fm = const_preflow_test.flowMap();
114 114
  b = const_preflow_test.minCut(n);
115 115
  const_preflow_test.minCutMap(cut);
116
  
116

	
117 117
  ignore_unused_variable_warning(fm);
118 118
}
119 119

	
120 120
int cutValue (const SmartDigraph& g,
121 121
              const SmartDigraph::NodeMap<bool>& cut,
122 122
              const SmartDigraph::ArcMap<int>& cap) {
123 123

	
124 124
  int c=0;
125 125
  for(SmartDigraph::ArcIt e(g); e!=INVALID; ++e) {
126 126
    if (cut[g.source(e)] && !cut[g.target(e)]) c+=cap[e];
127 127
  }
128 128
  return c;
129 129
}
130 130

	
131 131
bool checkFlow(const SmartDigraph& g,
132 132
               const SmartDigraph::ArcMap<int>& flow,
133 133
               const SmartDigraph::ArcMap<int>& cap,
134 134
               SmartDigraph::Node s, SmartDigraph::Node t) {
135 135

	
136 136
  for (SmartDigraph::ArcIt e(g); e != INVALID; ++e) {
137 137
    if (flow[e] < 0 || flow[e] > cap[e]) return false;
138 138
  }
139 139

	
140 140
  for (SmartDigraph::NodeIt n(g); n != INVALID; ++n) {
141 141
    if (n == s || n == t) continue;
142 142
    int sum = 0;
143 143
    for (SmartDigraph::OutArcIt e(g, n); e != INVALID; ++e) {
144 144
      sum += flow[e];
145 145
    }
146 146
    for (SmartDigraph::InArcIt e(g, n); e != INVALID; ++e) {
147 147
      sum -= flow[e];
148 148
    }
149 149
    if (sum != 0) return false;
150 150
  }
151 151
  return true;
152 152
}
153 153

	
154 154
void initFlowTest()
155 155
{
156 156
  DIGRAPH_TYPEDEFS(SmartDigraph);
157
  
157

	
158 158
  SmartDigraph g;
159 159
  SmartDigraph::ArcMap<int> cap(g),iflow(g);
160 160
  Node s=g.addNode(); Node t=g.addNode();
161 161
  Node n1=g.addNode(); Node n2=g.addNode();
162 162
  Arc a;
163 163
  a=g.addArc(s,n1); cap[a]=20; iflow[a]=20;
164 164
  a=g.addArc(n1,n2); cap[a]=10; iflow[a]=0;
165 165
  a=g.addArc(n2,t); cap[a]=20; iflow[a]=0;
166 166

	
167 167
  Preflow<SmartDigraph> pre(g,cap,s,t);
168 168
  pre.init(iflow);
169 169
  pre.startFirstPhase();
170 170
  check(pre.flowValue() == 10, "The incorrect max flow value.");
171 171
  check(pre.minCut(s), "Wrong min cut (Node s).");
172 172
  check(pre.minCut(n1), "Wrong min cut (Node n1).");
173 173
  check(!pre.minCut(n2), "Wrong min cut (Node n2).");
174 174
  check(!pre.minCut(t), "Wrong min cut (Node t).");
175 175
}
176 176

	
177 177

	
178 178
int main() {
179 179

	
180 180
  typedef SmartDigraph Digraph;
181 181

	
... ...
@@ -245,27 +245,27 @@
245 245
  preflow_test.flowMap(flow);
246 246

	
247 247
  NodeIt tmp1(g,s);
248 248
  ++tmp1;
249 249
  if ( tmp1 != INVALID ) s=tmp1;
250 250

	
251 251
  NodeIt tmp2(g,t);
252 252
  ++tmp2;
253 253
  if ( tmp2 != INVALID ) t=tmp2;
254 254

	
255 255
  preflow_test.source(s);
256 256
  preflow_test.target(t);
257 257

	
258 258
  preflow_test.run();
259 259

	
260 260
  CutMap min_cut3(g);
261 261
  preflow_test.minCutMap(min_cut3);
262 262
  min_cut_value=cutValue(g,min_cut3,cap);
263 263

	
264 264

	
265 265
  check(preflow_test.flowValue() == min_cut_value,
266 266
        "The max flow value or the three min cut values are incorrect.");
267 267

	
268 268
  initFlowTest();
269
  
269

	
270 270
  return 0;
271 271
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
#include <iostream>
20 20

	
21 21
#include <lemon/list_graph.h>
22 22
#include <lemon/lgf_reader.h>
23 23
#include <lemon/path.h>
24 24
#include <lemon/suurballe.h>
25 25
#include <lemon/concepts/digraph.h>
26 26

	
27 27
#include "test_tools.h"
28 28

	
29 29
using namespace lemon;
... ...
@@ -59,85 +59,85 @@
59 59
  " 6  9 140\n"
60 60
  " 6 10  90\n"
61 61
  " 7  1  30\n"
62 62
  " 8 12  60\n"
63 63
  " 9 12  50\n"
64 64
  "10 12  70\n"
65 65
  "10  2 100\n"
66 66
  "10  7  60\n"
67 67
  "11 10  20\n"
68 68
  "12 11  30\n"
69 69
  "@attributes\n"
70 70
  "source  1\n"
71 71
  "target 12\n"
72 72
  "@end\n";
73 73

	
74 74
// Check the interface of Suurballe
75 75
void checkSuurballeCompile()
76 76
{
77 77
  typedef int VType;
78 78
  typedef concepts::Digraph Digraph;
79 79

	
80 80
  typedef Digraph::Node Node;
81 81
  typedef Digraph::Arc Arc;
82 82
  typedef concepts::ReadMap<Arc, VType> LengthMap;
83
  
83

	
84 84
  typedef Suurballe<Digraph, LengthMap> SuurballeType;
85 85

	
86 86
  Digraph g;
87 87
  Node n;
88 88
  Arc e;
89 89
  LengthMap len;
90 90
  SuurballeType::FlowMap flow(g);
91 91
  SuurballeType::PotentialMap pi(g);
92 92

	
93 93
  SuurballeType suurb_test(g, len);
94 94
  const SuurballeType& const_suurb_test = suurb_test;
95 95

	
96 96
  suurb_test
97 97
    .flowMap(flow)
98 98
    .potentialMap(pi);
99 99

	
100 100
  int k;
101 101
  k = suurb_test.run(n, n);
102 102
  k = suurb_test.run(n, n, k);
103 103
  suurb_test.init(n);
104 104
  k = suurb_test.findFlow(n);
105 105
  k = suurb_test.findFlow(n, k);
106 106
  suurb_test.findPaths();
107
  
107

	
108 108
  int f;
109 109
  VType c;
110 110
  c = const_suurb_test.totalLength();
111 111
  f = const_suurb_test.flow(e);
112 112
  const SuurballeType::FlowMap& fm =
113 113
    const_suurb_test.flowMap();
114 114
  c = const_suurb_test.potential(n);
115 115
  const SuurballeType::PotentialMap& pm =
116 116
    const_suurb_test.potentialMap();
117 117
  k = const_suurb_test.pathNum();
118 118
  Path<Digraph> p = const_suurb_test.path(k);
119
  
119

	
120 120
  ignore_unused_variable_warning(fm);
121 121
  ignore_unused_variable_warning(pm);
122 122
}
123 123

	
124 124
// Check the feasibility of the flow
125 125
template <typename Digraph, typename FlowMap>
126 126
bool checkFlow( const Digraph& gr, const FlowMap& flow,
127 127
                typename Digraph::Node s, typename Digraph::Node t,
128 128
                int value )
129 129
{
130 130
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
131 131
  for (ArcIt e(gr); e != INVALID; ++e)
132 132
    if (!(flow[e] == 0 || flow[e] == 1)) return false;
133 133

	
134 134
  for (NodeIt n(gr); n != INVALID; ++n) {
135 135
    int sum = 0;
136 136
    for (OutArcIt e(gr, n); e != INVALID; ++e)
137 137
      sum += flow[e];
138 138
    for (InArcIt e(gr, n); e != INVALID; ++e)
139 139
      sum -= flow[e];
140 140
    if (n == s && sum != value) return false;
141 141
    if (n == t && sum != -value) return false;
142 142
    if (n != s && n != t && sum != 0) return false;
143 143
  }
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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 tools
20 20
///\file
21 21
///\brief DIMACS problem solver.
22 22
///
23 23
/// This program solves various problems given in DIMACS format.
24 24
///
25 25
/// See
26 26
/// \code
27 27
///   dimacs-solver --help
28 28
/// \endcode
29 29
/// for more info on usage.
... ...
@@ -67,49 +67,49 @@
67 67
  if(report) std::cerr << "Setup Dijkstra class: " << t << '\n';
68 68
  t.restart();
69 69
  dij.run(s);
70 70
  if(report) std::cerr << "Run Dijkstra: " << t << '\n';
71 71
}
72 72

	
73 73
template<class Value>
74 74
void solve_max(ArgParser &ap, std::istream &is, std::ostream &,
75 75
               Value infty, DimacsDescriptor &desc)
76 76
{
77 77
  bool report = !ap.given("q");
78 78
  Digraph g;
79 79
  Node s,t;
80 80
  Digraph::ArcMap<Value> cap(g);
81 81
  Timer ti;
82 82
  ti.restart();
83 83
  readDimacsMax(is, g, cap, s, t, infty, desc);
84 84
  if(report) std::cerr << "Read the file: " << ti << '\n';
85 85
  ti.restart();
86 86
  Preflow<Digraph, Digraph::ArcMap<Value> > pre(g,cap,s,t);
87 87
  if(report) std::cerr << "Setup Preflow class: " << ti << '\n';
88 88
  ti.restart();
89 89
  pre.run();
90 90
  if(report) std::cerr << "Run Preflow: " << ti << '\n';
91
  if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n';  
91
  if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n';
92 92
}
93 93

	
94 94
template<class Value>
95 95
void solve_min(ArgParser &ap, std::istream &is, std::ostream &,
96 96
               Value infty, DimacsDescriptor &desc)
97 97
{
98 98
  bool report = !ap.given("q");
99 99
  Digraph g;
100 100
  Digraph::ArcMap<Value> lower(g), cap(g), cost(g);
101 101
  Digraph::NodeMap<Value> sup(g);
102 102
  Timer ti;
103 103

	
104 104
  ti.restart();
105 105
  readDimacsMin(is, g, lower, cap, cost, sup, infty, desc);
106 106
  ti.stop();
107 107
  Value sum_sup = 0;
108 108
  for (Digraph::NodeIt n(g); n != INVALID; ++n) {
109 109
    sum_sup += sup[n];
110 110
  }
111 111
  if (report) {
112 112
    std::cerr << "Sum of supply values: " << sum_sup << "\n";
113 113
    if (sum_sup <= 0)
114 114
      std::cerr << "GEQ supply contraints are used for NetworkSimplex\n\n";
115 115
    else
... ...
@@ -126,67 +126,67 @@
126 126
  bool res = ns.run();
127 127
  if (report) {
128 128
    std::cerr << "Run NetworkSimplex: " << ti << "\n\n";
129 129
    std::cerr << "Feasible flow: " << (res ? "found" : "not found") << '\n';
130 130
    if (res) std::cerr << "Min flow cost: " << ns.totalCost() << '\n';
131 131
  }
132 132
}
133 133

	
134 134
void solve_mat(ArgParser &ap, std::istream &is, std::ostream &,
135 135
              DimacsDescriptor &desc)
136 136
{
137 137
  bool report = !ap.given("q");
138 138
  Graph g;
139 139
  Timer ti;
140 140
  ti.restart();
141 141
  readDimacsMat(is, g, desc);
142 142
  if(report) std::cerr << "Read the file: " << ti << '\n';
143 143
  ti.restart();
144 144
  MaxMatching<Graph> mat(g);
145 145
  if(report) std::cerr << "Setup MaxMatching class: " << ti << '\n';
146 146
  ti.restart();
147 147
  mat.run();
148 148
  if(report) std::cerr << "Run MaxMatching: " << ti << '\n';
149 149
  if(report) std::cerr << "\nCardinality of max matching: "
150
                       << mat.matchingSize() << '\n';  
150
                       << mat.matchingSize() << '\n';
151 151
}
152 152

	
153 153

	
154 154
template<class Value>
155 155
void solve(ArgParser &ap, std::istream &is, std::ostream &os,
156 156
           DimacsDescriptor &desc)
157 157
{
158 158
  std::stringstream iss(static_cast<std::string>(ap["infcap"]));
159 159
  Value infty;
160 160
  iss >> infty;
161 161
  if(iss.fail())
162 162
    {
163 163
      std::cerr << "Cannot interpret '"
164 164
                << static_cast<std::string>(ap["infcap"]) << "' as infinite"
165 165
                << std::endl;
166 166
      exit(1);
167 167
    }
168
  
168

	
169 169
  switch(desc.type)
170 170
    {
171 171
    case DimacsDescriptor::MIN:
172 172
      solve_min<Value>(ap,is,os,infty,desc);
173 173
      break;
174 174
    case DimacsDescriptor::MAX:
175 175
      solve_max<Value>(ap,is,os,infty,desc);
176 176
      break;
177 177
    case DimacsDescriptor::SP:
178 178
      solve_sp<Value>(ap,is,os,desc);
179 179
      break;
180 180
    case DimacsDescriptor::MAT:
181 181
      solve_mat(ap,is,os,desc);
182 182
      break;
183 183
    default:
184 184
      break;
185 185
    }
186 186
}
187 187

	
188 188
int main(int argc, const char *argv[]) {
189 189
  typedef SmartDigraph Digraph;
190 190

	
191 191
  typedef Digraph::Arc Arc;
192 192

	
... ...
@@ -216,62 +216,62 @@
216 216
  std::ofstream output;
217 217

	
218 218
  switch(ap.files().size())
219 219
    {
220 220
    case 2:
221 221
      output.open(ap.files()[1].c_str());
222 222
      if (!output) {
223 223
        throw IoError("Cannot open the file for writing", ap.files()[1]);
224 224
      }
225 225
    case 1:
226 226
      input.open(ap.files()[0].c_str());
227 227
      if (!input) {
228 228
        throw IoError("File cannot be found", ap.files()[0]);
229 229
      }
230 230
    case 0:
231 231
      break;
232 232
    default:
233 233
      std::cerr << ap.commandName() << ": too many arguments\n";
234 234
      return 1;
235 235
    }
236 236
  std::istream& is = (ap.files().size()<1 ? std::cin : input);
237 237
  std::ostream& os = (ap.files().size()<2 ? std::cout : output);
238 238

	
239 239
  DimacsDescriptor desc = dimacsType(is);
240
  
240

	
241 241
  if(!ap.given("q"))
242 242
    {
243 243
      std::cout << "Problem type: ";
244 244
      switch(desc.type)
245 245
        {
246 246
        case DimacsDescriptor::MIN:
247 247
          std::cout << "min";
248 248
          break;
249 249
        case DimacsDescriptor::MAX:
250 250
          std::cout << "max";
251 251
          break;
252 252
        case DimacsDescriptor::SP:
253 253
          std::cout << "sp";
254 254
        case DimacsDescriptor::MAT:
255 255
          std::cout << "mat";
256 256
          break;
257 257
        default:
258 258
          exit(1);
259 259
          break;
260 260
        }
261 261
      std::cout << "\nNum of nodes: " << desc.nodeNum;
262 262
      std::cout << "\nNum of arcs:  " << desc.edgeNum;
263 263
      std::cout << "\n\n";
264 264
    }
265
    
265

	
266 266
  if(ap.given("double"))
267 267
    solve<double>(ap,is,os,desc);
268 268
  else if(ap.given("ldouble"))
269 269
    solve<long double>(ap,is,os,desc);
270 270
#ifdef LEMON_HAVE_LONG_LONG
271 271
  else if(ap.given("long"))
272 272
    solve<long long>(ap,is,os,desc);
273 273
#endif
274 274
  else solve<int>(ap,is,os,desc);
275 275

	
276 276
  return 0;
277 277
}
0 comments (0 inline)