rs: Don't implicitly complete all context sequences with empty contexts.

This commit is contained in:
Sergiu Ivanov 2020-11-09 23:13:24 +01:00
parent 2b60b23bf1
commit dbbfc74eaf
3 changed files with 74 additions and 81 deletions

View File

@ -4,79 +4,73 @@
<!-- Generated by graphviz version 2.43.0 (0)
-->
<!-- Title: G Pages: 1 -->
<svg width="1014pt" height="62pt"
viewBox="0.00 0.00 1013.82 61.74" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg width="970pt" height="62pt"
viewBox="0.00 0.00 969.87 61.74" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 57.74)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-57.74 1009.82,-57.74 1009.82,4 -4,4"/>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-57.74 965.87,-57.74 965.87,4 -4,4"/>
<!-- node0 -->
<g id="node1" class="node">
<title>node0</title>
<ellipse fill="none" stroke="black" cx="434.62" cy="-26.87" rx="69.09" ry="26.74"/>
<text text-anchor="middle" x="434.62" y="-30.67" font-family="Times-Roman" font-size="14.00">C:{z}{}{t}</text>
<text text-anchor="middle" x="434.62" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{z}</text>
</g>
<!-- node1 -->
<g id="node2" class="node">
<title>node1</title>
<ellipse fill="none" stroke="black" cx="626.83" cy="-26.87" rx="50.82" ry="26.74"/>
<text text-anchor="middle" x="626.83" y="-30.67" font-family="Times-Roman" font-size="14.00">C:{}{t}</text>
<text text-anchor="middle" x="626.83" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{}</text>
</g>
<!-- node0&#45;&gt;node1 -->
<g id="edge2" class="edge">
<title>node0&#45;&gt;node1</title>
<path fill="none" stroke="black" d="M504.01,-26.87C524.16,-26.87 546,-26.87 565.61,-26.87"/>
<polygon fill="black" stroke="black" points="565.64,-30.37 575.64,-26.87 565.64,-23.37 565.64,-30.37"/>
<text text-anchor="middle" x="525.31" y="-30.67" font-family="Times-Roman" font-size="14.00">{}</text>
</g>
<!-- node3 -->
<g id="node4" class="node">
<title>node3</title>
<ellipse fill="none" stroke="black" cx="787.92" cy="-26.87" rx="38.37" ry="26.74"/>
<text text-anchor="middle" x="787.92" y="-30.67" font-family="Times-Roman" font-size="14.00">C:{t}</text>
<text text-anchor="middle" x="787.92" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{}</text>
</g>
<!-- node1&#45;&gt;node3 -->
<g id="edge3" class="edge">
<title>node1&#45;&gt;node3</title>
<path fill="none" stroke="black" d="M677.8,-26.87C697.49,-26.87 719.92,-26.87 739.37,-26.87"/>
<polygon fill="black" stroke="black" points="739.54,-30.37 749.54,-26.87 739.54,-23.37 739.54,-30.37"/>
<text text-anchor="middle" x="699.09" y="-30.67" font-family="Times-Roman" font-size="14.00">{}</text>
<ellipse fill="none" stroke="black" cx="527.25" cy="-26.87" rx="50.82" ry="26.74"/>
<text text-anchor="middle" x="527.25" y="-30.67" font-family="Times-Roman" font-size="14.00">C:{}{t}</text>
<text text-anchor="middle" x="527.25" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{}</text>
</g>
<!-- node2 -->
<g id="node3" class="node">
<title>node2</title>
<ellipse fill="none" stroke="black" cx="96.87" cy="-26.87" rx="96.75" ry="26.74"/>
<text text-anchor="middle" x="96.87" y="-30.67" font-family="Times-Roman" font-size="14.00">C:{x y}{z}{}{t}</text>
<text text-anchor="middle" x="96.87" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{}</text>
<ellipse fill="none" stroke="black" cx="780.98" cy="-26.87" rx="38.37" ry="26.74"/>
<text text-anchor="middle" x="780.98" y="-30.67" font-family="Times-Roman" font-size="14.00">C:{t}</text>
<text text-anchor="middle" x="780.98" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{}</text>
</g>
<!-- node2&#45;&gt;node0 -->
<g id="edge4" class="edge">
<title>node2&#45;&gt;node0</title>
<path fill="none" stroke="black" d="M194.11,-26.87C245.14,-26.87 306.89,-26.87 355.04,-26.87"/>
<polygon fill="black" stroke="black" points="355.1,-30.37 365.1,-26.87 355.1,-23.37 355.1,-30.37"/>
<text text-anchor="middle" x="260.58" y="-30.67" font-family="Times-Roman" font-size="14.00">{b}</text>
<!-- node0&#45;&gt;node2 -->
<g id="edge1" class="edge">
<title>node0&#45;&gt;node2</title>
<path fill="none" stroke="black" d="M578.29,-26.87C623.17,-26.87 688.05,-26.87 732.23,-26.87"/>
<polygon fill="black" stroke="black" points="732.44,-30.37 742.44,-26.87 732.44,-23.37 732.44,-30.37"/>
<text text-anchor="middle" x="645.76" y="-30.67" font-family="Times-Roman" font-size="14.00">{}</text>
</g>
<!-- node1 -->
<g id="node2" class="node">
<title>node1</title>
<ellipse fill="none" stroke="black" cx="335.04" cy="-26.87" rx="69.09" ry="26.74"/>
<text text-anchor="middle" x="335.04" y="-30.67" font-family="Times-Roman" font-size="14.00">C:{z}{}{t}</text>
<text text-anchor="middle" x="335.04" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{z}</text>
</g>
<!-- node1&#45;&gt;node0 -->
<g id="edge2" class="edge">
<title>node1&#45;&gt;node0</title>
<path fill="none" stroke="black" d="M404.44,-26.87C424.58,-26.87 446.43,-26.87 466.03,-26.87"/>
<polygon fill="black" stroke="black" points="466.06,-30.37 476.06,-26.87 466.06,-23.37 466.06,-30.37"/>
<text text-anchor="middle" x="425.73" y="-30.67" font-family="Times-Roman" font-size="14.00">{}</text>
</g>
<!-- node4 -->
<g id="node5" class="node">
<title>node4</title>
<ellipse fill="none" stroke="black" cx="933.46" cy="-26.87" rx="35.21" ry="26.74"/>
<text text-anchor="middle" x="933.46" y="-30.67" font-family="Times-Roman" font-size="14.00">C:</text>
<text text-anchor="middle" x="933.46" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{}</text>
<ellipse fill="none" stroke="black" cx="926.52" cy="-26.87" rx="35.21" ry="26.74"/>
<text text-anchor="middle" x="926.52" y="-30.67" font-family="Times-Roman" font-size="14.00">C:</text>
<text text-anchor="middle" x="926.52" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{}</text>
</g>
<!-- node3&#45;&gt;node4 -->
<g id="edge5" class="edge">
<title>node3&#45;&gt;node4</title>
<path fill="none" stroke="black" d="M826.16,-26.87C845.1,-26.87 868.09,-26.87 887.93,-26.87"/>
<polygon fill="black" stroke="black" points="887.98,-30.37 897.98,-26.87 887.98,-23.37 887.98,-30.37"/>
<text text-anchor="middle" x="847.55" y="-30.67" font-family="Times-Roman" font-size="14.00">{}</text>
<!-- node2&#45;&gt;node4 -->
<g id="edge3" class="edge">
<title>node2&#45;&gt;node4</title>
<path fill="none" stroke="black" d="M819.22,-26.87C838.15,-26.87 861.14,-26.87 880.98,-26.87"/>
<polygon fill="black" stroke="black" points="881.03,-30.37 891.03,-26.87 881.03,-23.37 881.03,-30.37"/>
<text text-anchor="middle" x="840.6" y="-30.67" font-family="Times-Roman" font-size="14.00">{}</text>
</g>
<!-- node4&#45;&gt;node4 -->
<g id="edge1" class="edge">
<title>node4&#45;&gt;node4</title>
<path fill="none" stroke="black" d="M967.85,-33.61C978.47,-33.48 986.82,-31.23 986.82,-26.87 986.82,-22.51 978.47,-20.26 967.85,-20.13"/>
<text text-anchor="middle" x="996.32" y="-23.17" font-family="Times-Roman" font-size="14.00">{}</text>
<!-- node3 -->
<g id="node4" class="node">
<title>node3</title>
<ellipse fill="none" stroke="black" cx="96.87" cy="-26.87" rx="96.75" ry="26.74"/>
<text text-anchor="middle" x="96.87" y="-30.67" font-family="Times-Roman" font-size="14.00">C:{x y}{z}{}{t}</text>
<text text-anchor="middle" x="96.87" y="-15.67" font-family="Times-Roman" font-size="14.00">D:{}</text>
</g>
<!-- node3&#45;&gt;node1 -->
<g id="edge4" class="edge">
<title>node3&#45;&gt;node1</title>
<path fill="none" stroke="black" d="M194.09,-26.87C214.46,-26.87 235.72,-26.87 255.37,-26.87"/>
<polygon fill="black" stroke="black" points="255.48,-30.37 265.48,-26.87 255.48,-23.37 255.48,-30.37"/>
<text text-anchor="middle" x="210.73" y="-30.67" font-family="Times-Roman" font-size="14.00">{b}</text>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -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

43
rs.rkt
View File

@ -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))))