pgr_primDD
¶
pgr_primDD
— Catchament nodes using Prim’s algorithm.
Availability
Version 3.0.0
New Official function
Description¶
Using Prim’s algorithm, extracts the nodes that have aggregate costs less than or equal to a distance from a root vertex (or vertices) within the calculated minimum spanning tree.
The main Characteristics are:
It’s implementation is only on undirected graph.
Process is done only on edges with positive costs.
When the graph is connected
The resulting edges make up a tree
When the graph is not connected,
Finds a minimum spanning tree for each connected component.
The resulting edges make up a forest.
Prim’s running time: \(O(E * log V)\)
Extracts all the nodes that have costs less than or equal to the value distance.
The edges extracted will conform to the corresponding spanning tree.
Edge \((u, v)\) will not be included when:
The distance from the root to \(u\) > limit distance.
The distance from the root to \(v\) > limit distance.
No new nodes are created on the graph, so when is within the limit and is not within the limit, the edge is not included.
Returned tree nodes from a root vertex are on Depth First Search order.
Depth First Search running time: \(O(E + V)\)
Signatures¶
(seq, depth, start_vid, node, edge, cost, agg_cost)
Single vertex¶
(seq, depth, start_vid, node, edge, cost, agg_cost)
 Example:
The Minimum Spanning Tree starting on vertex \(6\) with \(distance \leq 3.5\)
SELECT * FROM pgr_primDD(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
6, 3.5);
seq  depth  start_vid  node  edge  cost  agg_cost
++++++
1  0  6  6  1  0  0
2  1  6  5  1  1  1
3  1  6  10  2  1  1
4  2  6  15  3  1  2
5  2  6  11  5  1  2
6  3  6  16  9  1  3
7  3  6  12  11  1  3
8  1  6  7  4  1  1
9  2  6  3  7  1  2
10  3  6  1  6  1  3
11  2  6  8  10  1  2
12  3  6  9  14  1  3
(12 rows)
Multiple vertices¶
(seq, depth, start_vid, node, edge, cost, agg_cost)
 Example:
The Minimum Spanning Tree starting on vertices \(\{9, 6\}\) with \(distance \leq 3.5\)
SELECT * FROM pgr_primDD(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
ARRAY[9, 6], 3.5);
seq  depth  start_vid  node  edge  cost  agg_cost
++++++
1  0  6  6  1  0  0
2  1  6  5  1  1  1
3  1  6  10  2  1  1
4  2  6  15  3  1  2
5  2  6  11  5  1  2
6  3  6  16  9  1  3
7  3  6  12  11  1  3
8  1  6  7  4  1  1
9  2  6  3  7  1  2
10  3  6  1  6  1  3
11  2  6  8  10  1  2
12  3  6  9  14  1  3
13  0  9  9  1  0  0
14  1  9  8  14  1  1
15  2  9  7  10  1  2
16  3  9  6  4  1  3
17  3  9  3  7  1  3
(17 rows)
Parameters¶
Parameter 
Type 
Description 


Edges SQL as described below. 

Root vid 

Identifier of the root vertex of the tree. 
Root vids 

Array of identifiers of the root vertices.

distance 

Upper limit for the inclusion of a node in the result. 
Where:
 ANYINTEGER:
SMALLINT
,INTEGER
,BIGINT
 ANYNUMERIC:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Inner Queries¶
Edges SQL¶
Column 
Type 
Default 
Description 


ANYINTEGER 
Identifier of the edge. 


ANYINTEGER 
Identifier of the first end point vertex of the edge. 


ANYINTEGER 
Identifier of the second end point vertex of the edge. 


ANYNUMERICAL 
Weight of the edge ( 


ANYNUMERICAL 
1 
Weight of the edge (

Where:
 ANYINTEGER:
SMALLINT
,INTEGER
,BIGINT
 ANYNUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Result columns¶
Returns set of (seq, depth, start_vid, node, edge, cost, agg_cost)
Parameter 
Type 
Description 



Sequential value starting from \(1\). 


Depth of the



Identifier of the root vertex. 


Identifier of 


Identifier of the



Cost to traverse 


Aggregate cost from 
Where:
 ANYINTEGER:
SMALLINT, INTEGER, BIGINT
 ANYNUMERIC:
SMALLINT, INTEGER, BIGINT, REAL, FLOAT, NUMERIC
See Also¶
Indices and tables