From 6a3bd9e7a6cb3cd06f1148509d31ac9bf2c060cc Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 16 Aug 2023 14:01:17 +0200 Subject: [PATCH] Type build-interactive-process-graph. --- rs.rkt | 16 +++++++++++++++- scribblings/rs.scrbl | 22 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/rs.rkt b/rs.rkt index d6fe123..4305687 100644 --- a/rs.rkt +++ b/rs.rkt @@ -10,7 +10,7 @@ str-triple->reaction ht-str-triples->rs read-org-rs read-context-sequence reaction->str-triple rs->ht-str-triples - (struct-out state) State dynamics% Dynamics% + (struct-out state) State dynamics% Dynamics% build-interactive-process-graph ) (module+ test @@ -222,6 +222,20 @@ (cons '(b) (state (set 'x) (list (set) (set 'x)))) (cons '(a) (state (set 'z) (list (set 'x)))) (cons '(a) (state (set 'z) '())))))) + + (: build-interactive-process-graph (-> ReactionSystem (Listof (Setof Species)) Graph)) + (define (build-interactive-process-graph rs contexts) + (send (new dynamics% [rs rs]) + build-state-graph/annotated + (list (state (set) contexts)))) + + (module+ test + (test-case "build-interactive-process-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) '(#))\"];\n\tnode1 [label=\"(state (set 'z) '())\"];\n\tnode2 [label=\"(state (set) '(# #))\"];\n\tnode3 [label=\"(state (set) '(# # #))\"];\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") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index 6e45bfe..9dc2cc2 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -2,13 +2,15 @@ @(require scribble/example racket/sandbox (for-label typed/racket/base (submod "../rs.rkt" typed) + "../utils.rkt" "../dynamics.rkt")) @(define rs-evaluator (parameterize ([sandbox-output 'string] [sandbox-error-output 'string] [sandbox-memory-limit 500]) - (make-evaluator 'typed/racket #:requires '((submod "rs.rkt" typed))))) + (make-evaluator 'typed/racket + #:requires '((submod "rs.rkt" typed) "utils.rkt")))) @(define-syntax-rule (ex . args) (examples #:eval rs-evaluator . args)) @@ -249,3 +251,21 @@ these reactions. The type of an instance of @racket[dynamics%]. } + +@defproc[(build-interactive-process-graph [rs ReactionSystem] + [contexts (Listof (Setof Species))]) + Graph]{ + +Builds the state graph of the reaction system @racket[rs] driven by +the context sequence @racket[contexts]. + +This function directly calls @method[dds% build-state-graph/annotated] +under the hood, and is actually a light interface on top of +that function. + +@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 rs ctx))) +]}