ensure successfully functioning of simulate! with one propagator
This commit is contained in:
parent
d97bcfa82c
commit
02d2a56931
1 changed files with 31 additions and 9 deletions
|
@ -3,7 +3,6 @@
|
||||||
[prop-net.cell :as c]))
|
[prop-net.cell :as c]))
|
||||||
|
|
||||||
;; currently not implementing abort semantics
|
;; currently not implementing abort semantics
|
||||||
|
|
||||||
(defn- alerted-propagators* [] #{})
|
(defn- alerted-propagators* [] #{})
|
||||||
(defn- cells* [] {})
|
(defn- cells* [] {})
|
||||||
(defn- propagators-ever-alerted* [] #{})
|
(defn- propagators-ever-alerted* [] #{})
|
||||||
|
@ -53,8 +52,6 @@
|
||||||
|
|
||||||
(defn- deref-get [rec key] (deref (key rec)))
|
(defn- deref-get [rec key] (deref (key rec)))
|
||||||
|
|
||||||
;; TODO re-implementing with reference to PropNet
|
|
||||||
;; children should not make calls on each other, only return things to do?
|
|
||||||
(defrecord PropNet
|
(defrecord PropNet
|
||||||
[alerted-propagators
|
[alerted-propagators
|
||||||
last-value-of-run
|
last-value-of-run
|
||||||
|
@ -72,8 +69,8 @@
|
||||||
(cell-key (get-cells net)))
|
(cell-key (get-cells net)))
|
||||||
(cell-content [net cell-key] (deref-get (get-cell net cell-key)
|
(cell-content [net cell-key] (deref-get (get-cell net cell-key)
|
||||||
:content))
|
:content))
|
||||||
(propagator [net prop-key] (deref-get (propagators net)
|
(propagator [net prop-key] (prop-key (propagators net)))
|
||||||
prop-key))
|
|
||||||
;; mutation methods
|
;; mutation methods
|
||||||
(add-cell! [net cell-key]
|
(add-cell! [net cell-key]
|
||||||
(swap! (:cells net) assoc cell-key (c/make-cell))
|
(swap! (:cells net) assoc cell-key (c/make-cell))
|
||||||
|
@ -92,9 +89,23 @@
|
||||||
{:cell cur-cell})))
|
{:cell cur-cell})))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(prn e)))))
|
(prn e)))))
|
||||||
;; (add-propagator! [this prop-key func])
|
(add-propagator! [this prop-key func]
|
||||||
;; (add-neighbor-to-cell! [this cell-key propagator])
|
(swap! (:all-propagators this) assoc prop-key (p/function->propagator func)))
|
||||||
;; (add-output-to-propagator! [this prop-key cell])
|
(add-neighbor-to-cell! [this cell-key prop-key]
|
||||||
|
;; cell only needs to have its neighbors
|
||||||
|
;; c/new-neighbor! prop-key
|
||||||
|
(c/new-neighbor! (get-cell this cell-key) prop-key)
|
||||||
|
;; propagator needs to have the c/content wrapped in a lambda and have that added to its inputs
|
||||||
|
(p/add-input! (propagator this prop-key) (fn [] (c/content (get-cell this cell-key))))
|
||||||
|
:ok
|
||||||
|
)
|
||||||
|
(add-output-to-propagator! [this prop-key cell-key]
|
||||||
|
(let [output-setter
|
||||||
|
;; need to add content from the net in order to alert propagators
|
||||||
|
;; further down the network
|
||||||
|
(fn [new-content] (add-content-to-cell! this cell-key new-content))]
|
||||||
|
(p/add-output! (propagator this prop-key)
|
||||||
|
output-setter)))
|
||||||
|
|
||||||
;; run methods
|
;; run methods
|
||||||
(last-value-of-run [net] (deref-get net :last-value-of-run))
|
(last-value-of-run [net] (deref-get net :last-value-of-run))
|
||||||
|
@ -103,9 +114,14 @@
|
||||||
(reset! (:last-value-of-run this) done)
|
(reset! (:last-value-of-run this) done)
|
||||||
(reset! (:propagators-ever-alerted this) propagators-ever-alerted*)
|
(reset! (:propagators-ever-alerted this) propagators-ever-alerted*)
|
||||||
:ok)
|
:ok)
|
||||||
;; (simulate! [net])
|
(simulate! [net]
|
||||||
|
(run! (fn [prop-key]
|
||||||
|
(do (swap! (:alerted-propagators net) disj prop-key)
|
||||||
|
(p/apply! (propagator net prop-key))))
|
||||||
|
(vec (get-alerted-propagators net))))
|
||||||
;; (halt! [net])
|
;; (halt! [net])
|
||||||
)
|
)
|
||||||
|
|
||||||
;; returns a propnet
|
;; returns a propnet
|
||||||
(defn make-prop-net []
|
(defn make-prop-net []
|
||||||
(map->PropNet
|
(map->PropNet
|
||||||
|
@ -126,7 +142,13 @@
|
||||||
(add-cell! this-net :5)
|
(add-cell! this-net :5)
|
||||||
(add-cell! this-net :c*9)
|
(add-cell! this-net :c*9)
|
||||||
(add-cell! this-net :9)
|
(add-cell! this-net :9)
|
||||||
|
(add-cell! this-net :32+5)
|
||||||
|
(add-propagator! this-net :plusser +)
|
||||||
|
(add-neighbor-to-cell! this-net :32 :plusser)
|
||||||
(add-content-to-cell! this-net :32 32)
|
(add-content-to-cell! this-net :32 32)
|
||||||
|
(add-neighbor-to-cell! this-net :5 :plusser)
|
||||||
|
(add-content-to-cell! this-net :5 5)
|
||||||
|
(add-output-to-propagator! this-net :plusser :32+5)
|
||||||
this-net))
|
this-net))
|
||||||
|
|
||||||
(defn -main []
|
(defn -main []
|
||||||
|
|
Loading…
Reference in a new issue