[PgRouting 1.02] Shooting star - usage example with turn restriction
Par david techer, jeudi 24 juillet 2008 à 15:17 :: PostGIS et PostgreSQL :: #349 :: rss
This is my favorite function in PgRouting
. Here we will see an example. For more info, please see http://pgrouting.postlbs.org/wiki/ShootingStar
Let's suppose that we have the following network with two roundabouts as shown in the following picture. The SQL file used here is available at http://www.davidgis.fr/download/pgrouting_wr.sql 

The network
routing=# SELECT gid as id, source, target, cost, reverse_cost,x1, y1,x2, y2, rule, to_cost FROM wr order by id; id | source | target | cost | reverse_cost | x1 | y1 | x2 | y2 | rule | to_cost ----+--------+--------+------------------+------------------+------------------+-------------------+------------------+-------------------+------+--------- 1 | 1 | 2 | 14.2572101668807 | 1000 | 76.7176891326003 | 33.775246780918 | 87.3962905382969 | 43.2217018705726 | | 2 | 2 | 3 | 11.0893168443772 | 1000 | 87.3962905382969 | 43.2217018705726 | 87.3962905382969 | 54.3110187149498 | | 3 | 3 | 4 | 13.9884637834871 | 1000 | 87.3962905382969 | 54.3110187149498 | 76.7176891326003 | 63.3467583659239 | | 4 | 4 | 5 | 14.2572101668807 | 1000 | 76.7176891326003 | 63.3467583659239 | 67.2712340429456 | 52.6681569602273 | | 5 | 5 | 6 | 10.6864968606796 | 1000 | 67.2712340429456 | 52.6681569602273 | 66.860518604265 | 41.9895555545307 | | 6 | 6 | 1 | 12.8311604873812 | 1000 | 66.860518604265 | 41.9895555545307 | 76.7176891326003 | 33.775246780918 | | 7 | 7 | 1 | 53.8753258085636 | 53.8753258085636 | 80 | -20 | 76.7176891326003 | 33.775246780918 | | 8 | 8 | 4 | 62.5380849791951 | 62.5380849791951 | 73.0212501844746 | 125.775505045381 | 76.7176891326003 | 63.3467583659239 | | 9 | 7 | 9 | 40 | 40 | 80 | -20 | 120 | -20 | | 10 | 9 | 10 | 33.4201752293529 | 33.4201752293529 | 120 | -20 | 141.610728444141 | -45.4928328844451 | | 11 | 9 | 11 | 60 | 60 | 120 | -20 | 180 | -20 | | 12 | 11 | 12 | 25.9044654619518 | 25.9044654619518 | 180 | -20 | 180.217979680121 | -45.9035483231257 | | 13 | 12 | 10 | 38.6094358307609 | 38.6094358307609 | 180.217979680121 | -45.9035483231257 | 141.610728444141 | -45.4928328844451 | | 14 | 13 | 12 | 29.5829181472758 | 29.5829181472758 | 181.039410557482 | -75.4750599081316 | 180.217979680121 | -45.9035483231257 | | 15 | 13 | 14 | 39.4286821133412 | 39.4286821133412 | 181.039410557482 | -75.4750599081316 | 141.610728444141 | -75.4750599081316 | | 16 | 14 | 10 | 29.9822270236865 | 29.9822270236865 | 141.610728444141 | -75.4750599081316 | 141.610728444141 | -45.4928328844451 | | 17 | 15 | 13 | 39.2224758594282 | 39.2224758594282 | 220 | -80 | 181.039410557482 | -75.4750599081316 | | 18 | 15 | 16 | 38.0005743220152 | 1000 | 220 | -80 | 251.682466010552 | -79.1714988562574 | | 19 | 16 | 15 | 38.0539027874633 | 1000 | 251.682466010552 | -79.1714988562574 | 220 | -80 | | 20 | 17 | 16 | 48.3246366252935 | 48.3246366252935 | 300 | -80 | 251.682466010552 | -79.1714988562574 | | 21 | 11 | 18 | 115.27849852631 | 115.27849852631 | 180 | -20 | 295.218302510699 | -23.7249146343713 | | 22 | 18 | 17 | 56.4778705670458 | 56.4778705670458 | 295.218302510699 | -23.7249146343713 | 300 | -80 | | (22 rows)
I. Roundabouts
We have two roundabouts. First done with (1,2,3,4,5,6) and secund done with (18,19). So that is the reason why reverse_cost is enough expensive: reverse_cost=1000
routing=# SELECT * FROM shortest_path_shooting_star('SELECT gid as id, source, target, cost, reverse_cost,x1, y1,x2, y2, rule, to_cost FROM wr order by id',20,8,true,true);
vertex_id | edge_id | cost
-----------+---------+------------------
31 | 20 | 48.3246366252935
29 | 19 | 38.0539027874633
27 | 17 | 39.2224758594282
23 | 14 | 29.5829181472758
21 | 13 | 38.6094358307609
17 | 10 | 33.4201752293529
15 | 9 | 40
12 | 7 | 53.8753258085636
1 | 1 | 14.2572101668807
2 | 2 | 11.0893168443772
4 | 3 | 13.9884637834871
6 | 8 | 62.5380849791951
(12 rows)
We have

Shortest path using shooting star from edge=20 to 8
II. Turn restrictions
Let's suppose now that we have following restrictions:
- from edge from 17 to 14 ;
- from edge from 16 to 10;

Restricted edges: You can't go from 17 to 14 and from 16 to 10
So we have to do
routing=# update wr set to_cost=100,rule='17' where gid=14; UPDATE 1 routing=# update wr set to_cost=100,rule='16' where gid=10;So we have
routing=# SELECT edge_id FROM shortest_path_shooting_star('SELECT gid as id, source, target, cost, reverse_cost,x1, y1,x2, y2, rule, to_cost FROM wr order by id',20,8,true,true);
edge_id
---------
20
19
17
15
16
13
12
11
9
7
1
2
3
8
(14 rows)
Beautifull...
The final result is

Shortest path from edge=20 to 8
Commentaires
Aucun commentaire pour le moment.
Ajouter un commentaire