Add build-interactive-process-graph/simple-states.

Was build-reduced-state-graph.
This commit is contained in:
Sergiu Ivanov 2023-08-17 10:26:05 +02:00
parent 6a3bd9e7a6
commit 99d50c8505
2 changed files with 40 additions and 0 deletions

18
rs.rkt
View file

@ -11,6 +11,7 @@
reaction->str-triple rs->ht-str-triples
(struct-out state) State dynamics% Dynamics% build-interactive-process-graph
build-interactive-process-graph/simple-states
)
(module+ test
@ -236,6 +237,23 @@
(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")))
(: build-interactive-process-graph/simple-states (-> ReactionSystem (Listof (Setof Species)) Graph))
(define (build-interactive-process-graph/simple-states rs contexts)
(define sgr (build-interactive-process-graph rs contexts))
(weighted-graph/directed
(for/list ([e (in-edges sgr)])
(define u (assert-type (car e) State))
(define v (assert-type (cadr e) State))
(list (edge-weight sgr u v) (state-result u) (state-result v)))))
(module+ test
(test-case "build-interactive-process-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 (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")))
)
(require graph "utils.rkt" "generic.rkt")

View file

@ -269,3 +269,25 @@ that function.
[ctx : (Listof (Setof Species)) (list (set) (set) (set 'x))])
(dotit (build-interactive-process-graph rs ctx)))
]}
@defproc[(build-interactive-process-graph/simple-states
[rs ReactionSystem]
[contexts (Listof (Setof Species))])
Graph]{
Builds the state graph of the reaction system @racket[rs] driven by
the context sequence @racket[contexts], like
@racket[build-interactive-process-graph], but omits the context
sequences from the states.
@bold{Note:} If the reaction system visits the same set of species
multiple times, all these visits will be conflated into a single node
in the resulting graph. The number or the order of visits will not be
reflected in any way.
@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 (build-interactive-process-graph/simple-states rs ctx)))
]}