Processing math: 100%

pgRouting Manual (2.2)

pgr_dijkstra - Shortest Path Dijkstra

«  pgr_bdDijkstra - Bi-directional Dijkstra Shortest Path   ::   Contents   ::   pgr_dijkstra  »


Supported versions: latest (3.8) 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0 main dev
Unsupported versions:2.6 2.5 2.4 2.3 2.2

pgr_dijkstra - Shortest Path Dijkstra

The problem definition

Given the following query:

pgr_dijkstra(sql,startvid,endvid,directed)

where sql={(idi,sourcei,targeti,costi,reverse_costi)}

and

  • source=sourcei,
  • target=targeti,

The graphs are defined as follows:

Directed graph

The weighted directed graph, Gd(V,E), is definied by:

Undirected graph

The weighted undirected graph, Gu(V,E), is definied by:

The problem

Given:

  • startvidV a starting vertex
  • endvidV an ending vertex
  • G(V,E)={Gd(V,E) if directed=trueGu(V,E) if directed=false

Then:

pgr_dijkstra(sql,startvid,endvid,directed)={shortest path π between startvidand endvidif πotherwise

\boldsymbol{\pi} = \{(path_\seq_i, node_i, edge_i, cost_i, agg\_cost_i)\}

where:
  • path_\seq_i = i
  • path_\seq_{| \pi |} = | \pi |
  • nodeiV
  • node1=startvid
  • node|π|=endvid
  • i|π|,(nodei,nodei+1,costi)E
  • edgei={id(nodei,nodei+1,costi)when i|π|1when i=|π|
  • costi=cost(nodei,nodei+1)
  • agg_costi={0when i=1ik=1cost(nodek1,nodek)when i1
In other words: The algorithm returns a the shortest path between startvid and endvid , if it exists, in terms of a sequence of nodes and of edges,
  • path\seq indicates the relative position in the path of the node or edge.
  • cost is the cost of the edge to be used to go to the next node.
  • agg_cost is the cost from the startvid up to the node.

If there is no path, the resulting set is empty.

«  pgr_bdDijkstra - Bi-directional Dijkstra Shortest Path   ::   Contents   ::   pgr_dijkstra  »