diff --git a/networks-tests.rkt b/networks-tests.rkt index 05441df..c37b083 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -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))) diff --git a/networks.rkt b/networks.rkt index 92b2b92..fc78008 100644 --- a/networks.rkt +++ b/networks.rkt @@ -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)