Type pretty-print-state-graph.
This commit is contained in:
parent
1e9d906b34
commit
5a2307ed58
2 changed files with 32 additions and 1 deletions
18
rs.rkt
18
rs.rkt
|
@ -13,7 +13,7 @@
|
||||||
(struct-out state) State dynamics% Dynamics% build-interactive-process-graph
|
(struct-out state) State dynamics% Dynamics% build-interactive-process-graph
|
||||||
build-interactive-process-graph/simple-states
|
build-interactive-process-graph/simple-states
|
||||||
pretty-print-state-graph/simple-states build-interactive-process
|
pretty-print-state-graph/simple-states build-interactive-process
|
||||||
build-interactive-process/org pretty-print-state
|
build-interactive-process/org pretty-print-state pretty-print-state-graph
|
||||||
)
|
)
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
|
@ -338,6 +338,22 @@
|
||||||
(check-equal? (pretty-print-state
|
(check-equal? (pretty-print-state
|
||||||
(state (set 'x 'y) (list (set 'z) (set) (set 'x))))
|
(state (set 'x 'y) (list (set 'z) (set) (set 'x))))
|
||||||
"C:{z}{}{x}\nD:{x y}")))
|
"C:{z}{}{x}\nD:{x y}")))
|
||||||
|
|
||||||
|
(: pretty-print-state-graph (-> Graph Graph))
|
||||||
|
(define (pretty-print-state-graph sgr)
|
||||||
|
(update-graph
|
||||||
|
sgr
|
||||||
|
#:v-func (λ (st) (pretty-print-state (assert-type st State)))
|
||||||
|
#:e-func (λ (e) (pretty-print-set (assert-type e (Listof ReactionName))))))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "pretty-print-state-graph"
|
||||||
|
(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 (build-interactive-process-graph rs ctx))
|
||||||
|
"digraph G {\n\tnode0 [label=\"(state (set) '(#<set: x>))\"];\n\tnode1 [label=\"(state (set 'z) '())\"];\n\tnode2 [label=\"(state (set) '(#<set:> #<set: x>))\"];\n\tnode3 [label=\"(state (set) '(#<set:> #<set:> #<set: x>))\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node1 [label=\"'(a)\"];\n\t\tnode2 -> node0 [label=\"'()\"];\n\t\tnode3 -> node2 [label=\"'()\"];\n\t}\n}\n")
|
||||||
|
))
|
||||||
)
|
)
|
||||||
|
|
||||||
(require graph "utils.rkt" "generic.rkt")
|
(require graph "utils.rkt" "generic.rkt")
|
||||||
|
|
|
@ -356,3 +356,18 @@ Pretty prints the context sequence and the current result of
|
||||||
@ex[
|
@ex[
|
||||||
(pretty-print-state (state (set 'x 'y) (list (set 'z) (set) (set 'x))))
|
(pretty-print-state (state (set 'x 'y) (list (set 'z) (set) (set 'x))))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(pretty-print-state-graph [sgr Graph]) Graph]{
|
||||||
|
|
||||||
|
Pretty prints the state graph of a reaction system.
|
||||||
|
|
||||||
|
Note that we need to keep the full context sequence in the name of
|
||||||
|
each state to avoid confusion between the states at different steps of
|
||||||
|
the evolution.
|
||||||
|
|
||||||
|
@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 (build-interactive-process-graph rs ctx))))
|
||||||
|
]}
|
||||||
|
|
Loading…
Reference in a new issue