Refactoring names of structures, removing useless functions
This commit is contained in:
@ -16,7 +16,7 @@ pub fn compute_step<'a>(
|
||||
reaction: &'a RSreaction
|
||||
) -> Option<&'a RSset> {
|
||||
if reaction.enabled(current_state) {
|
||||
Some(reaction.products())
|
||||
Some(&reaction.products)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ impl GraphMapNodesTy {
|
||||
format!("{}",
|
||||
translator::RSsetDisplay::from(
|
||||
&translator,
|
||||
node.get_available_entities())
|
||||
&node.available_entities)
|
||||
)
|
||||
)
|
||||
},
|
||||
@ -94,7 +94,7 @@ impl GraphMapNodesTy {
|
||||
Box::new(
|
||||
move |_, node: &RSsystem| {
|
||||
let masked_entities =
|
||||
node.get_available_entities()
|
||||
node.available_entities
|
||||
.intersection(&mask);
|
||||
format!("{}",
|
||||
translator::RSsetDisplay::from(
|
||||
@ -110,7 +110,7 @@ impl GraphMapNodesTy {
|
||||
format!("{}",
|
||||
translator::RSprocessDisplay::from(
|
||||
&translator,
|
||||
node.get_context_process())
|
||||
&node.context_process)
|
||||
)
|
||||
)
|
||||
},
|
||||
@ -373,7 +373,7 @@ pub fn default_node_formatter(
|
||||
Box::new(
|
||||
move |_g, n|
|
||||
String::from(
|
||||
match original_graph.node_weight(n.0).unwrap().get_context_process()
|
||||
match original_graph.node_weight(n.0).unwrap().context_process
|
||||
{
|
||||
RSprocess::Nill =>
|
||||
", fillcolor=white",
|
||||
|
||||
@ -115,9 +115,9 @@ pub fn lollipops_decomposed(
|
||||
// see lollipop
|
||||
pub fn lollipops(system: RSsystem) -> Vec<(Vec<RSset>, Vec<RSset>)> {
|
||||
lollipops_decomposed(
|
||||
system.get_delta(),
|
||||
system.get_reaction_rules(),
|
||||
system.get_available_entities(),
|
||||
&system.delta,
|
||||
&system.reaction_rules,
|
||||
&system.available_entities,
|
||||
)
|
||||
}
|
||||
|
||||
@ -125,12 +125,12 @@ pub fn lollipops(system: RSsystem) -> Vec<(Vec<RSset>, Vec<RSset>)> {
|
||||
pub fn lollipops_only_loop(system: RSsystem) -> Vec<Vec<RSset>> {
|
||||
// FIXME: i think we are only interested in "x", not all symbols that
|
||||
// satisfy X = pre(Q, rec(X))
|
||||
let filtered = system.get_delta().iter().filter_map(filter_delta);
|
||||
let filtered = system.delta.iter().filter_map(filter_delta);
|
||||
|
||||
let find_loop_fn = |q| {
|
||||
find_only_loop(
|
||||
system.get_reaction_rules(),
|
||||
system.get_available_entities().clone(),
|
||||
&system.reaction_rules,
|
||||
system.available_entities.clone(),
|
||||
q,
|
||||
)
|
||||
};
|
||||
@ -226,9 +226,9 @@ pub fn lollipops_named(
|
||||
symb: IdType
|
||||
) -> Option<(Vec<RSset>, Vec<RSset>)> {
|
||||
lollipops_decomposed_named(
|
||||
system.get_delta(),
|
||||
system.get_reaction_rules(),
|
||||
system.get_available_entities(),
|
||||
&system.delta,
|
||||
&system.reaction_rules,
|
||||
&system.available_entities,
|
||||
symb,
|
||||
)
|
||||
}
|
||||
@ -239,15 +239,15 @@ pub fn lollipops_only_loop_named(
|
||||
symb: IdType
|
||||
) -> Option<Vec<RSset>> {
|
||||
let filtered = system
|
||||
.get_delta()
|
||||
.delta
|
||||
.iter()
|
||||
.filter_map(|x| filter_delta_named(x, &symb))
|
||||
.next();
|
||||
|
||||
let find_loop_fn = |q| {
|
||||
find_only_loop(
|
||||
system.get_reaction_rules(),
|
||||
system.get_available_entities().clone(),
|
||||
&system.reaction_rules,
|
||||
system.available_entities.clone(),
|
||||
q,
|
||||
)
|
||||
};
|
||||
|
||||
@ -13,17 +13,17 @@ pub fn of_RSsystem<'a>(translator: &'a Translator, system: &'a RSsystem) -> Stri
|
||||
);
|
||||
result.push_str(&format!(
|
||||
"the initial state has {} entities:\n",
|
||||
system.get_available_entities().len()
|
||||
system.available_entities.len()
|
||||
));
|
||||
result.push_str(&format!(
|
||||
"{}\n",
|
||||
translator::RSsetDisplay::from(translator, system.get_available_entities())
|
||||
translator::RSsetDisplay::from(translator, &system.available_entities)
|
||||
));
|
||||
|
||||
let reactants = system
|
||||
.get_reaction_rules()
|
||||
.reaction_rules
|
||||
.iter()
|
||||
.fold(RSset::new(), |acc, new| acc.union(new.reactants()));
|
||||
.fold(RSset::new(), |acc, new| acc.union(&new.reactants));
|
||||
result.push_str(&format!(
|
||||
"The reactants are {}:\n{}\n",
|
||||
reactants.len(),
|
||||
@ -31,9 +31,9 @@ pub fn of_RSsystem<'a>(translator: &'a Translator, system: &'a RSsystem) -> Stri
|
||||
));
|
||||
|
||||
let inhibitors = system
|
||||
.get_reaction_rules()
|
||||
.reaction_rules
|
||||
.iter()
|
||||
.fold(RSset::new(), |acc, new| acc.union(new.inihibitors()));
|
||||
.fold(RSset::new(), |acc, new| acc.union(&new.inihibitors));
|
||||
result.push_str(&format!(
|
||||
"The inhibitors are {}:\n{}\n",
|
||||
inhibitors.len(),
|
||||
@ -41,9 +41,9 @@ pub fn of_RSsystem<'a>(translator: &'a Translator, system: &'a RSsystem) -> Stri
|
||||
));
|
||||
|
||||
let products = system
|
||||
.get_reaction_rules()
|
||||
.reaction_rules
|
||||
.iter()
|
||||
.fold(RSset::new(), |acc, new| acc.union(new.products()));
|
||||
.fold(RSset::new(), |acc, new| acc.union(&new.products));
|
||||
result.push_str(&format!(
|
||||
"The products are {}:\n{}\n",
|
||||
products.len(),
|
||||
@ -57,14 +57,14 @@ pub fn of_RSsystem<'a>(translator: &'a Translator, system: &'a RSsystem) -> Stri
|
||||
translator::RSsetDisplay::from(translator, &total)
|
||||
));
|
||||
|
||||
let entities_env = system.get_delta().all_elements();
|
||||
let entities_env = system.delta.all_elements();
|
||||
result.push_str(&format!(
|
||||
"The environment involves {} entities:\n{}\n",
|
||||
entities_env.len(),
|
||||
translator::RSsetDisplay::from(translator, &entities_env)
|
||||
));
|
||||
|
||||
let entities_context = system.get_context_process().all_elements();
|
||||
let entities_context = system.context_process.all_elements();
|
||||
result.push_str(&format!(
|
||||
"The context involves {} entities:\n{}\n",
|
||||
entities_context.len(),
|
||||
@ -74,7 +74,7 @@ pub fn of_RSsystem<'a>(translator: &'a Translator, system: &'a RSsystem) -> Stri
|
||||
let entities_all = total
|
||||
.union(&entities_env)
|
||||
.union(&entities_context)
|
||||
.union(system.get_available_entities());
|
||||
.union(&system.available_entities);
|
||||
|
||||
result.push_str(&format!(
|
||||
"The whole RS involves {} entities:\n{}\n",
|
||||
@ -83,7 +83,7 @@ pub fn of_RSsystem<'a>(translator: &'a Translator, system: &'a RSsystem) -> Stri
|
||||
));
|
||||
|
||||
let possible_e = products
|
||||
.union(system.get_available_entities())
|
||||
.union(&system.available_entities)
|
||||
.union(&entities_context);
|
||||
let missing_e = reactants.subtraction(&possible_e);
|
||||
result.push_str(&format!(
|
||||
@ -101,14 +101,14 @@ pub fn of_RSsystem<'a>(translator: &'a Translator, system: &'a RSsystem) -> Stri
|
||||
|
||||
result.push_str(&format!(
|
||||
"There are {} reactions in total.\n",
|
||||
system.get_reaction_rules().len()
|
||||
system.reaction_rules.len()
|
||||
));
|
||||
|
||||
let mut admissible_reactions = vec![];
|
||||
let mut nonadmissible_reactions = vec![];
|
||||
|
||||
for reaction in system.get_reaction_rules().iter() {
|
||||
if reaction.reactants().is_disjoint(&missing_e) {
|
||||
for reaction in system.reaction_rules.iter() {
|
||||
if reaction.reactants.is_disjoint(&missing_e) {
|
||||
admissible_reactions.push(reaction);
|
||||
} else {
|
||||
nonadmissible_reactions.push(reaction);
|
||||
|
||||
@ -10,7 +10,7 @@ use std::rc::Rc;
|
||||
// -----------------------------------------------------------------------------
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct RSset {
|
||||
identifiers: BTreeSet<IdType>,
|
||||
pub identifiers: BTreeSet<IdType>,
|
||||
}
|
||||
|
||||
impl<const N: usize> From<[IdType; N]> for RSset {
|
||||
@ -89,10 +89,6 @@ impl RSset {
|
||||
RSset { identifiers: res }
|
||||
}
|
||||
|
||||
pub fn set(&self) -> &BTreeSet<IdType> {
|
||||
&self.identifiers
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> std::collections::btree_set::Iter<'_, IdType> {
|
||||
self.identifiers.iter()
|
||||
}
|
||||
@ -134,9 +130,9 @@ impl IntoIterator for RSset {
|
||||
// -----------------------------------------------------------------------------
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RSreaction {
|
||||
reactants: RSset,
|
||||
inihibitors: RSset,
|
||||
products: RSset,
|
||||
pub reactants: RSset,
|
||||
pub inihibitors: RSset,
|
||||
pub products: RSset,
|
||||
}
|
||||
|
||||
impl RSreaction {
|
||||
@ -161,22 +157,6 @@ impl RSreaction {
|
||||
self.reactants.is_subset(current_state)
|
||||
&& self.inihibitors.is_disjoint(current_state)
|
||||
}
|
||||
|
||||
pub fn products_clone(&self) -> RSset {
|
||||
self.products.clone()
|
||||
}
|
||||
|
||||
pub fn reactants(&self) -> &RSset {
|
||||
&self.reactants
|
||||
}
|
||||
|
||||
pub fn inihibitors(&self) -> &RSset {
|
||||
&self.inihibitors
|
||||
}
|
||||
|
||||
pub fn products(&self) -> &RSset {
|
||||
&self.products
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RSreaction {
|
||||
@ -434,10 +414,10 @@ impl From<Vec<(IdType, RSprocess)>> for RSenvironment {
|
||||
// -----------------------------------------------------------------------------
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RSsystem {
|
||||
delta: Rc<RSenvironment>,
|
||||
available_entities: RSset,
|
||||
context_process: RSprocess,
|
||||
reaction_rules: Rc<Vec<RSreaction>>,
|
||||
pub delta: Rc<RSenvironment>,
|
||||
pub available_entities: RSset,
|
||||
pub context_process: RSprocess,
|
||||
pub reaction_rules: Rc<Vec<RSreaction>>,
|
||||
}
|
||||
|
||||
impl RSsystem {
|
||||
@ -463,24 +443,10 @@ impl RSsystem {
|
||||
reaction_rules: Rc::clone(&reaction_rules),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_delta(&self) -> &Rc<RSenvironment> {
|
||||
&self.delta
|
||||
}
|
||||
|
||||
pub fn get_available_entities(&self) -> &RSset {
|
||||
&self.available_entities
|
||||
}
|
||||
|
||||
pub fn get_context_process(&self) -> &RSprocess {
|
||||
&self.context_process
|
||||
}
|
||||
|
||||
pub fn get_reaction_rules(&self) -> &Rc<Vec<RSreaction>> {
|
||||
&self.reaction_rules
|
||||
}
|
||||
}
|
||||
|
||||
/// Equality does not care about delta or reaction rules, only entities and
|
||||
/// context is compared
|
||||
impl PartialEq for RSsystem {
|
||||
// we ignore delta and reaction rules
|
||||
fn eq(&self, other: &RSsystem) -> bool {
|
||||
@ -489,8 +455,12 @@ impl PartialEq for RSsystem {
|
||||
}
|
||||
}
|
||||
|
||||
/// Equality does not care about delta or reaction rules, only entities and
|
||||
/// context is compared
|
||||
impl Eq for RSsystem {}
|
||||
|
||||
/// Hash does not care about delta or reaction rules, only entities and
|
||||
/// context is hashed
|
||||
impl Hash for RSsystem {
|
||||
// ignores delta and reaction rules
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
@ -513,11 +483,10 @@ pub struct RSlabel {
|
||||
pub available_entities: RSset,
|
||||
pub context: RSset,
|
||||
pub t: RSset,
|
||||
/// union of available_entities and context
|
||||
pub reactants: RSset,
|
||||
pub reactantsi: RSset, // reactants absent
|
||||
pub reactants_absent: RSset,
|
||||
pub inihibitors: RSset,
|
||||
pub ireactants: RSset, // inhibitors present
|
||||
pub inihibitors_present: RSset,
|
||||
pub products: RSset,
|
||||
}
|
||||
|
||||
@ -528,9 +497,9 @@ impl RSlabel {
|
||||
context: RSset::new(),
|
||||
t: RSset::new(),
|
||||
reactants: RSset::new(),
|
||||
reactantsi: RSset::new(),
|
||||
reactants_absent: RSset::new(),
|
||||
inihibitors: RSset::new(),
|
||||
ireactants: RSset::new(),
|
||||
inihibitors_present: RSset::new(),
|
||||
products: RSset::new(),
|
||||
}
|
||||
}
|
||||
@ -541,9 +510,9 @@ impl RSlabel {
|
||||
context: RSset,
|
||||
t: RSset,
|
||||
reactants: RSset,
|
||||
reactantsi: RSset,
|
||||
reactants_absent: RSset,
|
||||
inihibitors: RSset,
|
||||
ireactants: RSset,
|
||||
inihibitors_present: RSset,
|
||||
products: RSset,
|
||||
) -> Self {
|
||||
RSlabel {
|
||||
@ -551,19 +520,18 @@ impl RSlabel {
|
||||
context,
|
||||
t,
|
||||
reactants,
|
||||
reactantsi,
|
||||
reactants_absent,
|
||||
inihibitors,
|
||||
ireactants,
|
||||
inihibitors_present,
|
||||
products,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_context(&self) -> (RSset, RSset, RSset) {
|
||||
// TODO remove clone?
|
||||
pub fn get_context(&self) -> (&RSset, &RSset, &RSset) {
|
||||
(
|
||||
self.available_entities.clone(),
|
||||
self.context.clone(),
|
||||
self.t.clone(),
|
||||
&self.available_entities,
|
||||
&self.context,
|
||||
&self.t,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ impl<'a> TransitionsIterator<'a> {
|
||||
pub fn from(
|
||||
system: &'a RSsystem
|
||||
) -> Result<TransitionsIterator<'a>, String> {
|
||||
match unfold(system.get_delta(), system.get_context_process()) {
|
||||
match unfold(&system.delta, &system.context_process) {
|
||||
Ok(o) => Ok(TransitionsIterator {
|
||||
choices_iterator: o.into_iter(),
|
||||
system,
|
||||
@ -28,9 +28,9 @@ impl<'a> Iterator for TransitionsIterator<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<(RSlabel, RSsystem)> {
|
||||
let (c, k) = self.choices_iterator.next()?;
|
||||
let t = self.system.get_available_entities().union(c.as_ref());
|
||||
let t = self.system.available_entities.union(c.as_ref());
|
||||
let (reactants, reactantsi, inihibitors, ireactants, products) =
|
||||
self.system.get_reaction_rules().iter().fold(
|
||||
self.system.reaction_rules.iter().fold(
|
||||
(
|
||||
RSset::new(), // reactants
|
||||
RSset::new(), // reactantsi
|
||||
@ -41,18 +41,18 @@ impl<'a> Iterator for TransitionsIterator<'a> {
|
||||
|acc, reaction| {
|
||||
if reaction.enabled(&t) {
|
||||
(
|
||||
acc.0.union(reaction.reactants()),
|
||||
acc.0.union(&reaction.reactants),
|
||||
acc.1,
|
||||
acc.2.union(reaction.inihibitors()),
|
||||
acc.2.union(&reaction.inihibitors),
|
||||
acc.3,
|
||||
acc.4.union(reaction.products()),
|
||||
acc.4.union(&reaction.products),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
acc.0,
|
||||
acc.1.union(&reaction.inihibitors().intersection(&t)),
|
||||
acc.1.union(&reaction.inihibitors.intersection(&t)),
|
||||
acc.2,
|
||||
acc.3.union(&reaction.reactants().subtraction(&t)),
|
||||
acc.3.union(&reaction.reactants.subtraction(&t)),
|
||||
acc.4,
|
||||
)
|
||||
}
|
||||
@ -60,7 +60,7 @@ impl<'a> Iterator for TransitionsIterator<'a> {
|
||||
);
|
||||
|
||||
let label = RSlabel::from(
|
||||
self.system.get_available_entities().clone(),
|
||||
self.system.available_entities.clone(),
|
||||
(*c).clone(),
|
||||
t,
|
||||
reactants,
|
||||
@ -70,10 +70,10 @@ impl<'a> Iterator for TransitionsIterator<'a> {
|
||||
products.clone(),
|
||||
);
|
||||
let new_system = RSsystem::from(
|
||||
Rc::clone(self.system.get_delta()),
|
||||
Rc::clone(&self.system.delta),
|
||||
products,
|
||||
(*k).clone(),
|
||||
Rc::clone(self.system.get_reaction_rules()),
|
||||
Rc::clone(&self.system.reaction_rules),
|
||||
);
|
||||
Some((label, new_system))
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ pub fn target(
|
||||
) -> Result<(i64, RSset), String> {
|
||||
let current = one_transition(system)?;
|
||||
if current.is_none() {
|
||||
return Ok((0, system.get_available_entities().clone()));
|
||||
return Ok((0, system.available_entities.clone()));
|
||||
}
|
||||
let mut n = 1;
|
||||
let mut current = current.unwrap().1;
|
||||
@ -123,7 +123,7 @@ pub fn target(
|
||||
current = next;
|
||||
n += 1;
|
||||
}
|
||||
Ok((n, current.get_available_entities().clone()))
|
||||
Ok((n, current.available_entities.clone()))
|
||||
}
|
||||
|
||||
// see oneRun, run, smartOneRunEK, smartRunEK
|
||||
@ -145,11 +145,13 @@ pub fn run_separated(
|
||||
return Ok(res);
|
||||
}
|
||||
let current = current.unwrap();
|
||||
res.push(current.0.get_context());
|
||||
let (available_entities, context, t) = current.0.get_context();
|
||||
res.push((available_entities.clone(), context.clone(), t.clone()));
|
||||
let mut current = current.1;
|
||||
while let Some((label, next)) = one_transition(¤t)? {
|
||||
current = next;
|
||||
res.push(label.get_context());
|
||||
let (available_entities, context, t) = label.get_context();
|
||||
res.push((available_entities.clone(), context.clone(), t.clone()));
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
@ -121,9 +121,9 @@ fn print_reaction(
|
||||
write!(
|
||||
f,
|
||||
"(r: {}, i: {}, p: {})",
|
||||
RSsetDisplay::from(translator, reaction.reactants()),
|
||||
RSsetDisplay::from(translator, reaction.inihibitors()),
|
||||
RSsetDisplay::from(translator, reaction.products())
|
||||
RSsetDisplay::from(translator, &reaction.reactants),
|
||||
RSsetDisplay::from(translator, &reaction.inihibitors),
|
||||
RSsetDisplay::from(translator, &reaction.products)
|
||||
)
|
||||
}
|
||||
|
||||
@ -294,11 +294,11 @@ fn print_system(
|
||||
write!(
|
||||
f,
|
||||
"[delta: {}, available_entities: {}, context_process: {}, reaction_rules: [",
|
||||
RSenvironmentDisplay::from(translator, system.get_delta()),
|
||||
RSsetDisplay::from(translator, system.get_available_entities()),
|
||||
RSprocessDisplay::from(translator, system.get_context_process())
|
||||
RSenvironmentDisplay::from(translator, &system.delta),
|
||||
RSsetDisplay::from(translator, &system.available_entities),
|
||||
RSprocessDisplay::from(translator, &system.context_process)
|
||||
)?;
|
||||
let mut it = system.get_reaction_rules().iter().peekable();
|
||||
let mut it = system.reaction_rules.iter().peekable();
|
||||
while let Some(el) = it.next() {
|
||||
if it.peek().is_none() {
|
||||
write!(f, "{}", RSreactionDisplay::from(translator, el))?;
|
||||
@ -327,9 +327,9 @@ fn print_label(
|
||||
RSsetDisplay::from(translator, &label.context),
|
||||
RSsetDisplay::from(translator, &label.t),
|
||||
RSsetDisplay::from(translator, &label.reactants),
|
||||
RSsetDisplay::from(translator, &label.reactantsi),
|
||||
RSsetDisplay::from(translator, &label.reactants_absent),
|
||||
RSsetDisplay::from(translator, &label.inihibitors),
|
||||
RSsetDisplay::from(translator, &label.ireactants),
|
||||
RSsetDisplay::from(translator, &label.inihibitors_present),
|
||||
RSsetDisplay::from(translator, &label.products),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user