utils: Move pretty-print-modalities as pretty-print-set-sets from networks.

This commit is contained in:
Sergiu Ivanov 2020-03-02 23:59:37 +01:00
parent de9b703b44
commit a3967d8bf8
4 changed files with 11 additions and 9 deletions

View File

@ -112,7 +112,6 @@
(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,7 +47,6 @@
[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?)]
@ -340,15 +339,10 @@
(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-modalities))
(update-graph gr #:v-func pprinter #:e-func pretty-print-set-sets))
;;; Pretty prints a state graph with pretty-print-state.
(define (pretty-print-state-graph gr)

View File

@ -64,7 +64,8 @@
(check-equal? (read-symbol-list "a b c") '(a b c))
(check-equal? (drop-first-last "(a b)") "a b")
(check-equal? (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't)))
'("y x" "z" "" "t")))
'("y x" "z" "" "t"))
(check-equal? (pretty-print-set-sets (set (set 'a 'b) (set 'c))) "{a b}{c}"))
(test-case "Additional graph utilities"
(let* ([gr1 (directed-graph '((a b) (b c)))]

View File

@ -22,6 +22,7 @@
[read-symbol-list (-> string? (listof symbol?))]
[drop-first-last (-> string? string?)]
[list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))]
[pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)]
[update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)]
[update-graph (->* (graph?)
(#:v-func (-> any/c any/c)
@ -238,6 +239,13 @@
(define (list-sets->list-strings lst)
(map (compose drop-first-last any->string set->list) lst))
;;; Pretty-prints a set of sets of symbols.
;;;
;;; Typically used for pretty-printing the annotations on the edges of
;;; the state graph.
(define (pretty-print-set-sets ms)
(string-join (for/list ([m ms]) (format "{~a}" (pretty-print-set m))) ""))
;;; ==========================
;;; Additional graph utilities