Before running any algorithm from the GDS, we need to create a projected graph. At this stage, we need to be very careful about the entities to include in this graph. For shortest path applications, we need Junction nodes, LINKED_TO relationships, and the length of each road segment, stored in the length property of each relationship. However, this property is a String type, which is not compatible with the addition operation we need to do in shortest path algorithms. For this reason, we are going to create the projected graph using Cypher projection in order to cast the length property in the projected graph:
CALL gds.graph.create.cypher(
"road_network",
"MATCH (n:Junction) RETURN id(n) as id",
"MATCH (n)-[r:LINKED_TO]->(m) RETURN id(n) as source, id(m) as target, toInteger(r.length) as length"
)
Now, we can use the shortest path finding algorithm. Since our nodes do have latitude and...