Top Banner
Shortest Path Search with pgRouting Daniel Kastl
55

Shortest Path search for real road networks with pgRouting

Dec 09, 2014

Download

Technology

Daniel Kastl

pgRouting adds routing functionality to PostGIS. This presentation will show the inside and current state of pgRouting development. We will explain the shortest path search in real road networks and how the data structure is important to get better routing results. Furthermore we will show how you can improve the quality of the search with dynamic costs and make the result look closer to the reality. You will learn about difficulties and limitations of implementing routing functionality in GIS applications, the difference between algorithms and their performance.

pgRouting includes:
- Shortest path search (3 algorithms: Dijkstra, A-Star, Shooting Star)
- Traveling salesperson problem solver (TSP)
- Driving distance calculation
- NEW: Dial-a-ride-problem solver (DARP)
- NEW: All-pair-shortest-path algorithm (APSP)
pgRouting is an extension of PostgreSQL and PostGIS. A predecessor of pgRouting's pgDijkstra, written by Camptocamp, was later extended by Orkney and renamed to pgRouting. The project is now supported by Georepublic and a broad user community.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Shortest Path search for real road networks with pgRouting

Shortest Path Search with pgRouting

Daniel Kastl

Page 2: Shortest Path search for real road networks with pgRouting

What is pgRouting?

Page 3: Shortest Path search for real road networks with pgRouting

An Extension for

PostgreSQL / PostGIS, ...

Page 4: Shortest Path search for real road networks with pgRouting

An Open Source project, ...

Page 5: Shortest Path search for real road networks with pgRouting

A Library providing, ...

Page 6: Shortest Path search for real road networks with pgRouting

Shortest Path

Page 7: Shortest Path search for real road networks with pgRouting

DD and TSP

Page 8: Shortest Path search for real road networks with pgRouting

DARP

Page 9: Shortest Path search for real road networks with pgRouting

@justjkk

@jay_mahadeokar

Page 10: Shortest Path search for real road networks with pgRouting

APSP and TDSP

Page 11: Shortest Path search for real road networks with pgRouting

Multi-Modal

Page 12: Shortest Path search for real road networks with pgRouting

https://github.com/pgRouting/pgrouting

Page 13: Shortest Path search for real road networks with pgRouting

SQL Function

SELECT * FROM shortest_path('

SELECT gid as id,

source::integer,

target::integer,

length::float8 as cost

FROM ways',

605, 359, false, false);

Page 14: Shortest Path search for real road networks with pgRouting

Query Result

vertex_id | edge_id | cost

-----------+---------+--------------------

605 | 599 | 0.19925085940845

604 | 598 | 0.100258103875674

603 | 597 | 0.201123583387407

602 | 596 | 0.204847680679676

601 | 595 | 0.158334540345002

4293 | 9602 | 0.0183273901669081

... | ... | ...

Page 15: Shortest Path search for real road networks with pgRouting

Most users need pgRouting for

Road Networks

How do they look like?

Page 16: Shortest Path search for real road networks with pgRouting

Like this ...

Page 17: Shortest Path search for real road networks with pgRouting

… or like this ...

Page 18: Shortest Path search for real road networks with pgRouting

… or sometimes like this.

Page 19: Shortest Path search for real road networks with pgRouting

What makes them real?

Traffic lights Signs Road marking

Page 20: Shortest Path search for real road networks with pgRouting

How can pgRouting help here?

Page 21: Shortest Path search for real road networks with pgRouting

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

source

target

Page 22: Shortest Path search for real road networks with pgRouting

Traffic lights slow down

… so costs must increase.

Page 23: Shortest Path search for real road networks with pgRouting

A

BC

D

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

1min

Page 24: Shortest Path search for real road networks with pgRouting

Signs inform about

restrictions and rules

Page 25: Shortest Path search for real road networks with pgRouting
Page 26: Shortest Path search for real road networks with pgRouting

cost(A) = length(A)reverse_cost(A) = ∞

A

Page 27: Shortest Path search for real road networks with pgRouting

Sometimes

the costs

have different

meaning.

Page 28: Shortest Path search for real road networks with pgRouting

cost(A)=length(A)/2reverse_cost(A)=length(A)*2

cost(B)=length(B)*3reverse_cost(B)=length(B)/3

A

B

Page 29: Shortest Path search for real road networks with pgRouting

Turn restrictions

obviously

restrict turns.

Page 30: Shortest Path search for real road networks with pgRouting

A

BC

D

cost(A)=cost(A)+1mincost(B)=cost(B)+1mincost(C)=cost(C)+1mincost(D)=cost(D)+1min

1min

A

BC

D

rule(A) = "D"to_cost(A, D) = ∞

Page 31: Shortest Path search for real road networks with pgRouting

Road type

can be used

for cost

calculation.

Page 32: Shortest Path search for real road networks with pgRouting

Not only road types

but also conditions

Page 33: Shortest Path search for real road networks with pgRouting

http://upload.wikimedia.org/wikipedia/commons/e/e4/Jughandle_signage.jpg

Jughandle intersection

Page 34: Shortest Path search for real road networks with pgRouting

@ckrahe

Page 35: Shortest Path search for real road networks with pgRouting

And you know

what is great about pgRouting?

Page 36: Shortest Path search for real road networks with pgRouting

All costs are dynamic!… which is the opposite to pre-calculated

Page 37: Shortest Path search for real road networks with pgRouting

If the road is closed ...

Page 38: Shortest Path search for real road networks with pgRouting

… or there is an accident, ...

Page 39: Shortest Path search for real road networks with pgRouting

… there is a sign with

restrictions limited

to a certain time, ...

Page 40: Shortest Path search for real road networks with pgRouting

… bad weather conditions ...

Page 41: Shortest Path search for real road networks with pgRouting

… or any other obstacle, ...

Page 42: Shortest Path search for real road networks with pgRouting

You don't need to

rebuild and reload

your network

Page 43: Shortest Path search for real road networks with pgRouting

… and wait forever.

Page 44: Shortest Path search for real road networks with pgRouting

You only need to adjust the cost

for this particular road,

and the next search will go another way.

Page 45: Shortest Path search for real road networks with pgRouting

Cost can be virtually anything

Page 46: Shortest Path search for real road networks with pgRouting

OpenStreetMap data

Page 47: Shortest Path search for real road networks with pgRouting

pgRouting can be used for

different kinds of networks

Page 48: Shortest Path search for real road networks with pgRouting

Canals and

Rivers

Page 49: Shortest Path search for real road networks with pgRouting

Hiking trails

Page 50: Shortest Path search for real road networks with pgRouting

… or any other

kind of networks.

Page 51: Shortest Path search for real road networks with pgRouting

pgRouting Demo

http://websi.openvrp.com

http://map.veloland.ch

http://www.ridethecity.com

http://www.pgrouting.org/gallery.html

Page 52: Shortest Path search for real road networks with pgRouting

Plans until FOSS4G 2012

● Integrate new functions● All-Pair-Shortest-Path● Time-Dependent-Shortest-Path● Multi-Modal● Two-way A-Star, ...

● Drop CGAL dependency● PostgreSQL 9.x & PostGIS 2.0 support● Source cleanup

Page 53: Shortest Path search for real road networks with pgRouting

www.pgrouting.org

workshop.pgrouting.org

[email protected]

Page 54: Shortest Path search for real road networks with pgRouting
Page 55: Shortest Path search for real road networks with pgRouting

Photos from sxc.hu and flickr under Creative Commons Licence.