! Copyright (C) 2010 Samuel Tardieu.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs heaps kernel math sequences sets shuffle ;
+USING: accessors assocs hash-sets heaps kernel math sequences sets shuffle ;
IN: astar
! This implements the A* algorithm. See http://en.wikipedia.org/wiki/A*
(add-to-open-set) ;
: ?add-to-open-set ( node astar -- )
- 2dup astar>> in-closed-set>> key? [ 2drop ] [ add-to-open-set ] if ;
+ 2dup astar>> in-closed-set>> in? [ 2drop ] [ add-to-open-set ] if ;
: move-to-closed-set ( node astar -- )
- [ astar>> in-closed-set>> conjoin ] [ in-open-set>> delete-at ] 2bi ;
+ [ astar>> in-closed-set>> adjoin ] [ in-open-set>> delete-at ] 2bi ;
: get-first ( astar -- node )
[ open-set>> heap-pop drop dup ] [ move-to-closed-set ] bi ;
: (init) ( from to astar -- )
swap >>goal
H{ } clone over astar>> (>>g)
- H{ } clone over astar>> (>>in-closed-set)
+ { } <hash-set> over astar>> (>>in-closed-set)
H{ } clone >>origin
H{ } clone >>in-open-set
<min-heap> >>open-set
astar-simple new swap >>heuristic swap >>cost swap >>neighbours ;
: considered ( astar -- considered )
- in-closed-set>> keys ;
+ in-closed-set>> members ;