Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

30
Route Finding in Time Dependent Graphs Ben Earlam [@BenEarlam] Nima Montazeri [@Nimamon] [Presented By] [Located]

description

Nima and Ben will share some of the experiences of modelling Manchester’s Metrolink network while building a real-life application – Tramchester.

Transcript of Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Page 1: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Route Finding in Time Dependent Graphs

Ben Earlam [@BenEarlam]

Nima Montazeri [@Nimamon]

[Presented By]

[Located]

Page 2: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

What are we going to cover?

Introduction

Why Graph?

About The Data

Time Independent Model

Q & ADemo

Time-dependent Model

Page 3: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

How it all started?

5 Week tech lab

Experiment &

Learn

Real world problem

Produce working software Small team

Page 4: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Manchester

Page 5: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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)

Page 6: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Tram Network

Page 7: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Why Graph database?

3

35

52

2

2

2

Map © Transport for Greater Manchester 2013

Page 8: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 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

Page 9: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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.

Page 10: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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

Page 11: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Iterations

1 2

3 4

Page 12: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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]

Page 13: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Applying the timetable

Paths Timetable

Invalid Paths Valid Paths

Page 14: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Different Graph at each point in time…

Page 15: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Different Graph at each point in time…

A

B

CD

E

F9:30 AM / Friday

Example: A -> E

Page 16: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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…

Page 17: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Different Graph at each point in time…

A

B

CD

E

F10:00 AM / Saturday

Example: A -> E

Page 18: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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

Page 19: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Time Dependent Model

A C

R1A

R1B

R1C

B

[board]

[board]

[Depart]

[Depart]

[goes_to] [goes_to]

3 4

Page 20: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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

Page 21: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Modeling Time…

"Time is a dimension in which events can be ordered from the past through the present into the future.” - Wikipedia

Page 22: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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

Page 23: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Traversal Framework

Traversal Framework

Evaluator

Branch Selector

Path Expander

Page 24: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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(…) {

}

}

Page 25: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

The App

• http://www.tramchester.co.uk/

Page 26: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Any Questions?

Follow us on Twitter: @tramchester

Page 27: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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

Page 28: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

A nice problem to have…

Page 29: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

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

Page 30: Route Finding in Time Dependent Graphs - Nima Montazeri and Ben Earlam @ GraphConnect NY 2013

Spatial Indexes

C

B

A

D

P