pgr_kruskalBFS
— Prim algorithm for Minimum Spanning Tree with Depth First
Search ordering.
Availability
Support
Visits and extracts the nodes information in Breath First Search ordering of the Minimum Spanning Tree created using Prims’s algorithm.
The main Characteristics are:
pgr_kruskalBFS(Edges SQL, Root vid [, max_depth])
pgr_kruskalBFS(Edges SQL, Root vids [, max_depth])
RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
pgr_kruskalBFS(Edges SQL, Root vid [, max_depth])
RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
Example: | The Minimum Spanning Tree having as root vertex \(2\) |
---|
SELECT * FROM pgr_kruskalBFS(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
2
);
seq | depth | start_vid | node | edge | cost | agg_cost
-----+-------+-----------+------+------+------+----------
1 | 0 | 2 | 2 | -1 | 0 | 0
2 | 1 | 2 | 1 | 1 | 1 | 1
3 | 1 | 2 | 3 | 2 | 1 | 1
4 | 2 | 2 | 4 | 3 | 1 | 2
5 | 3 | 2 | 9 | 16 | 1 | 3
6 | 4 | 2 | 12 | 15 | 1 | 4
7 | 5 | 2 | 11 | 13 | 1 | 5
8 | 6 | 2 | 6 | 11 | 1 | 6
9 | 6 | 2 | 10 | 12 | 1 | 6
10 | 7 | 2 | 5 | 10 | 1 | 7
11 | 7 | 2 | 13 | 14 | 1 | 7
12 | 8 | 2 | 8 | 7 | 1 | 8
13 | 9 | 2 | 7 | 6 | 1 | 9
(13 rows)
pgr_kruskalBFS(Edges SQL, Root vids [, max_depth])
RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
Example: | The Minimum Spanning Tree starting on vertices \(\{13, 2\}\) with \(depth <= 3\) |
---|
SELECT * FROM pgr_kruskalBFS(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
ARRAY[13,2], max_depth := 3
);
seq | depth | start_vid | node | edge | cost | agg_cost
-----+-------+-----------+------+------+------+----------
1 | 0 | 2 | 2 | -1 | 0 | 0
2 | 1 | 2 | 1 | 1 | 1 | 1
3 | 1 | 2 | 3 | 2 | 1 | 1
4 | 2 | 2 | 4 | 3 | 1 | 2
5 | 3 | 2 | 9 | 16 | 1 | 3
6 | 0 | 13 | 13 | -1 | 0 | 0
7 | 1 | 13 | 10 | 14 | 1 | 1
8 | 2 | 13 | 5 | 10 | 1 | 2
9 | 2 | 13 | 11 | 12 | 1 | 2
10 | 3 | 13 | 8 | 7 | 1 | 3
11 | 3 | 13 | 6 | 11 | 1 | 3
12 | 3 | 13 | 12 | 13 | 1 | 3
(12 rows)
Parameter | Type | Description |
---|---|---|
Edges SQL | TEXT |
SQL query described in Inner query. |
Root vid | BIGINT |
Identifier of the root vertex of the tree.
|
Root vids | ARRAY[ANY-INTEGER] |
Array of identifiers of the root vertices.
|
Parameter | Type | Default | Description |
---|---|---|---|
max_depth | BIGINT |
\(9223372036854775807\) | Upper limit for depth of node in the tree
|
Column | Type | Default | Description |
---|---|---|---|
id | ANY-INTEGER |
Identifier of the edge. | |
source | ANY-INTEGER |
Identifier of the first end point vertex of the edge. | |
target | ANY-INTEGER |
Identifier of the second end point vertex of the edge. | |
cost | ANY-NUMERICAL |
Weight of the edge (source, target)
|
|
reverse_cost | ANY-NUMERICAL |
-1 | Weight of the edge (target, source),
|
Where:
ANY-INTEGER: | SMALLINT, INTEGER, BIGINT |
---|---|
ANY-NUMERICAL: | SMALLINT, INTEGER, BIGINT, REAL, FLOAT |
Returns SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
Column | Type | Description |
---|---|---|
seq | BIGINT |
Sequential value starting from \(1\). |
depth | BIGINT |
Depth of the
|
start_vid | BIGINT |
Identifier of the root vertex.
|
node | BIGINT |
Identifier of node reached using edge . |
edge | BIGINT |
Identifier of the
|
cost | FLOAT |
Cost to traverse edge . |
agg_cost | FLOAT |
Aggregate cost from start_vid to node . |
Indices and tables