Files
ReactionSystems/src/rsprocess/classical.rs

47 lines
1.2 KiB
Rust
Raw Normal View History

//! Definitions for the 'classical' mechanism for computation.
//!
//! This initial part allows to define the 'classical' mechanism to compute in a
//! Reaction System (RS) Framework.
//! The data is held in RSset or RSreaction, in the latter the reagents,
//! inhibitors and products are held.
2025-05-21 00:03:36 +02:00
#![allow(dead_code)]
2025-05-19 00:10:23 +02:00
use super::structure::{RSset, RSreaction};
/// Computes the result of a single reaction (if enabled returns the products)
/// otherwise returns None.
// see result
pub fn compute_step<'a>(
current_state: &'a RSset,
reaction: &'a RSreaction
) -> Option<&'a RSset> {
2025-05-19 00:10:23 +02:00
if reaction.enabled(current_state) {
Some(reaction.products())
2025-05-19 00:10:23 +02:00
} else {
None
2025-05-19 00:10:23 +02:00
}
}
/// Computes the result of a series of reactions. Returns the union of all
/// products.
// see result
pub fn compute_all<'a>(
current_state: &'a RSset,
reactions: Vec<&'a RSreaction>
) -> RSset {
reactions.iter().fold(
RSset::new(),
|acc, r| acc.union_option(compute_step(current_state, r))
)
}
pub fn compute_all_owned<'a>(
current_state: &'a RSset,
reactions: &'a [RSreaction]
) -> RSset {
reactions.iter().fold(
RSset::new(),
|acc, r| acc.union_option(compute_step(current_state, r))
)
2025-05-19 00:10:23 +02:00
}