apoc.algo.dijkstraWithDefaultWeight

Procedure APOC Core Deprecated

apoc.algo.dijkstraWithDefaultWeight(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance', 10) YIELD path, weight - run dijkstra with relationship property name as cost function and a default weight if the property does not exist

Signature

apoc.algo.dijkstraWithDefaultWeight(startNode :: NODE?, endNode :: NODE?, relationshipTypesAndDirections :: STRING?, weightPropertyName :: STRING?, defaultWeight :: FLOAT?) :: (path :: PATH?, weight :: FLOAT?)

Input parameters

Name Type Default

startNode

NODE?

null

endNode

NODE?

null

relationshipTypesAndDirections

STRING?

null

weightPropertyName

STRING?

null

defaultWeight

FLOAT?

null

Output parameters

Name Type

path

PATH?

weight

FLOAT?

Usage Examples

The examples in this section are based on the following sample graph:

CREATE
  (a:Loc{name:'A'}),
  (b:Loc{name:'B'}),
  (c:Loc{name:'C'}),
  (d:Loc{name:'D'}),
  (a)-[:ROAD {d:100}]->(d),
  (a)-[:RAIL {d:5}]->(d),
  (a)-[:ROAD {d:'10'}]->(b),
  (b)-[:ROAD {d:20}]->(c),
  (c)-[:ROAD]->(d),
  (a)-[:ROAD {d:20}]->(c);

We can find the shortest path from A to D, by running the following query:

MATCH (from:Loc{name:'A'}), (to:Loc{name:'D'})
CALL apoc.algo.dijkstraWithDefaultWeight(from, to, 'ROAD>', 'd', 10.5)
yield path, weight
RETURN path, weight;
Table 1. Results
path weight

(:Loc {name: "A"})-[:ROAD {d: 20}]→(:Loc {name: "C"})-[:ROAD]→(:Loc {name: "D"})

30.5