HartmannOrlinMmc

Declared in lemon/hartmann_orlin_mmc.h, in the group Minimum Mean Cycle Algorithms; the same class on the Doxygen site.

template< typename GR , typename CM , typename TR >
class HartmannOrlinMmc

Implementation of the Hartmann-Orlin algorithm for finding a minimum mean cycle.

This class implements the Hartmann-Orlin algorithm for finding a directed cycle of minimum mean cost in a digraph [22], [10]. This method is based on Karp’s original algorithm, but applies an early termination scheme. It makes the algorithm significantly faster for some problem instances, but slower for others. The algorithm runs in time O(nm) and uses space O(n2+m).

Template Parameters:
  • GR – The type of the digraph the algorithm runs on.

  • CM – The type of the cost map. The default map type is GR::ArcMap< int >.

  • TR – The traits class that defines various types used by the algorithm. By default, it is HartmannOrlinMmcDefaultTraits< GR , CM >. In most cases, this parameter should not be set directly, consider to use the named template parameters instead.

Execution control

The simplest way to execute the algorithm is to call the run()

function.

If you only need the minimum mean cost, you may call

findCycleMean().

inline bool run()

Run the algorithm.

This function runs the algorithm. It can be called more than once (e.g. if the underlying digraph and/or the arc costs have been modified).

Note

mmc.run() is just a shortcut of the following code.

return( mmc.findCycleMean() && mmc.findCycle() );

Returns:

true if a directed cycle exists in the digraph.

inline bool findCycleMean()

Find the minimum cycle mean.

This function finds the minimum mean cost of the directed cycles in the digraph.

Returns:

true if a directed cycle exists in the digraph.

inline bool findCycle()

Find a minimum mean directed cycle.

This function finds a directed cycle of minimum mean cost in the digraph using the data computed by findCycleMean().

Returns:

true if a directed cycle exists in the digraph.

Pre:

findCycleMean() must be called before using this function.

Query Functions

The results of the algorithm can be obtained using these functions.

The algorithm should be executed before using them.

inline Cost cycleCost() const

Return the total cost of the found cycle.

This function returns the total cost of the found cycle.

Pre:

run() or findCycleMean() must be called before using this function.

inline int cycleSize() const

Return the number of arcs on the found cycle.

This function returns the number of arcs on the found cycle.

Pre:

run() or findCycleMean() must be called before using this function.

inline double cycleMean() const

Return the mean cost of the found cycle.

This function returns the mean cost of the found cycle.

Note

alg.cycleMean() divides the cost of the cycle, kept as a LargeCost, by cycleSize(); hence it is the same as static_cast< double >( alg.cycleCost() ) / alg.cycleSize() only when that cost fits in Cost, to which cycleCost() converts it.

Pre:

run() or findCycleMean() must be called before using this function.

inline const Path & cycle() const

Return the found cycle.

This function returns a const reference to the path structure storing the found cycle.

Pre:

run() or findCycle() must be called before using this function.

Public Types

typedef TR::Digraph Digraph

The type of the digraph.

typedef TR::CostMap CostMap

The type of the cost map.

typedef TR::Cost Cost

The type of the arc costs.

typedef TR::LargeCost LargeCost

The large cost type.

The large cost type used for internal computations. By default, it is long long if the Cost type is integer, otherwise it is double.

typedef TR::Tolerance Tolerance

The tolerance type.

typedef TR::Path Path

The path type of the found cycles. Using the default traits class, it is Path< Digraph >.

typedef TR Traits

The traits class of the algorithm.

Public Functions

inline HartmannOrlinMmc( const Digraph & digraph , const CostMap & cost )

Constructor.

The constructor of the class.

Parameters:
  • digraph – The digraph the algorithm runs on.

  • cost – The costs of the arcs.

inline ~HartmannOrlinMmc()

Destructor.

inline HartmannOrlinMmc & cycle( Path & path )

Set the path structure for storing the found cycle.

This function sets an external path structure for storing the found cycle.

If you don’t call this function before calling run() or findCycleMean(), a local path structure will be allocated. The destuctor deallocates this automatically allocated object, of course.

Note

The algorithm calls only the addFront() function of the given path structure.

Returns:

(*this)

inline HartmannOrlinMmc & tolerance( const Tolerance & tolerance )

Set the tolerance used by the algorithm.

This function sets the tolerance object used by the algorithm.

Returns:

(*this)

inline const Tolerance & tolerance() const

Return a const reference to the tolerance.

This function returns a const reference to the tolerance object used by the algorithm.

Protected Functions

inline HartmannOrlinMmc()
template< typename T >
struct SetLargeCostTraits : public Traits

Public Types

typedef T LargeCost
typedef lemon::Tolerance< T > Tolerance
template< typename T >
struct SetLargeCost : public HartmannOrlinMmc< GR , CM , SetLargeCostTraits< T > >

Named parameter for setting LargeCost type. It is used for internal computations in the algorithm.

Public Types

typedef HartmannOrlinMmc< GR , CM , SetLargeCostTraits< T > > Create
template< typename T >
struct SetPathTraits : public Traits

Public Types

typedef T Path
template< typename T >
struct SetPath : public HartmannOrlinMmc< GR , CM , SetPathTraits< T > >

Named parameter for setting Path type.

Named parameter for setting the Path type of the found cycles. It must conform to the Path concept and it must have an addFront() function.

Public Types

typedef HartmannOrlinMmc< GR , CM , SetPathTraits< T > > Create