ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
MinimumSpanningTree.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------- File MinimumSpanningTree.h -----------------------*/
3/*--------------------------------------------------------------------------*/
55/*--------------------------------------------------------------------------*/
56/*----------------------------- DEFINITIONS --------------------------------*/
57/*--------------------------------------------------------------------------*/
58
59#ifndef __ADS_MinimumSpanningTree
60 #define __ADS_MinimumSpanningTree
61/* self-identification: #endif constant */
62
63/*--------------------------------------------------------------------------*/
64/*------------------------------ INCLUDES ----------------------------------*/
65/*--------------------------------------------------------------------------*/
66
67#include "ADS/Capabilities.h"
68#include "ADS/Contract.h"
69#include "ADS/graph/Graph.h"
71#include "ADS/mfset/MFSet.h"
75
76#include <algorithm>
77#include <concepts>
78#include <cstddef>
79#include <memory>
80#include <tuple>
81#include <type_traits>
82#include <vector>
83
84/*--------------------------------------------------------------------------*/
85/*--------------------------- NAMESPACE ------------------------------------*/
86/*--------------------------------------------------------------------------*/
87
88namespace ADS
89{
90
92template< class W >
94{
95 int u ,
96 v;
97 W w;
99 bool operator==( const WeightedEdge & ) const = default;
100 };
101
117template< Graph G >
118std::vector< WeightedEdge< typename G::Weight > > edges( const G & g );
119
146template< class W >
147std::vector< WeightedEdge< W > >
148kruskal( int n , std::vector< WeightedEdge< W > > A , long k = 0 );
149
152template< class M >
153concept Mergeable = requires( M m , int u , int v )
154{
155 { m.merge( u , v ) } -> std::convertible_to< bool >;
156 };
157
161{
162 long long merges = 0 ,
163 unions = 0;
164 };
165
182template< class W , Mergeable M >
183std::vector< WeightedEdge< W > >
184kruskal( int n , std::vector< WeightedEdge< W > > A , M & sets , long k = 0 ,
185 MergeCounts * c = nullptr );
186
197template< Graph G >
198auto kruskal( const G & g , long k = 0 );
199
214template< Graph G >
215std::vector< int > prim( const G & g , int r , Frontier how = Frontier::HEAP );
216
256template< Graph G , FrontierQueue Q >
257std::vector< int > prim( const G & g , int r , Q & q ,
258 FrontierCounts * c = nullptr );
259
280template< class W >
282 const std::vector< WeightedEdge< W > > & A ,
283 const std::vector< WeightedEdge< W > > & T );
284
285/*--------------------------------------------------------------------------*/
286
287} // end( namespace ADS )
288
289/*--------------------------------------------------------------------------*/
290/*-------------------------- IMPLEMENTATION --------------------------------*/
291/*--------------------------------------------------------------------------*/
292
293#include "ADS/graph/impl/MinimumSpanningTree.tpp"
294
295/*--------------------------------------------------------------------------*/
296
297#endif /* MinimumSpanningTree.h included */
298
299/*--------------------------------------------------------------------------*/
300/*--------------------- End File MinimumSpanningTree.h ---------------------*/
301/*--------------------------------------------------------------------------*/
The capabilities of the structures, beyond the book: what an algorithm may ask of its argument to cho...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The PRIORITYQUEUE [see PriorityQueue.h] on a Fibonacci heap, the structure that section 11....
The PRIORITYQUEUE [see PriorityQueue.h] on a heap.
The PRIORITYQUEUE [see PriorityQueue.h] on a list.
The MFSET of section 10.2, the union of disjoint sets: MFSet( n ) makes the components ,...
The shortest paths of chapter 11 from a node of an oriented GRAPH whose edges have a cost [see Grap...
a union of disjoint sets as kruskal() needs it: merge( u , v ) joins the components of u and v and te...
Definition MinimumSpanningTree.h:153
The GRAPH of chapter 9 and its realizations.
std::vector< WeightedEdge< typename G::Weight > > edges(const G &g)
the edges of an unoriented graph, each once, from its smaller end
std::vector< int > prim(const G &g, int r, Frontier how=Frontier::HEAP)
the parents of the tree from , NIL for and the nodes out of its component; how is LIST,...
bool isMinimumSpanningForest(int n, const std::vector< WeightedEdge< W > > &A, const std::vector< WeightedEdge< W > > &T)
whether is a minimum spanning forest of the edges on the nodes : its edges are in A,...
std::vector< WeightedEdge< W > > kruskal(int n, std::vector< WeightedEdge< W > > A, long k=0)
the edges of a minimum spanning forest of the nodes ; with the weights are integers in ,...
Frontier
the structure of the prototype
Definition ShortestPaths.h:135
@ HEAP
a priority queue on a binary heap: Johnson
Definition ShortestPaths.h:137
Definition ADT.h:96
what a run of the prototype did: the nodes added to (the lines (1) and (3)), the extractions (2),...
Definition ShortestPaths.h:171
what a run of kruskal() did: the merges tried and those that joined two components
Definition MinimumSpanningTree.h:161
long long unions
the merges that joined two components
Definition MinimumSpanningTree.h:163
long long merges
the merges tried
Definition MinimumSpanningTree.h:162
an edge of weight
Definition MinimumSpanningTree.h:94
W w
the weight
Definition MinimumSpanningTree.h:97
int v
the other end
Definition MinimumSpanningTree.h:96
int u
one end
Definition MinimumSpanningTree.h:95
bool operator==(const WeightedEdge &) const =default
whether the two edges have the same ends, in order, and weight