From a18620e6943118d4f60a2329cffd6895ba77f279 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Thu, 17 Aug 2023 17:43:50 +0200 Subject: [PATCH] Add pretty-print-state-graph/simple-states. Was pretty-print-reduced-graph. --- rs.rkt | 21 +++++++++++++++++++++ scribblings/rs.scrbl | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/rs.rkt b/rs.rkt index baaddb0..5a66d42 100644 --- a/rs.rkt +++ b/rs.rkt @@ -12,6 +12,7 @@ (struct-out state) State dynamics% Dynamics% build-interactive-process-graph build-interactive-process-graph/simple-states + pretty-print-state-graph/simple-states ) (module+ test @@ -254,6 +255,26 @@ (define ctx : (Listof (Setof Species)) (list (set) (set) (set 'x))) (check-equal? (graphviz (build-interactive-process-graph/simple-states rs ctx)) "digraph G {\n\tnode0 [label=\"(set)\"];\n\tnode1 [label=\"(set 'z)\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node0 [label=\"'()\"];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node1 [label=\"'(a)\"];\n\t}\n}\n"))) + + (: pretty-print-state-graph/simple-states (-> Graph Graph)) + (define (pretty-print-state-graph/simple-states sgr) + (update-graph + sgr + #:v-func + (λ (st) (~a "{" (pretty-print-set (assert-type st (Setof Species))) "}")) + #:e-func + (λ (e) (pretty-print-set (assert-type e (Listof ReactionName)))))) + + (module+ test + (test-case "pretty-print-state-graph/simple-states" + (define rs (hash 'a (make-reaction '(x) '(y) '(z)) + 'b (make-reaction '(x y) '() '(x)))) + (define ctx : (Listof (Setof Species)) (list (set) (set) (set 'x))) + (check-equal? + (graphviz (pretty-print-state-graph/simple-states + (build-interactive-process-graph/simple-states rs ctx))) + "digraph G {\n\tnode0 [label=\"{}\"];\n\tnode1 [label=\"{z}\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node0 [label=\"\"];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node1 [label=\"a\"];\n\t}\n}\n") + )) ) (require graph "utils.rkt" "generic.rkt") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index 5a9d058..3526f3e 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -291,3 +291,21 @@ reflected in any way. [ctx : (Listof (Setof Species)) (list (set) (set) (set 'x))]) (dotit (build-interactive-process-graph/simple-states rs ctx))) ]} + +@defproc[(pretty-print-state-graph/simple-states [sgr Graph]) Graph]{ + +Pretty prints the node and edge labels in a reaction system +state graph with simple states. + +Simple states, as opposed to @racket[State], do not include the +remaining context sequence. +See @racket[build-interactive-process-graph/simple-states] for further +explanations and examples. + +@ex[ +(let ([rs (hash 'a (make-reaction '(x) '(y) '(z)) + 'b (make-reaction '(x y) '() '(x)))] + [ctx : (Listof (Setof Species)) (list (set) (set) (set 'x))]) + (dotit (pretty-print-state-graph/simple-states + (build-interactive-process-graph/simple-states rs ctx)))) +]}