Closed Adevar8091 closed 5 years ago
By default we don't return the path, you can include it by doing this:
MATCH (start:Loc{name:'A'}), (end:Loc{name:'F'})
CALL algo.kShortestPaths.stream(start, end, 3, 'cost' ,{path: true})
YIELD index, nodeIds, path, costs
RETURN path,[node in algo.getNodesById(nodeIds) | node.name] AS places,
costs,
reduce(acc = 0.0, cost in costs | acc + cost) AS totalCost
@knutwalker,
I was expecting to see value of Path is not NULL if relationship ROAD has attribute called "routeName" with value route1, route2, route3, etc... like shown below in the query. The streaming results still returning null for "Path" , It's returning value, only costs, nodeIds and Indexes. Can you please tell me what needs to be done to get the value of "path" which is needed for my requirement, circuit connects two equipment (Nodes), in which case need to know the name (Property) of the circuit (relationship).
Here is how i have modified your example with routeName added to ROAD relationship
MERGE (a:Loc {name:'A'}) MERGE (b:Loc {name:'B'}) MERGE (c:Loc {name:'C'}) MERGE (d:Loc {name:'D'}) MERGE (e:Loc {name:'E'}) MERGE (f:Loc {name:'F'})
MERGE (a)-[:ROAD {cost:50,routename:'route1'}]->(b) MERGE (a)-[:ROAD {cost:50,routename:'route2'}]->(c) MERGE (a)-[:ROAD {cost:100,routename:'route3'}]->(d) MERGE (b)-[:ROAD {cost:40,routename:'route4'}]->(d) MERGE (c)-[:ROAD {cost:40,routename:'route5'}]->(d) MERGE (c)-[:ROAD {cost:80,routename:'route6'}]->(e) MERGE (d)-[:ROAD {cost:30,routename:'route7'}]->(e) MERGE (d)-[:ROAD {cost:80,routename:'route8'}]->(f) MERGE (e)-[:ROAD {cost:40,routename:'route9'}]->(f);
Query
MATCH (start:Loc{name:'A'}), (end:Loc{name:'F'}) CALL algo.kShortestPaths.stream(start, end, 3, 'cost' ,{})
YIELD index, nodeIds, path, costs RETURN path,[node in algo.getNodesById(nodeIds) | node.name] AS places, costs, reduce(acc = 0.0, cost in costs | acc + cost) AS totalCost
Expected Result
Path as route1,route4,route7,route9 for Places ["A", "B", "D", "E", "F"]
But the Value of path returned as NULL.
Let me know if i am missing anything else to get the path value from streaming results