Add and use ReactionName.

This commit is contained in:
Sergiu Ivanov 2023-08-09 11:29:09 +02:00
parent d779c52cc8
commit 064169f0b6
2 changed files with 15 additions and 6 deletions

8
rs.rkt
View File

@ -4,7 +4,7 @@
(require typed/graph "utils.rkt" "dynamics.rkt")
(provide
Species (struct-out reaction) Reaction ReactionSystem
Species (struct-out reaction) Reaction ReactionName ReactionSystem
make-reaction enabled? list-enabled)
(module+ test
@ -18,6 +18,8 @@
#:transparent
#:type-name Reaction)
(define-type ReactionName Symbol)
(: make-reaction (-> (Listof Species) (Listof Species) (Listof Species) Reaction))
(define (make-reaction r i p) (reaction (list->set r)
(list->set i)
@ -41,9 +43,9 @@
(check-false (enabled? (make-reaction '(a b) '(c d) '())
(set 'b 'e)))))
(define-type ReactionSystem (HashTable Symbol Reaction))
(define-type ReactionSystem (HashTable ReactionName Reaction))
(: list-enabled (-> ReactionSystem (Setof Species) (Listof Symbol)))
(: list-enabled (-> ReactionSystem (Setof Species) (Listof ReactionName)))
(define (list-enabled rs s)
(for/list ([(name reaction) (in-hash rs)]
#:when (enabled? reaction s))

View File

@ -47,6 +47,12 @@ The type of the instances of @racket[reaction].
}
@deftype[ReactionName]{
A reaction name is any @racket[Symbol].
}
@defproc[(make-reaction [r (Listof Reaction)]
[i (Listof Reaction)]
[p (Listof Reaction)])
@ -75,12 +81,13 @@ reactants are in the set and none of its inhibitors are.
@deftype[ReactionSystem]{
A reaction system is a dictionary mapping reaction names
(@racket[Symbol]s) to @racket[Reaction]s.
A reaction system is a dictionary mapping @racket[ReactionName]s to
@racket[Reaction]s.
}
@defproc[(list-enabled [rs ReactionSystem] [s (Setof Species)]) (Listof Symbol)]{
@defproc[(list-enabled [rs ReactionSystem] [s (Setof Species)])
(Listof ReactionName)]{
Returns the list of the names of reactions of @racket[rs] enabled on
@racket[s].