Hi,
Thanks for the comment. I took a quick peek at @reefwing source. Actually, I already came accross the Astar implementation he used in FindPath.lua. It was originally written in Lua by a coder named Altair (see reference).
As for comparison, well Jumper wins here, and that is fairly normal. The fact is, Jumper’s Astar implementation uses binary heaps to maintain internally a list of expanded nodes, which results in a huge speedup for the overall process. It also has to do with the way I implemented it, trying to keep it short, clean and reusable (you can see that the astar module is used by the dijkstra module).
Well, indeed, I made a test. ‘Altair’ refers to the star implementation used by @reefwing. See for yourself the output, seems like every single algorithm Jumper implements is faster:
lua -e "io.stdout:setvbuf 'no'" "bench.lua"Generating a grid of : 10 cells x 10 cells…
Memory used to store the grid (10 x 10): 23 kiB
DFS - path length: 33.31 - Time: 0.00 ms
JPS - path length: 32.49 - Time: 0.00 ms
DIJKSTRA - path length: 32.49 - Time: 1.00 ms
BFS - path length: 32.49 - Time: 1.00 ms
ALTAIR - path length: 37.00 - Time: 1.00 ms
ASTAR - path length: 32.49 - Time: 1.00 ms
THETASTAR - path length: 32.31 - Time: 1.00 ms
Generating a grid of : 25 cells x 25 cells…
Memory used to store the grid (25 x 25): 133 kiB
JPS - path length: 275.11 - Time: 2.00 ms
DFS - path length: 275.11 - Time: 3.00 ms
DIJKSTRA - path length: 275.11 - Time: 5.00 ms
BFS - path length: 275.11 - Time: 5.00 ms
ASTAR - path length: 275.11 - Time: 5.00 ms
THETASTAR - path length: 274.93 - Time: 7.00 ms
ALTAIR - path length: 289.00 - Time: 23.00 ms
Generating a grid of : 50 cells x 50 cells…
Memory used to store the grid (50 x 50): 525 kiB
JPS - path length: 1149.05 - Time: 8.00 ms
DFS - path length: 1149.88 - Time: 25.00 ms
BFS - path length: 1149.05 - Time: 27.00 ms
ASTAR - path length: 1149.05 - Time: 30.00 ms
DIJKSTRA - path length: 1149.05 - Time: 33.00 ms
THETASTAR - path length: 1148.88 - Time: 37.00 ms
ALTAIR - path length: 1177.00 - Time: 337.00 ms
Generating a grid of : 100 cells x 100 cells…
Memory used to store the grid (100 x 100): 2080 kiB
JPS - path length: 4892.59 - Time: 33.00 ms
THETASTAR - path length: 4892.19 - Time: 241.00 ms
BFS - path length: 4892.59 - Time: 290.00 ms
DFS - path length: 4932.36 - Time: 290.00 ms
DIJKSTRA - path length: 4892.59 - Time: 309.00 ms
ASTAR - path length: 4892.59 - Time: 317.00 ms
ALTAIR - path length: 4951.00 - Time: 5513.00 ms
Generating a grid of : 128 cells x 128 cells…
Memory used to store the grid (128 x 128): 3342 kiB
JPS - path length: 8054.19 - Time: 53.00 ms
THETASTAR - path length: 8053.79 - Time: 453.00 ms
DFS - path length: 8105.55 - Time: 705.00 ms
BFS - path length: 8054.19 - Time: 726.00 ms
DIJKSTRA - path length: 8054.19 - Time: 731.00 ms
ASTAR - path length: 8054.19 - Time: 735.00 ms
ALTAIR - path length: 8129.00 - Time: 14836.00 ms
Exit code: 0
@brookesi
I would also like to mention a few things.
Using Jumper, your tables do not have to start at 1, not necessarily. They can also start at 0, or -1, Jumper would accomodate with it.
`
– A 10x10 map, indices starting at zero.
local map = {}
for y = 0, 9 do
map[y] = {}
for x = 0, 9 do
map[y] = 0
end
end
local grid = Grid(map) – this is ok
`
Also, when trying to draw the map, you can also use the Grid module iterators. As is, it won’t be much of use, as it seems Corona’s display is kind of reverted, but in the next version of the library, I am planning to provide custom vectors for map iteration, so that one can define how he wants to loop through the map.
Ah oh, would you be interested in writing some Codea demos for Jumper, by the way ?
Thanks reading!