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