arttuka.astar

https://github.com/arttuka/astar.git

git clone 'https://github.com/arttuka/astar.git'

(ql:quickload :arttuka.astar)
9

astar

Pathfinding using A* algorithm

Releases and Dependency Information

Latest release is [0.2]

Leiningen dependency information:

[astar-search "0.2"]

Maven dependency information:

<dependency>
  <groupId>astar-search</groupId>
  <artifactId>astar-search</artifactId>
  <version>0.1.1</version>
</dependency>

Usage

astar.core/route takes the following parameters:

user=> (def graph {:a [:b :c]
                   :b [:a :d :e]
                   :c [:a :d :e]
                   :d [:b :c :f]
                   :e [:b :c :f]
                   :f [:e :d]})
#'user/graph
user=> (defn dist [from to]
         (let [d {:a {:b 4 :c 2}
                  :b {:a 4 :d 1 :e 1}
                  :c {:a 2 :d 3 :e 5}
                  :d {:b 1 :c 3 :f 3}
                  :e {:b 1 :c 5 :f 2}
                  :f {:d 3 :e 2}}]
           (get-in d [from to])))
#'user/dist
user=> (def h {:a 7
               :b 3
               :c 6
               :d 3
               :e 2
               :f 0})
#'user/h

It returns a list of nodes that form the shortest path from the start node (exclusive) to the goal node (inclusive).

user=> (require 'astar.core)
nil
user=> (astar.core/route graph dist h :a :f)
(:b :e :f)

If a route doesn't exist, it returns nil.