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

Dijkstra - Family of functions

Proposed

Warning

Proposed functions for next mayor release.

  • They are not officially in the current release.

  • They will likely officially be part of the next mayor release:

    • The functions make use of ANY-INTEGER and ANY-NUMERICAL

    • Name might not change. (But still can)

    • Signature might not change. (But still can)

    • Functionality might not change. (But still can)

    • pgTap tests have being done. But might need more.

    • Documentation might need refinement.

Experimental

Warning

Proposed functions for next mayor release.

  • They are not officially in the current release.

  • They will likely officially be part of the next mayor release:

    • The functions make use of ANY-INTEGER and ANY-NUMERICAL

    • Name might not change. (But still can)

    • Signature might not change. (But still can)

    • Functionality might not change. (But still can)

    • pgTap tests have being done. But might need more.

    • Documentation might need refinement.

The problem definition (Advanced documentation)

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:

  • the set of vertices V

    • V=sourcetargetstartvidendvid

  • the set of edges E

    • E={ {(sourcei,targeti,costi) when cost>=0}if reverse_cost=    {(sourcei,targeti,costi) when cost>=0} {(targeti,sourcei,reverse_costi) when reverse_costi>=0}if reverse_cost

Undirected graph

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

  • the set of vertices V

    • V=sourcetargetstartvvidendvid

  • the set of edges E

    • E={ {(sourcei,targeti,costi) when cost>=0} {(targeti,sourcei,costi) when cost>=0} if reverse_cost=    {(sourcei,targeti,costi) when cost>=0} {(targeti,sourcei,costi) when cost>=0} {(targeti,sourcei,reverse_costi) when reverse_costi>=0)} {(sourcei,targeti,reverse_costi) when reverse_costi>=0)} if reverse_cost

The problem

Given:

  • startvidV a starting vertex

  • endvidV an ending vertex

  • G(V,E)={Gd(V,E) if6 directed=trueGu(V,E) if5 directed=false

Then:

  • π={(path_seqi,nodei,edgei,costi,agg_costi)}

where:
  • path_seqi=i

  • path_seq|π|=|π|

  • 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=1k=1icost(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.

See Also

Indices and tables