From 871255dbaadafed20762a12734b6bdb890fc0ed5 Mon Sep 17 00:00:00 2001 From: elvis Date: Mon, 16 Jun 2025 16:35:54 +0200 Subject: [PATCH] oneRun, oneTarget --- src/main.rs | 37 +++++++++++++++++++++++++++--------- src/rsprocess/transitions.rs | 12 ++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index c4c1f04..dd123fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ mod rsprocess; use lalrpop_util::lalrpop_mod; -use rsprocess::transitions; use std::rc::Rc; // use std::io; @@ -96,6 +95,33 @@ fn main() -> Result<(), Box> { // ------------------------------------------------------------------------- // parse_ctx("[({a}.nil + {b}.nil),({c}.nil + {d}.nil)]",Ks) , allTransitions(sys([],[],Ks,[react([a],[c],[a]),react([b],[d],[b])]),Moves). + // let env = grammar::EnvironmentParser::new().parse(&mut translator, "[]").unwrap(); + // let process = grammar::ContextParser::new().parse(&mut translator, "[({a}.nil + {b}.nil),({c}.nil + {d}.nil)]").unwrap(); + + // let sys = rsprocess::structure::RSsystem::from(Rc::new(*env), + // rsprocess::structure::RSset::from(vec![]), + // *process, + // Rc::new(vec![ + // rsprocess::structure::RSreaction::from( + // rsprocess::structure::RSset::from(vec![translator.convert("a")]), + // rsprocess::structure::RSset::from(vec![translator.convert("c")]), + // rsprocess::structure::RSset::from(vec![translator.convert("a")]) + // ), + // rsprocess::structure::RSreaction::from( + // rsprocess::structure::RSset::from(vec![translator.convert("b")]), + // rsprocess::structure::RSset::from(vec![translator.convert("d")]), + // rsprocess::structure::RSset::from(vec![translator.convert("b")]) + // ) + // ])); + + // let it = rsprocess::transitions::iterator_transitions(&sys)?; + + // for (n, i) in it.into_iter().enumerate() { + // println!("next i - {n}: {:?}", i); + // println!("--------------------"); + // } + + // ------------------------------------------------------------------------- let env = grammar::EnvironmentParser::new().parse(&mut translator, "[]").unwrap(); let process = grammar::ContextParser::new().parse(&mut translator, "[({a}.nil + {b}.nil),({c}.nil + {d}.nil)]").unwrap(); @@ -114,13 +140,6 @@ fn main() -> Result<(), Box> { rsprocess::structure::RSset::from(vec![translator.convert("b")]) ) ])); - - let it = rsprocess::transitions::iterator_transitions(&sys)?; - - for (n, i) in it.into_iter().enumerate() { - println!("next i - {n}: {:?}", i); - println!("--------------------"); - } - + println!("{:?}", rsprocess::transitions::one_run(sys)); Ok(()) } diff --git a/src/rsprocess/transitions.rs b/src/rsprocess/transitions.rs index 87165a0..0c10cd0 100644 --- a/src/rsprocess/transitions.rs +++ b/src/rsprocess/transitions.rs @@ -87,6 +87,7 @@ pub fn iterator_transitions<'a>( TransitionsIterator::from(system) } +// see oneTransition, transition, smartTransition, smartOneTransition pub fn one_transition( system: &RSsystem, ) -> Result, String> { @@ -94,6 +95,7 @@ pub fn one_transition( Ok(tr.next()) } +// see allTransitions, smartAllTransitions pub fn all_transitions( system: &RSsystem, ) -> Result, String> { @@ -101,6 +103,7 @@ pub fn all_transitions( Ok(tr.collect::>()) } +// see oneTarget, smartOneTarget, target, smartTarget pub fn one_target(system: &RSsystem) -> Result<(i64, RSset), String> { let current = one_transition(system)?; if current.is_none() { @@ -114,3 +117,12 @@ pub fn one_target(system: &RSsystem) -> Result<(i64, RSset), String> { } Ok((n, current.get_available_entities().clone())) } + +// see oneRun, run, smartOneRunEK, smartRunEK +pub fn one_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) +}