All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Files | Functions
Minimum Spanning Tree Algorithms
Algorithms

Detailed Description

This group contains the algorithms for finding minimum cost spanning trees and arborescences [6].

Classes

class  MinCostArborescence< GR, CM, TR >
 Minimum Cost Arborescence algorithm class. More...
 
class  MinCostArborescence< GR, CM, TR >::DualIt
 LEMON iterator for getting a dual variable. More...
 
struct  MinCostArborescence< GR, CM, TR >::SetArborescenceMap< T >
 Named parameter for setting ArborescenceMap type More...
 
struct  MinCostArborescence< GR, CM, TR >::SetPredMap< T >
 Named parameter for setting PredMap type More...
 

Files

file  kruskal.h
 Kruskal's algorithm to compute a minimum cost spanning tree.
 
file  min_cost_arborescence.h
 Minimum Cost Arborescence algorithm.
 

Functions

template<typename Graph , typename In , typename Out >
Value kruskal (const Graph &g, const In &in, Out &out)
 Kruskal's algorithm for finding a minimum cost spanning tree of a graph.
 
template<typename Digraph , typename CostMap , typename ArborescenceMap >
CostMap::Value minCostArborescence (const Digraph &digraph, const CostMap &cost, typename Digraph::Node source, ArborescenceMap &arborescence)
 Function type interface for MinCostArborescence algorithm.
 

Function Documentation

Value lemon::kruskal ( const Graph &  g,
const In &  in,
Out &  out 
)

This function runs Kruskal's algorithm to find a minimum cost spanning tree of a graph. Due to some C++ hacking, it accepts various input and output types.

Parameters
gThe graph the algorithm runs on. It can be either directed or undirected. If the graph is directed, the algorithm consider it to be undirected by disregarding the direction of the arcs.
inThis object is used to describe the arc/edge costs. It can be one of the following choices.
  • An STL compatible 'Forward Container' with std::pair<GR::Arc,C> or std::pair<GR::Edge,C> as its value_type, where C is the type of the costs. The pairs indicates the arcs/edges along with the assigned cost. They must be in a cost-ascending order.
  • Any readable arc/edge map. The values of the map indicate the arc/edge costs.
Return values
outHere we also have a choice.
  • It can be a writable arc/edge map with bool value type. After running the algorithm it will contain the found minimum cost spanning tree: the value of an arc/edge will be set to true if it belongs to the tree, otherwise it will be set to false. The value of each arc/edge will be set exactly once.
  • It can also be an iteraror of an STL Container with GR::Arc or GR::Edge as its value_type. The algorithm copies the elements of the found tree into this sequence. For example, if we know that the spanning tree of the graph g has say 53 arcs, then we can put its arcs into an STL vector tree with a code like this.
    kruskal(g,cost,tree.begin());
    Or if we don't know in advance the size of the tree, we can write this.
    kruskal(g,cost,std::back_inserter(tree));
Returns
The total cost of the found spanning tree.
Note
If the input graph is not (weakly) connected, a spanning forest is calculated instead of a spanning tree.
CostMap::Value lemon::minCostArborescence ( const Digraph &  digraph,
const CostMap &  cost,
typename Digraph::Node  source,
ArborescenceMap &  arborescence 
)

Function type interface for MinCostArborescence algorithm.

Parameters
digraphThe digraph the algorithm runs on.
costAn arc map storing the costs.
sourceThe source node of the arborescence.
Return values
arborescenceAn arc map with bool (or convertible) value type that stores the arborescence.
Returns
The total cost of the arborescence.
See Also
MinCostArborescence