From 75bf044fd8d8737b8980f28a7d95af3002eb10a9 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Thu, 20 Feb 2020 15:17:32 +0100 Subject: [PATCH] networks: Add list-interactions. --- networks-tests.rkt | 6 ++++++ networks.rkt | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/networks-tests.rkt b/networks-tests.rkt index 04a0b8e..ec9e563 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -44,3 +44,9 @@ (check-equal? ((hash-ref bn1 'a) s) #t) (check-equal? ((hash-ref bn2 'a) s) #t) (check-equal? ((hash-ref bn3 'a) s) #t))) + +(test-case "Inferring interaction graphs" + (let ([n #hash((a . (+ a b c)) + (b . (- b c)))]) + (check-true (set=? (list-interactions n 'a) '(a b))) + (check-true (set=? (list-interactions n 'b) '(b))))) diff --git a/networks.rkt b/networks.rkt index 60ca706..2e53707 100644 --- a/networks.rkt +++ b/networks.rkt @@ -20,7 +20,8 @@ [update-function-form->update-function (-> update-function-form? update-function/c)] [network-form->network (-> network-form? network?)] [make-network-from-forms (-> (listof (cons/c symbol? update-function-form?)) - network?)]) + network?)] + [list-interactions (-> network-form? variable? (listof variable?))]) ;; Predicates (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)] @@ -121,3 +122,10 @@ ;;; interaction graphs, but since the inference of signed interaction ;;; graphs is based on analysing the dynamics of the networks, it may ;;; be quite resource-consuming. + +;;; Lists the variables of the network form appearing in the update +;;; function form for x. +(define (list-interactions nf x) + (set-intersect + (extract-symbols (hash-ref nf x)) + (hash-keys nf)))