Added guarded context
This commit is contained in:
@ -143,7 +143,7 @@ impl IntoIterator for RSset {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Basic structure for a reaction.
|
/// Basic structure for a reaction.
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||||
pub struct RSreaction {
|
pub struct RSreaction {
|
||||||
pub reactants: RSset,
|
pub reactants: RSset,
|
||||||
pub inhibitors: RSset,
|
pub inhibitors: RSset,
|
||||||
@ -195,6 +195,10 @@ pub enum RSprocess {
|
|||||||
entities: RSset,
|
entities: RSset,
|
||||||
next_process: Rc<RSprocess>,
|
next_process: Rc<RSprocess>,
|
||||||
},
|
},
|
||||||
|
Guarded {
|
||||||
|
reaction: RSreaction,
|
||||||
|
next_process: Rc<RSprocess>,
|
||||||
|
},
|
||||||
WaitEntity {
|
WaitEntity {
|
||||||
repeat: i64,
|
repeat: i64,
|
||||||
repeated_process: Rc<RSprocess>,
|
repeated_process: Rc<RSprocess>,
|
||||||
@ -248,6 +252,12 @@ impl RSprocess {
|
|||||||
elements.push(entities);
|
elements.push(entities);
|
||||||
queue.push_back(next_process);
|
queue.push_back(next_process);
|
||||||
}
|
}
|
||||||
|
Self::Guarded { reaction, next_process } => {
|
||||||
|
elements.push(&reaction.reactants);
|
||||||
|
elements.push(&reaction.inhibitors);
|
||||||
|
elements.push(&reaction.products);
|
||||||
|
queue.push_back(next_process);
|
||||||
|
}
|
||||||
Self::WaitEntity {
|
Self::WaitEntity {
|
||||||
repeat: _,
|
repeat: _,
|
||||||
repeated_process,
|
repeated_process,
|
||||||
|
|||||||
@ -14,7 +14,7 @@ impl<'a> TransitionsIterator<'a> {
|
|||||||
pub fn from(
|
pub fn from(
|
||||||
system: &'a RSsystem
|
system: &'a RSsystem
|
||||||
) -> Result<TransitionsIterator<'a>, String> {
|
) -> Result<TransitionsIterator<'a>, String> {
|
||||||
match unfold(&system.delta, &system.context_process) {
|
match unfold(&system.delta, &system.context_process, &system.available_entities) {
|
||||||
Ok(o) => Ok(TransitionsIterator {
|
Ok(o) => Ok(TransitionsIterator {
|
||||||
choices_iterator: o.into_iter(),
|
choices_iterator: o.into_iter(),
|
||||||
system,
|
system,
|
||||||
|
|||||||
@ -16,44 +16,46 @@ use std::rc::Rc;
|
|||||||
pub fn unfold(
|
pub fn unfold(
|
||||||
environment: &RSenvironment,
|
environment: &RSenvironment,
|
||||||
context_process: &RSprocess,
|
context_process: &RSprocess,
|
||||||
|
current_entities: &RSset,
|
||||||
) -> Result<RSchoices, String> {
|
) -> Result<RSchoices, String> {
|
||||||
match context_process {
|
match context_process {
|
||||||
RSprocess::Nill => Ok(RSchoices::new()),
|
RSprocess::Nill => {
|
||||||
|
Ok(RSchoices::new())
|
||||||
|
},
|
||||||
RSprocess::RecursiveIdentifier { identifier } => {
|
RSprocess::RecursiveIdentifier { identifier } => {
|
||||||
let newprocess = environment.get(*identifier);
|
let newprocess = environment.get(*identifier);
|
||||||
if let Some(newprocess) = newprocess {
|
if let Some(newprocess) = newprocess {
|
||||||
unfold(environment, newprocess)
|
unfold(environment, newprocess, current_entities)
|
||||||
} else {
|
} else {
|
||||||
Err(format!("Missing symbol in context: {identifier}"))
|
Err(format!("Missing symbol in context: {identifier}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RSprocess::EntitySet {
|
RSprocess::EntitySet { entities, next_process, } => {
|
||||||
entities,
|
Ok(RSchoices::from([(
|
||||||
next_process,
|
Rc::new(entities.clone()),
|
||||||
} => Ok(RSchoices::from(vec![(
|
Rc::clone(next_process),
|
||||||
Rc::new(entities.clone()),
|
)]))
|
||||||
Rc::clone(next_process),
|
},
|
||||||
)])),
|
RSprocess::Guarded { reaction, next_process } => {
|
||||||
RSprocess::WaitEntity {
|
if reaction.enabled(current_entities) {
|
||||||
repeat,
|
Ok(RSchoices::from([(Rc::new(reaction.products.clone()),
|
||||||
repeated_process: _,
|
Rc::clone(next_process))]))
|
||||||
next_process,
|
} else {
|
||||||
} if *repeat <= 0 => unfold(environment, next_process),
|
Ok(RSchoices::new())
|
||||||
RSprocess::WaitEntity {
|
}
|
||||||
repeat,
|
}
|
||||||
repeated_process,
|
RSprocess::WaitEntity { repeat, repeated_process: _, next_process, }
|
||||||
next_process,
|
if *repeat <= 0 => {
|
||||||
} if *repeat == 1 => {
|
unfold(environment, next_process, current_entities)
|
||||||
let mut choices1 = unfold(environment, repeated_process)?;
|
},
|
||||||
|
RSprocess::WaitEntity { repeat, repeated_process, next_process, }
|
||||||
|
if *repeat == 1 => {
|
||||||
|
let mut choices1 = unfold(environment, repeated_process, current_entities)?;
|
||||||
choices1.replace(Rc::clone(next_process));
|
choices1.replace(Rc::clone(next_process));
|
||||||
Ok(choices1)
|
Ok(choices1)
|
||||||
}
|
}
|
||||||
RSprocess::WaitEntity {
|
RSprocess::WaitEntity { repeat, repeated_process, next_process, } => {
|
||||||
repeat,
|
let mut choices1 = unfold(environment, repeated_process, current_entities)?;
|
||||||
repeated_process,
|
|
||||||
next_process,
|
|
||||||
} => {
|
|
||||||
let mut choices1 = unfold(environment, repeated_process)?;
|
|
||||||
choices1.replace(Rc::new(RSprocess::WaitEntity {
|
choices1.replace(Rc::new(RSprocess::WaitEntity {
|
||||||
repeat: (*repeat - 1),
|
repeat: (*repeat - 1),
|
||||||
repeated_process: Rc::clone(repeated_process),
|
repeated_process: Rc::clone(repeated_process),
|
||||||
@ -64,7 +66,7 @@ pub fn unfold(
|
|||||||
RSprocess::Summation { children } => {
|
RSprocess::Summation { children } => {
|
||||||
// short-circuits with try_fold.
|
// short-circuits with try_fold.
|
||||||
children.iter().try_fold(RSchoices::new(), |mut acc, x| {
|
children.iter().try_fold(RSchoices::new(), |mut acc, x| {
|
||||||
match unfold(environment, x) {
|
match unfold(environment, x, current_entities) {
|
||||||
Ok(mut choices) => {
|
Ok(mut choices) => {
|
||||||
acc.append(&mut choices);
|
acc.append(&mut choices);
|
||||||
Ok(acc)
|
Ok(acc)
|
||||||
@ -82,7 +84,7 @@ pub fn unfold(
|
|||||||
)]))
|
)]))
|
||||||
} else {
|
} else {
|
||||||
children.iter().try_fold(RSchoices::new(), |mut acc, x| {
|
children.iter().try_fold(RSchoices::new(), |mut acc, x| {
|
||||||
acc.shuffle(unfold(environment, x)?);
|
acc.shuffle(unfold(environment, x, current_entities)?);
|
||||||
Ok(acc)
|
Ok(acc)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,28 +166,27 @@ fn print_process(
|
|||||||
match process {
|
match process {
|
||||||
Nill => {
|
Nill => {
|
||||||
write!(f, "Nill")
|
write!(f, "Nill")
|
||||||
}
|
},
|
||||||
RecursiveIdentifier { identifier } => {
|
RecursiveIdentifier { identifier } => {
|
||||||
write!(f,
|
write!(f,
|
||||||
"[{}]",
|
"[{}]",
|
||||||
translator.decode(*identifier).unwrap_or("Missing".into()))
|
translator.decode(*identifier).unwrap_or("Missing".into()))
|
||||||
}
|
},
|
||||||
EntitySet {
|
EntitySet { entities, next_process, } => {
|
||||||
entities,
|
|
||||||
next_process,
|
|
||||||
} => {
|
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
RSsetDisplay::from(translator, entities),
|
RSsetDisplay::from(translator, entities),
|
||||||
RSprocessDisplay::from(translator, next_process)
|
RSprocessDisplay::from(translator, next_process)
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
WaitEntity {
|
Guarded { reaction, next_process } => {
|
||||||
repeat,
|
write!(f,
|
||||||
repeated_process,
|
"?{}?.{}",
|
||||||
next_process,
|
RSreactionDisplay::from(translator, reaction),
|
||||||
} => {
|
RSprocessDisplay::from(translator, next_process))
|
||||||
|
},
|
||||||
|
WaitEntity { repeat, repeated_process, next_process, } => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"({})^{repeat}.{}",
|
"({})^{repeat}.{}",
|
||||||
|
|||||||
Reference in New Issue
Block a user