use std::collections::{BTreeMap, HashSet}; // ----------------------------------------------------------------------------- // RSset // ----------------------------------------------------------------------------- #[derive(Clone, Debug)] #[allow(dead_code)] pub struct RSset<'a> { identifiers: HashSet<&'a str> } impl<'a, const N: usize> From<[&'a str; N]> for RSset<'a> { fn from(arr: [&'a str; N]) -> Self { RSset{identifiers: HashSet::from(arr)} } } impl<'a> From<&[&'a str]> for RSset<'a> { fn from(arr: &[&'a str]) -> Self { RSset{identifiers: HashSet::from_iter(arr.to_vec())} } } impl<'a> From> for RSset<'a> { fn from(arr: Vec<&'a str>) -> Self { RSset{identifiers: HashSet::from_iter(arr)} } } impl<'a> RSset<'a> { pub fn new() -> Self { RSset{identifiers: HashSet::new()} } pub fn is_subset(&self, b: &RSset<'a>) -> bool { self.identifiers.is_subset(&b.identifiers) } pub fn is_disjoint(&self, b: &RSset<'a>) -> bool { self.identifiers.is_disjoint(&b.identifiers) } #[allow(dead_code)] pub fn union(&self, b: &RSset<'a>) -> RSset<'a> { // TODO maybe find more efficient way let mut ret: RSset = b.clone(); ret.identifiers.extend(self.identifiers.iter()); ret } pub fn union_option(&self, b: Option<&RSset<'a>>) -> RSset<'a> { if let Some(b) = b { // TODO maybe find more efficient way let mut ret: RSset = b.clone(); ret.identifiers.extend(self.identifiers.iter()); ret } else { self.clone() } } } // ----------------------------------------------------------------------------- // RSreaction // ----------------------------------------------------------------------------- #[derive(Clone, Debug)] #[allow(dead_code)] pub struct RSreaction<'a> { reactants: RSset<'a>, inihibitors: RSset<'a>, products: RSset<'a> } impl<'a> RSreaction<'a> { #[allow(dead_code)] pub fn new() -> Self { RSreaction{ reactants: RSset::new(), inihibitors: RSset::new(), products: RSset::new(), } } pub fn from(reactants: RSset<'a>, inihibitors: RSset<'a>, products: RSset<'a>) -> Self { RSreaction{ reactants, inihibitors, products } } pub fn enabled(&self, current_state: &RSset<'a>) -> bool { self.reactants.is_subset(current_state) && self.inihibitors.is_disjoint(current_state) } #[allow(dead_code)] pub fn products_clone(&self) -> RSset<'a> { self.products.clone() } pub fn products(&self) -> &RSset<'a> { &self.products } } // ----------------------------------------------------------------------------- // RSprocess // ----------------------------------------------------------------------------- #[derive(Clone, Debug)] #[allow(dead_code)] pub enum RSprocess<'a> { Nill, ConstantIdentifier{identifier: &'a str}, EntitySet{entities: RSset<'a>, next_process: Box>}, WaitEntity{repeat: i64, repeated_process: Box>, next_process: Box>}, NondeterministicChoice{children: Vec>}, Summation{children: Vec>} } // ----------------------------------------------------------------------------- // RSenvironment // ----------------------------------------------------------------------------- #[derive(Clone, Debug)] #[allow(dead_code)] pub struct RSenvironment<'a> { definitions: BTreeMap<&'a str, Box>>, } impl<'a> RSenvironment<'a> { pub fn new() -> RSenvironment<'a> { RSenvironment{definitions: BTreeMap::new()} } } impl<'a, const N: usize> From<[(&'a str, Box>); N]> for RSenvironment<'a> { fn from(arr: [(&'a str, Box>); N]) -> Self { RSenvironment{definitions: BTreeMap::from(arr)} } } impl<'a> From<&[(&'a str, Box>)]> for RSenvironment<'a> { fn from(arr: &[(&'a str, Box>)]) -> Self { RSenvironment{definitions: BTreeMap::from_iter(arr.to_vec())} } } impl<'a> From>)>> for RSenvironment<'a> { fn from(arr: Vec<(&'a str, Box>)>) -> Self { RSenvironment{definitions: BTreeMap::from_iter(arr)} } } // ----------------------------------------------------------------------------- // RSassertOp // ----------------------------------------------------------------------------- #[derive(Clone, Debug)] #[allow(dead_code)] pub enum RSassertOp { InW, InR, InI, InP } // ----------------------------------------------------------------------------- // RSassert // ----------------------------------------------------------------------------- #[derive(Clone, Debug)] #[allow(dead_code)] pub enum RSassert<'a> { Not(Box>), Xor(Box>, Box>), Or(Vec>), And(Vec>), Sub(RSset<'a>, RSassertOp), NonEmpty(RSassertOp) } // ----------------------------------------------------------------------------- // RSBHML // ----------------------------------------------------------------------------- #[derive(Clone, Debug)] #[allow(dead_code)] #[allow(clippy::upper_case_acronyms)] pub enum RSBHML<'a> { True, False, Or(Vec>), And(Vec>), Diamond(Box>, Box>), Box(Box>, Box>) }