1.1 --- a/lemon/suurballe.h Fri Aug 09 11:07:27 2013 +0200
1.2 +++ b/lemon/suurballe.h Sun Aug 11 15:28:12 2013 +0200
1.3 @@ -2,7 +2,7 @@
1.4 *
1.5 * This file is a part of LEMON, a generic C++ optimization library.
1.6 *
1.7 - * Copyright (C) 2003-2009
1.8 + * Copyright (C) 2003-2010
1.9 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 *
1.12 @@ -29,10 +29,54 @@
1.13 #include <lemon/bin_heap.h>
1.14 #include <lemon/path.h>
1.15 #include <lemon/list_graph.h>
1.16 +#include <lemon/dijkstra.h>
1.17 #include <lemon/maps.h>
1.18
1.19 namespace lemon {
1.20
1.21 + /// \brief Default traits class of Suurballe algorithm.
1.22 + ///
1.23 + /// Default traits class of Suurballe algorithm.
1.24 + /// \tparam GR The digraph type the algorithm runs on.
1.25 + /// \tparam LEN The type of the length map.
1.26 + /// The default value is <tt>GR::ArcMap<int></tt>.
1.27 +#ifdef DOXYGEN
1.28 + template <typename GR, typename LEN>
1.29 +#else
1.30 + template < typename GR,
1.31 + typename LEN = typename GR::template ArcMap<int> >
1.32 +#endif
1.33 + struct SuurballeDefaultTraits
1.34 + {
1.35 + /// The type of the digraph.
1.36 + typedef GR Digraph;
1.37 + /// The type of the length map.
1.38 + typedef LEN LengthMap;
1.39 + /// The type of the lengths.
1.40 + typedef typename LEN::Value Length;
1.41 + /// The type of the flow map.
1.42 + typedef typename GR::template ArcMap<int> FlowMap;
1.43 + /// The type of the potential map.
1.44 + typedef typename GR::template NodeMap<Length> PotentialMap;
1.45 +
1.46 + /// \brief The path type
1.47 + ///
1.48 + /// The type used for storing the found arc-disjoint paths.
1.49 + /// It must conform to the \ref lemon::concepts::Path "Path" concept
1.50 + /// and it must have an \c addBack() function.
1.51 + typedef lemon::Path<Digraph> Path;
1.52 +
1.53 + /// The cross reference type used for the heap.
1.54 + typedef typename GR::template NodeMap<int> HeapCrossRef;
1.55 +
1.56 + /// \brief The heap type used for internal Dijkstra computations.
1.57 + ///
1.58 + /// The type of the heap used for internal Dijkstra computations.
1.59 + /// It must conform to the \ref lemon::concepts::Heap "Heap" concept
1.60 + /// and its priority type must be \c Length.
1.61 + typedef BinHeap<Length, HeapCrossRef> Heap;
1.62 + };
1.63 +
1.64 /// \addtogroup shortest_path
1.65 /// @{
1.66
1.67 @@ -46,7 +90,7 @@
1.68 /// Note that this problem is a special case of the \ref min_cost_flow
1.69 /// "minimum cost flow problem". This implementation is actually an
1.70 /// efficient specialized version of the \ref CapacityScaling
1.71 - /// "Successive Shortest Path" algorithm directly for this problem.
1.72 + /// "successive shortest path" algorithm directly for this problem.
1.73 /// Therefore this class provides query functions for flow values and
1.74 /// node potentials (the dual solution) just like the minimum cost flow
1.75 /// algorithms.
1.76 @@ -57,13 +101,14 @@
1.77 ///
1.78 /// \warning Length values should be \e non-negative.
1.79 ///
1.80 - /// \note For finding node-disjoint paths this algorithm can be used
1.81 + /// \note For finding \e node-disjoint paths, this algorithm can be used
1.82 /// along with the \ref SplitNodes adaptor.
1.83 #ifdef DOXYGEN
1.84 - template <typename GR, typename LEN>
1.85 + template <typename GR, typename LEN, typename TR>
1.86 #else
1.87 template < typename GR,
1.88 - typename LEN = typename GR::template ArcMap<int> >
1.89 + typename LEN = typename GR::template ArcMap<int>,
1.90 + typename TR = SuurballeDefaultTraits<GR, LEN> >
1.91 #endif
1.92 class Suurballe
1.93 {
1.94 @@ -74,26 +119,26 @@
1.95
1.96 public:
1.97
1.98 - /// The type of the digraph the algorithm runs on.
1.99 - typedef GR Digraph;
1.100 + /// The type of the digraph.
1.101 + typedef typename TR::Digraph Digraph;
1.102 /// The type of the length map.
1.103 - typedef LEN LengthMap;
1.104 + typedef typename TR::LengthMap LengthMap;
1.105 /// The type of the lengths.
1.106 - typedef typename LengthMap::Value Length;
1.107 -#ifdef DOXYGEN
1.108 + typedef typename TR::Length Length;
1.109 +
1.110 /// The type of the flow map.
1.111 - typedef GR::ArcMap<int> FlowMap;
1.112 + typedef typename TR::FlowMap FlowMap;
1.113 /// The type of the potential map.
1.114 - typedef GR::NodeMap<Length> PotentialMap;
1.115 -#else
1.116 - /// The type of the flow map.
1.117 - typedef typename Digraph::template ArcMap<int> FlowMap;
1.118 - /// The type of the potential map.
1.119 - typedef typename Digraph::template NodeMap<Length> PotentialMap;
1.120 -#endif
1.121 + typedef typename TR::PotentialMap PotentialMap;
1.122 + /// The type of the path structures.
1.123 + typedef typename TR::Path Path;
1.124 + /// The cross reference type used for the heap.
1.125 + typedef typename TR::HeapCrossRef HeapCrossRef;
1.126 + /// The heap type used for internal Dijkstra computations.
1.127 + typedef typename TR::Heap Heap;
1.128
1.129 - /// The type of the path structures.
1.130 - typedef SimplePath<GR> Path;
1.131 + /// The \ref SuurballeDefaultTraits "traits class" of the algorithm.
1.132 + typedef TR Traits;
1.133
1.134 private:
1.135
1.136 @@ -104,44 +149,38 @@
1.137 // distance of the nodes.
1.138 class ResidualDijkstra
1.139 {
1.140 - typedef typename Digraph::template NodeMap<int> HeapCrossRef;
1.141 - typedef BinHeap<Length, HeapCrossRef> Heap;
1.142 + private:
1.143 +
1.144 + const Digraph &_graph;
1.145 + const LengthMap &_length;
1.146 + const FlowMap &_flow;
1.147 + PotentialMap &_pi;
1.148 + PredMap &_pred;
1.149 + Node _s;
1.150 + Node _t;
1.151 +
1.152 + PotentialMap _dist;
1.153 + std::vector<Node> _proc_nodes;
1.154 +
1.155 + public:
1.156 +
1.157 + // Constructor
1.158 + ResidualDijkstra(Suurballe &srb) :
1.159 + _graph(srb._graph), _length(srb._length),
1.160 + _flow(*srb._flow), _pi(*srb._potential), _pred(srb._pred),
1.161 + _s(srb._s), _t(srb._t), _dist(_graph) {}
1.162 +
1.163 + // Run the algorithm and return true if a path is found
1.164 + // from the source node to the target node.
1.165 + bool run(int cnt) {
1.166 + return cnt == 0 ? startFirst() : start();
1.167 + }
1.168
1.169 private:
1.170
1.171 - // The digraph the algorithm runs on
1.172 - const Digraph &_graph;
1.173 -
1.174 - // The main maps
1.175 - const FlowMap &_flow;
1.176 - const LengthMap &_length;
1.177 - PotentialMap &_potential;
1.178 -
1.179 - // The distance map
1.180 - PotentialMap _dist;
1.181 - // The pred arc map
1.182 - PredMap &_pred;
1.183 - // The processed (i.e. permanently labeled) nodes
1.184 - std::vector<Node> _proc_nodes;
1.185 -
1.186 - Node _s;
1.187 - Node _t;
1.188 -
1.189 - public:
1.190 -
1.191 - /// Constructor.
1.192 - ResidualDijkstra( const Digraph &graph,
1.193 - const FlowMap &flow,
1.194 - const LengthMap &length,
1.195 - PotentialMap &potential,
1.196 - PredMap &pred,
1.197 - Node s, Node t ) :
1.198 - _graph(graph), _flow(flow), _length(length), _potential(potential),
1.199 - _dist(graph), _pred(pred), _s(s), _t(t) {}
1.200 -
1.201 - /// \brief Run the algorithm. It returns \c true if a path is found
1.202 - /// from the source node to the target node.
1.203 - bool run() {
1.204 + // Execute the algorithm for the first time (the flow and potential
1.205 + // functions have to be identically zero).
1.206 + bool startFirst() {
1.207 HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP);
1.208 Heap heap(heap_cross_ref);
1.209 heap.push(_s, 0);
1.210 @@ -151,29 +190,74 @@
1.211 // Process nodes
1.212 while (!heap.empty() && heap.top() != _t) {
1.213 Node u = heap.top(), v;
1.214 - Length d = heap.prio() + _potential[u], nd;
1.215 + Length d = heap.prio(), dn;
1.216 _dist[u] = heap.prio();
1.217 + _proc_nodes.push_back(u);
1.218 heap.pop();
1.219 +
1.220 + // Traverse outgoing arcs
1.221 + for (OutArcIt e(_graph, u); e != INVALID; ++e) {
1.222 + v = _graph.target(e);
1.223 + switch(heap.state(v)) {
1.224 + case Heap::PRE_HEAP:
1.225 + heap.push(v, d + _length[e]);
1.226 + _pred[v] = e;
1.227 + break;
1.228 + case Heap::IN_HEAP:
1.229 + dn = d + _length[e];
1.230 + if (dn < heap[v]) {
1.231 + heap.decrease(v, dn);
1.232 + _pred[v] = e;
1.233 + }
1.234 + break;
1.235 + case Heap::POST_HEAP:
1.236 + break;
1.237 + }
1.238 + }
1.239 + }
1.240 + if (heap.empty()) return false;
1.241 +
1.242 + // Update potentials of processed nodes
1.243 + Length t_dist = heap.prio();
1.244 + for (int i = 0; i < int(_proc_nodes.size()); ++i)
1.245 + _pi[_proc_nodes[i]] = _dist[_proc_nodes[i]] - t_dist;
1.246 + return true;
1.247 + }
1.248 +
1.249 + // Execute the algorithm.
1.250 + bool start() {
1.251 + HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP);
1.252 + Heap heap(heap_cross_ref);
1.253 + heap.push(_s, 0);
1.254 + _pred[_s] = INVALID;
1.255 + _proc_nodes.clear();
1.256 +
1.257 + // Process nodes
1.258 + while (!heap.empty() && heap.top() != _t) {
1.259 + Node u = heap.top(), v;
1.260 + Length d = heap.prio() + _pi[u], dn;
1.261 + _dist[u] = heap.prio();
1.262 _proc_nodes.push_back(u);
1.263 + heap.pop();
1.264
1.265 // Traverse outgoing arcs
1.266 for (OutArcIt e(_graph, u); e != INVALID; ++e) {
1.267 if (_flow[e] == 0) {
1.268 v = _graph.target(e);
1.269 switch(heap.state(v)) {
1.270 - case Heap::PRE_HEAP:
1.271 - heap.push(v, d + _length[e] - _potential[v]);
1.272 - _pred[v] = e;
1.273 - break;
1.274 - case Heap::IN_HEAP:
1.275 - nd = d + _length[e] - _potential[v];
1.276 - if (nd < heap[v]) {
1.277 - heap.decrease(v, nd);
1.278 + case Heap::PRE_HEAP:
1.279 + heap.push(v, d + _length[e] - _pi[v]);
1.280 _pred[v] = e;
1.281 - }
1.282 - break;
1.283 - case Heap::POST_HEAP:
1.284 - break;
1.285 + break;
1.286 + case Heap::IN_HEAP:
1.287 + dn = d + _length[e] - _pi[v];
1.288 + if (dn < heap[v]) {
1.289 + heap.decrease(v, dn);
1.290 + _pred[v] = e;
1.291 + }
1.292 + break;
1.293 + case Heap::POST_HEAP:
1.294 + break;
1.295 }
1.296 }
1.297 }
1.298 @@ -183,19 +267,19 @@
1.299 if (_flow[e] == 1) {
1.300 v = _graph.source(e);
1.301 switch(heap.state(v)) {
1.302 - case Heap::PRE_HEAP:
1.303 - heap.push(v, d - _length[e] - _potential[v]);
1.304 - _pred[v] = e;
1.305 - break;
1.306 - case Heap::IN_HEAP:
1.307 - nd = d - _length[e] - _potential[v];
1.308 - if (nd < heap[v]) {
1.309 - heap.decrease(v, nd);
1.310 + case Heap::PRE_HEAP:
1.311 + heap.push(v, d - _length[e] - _pi[v]);
1.312 _pred[v] = e;
1.313 - }
1.314 - break;
1.315 - case Heap::POST_HEAP:
1.316 - break;
1.317 + break;
1.318 + case Heap::IN_HEAP:
1.319 + dn = d - _length[e] - _pi[v];
1.320 + if (dn < heap[v]) {
1.321 + heap.decrease(v, dn);
1.322 + _pred[v] = e;
1.323 + }
1.324 + break;
1.325 + case Heap::POST_HEAP:
1.326 + break;
1.327 }
1.328 }
1.329 }
1.330 @@ -205,12 +289,89 @@
1.331 // Update potentials of processed nodes
1.332 Length t_dist = heap.prio();
1.333 for (int i = 0; i < int(_proc_nodes.size()); ++i)
1.334 - _potential[_proc_nodes[i]] += _dist[_proc_nodes[i]] - t_dist;
1.335 + _pi[_proc_nodes[i]] += _dist[_proc_nodes[i]] - t_dist;
1.336 return true;
1.337 }
1.338
1.339 }; //class ResidualDijkstra
1.340
1.341 + public:
1.342 +
1.343 + /// \name Named Template Parameters
1.344 + /// @{
1.345 +
1.346 + template <typename T>
1.347 + struct SetFlowMapTraits : public Traits {
1.348 + typedef T FlowMap;
1.349 + };
1.350 +
1.351 + /// \brief \ref named-templ-param "Named parameter" for setting
1.352 + /// \c FlowMap type.
1.353 + ///
1.354 + /// \ref named-templ-param "Named parameter" for setting
1.355 + /// \c FlowMap type.
1.356 + template <typename T>
1.357 + struct SetFlowMap
1.358 + : public Suurballe<GR, LEN, SetFlowMapTraits<T> > {
1.359 + typedef Suurballe<GR, LEN, SetFlowMapTraits<T> > Create;
1.360 + };
1.361 +
1.362 + template <typename T>
1.363 + struct SetPotentialMapTraits : public Traits {
1.364 + typedef T PotentialMap;
1.365 + };
1.366 +
1.367 + /// \brief \ref named-templ-param "Named parameter" for setting
1.368 + /// \c PotentialMap type.
1.369 + ///
1.370 + /// \ref named-templ-param "Named parameter" for setting
1.371 + /// \c PotentialMap type.
1.372 + template <typename T>
1.373 + struct SetPotentialMap
1.374 + : public Suurballe<GR, LEN, SetPotentialMapTraits<T> > {
1.375 + typedef Suurballe<GR, LEN, SetPotentialMapTraits<T> > Create;
1.376 + };
1.377 +
1.378 + template <typename T>
1.379 + struct SetPathTraits : public Traits {
1.380 + typedef T Path;
1.381 + };
1.382 +
1.383 + /// \brief \ref named-templ-param "Named parameter" for setting
1.384 + /// \c %Path type.
1.385 + ///
1.386 + /// \ref named-templ-param "Named parameter" for setting \c %Path type.
1.387 + /// It must conform to the \ref lemon::concepts::Path "Path" concept
1.388 + /// and it must have an \c addBack() function.
1.389 + template <typename T>
1.390 + struct SetPath
1.391 + : public Suurballe<GR, LEN, SetPathTraits<T> > {
1.392 + typedef Suurballe<GR, LEN, SetPathTraits<T> > Create;
1.393 + };
1.394 +
1.395 + template <typename H, typename CR>
1.396 + struct SetHeapTraits : public Traits {
1.397 + typedef H Heap;
1.398 + typedef CR HeapCrossRef;
1.399 + };
1.400 +
1.401 + /// \brief \ref named-templ-param "Named parameter" for setting
1.402 + /// \c Heap and \c HeapCrossRef types.
1.403 + ///
1.404 + /// \ref named-templ-param "Named parameter" for setting \c Heap
1.405 + /// and \c HeapCrossRef types with automatic allocation.
1.406 + /// They will be used for internal Dijkstra computations.
1.407 + /// The heap type must conform to the \ref lemon::concepts::Heap "Heap"
1.408 + /// concept and its priority type must be \c Length.
1.409 + template <typename H,
1.410 + typename CR = typename Digraph::template NodeMap<int> >
1.411 + struct SetHeap
1.412 + : public Suurballe<GR, LEN, SetHeapTraits<H, CR> > {
1.413 + typedef Suurballe<GR, LEN, SetHeapTraits<H, CR> > Create;
1.414 + };
1.415 +
1.416 + /// @}
1.417 +
1.418 private:
1.419
1.420 // The digraph the algorithm runs on
1.421 @@ -226,19 +387,25 @@
1.422 bool _local_potential;
1.423
1.424 // The source node
1.425 - Node _source;
1.426 + Node _s;
1.427 // The target node
1.428 - Node _target;
1.429 + Node _t;
1.430
1.431 // Container to store the found paths
1.432 - std::vector< SimplePath<Digraph> > paths;
1.433 + std::vector<Path> _paths;
1.434 int _path_num;
1.435
1.436 // The pred arc map
1.437 PredMap _pred;
1.438 - // Implementation of the Dijkstra algorithm for finding augmenting
1.439 - // shortest paths in the residual network
1.440 - ResidualDijkstra *_dijkstra;
1.441 +
1.442 + // Data for full init
1.443 + PotentialMap *_init_dist;
1.444 + PredMap *_init_pred;
1.445 + bool _full_init;
1.446 +
1.447 + protected:
1.448 +
1.449 + Suurballe() {}
1.450
1.451 public:
1.452
1.453 @@ -251,14 +418,16 @@
1.454 Suurballe( const Digraph &graph,
1.455 const LengthMap &length ) :
1.456 _graph(graph), _length(length), _flow(0), _local_flow(false),
1.457 - _potential(0), _local_potential(false), _pred(graph)
1.458 + _potential(0), _local_potential(false), _pred(graph),
1.459 + _init_dist(0), _init_pred(0)
1.460 {}
1.461
1.462 /// Destructor.
1.463 ~Suurballe() {
1.464 if (_local_flow) delete _flow;
1.465 if (_local_potential) delete _potential;
1.466 - delete _dijkstra;
1.467 + delete _init_dist;
1.468 + delete _init_pred;
1.469 }
1.470
1.471 /// \brief Set the flow map.
1.472 @@ -303,10 +472,13 @@
1.473
1.474 /// \name Execution Control
1.475 /// The simplest way to execute the algorithm is to call the run()
1.476 - /// function.
1.477 - /// \n
1.478 + /// function.\n
1.479 + /// If you need to execute the algorithm many times using the same
1.480 + /// source node, then you may call fullInit() once and start()
1.481 + /// for each target node.\n
1.482 /// If you only need the flow that is the union of the found
1.483 - /// arc-disjoint paths, you may call init() and findFlow().
1.484 + /// arc-disjoint paths, then you may call findFlow() instead of
1.485 + /// start().
1.486
1.487 /// @{
1.488
1.489 @@ -326,23 +498,21 @@
1.490 /// just a shortcut of the following code.
1.491 /// \code
1.492 /// s.init(s);
1.493 - /// s.findFlow(t, k);
1.494 - /// s.findPaths();
1.495 + /// s.start(t, k);
1.496 /// \endcode
1.497 int run(const Node& s, const Node& t, int k = 2) {
1.498 init(s);
1.499 - findFlow(t, k);
1.500 - findPaths();
1.501 + start(t, k);
1.502 return _path_num;
1.503 }
1.504
1.505 /// \brief Initialize the algorithm.
1.506 ///
1.507 - /// This function initializes the algorithm.
1.508 + /// This function initializes the algorithm with the given source node.
1.509 ///
1.510 /// \param s The source node.
1.511 void init(const Node& s) {
1.512 - _source = s;
1.513 + _s = s;
1.514
1.515 // Initialize maps
1.516 if (!_flow) {
1.517 @@ -353,8 +523,63 @@
1.518 _potential = new PotentialMap(_graph);
1.519 _local_potential = true;
1.520 }
1.521 - for (ArcIt e(_graph); e != INVALID; ++e) (*_flow)[e] = 0;
1.522 - for (NodeIt n(_graph); n != INVALID; ++n) (*_potential)[n] = 0;
1.523 + _full_init = false;
1.524 + }
1.525 +
1.526 + /// \brief Initialize the algorithm and perform Dijkstra.
1.527 + ///
1.528 + /// This function initializes the algorithm and performs a full
1.529 + /// Dijkstra search from the given source node. It makes consecutive
1.530 + /// executions of \ref start() "start(t, k)" faster, since they
1.531 + /// have to perform %Dijkstra only k-1 times.
1.532 + ///
1.533 + /// This initialization is usually worth using instead of \ref init()
1.534 + /// if the algorithm is executed many times using the same source node.
1.535 + ///
1.536 + /// \param s The source node.
1.537 + void fullInit(const Node& s) {
1.538 + // Initialize maps
1.539 + init(s);
1.540 + if (!_init_dist) {
1.541 + _init_dist = new PotentialMap(_graph);
1.542 + }
1.543 + if (!_init_pred) {
1.544 + _init_pred = new PredMap(_graph);
1.545 + }
1.546 +
1.547 + // Run a full Dijkstra
1.548 + typename Dijkstra<Digraph, LengthMap>
1.549 + ::template SetStandardHeap<Heap>
1.550 + ::template SetDistMap<PotentialMap>
1.551 + ::template SetPredMap<PredMap>
1.552 + ::Create dijk(_graph, _length);
1.553 + dijk.distMap(*_init_dist).predMap(*_init_pred);
1.554 + dijk.run(s);
1.555 +
1.556 + _full_init = true;
1.557 + }
1.558 +
1.559 + /// \brief Execute the algorithm.
1.560 + ///
1.561 + /// This function executes the algorithm.
1.562 + ///
1.563 + /// \param t The target node.
1.564 + /// \param k The number of paths to be found.
1.565 + ///
1.566 + /// \return \c k if there are at least \c k arc-disjoint paths from
1.567 + /// \c s to \c t in the digraph. Otherwise it returns the number of
1.568 + /// arc-disjoint paths found.
1.569 + ///
1.570 + /// \note Apart from the return value, <tt>s.start(t, k)</tt> is
1.571 + /// just a shortcut of the following code.
1.572 + /// \code
1.573 + /// s.findFlow(t, k);
1.574 + /// s.findPaths();
1.575 + /// \endcode
1.576 + int start(const Node& t, int k = 2) {
1.577 + findFlow(t, k);
1.578 + findPaths();
1.579 + return _path_num;
1.580 }
1.581
1.582 /// \brief Execute the algorithm to find an optimal flow.
1.583 @@ -372,20 +597,39 @@
1.584 ///
1.585 /// \pre \ref init() must be called before using this function.
1.586 int findFlow(const Node& t, int k = 2) {
1.587 - _target = t;
1.588 - _dijkstra =
1.589 - new ResidualDijkstra( _graph, *_flow, _length, *_potential, _pred,
1.590 - _source, _target );
1.591 + _t = t;
1.592 + ResidualDijkstra dijkstra(*this);
1.593 +
1.594 + // Initialization
1.595 + for (ArcIt e(_graph); e != INVALID; ++e) {
1.596 + (*_flow)[e] = 0;
1.597 + }
1.598 + if (_full_init) {
1.599 + for (NodeIt n(_graph); n != INVALID; ++n) {
1.600 + (*_potential)[n] = (*_init_dist)[n];
1.601 + }
1.602 + Node u = _t;
1.603 + Arc e;
1.604 + while ((e = (*_init_pred)[u]) != INVALID) {
1.605 + (*_flow)[e] = 1;
1.606 + u = _graph.source(e);
1.607 + }
1.608 + _path_num = 1;
1.609 + } else {
1.610 + for (NodeIt n(_graph); n != INVALID; ++n) {
1.611 + (*_potential)[n] = 0;
1.612 + }
1.613 + _path_num = 0;
1.614 + }
1.615
1.616 // Find shortest paths
1.617 - _path_num = 0;
1.618 while (_path_num < k) {
1.619 // Run Dijkstra
1.620 - if (!_dijkstra->run()) break;
1.621 + if (!dijkstra.run(_path_num)) break;
1.622 ++_path_num;
1.623
1.624 // Set the flow along the found shortest path
1.625 - Node u = _target;
1.626 + Node u = _t;
1.627 Arc e;
1.628 while ((e = _pred[u]) != INVALID) {
1.629 if (u == _graph.target(e)) {
1.630 @@ -402,8 +646,8 @@
1.631
1.632 /// \brief Compute the paths from the flow.
1.633 ///
1.634 - /// This function computes the paths from the found minimum cost flow,
1.635 - /// which is the union of some arc-disjoint paths.
1.636 + /// This function computes arc-disjoint paths from the found minimum
1.637 + /// cost flow, which is the union of them.
1.638 ///
1.639 /// \pre \ref init() and \ref findFlow() must be called before using
1.640 /// this function.
1.641 @@ -411,15 +655,15 @@
1.642 FlowMap res_flow(_graph);
1.643 for(ArcIt a(_graph); a != INVALID; ++a) res_flow[a] = (*_flow)[a];
1.644
1.645 - paths.clear();
1.646 - paths.resize(_path_num);
1.647 + _paths.clear();
1.648 + _paths.resize(_path_num);
1.649 for (int i = 0; i < _path_num; ++i) {
1.650 - Node n = _source;
1.651 - while (n != _target) {
1.652 + Node n = _s;
1.653 + while (n != _t) {
1.654 OutArcIt e(_graph, n);
1.655 for ( ; res_flow[e] == 0; ++e) ;
1.656 n = _graph.target(e);
1.657 - paths[i].addBack(e);
1.658 + _paths[i].addBack(e);
1.659 res_flow[e] = 0;
1.660 }
1.661 }
1.662 @@ -518,7 +762,7 @@
1.663 /// \pre \ref run() or \ref findPaths() must be called before using
1.664 /// this function.
1.665 const Path& path(int i) const {
1.666 - return paths[i];
1.667 + return _paths[i];
1.668 }
1.669
1.670 /// @}