Created
July 7, 2009 19:35
-
-
Save fffej/142305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn new-states | |
"Generate successor states that have not been seen before." | |
[states successors state-eq old-states] | |
(remove | |
(fn [state] | |
(or (some (partial state-eq state) old-states) | |
(some (partial state-eq state) states))) | |
(successors (first states)))) | |
(defn graph-search | |
"Find a state that statisfies goal?. Start with states and search | |
according to successors and combiner. Don't repeat same state twice" | |
([states goal? successors combiner] | |
(graph-search states goal? successors combiner = #{})) | |
([states goal? successors combiner old-states] | |
(graph-search states goal? successors combiner = old-states)) | |
([states goal? successors combiner state-eq old-states] | |
(dbg :search "Search: %s" states) | |
(cond | |
(empty? states) nil | |
(goal? (first states)) (first states) | |
:else (recur | |
(combiner (new-states states successors state-eq old-states) | |
(rest states)) | |
goal? successors combiner state-eq | |
(conj old-states (first states)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment