[pgrouting-users] Why does shooting star return the last segment twice?

Stephen Woodbridge woodbri at swoodbridge.com
Fri May 8 14:40:27 EDT 2009


Anton,

Does this also explain why the starting segment is NOT returned?
Notice below that the route request is from 11213 to 11218 and 11213 is 
missing from the results and 11218 is duplicated. Does this indicate 
some weird off by one issue?

It would be nice this this were fixed in the underlying code as it is 
hard to detect and repair after the route is complete.

Thanks,
   -Steve


Anton Patrushev wrote:
> Hi Steve,
> 
> This is known issue and it also might also happen with first edge.
> It happens because we have two edges for both way streets. For
> example, we start (or end) with the edge which is both way streets.
> For Shooting* I need to create two edges for both directions with
> unique ids (original id for one direction and original id + max id for
> reverse direction).
> 
>    id
> -------------------->
> <-------------------
>   id+max_id
> 
> So, from the function interface we always get original id for both
> start and end. And it might happen that the particular id for one or
> both of them is an id for the reverse direction, so it passes the edge
> twice - forth and back.
> 
> When result is returned, function reduces all ids higher than max_id
> to give you original ids. Thus instead of sequence, for example, id ->
> id+max_id you have id -> id.
> 
> Probably it is worth to add a check to the core Shooting* function
> which forms an output sequence (and I actually thought I did it
> already). I need to check the source code.
> 
> Anton.
> 
> 
> On Fri, May 8, 2009 at 12:07 AM, Stephen Woodbridge
> <woodbri at swoodbridge.com> wrote:
>> Any idea why shooting_star would return the last segment twice???
>>
>> -Steve
>>
>>
>> routing=# SELECT gid, the_geom
>> routing-#                     FROM shooting_star_sp_cd(
>> routing(#                         'st',
>> routing(#                         11213,
>> routing(#                         11218,
>> routing(#                         0.0724637681159,
>> routing(#                         'cost_time',
>> routing(#                         'rcost_time',
>> routing(#                         false);
>>   gid  |
>>     the_geom
>> -------+----------------------------------------------------------------------------------------------------------------------------------------------
>>  11212 |
>> 0105000020E610000001000000010200000003000000A83BA88CC54B5140782922711A44414058048149C74B51403832B9011F444140B8ECA0B9CF4B5140D84BD5C734444140
>>  33942 |
>> 0105000020E610000001000000010200000002000000F82D2A95B54B514008144FD950444140B8ECA0B9CF4B5140D84BD5C734444140
>>  11217 |
>> 0105000020E610000001000000010200000002000000E06B2FD39E4B514090B0354869444140F82D2A95B54B514008144FD950444140
>>  11218 |
>> 0105000020E610000001000000010200000002000000E8004137864B514068B4ABB383444140E06B2FD39E4B514090B0354869444140
>>  11218 |
>> 0105000020E610000001000000010200000002000000E8004137864B514068B4ABB383444140E06B2FD39E4B514090B0354869444140
>> (5 rows)
>>
>>
>> shooting_star_sp_cd() function is just a straight wrapper around your
>> standard function.
>>
>>
>> CREATE OR REPLACE FUNCTION shooting_star_sp_cd(
>>     geom_table varchar, sourceid int4, targetid int4, delta float8,
>>     cost_column varchar, rcost_column varchar, dir boolean)
>>     RETURNS SETOF GEOMS AS
>> $$
>> DECLARE
>>         path_result record;
>>         geom geoms;
>>     query text;
>>     id integer;
>>
>> BEGIN
>>     query := generic_sp_query('shortest_path_shooting_star', geom_table,
>>         sourceid, targetid, delta, cost_column, rcost_column, dir);
>>
>>     id :=0;
>>     FOR path_result IN EXECUTE query
>>         LOOP
>>
>>                  geom.gid      := path_result.gid;
>>                  geom.the_geom := path_result.the_geom;
>>          id := id+1;
>>          geom.id       := id;
>>
>>                  RETURN NEXT geom;
>>
>>         END LOOP;
>>         RETURN;
>> END;
>> $$
>> LANGUAGE 'plpgsql' VOLATILE STRICT;
>> _______________________________________________
>> Pgrouting-users mailing list
>> Pgrouting-users at lists.postlbs.org
>> http://lists.postlbs.org/mailman/listinfo/pgrouting-users
>>
> 
> _______________________________________________
> Pgrouting-users mailing list
> Pgrouting-users at lists.postlbs.org
> http://lists.postlbs.org/mailman/listinfo/pgrouting-users




More information about the Pgrouting-users mailing list