oneRun, oneTarget
This commit is contained in:
37
src/main.rs
37
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<dyn std::error::Error>> {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 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<dyn std::error::Error>> {
|
||||
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(())
|
||||
}
|
||||
|
||||
@ -87,6 +87,7 @@ pub fn iterator_transitions<'a>(
|
||||
TransitionsIterator::from(system)
|
||||
}
|
||||
|
||||
// see oneTransition, transition, smartTransition, smartOneTransition
|
||||
pub fn one_transition(
|
||||
system: &RSsystem,
|
||||
) -> Result<Option<(RSlabel, RSsystem)>, String> {
|
||||
@ -94,6 +95,7 @@ pub fn one_transition(
|
||||
Ok(tr.next())
|
||||
}
|
||||
|
||||
// see allTransitions, smartAllTransitions
|
||||
pub fn all_transitions(
|
||||
system: &RSsystem,
|
||||
) -> Result<Vec<(RSlabel, RSsystem)>, String> {
|
||||
@ -101,6 +103,7 @@ pub fn all_transitions(
|
||||
Ok(tr.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
// 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<Vec<Rc<RSsystem>>, 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user