Finish adding sbfs/state->lists.

This commit is contained in:
Sergiu Ivanov 2023-05-25 14:51:55 +02:00
parent 18c9828a5a
commit 76c6bb5745
2 changed files with 23 additions and 6 deletions

View file

@ -228,6 +228,23 @@ corresponds to the column giving the thresholds of the TBFs.
(tbf/state (hash 'a -2 'b 1) 1)))
]}
@defproc[(sbfs/state->lists [sbfs (Listof TBF/State)])
(Listof (Listof Real))]{
Like @racket[tbfs/state->lists], but the thresholds are omitted.
@ex[
(sbfs/state->lists (list (tbf/state (hash 'a 1 'b 2) 0)
(tbf/state (hash 'a -2 'b 1) 0)))
]
Note that this function just drops the threshold, without checking
whether it is actually 0:
@ex[
(sbfs/state->lists (list (tbf/state (hash 'a 1 'b 2) 3)))
]}
@section{Tabulating TBFs and SBFs}
@defproc[(tabulate-tbfs/state [tbfs (Listof TBF/State)]) (Listof (Listof Real))]{

12
tbn.rkt
View file

@ -29,6 +29,7 @@
lists+vars->sbfs/state lists+headers->sbfs/state lists->sbfs/state
read-org-tbfs/state read-org-tbfs/state+headers
tbfs/state->lists tbfs/state->lists+headers
sbfs/state->lists
tabulate-tbfs/state tabulate-tbfs/state+headers
tabulate-tbf/state tabulate-tbf/state+headers
@ -224,15 +225,14 @@
(: sbfs/state->lists (-> (Listof TBF/State) (Listof (Listof Real))))
(define (sbfs/state->lists tbfs)
(for/list ([tbf (in-list tbfs)])
(append (hash-map (tbf/state-w tbf) (λ (_ [w : Real]) w) #t)
(list (tbf/state-θ tbf)))))
(hash-map (tbf/state-w tbf) (λ (_ [w : Real]) w) #t)))
(module+ test
(test-case "tbfs/state->lists"
(test-case "sbfs/state->lists"
(check-equal?
(tbfs/state->lists (list (tbf/state (hash 'a 1 'b 2) 3)
(tbf/state (hash 'a -2 'b 1) 1)))
'((1 2 3) (-2 1 1)))))
(sbfs/state->lists (list (tbf/state (hash 'a 1 'b 2) 0)
(tbf/state (hash 'a -2 'b 1) 0)))
'((1 2) (-2 1)))))
(: tabulate-tbfs/state (-> (Listof TBF/State) (Listof (Listof Real))))
(define (tabulate-tbfs/state tbfs)