0
votes

I build a graphe this way: the nodes represents: busStops, and the relationship represent the bus line linking bus stops each others.

The relationship type correspond to the time needed to go from a node two another one.

When I'm querying the graph (thanks to cypher) to get the shortestPath between two which are maybe not linked, the result is the one where the number of relations used is the smallest.

I would to change that in order that the shortest path corresponds to the path where the addition of all relationship types used between two nodes(which correspond to the time) is the smallest?

1

1 Answers

8
votes

first, you are doing it wrong. don't use a unique relationship type for each time. use one relationship type and then put a property "time" on all relations.

second, to calculate the addition you can use this cypher formula:

START from=node({busStopId1}), to=node({busStopId2})
MATCH p=from-[:LINE*]-to  //asterix * means any distance
RETURN p,reduce(total = 0, r in relationships(p): total + r.time) as tt
ORDER by tt asc;