Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgr_bdastar doesn't return the same result as pgr_astar #1885

Open
LHBruneton-C2C opened this issue May 11, 2021 · 3 comments
Open

pgr_bdastar doesn't return the same result as pgr_astar #1885

LHBruneton-C2C opened this issue May 11, 2021 · 3 comments

Comments

@LHBruneton-C2C
Copy link

Problem

pgr_bdastar doesn't return the same result as pgr_astar

To Reproduce

Using pgRouting docker image, import the following data:

edge_min_repro.zip

Then run the following queries:

SELECT 
seq, path_seq AS "pathSeq", node, edge, pgr.cost, agg_cost AS "aggCost"
FROM pgr_bdastar('SELECT * FROM edge', 1153548005, 558255664, true) as pgr
ORDER BY seq;

which returns:

1 1 1153548005 54256 0.000379723504336132 0
2 2 558255704 54146 0.000304523536838747 0.000379723504336132
3 3 558255705 54149 0.00138401927422877 0.00068424704117488
4 4 558255703 54142 0.000341445410931827 0.00206826631540365
5 5 558255702 54141 0.00148219733407846 0.00240971172633548
6 6 558255664 -1 0 0.00389190906041394

and

SELECT 
seq, path_seq AS "pathSeq", node, edge, pgr.cost, agg_cost AS "aggCost"
FROM pgr_astar('SELECT * FROM edge', 1153548005, 558255664, true) as pgr
ORDER BY seq;

which returns:

1 1 1153548005 54256 0.00037972350433613237 0
2 2 558255704 54147 0.00027403899672301315 0.00037972350433613237
3 3 1037080644 54145 0.0002883815801048997 0.0006537625010591456
4 4 1037086594 54144 0.0005431804623754474 0.0009421440811640453
5 5 1037074188 54143 0.0003132688487491818 0.0014853245435394926
6 6 558255702 54141 0.001482197334078463 0.0017985933922886744
7 7 558255664 -1 0 0.0032807907263671375

Expectation

Result should be the same, with the same sequence and the same aggCost.

Sample Data

Uploaded above.

Platform/versions

docker images 11-2.5-2.6.2 or 12-3.0-3.1.0 or 13-3.1-3.1.3

@LHBruneton-C2C LHBruneton-C2C added the bug Something isn't working label May 11, 2021
@cvvergara
Copy link
Member

From the pgr_aStar and pgr_bdAstar documentation
They are comparable with dijkstra when you use heuristic 0

0: h(v) = 0 (Use this value to compare with pgr_dijkstra)

Both should give the same result as pgr_dijkstra, and therefore they give the same result between each other.
They are not comparable between each other or with pgr_dijkstra with a different heuristic that I know of.
If you find a publication that proves that they are comparable, would be nice.
Tests about comparison with pgr_dijkstra:
https://github.com/pgRouting/pgrouting/blob/master/pgtap/bdAstar/bdAstar-compare-dijkstra.sql
https://github.com/pgRouting/pgrouting/blob/master/pgtap/astar/astar_ManyToMany-compare-dijkstra.test.sql

Note of the modification the sample data due to the fact that all edges have the same value 1 for cost and that alone can give different results for pgr_dijkstra in different runs. This change assures that no matter the order of the data, all routes have different values and has a unique solution for a shortest path.

UPDATE edge_table SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;

@cvvergara cvvergara added Discussion and removed bug Something isn't working labels Jun 2, 2021
@LHBruneton-C2C
Copy link
Author

Thank you @cvvergara for taking the time to answer me !
Indeed, on reading your asnwer, I found out I had misunderstood the pgr_bdAstar documentation. I still thought this was meant to find the shortest path, whatever graph we feed to it. But it would be more appropriate to say that it will find the shortest path, if the graph is homogeneous. Would you say this is more correct ?
Tank you again, and indeed, this wasn't a bug.

@cvvergara
Copy link
Member

@LHBruneton-C2C
Marked it as a documentation issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants