This commit is contained in:
elvis
2025-10-28 14:01:49 +01:00
parent 975b67bc79
commit f90308a11e
11 changed files with 474 additions and 197 deletions

View File

@ -20,7 +20,6 @@ impl PrintableWithTranslator for IdType {
}
}
// -----------------------------------------------------------------------------
#[derive(

View File

@ -813,8 +813,9 @@ impl From<Environment> for PositiveEnvironment {
}
}
impl<const N: usize> From<[(IdType, PositiveProcess); N]> for PositiveEnvironment {
impl<const N: usize> From<[(IdType, PositiveProcess); N]>
for PositiveEnvironment
{
fn from(arr: [(IdType, PositiveProcess); N]) -> Self {
Self {
definitions: BTreeMap::from(arr),

View File

@ -14,8 +14,8 @@ use super::translator;
pub type SystemGraph = Graph<System, Label, Directed, u32>;
pub type PositiveSystemGraph = Graph<PositiveSystem, PositiveLabel, Directed, u32>;
pub type PositiveSystemGraph =
Graph<PositiveSystem, PositiveLabel, Directed, u32>;
fn common_system_entities(graph: &SystemGraph) -> Set {
graph

View File

@ -88,7 +88,6 @@ impl BasicLabel for Label {
&self.products
}
fn set_available_entities(&mut self, set: Self::Set) {
self.available_entities = set;
}
@ -265,7 +264,6 @@ impl BasicLabel for PositiveLabel {
&self.products
}
fn set_available_entities(&mut self, set: Self::Set) {
self.available_entities = set;
}

View File

@ -226,7 +226,9 @@ impl Reaction {
// -----------------------------------------------------------------------------
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[derive(
Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash,
)]
pub struct PositiveReaction {
pub reactants: PositiveSet,
pub products: PositiveSet,
@ -311,14 +313,15 @@ impl PositiveReaction {
// Convert from list of reactions to list of positive reactions
impl Reaction {
pub fn into_positive_reactions(reactions: &[Self]) -> Vec<PositiveReaction> {
pub fn into_positive_reactions(
reactions: &[Self],
) -> Vec<PositiveReaction> {
let mut res = vec![];
let old_reactions = &reactions;
let all_products = Reaction::all_products(old_reactions);
for el in all_products {
let p =
Reaction::all_reactions_with_product(old_reactions, &el);
let p = Reaction::all_reactions_with_product(old_reactions, &el);
let mut tmp = vec![];
for r in p.iter() {
tmp.push(PositiveReaction::create(
@ -347,7 +350,7 @@ impl Reaction {
&p.iter().map(|p| p.reactants.clone()).collect::<Vec<_>>(),
&p.iter().map(|p| p.inhibitors.clone()).collect::<Vec<_>>(),
)
.unwrap(); // since we have in input a valid system
.unwrap(); // since we have in input a valid system
for s in prohib_set {
res.push(PositiveReaction {
reactants: s,

View File

@ -705,14 +705,16 @@ impl System {
}
pub fn overwrite_context_elements(&mut self, new_context_elements: Set) {
self.context_elements = Rc::new(RefCell::new(Some(new_context_elements)));
self.context_elements =
Rc::new(RefCell::new(Some(new_context_elements)));
}
pub fn overwrite_product_elements(&mut self, new_product_elements: Set) {
// since context_elements depend on product elements we make sure that
// its computed to ensure consistent behaviour
self.context_elements();
self.products_elements = Rc::new(RefCell::new(Some(new_product_elements)));
self.products_elements =
Rc::new(RefCell::new(Some(new_product_elements)));
}
}
@ -1039,7 +1041,8 @@ impl From<System> for PositiveSystem {
let new_available_entities =
positive_entities.union(&negative_entities);
let new_reactions = Rc::new(PositiveReaction::from_reactions(value.reactions()));
let new_reactions =
Rc::new(PositiveReaction::from_reactions(value.reactions()));
let new_context = value.context_process.into();
Self::from(new_env, new_available_entities, new_context, new_reactions)
@ -1071,14 +1074,22 @@ impl PositiveSystem {
.collect::<PositiveSet>()
}
pub fn overwrite_context_elements(&mut self, new_context_elements: PositiveSet) {
self.context_elements = Rc::new(RefCell::new(Some(new_context_elements)));
pub fn overwrite_context_elements(
&mut self,
new_context_elements: PositiveSet,
) {
self.context_elements =
Rc::new(RefCell::new(Some(new_context_elements)));
}
pub fn overwrite_product_elements(&mut self, new_product_elements: PositiveSet) {
pub fn overwrite_product_elements(
&mut self,
new_product_elements: PositiveSet,
) {
// since context_elements depend on product elements we make sure that
// its computed to ensure consistent behaviour
self.context_elements();
self.products_elements = Rc::new(RefCell::new(Some(new_product_elements)));
self.products_elements =
Rc::new(RefCell::new(Some(new_product_elements)));
}
}

View File

@ -407,7 +407,8 @@ impl<
while let Some(el) = elements.next() {
if let Some(r) = enabled_reactions.next() {
let reaction_string = format!("{}", Formatter::from(translator, r));
let reaction_string =
format!("{}", Formatter::from(translator, r));
let reaction_string = if reaction_string.is_empty() {
"( )"
} else {