lemon/suurballe.h
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 29 Mar 2009 23:08:20 +0200
changeset 606 c5fd2d996909
parent 566 c786cd201266
child 631 33c6b6e755cd
permissions -rw-r--r--
Various doc improvements (#248)
- Rename all the ugly template parameters (too long and/or starting
with an underscore).
- Rename function parameters starting with an underscore.
- Extend the doc for many classes.
- Use LaTeX-style O(...) expressions only for the complicated ones.
- A lot of small unification changes.
- Small fixes.
- Some other improvements.
alpar@463
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@357
     2
 *
alpar@463
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@357
     4
 *
alpar@463
     5
 * Copyright (C) 2003-2009
alpar@357
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@357
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@357
     8
 *
alpar@357
     9
 * Permission to use, modify and distribute this software is granted
alpar@357
    10
 * provided that this copyright notice appears in all copies. For
alpar@357
    11
 * precise terms see the accompanying LICENSE file.
alpar@357
    12
 *
alpar@357
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@357
    14
 * express or implied, and with no claim as to its suitability for any
alpar@357
    15
 * purpose.
alpar@357
    16
 *
alpar@357
    17
 */
alpar@357
    18
alpar@357
    19
#ifndef LEMON_SUURBALLE_H
alpar@357
    20
#define LEMON_SUURBALLE_H
alpar@357
    21
alpar@357
    22
///\ingroup shortest_path
alpar@357
    23
///\file
alpar@357
    24
///\brief An algorithm for finding arc-disjoint paths between two
alpar@357
    25
/// nodes having minimum total length.
alpar@357
    26
alpar@357
    27
#include <vector>
alpar@357
    28
#include <lemon/bin_heap.h>
alpar@357
    29
#include <lemon/path.h>
deba@566
    30
#include <lemon/list_graph.h>
deba@566
    31
#include <lemon/maps.h>
alpar@357
    32
alpar@357
    33
namespace lemon {
alpar@357
    34
alpar@357
    35
  /// \addtogroup shortest_path
alpar@357
    36
  /// @{
alpar@357
    37
kpeter@358
    38
  /// \brief Algorithm for finding arc-disjoint paths between two nodes
kpeter@358
    39
  /// having minimum total length.
alpar@357
    40
  ///
alpar@357
    41
  /// \ref lemon::Suurballe "Suurballe" implements an algorithm for
alpar@357
    42
  /// finding arc-disjoint paths having minimum total length (cost)
kpeter@358
    43
  /// from a given source node to a given target node in a digraph.
alpar@357
    44
  ///
alpar@357
    45
  /// In fact, this implementation is the specialization of the
alpar@357
    46
  /// \ref CapacityScaling "successive shortest path" algorithm.
alpar@357
    47
  ///
kpeter@606
    48
  /// \tparam GR The digraph type the algorithm runs on.
kpeter@358
    49
  /// The default value is \c ListDigraph.
kpeter@606
    50
  /// \tparam LEN The type of the length (cost) map.
kpeter@358
    51
  /// The default value is <tt>Digraph::ArcMap<int></tt>.
alpar@357
    52
  ///
alpar@357
    53
  /// \warning Length values should be \e non-negative \e integers.
alpar@357
    54
  ///
alpar@357
    55
  /// \note For finding node-disjoint paths this algorithm can be used
deba@444
    56
  /// with \ref SplitNodes.
kpeter@358
    57
#ifdef DOXYGEN
kpeter@606
    58
  template <typename GR, typename LEN>
kpeter@358
    59
#else
kpeter@606
    60
  template < typename GR = ListDigraph,
kpeter@606
    61
             typename LEN = typename GR::template ArcMap<int> >
kpeter@358
    62
#endif
alpar@357
    63
  class Suurballe
alpar@357
    64
  {
kpeter@606
    65
    TEMPLATE_DIGRAPH_TYPEDEFS(GR);
alpar@357
    66
alpar@357
    67
    typedef ConstMap<Arc, int> ConstArcMap;
kpeter@606
    68
    typedef typename GR::template NodeMap<Arc> PredMap;
alpar@357
    69
alpar@357
    70
  public:
alpar@357
    71
kpeter@606
    72
    /// The type of the digraph the algorithm runs on.
kpeter@606
    73
    typedef GR Digraph;
kpeter@606
    74
    /// The type of the length map.
kpeter@606
    75
    typedef LEN LengthMap;
kpeter@606
    76
    /// The type of the lengths.
kpeter@606
    77
    typedef typename LengthMap::Value Length;
alpar@357
    78
    /// The type of the flow map.
alpar@357
    79
    typedef typename Digraph::template ArcMap<int> FlowMap;
alpar@357
    80
    /// The type of the potential map.
alpar@357
    81
    typedef typename Digraph::template NodeMap<Length> PotentialMap;
alpar@357
    82
    /// The type of the path structures.
alpar@357
    83
    typedef SimplePath<Digraph> Path;
alpar@357
    84
alpar@357
    85
  private:
alpar@463
    86
kpeter@358
    87
    /// \brief Special implementation of the Dijkstra algorithm
alpar@357
    88
    /// for finding shortest paths in the residual network.
alpar@357
    89
    ///
alpar@357
    90
    /// \ref ResidualDijkstra is a special implementation of the
alpar@357
    91
    /// \ref Dijkstra algorithm for finding shortest paths in the
alpar@357
    92
    /// residual network of the digraph with respect to the reduced arc
alpar@357
    93
    /// lengths and modifying the node potentials according to the
alpar@357
    94
    /// distance of the nodes.
alpar@357
    95
    class ResidualDijkstra
alpar@357
    96
    {
alpar@357
    97
      typedef typename Digraph::template NodeMap<int> HeapCrossRef;
alpar@357
    98
      typedef BinHeap<Length, HeapCrossRef> Heap;
alpar@357
    99
alpar@357
   100
    private:
alpar@357
   101
kpeter@358
   102
      // The digraph the algorithm runs on
alpar@357
   103
      const Digraph &_graph;
alpar@357
   104
alpar@357
   105
      // The main maps
alpar@357
   106
      const FlowMap &_flow;
alpar@357
   107
      const LengthMap &_length;
alpar@357
   108
      PotentialMap &_potential;
alpar@357
   109
alpar@357
   110
      // The distance map
alpar@357
   111
      PotentialMap _dist;
alpar@357
   112
      // The pred arc map
alpar@357
   113
      PredMap &_pred;
alpar@357
   114
      // The processed (i.e. permanently labeled) nodes
alpar@357
   115
      std::vector<Node> _proc_nodes;
alpar@463
   116
alpar@357
   117
      Node _s;
alpar@357
   118
      Node _t;
alpar@357
   119
alpar@357
   120
    public:
alpar@357
   121
alpar@357
   122
      /// Constructor.
alpar@357
   123
      ResidualDijkstra( const Digraph &digraph,
alpar@357
   124
                        const FlowMap &flow,
alpar@357
   125
                        const LengthMap &length,
alpar@357
   126
                        PotentialMap &potential,
alpar@357
   127
                        PredMap &pred,
alpar@357
   128
                        Node s, Node t ) :
alpar@357
   129
        _graph(digraph), _flow(flow), _length(length), _potential(potential),
alpar@357
   130
        _dist(digraph), _pred(pred), _s(s), _t(t) {}
alpar@357
   131
kpeter@358
   132
      /// \brief Run the algorithm. It returns \c true if a path is found
alpar@357
   133
      /// from the source node to the target node.
alpar@357
   134
      bool run() {
alpar@357
   135
        HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP);
alpar@357
   136
        Heap heap(heap_cross_ref);
alpar@357
   137
        heap.push(_s, 0);
alpar@357
   138
        _pred[_s] = INVALID;
alpar@357
   139
        _proc_nodes.clear();
alpar@357
   140
kpeter@358
   141
        // Process nodes
alpar@357
   142
        while (!heap.empty() && heap.top() != _t) {
alpar@357
   143
          Node u = heap.top(), v;
alpar@357
   144
          Length d = heap.prio() + _potential[u], nd;
alpar@357
   145
          _dist[u] = heap.prio();
alpar@357
   146
          heap.pop();
alpar@357
   147
          _proc_nodes.push_back(u);
alpar@357
   148
kpeter@358
   149
          // Traverse outgoing arcs
alpar@357
   150
          for (OutArcIt e(_graph, u); e != INVALID; ++e) {
alpar@357
   151
            if (_flow[e] == 0) {
alpar@357
   152
              v = _graph.target(e);
alpar@357
   153
              switch(heap.state(v)) {
alpar@357
   154
              case Heap::PRE_HEAP:
alpar@357
   155
                heap.push(v, d + _length[e] - _potential[v]);
alpar@357
   156
                _pred[v] = e;
alpar@357
   157
                break;
alpar@357
   158
              case Heap::IN_HEAP:
alpar@357
   159
                nd = d + _length[e] - _potential[v];
alpar@357
   160
                if (nd < heap[v]) {
alpar@357
   161
                  heap.decrease(v, nd);
alpar@357
   162
                  _pred[v] = e;
alpar@357
   163
                }
alpar@357
   164
                break;
alpar@357
   165
              case Heap::POST_HEAP:
alpar@357
   166
                break;
alpar@357
   167
              }
alpar@357
   168
            }
alpar@357
   169
          }
alpar@357
   170
kpeter@358
   171
          // Traverse incoming arcs
alpar@357
   172
          for (InArcIt e(_graph, u); e != INVALID; ++e) {
alpar@357
   173
            if (_flow[e] == 1) {
alpar@357
   174
              v = _graph.source(e);
alpar@357
   175
              switch(heap.state(v)) {
alpar@357
   176
              case Heap::PRE_HEAP:
alpar@357
   177
                heap.push(v, d - _length[e] - _potential[v]);
alpar@357
   178
                _pred[v] = e;
alpar@357
   179
                break;
alpar@357
   180
              case Heap::IN_HEAP:
alpar@357
   181
                nd = d - _length[e] - _potential[v];
alpar@357
   182
                if (nd < heap[v]) {
alpar@357
   183
                  heap.decrease(v, nd);
alpar@357
   184
                  _pred[v] = e;
alpar@357
   185
                }
alpar@357
   186
                break;
alpar@357
   187
              case Heap::POST_HEAP:
alpar@357
   188
                break;
alpar@357
   189
              }
alpar@357
   190
            }
alpar@357
   191
          }
alpar@357
   192
        }
alpar@357
   193
        if (heap.empty()) return false;
alpar@357
   194
kpeter@358
   195
        // Update potentials of processed nodes
alpar@357
   196
        Length t_dist = heap.prio();
alpar@357
   197
        for (int i = 0; i < int(_proc_nodes.size()); ++i)
alpar@357
   198
          _potential[_proc_nodes[i]] += _dist[_proc_nodes[i]] - t_dist;
alpar@357
   199
        return true;
alpar@357
   200
      }
alpar@357
   201
alpar@357
   202
    }; //class ResidualDijkstra
alpar@357
   203
alpar@357
   204
  private:
alpar@357
   205
kpeter@358
   206
    // The digraph the algorithm runs on
alpar@357
   207
    const Digraph &_graph;
alpar@357
   208
    // The length map
alpar@357
   209
    const LengthMap &_length;
alpar@463
   210
alpar@357
   211
    // Arc map of the current flow
alpar@357
   212
    FlowMap *_flow;
alpar@357
   213
    bool _local_flow;
alpar@357
   214
    // Node map of the current potentials
alpar@357
   215
    PotentialMap *_potential;
alpar@357
   216
    bool _local_potential;
alpar@357
   217
alpar@357
   218
    // The source node
alpar@357
   219
    Node _source;
alpar@357
   220
    // The target node
alpar@357
   221
    Node _target;
alpar@357
   222
alpar@357
   223
    // Container to store the found paths
alpar@357
   224
    std::vector< SimplePath<Digraph> > paths;
alpar@357
   225
    int _path_num;
alpar@357
   226
alpar@357
   227
    // The pred arc map
alpar@357
   228
    PredMap _pred;
alpar@357
   229
    // Implementation of the Dijkstra algorithm for finding augmenting
alpar@357
   230
    // shortest paths in the residual network
alpar@357
   231
    ResidualDijkstra *_dijkstra;
alpar@357
   232
alpar@357
   233
  public:
alpar@357
   234
alpar@357
   235
    /// \brief Constructor.
alpar@357
   236
    ///
alpar@357
   237
    /// Constructor.
alpar@357
   238
    ///
kpeter@358
   239
    /// \param digraph The digraph the algorithm runs on.
alpar@357
   240
    /// \param length The length (cost) values of the arcs.
alpar@357
   241
    /// \param s The source node.
alpar@357
   242
    /// \param t The target node.
alpar@357
   243
    Suurballe( const Digraph &digraph,
alpar@357
   244
               const LengthMap &length,
alpar@357
   245
               Node s, Node t ) :
alpar@357
   246
      _graph(digraph), _length(length), _flow(0), _local_flow(false),
alpar@357
   247
      _potential(0), _local_potential(false), _source(s), _target(t),
alpar@357
   248
      _pred(digraph) {}
alpar@357
   249
alpar@357
   250
    /// Destructor.
alpar@357
   251
    ~Suurballe() {
alpar@357
   252
      if (_local_flow) delete _flow;
alpar@357
   253
      if (_local_potential) delete _potential;
alpar@357
   254
      delete _dijkstra;
alpar@357
   255
    }
alpar@357
   256
kpeter@358
   257
    /// \brief Set the flow map.
alpar@357
   258
    ///
kpeter@358
   259
    /// This function sets the flow map.
alpar@357
   260
    ///
alpar@357
   261
    /// The found flow contains only 0 and 1 values. It is the union of
alpar@357
   262
    /// the found arc-disjoint paths.
alpar@357
   263
    ///
kpeter@606
   264
    /// \return <tt>(*this)</tt>
alpar@357
   265
    Suurballe& flowMap(FlowMap &map) {
alpar@357
   266
      if (_local_flow) {
alpar@357
   267
        delete _flow;
alpar@357
   268
        _local_flow = false;
alpar@357
   269
      }
alpar@357
   270
      _flow = &map;
alpar@357
   271
      return *this;
alpar@357
   272
    }
alpar@357
   273
kpeter@358
   274
    /// \brief Set the potential map.
alpar@357
   275
    ///
kpeter@358
   276
    /// This function sets the potential map.
alpar@357
   277
    ///
alpar@463
   278
    /// The potentials provide the dual solution of the underlying
alpar@357
   279
    /// minimum cost flow problem.
alpar@357
   280
    ///
kpeter@606
   281
    /// \return <tt>(*this)</tt>
alpar@357
   282
    Suurballe& potentialMap(PotentialMap &map) {
alpar@357
   283
      if (_local_potential) {
alpar@357
   284
        delete _potential;
alpar@357
   285
        _local_potential = false;
alpar@357
   286
      }
alpar@357
   287
      _potential = &map;
alpar@357
   288
      return *this;
alpar@357
   289
    }
alpar@357
   290
alpar@357
   291
    /// \name Execution control
alpar@357
   292
    /// The simplest way to execute the algorithm is to call the run()
alpar@357
   293
    /// function.
alpar@357
   294
    /// \n
alpar@357
   295
    /// If you only need the flow that is the union of the found
alpar@357
   296
    /// arc-disjoint paths, you may call init() and findFlow().
alpar@357
   297
alpar@357
   298
    /// @{
alpar@357
   299
kpeter@358
   300
    /// \brief Run the algorithm.
alpar@357
   301
    ///
kpeter@358
   302
    /// This function runs the algorithm.
alpar@357
   303
    ///
alpar@357
   304
    /// \param k The number of paths to be found.
alpar@357
   305
    ///
kpeter@358
   306
    /// \return \c k if there are at least \c k arc-disjoint paths from
kpeter@358
   307
    /// \c s to \c t in the digraph. Otherwise it returns the number of
alpar@357
   308
    /// arc-disjoint paths found.
alpar@357
   309
    ///
alpar@357
   310
    /// \note Apart from the return value, <tt>s.run(k)</tt> is just a
alpar@357
   311
    /// shortcut of the following code.
alpar@357
   312
    /// \code
alpar@357
   313
    ///   s.init();
alpar@357
   314
    ///   s.findFlow(k);
alpar@357
   315
    ///   s.findPaths();
alpar@357
   316
    /// \endcode
alpar@357
   317
    int run(int k = 2) {
alpar@357
   318
      init();
alpar@357
   319
      findFlow(k);
alpar@357
   320
      findPaths();
alpar@357
   321
      return _path_num;
alpar@357
   322
    }
alpar@357
   323
kpeter@358
   324
    /// \brief Initialize the algorithm.
alpar@357
   325
    ///
kpeter@358
   326
    /// This function initializes the algorithm.
alpar@357
   327
    void init() {
kpeter@358
   328
      // Initialize maps
alpar@357
   329
      if (!_flow) {
alpar@357
   330
        _flow = new FlowMap(_graph);
alpar@357
   331
        _local_flow = true;
alpar@357
   332
      }
alpar@357
   333
      if (!_potential) {
alpar@357
   334
        _potential = new PotentialMap(_graph);
alpar@357
   335
        _local_potential = true;
alpar@357
   336
      }
alpar@357
   337
      for (ArcIt e(_graph); e != INVALID; ++e) (*_flow)[e] = 0;
alpar@357
   338
      for (NodeIt n(_graph); n != INVALID; ++n) (*_potential)[n] = 0;
alpar@357
   339
alpar@463
   340
      _dijkstra = new ResidualDijkstra( _graph, *_flow, _length,
alpar@357
   341
                                        *_potential, _pred,
alpar@357
   342
                                        _source, _target );
alpar@357
   343
    }
alpar@357
   344
kpeter@358
   345
    /// \brief Execute the successive shortest path algorithm to find
alpar@357
   346
    /// an optimal flow.
alpar@357
   347
    ///
kpeter@358
   348
    /// This function executes the successive shortest path algorithm to
kpeter@358
   349
    /// find a minimum cost flow, which is the union of \c k or less
alpar@357
   350
    /// arc-disjoint paths.
alpar@357
   351
    ///
kpeter@358
   352
    /// \return \c k if there are at least \c k arc-disjoint paths from
kpeter@358
   353
    /// \c s to \c t in the digraph. Otherwise it returns the number of
alpar@357
   354
    /// arc-disjoint paths found.
alpar@357
   355
    ///
alpar@357
   356
    /// \pre \ref init() must be called before using this function.
alpar@357
   357
    int findFlow(int k = 2) {
kpeter@358
   358
      // Find shortest paths
alpar@357
   359
      _path_num = 0;
alpar@357
   360
      while (_path_num < k) {
kpeter@358
   361
        // Run Dijkstra
alpar@357
   362
        if (!_dijkstra->run()) break;
alpar@357
   363
        ++_path_num;
alpar@357
   364
kpeter@358
   365
        // Set the flow along the found shortest path
alpar@357
   366
        Node u = _target;
alpar@357
   367
        Arc e;
alpar@357
   368
        while ((e = _pred[u]) != INVALID) {
alpar@357
   369
          if (u == _graph.target(e)) {
alpar@357
   370
            (*_flow)[e] = 1;
alpar@357
   371
            u = _graph.source(e);
alpar@357
   372
          } else {
alpar@357
   373
            (*_flow)[e] = 0;
alpar@357
   374
            u = _graph.target(e);
alpar@357
   375
          }
alpar@357
   376
        }
alpar@357
   377
      }
alpar@357
   378
      return _path_num;
alpar@357
   379
    }
alpar@463
   380
kpeter@358
   381
    /// \brief Compute the paths from the flow.
alpar@357
   382
    ///
kpeter@358
   383
    /// This function computes the paths from the flow.
alpar@357
   384
    ///
alpar@357
   385
    /// \pre \ref init() and \ref findFlow() must be called before using
alpar@357
   386
    /// this function.
alpar@357
   387
    void findPaths() {
kpeter@358
   388
      // Create the residual flow map (the union of the paths not found
kpeter@358
   389
      // so far)
alpar@357
   390
      FlowMap res_flow(_graph);
kpeter@358
   391
      for(ArcIt a(_graph); a != INVALID; ++a) res_flow[a] = (*_flow)[a];
alpar@357
   392
alpar@357
   393
      paths.clear();
alpar@357
   394
      paths.resize(_path_num);
alpar@357
   395
      for (int i = 0; i < _path_num; ++i) {
alpar@357
   396
        Node n = _source;
alpar@357
   397
        while (n != _target) {
alpar@357
   398
          OutArcIt e(_graph, n);
alpar@357
   399
          for ( ; res_flow[e] == 0; ++e) ;
alpar@357
   400
          n = _graph.target(e);
alpar@357
   401
          paths[i].addBack(e);
alpar@357
   402
          res_flow[e] = 0;
alpar@357
   403
        }
alpar@357
   404
      }
alpar@357
   405
    }
alpar@357
   406
alpar@357
   407
    /// @}
alpar@357
   408
alpar@357
   409
    /// \name Query Functions
kpeter@358
   410
    /// The results of the algorithm can be obtained using these
alpar@357
   411
    /// functions.
alpar@357
   412
    /// \n The algorithm should be executed before using them.
alpar@357
   413
alpar@357
   414
    /// @{
alpar@357
   415
kpeter@358
   416
    /// \brief Return a const reference to the arc map storing the
alpar@357
   417
    /// found flow.
alpar@357
   418
    ///
kpeter@358
   419
    /// This function returns a const reference to the arc map storing
kpeter@358
   420
    /// the flow that is the union of the found arc-disjoint paths.
alpar@357
   421
    ///
kpeter@358
   422
    /// \pre \ref run() or \ref findFlow() must be called before using
kpeter@358
   423
    /// this function.
alpar@357
   424
    const FlowMap& flowMap() const {
alpar@357
   425
      return *_flow;
alpar@357
   426
    }
alpar@357
   427
kpeter@358
   428
    /// \brief Return a const reference to the node map storing the
alpar@357
   429
    /// found potentials (the dual solution).
alpar@357
   430
    ///
kpeter@358
   431
    /// This function returns a const reference to the node map storing
kpeter@358
   432
    /// the found potentials that provide the dual solution of the
kpeter@358
   433
    /// underlying minimum cost flow problem.
alpar@357
   434
    ///
kpeter@358
   435
    /// \pre \ref run() or \ref findFlow() must be called before using
kpeter@358
   436
    /// this function.
alpar@357
   437
    const PotentialMap& potentialMap() const {
alpar@357
   438
      return *_potential;
alpar@357
   439
    }
alpar@357
   440
kpeter@358
   441
    /// \brief Return the flow on the given arc.
alpar@357
   442
    ///
kpeter@358
   443
    /// This function returns the flow on the given arc.
alpar@357
   444
    /// It is \c 1 if the arc is involved in one of the found paths,
alpar@357
   445
    /// otherwise it is \c 0.
alpar@357
   446
    ///
kpeter@358
   447
    /// \pre \ref run() or \ref findFlow() must be called before using
kpeter@358
   448
    /// this function.
alpar@357
   449
    int flow(const Arc& arc) const {
alpar@357
   450
      return (*_flow)[arc];
alpar@357
   451
    }
alpar@357
   452
kpeter@358
   453
    /// \brief Return the potential of the given node.
alpar@357
   454
    ///
kpeter@358
   455
    /// This function returns the potential of the given node.
alpar@357
   456
    ///
kpeter@358
   457
    /// \pre \ref run() or \ref findFlow() must be called before using
kpeter@358
   458
    /// this function.
alpar@357
   459
    Length potential(const Node& node) const {
alpar@357
   460
      return (*_potential)[node];
alpar@357
   461
    }
alpar@357
   462
kpeter@358
   463
    /// \brief Return the total length (cost) of the found paths (flow).
alpar@357
   464
    ///
kpeter@358
   465
    /// This function returns the total length (cost) of the found paths
kpeter@606
   466
    /// (flow). The complexity of the function is O(e).
alpar@357
   467
    ///
kpeter@358
   468
    /// \pre \ref run() or \ref findFlow() must be called before using
kpeter@358
   469
    /// this function.
alpar@357
   470
    Length totalLength() const {
alpar@357
   471
      Length c = 0;
alpar@357
   472
      for (ArcIt e(_graph); e != INVALID; ++e)
alpar@357
   473
        c += (*_flow)[e] * _length[e];
alpar@357
   474
      return c;
alpar@357
   475
    }
alpar@357
   476
kpeter@358
   477
    /// \brief Return the number of the found paths.
alpar@357
   478
    ///
kpeter@358
   479
    /// This function returns the number of the found paths.
alpar@357
   480
    ///
kpeter@358
   481
    /// \pre \ref run() or \ref findFlow() must be called before using
kpeter@358
   482
    /// this function.
alpar@357
   483
    int pathNum() const {
alpar@357
   484
      return _path_num;
alpar@357
   485
    }
alpar@357
   486
kpeter@358
   487
    /// \brief Return a const reference to the specified path.
alpar@357
   488
    ///
kpeter@358
   489
    /// This function returns a const reference to the specified path.
alpar@357
   490
    ///
alpar@357
   491
    /// \param i The function returns the \c i-th path.
alpar@357
   492
    /// \c i must be between \c 0 and <tt>%pathNum()-1</tt>.
alpar@357
   493
    ///
kpeter@358
   494
    /// \pre \ref run() or \ref findPaths() must be called before using
kpeter@358
   495
    /// this function.
alpar@357
   496
    Path path(int i) const {
alpar@357
   497
      return paths[i];
alpar@357
   498
    }
alpar@357
   499
alpar@357
   500
    /// @}
alpar@357
   501
alpar@357
   502
  }; //class Suurballe
alpar@357
   503
alpar@357
   504
  ///@}
alpar@357
   505
alpar@357
   506
} //namespace lemon
alpar@357
   507
alpar@357
   508
#endif //LEMON_SUURBALLE_H