From 11ecbf84dc6b1013c16912f6917773edb41102dc Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sat, 24 Oct 2020 23:15:13 +0200 Subject: [PATCH] networks: Add normalized-tbn?. --- networks.rkt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/networks.rkt b/networks.rkt index 6aea0cc..9057a45 100644 --- a/networks.rkt +++ b/networks.rkt @@ -117,7 +117,8 @@ [read-org-sbn (->* (string?) (#:headers boolean? #:func-names boolean?) tbn?)] - [build-tbn-state-graph (-> tbn? graph?)]) + [build-tbn-state-graph (-> tbn? graph?)] + [normalized-tbn? (-> tbn? boolean?)]) ;; Predicates (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)] @@ -1474,3 +1475,20 @@ build-full-01-state-graph make-syn-dynamics tbn->network)) + +;;; Checks whether a TBN is normalized: whether all of the functions +;;; have the same inputs, and whether these inputs are exactly the +;;; variables of the TBN. +(define (normalized-tbn? tbn) + (define tbn-vars (hash-keys tbn)) + (for/and ([tbf (in-list (hash-values tbn))]) + (set=? tbn-vars (hash-keys (tbf/state-w tbf))))) + +(module+ test + (test-case "normalized-tbn?" + (check-false (normalized-tbn? + (make-tbn `((a . ,(make-sbf/state '((b . 1)))) + (b . ,(make-tbf/state '((a . -1)) -1)))))) + (check-true (normalized-tbn? + (make-tbn `((a . ,(make-sbf/state '((a . 1) (b . -1)))) + (b . ,(make-tbf/state '((a . -1) (b . 1)) -1))))))))