All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions
HowardMmc< GR, CM, TR > Class Template Reference

Detailed Description

template<typename GR, typename CM, typename TR>
class lemon::HowardMmc< GR, CM, TR >

This class implements Howard's policy iteration algorithm for finding a directed cycle of minimum mean cost in a digraph [9], [10]. This class provides the most efficient algorithm for the minimum mean cycle problem, though the best known theoretical bound on its running time is exponential.

Template Parameters
GRThe type of the digraph the algorithm runs on.
CMThe type of the cost map. The default map type is GR::ArcMap<int>.
TRThe traits class that defines various types used by the algorithm. By default, it is HowardMmcDefaultTraits<GR, CM>. In most cases, this parameter should not be set directly, consider to use the named template parameters instead.

#include <lemon/howard_mmc.h>

Classes

struct  SetLargeCost
 Named parameter for setting LargeCost type. More...
 
struct  SetPath
 Named parameter for setting Path type. More...
 

Public Types

enum  TerminationCause { NO_CYCLE = 0, OPTIMAL = 1, ITERATION_LIMIT }
 Constants for the causes of search termination. More...
 
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.
 
typedef TR::Tolerance Tolerance
 The tolerance type.
 
typedef TR::Path Path
 The path type of the found cycles.
 
typedef TR Traits
 The traits class of the algorithm.
 

Public Member Functions

 HowardMmc (const Digraph &digraph, const CostMap &cost)
 Constructor.
 
 ~HowardMmc ()
 Destructor.
 
HowardMmccycle (Path &path)
 Set the path structure for storing the found cycle.
 
HowardMmctolerance (const Tolerance &tolerance)
 Set the tolerance used by the algorithm.
 
const Tolerancetolerance () const
 Return a const reference to the tolerance.
 
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().

bool run ()
 Run the algorithm.
 
TerminationCause findCycleMean (int limit=std::numeric_limits< int >::max())
 Find the minimum cycle mean (or an upper bound).
 
bool findCycle ()
 Find a minimum mean directed cycle.
 
Query Functions

The results of the algorithm can be obtained using these functions.
The algorithm should be executed before using them.

Cost cycleCost () const
 Return the total cost of the found cycle.
 
int cycleSize () const
 Return the number of arcs on the found cycle.
 
double cycleMean () const
 Return the mean cost of the found cycle.
 
const Pathcycle () const
 Return the found cycle.
 

Member Typedef Documentation

typedef TR::LargeCost LargeCost

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::Path Path

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

Member Enumeration Documentation

Enum type containing constants for the different causes of search termination. The findCycleMean() function returns one of these values.

Enumerator:
NO_CYCLE 

No directed cycle can be found in the digraph.

OPTIMAL 

Optimal solution (minimum cycle mean) is found.

ITERATION_LIMIT 

The iteration count limit is reached.

Constructor & Destructor Documentation

HowardMmc ( const Digraph digraph,
const CostMap cost 
)
inline

The constructor of the class.

Parameters
digraphThe digraph the algorithm runs on.
costThe costs of the arcs.

Member Function Documentation

HowardMmc& cycle ( Path path)
inline

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 addBack() function of the given path structure.
Returns
(*this)
HowardMmc& tolerance ( const Tolerance tolerance)
inline

This function sets the tolerance object used by the algorithm.

Returns
(*this)
const Tolerance& tolerance ( ) const
inline

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

bool run ( )
inline

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).

Returns
true if a directed cycle exists in the digraph.
Note
mmc.run() is just a shortcut of the following code.
return mmc.findCycleMean() && mmc.findCycle();
TerminationCause findCycleMean ( int  limit = std::numeric_limits<int>::max())
inline

This function finds the minimum mean cost of the directed cycles in the digraph (or an upper bound for it).

By default, the function finds the exact minimum cycle mean, but an optional limit can also be specified for the number of iterations performed during the search process. The return value indicates if the optimal solution is found or the iteration limit is reached. In the latter case, an approximate solution is provided, which corresponds to a directed cycle whose mean cost is relatively small, but not necessarily minimal.

Parameters
limitThe maximum allowed number of iterations during the search process. Its default value implies that the algorithm runs until it finds the exact optimal solution.
Returns
The termination cause of the search process. For more information, see TerminationCause.
bool findCycle ( )
inline

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.
Precondition
findCycleMean() must be called before using this function.
Cost cycleCost ( ) const
inline

This function returns the total cost of the found cycle.

Precondition
run() or findCycleMean() must be called before using this function.
int cycleSize ( ) const
inline

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

Precondition
run() or findCycleMean() must be called before using this function.
double cycleMean ( ) const
inline

This function returns the mean cost of the found cycle.

Note
alg.cycleMean() is just a shortcut of the following code.
return static_cast<double>(alg.cycleCost()) / alg.cycleSize();
Precondition
run() or findCycleMean() must be called before using this function.
const Path& cycle ( ) const
inline

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

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