rs: Add build-interactive-process.
This commit is contained in:
parent
9cfab2e45d
commit
9ce3040240
2 changed files with 28 additions and 1 deletions
10
rs-tests.rkt
10
rs-tests.rkt
|
@ -73,4 +73,12 @@
|
|||
(state (set 'y 'z) (list (set 'y) (set 'z) (set) (set 'z))))
|
||||
(set (set 'a 'b)))
|
||||
|
||||
(check-equal? sgr ip)))
|
||||
(check-equal? sgr ip)
|
||||
|
||||
(check-equal? (build-interactive-process rs (list (set 'x) (set 'y) (set 'z) (set) (set 'z)))
|
||||
(list
|
||||
(list (set 'x) (set))
|
||||
(list (set 'y) (set 'y 'z))
|
||||
(list (set 'z) (set))
|
||||
(list (set) (set))
|
||||
(list (set 'z) (set))))))
|
||||
|
|
19
rs.rkt
19
rs.rkt
|
@ -27,6 +27,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-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
|
||||
(contract-out [species? (-> any/c boolean?)])
|
||||
|
@ -173,6 +174,24 @@
|
|||
(dds-build-state-graph-annotated (dynamics rs)
|
||||
(set (state (set) contexts))))
|
||||
|
||||
;;; 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
|
||||
;;; result of the application of reactions to the previous state. The
|
||||
;;; interactive process stops when there are no more contexts left.
|
||||
(define (build-interactive-process rs contexts)
|
||||
(let ([dyn (dynamics rs)])
|
||||
(for/fold ([proc '()]
|
||||
[st (state (set) contexts)]
|
||||
#:result (reverse proc))
|
||||
([c contexts])
|
||||
(values
|
||||
(cons (match st
|
||||
[(state res ctx)
|
||||
(list (if (empty? ctx) (set) (car ctx)) res)])
|
||||
proc)
|
||||
(set-first (dds-step-one dyn st))))))
|
||||
|
||||
;;; Pretty-prints the context sequence and the current result of a
|
||||
;;; state of the reaction system. Note that we need to keep the full
|
||||
;;; context sequence in the name of each state to avoid confusion
|
||||
|
|
Loading…
Reference in a new issue