dds/rs.rkt

45 lines
1.2 KiB
Racket
Raw Normal View History

2020-03-01 19:05:28 +01:00
#lang typed/racket
;;; dds/rs
;;; Definitions for working with reaction systems.
(provide
;; Structures
reaction
2020-03-01 19:07:16 +01:00
;; Type names
2020-03-01 19:19:58 +01:00
Species ReactionSystem
2020-03-01 19:05:28 +01:00
;; Functions
2020-03-01 19:20:24 +01:00
enabled? list-enabled)
2020-03-01 19:05:28 +01:00
;;; =================
;;; Basic definitions
;;; =================
;;; A species is a symbol.
(define-type Species Symbol)
;;; A reaction is a triple of sets, giving the reactants, the
;;; inhibitors, and the products, respectively.
(struct reaction ([reactants : (Setof Symbol)]
[inhibitors : (Setof Symbol)]
[products : (Setof Symbol)]))
;;; A reaction is enabled on a set if all of its reactants are in the
;;; set and none of its inhibitors are.
(: enabled? (-> reaction (Setof Symbol) Boolean))
(define/match (enabled? r s)
[((reaction r i p) s)
(and (subset? r s) (set-empty? (set-intersect i s)))])
2020-03-01 19:19:58 +01:00
;;; A reaction system is a dictionary mapping reaction names to
;;; reactions.
(define-type ReactionSystem (HashTable Symbol reaction))
2020-03-01 19:20:24 +01:00
;;; Returns the list of reaction names enabled on a given set.
(: list-enabled (-> ReactionSystem (Setof Species) (Listof Symbol)))
2020-03-01 19:20:24 +01:00
(define (list-enabled rs s)
(for/list ([(name reaction) (in-hash rs)]
#:when (enabled? reaction s))
name))