Reputation: 105
I have a graph with 2 types of relationships :
T1
represents one way streetsT2
represents two way streets. On neo4j document's advice, I want to avoid creating two relationships for two way streets, because it slows down shortestPath function.
But is there any way to traverse T1
directional and T2
bidirectional in shortestPath
function?
To be noted, I can't use undirected search because of T1
relationships!
Upvotes: 4
Views: 227
Reputation: 7478
With the cypher shortespath
function you can't do it.
So if you want to use this function, you will have to create two relationships for T2
.
But when I see street
and shortestpath
, I assume you are doing some routing algo, and so the shortespath function is perhaps not the most optimized for that.
You should take a look at the graph traversal API if you have a complexe routing algo or to graph algo into APOC (https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_graph_algorithms_work_in_progress) with the AStar
or dijkstraWithDefaultWeight
procedure.
This is an example of the query you are looking for with apoc.algo.dijkstraWithDefaultWeight
algo from APOC :
MATCH (from:Way { id: $idFrom }),
(to:Way { id: $idTo })
WITH from, to
CALL apoc.algo.dijkstraWithDefaultWeight(from, to, 'T1>|T2', 'distance', 1) YIELD path, weight
RETURN path, weight
Upvotes: 2