template<AlephGraph GT,
class Distance = Dft_Dist<GT>, ArcFilter<
GT > SA = Dft_Show_Arc<GT>>
class Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >
Computes the minimum spanning tree of a graph using Kruskal's algorithm.
Kruskal's algorithm is recommended for sparse graphs. It works by sorting all arcs by weight and greedily adding arcs that don't form a cycle.
The procedure is parameterized with the following specifications:
- GT: The graph type based on List_Graph.
- Distance<GT>: The arc weight accessor class that must export the following attributes:
- typedef Distance<GT>::Distance_Type: The data type that represents an arc weight.
- Distance<GT>::Distance_Type operator()(typename GT::Arc *a): Returns the weight value of arc a.
- Distance<GT>::Max_Distance: Static constant representing the maximum distance value that an algorithm would consider as infinity.
- typename Distance<GT>::Zero_Distance: Static constant corresponding to the neutral element of addition. Traditionally, in the vast majority of cases, this is zero.
- SA: Arc filter for arc iterators.
Time complexity: O(E log E) where E is the number of arcs. Space complexity: O(V) for the Union-Find structure.
- See also
- Prim_Min_Spanning_Tree
Definition at line 91 of file Kruskal.H.
template<AlephGraph GT,
class Distance = Dft_Dist<GT>, ArcFilter<
GT > SA = Dft_Show_Arc<GT>>
Paints the minimum spanning tree arcs on the graph.
After calling this method, the arcs belonging to the MST are marked with the Spanning_Tree bit. Use is_painted() to check if the tree has been painted.
- Note
- The const_cast on g is safe because sort_arcs only changes the physical ordering of arcs, not the logical graph structure.
- Parameters
-
| [in] | g | The graph for which to compute the minimum spanning tree. |
- Exceptions
-
| domain_error | If g is a digraph. |
Definition at line 168 of file Kruskal.H.
References ah_domain_error_if, Aleph::and, ARC_BITS, Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::arc_is_in_tree(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::dist, Fixed_Relation::get_num_blocks(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), GraphCommon< GT, Node, Arc >::is_digraph(), Fixed_Relation::join(), NODE_COUNTER, Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::painted, GraphCommon< GT, Node, Arc >::reset_bit_arcs(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::sa, Aleph::Spanning_Tree, and V.
Referenced by Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::operator()(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::operator()(), and Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree().
template<AlephGraph GT,
class Distance = Dft_Dist<GT>, ArcFilter<
GT > SA = Dft_Show_Arc<GT>>
Paints the MST on g and copies it to a separate tree graph.
First paints the spanning tree arcs on g, then creates a copy of the MST in the tree parameter.
- Parameters
-
| [in] | g | The graph for which to compute the minimum spanning tree. |
| [out] | tree | The graph where the resulting minimum spanning tree will be stored. This graph is cleared before the algorithm starts. |
- Exceptions
-
| bad_alloc | If there is not enough memory to construct the tree. |
| domain_error | If g is a digraph. |
Definition at line 211 of file Kruskal.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::clear_graph(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), GraphCommon< GT, Node, Arc >::map_arcs(), GraphCommon< GT, Node, Arc >::map_nodes(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree(), and Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::sa.