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)))