pgr_bdDijkstra - Bi-directional Dijkstra Shortest Path¶
Name¶
pgr_bdDijkstra
- Returns the shortest path using Bidirectional Dijkstra algorithm.
Synopsis¶
This is a bi-directional Dijkstra search algorithm. It searchs from the source toward the distination and at the same time from the destination to the source and terminates whe these to searchs meet in the middle. Returns a set of pgr_costResult (seq, id1, id2, cost) rows, that make up a path.
pgr_costResult[] pgr_bdDijkstra(sql text, source integer, target integer,
directed boolean, has_rcost boolean);
Description¶
sql: | a SQL query, which should return a set of rows with the following columns: SELECT id, source, target, cost [,reverse_cost] FROM edge_table
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
source: |
|
||||||||||
target: |
|
||||||||||
directed: |
|
||||||||||
has_rcost: | if |
Returns set of pgr_costResult[]:
seq: | row sequence |
---|---|
id1: | node ID |
id2: | edge ID (-1 for the last row) |
cost: | cost to traverse from id1 using id2 |
History
- New in version 2.0.0
Examples¶
- Without
reverse_cost
SELECT seq, id1 AS node, id2 AS edge, cost
FROM pgr_bdDijkstra(
'SELECT id, source, target, cost FROM edge_table',
4, 10, false, false
);
seq | node | edge | cost
-----+------+------+------
0 | 4 | 3 | 0
1 | 3 | 5 | 1
2 | 6 | 11 | 1
3 | 11 | 12 | 0
4 | 10 | -1 | 0
(5 rows)
- With
reverse_cost
SELECT seq, id1 AS node, id2 AS edge, cost
FROM pgr_bdDijkstra(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
4, 10, true, true
);
seq | node | edge | cost
-----+------+------+------
0 | 4 | 3 | 1
1 | 3 | 2 | 1
2 | 2 | 4 | 1
3 | 5 | 10 | 1
4 | 10 | -1 | 0
(5 rows)
The queries use the Sample Data network.