Add make-asyn-dynamics and make-syn-dynamics.
This commit is contained in:
parent
4d05b9d9ee
commit
945626487c
2 changed files with 54 additions and 0 deletions
40
networks.rkt
40
networks.rkt
|
@ -34,6 +34,7 @@
|
|||
build-signed-interaction-graph/form
|
||||
|
||||
Modality Mode dynamics% Dynamics% make-syn make-asyn
|
||||
make-asyn-dynamics make-syn-dynamics
|
||||
)
|
||||
|
||||
(define-type (State a) (VariableMapping a))
|
||||
|
@ -615,6 +616,45 @@
|
|||
(module+ test
|
||||
(test-case "make-syn"
|
||||
(check-equal? (make-syn '(x y z)) '((x y z)))))
|
||||
|
||||
;;; Given a network, applies a function for building a mode to its
|
||||
;;; variables and returns the corresponding network dynamics.
|
||||
(: make-dynamics-from-mode
|
||||
(All (a) (-> (Network a) (-> (Listof Variable) Mode) (Dynamics% a))))
|
||||
(define (make-dynamics-from-mode n make-mode)
|
||||
(new (inst dynamics% a)
|
||||
[network n]
|
||||
[mode (make-mode (hash-keys (network-functions n)))]))
|
||||
|
||||
(: make-asyn-dynamics (All (a) (-> (Network a) (Dynamics% a))))
|
||||
(define (make-asyn-dynamics [n : (Network a)])
|
||||
((inst make-dynamics-from-mode a) n make-asyn))
|
||||
|
||||
(module+ test
|
||||
(test-case "make-asyn-dynamics"
|
||||
(define n : (Network Boolean)
|
||||
(forms->boolean-network (hash 'x '(not y)
|
||||
'y 'x
|
||||
'z '(and y z))))
|
||||
(define asyn-dyn (make-asyn-dynamics n))
|
||||
(check-equal? (get-field network asyn-dyn) n)
|
||||
(check-true (set=? (get-field mode asyn-dyn) '((x) (y) (z))))))
|
||||
|
||||
(: make-syn-dynamics (All (a) (-> (Network a) (Dynamics% a))))
|
||||
(define (make-syn-dynamics [n : (Network a)])
|
||||
((inst make-dynamics-from-mode a) n make-syn))
|
||||
|
||||
(module+ test
|
||||
(test-case "make-syn-dynamics"
|
||||
(define n : (Network Boolean)
|
||||
(forms->boolean-network (hash 'x '(not y)
|
||||
'y 'x
|
||||
'z '(and y z))))
|
||||
(define syn-dyn (make-syn-dynamics n))
|
||||
(check-equal? (get-field network syn-dyn) n)
|
||||
(define m (get-field mode syn-dyn))
|
||||
(check-equal? (length m) 1)
|
||||
(check-true (set=? (car m) '(x y z)))))
|
||||
)
|
||||
|
||||
(require 'typed)
|
||||
|
|
|
@ -447,6 +447,20 @@ containing the set of all variables.
|
|||
|
||||
}
|
||||
|
||||
@defproc[(make-asyn-dynamics [network (Network a)]) (Dynamics% a)]{
|
||||
|
||||
Creates the asynchronous dynamics for a given network: an instance of
|
||||
@racket[dynamics%] with @tt{network} as the network and the asynchronous
|
||||
mode as @tt{mode}.
|
||||
|
||||
}
|
||||
|
||||
@defproc[(make-syn-dynamics [network (Network a)]) (Dynamics% a)]{
|
||||
|
||||
Creates the synchronous dynamics for a given network: an instance of
|
||||
@racket[dynamics%] with @tt{network} as the network and the synchronous mode as
|
||||
@tt{mode}.
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue