Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Minimum Cost Spanning Tree Algorithms
[Graph Algorithms]


Detailed Description

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


Files

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

Functions

template<class GR, class IN, class OUT>
IN::value_type::second_type lemon::kruskal (GR const &g, IN const &in, OUT &out)
 Kruskal's algorithm to find a minimum cost tree of a graph.


Function Documentation

IN::value_type::second_type lemon::kruskal GR const &  g,
IN const &  in,
OUT &  out
 

This function runs Kruskal's algorithm to find a minimum cost tree. Due to hard 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 edges.
in This object is used to describe the edge costs. It can be one of the following choices.
  • An STL compatible 'Forward Container' with std::pair<GR::Edge,X> as its value_type, where X is the type of the costs. The pairs indicates the edges along with the assigned cost. They must be in a cost-ascending order.
  • Any readable Edge map. The values of the map indicate the edge costs.
Return values:
out Here we also have a choise.
  • Is can be a writable bool edge map. After running the algorithm this will contain the found minimum cost spanning tree: the value of an edge will be set to true if it belongs to the tree, otherwise it will be set to false. The value of each edge will be set exactly once.
  • It can also be an iteraror of an STL Container with 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 edges, then we can put its edges into a STL vector tree with a code like this.
          std::vector<Edge> tree(53);
          kruskal(g,cost,tree.begin());
    
    Or if we don't know in advance the size of the tree, we can write this.
Returns:
The cost of the found tree.
Warning:
If kruskal is run on an undirected graph, be sure that the map storing the tree is also undirected (e.g. UndirListGraph::UndirEdgeMap<bool>, otherwise the values of the half of the edges will not be set.
Todo:
Discuss the case of undirected graphs: In this case the algorithm also require Edges instead of UndirEdges, as some people would expect. So, one should be careful not to add both of the Edges belonging to a certain UndirEdge. (kruskal() and KruskalMapInput are kind enough to do so.)


Generated on Sat Aug 27 14:14:56 2005 for LEMON by  doxygen 1.4.4