Skip to content

Commit

Permalink
Refactoring, updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
kongra committed Mar 19, 2020
1 parent b57f2f0 commit 5959bcd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 38 deletions.
15 changes: 7 additions & 8 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
[org.clojure/math.numeric-tower "0.0.4"]
[org.apache.commons/commons-lang3 "3.9"]
[org.uncommons.maths/uncommons-maths "1.2.2a"]
[kongra/ch "0.1.18"]

[org.clojure/clojurescript "1.10.520"]]
[kongra/ch "0.1.27"]
[org.clojure/clojurescript "1.10.597"]]

:plugins [[lein-cljsbuild "1.1.7"]]

Expand All @@ -34,12 +33,12 @@

:aliases {"fig:repl" ["trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"]}

:profiles {:repl {:dependencies [[org.clojure/test.check "0.10.0"]]
:plugins [[lein-nodisassemble "0.1.3"]
[cider/cider-nrepl "0.22.3"]]
:profiles {:repl {:dependencies [[org.clojure/test.check "1.0.0"]]
:plugins [[lein-nodisassemble "0.1.3"]
[cider/cider-nrepl "0.25.0-SNAPSHOT"]]

:middleware [lein-nodisassemble.plugin/middleware
cider-nrepl.plugin/middleware]
:middleware [lein-nodisassemble.plugin/middleware
cider-nrepl.plugin/middleware]

:jvm-opts [;; "-Dclojure.compiler.direct-linking=false"
"-XX:+DoEscapeAnalysis"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
;; Copyright (c) 2016-present Konrad Grzanek
;; Created 2016-10-11
(ns clojure.kongra.prelude.search
(:require
[cljc.kongra.ch
:refer [chIfn chBool chSeq chPosLong]]

[clojure.kongra.prelude
:refer [lazyCat]]))
(ns clojure.kongra.prelude.search)

(set! *warn-on-reflection* true)

;; TREE SEARCH ROUTINES FROM BY PAIP, CHAPTER 6.4

;; COMBINERS
(def breadthFirstCombiner concat)
(def lazyBreadthFirstCombiner lazyCat)
(def breadthFirstCombiner concat)
(def lazyBreadthFirstCombiner #(lazy-cat %1 %2))

(def depthFirstCombiner #(concat %2 %1))
(def lazyDepthFirstCombiner #(lazy-cat %2 %1))
(def depthFirstCombiner #(concat %2 %1))
(def lazyDepthFirstCombiner #(lazy-cat %2 %1))

;; TREE-SEARCH
(defn treeSearch
[start goal? adjs comb]
(chIfn goal?)
(chIfn adjs)
(chIfn comb)
(loop [nodes (list start)]
(when (seq nodes)
(let [obj (first nodes)]
(if (chBool (goal? obj))
(if (goal? obj)
obj
(recur (chSeq (comb (chSeq (rest nodes))
(chSeq (adjs obj))))))))))
(recur (comb (rest nodes) (adjs obj))))))))

(defn breadthFirstSearch
[start goal? adjs]
Expand All @@ -44,22 +34,20 @@
;; TREE-SEARCH SEQ
(defn breadthFirstTreeLevels
[start adjs]
(chIfn adjs)
(chSeq (->> (list start)
(iterate #(mapcat adjs %))
(map chSeq)
(take-while seq))))
(->>
(list start)
(iterate #(mapcat adjs %))
(take-while seq)))

(defn breadthFirstTreeSeq
([start adjs]
(chIfn adjs)
(chSeq (apply concat (breadthFirstTreeLevels start adjs))))

([start adjs ^long depth]
(chPosLong depth)
(chSeq (->> (breadthFirstTreeLevels start adjs)
(take depth)
(apply concat)))))
(apply concat (breadthFirstTreeLevels start adjs)))

([start adjs depth]
(->>
(breadthFirstTreeLevels start adjs)
(take depth)
(apply concat))))

;; PERF. TEST
;; (defn evenAdjs
Expand Down

0 comments on commit 5959bcd

Please sign in to comment.