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