A* search: optimized implementation in Lisp
gitlab.com
gitlab.com
It's quite a bit faster than my Lisp version, at least, though mine's an unoptimized (lots of lists) incompletely ported C++ version. Tempted to dig out the C++ version and compare since it was pretty fast... I originally ported it to make a joke about a vtuber's long neck: https://pbs.twimg.com/media/FAJQkskVQAoiGlT?format=png&name=... (Edit: screenshot from C++ version: https://www.thejach.com/imgs/visibility_with_astar.png Note how the shorter path would be going through the central chamber, but visibility is high there, so it goes down the corridors. Original had lots of extra features like fog of war, visibility tests/terrain analysis, smoothing and rubber-banding, a Floyd-Warshall implementation...)
I implemented A* in Common Lisp for my Springer Verlag AI book (1998), so a bit of nostalgia for me.
SBCL is really an amazing ecosystem and I argue that it is a great example of the power of open source.
> This implementation of A* running on SBCL outperforms even C++ implementations, at least the ones for which I was able to find performance numbers (1, 2). You can have a look at impressively sleek assembly produced by SBCL for FIND-PATH function here.
Beating similar C++ implementations in performance seems at least a bit noteworthy, as C/C++ is often held as the language(s) to chose for best performance.
1 - Is an innefficient and obfuscated BFS. It has no heuristics. (The lisp benchmark is using Manhattan distance. You can think of it as comparing walking blindfolded on a maze vs having a GPS that tells you how far you are from the exit)
2 - Is a person claiming numbers on a specific instance of a problem that was tested, without showing any code or details on what heuristics were used
This is pretty uncharitable. One of the "answers" is just a link to the authors research paper. Not like it's just something they quickly threw together for some SO post.
It is a bit strange that they link to the SO post and not the paper though.
There is significant legal risk if your juniors are pasting non-trivial code from SO into your codebase verbatim...
I imagine this could be done with C++ templates as well, I’ve just never used them myself.
But this gives the compiler ample opportunities to optimize, since the code is specific to the desired domain. It also hides a bunch of the clutter that typically accompanies optimized Common Lisp code with all of the declares, declaims, and type specifiers.
However I am also on for some Lisp love.