From 7b4564cd6073e56f43dd6b7c7382d7ba8060dd35 Mon Sep 17 00:00:00 2001 From: elvis Date: Tue, 17 Jun 2025 13:45:35 +0200 Subject: [PATCH] smartOneRunECT, smartRunECT --- src/main.rs | 2 +- src/rsprocess/structure.rs | 15 ++++++++++----- src/rsprocess/transitions.rs | 21 +++++++++++++++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index dd123fc..8b43ce3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,6 +140,6 @@ fn main() -> Result<(), Box> { rsprocess::structure::RSset::from(vec![translator.convert("b")]) ) ])); - println!("{:?}", rsprocess::transitions::one_run(sys)); + println!("{:?}", rsprocess::transitions::run_separated(&sys)); Ok(()) } diff --git a/src/rsprocess/structure.rs b/src/rsprocess/structure.rs index 1e6c15a..0dda472 100644 --- a/src/rsprocess/structure.rs +++ b/src/rsprocess/structure.rs @@ -330,8 +330,8 @@ impl RSsystem { #[derive(Clone, Debug)] pub struct RSlabel { available_entities: RSset, - c: RSset, /// TODO: what is c? what is t? (c comes from choices, t is - t: RSset, /// the union of available_entities and c) + context: RSset, + t: RSset, /// union of available_entities and context reactants: RSset, reactantsi: RSset, inihibitors: RSset, @@ -342,7 +342,7 @@ pub struct RSlabel { impl RSlabel { pub fn new() -> Self { RSlabel { available_entities: RSset::new(), - c: RSset::new(), + context: RSset::new(), t: RSset::new(), reactants: RSset::new(), reactantsi: RSset::new(), @@ -353,7 +353,7 @@ impl RSlabel { #[allow(clippy::too_many_arguments)] pub fn from(available_entities: RSset, - c: RSset, + context: RSset, t: RSset, reactants: RSset, reactantsi: RSset, @@ -361,7 +361,7 @@ impl RSlabel { ireactants: RSset, products: RSset,) -> Self { RSlabel { available_entities, - c, + context, t, reactants, reactantsi, @@ -369,6 +369,11 @@ impl RSlabel { ireactants, products } } + + pub fn get_context(&self) -> (RSset, RSset, RSset) { + // FIXME clone? + (self.available_entities.clone(), self.context.clone(), self.t.clone()) + } } diff --git a/src/rsprocess/transitions.rs b/src/rsprocess/transitions.rs index 0c10cd0..1251381 100644 --- a/src/rsprocess/transitions.rs +++ b/src/rsprocess/transitions.rs @@ -104,7 +104,7 @@ pub fn all_transitions( } // see oneTarget, smartOneTarget, target, smartTarget -pub fn one_target(system: &RSsystem) -> Result<(i64, RSset), String> { +pub fn target(system: &RSsystem) -> Result<(i64, RSset), String> { let current = one_transition(system)?; if current.is_none() { return Ok((0, system.get_available_entities().clone())); @@ -119,10 +119,27 @@ pub fn one_target(system: &RSsystem) -> Result<(i64, RSset), String> { } // see oneRun, run, smartOneRunEK, smartRunEK -pub fn one_run(system: RSsystem) -> Result>, String> { +pub fn run(system: RSsystem) -> Result>, String> { let mut res = vec![Rc::new(system)]; while let Some((_, next_sys)) = one_transition(res.last().unwrap())? { res.push(Rc::new(next_sys)); } Ok(res) } + +// see smartOneRunECT, smartRunECT +pub fn run_separated(system: &RSsystem) -> Result, String> { + let mut res = vec![]; + let current = one_transition(system)?; + if current.is_none() { + return Ok(res); + } + let current = current.unwrap(); + res.push(current.0.get_context()); + let mut current = current.1; + while let Some((label, next)) = one_transition(¤t)? { + current = next; + res.push(label.get_context()); + } + Ok(res) +}