Add enabled?.

This commit is contained in:
Sergiu Ivanov 2023-08-08 18:28:25 +02:00
parent 6518ae2fdd
commit 9efca22f7b
2 changed files with 29 additions and 1 deletions

16
rs.rkt
View file

@ -5,7 +5,7 @@
(provide (provide
Species (struct-out reaction) Reaction Species (struct-out reaction) Reaction
make-reaction) make-reaction enabled?)
(module+ test (module+ test
(require typed/rackunit)) (require typed/rackunit))
@ -26,6 +26,20 @@
(test-case "make-reaction" (test-case "make-reaction"
(check-equal? (make-reaction '(a b) '(c d) '(e f)) (check-equal? (make-reaction '(a b) '(c d) '(e f))
(reaction (set 'b 'a) (set 'c 'd) (set 'f 'e))))) (reaction (set 'b 'a) (set 'c 'd) (set 'f 'e)))))
(: enabled? (-> Reaction (Setof Species) Boolean))
(define/match (enabled? r s)
[((reaction r i _) s)
(and (subset? r s) (set-empty? (set-intersect i s)))])
(module+ test
(test-case "enabled?"
(check-true (enabled? (make-reaction '(a b) '(c d) '())
(set 'a 'b 'e)))
(check-false (enabled? (make-reaction '(a b) '(c d) '())
(set 'a 'b 'c)))
(check-false (enabled? (make-reaction '(a b) '(c d) '())
(set 'b 'e)))))
) )
(require graph "utils.rkt" "generic.rkt") (require graph "utils.rkt" "generic.rkt")

View file

@ -59,6 +59,20 @@ instead of set syntax.
(make-reaction '(a b) '(c d) '(e f)) (make-reaction '(a b) '(c d) '(e f))
]} ]}
@defproc[(enabled? [r Reaction] [s (Setof Species)]) Boolean]{
A @racket[Reaction] is enabled on a set of species if all of its
reactants are in the set and none of its inhibitors are.
@ex[
(enabled? (make-reaction '(a b) '(c d) '())
(set 'a 'b 'e))
(enabled? (make-reaction '(a b) '(c d) '())
(set 'a 'b 'c))
(enabled? (make-reaction '(a b) '(c d) '())
(set 'b 'e))
]}
@section{Org-mode interaction} @section{Org-mode interaction}
This section contains some useful primitives for This section contains some useful primitives for