diff --git a/networks.rkt b/networks.rkt index be033e1..697b34c 100644 --- a/networks.rkt +++ b/networks.rkt @@ -102,7 +102,8 @@ [tbf/state-tabulate (->* (tbf/state?) (#:headers boolean?) (listof (listof (or/c symbol? number?))))] [make-tbn (-> (listof (cons/c variable? tbf/state?)) tbn?)] - [tbn->network (-> tbn? network?)]) + [tbn->network (-> tbn? network?)] + [make-sbn (-> (listof (cons/c variable? tbf/state?)) sbn?)]) ;; Predicates (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)] @@ -115,7 +116,8 @@ (contract-out [state/c contract?] [update-function/c contract?] [domain-mapping/c contract?] - [tbn? contract?])) + [tbn? contract?] + [sbn? contract?])) (module+ test (require rackunit)) @@ -1249,6 +1251,23 @@ (hash 'a (tbf/state '#hash((a . -1)) -1) 'b (tbf/state '#hash((a . 1)) 0))))) +;;; A SBN is a network form mapping variables to sbf/state. +;;; +;;; The tbf/state must only reference variables appearing in the +;;; network. This contract does not check this condition. +(define sbn? (hash/c variable? sbf/state?)) + +;;; Builds an SBN from a list of pairs (variable, sbf/state). +(define make-sbn make-immutable-hash) + +(module+ test + (test-case "make-sbn" + (define sbf1 (make-sbf/state '((a . -1)))) + (define sbf2 (make-sbf/state '((a . 1)))) + (check-equal? (make-sbn `((a . ,sbf1) (b . ,sbf2))) + (hash 'a (tbf/state '#hash((a . -1)) 0) + 'b (tbf/state '#hash((a . 1)) 0))))) + ;;; Constructs a network from a network form defining a TBN. (define (tbn->network tbn) (for/hash ([(var tbf) (in-hash tbn)])