In order to test that the shortest path algorithm has been implemented in the GDS library, we will use the same graph we have been using since the beginning of this chapter. So let's first create our test graph in Neo4j:
CREATE (A:Node {name: "A"})
CREATE (B:Node {name: "B"})
CREATE (C:Node {name: "C"})
CREATE (D:Node {name: "D"})
CREATE (E:Node {name: "E"})
CREATE (A)-[:LINKED_TO {weight: 10}]->(B)
CREATE (A)-[:LINKED_TO {weight: 33}]->(C)
CREATE (A)-[:LINKED_TO {weight: 35}]->(D)
CREATE (B)-[:LINKED_TO {weight: 20}]->(C)
CREATE (C)-[:LINKED_TO {weight: 28}]->(D)
CREATE (C)-[:LINKED_TO {weight: 6 }]->(E)
CREATE (D)-[:LINKED_TO {weight: 40}]->(E)
The resulting graph in Neo4j is illustrated in the following figure:
The procedure to find the shortest path between two nodes is as follows:
gds.alpha.shortestPath.stream(
graphName::STRING,
{
startNode::NODE,
...