Bombay Railway Routes
Most people from Bombay have a love-hate relation with trains. While they are still the quickest way to get to almost any place, getting into a train is an entirely different matter. We have beautiful structures such as CST (formerly Victoria Terminus):

and then horrors such as these:

Still, our train system deserves a graph.
Two students from IIT-B put together this nice local train network - https://www.dnaindia.com/mumbai/report-iit-b-students-design-navigable-railway-map-to-ease-commuter-woes-1929123
How to get from one station to another is easy to answer after this network is modeled as a graph.

The graph in this example contains stations on the Western line (pink) from Churchgate to Vasai, Harbour line (green) from Andheri to Wadala and CST to Vashi and a few stations on Central(orange).
Domain
We have four main railway lines- Western, Central, Harbour and Trans Harbour. Each line serves various sections of the city. There are also two minor lines- Vasai Road-Diva and Nerul-Uran line. To travel across sections, one must change lines at various interchange stations (many lines converge here). A couple of lines notably Western and Central operate fast trains that do not stop at every station.

Queries:
Route from Churchgate to Vashi
The shortest path is a fast train on the Western line up to Dadar, and then one switches over to Central line taking a slow up to Kurla, followed by a slow on Harbour line to Vashi.

match (churchgate {name:"Churchgate"}),(vashi {name:"Vashi"}),p=shortestPath((churchgate)-[:NEXT*]->(vashi)) return p
Route from Santa Cruz to Dockyard Road
A slow train from Santa Cruz right up to Dockyard Road on the Harbour line is the shortest path.

match (santacruz {name:"Santa Cruz"}),(dockyard {name:"Dockyard Road"}),p=shortestPath((santacruz)-[:NEXT*]-(dockyard)) return p
Route from Elphinstone to Andheri
From Elphinstone, take a slow train to Dadar on the Western line, then switch over to a fast train on the same line up to Andheri.

match (elphinstone {name:"Elphinstone"}),(andheri {name:"Andheri"}),p=shortestPath((elphinstone)-[:NEXT*]-(andheri)) return p
Route from Elphinstone to Andheri without having to change trains
The query above might be the shortest path, but it involves changing trains, wherein you might face this:

To stay on the same train (without switching lines or train types), the query below correctly advises that one must pick a slow train on Western line from Elphinstone all the to Andheri.
match (elphinstone {name:"Elphinstone"}),(andheri {name:"Andheri"})
with elphinstone, andheri
match p=(elphinstone)-[r:NEXT*..10]-(andheri)
with head(r).type as trainType, head(r).line as railwayLine, p,r
where all(x in r where x.type=trainType) and
all(y in r where y.line=railwayLine)
return p;
Created by Luanne Misquitta:
Is this page helpful?