|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Computes the minimum spanning tree of a graph using Kruskal's algorithm. More...
#include <Kruskal.H>
Classes | |
| struct | Init_Node |
| Helper struct for initializing node counters during DFS. More... | |
| struct | Paint_Filt |
| Filter for arcs painted by Kruskal's algorithm. More... | |
Public Member Functions | |
| Kruskal_Min_Spanning_Tree (Distance __dist=Distance(), SA __sa=SA()) | |
| Constructor. | |
| bool | is_painted () const noexcept |
| Returns true if the spanning tree has been painted on the graph. | |
| void | paint_min_spanning_tree (const GT &g) |
| Paints the minimum spanning tree arcs on the graph. | |
| void | paint_min_spanning_tree (const GT &g, GT &tree) |
| Paints the MST on g and copies it to a separate tree graph. | |
| void | operator() (const GT &g, GT &tree) |
| Computes the minimum spanning tree using Kruskal's algorithm. | |
| void | operator() (const GT &g) |
| Paints the minimum spanning tree on the graph using Kruskal's algorithm. | |
Static Private Member Functions | |
| static bool | arc_is_in_tree (Fixed_Relation &tree, long i, long j) noexcept |
Private Attributes | |
| Distance | dist |
| SA | sa |
| bool | painted |
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:
Time complexity: O(E log E) where E is the number of arcs. Space complexity: O(V) for the Union-Find structure.
|
inline |
|
inlinestaticprivatenoexcept |
Definition at line 113 of file Kruskal.H.
Referenced by Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree().
|
inlinenoexcept |
Returns true if the spanning tree has been painted on the graph.
Definition at line 134 of file Kruskal.H.
References Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::painted.
Referenced by TEST().
|
inline |
Paints the minimum spanning tree on the graph using Kruskal's algorithm.
After the algorithm completes, the arcs of g that belong to the spanning tree are marked with the Spanning_Tree bit.
| [in] | g | The graph for which to compute the minimum spanning tree. |
| bad_alloc | If there is not enough memory. |
| domain_error | If g is a digraph. |
Definition at line 276 of file Kruskal.H.
References Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree().
|
inline |
Computes the minimum spanning tree using Kruskal's algorithm.
| [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. |
| bad_alloc | If there is not enough memory to construct the tree. In this case, the value of tree is indeterminate and not clean. |
| domain_error | If g is a digraph. |
Definition at line 261 of file Kruskal.H.
References Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree().
|
inline |
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.
The arcs are sorted in an array of their own, so the order of the arcs of g does not change.
| [in] | g | The graph for which to compute the minimum spanning tree. |
| domain_error | If g is a digraph. |
| bad_alloc | If there is not enough memory for the array. |
Definition at line 176 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(), arcs, Aleph::Array< T >::create_reserved(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::dist, GraphCommon< GT, Node, Arc >::get_num_arcs(), 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(), k, Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), 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, Aleph::timsort(), 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().
|
inline |
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.
| [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. |
| bad_alloc | If there is not enough memory to construct the tree. |
| domain_error | If g is a digraph. |
Definition at line 224 of file Kruskal.H.
References ARC_COOKIE, 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(), NODE_COOKIE, Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree(), and Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::sa.
|
private |
Definition at line 95 of file Kruskal.H.
Referenced by Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree().
|
private |
Definition at line 97 of file Kruskal.H.
Referenced by Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::is_painted(), and Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree().
|
private |
Definition at line 96 of file Kruskal.H.
Referenced by Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree(), and Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree().