Minimum Spanning Tree Algorithms
[Algorithms]


Detailed Description

This group describes the algorithms for finding a minimum cost spanning tree in a graph


Files

file  kruskal.h
 Kruskal's algorithm to compute a minimum cost spanning tree.

Functions

template<class Graph, class In, class Out>
Value kruskal (GR const &g, const In &in, Out &out)
 Kruskal algorithm to find a minimum cost spanning tree of a graph.


Function Documentation

Value lemon::kruskal ( GR const &  g,
const In &  in,
Out &  out 
) [inline]

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

Parameters:
g The 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.
in This 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,X> or std::pair<GR::Edge,X> as its value_type, where X 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:
out Here we also have a choice.
  • It can be a writable bool arc/edge map. 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.
          std::vector<Arc> tree(53);
          kruskal(g,cost,tree.begin());
    
    Or if we don't know in advance the size of the tree, we can write this.
          std::vector<Arc> tree;
          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.


Generated on Tue May 5 07:41:37 2009 for LEMON by  doxygen 1.5.6