From ce0d5023bf5d9ad7be5cde1ff93fe744e337afbb Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Tue, 10 Nov 2020 09:42:50 +0100 Subject: [PATCH] rs: Add build-reduced-state-graph. --- rs.rkt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rs.rkt b/rs.rkt index 30e0a2d..1fa84aa 100644 --- a/rs.rkt +++ b/rs.rkt @@ -28,6 +28,7 @@ [dds-build-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) graph?)] [dds-build-n-step-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) number? graph?)] [build-interactive-process-graph (-> reaction-system/c (listof (set/c species?)) graph?)] + [build-reduced-state-graph (-> reaction-system/c (listof (set/c species?)) graph?)] [build-interactive-process (-> reaction-system/c (listof (set/c species?)) (listof (list/c (set/c species?) (set/c species?))))] [pretty-print-state-graph (-> graph? graph?)]) ;; Predicates @@ -210,6 +211,24 @@ (dds-build-state-graph-annotated (dynamics rs) (set (state (set) contexts)))) +;;; Builds the reduced state graph of a reaction system driven by +;;; a given context sequence. Unlike build-interactive-process-graph, +;;; the nodes of this state graph do not contain the context sequence. +(define (build-reduced-state-graph rs contexts) + (define sgr (build-interactive-process-graph rs contexts)) + (weighted-graph/directed + (for/list ([e (in-edges sgr)]) + (define u (car e)) (define v (cadr e)) + (list (edge-weight sgr u v) (state-result u) (state-result v))))) + +(module+ test + (test-case "build-reduced-state-graph" + (define rs (hash 'a (reaction (set 'x) (set 'y) (set 'z)) + 'b (reaction (set 'x) (set) (set 'y)))) + (define ctx (list (set 'x) (set 'y) (set 'z) (set) (set 'z))) + (check-equal? (graphviz (build-reduced-state-graph rs ctx)) + "digraph G {\n\tnode0 [label=\"(set)\\n\"];\n\tnode1 [label=\"(set 'y 'z)\\n\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node0 [label=\"#>\"];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node1 [label=\"#>\"];\n\t\tnode1 -> node0 [label=\"#>\"];\n\t}\n}\n"))) + ;;; Builds the interactive process driven by the given context ;;; sequence. The output is a list of pairs of lists in which the ;;; first element is the current context and the second element is the