From dedfddfe5597d7e5b6ceab863645d93954591db0 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 23 Feb 2020 11:42:01 +0100 Subject: [PATCH] networks: Add make-dynamics-from-func, make-asyn-dynamics, make-syn-dynamics. --- networks-tests.rkt | 9 ++++++++- networks.rkt | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/networks-tests.rkt b/networks-tests.rkt index 1c847ba..bbedb2f 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -100,4 +100,11 @@ (test-case "Dynamics of networks" (let ([vars '(a b 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))))) diff --git a/networks.rkt b/networks.rkt index 52aab7f..a29d27c 100644 --- a/networks.rkt +++ b/networks.rkt @@ -32,7 +32,10 @@ [build-signed-interaction-graph (-> network-form? domain-mapping/c graph?)] [build-boolean-signed-interaction-graph (-> network-form? graph?)] [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 (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)] @@ -265,3 +268,16 @@ ;;; Given a list of variables, builds the synchronous mode (a set ;;; containing the set of variables). (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))