Detailed Description
This group contains the algorithms for finding minimum cost spanning trees and arborescences [CLRS01].
Classes |
class | MinCostArborescence< GR, CM, TR > |
| Minimum Cost Arborescence algorithm class. More...
|
Files |
file | kruskal.h |
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:
-
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,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:
-
out | Here 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. 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.
CostMap::Value lemon::minCostArborescence |
( |
const Digraph & |
digraph, |
|
|
const CostMap & |
cost, |
|
|
typename Digraph::Node |
source, |
|
|
ArborescenceMap & |
arborescence |
|
) |
| |
Function type interface for MinCostArborescence algorithm.
- Parameters:
-
digraph | The digraph the algorithm runs on. |
cost | An arc map storing the costs. |
source | The source node of the arborescence. |
- Return values:
-
arborescence | An arc map with bool (or convertible) value type that stores the arborescence. |
- Returns:
- The total cost of the arborescence.
- See also:
- MinCostArborescence