COIN-OR::LEMON - Graph Library

source: lemon-1.2/lemon/suurballe.h @ 857:abb95d48e89e

Last change on this file since 857:abb95d48e89e was 857:abb95d48e89e, checked in by Peter Kovacs <kpeter@…>, 15 years ago

Add traits class + named parameters to Suurballe (#323)

The following types can be modified using named parameters:

File size: 23.3 KB
RevLine 
[440]1/* -*- mode: C++; indent-tabs-mode: nil; -*-
[345]2 *
[440]3 * This file is a part of LEMON, a generic C++ optimization library.
[345]4 *
[440]5 * Copyright (C) 2003-2009
[345]6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19#ifndef LEMON_SUURBALLE_H
20#define LEMON_SUURBALLE_H
21
22///\ingroup shortest_path
23///\file
24///\brief An algorithm for finding arc-disjoint paths between two
25/// nodes having minimum total length.
26
27#include <vector>
[623]28#include <limits>
[345]29#include <lemon/bin_heap.h>
30#include <lemon/path.h>
[519]31#include <lemon/list_graph.h>
[854]32#include <lemon/dijkstra.h>
[519]33#include <lemon/maps.h>
[345]34
35namespace lemon {
36
[857]37  /// \brief Default traits class of Suurballe algorithm.
38  ///
39  /// Default traits class of Suurballe algorithm.
40  /// \tparam GR The digraph type the algorithm runs on.
41  /// \tparam LEN The type of the length map.
42  /// The default value is <tt>GR::ArcMap<int></tt>.
43#ifdef DOXYGEN
44  template <typename GR, typename LEN>
45#else
46  template < typename GR,
47             typename LEN = typename GR::template ArcMap<int> >
48#endif
49  struct SuurballeDefaultTraits
50  {
51    /// The type of the digraph.
52    typedef GR Digraph;
53    /// The type of the length map.
54    typedef LEN LengthMap;
55    /// The type of the lengths.
56    typedef typename LEN::Value Length;
57    /// The type of the flow map.
58    typedef typename GR::template ArcMap<int> FlowMap;
59    /// The type of the potential map.
60    typedef typename GR::template NodeMap<Length> PotentialMap;
61
62    /// \brief The path type
63    ///
64    /// The type used for storing the found arc-disjoint paths.
65    /// It must conform to the \ref lemon::concepts::Path "Path" concept
66    /// and it must have an \c addBack() function.
67    typedef lemon::Path<Digraph> Path;
68   
69    /// The cross reference type used for the heap.
70    typedef typename GR::template NodeMap<int> HeapCrossRef;
71
72    /// \brief The heap type used for internal Dijkstra computations.
73    ///
74    /// The type of the heap used for internal Dijkstra computations.
75    /// It must conform to the \ref lemon::concepts::Heap "Heap" concept
76    /// and its priority type must be \c Length.
77    typedef BinHeap<Length, HeapCrossRef> Heap;
78  };
79
[345]80  /// \addtogroup shortest_path
81  /// @{
82
[346]83  /// \brief Algorithm for finding arc-disjoint paths between two nodes
84  /// having minimum total length.
[345]85  ///
86  /// \ref lemon::Suurballe "Suurballe" implements an algorithm for
87  /// finding arc-disjoint paths having minimum total length (cost)
[346]88  /// from a given source node to a given target node in a digraph.
[345]89  ///
[623]90  /// Note that this problem is a special case of the \ref min_cost_flow
91  /// "minimum cost flow problem". This implementation is actually an
92  /// efficient specialized version of the \ref CapacityScaling
[853]93  /// "successive shortest path" algorithm directly for this problem.
[623]94  /// Therefore this class provides query functions for flow values and
95  /// node potentials (the dual solution) just like the minimum cost flow
96  /// algorithms.
[345]97  ///
[559]98  /// \tparam GR The digraph type the algorithm runs on.
[623]99  /// \tparam LEN The type of the length map.
100  /// The default value is <tt>GR::ArcMap<int></tt>.
[345]101  ///
[852]102  /// \warning Length values should be \e non-negative.
[345]103  ///
[853]104  /// \note For finding \e node-disjoint paths, this algorithm can be used
[623]105  /// along with the \ref SplitNodes adaptor.
[346]106#ifdef DOXYGEN
[857]107  template <typename GR, typename LEN, typename TR>
[346]108#else
[623]109  template < typename GR,
[857]110             typename LEN = typename GR::template ArcMap<int>,
111             typename TR = SuurballeDefaultTraits<GR, LEN> >
[346]112#endif
[345]113  class Suurballe
114  {
[559]115    TEMPLATE_DIGRAPH_TYPEDEFS(GR);
[345]116
117    typedef ConstMap<Arc, int> ConstArcMap;
[559]118    typedef typename GR::template NodeMap<Arc> PredMap;
[345]119
120  public:
121
[857]122    /// The type of the digraph.
123    typedef typename TR::Digraph Digraph;
[559]124    /// The type of the length map.
[857]125    typedef typename TR::LengthMap LengthMap;
[559]126    /// The type of the lengths.
[857]127    typedef typename TR::Length Length;
128
[623]129    /// The type of the flow map.
[857]130    typedef typename TR::FlowMap FlowMap;
[623]131    /// The type of the potential map.
[857]132    typedef typename TR::PotentialMap PotentialMap;
133    /// The type of the path structures.
134    typedef typename TR::Path Path;
135    /// The cross reference type used for the heap.
136    typedef typename TR::HeapCrossRef HeapCrossRef;
137    /// The heap type used for internal Dijkstra computations.
138    typedef typename TR::Heap Heap;
[623]139
[857]140    /// The \ref SuurballeDefaultTraits "traits class" of the algorithm.
141    typedef TR Traits;
[345]142
143  private:
[440]144
[623]145    // ResidualDijkstra is a special implementation of the
146    // Dijkstra algorithm for finding shortest paths in the
147    // residual network with respect to the reduced arc lengths
148    // and modifying the node potentials according to the
149    // distance of the nodes.
[345]150    class ResidualDijkstra
151    {
152    private:
153
154      const Digraph &_graph;
[853]155      const LengthMap &_length;
[345]156      const FlowMap &_flow;
[853]157      PotentialMap &_pi;
[345]158      PredMap &_pred;
159      Node _s;
160      Node _t;
[853]161     
162      PotentialMap _dist;
163      std::vector<Node> _proc_nodes;
[345]164
165    public:
166
[853]167      // Constructor
168      ResidualDijkstra(Suurballe &srb) :
169        _graph(srb._graph), _length(srb._length),
170        _flow(*srb._flow), _pi(*srb._potential), _pred(srb._pred),
171        _s(srb._s), _t(srb._t), _dist(_graph) {}
172       
173      // Run the algorithm and return true if a path is found
174      // from the source node to the target node.
175      bool run(int cnt) {
176        return cnt == 0 ? startFirst() : start();
177      }
[345]178
[853]179    private:
180   
181      // Execute the algorithm for the first time (the flow and potential
182      // functions have to be identically zero).
183      bool startFirst() {
[345]184        HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP);
185        Heap heap(heap_cross_ref);
186        heap.push(_s, 0);
187        _pred[_s] = INVALID;
188        _proc_nodes.clear();
189
[346]190        // Process nodes
[345]191        while (!heap.empty() && heap.top() != _t) {
192          Node u = heap.top(), v;
[853]193          Length d = heap.prio(), dn;
[345]194          _dist[u] = heap.prio();
[853]195          _proc_nodes.push_back(u);
[345]196          heap.pop();
[853]197
198          // Traverse outgoing arcs
199          for (OutArcIt e(_graph, u); e != INVALID; ++e) {
200            v = _graph.target(e);
201            switch(heap.state(v)) {
202              case Heap::PRE_HEAP:
203                heap.push(v, d + _length[e]);
204                _pred[v] = e;
205                break;
206              case Heap::IN_HEAP:
207                dn = d + _length[e];
208                if (dn < heap[v]) {
209                  heap.decrease(v, dn);
210                  _pred[v] = e;
211                }
212                break;
213              case Heap::POST_HEAP:
214                break;
215            }
216          }
217        }
218        if (heap.empty()) return false;
219
220        // Update potentials of processed nodes
221        Length t_dist = heap.prio();
222        for (int i = 0; i < int(_proc_nodes.size()); ++i)
223          _pi[_proc_nodes[i]] = _dist[_proc_nodes[i]] - t_dist;
224        return true;
225      }
226
227      // Execute the algorithm.
228      bool start() {
229        HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP);
230        Heap heap(heap_cross_ref);
231        heap.push(_s, 0);
232        _pred[_s] = INVALID;
233        _proc_nodes.clear();
234
235        // Process nodes
236        while (!heap.empty() && heap.top() != _t) {
237          Node u = heap.top(), v;
238          Length d = heap.prio() + _pi[u], dn;
239          _dist[u] = heap.prio();
[345]240          _proc_nodes.push_back(u);
[853]241          heap.pop();
[345]242
[346]243          // Traverse outgoing arcs
[345]244          for (OutArcIt e(_graph, u); e != INVALID; ++e) {
245            if (_flow[e] == 0) {
246              v = _graph.target(e);
247              switch(heap.state(v)) {
[853]248                case Heap::PRE_HEAP:
249                  heap.push(v, d + _length[e] - _pi[v]);
[345]250                  _pred[v] = e;
[853]251                  break;
252                case Heap::IN_HEAP:
253                  dn = d + _length[e] - _pi[v];
254                  if (dn < heap[v]) {
255                    heap.decrease(v, dn);
256                    _pred[v] = e;
257                  }
258                  break;
259                case Heap::POST_HEAP:
260                  break;
[345]261              }
262            }
263          }
264
[346]265          // Traverse incoming arcs
[345]266          for (InArcIt e(_graph, u); e != INVALID; ++e) {
267            if (_flow[e] == 1) {
268              v = _graph.source(e);
269              switch(heap.state(v)) {
[853]270                case Heap::PRE_HEAP:
271                  heap.push(v, d - _length[e] - _pi[v]);
[345]272                  _pred[v] = e;
[853]273                  break;
274                case Heap::IN_HEAP:
275                  dn = d - _length[e] - _pi[v];
276                  if (dn < heap[v]) {
277                    heap.decrease(v, dn);
278                    _pred[v] = e;
279                  }
280                  break;
281                case Heap::POST_HEAP:
282                  break;
[345]283              }
284            }
285          }
286        }
287        if (heap.empty()) return false;
288
[346]289        // Update potentials of processed nodes
[345]290        Length t_dist = heap.prio();
291        for (int i = 0; i < int(_proc_nodes.size()); ++i)
[853]292          _pi[_proc_nodes[i]] += _dist[_proc_nodes[i]] - t_dist;
[345]293        return true;
294      }
295
296    }; //class ResidualDijkstra
297
[857]298  public:
299
300    /// \name Named Template Parameters
301    /// @{
302
303    template <typename T>
304    struct SetFlowMapTraits : public Traits {
305      typedef T FlowMap;
306    };
307
308    /// \brief \ref named-templ-param "Named parameter" for setting
309    /// \c FlowMap type.
310    ///
311    /// \ref named-templ-param "Named parameter" for setting
312    /// \c FlowMap type.
313    template <typename T>
314    struct SetFlowMap
315      : public Suurballe<GR, LEN, SetFlowMapTraits<T> > {
316      typedef Suurballe<GR, LEN, SetFlowMapTraits<T> > Create;
317    };
318
319    template <typename T>
320    struct SetPotentialMapTraits : public Traits {
321      typedef T PotentialMap;
322    };
323
324    /// \brief \ref named-templ-param "Named parameter" for setting
325    /// \c PotentialMap type.
326    ///
327    /// \ref named-templ-param "Named parameter" for setting
328    /// \c PotentialMap type.
329    template <typename T>
330    struct SetPotentialMap
331      : public Suurballe<GR, LEN, SetPotentialMapTraits<T> > {
332      typedef Suurballe<GR, LEN, SetPotentialMapTraits<T> > Create;
333    };
334
335    template <typename T>
336    struct SetPathTraits : public Traits {
337      typedef T Path;
338    };
339
340    /// \brief \ref named-templ-param "Named parameter" for setting
341    /// \c %Path type.
342    ///
343    /// \ref named-templ-param "Named parameter" for setting \c %Path type.
344    /// It must conform to the \ref lemon::concepts::Path "Path" concept
345    /// and it must have an \c addBack() function.
346    template <typename T>
347    struct SetPath
348      : public Suurballe<GR, LEN, SetPathTraits<T> > {
349      typedef Suurballe<GR, LEN, SetPathTraits<T> > Create;
350    };
351   
352    template <typename H, typename CR>
353    struct SetHeapTraits : public Traits {
354      typedef H Heap;
355      typedef CR HeapCrossRef;
356    };
357
358    /// \brief \ref named-templ-param "Named parameter" for setting
359    /// \c Heap and \c HeapCrossRef types.
360    ///
361    /// \ref named-templ-param "Named parameter" for setting \c Heap
362    /// and \c HeapCrossRef types with automatic allocation.
363    /// They will be used for internal Dijkstra computations.
364    /// The heap type must conform to the \ref lemon::concepts::Heap "Heap"
365    /// concept and its priority type must be \c Length.
366    template <typename H,
367              typename CR = typename Digraph::template NodeMap<int> >
368    struct SetHeap
369      : public Suurballe<GR, LEN, SetHeapTraits<H, CR> > {
370      typedef Suurballe<GR, LEN, SetHeapTraits<H, CR> > Create;
371    };
372
373    /// @}
374
[345]375  private:
376
[346]377    // The digraph the algorithm runs on
[345]378    const Digraph &_graph;
379    // The length map
380    const LengthMap &_length;
[440]381
[345]382    // Arc map of the current flow
383    FlowMap *_flow;
384    bool _local_flow;
385    // Node map of the current potentials
386    PotentialMap *_potential;
387    bool _local_potential;
388
389    // The source node
[853]390    Node _s;
[345]391    // The target node
[853]392    Node _t;
[345]393
394    // Container to store the found paths
[853]395    std::vector<Path> _paths;
[345]396    int _path_num;
397
398    // The pred arc map
399    PredMap _pred;
[854]400   
401    // Data for full init
402    PotentialMap *_init_dist;
403    PredMap *_init_pred;
404    bool _full_init;
[345]405
406  public:
407
408    /// \brief Constructor.
409    ///
410    /// Constructor.
411    ///
[623]412    /// \param graph The digraph the algorithm runs on.
[345]413    /// \param length The length (cost) values of the arcs.
[623]414    Suurballe( const Digraph &graph,
415               const LengthMap &length ) :
416      _graph(graph), _length(length), _flow(0), _local_flow(false),
[854]417      _potential(0), _local_potential(false), _pred(graph),
418      _init_dist(0), _init_pred(0)
[852]419    {}
[345]420
421    /// Destructor.
422    ~Suurballe() {
423      if (_local_flow) delete _flow;
424      if (_local_potential) delete _potential;
[854]425      delete _init_dist;
426      delete _init_pred;
[345]427    }
428
[346]429    /// \brief Set the flow map.
[345]430    ///
[346]431    /// This function sets the flow map.
[623]432    /// If it is not used before calling \ref run() or \ref init(),
433    /// an instance will be allocated automatically. The destructor
434    /// deallocates this automatically allocated map, of course.
[345]435    ///
[623]436    /// The found flow contains only 0 and 1 values, since it is the
437    /// union of the found arc-disjoint paths.
[345]438    ///
[559]439    /// \return <tt>(*this)</tt>
[345]440    Suurballe& flowMap(FlowMap &map) {
441      if (_local_flow) {
442        delete _flow;
443        _local_flow = false;
444      }
445      _flow = &map;
446      return *this;
447    }
448
[346]449    /// \brief Set the potential map.
[345]450    ///
[346]451    /// This function sets the potential map.
[623]452    /// If it is not used before calling \ref run() or \ref init(),
453    /// an instance will be allocated automatically. The destructor
454    /// deallocates this automatically allocated map, of course.
[345]455    ///
[623]456    /// The node potentials provide the dual solution of the underlying
457    /// \ref min_cost_flow "minimum cost flow problem".
[345]458    ///
[559]459    /// \return <tt>(*this)</tt>
[345]460    Suurballe& potentialMap(PotentialMap &map) {
461      if (_local_potential) {
462        delete _potential;
463        _local_potential = false;
464      }
465      _potential = &map;
466      return *this;
467    }
468
[584]469    /// \name Execution Control
[345]470    /// The simplest way to execute the algorithm is to call the run()
[854]471    /// function.\n
472    /// If you need to execute the algorithm many times using the same
473    /// source node, then you may call fullInit() once and start()
474    /// for each target node.\n
[345]475    /// If you only need the flow that is the union of the found
[854]476    /// arc-disjoint paths, then you may call findFlow() instead of
477    /// start().
[345]478
479    /// @{
480
[346]481    /// \brief Run the algorithm.
[345]482    ///
[346]483    /// This function runs the algorithm.
[345]484    ///
[623]485    /// \param s The source node.
486    /// \param t The target node.
[345]487    /// \param k The number of paths to be found.
488    ///
[346]489    /// \return \c k if there are at least \c k arc-disjoint paths from
490    /// \c s to \c t in the digraph. Otherwise it returns the number of
[345]491    /// arc-disjoint paths found.
492    ///
[623]493    /// \note Apart from the return value, <tt>s.run(s, t, k)</tt> is
494    /// just a shortcut of the following code.
[345]495    /// \code
[623]496    ///   s.init(s);
[854]497    ///   s.start(t, k);
[345]498    /// \endcode
[623]499    int run(const Node& s, const Node& t, int k = 2) {
500      init(s);
[854]501      start(t, k);
[345]502      return _path_num;
503    }
504
[346]505    /// \brief Initialize the algorithm.
[345]506    ///
[854]507    /// This function initializes the algorithm with the given source node.
[623]508    ///
509    /// \param s The source node.
510    void init(const Node& s) {
[853]511      _s = s;
[623]512
[346]513      // Initialize maps
[345]514      if (!_flow) {
515        _flow = new FlowMap(_graph);
516        _local_flow = true;
517      }
518      if (!_potential) {
519        _potential = new PotentialMap(_graph);
520        _local_potential = true;
521      }
[854]522      _full_init = false;
523    }
524
525    /// \brief Initialize the algorithm and perform Dijkstra.
526    ///
527    /// This function initializes the algorithm and performs a full
528    /// Dijkstra search from the given source node. It makes consecutive
529    /// executions of \ref start() "start(t, k)" faster, since they
530    /// have to perform %Dijkstra only k-1 times.
531    ///
532    /// This initialization is usually worth using instead of \ref init()
533    /// if the algorithm is executed many times using the same source node.
534    ///
535    /// \param s The source node.
536    void fullInit(const Node& s) {
537      // Initialize maps
538      init(s);
539      if (!_init_dist) {
540        _init_dist = new PotentialMap(_graph);
541      }
542      if (!_init_pred) {
543        _init_pred = new PredMap(_graph);
544      }
545
546      // Run a full Dijkstra
547      typename Dijkstra<Digraph, LengthMap>
548        ::template SetStandardHeap<Heap>
549        ::template SetDistMap<PotentialMap>
550        ::template SetPredMap<PredMap>
551        ::Create dijk(_graph, _length);
552      dijk.distMap(*_init_dist).predMap(*_init_pred);
553      dijk.run(s);
554     
555      _full_init = true;
556    }
557
558    /// \brief Execute the algorithm.
559    ///
560    /// This function executes the algorithm.
561    ///
562    /// \param t The target node.
563    /// \param k The number of paths to be found.
564    ///
565    /// \return \c k if there are at least \c k arc-disjoint paths from
566    /// \c s to \c t in the digraph. Otherwise it returns the number of
567    /// arc-disjoint paths found.
568    ///
569    /// \note Apart from the return value, <tt>s.start(t, k)</tt> is
570    /// just a shortcut of the following code.
571    /// \code
572    ///   s.findFlow(t, k);
573    ///   s.findPaths();
574    /// \endcode
575    int start(const Node& t, int k = 2) {
576      findFlow(t, k);
577      findPaths();
578      return _path_num;
[345]579    }
580
[623]581    /// \brief Execute the algorithm to find an optimal flow.
[345]582    ///
[346]583    /// This function executes the successive shortest path algorithm to
[623]584    /// find a minimum cost flow, which is the union of \c k (or less)
[345]585    /// arc-disjoint paths.
586    ///
[623]587    /// \param t The target node.
588    /// \param k The number of paths to be found.
589    ///
[346]590    /// \return \c k if there are at least \c k arc-disjoint paths from
[623]591    /// the source node to the given node \c t in the digraph.
592    /// Otherwise it returns the number of arc-disjoint paths found.
[345]593    ///
594    /// \pre \ref init() must be called before using this function.
[623]595    int findFlow(const Node& t, int k = 2) {
[853]596      _t = t;
597      ResidualDijkstra dijkstra(*this);
[854]598     
599      // Initialization
600      for (ArcIt e(_graph); e != INVALID; ++e) {
601        (*_flow)[e] = 0;
602      }
603      if (_full_init) {
604        for (NodeIt n(_graph); n != INVALID; ++n) {
605          (*_potential)[n] = (*_init_dist)[n];
606        }
607        Node u = _t;
608        Arc e;
609        while ((e = (*_init_pred)[u]) != INVALID) {
610          (*_flow)[e] = 1;
611          u = _graph.source(e);
612        }       
613        _path_num = 1;
614      } else {
615        for (NodeIt n(_graph); n != INVALID; ++n) {
616          (*_potential)[n] = 0;
617        }
618        _path_num = 0;
619      }
[623]620
[346]621      // Find shortest paths
[345]622      while (_path_num < k) {
[346]623        // Run Dijkstra
[853]624        if (!dijkstra.run(_path_num)) break;
[345]625        ++_path_num;
626
[346]627        // Set the flow along the found shortest path
[853]628        Node u = _t;
[345]629        Arc e;
630        while ((e = _pred[u]) != INVALID) {
631          if (u == _graph.target(e)) {
632            (*_flow)[e] = 1;
633            u = _graph.source(e);
634          } else {
635            (*_flow)[e] = 0;
636            u = _graph.target(e);
637          }
638        }
639      }
640      return _path_num;
641    }
[440]642
[346]643    /// \brief Compute the paths from the flow.
[345]644    ///
[853]645    /// This function computes arc-disjoint paths from the found minimum
646    /// cost flow, which is the union of them.
[345]647    ///
648    /// \pre \ref init() and \ref findFlow() must be called before using
649    /// this function.
650    void findPaths() {
651      FlowMap res_flow(_graph);
[346]652      for(ArcIt a(_graph); a != INVALID; ++a) res_flow[a] = (*_flow)[a];
[345]653
[853]654      _paths.clear();
655      _paths.resize(_path_num);
[345]656      for (int i = 0; i < _path_num; ++i) {
[853]657        Node n = _s;
658        while (n != _t) {
[345]659          OutArcIt e(_graph, n);
660          for ( ; res_flow[e] == 0; ++e) ;
661          n = _graph.target(e);
[853]662          _paths[i].addBack(e);
[345]663          res_flow[e] = 0;
664        }
665      }
666    }
667
668    /// @}
669
670    /// \name Query Functions
[346]671    /// The results of the algorithm can be obtained using these
[345]672    /// functions.
673    /// \n The algorithm should be executed before using them.
674
675    /// @{
676
[623]677    /// \brief Return the total length of the found paths.
678    ///
679    /// This function returns the total length of the found paths, i.e.
680    /// the total cost of the found flow.
681    /// The complexity of the function is O(e).
682    ///
683    /// \pre \ref run() or \ref findFlow() must be called before using
684    /// this function.
685    Length totalLength() const {
686      Length c = 0;
687      for (ArcIt e(_graph); e != INVALID; ++e)
688        c += (*_flow)[e] * _length[e];
689      return c;
690    }
691
692    /// \brief Return the flow value on the given arc.
693    ///
694    /// This function returns the flow value on the given arc.
695    /// It is \c 1 if the arc is involved in one of the found arc-disjoint
696    /// paths, otherwise it is \c 0.
697    ///
698    /// \pre \ref run() or \ref findFlow() must be called before using
699    /// this function.
700    int flow(const Arc& arc) const {
701      return (*_flow)[arc];
702    }
703
704    /// \brief Return a const reference to an arc map storing the
[345]705    /// found flow.
706    ///
[623]707    /// This function returns a const reference to an arc map storing
[346]708    /// the flow that is the union of the found arc-disjoint paths.
[345]709    ///
[346]710    /// \pre \ref run() or \ref findFlow() must be called before using
711    /// this function.
[345]712    const FlowMap& flowMap() const {
713      return *_flow;
714    }
715
[346]716    /// \brief Return the potential of the given node.
[345]717    ///
[346]718    /// This function returns the potential of the given node.
[623]719    /// The node potentials provide the dual solution of the
720    /// underlying \ref min_cost_flow "minimum cost flow problem".
[345]721    ///
[346]722    /// \pre \ref run() or \ref findFlow() must be called before using
723    /// this function.
[345]724    Length potential(const Node& node) const {
725      return (*_potential)[node];
726    }
727
[623]728    /// \brief Return a const reference to a node map storing the
729    /// found potentials (the dual solution).
[345]730    ///
[623]731    /// This function returns a const reference to a node map storing
732    /// the found potentials that provide the dual solution of the
733    /// underlying \ref min_cost_flow "minimum cost flow problem".
[345]734    ///
[346]735    /// \pre \ref run() or \ref findFlow() must be called before using
736    /// this function.
[623]737    const PotentialMap& potentialMap() const {
738      return *_potential;
[345]739    }
740
[346]741    /// \brief Return the number of the found paths.
[345]742    ///
[346]743    /// This function returns the number of the found paths.
[345]744    ///
[346]745    /// \pre \ref run() or \ref findFlow() must be called before using
746    /// this function.
[345]747    int pathNum() const {
748      return _path_num;
749    }
750
[346]751    /// \brief Return a const reference to the specified path.
[345]752    ///
[346]753    /// This function returns a const reference to the specified path.
[345]754    ///
[623]755    /// \param i The function returns the <tt>i</tt>-th path.
[345]756    /// \c i must be between \c 0 and <tt>%pathNum()-1</tt>.
757    ///
[346]758    /// \pre \ref run() or \ref findPaths() must be called before using
759    /// this function.
[851]760    const Path& path(int i) const {
[853]761      return _paths[i];
[345]762    }
763
764    /// @}
765
766  }; //class Suurballe
767
768  ///@}
769
770} //namespace lemon
771
772#endif //LEMON_SUURBALLE_H
Note: See TracBrowser for help on using the repository browser.