Add pretty-print-state-graph/simple-states.

Was pretty-print-reduced-graph.
This commit is contained in:
Sergiu Ivanov 2023-08-17 17:43:50 +02:00
parent 0e364eb52d
commit a18620e694
2 changed files with 39 additions and 0 deletions

21
rs.rkt
View File

@ -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")

View File

@ -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))))
]}