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