networks: Add apply-tbf/state.

This commit is contained in:
Sergiu Ivanov 2020-07-22 23:46:58 +02:00
parent 3c640d2cab
commit e10b208079
1 changed files with 15 additions and 1 deletions

View File

@ -76,7 +76,8 @@
[random-boolean-function/state ((listof variable?) . -> . procedure?)]
[random-network (domain-mapping/c . -> . network?)]
[random-boolean-network ((listof variable?) . -> . network?)]
[random-boolean-network/vars (number? . -> . network?)])
[random-boolean-network/vars (number? . -> . network?)]
[apply-tbf/state (-> tbf? state? (or/c 0 1))])
;; Predicates
(contract-out [variable? (-> any/c boolean?)]
[state? (-> any/c boolean?)]
@ -926,3 +927,16 @@
;;; A TBN is a network form mapping TBFs to variables.
(define tbn? (hash/c variable? tbf?))
;;; Applies a TBF to a state.
;;;
;;; The values of the variables of the state are ordered by hash-map
;;; and fed to the TBF in order. The number of the inputs of the TBF
;;; must match the number of variables in the state.
(define (apply-tbf/state tbf st)
(apply-tbf tbf (list->vector (hash-map st (λ (_ val) val)))))
(module+ test
(define st (make-state '((x1 . 0) (x2 . 1))))
(define f (tbf #(1 1) 1))
(check-equal? (apply-tbf/state f st) 0))