diff --git a/networks.rkt b/networks.rkt index 3609ce6..be033e1 100644 --- a/networks.rkt +++ b/networks.rkt @@ -101,7 +101,8 @@ (listof (listof (or/c symbol? number?))))] [tbf/state-tabulate (->* (tbf/state?) (#:headers boolean?) (listof (listof (or/c symbol? number?))))] - [make-tbn (-> (listof (cons/c variable? tbf/state?)) tbn?)]) + [make-tbn (-> (listof (cons/c variable? tbf/state?)) tbn?)] + [tbn->network (-> tbn? network?)]) ;; Predicates (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)] @@ -1247,3 +1248,17 @@ (check-equal? (make-tbn `((a . ,tbf-not) (b . ,tbf-id))) (hash 'a (tbf/state '#hash((a . -1)) -1) '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)]) + (values var ((curry apply-tbf/state) tbf)))) + +(module+ test + (test-case "tbn->network" + (define tbn (make-tbn `((a . ,(make-sbf/state '((b . 1)))) + (b . ,(make-tbf/state '((a . -1)) -1))))) + (define n (tbn->network tbn)) + (define s1 (make-state '((a . 0) (b . 0)))) + (check-equal? (update n s1 '(a b)) + (make-state '((a . 0) (b . 1))))))