networks, generic: Add dds-step.
This commit is contained in:
parent
598904fecd
commit
8c92a4bbd8
3 changed files with 24 additions and 5 deletions
18
generic.rkt
18
generic.rkt
|
@ -11,11 +11,25 @@
|
||||||
;; Generics
|
;; Generics
|
||||||
gen:dds
|
gen:dds
|
||||||
;; Functions
|
;; Functions
|
||||||
(contract-out [dds-step-one (-> dds? any/c (set/c any/c))])
|
(contract-out [dds-step-one (-> dds? any/c (set/c any/c))]
|
||||||
|
[dds-step (-> dds? (set/c any/c) (set/c any/c))])
|
||||||
;; Predicates
|
;; Predicates
|
||||||
(contract-out [dds? (-> any/c boolean?)]))
|
(contract-out [dds? (-> any/c boolean?)]))
|
||||||
|
|
||||||
|
;;; Given a dds and a set of starting states, produce the set of
|
||||||
|
;;; states reachable in one step. This is a fallback for dds-step.
|
||||||
|
(define (fallback-dds-step dds ss)
|
||||||
|
(list->set (flatten (for/list ([s ss]) (dds-step-one dds s)))))
|
||||||
|
|
||||||
;;; A discrete dynamical system.
|
;;; A discrete dynamical system.
|
||||||
(define-generics dds
|
(define-generics dds
|
||||||
;; Given a dds and a state, produce the next states of the dds.
|
;; Given a dds and a state, produce the next states of the dds.
|
||||||
(dds-step-one dds state))
|
(dds-step-one dds state)
|
||||||
|
;; Given a dds and a set of starting states, produce the set of
|
||||||
|
;; states reachable in one step. This method falls back to running
|
||||||
|
;; dds-step-one for all states.
|
||||||
|
(dds-step dds states)
|
||||||
|
|
||||||
|
#:defined-predicate dds-implements?
|
||||||
|
#:fallbacks
|
||||||
|
[(define dds-step fallback-dds-step)])
|
||||||
|
|
|
@ -114,4 +114,8 @@
|
||||||
[s (st '((a . #t) (b . #f)))])
|
[s (st '((a . #t) (b . #f)))])
|
||||||
(check-equal? (dds-step-one asyn s) (set (st '((a . #f) (b . #f)))
|
(check-equal? (dds-step-one asyn s) (set (st '((a . #f) (b . #f)))
|
||||||
(st '((a . #t) (b . #f)))))
|
(st '((a . #t) (b . #f)))))
|
||||||
(check-equal? (dds-step-one syn s) (set (st '((a . #f) (b . #f)))))))
|
(check-equal? (dds-step-one syn s) (set (st '((a . #f) (b . #f)))))
|
||||||
|
(check-equal? (dds-step asyn (set (st '((a . #t) (b . #t)))
|
||||||
|
(st '((a . #f) (b . #t)))))
|
||||||
|
(set (st '((a . #f) (b . #t)))
|
||||||
|
(st '((a . #t) (b . #t)))))))
|
||||||
|
|
|
@ -36,7 +36,8 @@
|
||||||
[make-dynamics-from-func (-> network? (-> (listof variable?) mode?) dynamics?)]
|
[make-dynamics-from-func (-> network? (-> (listof variable?) mode?) dynamics?)]
|
||||||
[make-asyn-dynamics (-> network? dynamics?)]
|
[make-asyn-dynamics (-> network? dynamics?)]
|
||||||
[make-syn-dynamics (-> network? dynamics?)]
|
[make-syn-dynamics (-> network? dynamics?)]
|
||||||
[dds-step-one (-> dynamics? state? (set/c state?))])
|
[dds-step-one (-> dynamics? state? (set/c state?))]
|
||||||
|
[dds-step (-> dynamics? (set/c state?) (set/c state?))])
|
||||||
;; Predicates
|
;; Predicates
|
||||||
(contract-out [variable? (-> any/c boolean?)]
|
(contract-out [variable? (-> any/c boolean?)]
|
||||||
[state? (-> any/c boolean?)]
|
[state? (-> any/c boolean?)]
|
||||||
|
|
Loading…
Reference in a new issue