networks: Add pretty-print-modalities and use it for state graphs.

This commit is contained in:
Sergiu Ivanov 2020-03-01 17:57:58 +01:00
parent 1fa342c2ad
commit 9143f6f9fc
2 changed files with 8 additions and 1 deletions

View file

@ -112,6 +112,7 @@
(test-case "Dynamics of networks"
(check-equal? (pretty-print-state (st '((a . #f) (b . 3) (c . 4)))) "a:#f b:3 c:4")
(check-equal? (pretty-print-modalities (list (set 'a) (set 'b 'a))) "{a}{a b}")
(check-equal? (pretty-print-boolean-state (st '((a . #f) (b . #t) (c . #t)))) "a:0 b:1 c:1")
(let ([vars '(a b c)])
(check-equal? (make-asyn vars) (set (set 'a) (set 'b) (set 'c)))

View file

@ -47,6 +47,7 @@
[dds-build-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) graph?)]
[dds-build-n-step-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) number? graph?)]
[pretty-print-state (-> state? string?)]
[pretty-print-modalities (-> (listof modality?) string?)]
[any->boolean (-> any/c boolean?)]
[pretty-print-boolean-state (-> state? string?)]
[pretty-print-state-graph-with (-> graph? (-> state? string?) graph?)]
@ -343,10 +344,15 @@
(define (pretty-print-boolean-state s)
(string-join (hash-map s (λ (key val) (format "~a:~a" key (any->boolean val))) #t)))
;;; Pretty-prints a list of modalities, as suitable for showing on
;;; state graphs.
(define (pretty-print-modalities ms)
(string-join (for/list ([m ms]) (format "{~a}" (pretty-print-set m))) ""))
;;; Given a state graph and a pretty-printer for states build a new
;;; state graph with pretty-printed vertices and edges.
(define (pretty-print-state-graph-with gr pprinter)
(update-graph gr #:v-func pprinter #:e-func pretty-print-set))
(update-graph gr #:v-func pprinter #:e-func pretty-print-modalities))
;;; Pretty prints a state graph with pretty-print-state.
(define (pretty-print-state-graph gr)