route finding in time dependent graphs - nima montazeri and ben earlam @ graphconnect ny 2013
DESCRIPTION
Nima and Ben will share some of the experiences of modelling Manchester’s Metrolink network while building a real-life application – Tramchester.TRANSCRIPT
Route Finding in Time Dependent Graphs
Ben Earlam [@BenEarlam]
Nima Montazeri [@Nimamon]
[Presented By]
[Located]
What are we going to cover?
Introduction
Why Graph?
About The Data
Time Independent Model
Q & ADemo
Time-dependent Model
How it all started?
5 Week tech lab
Experiment &
Learn
Real world problem
Produce working software Small team
Manchester
The Focus…
Travel & Transport (Manchester)Open DataOpen SourceMetrolink System (25 Million Journeys p/a)
Tech: Not Only SQL• Neo4JExperiment with Graph database as way of modeling a travel networkEverything in the Cloud (AWS)
Tram Network
Why Graph database?
3
35
52
2
2
2
Map © Transport for Greater Manchester 2013
Tram Data…
Tabular Data in text file (General Transit Feed Specification)250 Cities publish GTFS data
http://www.gtfs-data-exchange.com/agency/mta-new-york-city-transit/
StopsStop
TimesTrips Calenda
r
Routes
Stop_id Trip_id Service_id
Route_id
Earliest Arrival Time Problem
Earliest Arrival Time (EAT) attempts to find the path through a network from source to destination, such that given a start time T we arrive at the destination at the earliest possible time after T.
Starting point…
A1
A2
B1
B2
3
3
C1
C2
4
4
G2
F2
2
G1
F1
2
[goes_to]
[platform]
[platform]
[goes_to]
7
7
Iterations
1 2
3 4
Time Independent
A C
R1A
R1B
R1C
B
[board]
[Depart]
[Depart]
[goes_to] [goes_to]
3 4
[board]
R2D
D
R2B
[board]
[Depart]
5
[goes_to]
Applying the timetable
Paths Timetable
Invalid Paths Valid Paths
Different Graph at each point in time…
Different Graph at each point in time…
A
B
CD
E
F9:30 AM / Friday
Example: A -> E
Different Graph at each point in time…
A
B
CD
E
F9:30 AM / Saturday
Example: A -> E
Different Graph at each point in time…
Different Graph at each point in time…
A
B
CD
E
F10:00 AM / Saturday
Example: A -> E
Modeling Time
Time Expanded Model • Model temporal events as Nodes –
– Arrivals– Department– Transfers
• Duration as edge weight, use Dijkstra to find EAT
Time Dependent Model• Model temporal data as properties• Model all distinct routes with 2 Node types –
Station Station Route
• Use modified Dijsktra to perform Travel Time Function during traversal
Time Dependent Model
A C
R1A
R1B
R1C
B
[board]
[board]
[Depart]
[Depart]
[goes_to] [goes_to]
3 4
Modeling Time…
A C
R1A
R1B
R1C
B
[board]
[board]
[Depart]
[Depart]
[T1] 09:30
[T2] 09:40[T3] 09:50[T4] 10:10[T5] 10:20[T6] 10:30[T7] 10:40[T8] 10:50[T9] 11:00
[T1] 09:33
[T2] 09:43[T3] 09:53[T4] 10:13[T5] 10:23
[T7] 10:43[T8] 10:53[T9] 11:03
Up to 900 Trams…
300 Nodes100K Relations300K Properties
Modeling Time…
"Time is a dimension in which events can be ordered from the past through the present into the future.” - Wikipedia
Modeling Time…
A C
R1A
R1B
R1C
B
[board]
[board]
[Depart]
[Depart]
[T1] 09:30
[T2] 09:40[T3] 09:50[T4] 10:10[T5] 10:20[T6] 10:30[T7] 10:40[T8] 10:50[T9] 11:00
[T1] 09:33
[T2] 09:43[T3] 09:53[T4] 10:13[T5] 10:23
[T7] 10:43[T8] 10:53[T9] 11:03
10:15
Traversal Framework
Traversal Framework
Evaluator
Branch Selector
Path Expander
Path Expander
The traversal framework use PathExpanders to discover the relationships that should be followed from a particular path to further branches in the traversal.
public class TripPathExpander implements PathExpander<GraphState>
{
public Iterable<Relationship> expand(…) {
}
}
Any Questions?
Follow us on Twitter: @tramchester
Traversal Framework
Declarative Java API
It enables the user to specify a set of constraints that limit
the parts of the graph the traversal is allowed to visit
Can specify which relationship types to follow, and in
which direction (effectively specifying relationship filters)
Can specify a user-defined path evaluator that is triggered
with each node encountered
A nice problem to have…
Example - Time Dependent ModelStop Trip Arr. Dept
.
A 1 12:00
12:01
B 1 12:05
12:05
C 1 12:10
C 2 12:11
12:11
D 2 12:16
C 3 12:20
12:21
D 3 12:26
A
C
R1A
R1B
R1C
B
[board]
[board]
[Depart]
[Depart]
T1 Arr.12:00 Dept.12:01
T1 Arr.12:05 Dept.12:05
[board]
D
R1D [
Depart]
[board]
T2 Arr.12:10 Dept.12:21T3 Arr.12:20 Dept.12:26
Spatial Indexes
C
B
A
D
P