62 /// but rather slower in practice. |
62 /// but rather slower in practice. |
63 /// To use this version of the algorithm, call \ref run() with \c true |
63 /// To use this version of the algorithm, call \ref run() with \c true |
64 /// parameter. |
64 /// parameter. |
65 /// |
65 /// |
66 /// \author Peter Kovacs |
66 /// \author Peter Kovacs |
67 |
|
68 template < typename Graph, |
67 template < typename Graph, |
69 typename LowerMap = typename Graph::template EdgeMap<int>, |
68 typename LowerMap = typename Graph::template EdgeMap<int>, |
70 typename CapacityMap = typename Graph::template EdgeMap<int>, |
69 typename CapacityMap = typename Graph::template EdgeMap<int>, |
71 typename CostMap = typename Graph::template EdgeMap<int>, |
70 typename CostMap = typename Graph::template EdgeMap<int>, |
72 typename SupplyMap = typename Graph::template NodeMap<int> > |
71 typename SupplyMap = typename Graph::template NodeMap<int> > |
305 _potential = ↦ |
303 _potential = ↦ |
306 return *this; |
304 return *this; |
307 } |
305 } |
308 |
306 |
309 /// \name Execution control |
307 /// \name Execution control |
310 /// The only way to execute the algorithm is to call the run() |
|
311 /// function. |
|
312 |
308 |
313 /// @{ |
309 /// @{ |
314 |
310 |
315 /// \brief Runs the algorithm. |
311 /// \brief Run the algorithm. |
316 /// |
312 /// |
317 /// Runs the algorithm. |
313 /// Run the algorithm. |
318 /// |
314 /// |
319 /// \param min_mean_cc Set this parameter to \c true to run the |
315 /// \param min_mean_cc Set this parameter to \c true to run the |
320 /// "Minimum Mean Cycle-Canceling" algorithm, which is strongly |
316 /// "Minimum Mean Cycle-Canceling" algorithm, which is strongly |
321 /// polynomial, but rather slower in practice. |
317 /// polynomial, but rather slower in practice. |
322 /// |
318 /// |
327 |
323 |
328 /// @} |
324 /// @} |
329 |
325 |
330 /// \name Query Functions |
326 /// \name Query Functions |
331 /// The result of the algorithm can be obtained using these |
327 /// The result of the algorithm can be obtained using these |
332 /// functions. |
328 /// functions.\n |
333 /// \n run() must be called before using them. |
329 /// \ref lemon::CycleCanceling::run() "run()" must be called before |
|
330 /// using them. |
334 |
331 |
335 /// @{ |
332 /// @{ |
336 |
333 |
337 /// \brief Returns a const reference to the edge map storing the |
334 /// \brief Return a const reference to the edge map storing the |
338 /// found flow. |
335 /// found flow. |
339 /// |
336 /// |
340 /// Returns a const reference to the edge map storing the found flow. |
337 /// Return a const reference to the edge map storing the found flow. |
341 /// |
338 /// |
342 /// \pre \ref run() must be called before using this function. |
339 /// \pre \ref run() must be called before using this function. |
343 const FlowMap& flowMap() const { |
340 const FlowMap& flowMap() const { |
344 return *_flow; |
341 return *_flow; |
345 } |
342 } |
346 |
343 |
347 /// \brief Returns a const reference to the node map storing the |
344 /// \brief Return a const reference to the node map storing the |
348 /// found potentials (the dual solution). |
345 /// found potentials (the dual solution). |
349 /// |
346 /// |
350 /// Returns a const reference to the node map storing the found |
347 /// Return a const reference to the node map storing the found |
351 /// potentials (the dual solution). |
348 /// potentials (the dual solution). |
352 /// |
349 /// |
353 /// \pre \ref run() must be called before using this function. |
350 /// \pre \ref run() must be called before using this function. |
354 const PotentialMap& potentialMap() const { |
351 const PotentialMap& potentialMap() const { |
355 return *_potential; |
352 return *_potential; |
356 } |
353 } |
357 |
354 |
358 /// \brief Returns the flow on the given edge. |
355 /// \brief Return the flow on the given edge. |
359 /// |
356 /// |
360 /// Returns the flow on the given edge. |
357 /// Return the flow on the given edge. |
361 /// |
358 /// |
362 /// \pre \ref run() must be called before using this function. |
359 /// \pre \ref run() must be called before using this function. |
363 Capacity flow(const Edge& edge) const { |
360 Capacity flow(const Edge& edge) const { |
364 return (*_flow)[edge]; |
361 return (*_flow)[edge]; |
365 } |
362 } |
366 |
363 |
367 /// \brief Returns the potential of the given node. |
364 /// \brief Return the potential of the given node. |
368 /// |
365 /// |
369 /// Returns the potential of the given node. |
366 /// Return the potential of the given node. |
370 /// |
367 /// |
371 /// \pre \ref run() must be called before using this function. |
368 /// \pre \ref run() must be called before using this function. |
372 Cost potential(const Node& node) const { |
369 Cost potential(const Node& node) const { |
373 return (*_potential)[node]; |
370 return (*_potential)[node]; |
374 } |
371 } |
375 |
372 |
376 /// \brief Returns the total cost of the found flow. |
373 /// \brief Return the total cost of the found flow. |
377 /// |
374 /// |
378 /// Returns the total cost of the found flow. The complexity of the |
375 /// Return the total cost of the found flow. The complexity of the |
379 /// function is \f$ O(e) \f$. |
376 /// function is \f$ O(e) \f$. |
380 /// |
377 /// |
381 /// \pre \ref run() must be called before using this function. |
378 /// \pre \ref run() must be called before using this function. |
382 Cost totalCost() const { |
379 Cost totalCost() const { |
383 Cost c = 0; |
380 Cost c = 0; |
426 (*_flow)[e] += (*_lower)[e]; |
423 (*_flow)[e] += (*_lower)[e]; |
427 } |
424 } |
428 return true; |
425 return true; |
429 } |
426 } |
430 |
427 |
431 /// \brief Executes the algorithm using \ref BellmanFord. |
428 /// \brief Execute the algorithm using \ref BellmanFord. |
432 /// |
429 /// |
433 /// Executes the algorithm using the \ref BellmanFord |
430 /// Execute the algorithm using the \ref BellmanFord |
434 /// "Bellman-Ford" algorithm for negative cycle detection with |
431 /// "Bellman-Ford" algorithm for negative cycle detection with |
435 /// successively larger limit for the number of iterations. |
432 /// successively larger limit for the number of iterations. |
436 void start() { |
433 void start() { |
437 typename BellmanFord<ResGraph, ResidualCostMap>::PredMap pred(*_res_graph); |
434 typename BellmanFord<ResGraph, ResidualCostMap>::PredMap pred(*_res_graph); |
438 typename ResGraph::template NodeMap<int> visited(*_res_graph); |
435 typename ResGraph::template NodeMap<int> visited(*_res_graph); |
504 length_bound = length_bound * BF_LIMIT_FACTOR / 100; |
501 length_bound = length_bound * BF_LIMIT_FACTOR / 100; |
505 } |
502 } |
506 } |
503 } |
507 } |
504 } |
508 |
505 |
509 /// \brief Executes the algorithm using \ref MinMeanCycle. |
506 /// \brief Execute the algorithm using \ref MinMeanCycle. |
510 /// |
507 /// |
511 /// Executes the algorithm using \ref MinMeanCycle for negative |
508 /// Execute the algorithm using \ref MinMeanCycle for negative |
512 /// cycle detection. |
509 /// cycle detection. |
513 void startMinMean() { |
510 void startMinMean() { |
514 typedef Path<ResGraph> ResPath; |
511 typedef Path<ResGraph> ResPath; |
515 MinMeanCycle<ResGraph, ResidualCostMap> mmc(*_res_graph, _res_cost); |
512 MinMeanCycle<ResGraph, ResidualCostMap> mmc(*_res_graph, _res_cost); |
516 ResPath cycle; |
513 ResPath cycle; |