networks: Add make-dynamics-from-func, make-asyn-dynamics, make-syn-dynamics.
This commit is contained in:
parent
c9cbb1c951
commit
dedfddfe55
2 changed files with 25 additions and 2 deletions
|
@ -100,4 +100,11 @@
|
||||||
(test-case "Dynamics of networks"
|
(test-case "Dynamics of networks"
|
||||||
(let ([vars '(a b c)])
|
(let ([vars '(a b c)])
|
||||||
(check-equal? (make-asyn vars) (set (set 'a) (set 'b) (set 'c)))
|
(check-equal? (make-asyn vars) (set (set 'a) (set 'b) (set 'c)))
|
||||||
(check-equal? (make-syn vars) (set (set 'a 'b 'c)))))
|
(check-equal? (make-syn vars) (set (set 'a 'b 'c))))
|
||||||
|
(let* ([n (nn '((a . (not a)) (b . b)))]
|
||||||
|
[asyn (make-asyn-dynamics n)]
|
||||||
|
[syn (make-syn-dynamics n)])
|
||||||
|
(check-equal? (dynamics-network asyn) n)
|
||||||
|
(check-equal? (dynamics-mode asyn) (set (set 'a) (set 'b)))
|
||||||
|
(check-equal? (dynamics-network syn) n)
|
||||||
|
(check-equal? (dynamics-mode syn) (set (set 'a 'b)))))
|
||||||
|
|
18
networks.rkt
18
networks.rkt
|
@ -32,7 +32,10 @@
|
||||||
[build-signed-interaction-graph (-> network-form? domain-mapping/c graph?)]
|
[build-signed-interaction-graph (-> network-form? domain-mapping/c graph?)]
|
||||||
[build-boolean-signed-interaction-graph (-> network-form? graph?)]
|
[build-boolean-signed-interaction-graph (-> network-form? graph?)]
|
||||||
[make-asyn (-> (listof variable?) mode?)]
|
[make-asyn (-> (listof variable?) mode?)]
|
||||||
[make-syn (-> (listof variable?) mode?)])
|
[make-syn (-> (listof variable?) mode?)]
|
||||||
|
[make-dynamics-from-func (-> network? (-> (listof variable?) mode?) dynamics?)]
|
||||||
|
[make-asyn-dynamics (-> network? dynamics?)]
|
||||||
|
[make-syn-dynamics (-> network? dynamics?)])
|
||||||
;; Predicates
|
;; Predicates
|
||||||
(contract-out [variable? (-> any/c boolean?)]
|
(contract-out [variable? (-> any/c boolean?)]
|
||||||
[state? (-> any/c boolean?)]
|
[state? (-> any/c boolean?)]
|
||||||
|
@ -265,3 +268,16 @@
|
||||||
;;; Given a list of variables, builds the synchronous mode (a set
|
;;; Given a list of variables, builds the synchronous mode (a set
|
||||||
;;; containing the set of variables).
|
;;; containing the set of variables).
|
||||||
(define (make-syn vars) (set (list->set vars)))
|
(define (make-syn vars) (set (list->set vars)))
|
||||||
|
|
||||||
|
;;; Given a network, applies a function for building a mode to its
|
||||||
|
;;; variables and returns the corresponding network dynamics.
|
||||||
|
(define (make-dynamics-from-func network mode-func)
|
||||||
|
(dynamics network (mode-func (hash-keys network))))
|
||||||
|
|
||||||
|
;;; Creates the asynchronous dynamics for a given network.
|
||||||
|
(define (make-asyn-dynamics network)
|
||||||
|
(make-dynamics-from-func network make-asyn))
|
||||||
|
|
||||||
|
;;; Creates the synchronous dynamics for a given network.
|
||||||
|
(define (make-syn-dynamics network)
|
||||||
|
(make-dynamics-from-func network make-syn))
|
||||||
|
|
Loading…
Reference in a new issue