Skip to content

Instantly share code, notes, and snippets.

@fffej
Created July 4, 2009 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fffej/140556 to your computer and use it in GitHub Desktop.
Save fffej/140556 to your computer and use it in GitHub Desktop.
(defn beam-search
"Search highest scoring states first until goal is reached"
[start goal? successors cost-fn beam-width]
(tree-search (list start) goal? successors
(fn [old new]
(let [sorted ((sorter cost-fn) old new)]
(if (> beam-width (count sorted))
sorted
(take beam-width sorted))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment