0
4
0
| ... | ... |
@@ -346,96 +346,130 @@ |
| 346 | 346 |
|
| 347 | 347 |
LEMON contains several algorithms for this problem. |
| 348 | 348 |
- \ref NetworkSimplex Primal Network Simplex algorithm with various |
| 349 | 349 |
pivot strategies. |
| 350 | 350 |
- \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on |
| 351 | 351 |
cost scaling. |
| 352 | 352 |
- \ref CapacityScaling Successive Shortest %Path algorithm with optional |
| 353 | 353 |
capacity scaling. |
| 354 | 354 |
- \ref CancelAndTighten The Cancel and Tighten algorithm. |
| 355 | 355 |
- \ref CycleCanceling Cycle-Canceling algorithms. |
| 356 | 356 |
|
| 357 | 357 |
In general NetworkSimplex is the most efficient implementation, |
| 358 | 358 |
but in special cases other algorithms could be faster. |
| 359 | 359 |
For example, if the total supply and/or capacities are rather small, |
| 360 | 360 |
CapacityScaling is usually the fastest algorithm (without effective scaling). |
| 361 | 361 |
*/ |
| 362 | 362 |
|
| 363 | 363 |
/** |
| 364 | 364 |
@defgroup min_cut Minimum Cut Algorithms |
| 365 | 365 |
@ingroup algs |
| 366 | 366 |
|
| 367 | 367 |
\brief Algorithms for finding minimum cut in graphs. |
| 368 | 368 |
|
| 369 | 369 |
This group contains the algorithms for finding minimum cut in graphs. |
| 370 | 370 |
|
| 371 | 371 |
The \e minimum \e cut \e problem is to find a non-empty and non-complete |
| 372 | 372 |
\f$X\f$ subset of the nodes with minimum overall capacity on |
| 373 | 373 |
outgoing arcs. Formally, there is a \f$G=(V,A)\f$ digraph, a |
| 374 | 374 |
\f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function. The minimum
|
| 375 | 375 |
cut is the \f$X\f$ solution of the next optimization problem: |
| 376 | 376 |
|
| 377 | 377 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
|
| 378 | 378 |
\sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f]
|
| 379 | 379 |
|
| 380 | 380 |
LEMON contains several algorithms related to minimum cut problems: |
| 381 | 381 |
|
| 382 | 382 |
- \ref HaoOrlin "Hao-Orlin algorithm" for calculating minimum cut |
| 383 | 383 |
in directed graphs. |
| 384 | 384 |
- \ref NagamochiIbaraki "Nagamochi-Ibaraki algorithm" for |
| 385 | 385 |
calculating minimum cut in undirected graphs. |
| 386 | 386 |
- \ref GomoryHu "Gomory-Hu tree computation" for calculating |
| 387 | 387 |
all-pairs minimum cut in undirected graphs. |
| 388 | 388 |
|
| 389 | 389 |
If you want to find minimum cut just between two distinict nodes, |
| 390 | 390 |
see the \ref max_flow "maximum flow problem". |
| 391 | 391 |
*/ |
| 392 | 392 |
|
| 393 | 393 |
/** |
| 394 |
@defgroup min_mean_cycle Minimum Mean Cycle Algorithms |
|
| 395 |
@ingroup algs |
|
| 396 |
\brief Algorithms for finding minimum mean cycles. |
|
| 397 |
|
|
| 398 |
This group contains the algorithms for finding minimum mean cycles. |
|
| 399 |
|
|
| 400 |
The \e minimum \e mean \e cycle \e problem is to find a directed cycle |
|
| 401 |
of minimum mean length (cost) in a digraph. |
|
| 402 |
The mean length of a cycle is the average length of its arcs, i.e. the |
|
| 403 |
ratio between the total length of the cycle and the number of arcs on it. |
|
| 404 |
|
|
| 405 |
This problem has an important connection to \e conservative \e length |
|
| 406 |
\e functions, too. A length function on the arcs of a digraph is called |
|
| 407 |
conservative if and only if there is no directed cycle of negative total |
|
| 408 |
length. For an arbitrary length function, the negative of the minimum |
|
| 409 |
cycle mean is the smallest \f$\epsilon\f$ value so that increasing the |
|
| 410 |
arc lengths uniformly by \f$\epsilon\f$ results in a conservative length |
|
| 411 |
function. |
|
| 412 |
|
|
| 413 |
LEMON contains three algorithms for solving the minimum mean cycle problem: |
|
| 414 |
- \ref Karp "Karp"'s original algorithm. |
|
| 415 |
- \ref HartmannOrlin "Hartmann-Orlin"'s algorithm, which is an improved |
|
| 416 |
version of Karp's algorithm. |
|
| 417 |
- \ref Howard "Howard"'s policy iteration algorithm. |
|
| 418 |
|
|
| 419 |
In practice, the Howard algorithm proved to be by far the most efficient |
|
| 420 |
one, though the best known theoretical bound on its running time is |
|
| 421 |
exponential. |
|
| 422 |
Both Karp and HartmannOrlin algorithms run in time O(ne) and use space |
|
| 423 |
O(n<sup>2</sup>+e), but the latter one is typically faster due to the |
|
| 424 |
applied early termination scheme. |
|
| 425 |
*/ |
|
| 426 |
|
|
| 427 |
/** |
|
| 394 | 428 |
@defgroup graph_properties Connectivity and Other Graph Properties |
| 395 | 429 |
@ingroup algs |
| 396 | 430 |
\brief Algorithms for discovering the graph properties |
| 397 | 431 |
|
| 398 | 432 |
This group contains the algorithms for discovering the graph properties |
| 399 | 433 |
like connectivity, bipartiteness, euler property, simplicity etc. |
| 400 | 434 |
|
| 401 | 435 |
\image html edge_biconnected_components.png |
| 402 | 436 |
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth |
| 403 | 437 |
*/ |
| 404 | 438 |
|
| 405 | 439 |
/** |
| 406 | 440 |
@defgroup planar Planarity Embedding and Drawing |
| 407 | 441 |
@ingroup algs |
| 408 | 442 |
\brief Algorithms for planarity checking, embedding and drawing |
| 409 | 443 |
|
| 410 | 444 |
This group contains the algorithms for planarity checking, |
| 411 | 445 |
embedding and drawing. |
| 412 | 446 |
|
| 413 | 447 |
\image html planar.png |
| 414 | 448 |
\image latex planar.eps "Plane graph" width=\textwidth |
| 415 | 449 |
*/ |
| 416 | 450 |
|
| 417 | 451 |
/** |
| 418 | 452 |
@defgroup matching Matching Algorithms |
| 419 | 453 |
@ingroup algs |
| 420 | 454 |
\brief Algorithms for finding matchings in graphs and bipartite graphs. |
| 421 | 455 |
|
| 422 | 456 |
This group contains the algorithms for calculating |
| 423 | 457 |
matchings in graphs and bipartite graphs. The general matching problem is |
| 424 | 458 |
finding a subset of the edges for which each node has at most one incident |
| 425 | 459 |
edge. |
| 426 | 460 |
|
| 427 | 461 |
There are several different algorithms for calculate matchings in |
| 428 | 462 |
graphs. The matching problems in bipartite graphs are generally |
| 429 | 463 |
easier than in general graphs. The goal of the matching optimization |
| 430 | 464 |
can be finding maximum cardinality, maximum weight or minimum cost |
| 431 | 465 |
matching. The search can be constrained to find perfect or |
| 432 | 466 |
maximum cardinality matching. |
| 433 | 467 |
|
| 434 | 468 |
The matching algorithms implemented in LEMON: |
| 435 | 469 |
- \ref MaxBipartiteMatching Hopcroft-Karp augmenting path algorithm |
| 436 | 470 |
for calculating maximum cardinality matching in bipartite graphs. |
| 437 | 471 |
- \ref PrBipartiteMatching Push-relabel algorithm |
| 438 | 472 |
for calculating maximum cardinality matching in bipartite graphs. |
| 439 | 473 |
- \ref MaxWeightedBipartiteMatching |
| 440 | 474 |
Successive shortest path algorithm for calculating maximum weighted |
| 441 | 475 |
matching and maximum weighted bipartite matching in bipartite graphs. |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_HARTMANN_ORLIN_H |
| 20 | 20 |
#define LEMON_HARTMANN_ORLIN_H |
| 21 | 21 |
|
| 22 |
/// \ingroup |
|
| 22 |
/// \ingroup min_mean_cycle |
|
| 23 | 23 |
/// |
| 24 | 24 |
/// \file |
| 25 | 25 |
/// \brief Hartmann-Orlin's algorithm for finding a minimum mean cycle. |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
#include <lemon/path.h> |
| 31 | 31 |
#include <lemon/tolerance.h> |
| 32 | 32 |
#include <lemon/connectivity.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief Default traits class of HartmannOrlin algorithm. |
| 37 | 37 |
/// |
| 38 | 38 |
/// Default traits class of HartmannOrlin algorithm. |
| 39 | 39 |
/// \tparam GR The type of the digraph. |
| 40 | 40 |
/// \tparam LEN The type of the length map. |
| 41 | 41 |
/// It must conform to the \ref concepts::Rea_data "Rea_data" concept. |
| 42 | 42 |
#ifdef DOXYGEN |
| 43 | 43 |
template <typename GR, typename LEN> |
| 44 | 44 |
#else |
| 45 | 45 |
template <typename GR, typename LEN, |
| 46 | 46 |
bool integer = std::numeric_limits<typename LEN::Value>::is_integer> |
| 47 | 47 |
#endif |
| 48 | 48 |
struct HartmannOrlinDefaultTraits |
| 49 | 49 |
{
|
| 50 | 50 |
/// The type of the digraph |
| 51 | 51 |
typedef GR Digraph; |
| 52 | 52 |
/// The type of the length map |
| 53 | 53 |
typedef LEN LengthMap; |
| 54 | 54 |
/// The type of the arc lengths |
| 55 | 55 |
typedef typename LengthMap::Value Value; |
| 56 | 56 |
|
| 57 | 57 |
/// \brief The large value type used for internal computations |
| 58 | 58 |
/// |
| 59 | 59 |
/// The large value type used for internal computations. |
| 60 | 60 |
/// It is \c long \c long if the \c Value type is integer, |
| 61 | 61 |
/// otherwise it is \c double. |
| 62 | 62 |
/// \c Value must be convertible to \c LargeValue. |
| 63 | 63 |
typedef double LargeValue; |
| 64 | 64 |
|
| 65 | 65 |
/// The tolerance type used for internal computations |
| 66 | 66 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
| 67 | 67 |
|
| 68 | 68 |
/// \brief The path type of the found cycles |
| 69 | 69 |
/// |
| 70 | 70 |
/// The path type of the found cycles. |
| 71 | 71 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
| 72 | 72 |
/// and it must have an \c addBack() function. |
| 73 | 73 |
typedef lemon::Path<Digraph> Path; |
| 74 | 74 |
}; |
| 75 | 75 |
|
| 76 | 76 |
// Default traits class for integer value types |
| 77 | 77 |
template <typename GR, typename LEN> |
| 78 | 78 |
struct HartmannOrlinDefaultTraits<GR, LEN, true> |
| 79 | 79 |
{
|
| 80 | 80 |
typedef GR Digraph; |
| 81 | 81 |
typedef LEN LengthMap; |
| 82 | 82 |
typedef typename LengthMap::Value Value; |
| 83 | 83 |
#ifdef LEMON_HAVE_LONG_LONG |
| 84 | 84 |
typedef long long LargeValue; |
| 85 | 85 |
#else |
| 86 | 86 |
typedef long LargeValue; |
| 87 | 87 |
#endif |
| 88 | 88 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
| 89 | 89 |
typedef lemon::Path<Digraph> Path; |
| 90 | 90 |
}; |
| 91 | 91 |
|
| 92 | 92 |
|
| 93 |
/// \addtogroup |
|
| 93 |
/// \addtogroup min_mean_cycle |
|
| 94 | 94 |
/// @{
|
| 95 | 95 |
|
| 96 | 96 |
/// \brief Implementation of the Hartmann-Orlin algorithm for finding |
| 97 | 97 |
/// a minimum mean cycle. |
| 98 | 98 |
/// |
| 99 | 99 |
/// This class implements the Hartmann-Orlin algorithm for finding |
| 100 | 100 |
/// a directed cycle of minimum mean length (cost) in a digraph. |
| 101 |
/// It is an improved version of \ref Karp "Karp's original algorithm |
|
| 101 |
/// It is an improved version of \ref Karp "Karp"'s original algorithm, |
|
| 102 | 102 |
/// it applies an efficient early termination scheme. |
| 103 |
/// It runs in time O(ne) and uses space O(n<sup>2</sup>+e). |
|
| 103 | 104 |
/// |
| 104 | 105 |
/// \tparam GR The type of the digraph the algorithm runs on. |
| 105 | 106 |
/// \tparam LEN The type of the length map. The default |
| 106 | 107 |
/// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
| 107 | 108 |
#ifdef DOXYGEN |
| 108 | 109 |
template <typename GR, typename LEN, typename TR> |
| 109 | 110 |
#else |
| 110 | 111 |
template < typename GR, |
| 111 | 112 |
typename LEN = typename GR::template ArcMap<int>, |
| 112 | 113 |
typename TR = HartmannOrlinDefaultTraits<GR, LEN> > |
| 113 | 114 |
#endif |
| 114 | 115 |
class HartmannOrlin |
| 115 | 116 |
{
|
| 116 | 117 |
public: |
| 117 | 118 |
|
| 118 | 119 |
/// The type of the digraph |
| 119 | 120 |
typedef typename TR::Digraph Digraph; |
| 120 | 121 |
/// The type of the length map |
| 121 | 122 |
typedef typename TR::LengthMap LengthMap; |
| 122 | 123 |
/// The type of the arc lengths |
| 123 | 124 |
typedef typename TR::Value Value; |
| 124 | 125 |
|
| 125 | 126 |
/// \brief The large value type |
| 126 | 127 |
/// |
| 127 | 128 |
/// The large value type used for internal computations. |
| 128 | 129 |
/// Using the \ref HartmannOrlinDefaultTraits "default traits class", |
| 129 | 130 |
/// it is \c long \c long if the \c Value type is integer, |
| 130 | 131 |
/// otherwise it is \c double. |
| 131 | 132 |
typedef typename TR::LargeValue LargeValue; |
| 132 | 133 |
|
| 133 | 134 |
/// The tolerance type |
| 134 | 135 |
typedef typename TR::Tolerance Tolerance; |
| 135 | 136 |
|
| 136 | 137 |
/// \brief The path type of the found cycles |
| 137 | 138 |
/// |
| 138 | 139 |
/// The path type of the found cycles. |
| 139 | 140 |
/// Using the \ref HartmannOrlinDefaultTraits "default traits class", |
| 140 | 141 |
/// it is \ref lemon::Path "Path<Digraph>". |
| 141 | 142 |
typedef typename TR::Path Path; |
| 142 | 143 |
|
| 143 | 144 |
/// The \ref HartmannOrlinDefaultTraits "traits class" of the algorithm |
| 144 | 145 |
typedef TR Traits; |
| 145 | 146 |
|
| 146 | 147 |
private: |
| 147 | 148 |
|
| 148 | 149 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 149 | 150 |
|
| 150 | 151 |
// Data sturcture for path data |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_HOWARD_H |
| 20 | 20 |
#define LEMON_HOWARD_H |
| 21 | 21 |
|
| 22 |
/// \ingroup |
|
| 22 |
/// \ingroup min_mean_cycle |
|
| 23 | 23 |
/// |
| 24 | 24 |
/// \file |
| 25 | 25 |
/// \brief Howard's algorithm for finding a minimum mean cycle. |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
#include <lemon/path.h> |
| 31 | 31 |
#include <lemon/tolerance.h> |
| 32 | 32 |
#include <lemon/connectivity.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief Default traits class of Howard class. |
| 37 | 37 |
/// |
| 38 | 38 |
/// Default traits class of Howard class. |
| 39 | 39 |
/// \tparam GR The type of the digraph. |
| 40 | 40 |
/// \tparam LEN The type of the length map. |
| 41 | 41 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
| 42 | 42 |
#ifdef DOXYGEN |
| 43 | 43 |
template <typename GR, typename LEN> |
| 44 | 44 |
#else |
| 45 | 45 |
template <typename GR, typename LEN, |
| 46 | 46 |
bool integer = std::numeric_limits<typename LEN::Value>::is_integer> |
| 47 | 47 |
#endif |
| 48 | 48 |
struct HowardDefaultTraits |
| 49 | 49 |
{
|
| 50 | 50 |
/// The type of the digraph |
| 51 | 51 |
typedef GR Digraph; |
| 52 | 52 |
/// The type of the length map |
| 53 | 53 |
typedef LEN LengthMap; |
| 54 | 54 |
/// The type of the arc lengths |
| 55 | 55 |
typedef typename LengthMap::Value Value; |
| 56 | 56 |
|
| 57 | 57 |
/// \brief The large value type used for internal computations |
| 58 | 58 |
/// |
| 59 | 59 |
/// The large value type used for internal computations. |
| 60 | 60 |
/// It is \c long \c long if the \c Value type is integer, |
| 61 | 61 |
/// otherwise it is \c double. |
| 62 | 62 |
/// \c Value must be convertible to \c LargeValue. |
| 63 | 63 |
typedef double LargeValue; |
| 64 | 64 |
|
| 65 | 65 |
/// The tolerance type used for internal computations |
| 66 | 66 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
| 67 | 67 |
|
| 68 | 68 |
/// \brief The path type of the found cycles |
| 69 | 69 |
/// |
| 70 | 70 |
/// The path type of the found cycles. |
| 71 | 71 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
| 72 | 72 |
/// and it must have an \c addBack() function. |
| 73 | 73 |
typedef lemon::Path<Digraph> Path; |
| 74 | 74 |
}; |
| 75 | 75 |
|
| 76 | 76 |
// Default traits class for integer value types |
| 77 | 77 |
template <typename GR, typename LEN> |
| 78 | 78 |
struct HowardDefaultTraits<GR, LEN, true> |
| 79 | 79 |
{
|
| 80 | 80 |
typedef GR Digraph; |
| 81 | 81 |
typedef LEN LengthMap; |
| 82 | 82 |
typedef typename LengthMap::Value Value; |
| 83 | 83 |
#ifdef LEMON_HAVE_LONG_LONG |
| 84 | 84 |
typedef long long LargeValue; |
| 85 | 85 |
#else |
| 86 | 86 |
typedef long LargeValue; |
| 87 | 87 |
#endif |
| 88 | 88 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
| 89 | 89 |
typedef lemon::Path<Digraph> Path; |
| 90 | 90 |
}; |
| 91 | 91 |
|
| 92 | 92 |
|
| 93 |
/// \addtogroup |
|
| 93 |
/// \addtogroup min_mean_cycle |
|
| 94 | 94 |
/// @{
|
| 95 | 95 |
|
| 96 | 96 |
/// \brief Implementation of Howard's algorithm for finding a minimum |
| 97 | 97 |
/// mean cycle. |
| 98 | 98 |
/// |
| 99 | 99 |
/// This class implements Howard's policy iteration algorithm for finding |
| 100 | 100 |
/// a directed cycle of minimum mean length (cost) in a digraph. |
| 101 |
/// This class provides the most efficient algorithm for the |
|
| 102 |
/// minimum mean cycle problem, though the best known theoretical |
|
| 103 |
/// bound on its running time is exponential. |
|
| 101 | 104 |
/// |
| 102 | 105 |
/// \tparam GR The type of the digraph the algorithm runs on. |
| 103 | 106 |
/// \tparam LEN The type of the length map. The default |
| 104 | 107 |
/// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
| 105 | 108 |
#ifdef DOXYGEN |
| 106 | 109 |
template <typename GR, typename LEN, typename TR> |
| 107 | 110 |
#else |
| 108 | 111 |
template < typename GR, |
| 109 | 112 |
typename LEN = typename GR::template ArcMap<int>, |
| 110 | 113 |
typename TR = HowardDefaultTraits<GR, LEN> > |
| 111 | 114 |
#endif |
| 112 | 115 |
class Howard |
| 113 | 116 |
{
|
| 114 | 117 |
public: |
| 115 | 118 |
|
| 116 | 119 |
/// The type of the digraph |
| 117 | 120 |
typedef typename TR::Digraph Digraph; |
| 118 | 121 |
/// The type of the length map |
| 119 | 122 |
typedef typename TR::LengthMap LengthMap; |
| 120 | 123 |
/// The type of the arc lengths |
| 121 | 124 |
typedef typename TR::Value Value; |
| 122 | 125 |
|
| 123 | 126 |
/// \brief The large value type |
| 124 | 127 |
/// |
| 125 | 128 |
/// The large value type used for internal computations. |
| 126 | 129 |
/// Using the \ref HowardDefaultTraits "default traits class", |
| 127 | 130 |
/// it is \c long \c long if the \c Value type is integer, |
| 128 | 131 |
/// otherwise it is \c double. |
| 129 | 132 |
typedef typename TR::LargeValue LargeValue; |
| 130 | 133 |
|
| 131 | 134 |
/// The tolerance type |
| 132 | 135 |
typedef typename TR::Tolerance Tolerance; |
| 133 | 136 |
|
| 134 | 137 |
/// \brief The path type of the found cycles |
| 135 | 138 |
/// |
| 136 | 139 |
/// The path type of the found cycles. |
| 137 | 140 |
/// Using the \ref HowardDefaultTraits "default traits class", |
| 138 | 141 |
/// it is \ref lemon::Path "Path<Digraph>". |
| 139 | 142 |
typedef typename TR::Path Path; |
| 140 | 143 |
|
| 141 | 144 |
/// The \ref HowardDefaultTraits "traits class" of the algorithm |
| 142 | 145 |
typedef TR Traits; |
| 143 | 146 |
|
| 144 | 147 |
private: |
| 145 | 148 |
|
| 146 | 149 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 147 | 150 |
|
| 148 | 151 |
// The digraph the algorithm runs on |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_KARP_H |
| 20 | 20 |
#define LEMON_KARP_H |
| 21 | 21 |
|
| 22 |
/// \ingroup |
|
| 22 |
/// \ingroup min_mean_cycle |
|
| 23 | 23 |
/// |
| 24 | 24 |
/// \file |
| 25 | 25 |
/// \brief Karp's algorithm for finding a minimum mean cycle. |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
#include <lemon/path.h> |
| 31 | 31 |
#include <lemon/tolerance.h> |
| 32 | 32 |
#include <lemon/connectivity.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief Default traits class of Karp algorithm. |
| 37 | 37 |
/// |
| 38 | 38 |
/// Default traits class of Karp algorithm. |
| 39 | 39 |
/// \tparam GR The type of the digraph. |
| 40 | 40 |
/// \tparam LEN The type of the length map. |
| 41 | 41 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
| 42 | 42 |
#ifdef DOXYGEN |
| 43 | 43 |
template <typename GR, typename LEN> |
| 44 | 44 |
#else |
| 45 | 45 |
template <typename GR, typename LEN, |
| 46 | 46 |
bool integer = std::numeric_limits<typename LEN::Value>::is_integer> |
| 47 | 47 |
#endif |
| 48 | 48 |
struct KarpDefaultTraits |
| 49 | 49 |
{
|
| 50 | 50 |
/// The type of the digraph |
| 51 | 51 |
typedef GR Digraph; |
| 52 | 52 |
/// The type of the length map |
| 53 | 53 |
typedef LEN LengthMap; |
| 54 | 54 |
/// The type of the arc lengths |
| 55 | 55 |
typedef typename LengthMap::Value Value; |
| 56 | 56 |
|
| 57 | 57 |
/// \brief The large value type used for internal computations |
| 58 | 58 |
/// |
| 59 | 59 |
/// The large value type used for internal computations. |
| 60 | 60 |
/// It is \c long \c long if the \c Value type is integer, |
| 61 | 61 |
/// otherwise it is \c double. |
| 62 | 62 |
/// \c Value must be convertible to \c LargeValue. |
| 63 | 63 |
typedef double LargeValue; |
| 64 | 64 |
|
| 65 | 65 |
/// The tolerance type used for internal computations |
| 66 | 66 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
| 67 | 67 |
|
| 68 | 68 |
/// \brief The path type of the found cycles |
| 69 | 69 |
/// |
| 70 | 70 |
/// The path type of the found cycles. |
| 71 | 71 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
| 72 | 72 |
/// and it must have an \c addBack() function. |
| 73 | 73 |
typedef lemon::Path<Digraph> Path; |
| 74 | 74 |
}; |
| 75 | 75 |
|
| 76 | 76 |
// Default traits class for integer value types |
| 77 | 77 |
template <typename GR, typename LEN> |
| 78 | 78 |
struct KarpDefaultTraits<GR, LEN, true> |
| 79 | 79 |
{
|
| 80 | 80 |
typedef GR Digraph; |
| 81 | 81 |
typedef LEN LengthMap; |
| 82 | 82 |
typedef typename LengthMap::Value Value; |
| 83 | 83 |
#ifdef LEMON_HAVE_LONG_LONG |
| 84 | 84 |
typedef long long LargeValue; |
| 85 | 85 |
#else |
| 86 | 86 |
typedef long LargeValue; |
| 87 | 87 |
#endif |
| 88 | 88 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
| 89 | 89 |
typedef lemon::Path<Digraph> Path; |
| 90 | 90 |
}; |
| 91 | 91 |
|
| 92 | 92 |
|
| 93 |
/// \addtogroup |
|
| 93 |
/// \addtogroup min_mean_cycle |
|
| 94 | 94 |
/// @{
|
| 95 | 95 |
|
| 96 | 96 |
/// \brief Implementation of Karp's algorithm for finding a minimum |
| 97 | 97 |
/// mean cycle. |
| 98 | 98 |
/// |
| 99 | 99 |
/// This class implements Karp's algorithm for finding a directed |
| 100 | 100 |
/// cycle of minimum mean length (cost) in a digraph. |
| 101 |
/// It runs in time O(ne) and uses space O(n<sup>2</sup>+e). |
|
| 101 | 102 |
/// |
| 102 | 103 |
/// \tparam GR The type of the digraph the algorithm runs on. |
| 103 | 104 |
/// \tparam LEN The type of the length map. The default |
| 104 | 105 |
/// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
| 105 | 106 |
#ifdef DOXYGEN |
| 106 | 107 |
template <typename GR, typename LEN, typename TR> |
| 107 | 108 |
#else |
| 108 | 109 |
template < typename GR, |
| 109 | 110 |
typename LEN = typename GR::template ArcMap<int>, |
| 110 | 111 |
typename TR = KarpDefaultTraits<GR, LEN> > |
| 111 | 112 |
#endif |
| 112 | 113 |
class Karp |
| 113 | 114 |
{
|
| 114 | 115 |
public: |
| 115 | 116 |
|
| 116 | 117 |
/// The type of the digraph |
| 117 | 118 |
typedef typename TR::Digraph Digraph; |
| 118 | 119 |
/// The type of the length map |
| 119 | 120 |
typedef typename TR::LengthMap LengthMap; |
| 120 | 121 |
/// The type of the arc lengths |
| 121 | 122 |
typedef typename TR::Value Value; |
| 122 | 123 |
|
| 123 | 124 |
/// \brief The large value type |
| 124 | 125 |
/// |
| 125 | 126 |
/// The large value type used for internal computations. |
| 126 | 127 |
/// Using the \ref KarpDefaultTraits "default traits class", |
| 127 | 128 |
/// it is \c long \c long if the \c Value type is integer, |
| 128 | 129 |
/// otherwise it is \c double. |
| 129 | 130 |
typedef typename TR::LargeValue LargeValue; |
| 130 | 131 |
|
| 131 | 132 |
/// The tolerance type |
| 132 | 133 |
typedef typename TR::Tolerance Tolerance; |
| 133 | 134 |
|
| 134 | 135 |
/// \brief The path type of the found cycles |
| 135 | 136 |
/// |
| 136 | 137 |
/// The path type of the found cycles. |
| 137 | 138 |
/// Using the \ref KarpDefaultTraits "default traits class", |
| 138 | 139 |
/// it is \ref lemon::Path "Path<Digraph>". |
| 139 | 140 |
typedef typename TR::Path Path; |
| 140 | 141 |
|
| 141 | 142 |
/// The \ref KarpDefaultTraits "traits class" of the algorithm |
| 142 | 143 |
typedef TR Traits; |
| 143 | 144 |
|
| 144 | 145 |
private: |
| 145 | 146 |
|
| 146 | 147 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 147 | 148 |
|
| 148 | 149 |
// Data sturcture for path data |
0 comments (0 inline)