From dbbfc74eaf3e32af44f56dbc3ddc2b209f16823e Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 9 Nov 2020 23:13:24 +0100 Subject: [PATCH] rs: Don't implicitly complete all context sequences with empty contexts. --- example/dots/examplevvXFaI.svg | 108 ++++++++++++++++----------------- example/example.org | 4 +- rs.rkt | 43 +++++++------ 3 files changed, 74 insertions(+), 81 deletions(-) diff --git a/example/dots/examplevvXFaI.svg b/example/dots/examplevvXFaI.svg index 7fe5acb..a4f6539 100644 --- a/example/dots/examplevvXFaI.svg +++ b/example/dots/examplevvXFaI.svg @@ -4,79 +4,73 @@ - + G - + node0 - -C:{z}{}{t} -D:{z} - - - -node1 - -C:{}{t} -D:{} - - - -node0->node1 - - -{} - - - -node3 - -C:{t} -D:{} - - - -node1->node3 - - -{} + +C:{}{t} +D:{} node2 - -C:{x y}{z}{}{t} -D:{} + +C:{t} +D:{} - - -node2->node0 - - -{b} + + +node0->node2 + + +{} + + + +node1 + +C:{z}{}{t} +D:{z} + + + +node1->node0 + + +{} node4 - -C: -D:{} + +C: +D:{} - - -node3->node4 - - -{} + + +node2->node4 + + +{} - - -node4->node4 - -{} + + +node3 + +C:{x y}{z}{}{t} +D:{} + + + +node3->node1 + + +{b} diff --git a/example/example.org b/example/example.org index 716dcf2..57df147 100644 --- a/example/example.org +++ b/example/example.org @@ -1279,9 +1279,9 @@ tab #+END_SRC #+RESULTS: - :RESULTS: + :results: [[file:dots/examplevvXFaI.svg]] - :END: + :end: Note that we need to keep the full context sequence in the name of each state to avoid merging states with the same result and diff --git a/rs.rkt b/rs.rkt index 342e1b4..4d412f7 100644 --- a/rs.rkt +++ b/rs.rkt @@ -172,11 +172,12 @@ ;;; ============================ ;;; An interactive process of a reaction system is a sequence of -;;; states driven by a sequence of contexts in the following way. The -;;; reaction system starts with the initial context. Then, at every -;;; step, the result of applying the reaction system is merged with -;;; the next element of the context sequence, and the reaction system -;;; is then applied to the result of the union. +;;; states driven by a sequence of contexts in the following way. +;;; The reaction system starts with the initial context. Then, at +;;; every step, the result of applying the reaction system is merged +;;; with the next element of the context sequence, and the reaction +;;; system is then applied to the result of the union. If the +;;; sequence of contexts is empty, the reaction system cannot evolve. ;;; A state of a reaction system is a set of species representing the ;;; result of the application of the reactions from the previous @@ -189,20 +190,19 @@ (struct dynamics (rs) #:transparent #:methods gen:dds [;; Since reaction systems are deterministic, a singleton set is - ;; always produced. It is annotated by the list of rules which - ;; were enabled in the current step. + ;; produced, unless the context sequence is empty, in which case an + ;; empty set of states is generated. This transition is annotated + ;; by the list of rules which were enabled in the current step. (define (dds-step-one-annotated dyn st) - (let* ([rs (dynamics-rs dyn)] - [apply-rs-annotate - (λ (s rest-ctx) - (let ([en (list-enabled rs s)]) - (set (cons (list->set en) - (state (union-products rs en) rest-ctx)))))]) - (match st - [(state res (cons ctx rest-ctx)) - (apply-rs-annotate (set-union res ctx) rest-ctx)] - [(state res '()) - (apply-rs-annotate res '())])))]) + (define rs (dynamics-rs dyn)) + (define (apply-rs-annotate s rest-ctx) + (define en (list-enabled rs s)) + (set (cons (list->set en) + (state (union-products rs en) rest-ctx)))) + (match st + [(state res (cons ctx rest-ctx)) + (apply-rs-annotate (set-union res ctx) rest-ctx)] + [(state res '()) (set)]))]) ;;; Builds the state graph of a reaction system driven by a given ;;; context sequence. When the context sequence is exhausted, keeps @@ -268,10 +268,9 @@ (check-true (has-vertex? sgr (state (set) (list (set 'x) (set 'y) (set 'z) (set) (set 'z))))) (check-true (has-vertex? sgr (state (set) '()))) - (check-equal? (edge-weight sgr - (state (set) '()) - (state (set) '())) - (set (set))) + (check-false (has-edge? sgr + (state (set) '()) + (state (set) '()))) (check-equal? (edge-weight sgr (state (set 'y 'z) (list (set 'y) (set 'z) (set) (set 'z))) (state (set) (list (set 'z) (set) (set 'z))))