Hi Ratul,

>From your link, I picked up the nodes that have relationships and analysed. 
Here is my recommendation to achieve your goals.

1. I selected two routes: 9 and 23. Here is the Cypher script that I used:

CREATE (bus:Routes {name: "Routes"})

CREATE (route:RtNbr {id: 9})
CREATE (route2:RtNbr {id: 23})

CREATE (bus)-[:ROUTES]->(route)
CREATE (bus)-[:ROUTES]->(route2)

MERGE (stop20: StopID {id:20})
MERGE (stop21: StopID {id:21})
MERGE (stop109: StopID {id:109})
MERGE (stop111: StopID {id:111})
MERGE (stop48: StopID {id:48})

MERGE (stop113: StopID {id:113})
MERGE (stop110: StopID {id:110})

MERGE (route2)-[:START]->(stop20)
MERGE (stop20)-[:TO]->(stop110)
MERGE (stop110)-[:TO]->(stop111)
MERGE (stop111)-[:TO]->(stop48)


MERGE (route)-[:START]->(stop20)
MERGE (stop20)-[:TO]->(stop21)
MERGE (stop21)-[:TO]->(stop109)
MERGE (stop109)-[:TO]->(stop111)
MERGE (stop111)-[:TO]->(stop48)
MERGE (stop48)-[:TO]->(stop113)
; 

<https://lh3.googleusercontent.com/-MpIKYYLxYuQ/WUA81JrPBiI/AAAAAAAACO0/3SGgOYSqhFUMbYmNhB4E4wCIKAp0WQaewCLcB/s1600/Screen%2BShot%2B06-13-17%2Bat%2B12.15%2BPM.PNG>
2. Shortest path between stop id = 20 and stop id = 38:

MATCH (origin:StopID {id: 20}), (destination:StopID {id: 48}),
path = allShortestPaths((origin)-[:TO*]->(destination))
RETURN path;

<https://lh3.googleusercontent.com/-We6oe0FM0U0/WUA9OLM16hI/AAAAAAAACO4/Y4EiocxIJ0MXysRNa-oiokKGGKTkAUfVgCLcB/s1600/Screen%2BShot%2B06-13-17%2Bat%2B12.22%2BPM.PNG>

Hope this will help you.
Thanks,
-Kamal


On Tuesday, June 13, 2017 at 12:23:34 AM UTC-7, Ratul Jain wrote:
>
> Hi, I am working on a project dealing with bus routes and I’m using neo4j 
> to retrive indirect routes between two stops. I modelled it in a way in 
> which I was creating a ‘Route’ relationship for all the routes between two 
> stops. This was okay at first but then I reached a point where I had 
> at-least 10 relationships between any two given nodes and that led to most 
> of the queries getting timed out.
>
> So to reduce the number of relationships between two nodes, I am 
> maintaining the routes between two stops as an array relationship property. 
>  
>
> My question is how can I query the DB in such a way that I get that route 
> which requires the lest number of bus changes. Can I implement something 
> like backtracking to achieve this?
>
> I have set up a neo4j instance with some dummy data. Here’s the link to it 
> - http://207.154.231.108:7474/browser/ 
>
> The query I’m using to find the shortest distance between two nodes.
>
>
>
>
>
> MATCH (origin:Stop {name: "Petraro"}), (destination:Stop {name: "Rossano 
> Scalo - Torre Pisani"}),
> path = allShortestPaths((origin)-[:Route*]->(destination))
> RETURN path
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to