System behind reference

This commit is contained in:
elvis
2025-06-12 20:12:21 +02:00
parent c9e3701460
commit 0975d593f8
3 changed files with 18 additions and 14 deletions

View File

@ -1,5 +1,6 @@
mod rsprocess; mod rsprocess;
use lalrpop_util::lalrpop_mod; use lalrpop_util::lalrpop_mod;
use std::rc::Rc;
// use std::io; // use std::io;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -94,10 +95,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let env = grammar::EnvironmentParser::new().parse("[]").unwrap(); let env = grammar::EnvironmentParser::new().parse("[]").unwrap();
let process = grammar::ContextParser::new().parse("[({a}.nil + {b}.nil),({c}.nil + {d}.nil)]").unwrap(); let process = grammar::ContextParser::new().parse("[({a}.nil + {b}.nil),({c}.nil + {d}.nil)]").unwrap();
let sys = rsprocess::structure::RSsystem::from(*env, let sys = rsprocess::structure::RSsystem::from(Rc::new(*env),
rsprocess::structure::RSset::from(vec![]), rsprocess::structure::RSset::from(vec![]),
*process, *process,
vec![ Rc::new(vec![
rsprocess::structure::RSreaction::from( rsprocess::structure::RSreaction::from(
rsprocess::structure::RSset::from(vec!["a"]), rsprocess::structure::RSset::from(vec!["a"]),
rsprocess::structure::RSset::from(vec!["c"]), rsprocess::structure::RSset::from(vec!["c"]),
@ -108,7 +109,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
rsprocess::structure::RSset::from(vec!["d"]), rsprocess::structure::RSset::from(vec!["d"]),
rsprocess::structure::RSset::from(vec!["b"]) rsprocess::structure::RSset::from(vec!["b"])
) )
]); ]));
let it = rsprocess::transitions::iterator_transitions(&sys)?; let it = rsprocess::transitions::iterator_transitions(&sys)?;

View File

@ -267,30 +267,33 @@ impl<'a> From<Vec<(&'a str, RSprocess<'a>)>> for RSenvironment<'a> {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct RSsystem<'a> { pub struct RSsystem<'a> {
delta: RSenvironment<'a>, delta: Rc<RSenvironment<'a>>,
available_entities: RSset<'a>, available_entities: RSset<'a>,
context_process: RSprocess<'a>, context_process: RSprocess<'a>,
reaction_rules: Vec<RSreaction<'a>>, reaction_rules: Rc<Vec<RSreaction<'a>>>,
} }
impl<'a> RSsystem<'a> { impl<'a> RSsystem<'a> {
pub fn new() -> RSsystem<'a> { pub fn new() -> RSsystem<'a> {
RSsystem { RSsystem {
delta: RSenvironment::new(), delta: Rc::new(RSenvironment::new()),
available_entities: RSset::new(), available_entities: RSset::new(),
context_process: RSprocess::Nill, context_process: RSprocess::Nill,
reaction_rules: vec![], reaction_rules: Rc::new(vec![]),
} }
} }
pub fn from(delta: RSenvironment<'a>, pub fn from(delta: Rc<RSenvironment<'a>>,
available_entities: RSset<'a>, available_entities: RSset<'a>,
context_process: RSprocess<'a>, context_process: RSprocess<'a>,
reaction_rules: Vec<RSreaction<'a>>) -> RSsystem<'a> { reaction_rules: Rc<Vec<RSreaction<'a>>>) -> RSsystem<'a> {
RSsystem { delta, available_entities, context_process, reaction_rules } RSsystem { delta: Rc::clone(&delta),
available_entities,
context_process,
reaction_rules: Rc::clone(&reaction_rules) }
} }
pub fn get_delta(&self) -> &RSenvironment<'a> { pub fn get_delta(&self) -> &Rc<RSenvironment<'a>> {
&self.delta &self.delta
} }
@ -302,7 +305,7 @@ impl<'a> RSsystem<'a> {
&self.context_process &self.context_process
} }
pub fn get_reaction_rules(&self) -> &Vec<RSreaction<'a>> { pub fn get_reaction_rules(&self) -> &Rc<Vec<RSreaction<'a>>> {
&self.reaction_rules &self.reaction_rules
} }
} }

View File

@ -65,10 +65,10 @@ impl<'a> Iterator for TransitionsIterator<'a> {
ireactants, ireactants,
products.clone() products.clone()
); );
let new_system = RSsystem::from(self.system.get_delta().clone(), let new_system = RSsystem::from(Rc::clone(self.system.get_delta()),
products, products,
(*k).clone(), (*k).clone(),
self.system.get_reaction_rules().clone() Rc::clone(self.system.get_reaction_rules())
); );
Some((label, new_system)) Some((label, new_system))
} }