pgr_betweennessCentrality - pgRouting Manual (3.7)
pgr_betweennessCentrality
pgr_betweennessCentrality
- Calculates the relative betweeness centrality
using Brandes Algorithm

Availability
-
Version 3.7.0
-
New experimental function:
-
pgr_betweennessCentrality
-
-
Description
The Brandes Algorithm takes advantage of the sparse graphs for evaluating the betweenness centrality score of all vertices.
Betweenness centrality measures the extent to which a vertex lies on the shortest paths between all other pairs of vertices. Vertices with a high betweenness centrality score may have considerable influence in a network by the virtue of their control over the shortest paths passing between them.
The removal of these vertices will affect the network by disrupting the it, as most of the shortest paths between vertices pass through them.
This implementation work for both directed and undirected graphs.
-
Running time: \(\Theta(VE)\)
-
Running space: \(\Theta(VE)\)
-
Throws when there are no edges in the graph
Signatures
Summary
- Example :
-
For a directed graph with edges \(\{1, 2, 3, 4\}\) .
SELECT * FROM pgr_betweennessCentrality(
'SELECT id, source, target, cost, reverse_cost
FROM edges where id < 5'
) ORDER BY vid;
vid centrality
-----+------------
5 0
6 0.5
7 0
10 0.25
15 0
(5 rows)
Explanation
-
The betweenness centrality are between parenthesis.
-
The leaf vertices have betweenness centrality \(0\) .
-
Betweenness centrality of vertex \(6\) is higher than of vertex \(10\) .
-
Removing vertex \(6\) will create three graph components.
-
Removing vertex \(10\) will create two graph components.
-
![digraph G {
5, 7, 15 [shape=circle;style=filled;width=.5;color=deepskyblue;fontsize=8;fixedsize=true;];
6, 10 [shape=circle;style=filled;width=.5;color=green;fontsize=8;fixedsize=true;];
5 [pos="0,0!";label="5 (0)"];
6 [pos="0,1!"label="6 (0.5)"];
7 [pos="0,2!"label="7 (0)"];
10 [pos="1,1!"label="10 (0.25)"];
15 [pos="2,1!"label="15 (0)"];
5 -> 6 [dir=both;label="1 "];
6->7 [dir=both;label="4 "];
10->6 [label="3"];
15->10 [label="4"];
}](images/graphviz-efca2d7cb27245f77d9726b2cd34bc9ffade4854.png)
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
Edges SQL as described below. |
Optional parameters
Column |
Type |
Default |
Description |
---|---|---|---|
|
|
|
|
Inner Queries
Edges SQL
Column |
Type |
Default |
Description |
---|---|---|---|
|
ANY-INTEGER |
Identifier of the first end point vertex of the edge. |
|
|
ANY-INTEGER |
Identifier of the second end point vertex of the edge. |
|
|
ANY-NUMERICAL |
Weight of the edge (
|
|
|
ANY-NUMERICAL |
-1 |
Weight of the edge (
|
Where:
- ANY-INTEGER :
-
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL :
-
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Result columns
Column |
Type |
Description |
---|---|---|
|
|
Identifier of the vertex. |
|
|
Relative betweenness centrality score of the vertex (will be in range [0,1]) |
See Also
-
Boost’s betweenness_centrality
-
Queries use the Sample Data network.
Indices and tables