networks, generic: Add dds-step.

This commit is contained in:
Sergiu Ivanov 2020-02-23 13:28:51 +01:00
parent 598904fecd
commit 8c92a4bbd8
3 changed files with 24 additions and 5 deletions

View file

@ -11,11 +11,25 @@
;; Generics
gen:dds
;; 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
(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.
(define-generics 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)])

View file

@ -114,4 +114,8 @@
[s (st '((a . #t) (b . #f)))])
(check-equal? (dds-step-one asyn s) (set (st '((a . #f) (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)))))))

View file

@ -36,7 +36,8 @@
[make-dynamics-from-func (-> network? (-> (listof variable?) mode?) dynamics?)]
[make-asyn-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
(contract-out [variable? (-> any/c boolean?)]
[state? (-> any/c boolean?)]