Transcript
Page 1: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Shortest Path Search with pgRouting

Daniel Kastl

Page 2: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

What is pgRouting ?

Page 3: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

An Extension for

PostgreSQL / PostGIS, ...

Page 4: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

An Open Source

project, ...

Page 5: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

A Library providing, ...

Page 6: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Shortest Path

Page 7: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Driving Distance

Page 8: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Traveling Salesperson

Page 9: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

v2.0

Page 10: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Feature Highlights

➔ Two new All Pairs Short Path algorithms

➔ Bi-directional Dijkstra and A-star algorithms

➔ One to many nodes shortest path search

➔ New TSP solver (with distance matrix)

➔ Turn Restricted shortest path (replaces Shooting

Star algorithm)

➔ A collection of useful utility and graph analytics

functions

Page 11: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

More Highlights

➔ Modular library design

➔ Unit tests and automated tests with Travis

➔ Compatibility with PostgreSQL 9.1+ / PostGIS 2.0+

➔ Installs as PostgreSQL EXTENSION

➔ Added pgr_ prefix to functions and types

➔ Improved build process for Windows

➔ Better documentation in several languages

https://www.transifex.com/projects/p/pgrouting/

Page 12: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Most users need pgRouting for

Road Networks

How do they look like?

Page 13: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Like this ...

Page 14: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

… or like this ...

Page 15: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

… or sometimes like this.

Page 16: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

What makes them real?

Traffic lights Signs Road marking

Page 17: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

pgRouting extends

PostgreSQL/PostGIS

CREATE EXTENSION postgis;CREATE EXTENSION pgrouting;

Page 18: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

SQL Function

SELECT * FROM pgr_dijkstra(' SELECT gid as id, source::integer, target::integer, length::float8 as cost FROM ways', 30, 60, false, false);

Page 19: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Query Result

seq | node | edge | cost -----+------+------+--------------------- 0 | 30 | 53 | 0.0591267653820616 1 | 44 | 52 | 0.0665408320949312 2 | 14 | 15 | 0.0809556879332114 3 | 13 | 14 | 0.072694271986776 4 | 12 | 13 | 0.081239348480584 5 | 11 | 12 | 0.00746935522787469 6 | 10 | 6869 | 0.0164274192597773 7 | 59 | 72 | 0.0109385169537801 8 | 60 | -1 | 0(9 rows)

Page 20: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

gid,source,target,cost,reverse_cost,x1, y1,x2, y2,rule, to_cost

source

target

Page 21: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Traffic lights slow down

… so costs must increase.

Page 22: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

1 min

cost(A) = cost(A) + 30seccost(B) = cost(B) + 30seccost(C) = cost(C) + 30seccost(D) = cost(D) + 30sec

B C

D

A

Page 23: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014
Page 24: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

cost(A) = length(A)

reverse_cost(A) = ∞

A

Page 25: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Sometimes

the costs

have different

meaning.

Page 26: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

A

B

cost(A) = length(A) / 2

reverse_cost(A) = length(A) * 4

Page 27: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Road type can be used

for cost calculation.

Page 28: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Not only road types

but also conditions

Page 29: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

And you know

what is great about pgRouting?

Page 30: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

All costs are dynamic!

… which is the opposite to pre-calculated

Page 31: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

If the road is closed ...

Page 32: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

… or there is an accident, ...

Page 33: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

… there is a sign with restrictions limited to a certain time, ...

Page 34: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

… bad weather conditions ...

Page 35: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

You don't need to

rebuild and reload

your network

Page 36: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

You only need to adjust the cost

for this particular road,

… and the next search will go another way.

Page 37: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Flexiblity vs. Speed

Page 38: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Cost can be virtually

anything

Page 39: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

pgRouting can be used for

different kinds of networks

Page 40: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Canals and Rivers

Page 41: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Hiking trails

Page 42: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

… or any other kind of networks

Page 43: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

pgRouting can be enhanced

with custom functions

Page 44: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

SELECT * FROM ctg_drivingdistance( ST_SetSRID( ST_MakePoint(-117.1078764,32.7111995),4326), 'ways', '2500,5000,7500', 'm');

Page 45: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Roadmap for Version 2.1

➔ Add “Multi-modal public transit routing”

(GSoC 2011)

➔ Add “Time dependent shortest path” algorithm

(GSoC 2011)

➔ Add “Two Queue” Algorithm (GSoC 2012)

➔ Add DARP and VRP (GSoC 2013 and 2014)

➔ Add Graph network partitioning (GSoC 2013)

➔ …. further improvements and bug fixes.

Page 46: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Tour Optimization & VRP

Page 47: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

https://github.com/pgRouting

Page 48: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Website: pgrouting.org

Documentation: docs.pgrouting.org

Workshop: workshop.pgrouting.org

Support: pgrouting.org/support.html

More Information

… or talk contact us directly:

[email protected]

➔ Twitter: @dkastl

Page 49: Shortest Path search in your Database and more with pgRouting - FOSS4G Europe 2014

Photos from sxc.hu and

flickr under Creative Commons Licence.