1 /* -*- mode: C++; indent-tabs-mode: nil; -*- |
1 /* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 * |
2 * |
3 * This file is a part of LEMON, a generic C++ optimization library. |
3 * This file is a part of LEMON, a generic C++ optimization library. |
4 * |
4 * |
5 * Copyright (C) 2003-2009 |
5 * Copyright (C) 2003-2010 |
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
7 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 * |
8 * |
9 * Permission to use, modify and distribute this software is granted |
9 * Permission to use, modify and distribute this software is granted |
10 * provided that this copyright notice appears in all copies. For |
10 * provided that this copyright notice appears in all copies. For |
63 /// |
63 /// |
64 /// The type used for storing the found arc-disjoint paths. |
64 /// The type used for storing the found arc-disjoint paths. |
65 /// It must conform to the \ref lemon::concepts::Path "Path" concept |
65 /// It must conform to the \ref lemon::concepts::Path "Path" concept |
66 /// and it must have an \c addBack() function. |
66 /// and it must have an \c addBack() function. |
67 typedef lemon::Path<Digraph> Path; |
67 typedef lemon::Path<Digraph> Path; |
68 |
68 |
69 /// The cross reference type used for the heap. |
69 /// The cross reference type used for the heap. |
70 typedef typename GR::template NodeMap<int> HeapCrossRef; |
70 typedef typename GR::template NodeMap<int> HeapCrossRef; |
71 |
71 |
72 /// \brief The heap type used for internal Dijkstra computations. |
72 /// \brief The heap type used for internal Dijkstra computations. |
73 /// |
73 /// |
156 const FlowMap &_flow; |
156 const FlowMap &_flow; |
157 PotentialMap &_pi; |
157 PotentialMap &_pi; |
158 PredMap &_pred; |
158 PredMap &_pred; |
159 Node _s; |
159 Node _s; |
160 Node _t; |
160 Node _t; |
161 |
161 |
162 PotentialMap _dist; |
162 PotentialMap _dist; |
163 std::vector<Node> _proc_nodes; |
163 std::vector<Node> _proc_nodes; |
164 |
164 |
165 public: |
165 public: |
166 |
166 |
167 // Constructor |
167 // Constructor |
168 ResidualDijkstra(Suurballe &srb) : |
168 ResidualDijkstra(Suurballe &srb) : |
169 _graph(srb._graph), _length(srb._length), |
169 _graph(srb._graph), _length(srb._length), |
170 _flow(*srb._flow), _pi(*srb._potential), _pred(srb._pred), |
170 _flow(*srb._flow), _pi(*srb._potential), _pred(srb._pred), |
171 _s(srb._s), _t(srb._t), _dist(_graph) {} |
171 _s(srb._s), _t(srb._t), _dist(_graph) {} |
172 |
172 |
173 // Run the algorithm and return true if a path is found |
173 // Run the algorithm and return true if a path is found |
174 // from the source node to the target node. |
174 // from the source node to the target node. |
175 bool run(int cnt) { |
175 bool run(int cnt) { |
176 return cnt == 0 ? startFirst() : start(); |
176 return cnt == 0 ? startFirst() : start(); |
177 } |
177 } |
178 |
178 |
179 private: |
179 private: |
180 |
180 |
181 // Execute the algorithm for the first time (the flow and potential |
181 // Execute the algorithm for the first time (the flow and potential |
182 // functions have to be identically zero). |
182 // functions have to be identically zero). |
183 bool startFirst() { |
183 bool startFirst() { |
184 HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP); |
184 HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP); |
185 Heap heap(heap_cross_ref); |
185 Heap heap(heap_cross_ref); |
346 template <typename T> |
346 template <typename T> |
347 struct SetPath |
347 struct SetPath |
348 : public Suurballe<GR, LEN, SetPathTraits<T> > { |
348 : public Suurballe<GR, LEN, SetPathTraits<T> > { |
349 typedef Suurballe<GR, LEN, SetPathTraits<T> > Create; |
349 typedef Suurballe<GR, LEN, SetPathTraits<T> > Create; |
350 }; |
350 }; |
351 |
351 |
352 template <typename H, typename CR> |
352 template <typename H, typename CR> |
353 struct SetHeapTraits : public Traits { |
353 struct SetHeapTraits : public Traits { |
354 typedef H Heap; |
354 typedef H Heap; |
355 typedef CR HeapCrossRef; |
355 typedef CR HeapCrossRef; |
356 }; |
356 }; |
357 |
357 |
358 /// \brief \ref named-templ-param "Named parameter" for setting |
358 /// \brief \ref named-templ-param "Named parameter" for setting |
359 /// \c Heap and \c HeapCrossRef types. |
359 /// \c Heap and \c HeapCrossRef types. |
360 /// |
360 /// |
361 /// \ref named-templ-param "Named parameter" for setting \c Heap |
361 /// \ref named-templ-param "Named parameter" for setting \c Heap |
362 /// and \c HeapCrossRef types with automatic allocation. |
362 /// and \c HeapCrossRef types with automatic allocation. |
363 /// They will be used for internal Dijkstra computations. |
363 /// They will be used for internal Dijkstra computations. |
364 /// The heap type must conform to the \ref lemon::concepts::Heap "Heap" |
364 /// The heap type must conform to the \ref lemon::concepts::Heap "Heap" |
365 /// concept and its priority type must be \c Length. |
365 /// concept and its priority type must be \c Length. |
366 template <typename H, |
366 template <typename H, |
367 typename CR = typename Digraph::template NodeMap<int> > |
367 typename CR = typename Digraph::template NodeMap<int> > |
553 ::template SetDistMap<PotentialMap> |
553 ::template SetDistMap<PotentialMap> |
554 ::template SetPredMap<PredMap> |
554 ::template SetPredMap<PredMap> |
555 ::Create dijk(_graph, _length); |
555 ::Create dijk(_graph, _length); |
556 dijk.distMap(*_init_dist).predMap(*_init_pred); |
556 dijk.distMap(*_init_dist).predMap(*_init_pred); |
557 dijk.run(s); |
557 dijk.run(s); |
558 |
558 |
559 _full_init = true; |
559 _full_init = true; |
560 } |
560 } |
561 |
561 |
562 /// \brief Execute the algorithm. |
562 /// \brief Execute the algorithm. |
563 /// |
563 /// |