[pgrouting-users] Problem with way restrictions in shooting star if you have more then one rule for an edge

Hi

Thanks for providing the shooting star algorithm.
I am using your shooting star code. The only difference
is that I use a sqlite3 DB instead of postgres. So I only
"adapted" the code of fetching the data from DB to use
the sqlite3 API. The rest of the code is as it is in the
git repository at the moment.

The routing works find in general I only have problems
using certain "types" of turn restrictions. In special
as soon as there is more then one rule for an edge

It seems that it only "respects" the first rule for
turn restrictions and always ignore the other ones.

I correctly provide the "same" edge for every rule and AFAIKT
adjacent_edges is correctly filled with all the rules for this edge.
After that I am "lost" how the "boost" algorithm actually works
and at which point the information from adjacent_edges is used
during routing.

I also tried the same "osm data" with the "original" code
from a postgres DB and the result is the same

An example where it happens is here
routing from http://www.openstreetmap.org/browse/way/34849107
to http://www.openstreetmap.org/browse/way/96379178

As you can see it is not allowed to go "straight" on
still shooting star returns exactly this route

way http://www.openstreetmap.org/browse/way/96379178 has two rules with
to_cost > 100000

from http://www.openstreetmap.org/browse/way/96379173 (only straight on)
and as a second one
from http://www.openstreetmap.org/browse/way/34849107 (only styraight
on)but the second one seems to be ignored and thefore choosen for the route

The correct routing would be to go right to the next roundabout
and back which definitly has a lower cost.

So maybe you can give me some hints how I can debug where the
rules are "evaluated" to see if my "assumptions" are correct

Regards

max

Hi Max,

The bad news:

There are bugs in v1.03 and v1.05 for the shooting star algorithm to the extent that it is pretty much broken at the moment. In addition to that the developer that was working on it has moved on is no longer supporting it. While I was testing this, I found out that the code is also running 3-5 times slower than Dijkstra when we thought it should be running faster, so we are not sure if this is symptomatic of the bugs or just that the algorithm is slower.

The good news:

If you need to support multiple turn restrictions as just developed and added an new branch to git:
   https://github.com/pgRouting/pgrouting/tree/trsp
Sorry there is no doc for this yet, but it works and is only marginally slow than Dijkstra.

The big differences at the moment between trsp and shooting star are:
1. trsp is a Dijkstra style solver based on nodes and shooting star is an edged based solver
2. trsp takes a second query string to load the restrictions rather than loading the edge multiple times with different rules
3. The order of the edges in the rules are reversed in the via_path for trsp vs shooting* rules. See the trsp_rest table below. So for example:

target_id: 27
via_path : 1,3,4,5
rule : 5,4,3,1

This might get changed before we release it officially to so both of these are consistent.

As soon as we can get someone to look at the shooting star code we will, but given that we have a faster algorithm already, I could see us potentially drop support for that in the future. Although we have not even discussed that at the PSC or with the user community yet.

Thanks,
   -Steve

Here are some examples of how I have used this:

nav11=# \d trsp_rest
           Table "data.trsp_rest"
   Column | Type | Modifiers
-----------+------------------+-----------
  to_cost | double precision |
  target_id | integer |
  via_path | text |
  the_geom | geometry |
  rule | text |
Indexes:
     "trsp_rest_gidx" gist (the_geom)

I also just extended it to be useful with shooting_path.

to_cost - is the turn cost and the same for shooting_star and for trsp
target_id - is the target edge id where this rule applies
via_path - restriction path for trsp (edge ids)
rule - restriction path for shooting_star (edge ids)
the_geom - this is the_geom of the target_id for bbox searches

How can these be used?

For the trsp we would generate a query like:

SELECT count(*) FROM turn_restrict_shortest_path(
   'select edges',
   start_node_id,
   end_node_id,
   directed,
   has_reverse_cost,
   'select restrictions');

And here is a real query that will work in nav11

SELECT count(*) FROM turn_restrict_shortest_path(
   'SELECT link_id as id, source::integer, target::integer, cost_time::double precision as cost,
           x1::double precision, y1::double precision, x2::double precision, y2::double precision ,
           rcost_time as reverse_cost
      FROM st
     WHERE setSRID(''BOX3D(-0.208393768115942 51.4715162318841 -0.072463768115942,0.063713768115942 51.6644037681159 0.072463768115942)''::BOX3D,
           4326) && the_geom',
    '67230',
    '214167',
    'true',
    'select to_cost, target_id, via_path
       from trsp_rest
      where setSRID(''BOX3D(-0.208393768115942 51.4715162318841 -0.072463768115942,0.063713768115942 51.6644037681159 0.072463768115942)''::BOX3D,
            4326) && the_geom' ), st
   where edge_id = link_id;

Here is a basic shooting_star query without restrictions:

SELECT count(*) FROM shortest_path_shooting_star(
     'SELECT gid as id, source::integer, target::integer, cost_time::double precision as cost,
             x1::double precision, y1::double precision, x2::double precision, y2::double precision,
             rule::varchar, to_cost::double precision , rcost_time as reverse_cost
        FROM st
       WHERE setSRID(''BOX3D(-0.208393768115942 51.4715162318841 -0.072463768115942,0.063713768115942 51.6653837681159 0.072463768115942)''::BOX3D,
             4326) && the_geom', '1423847' , '2183259' , 'true', 'true' ), st where edge_id = gid;

Which follow this schema:

SELECT count(*) FROM shortest_path_shooting_star(
   'select edges',
   start_node_id,
   end_node_id,
   directed,
   has_reverse_cost);

And expects the rules and to_cost to be passed with the edges and if there are multiple rules
then the same edge gets passed multiple times. So we can join the edges with the restriction
table as follows:

SELECT gid as id,
        source::integer,
        target::integer,
        cost_time::double precision as cost,
        x1::double precision,
        y1::double precision,
        x2::double precision,
        y2::double precision,
        b.rule::varchar,
        b.to_cost::double precision,
        rcost_time as reverse_cost
   FROM st a left outer join trsp_rest b on a.link_id=b.target_id
  WHERE setSRID('BOX3D(-0.208393768115942 51.4715162318841 -0.072463768115942,0.063713768115942 51.6653837681159 0.072463768115942)'::BOX3D, 4326) && a.the_geom;

And the same embedded in the shooting_star query:

SELECT count(*) FROM shortest_path_shooting_star(
     'SELECT gid as id, source::integer, target::integer, cost_time::double precision as cost,
             x1::double precision, y1::double precision, x2::double precision, y2::double precision,
             b.rule::varchar, b.to_cost::double precision, rcost_time as reverse_cost
        FROM st a left outer join trsp_rest b on a.link_id=b.target_id
       WHERE setSRID(''BOX3D(-0.208393768115942 51.4715162318841 -0.072463768115942,0.063713768115942 51.6653837681159 0.072463768115942)''::BOX3D,
             4326) && a.the_geom', '1423847' , '2183259' , 'true', 'true' ),st where edge_id = gid;

On 1/11/2012 10:11 AM, Max Weninger wrote:

Hi

Thanks for providing the shooting star algorithm.
I am using your shooting star code. The only difference
is that I use a sqlite3 DB instead of postgres. So I only
"adapted" the code of fetching the data from DB to use
the sqlite3 API. The rest of the code is as it is in the
git repository at the moment.

The routing works find in general I only have problems
using certain "types" of turn restrictions. In special
as soon as there is more then one rule for an edge

It seems that it only "respects" the first rule for
turn restrictions and always ignore the other ones.

I correctly provide the "same" edge for every rule and AFAIKT
adjacent_edges is correctly filled with all the rules for this edge.
After that I am "lost" how the "boost" algorithm actually works
and at which point the information from adjacent_edges is used
during routing.

I also tried the same "osm data" with the "original" code
from a postgres DB and the result is the same

An example where it happens is here
routing from http://www.openstreetmap.org/browse/way/34849107
to http://www.openstreetmap.org/browse/way/96379178

As you can see it is not allowed to go "straight" on
still shooting star returns exactly this route

way http://www.openstreetmap.org/browse/way/96379178 has two rules with
to_cost> 100000

from http://www.openstreetmap.org/browse/way/96379173 (only straight on)
and as a second one
from http://www.openstreetmap.org/browse/way/34849107 (only styraight
on)but the second one seems to be ignored and thefore choosen for the route

The correct routing would be to go right to the next roundabout
and back which definitly has a lower cost.

So maybe you can give me some hints how I can debug where the
rules are "evaluated" to see if my "assumptions" are correct

Regards

max
_______________________________________________
Pgrouting-users mailing list
Pgrouting-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users

Hi

Thanks for your replay

I just confirmed that the "order" is indeed the problem
by creating a "hacked" version that changes the order "on the fly" :slight_smile:

I will take a look at the "new" code asap :slight_smile:

BTW: just about "speed". I tried some different graph based
routing "solutions" now. By far the fastest was one based on the
igraph package. http://igraph.sourceforge.net/index.html

The problem is that it is "just" a "static" Dijkstra
without any support for turn restrictions which is
definitly a "must" for me as the "final" goal

Regards

max

On Wed, 11 Jan 2012 10:52:54 -0500
Stephen Woodbridge <woodbri@swoodbridge.com> wrote:
...

The good news:

If you need to support multiple turn restrictions as just developed
and added an new branch to git:
   https://github.com/pgRouting/pgrouting/tree/trsp
Sorry there is no doc for this yet, but it works and is only
marginally slow than Dijkstra.

...

On 1/11/2012 11:06 AM, Max Weninger wrote:

Hi

Thanks for your replay

I just confirmed that the "order" is indeed the problem
by creating a "hacked" version that changes the order "on the fly" :slight_smile:

What are you referring to with respect to "order"?
The order of the edge_ids in the rules? or something else?

Regarding shooting star, there are definitely bugs in the current code so I would recommend that people test their use cases before relying on it or just avoid it until we can sort our what the issues are.

I will take a look at the "new" code asap :slight_smile:

BTW: just about "speed". I tried some different graph based
routing "solutions" now. By far the fastest was one based on the
igraph package. http://igraph.sourceforge.net/index.html

Thanks, I will look at this. I'm always interested in what other people are doing for routing.

The problem is that it is "just" a "static" Dijkstra
without any support for turn restrictions which is
definitly a "must" for me as the "final" goal

This is exactly why the new code was developed. It is going into a production web site that is targeted at routing for trucks and trucks typically have more restrictions the cars because of things like low bridges, weight restrictions, width restrictions, low maneuverability areas, tight turns, legal restrictions, etc, etc.

Also the trsp code is Boost free so it might be a little easier to follow how it works if you plan to dig into the guts of it. :wink:

Regards,
   -Steve

Regards

max

On Wed, 11 Jan 2012 10:52:54 -0500
Stephen Woodbridge<woodbri@swoodbridge.com> wrote:
...

The good news:

If you need to support multiple turn restrictions as just developed
and added an new branch to git:
    https://github.com/pgRouting/pgrouting/tree/trsp
Sorry there is no doc for this yet, but it works and is only
marginally slow than Dijkstra.

...

_______________________________________________
Pgrouting-users mailing list
Pgrouting-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users

Hi

On Wed, 11 Jan 2012 11:28:38 -0500
Stephen Woodbridge <woodbri@swoodbridge.com> wrote:

On 1/11/2012 11:06 AM, Max Weninger wrote:
> Hi
>
> Thanks for your replay
>
> I just confirmed that the "order" is indeed the problem
> by creating a "hacked" version that changes the order "on the
> fly" :slight_smile:

What are you referring to with respect to "order"?
The order of the edge_ids in the rules? or something else?

Yes the order of the rules as they are stored in adjacent_edges
in the shooting_star_boost_wrapper.cpp file based on the DB entries

It always respects only the first edge entry.
Doing an "internal" revert made my "example" work correctly but
now others will fail (that worked before) of course.

I tried to "understand" the C++ code of the "boost part" but the
last time I used C++ is definitely too far away and I always "hated"
using it :slight_smile:

But I am pretty sure that the problem is somewehre in the relax method
of shooting_star_relax.hpp since there it iterates over the rule
entries (around line 99)

Regards

max

Regarding shooting star, there are definitely bugs in the current
code so I would recommend that people test their use cases before
relying on it or just avoid it until we can sort our what the issues
are.

> I will take a look at the "new" code asap :slight_smile:
>
> BTW: just about "speed". I tried some different graph based
> routing "solutions" now. By far the fastest was one based on the
> igraph package. http://igraph.sourceforge.net/index.html

Thanks, I will look at this. I'm always interested in what other
people are doing for routing.

> The problem is that it is "just" a "static" Dijkstra
> without any support for turn restrictions which is
> definitly a "must" for me as the "final" goal

This is exactly why the new code was developed. It is going into a
production web site that is targeted at routing for trucks and trucks
typically have more restrictions the cars because of things like low
bridges, weight restrictions, width restrictions, low maneuverability
areas, tight turns, legal restrictions, etc, etc.

Also the trsp code is Boost free so it might be a little easier to
follow how it works if you plan to dig into the guts of it. :wink:

Regards,
   -Steve

> Regards
>
> max
>
> On Wed, 11 Jan 2012 10:52:54 -0500
> Stephen Woodbridge<woodbri@swoodbridge.com> wrote:
> ...
>> The good news:
>>
>> If you need to support multiple turn restrictions as just developed
>> and added an new branch to git:
>> https://github.com/pgRouting/pgrouting/tree/trsp
>> Sorry there is no doc for this yet, but it works and is only
>> marginally slow than Dijkstra.
>>
> ...
>
> _______________________________________________
> Pgrouting-users mailing list
> Pgrouting-users@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/pgrouting-users

_______________________________________________
Pgrouting-users mailing list
Pgrouting-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users

Hi

Tried the new trsp code and it looks good :slight_smile:
I havent tried complex turn restrictions though

But just a quick question:
Is it normal that it always returns -1 as the last edge id?

regards

max
On Wed, 11 Jan 2012 11:28:38 -0500
Stephen Woodbridge <woodbri@swoodbridge.com> wrote:

> I will take a look at the "new" code asap :slight_smile:

Hi again

It does not only look good - its perfect :slight_smile:
All my turn restriction "testcases" work as expected
and give the correct routing.

Thanks a lot for the work and if you need some help
e.g for testing just give me a note.

Regards

max

On Thu, 12 Jan 2012 02:02:48 +0100
Max Weninger <max.weninger@gmail.com> wrote:

Hi

Tried the new trsp code and it looks good :slight_smile:
I havent tried complex turn restrictions though

But just a quick question:
Is it normal that it always returns -1 as the last edge id?

regards

max
On Wed, 11 Jan 2012 11:28:38 -0500
Stephen Woodbridge <woodbri@swoodbridge.com> wrote:
> > I will take a look at the "new" code asap :slight_smile:

Max,

Great! we have tested this pretty extensively but we also appreciate you testing and feedback. One area that we need to get better at is setting up a standard testing framework that we can apply before releases to verify that we have not broken any code. We have discussed the need for this, but not the details of how to do it yet.

My thinking is along the lines of we create a database of graphs, test cases, expected results and have a test runner that runs the test stores the results in a table and reports the results.

An alternative to this would be to create a collection of files that each represent some series of tests like the above, and can be loaded run evaluated, and dropped. This might be easier to manage that one huge file.

It would be easy to automate the running of the tests using a Perl or Python script to run each test in sequence and summarize the results.

I also think that it is probably a good idea for the developers to create unit tests so that they can verify their code before it is wrapped into postgres so we can separate algorithm issues from integration or changes in the postgresql API that might break stuff.

Anyway if you have good simple test cases, I would love to get them and if you are interested in support pgRouting buy helping build some of the above, I would be happy to work on designing something that is easy to build and and maintain.

Thanks for the report.

OH and yes the last edge is always -1, but I forget the rationale for why at the moment.

-Steve

On 1/11/2012 8:13 PM, Max Weninger wrote:

Hi again

It does not only look good - its perfect :slight_smile:
All my turn restriction "testcases" work as expected
and give the correct routing.

Thanks a lot for the work and if you need some help
e.g for testing just give me a note.

Regards

max

On Thu, 12 Jan 2012 02:02:48 +0100
Max Weninger<max.weninger@gmail.com> wrote:

Hi

Tried the new trsp code and it looks good :slight_smile:
I havent tried complex turn restrictions though

But just a quick question:
Is it normal that it always returns -1 as the last edge id?

regards

max
On Wed, 11 Jan 2012 11:28:38 -0500
Stephen Woodbridge<woodbri@swoodbridge.com> wrote:

I will take a look at the "new" code asap :slight_smile:

_______________________________________________
Pgrouting-users mailing list
Pgrouting-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users

Hi

Just FYI:
Since I use the trsp algorithm in my "self-made" car
navigation system I have "tweaked" it a little bit
to speed up the perfomance.

And I can say the trsp is really fast :slight_smile:

Most of the time is "spent" during creating the graph
for the djikstra after fetching the contents from the DB
which is done always. So to speed up I "moved" that part of
the code to be done only if the bounding box has changed
since the last "calculation". Otherwise the data is kept
in memory.

Just some numbers (my machine is not really fast :):
I have an "edge" table with 1648921 entries (in a sqlite3 DB
with libspatialite extension)
Calculating a route with a result of 720 edges (bounding box reduced the
edges to 99254) takes about 10 seconds with DB access and building
the graph. And about 1-2 seconds without :slight_smile: DB access is not really the
important factor here. Building the graph takes most of the time.

This "modification" allows real "on-the-fly" route recalculation during
driving which "typically" is not changing the bounding box.

So again thanks for your work in providing the trsp algorithm :slight_smile:

Regards

max

On Wed, 11 Jan 2012 20:48:32 -0500
Stephen Woodbridge <woodbri@swoodbridge.com> wrote:

Max,

Great! we have tested this pretty extensively but we also appreciate
you testing and feedback. One area that we need to get better at is
setting up a standard testing framework that we can apply before
releases to verify that we have not broken any code. We have
discussed the need for this, but not the details of how to do it yet.

My thinking is along the lines of we create a database of graphs,
test cases, expected results and have a test runner that runs the
test stores the results in a table and reports the results.

An alternative to this would be to create a collection of files that
each represent some series of tests like the above, and can be loaded
run evaluated, and dropped. This might be easier to manage that one
huge file.

It would be easy to automate the running of the tests using a Perl or
Python script to run each test in sequence and summarize the results.

I also think that it is probably a good idea for the developers to
create unit tests so that they can verify their code before it is
wrapped into postgres so we can separate algorithm issues from
integration or changes in the postgresql API that might break stuff.

Anyway if you have good simple test cases, I would love to get them
and if you are interested in support pgRouting buy helping build some
of the above, I would be happy to work on designing something that is
easy to build and and maintain.

Thanks for the report.

OH and yes the last edge is always -1, but I forget the rationale for
why at the moment.

-Steve

On 1/11/2012 8:13 PM, Max Weninger wrote:
> Hi again
>
> It does not only look good - its perfect :slight_smile:
> All my turn restriction "testcases" work as expected
> and give the correct routing.
>
> Thanks a lot for the work and if you need some help
> e.g for testing just give me a note.
>
> Regards
>
> max
>
> On Thu, 12 Jan 2012 02:02:48 +0100
> Max Weninger<max.weninger@gmail.com> wrote:
>
>> Hi
>>
>> Tried the new trsp code and it looks good :slight_smile:
>> I havent tried complex turn restrictions though
>>
>> But just a quick question:
>> Is it normal that it always returns -1 as the last edge id?
>>
>> regards
>>
>> max
>> On Wed, 11 Jan 2012 11:28:38 -0500
>> Stephen Woodbridge<woodbri@swoodbridge.com> wrote:
>>>> I will take a look at the "new" code asap :slight_smile:
>>
>>
>
> _______________________________________________
> Pgrouting-users mailing list
> Pgrouting-users@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/pgrouting-users

_______________________________________________
Pgrouting-users mailing list
Pgrouting-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users