networks: Add tbf/state-tabulate.

This commit is contained in:
Sergiu Ivanov 2020-10-12 00:53:56 +02:00
parent f37155fd3e
commit 848d53f97a

View file

@ -91,6 +91,8 @@
[print-org-tbfs/state (->* ((non-empty-listof tbf/state?)) (#:headers boolean?)
(listof (listof (or/c number? symbol?))))]
[tbf/state-tabulate* (->* ((non-empty-listof tbf/state?)) (#:headers boolean?)
(listof (listof (or/c symbol? number?))))]
[tbf/state-tabulate (->* (tbf/state?) (#:headers boolean?)
(listof (listof (or/c symbol? number?))))])
;; Predicates
(contract-out [variable? (-> any/c boolean?)]
@ -1117,5 +1119,19 @@
(1 0 0 0)
(1 1 1 0)))))
;;; Like tbf/state-tabulate*, but only tabulates a single TBF.
(define (tbf/state-tabulate tbf #:headers [headers #t])
(tbf/state-tabulate* (list tbf) #:headers headers))
(module+ test
(test-case "tbf/state-tabulate"
(define tbf (make-tbf/state '((a . -2) (b . 3)) 1))
(check-equal? (tbf/state-tabulate tbf)
'((a b f1)
(0 0 0)
(0 1 1)
(1 0 0)
(1 1 0)))))
;;; A TBN is a network form mapping TBFs to variables.
(define tbn? (hash/c variable? tbf?))