From 3b8ce5eb84d1be077f76f898bba6d90ea223ae12 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 11 Nov 2020 00:36:49 +0100 Subject: [PATCH] rs: Add pretty-print-reduced-state-graph. --- rs.rkt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rs.rkt b/rs.rkt index 1fa84aa..ae111ff 100644 --- a/rs.rkt +++ b/rs.rkt @@ -29,6 +29,7 @@ [dds-build-n-step-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) number? graph?)] [build-interactive-process-graph (-> reaction-system/c (listof (set/c species?)) graph?)] [build-reduced-state-graph (-> reaction-system/c (listof (set/c species?)) graph?)] + [pretty-print-reduced-state-graph (-> graph? graph?)] [build-interactive-process (-> reaction-system/c (listof (set/c species?)) (listof (list/c (set/c species?) (set/c species?))))] [pretty-print-state-graph (-> graph? graph?)]) ;; Predicates @@ -229,6 +230,20 @@ (check-equal? (graphviz (build-reduced-state-graph rs ctx)) "digraph G {\n\tnode0 [label=\"(set)\\n\"];\n\tnode1 [label=\"(set 'y 'z)\\n\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node0 [label=\"#>\"];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node1 [label=\"#>\"];\n\t\tnode1 -> node0 [label=\"#>\"];\n\t}\n}\n"))) +(define (pretty-print-reduced-state-graph sgr) + (update-graph sgr + #:v-func (λ (st) (~a "{" (pretty-print-set st) "}")) + #:e-func pretty-print-set-sets)) + +(module+ test + (test-case "pretty-print-reduced-graph" + (define rs (hash 'a (reaction (set 'x) (set 'y) (set 'z)) + 'b (reaction (set 'x) (set) (set 'y)))) + (define ctx (list (set 'x) (set 'y) (set 'z) (set) (set 'z))) + (define sgr (build-reduced-state-graph rs ctx)) + (graphviz (pretty-print-reduced-state-graph sgr)))) + + ;;; Builds the interactive process driven by the given context ;;; sequence. The output is a list of pairs of lists in which the ;;; first element is the current context and the second element is the