... | ... |
@@ -34,49 +34,49 @@ |
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
/// \addtogroup shortest_path |
37 | 37 |
/// @{ |
38 | 38 |
|
39 | 39 |
/// \brief Algorithm for finding arc-disjoint paths between two nodes |
40 | 40 |
/// having minimum total length. |
41 | 41 |
/// |
42 | 42 |
/// \ref lemon::Suurballe "Suurballe" implements an algorithm for |
43 | 43 |
/// finding arc-disjoint paths having minimum total length (cost) |
44 | 44 |
/// from a given source node to a given target node in a digraph. |
45 | 45 |
/// |
46 | 46 |
/// Note that this problem is a special case of the \ref min_cost_flow |
47 | 47 |
/// "minimum cost flow problem". This implementation is actually an |
48 | 48 |
/// efficient specialized version of the Successive Shortest Path |
49 | 49 |
/// algorithm directly for this problem. |
50 | 50 |
/// Therefore this class provides query functions for flow values and |
51 | 51 |
/// node potentials (the dual solution) just like the minimum cost flow |
52 | 52 |
/// algorithms. |
53 | 53 |
/// |
54 | 54 |
/// \tparam GR The digraph type the algorithm runs on. |
55 | 55 |
/// \tparam LEN The type of the length map. |
56 | 56 |
/// The default value is <tt>GR::ArcMap<int></tt>. |
57 | 57 |
/// |
58 |
/// \warning Length values should be \e non-negative |
|
58 |
/// \warning Length values should be \e non-negative. |
|
59 | 59 |
/// |
60 | 60 |
/// \note For finding node-disjoint paths this algorithm can be used |
61 | 61 |
/// along with the \ref SplitNodes adaptor. |
62 | 62 |
#ifdef DOXYGEN |
63 | 63 |
template <typename GR, typename LEN> |
64 | 64 |
#else |
65 | 65 |
template < typename GR, |
66 | 66 |
typename LEN = typename GR::template ArcMap<int> > |
67 | 67 |
#endif |
68 | 68 |
class Suurballe |
69 | 69 |
{ |
70 | 70 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
71 | 71 |
|
72 | 72 |
typedef ConstMap<Arc, int> ConstArcMap; |
73 | 73 |
typedef typename GR::template NodeMap<Arc> PredMap; |
74 | 74 |
|
75 | 75 |
public: |
76 | 76 |
|
77 | 77 |
/// The type of the digraph the algorithm runs on. |
78 | 78 |
typedef GR Digraph; |
79 | 79 |
/// The type of the length map. |
80 | 80 |
typedef LEN LengthMap; |
81 | 81 |
/// The type of the lengths. |
82 | 82 |
typedef typename LengthMap::Value Length; |
... | ... |
@@ -231,52 +231,49 @@ |
231 | 231 |
Node _target; |
232 | 232 |
|
233 | 233 |
// Container to store the found paths |
234 | 234 |
std::vector< SimplePath<Digraph> > paths; |
235 | 235 |
int _path_num; |
236 | 236 |
|
237 | 237 |
// The pred arc map |
238 | 238 |
PredMap _pred; |
239 | 239 |
// Implementation of the Dijkstra algorithm for finding augmenting |
240 | 240 |
// shortest paths in the residual network |
241 | 241 |
ResidualDijkstra *_dijkstra; |
242 | 242 |
|
243 | 243 |
public: |
244 | 244 |
|
245 | 245 |
/// \brief Constructor. |
246 | 246 |
/// |
247 | 247 |
/// Constructor. |
248 | 248 |
/// |
249 | 249 |
/// \param graph The digraph the algorithm runs on. |
250 | 250 |
/// \param length The length (cost) values of the arcs. |
251 | 251 |
Suurballe( const Digraph &graph, |
252 | 252 |
const LengthMap &length ) : |
253 | 253 |
_graph(graph), _length(length), _flow(0), _local_flow(false), |
254 | 254 |
_potential(0), _local_potential(false), _pred(graph) |
255 |
{ |
|
256 |
LEMON_ASSERT(std::numeric_limits<Length>::is_integer, |
|
257 |
"The length type of Suurballe must be integer"); |
|
258 |
} |
|
255 |
{} |
|
259 | 256 |
|
260 | 257 |
/// Destructor. |
261 | 258 |
~Suurballe() { |
262 | 259 |
if (_local_flow) delete _flow; |
263 | 260 |
if (_local_potential) delete _potential; |
264 | 261 |
delete _dijkstra; |
265 | 262 |
} |
266 | 263 |
|
267 | 264 |
/// \brief Set the flow map. |
268 | 265 |
/// |
269 | 266 |
/// This function sets the flow map. |
270 | 267 |
/// If it is not used before calling \ref run() or \ref init(), |
271 | 268 |
/// an instance will be allocated automatically. The destructor |
272 | 269 |
/// deallocates this automatically allocated map, of course. |
273 | 270 |
/// |
274 | 271 |
/// The found flow contains only 0 and 1 values, since it is the |
275 | 272 |
/// union of the found arc-disjoint paths. |
276 | 273 |
/// |
277 | 274 |
/// \return <tt>(*this)</tt> |
278 | 275 |
Suurballe& flowMap(FlowMap &map) { |
279 | 276 |
if (_local_flow) { |
280 | 277 |
delete _flow; |
281 | 278 |
_local_flow = false; |
282 | 279 |
} |
... | ... |
@@ -499,37 +496,37 @@ |
499 | 496 |
/// this function. |
500 | 497 |
const PotentialMap& potentialMap() const { |
501 | 498 |
return *_potential; |
502 | 499 |
} |
503 | 500 |
|
504 | 501 |
/// \brief Return the number of the found paths. |
505 | 502 |
/// |
506 | 503 |
/// This function returns the number of the found paths. |
507 | 504 |
/// |
508 | 505 |
/// \pre \ref run() or \ref findFlow() must be called before using |
509 | 506 |
/// this function. |
510 | 507 |
int pathNum() const { |
511 | 508 |
return _path_num; |
512 | 509 |
} |
513 | 510 |
|
514 | 511 |
/// \brief Return a const reference to the specified path. |
515 | 512 |
/// |
516 | 513 |
/// This function returns a const reference to the specified path. |
517 | 514 |
/// |
518 | 515 |
/// \param i The function returns the <tt>i</tt>-th path. |
519 | 516 |
/// \c i must be between \c 0 and <tt>%pathNum()-1</tt>. |
520 | 517 |
/// |
521 | 518 |
/// \pre \ref run() or \ref findPaths() must be called before using |
522 | 519 |
/// this function. |
523 |
Path path(int i) const { |
|
520 |
const Path& path(int i) const { |
|
524 | 521 |
return paths[i]; |
525 | 522 |
} |
526 | 523 |
|
527 | 524 |
/// @} |
528 | 525 |
|
529 | 526 |
}; //class Suurballe |
530 | 527 |
|
531 | 528 |
///@} |
532 | 529 |
|
533 | 530 |
} //namespace lemon |
534 | 531 |
|
535 | 532 |
#endif //LEMON_SUURBALLE_H |
0 comments (0 inline)