lemon/suurballe.h
author Peter Kovacs <kpeter@inf.elte.hu>
Fri, 12 Dec 2008 22:59:17 +0100
changeset 472 91fcb8ed4cdc
parent 357 2f64c4a692a8
child 444 cace3206223b
permissions -rw-r--r--
Various bug fixes and code improvements in adaptors.h (#67)

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