From 945626487cff2159a31289e64b421f378726878c Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 18 Sep 2022 01:03:16 +0200 Subject: [PATCH] Add make-asyn-dynamics and make-syn-dynamics. --- networks.rkt | 40 ++++++++++++++++++++++++++++++++++++++ scribblings/networks.scrbl | 14 +++++++++++++ 2 files changed, 54 insertions(+) diff --git a/networks.rkt b/networks.rkt index 27f3943..48b58fe 100644 --- a/networks.rkt +++ b/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) diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index 567611f..c2fccbe 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -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}. + }