orientechnologies / orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
https://orientdb.dev
Apache License 2.0
4.72k stars 870 forks source link

A* SQL function returns paths of increasing length for consecutive, identical queries #7103

Closed martineutinger closed 7 years ago

martineutinger commented 7 years ago

OrientDB Version, operating system, or hardware.

Operating System

Expected behavior and actual behavior

When sending the same query (e.g. 'SELECT astar(#23:19965, #23:19187, 'length')') more than once, only the first result is correct. The consecutive results are longer and longer paths until it seems to either plateau or return no path at all.

So e.g. the shortest path contains 5 nodes. The first query would return the 5 nodes. The second would return 10. Then 17. And then it returns 21 for every query past that point.

Steps to reproduce the problem

Possible solutions

The problem seems to be, that in com.orientechnologies.orient.graph.sql.functions.OSQLFunctionAstar 'PriorityQueue open' and 'Set closedSet' are carried over from the last execution of the algorithm. It seems like ... ... either .clear() should be called for 'open' and 'closedSet' before each execution ... or a new instance of OSQLFunctionAstar should be created, every time the function is executed.

Misc

This is not the case with Dijkstra's algorithm, because a new instance of A* is created each time.

saeedtabrizi commented 7 years ago

Hi @martineutinger , @luigidellaquila
yes i detect some bugs in the astar function too (null checking and etc ) . i check it asap .

luigidellaquila commented 7 years ago

Thank you @saeedtabrizi, I'll check it as well

Thanks!

Luigi

saeedtabrizi commented 7 years ago

Hi @martineutinger , @luigidellaquila I fix some bugs (reported bug) and more test to astar function now . i will push it asap .

luigidellaquila commented 7 years ago

Great, thank you very much @saeedtabrizi !

Looking forward to the pr!

Thanks

Luigi

saeedtabrizi commented 7 years ago

@luigidellaquila the bugs fixed now .

martineutinger commented 7 years ago

Thank you @saeedtabrizi.

So does that mean the single-astar-instance-per-server is by design?

saeedtabrizi commented 7 years ago

Dear @martineutinger , Short answer is Yes in the current version . but i planned to add and implement some useful and more efficient path finding functions like the Block A , Hybrid A , CH , CRP for OrientDB asap . As we know path-finding algorithms is so useful to Robotic , Intelligence Traffic Management, Routing for the smart vehicle systems and some similar applications.

screenshot from 2017-01-28 12-47-17

I'm glad if i hear from @lvca , @luigidellaquila and i create an issue for proposal path-finding .

lvca commented 7 years ago

+100!

luigidellaquila commented 7 years ago

Hi @martineutinger

I just pushed a fix for this. Thank you very much @saeedtabrizi for the contribution!

Luigi

saeedtabrizi commented 7 years ago

@luigidellaquila Thanks to solve the root of problem .

santo-it commented 7 years ago

Noted in the Release Notes