pgr_floydWarshall
 Returns the sum of the costs of the shortest path for each
pair of nodes in the graph using FloydWarshall algorithm.
Availability: 2.0.0
The FloydWarshall algorithm, also known as Floyd’s algorithm, is a good choice to calculate the sum of the costs of the shortest path for each pair of nodes in the graph, for dense graphs. We use Boost’s implementation which runs in \(\Theta(V^3)\) time,
pgr_floydWarshall(edges_sql)
pgr floydWarshall(edges_sql, directed)
RETURNS SET OF (start_vid, end_vid, agg_cost) or EMPTY SET
pgr_floydWarshall(edges_sql)
RETURNS SET OF (start_vid, end_vid, agg_cost) or EMPTY SET
Example 1:  On a directed graph. 

SELECT * FROM pgr_floydWarshall(
'SELECT id, source, target, cost FROM edge_table where id < 5'
);
start_vid  end_vid  agg_cost
++
1  2  1
1  5  2
2  5  1
(3 rows)
pgr_floydWarshall(edges_sql, directed)
RETURNS SET OF (start_vid, end_vid, agg_cost) or EMPTY SET
Example 2:  On an undirected graph. 

SELECT * FROM pgr_floydWarshall(
'SELECT id, source, target, cost FROM edge_table where id < 5',
false
);
start_vid  end_vid  agg_cost
++
1  2  1
1  5  2
2  1  1
2  5  1
5  1  2
5  2  1
(6 rows)
edges_sql:  an SQL query, which should return a set of rows with the following columns: 

Column  Type  Default  Description 

source  ANYINTEGER 
Identifier of the first end point vertex of the edge.  
target  ANYINTEGER 
Identifier of the second end point vertex of the edge.  
cost  ANYNUMERICAL 
Weight of the edge (source, target)


reverse_cost  ANYNUMERICAL 
1  Weight of the edge (target, source),

Where:
ANYINTEGER:  SMALLINT, INTEGER, BIGINT 

ANYNUMERICAL:  SMALLINT, INTEGER, BIGINT, REAL, FLOAT 
Receives (edges_sql, directed)
Parameter  Type  Description 

edges_sql  TEXT 
SQL query as described above. 
directed  BOOLEAN 
(optional) Default is true (is directed). When set to false the graph is considered as Undirected 
Returns set of (start_vid, end_vid, agg_cost)
Column  Type  Description 

start_vid  BIGINT 
Identifier of the starting vertex. 
end_vid  BIGINT 
Identifier of the ending vertex. 
agg_cost  FLOAT 
Total cost from start_vid to end_vid . 
History
Indices and tables