smartOneRunECT, smartRunECT

This commit is contained in:
elvis
2025-06-17 13:45:35 +02:00
parent 871255dbaa
commit 7b4564cd60
3 changed files with 30 additions and 8 deletions

View File

@ -140,6 +140,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
rsprocess::structure::RSset::from(vec![translator.convert("b")]) rsprocess::structure::RSset::from(vec![translator.convert("b")])
) )
])); ]));
println!("{:?}", rsprocess::transitions::one_run(sys)); println!("{:?}", rsprocess::transitions::run_separated(&sys));
Ok(()) Ok(())
} }

View File

@ -330,8 +330,8 @@ impl RSsystem {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct RSlabel { pub struct RSlabel {
available_entities: RSset, available_entities: RSset,
c: RSset, /// TODO: what is c? what is t? (c comes from choices, t is context: RSset,
t: RSset, /// the union of available_entities and c) t: RSset, /// union of available_entities and context
reactants: RSset, reactants: RSset,
reactantsi: RSset, reactantsi: RSset,
inihibitors: RSset, inihibitors: RSset,
@ -342,7 +342,7 @@ pub struct RSlabel {
impl RSlabel { impl RSlabel {
pub fn new() -> Self { pub fn new() -> Self {
RSlabel { available_entities: RSset::new(), RSlabel { available_entities: RSset::new(),
c: RSset::new(), context: RSset::new(),
t: RSset::new(), t: RSset::new(),
reactants: RSset::new(), reactants: RSset::new(),
reactantsi: RSset::new(), reactantsi: RSset::new(),
@ -353,7 +353,7 @@ impl RSlabel {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn from(available_entities: RSset, pub fn from(available_entities: RSset,
c: RSset, context: RSset,
t: RSset, t: RSset,
reactants: RSset, reactants: RSset,
reactantsi: RSset, reactantsi: RSset,
@ -361,7 +361,7 @@ impl RSlabel {
ireactants: RSset, ireactants: RSset,
products: RSset,) -> Self { products: RSset,) -> Self {
RSlabel { available_entities, RSlabel { available_entities,
c, context,
t, t,
reactants, reactants,
reactantsi, reactantsi,
@ -369,6 +369,11 @@ impl RSlabel {
ireactants, ireactants,
products } products }
} }
pub fn get_context(&self) -> (RSset, RSset, RSset) {
// FIXME clone?
(self.available_entities.clone(), self.context.clone(), self.t.clone())
}
} }

View File

@ -104,7 +104,7 @@ pub fn all_transitions(
} }
// see oneTarget, smartOneTarget, target, smartTarget // 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)?; let current = one_transition(system)?;
if current.is_none() { if current.is_none() {
return Ok((0, system.get_available_entities().clone())); 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 // see oneRun, run, smartOneRunEK, smartRunEK
pub fn one_run(system: RSsystem) -> Result<Vec<Rc<RSsystem>>, String> { pub fn run(system: RSsystem) -> Result<Vec<Rc<RSsystem>>, String> {
let mut res = vec![Rc::new(system)]; let mut res = vec![Rc::new(system)];
while let Some((_, next_sys)) = one_transition(res.last().unwrap())? { while let Some((_, next_sys)) = one_transition(res.last().unwrap())? {
res.push(Rc::new(next_sys)); res.push(Rc::new(next_sys));
} }
Ok(res) Ok(res)
} }
// see smartOneRunECT, smartRunECT
pub fn run_separated(system: &RSsystem) -> Result<Vec<(RSset, RSset, RSset)>, 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(&current)? {
current = next;
res.push(label.get_context());
}
Ok(res)
}