Fix, clippy now working better
This commit is contained in:
1
clippy.toml
Normal file
1
clippy.toml
Normal file
@ -0,0 +1 @@
|
|||||||
|
ignore-interior-mutability = ["rsprocess::system::System", "rsprocess::system::PositiveSystem", ".."]
|
||||||
@ -638,9 +638,16 @@ impl PositiveSet {
|
|||||||
|
|
||||||
/// Returns all elements that are present in self and are positive in other.
|
/// Returns all elements that are present in self and are positive in other.
|
||||||
pub fn mask(&self, other: &Self) -> Self {
|
pub fn mask(&self, other: &Self) -> Self {
|
||||||
Self::from_iter(self.iter().filter(|el| {
|
Self::from_iter(
|
||||||
other.contains(&PositiveType::from((*el.0, IdState::Positive)))
|
self.iter()
|
||||||
}).map(|el| (*el.0, *el.1)))
|
.filter(|el| {
|
||||||
|
other.contains(&PositiveType::from((
|
||||||
|
*el.0,
|
||||||
|
IdState::Positive,
|
||||||
|
)))
|
||||||
|
})
|
||||||
|
.map(|el| (*el.0, *el.1)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_elements(&mut self, other: Vec<IdType>) {
|
fn remove_elements(&mut self, other: Vec<IdType>) {
|
||||||
@ -664,6 +671,7 @@ impl PositiveSet {
|
|||||||
self_copy.is_empty()
|
self_copy.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns only the positive entities.
|
||||||
pub fn positives(&self) -> Self {
|
pub fn positives(&self) -> Self {
|
||||||
self.iter()
|
self.iter()
|
||||||
.filter(|el| *el.1 == IdState::Positive)
|
.filter(|el| *el.1 == IdState::Positive)
|
||||||
@ -671,10 +679,20 @@ impl PositiveSet {
|
|||||||
.collect::<PositiveSet>()
|
.collect::<PositiveSet>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns only the negative entities.
|
||||||
pub fn negatives(&self) -> Self {
|
pub fn negatives(&self) -> Self {
|
||||||
self.iter()
|
self.iter()
|
||||||
.filter(|el| *el.1 == IdState::Negative)
|
.filter(|el| *el.1 == IdState::Negative)
|
||||||
.map(|el| (*el.0, *el.1))
|
.map(|el| (*el.0, *el.1))
|
||||||
.collect::<PositiveSet>()
|
.collect::<PositiveSet>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_unique(&self, other: &Self) -> Self {
|
||||||
|
other
|
||||||
|
.iter()
|
||||||
|
.filter(|e| !self.contains(&PositiveType::from((*e.0, *e.1))))
|
||||||
|
.map(|el| (*el.0, *el.1))
|
||||||
|
.collect::<PositiveSet>()
|
||||||
|
.union(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,10 +18,12 @@ use super::process::{BasicProcess, PositiveProcess, Process};
|
|||||||
use super::reaction::{
|
use super::reaction::{
|
||||||
BasicReaction, ExtensionReaction, PositiveReaction, Reaction,
|
BasicReaction, ExtensionReaction, PositiveReaction, Reaction,
|
||||||
};
|
};
|
||||||
use super::set::{BasicSet, PositiveSet, Set};
|
use super::set::{BasicSet, ExtensionsSet, PositiveSet, Set};
|
||||||
use super::trace::Trace;
|
use super::trace::Trace;
|
||||||
use super::transitions::TransitionsIterator;
|
use super::transitions::TransitionsIterator;
|
||||||
use super::translator::{Formatter, PrintableWithTranslator, Translator};
|
use super::translator::{Formatter, PrintableWithTranslator, Translator};
|
||||||
|
use crate::trace::{EnabledReactions, SlicingElement, SlicingTrace};
|
||||||
|
use crate::transitions::TraceIterator;
|
||||||
|
|
||||||
pub trait BasicSystem
|
pub trait BasicSystem
|
||||||
where
|
where
|
||||||
@ -49,6 +51,14 @@ where
|
|||||||
&self,
|
&self,
|
||||||
) -> Result<impl Iterator<Item = (Self::Label, Self)>, String>;
|
) -> Result<impl Iterator<Item = (Self::Label, Self)>, String>;
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
|
fn to_slicing_iterator(
|
||||||
|
&self,
|
||||||
|
) -> Result<
|
||||||
|
impl Iterator<Item = (Self::Set, Self::Set, Vec<usize>, Self)>,
|
||||||
|
String,
|
||||||
|
>;
|
||||||
|
|
||||||
fn environment(&self) -> &Self::Environment;
|
fn environment(&self) -> &Self::Environment;
|
||||||
fn available_entities(&self) -> &Self::Set;
|
fn available_entities(&self) -> &Self::Set;
|
||||||
fn context(&self) -> &Self::Process;
|
fn context(&self) -> &Self::Process;
|
||||||
@ -89,7 +99,12 @@ pub trait ExtensionsSystem: BasicSystem {
|
|||||||
limit: usize,
|
limit: usize,
|
||||||
) -> Result<Vec<(Self::Set, Self::Set, Self::Set)>, String>;
|
) -> Result<Vec<(Self::Set, Self::Set, Self::Set)>, String>;
|
||||||
|
|
||||||
fn traces(self, n: usize) -> Result<Vec<Trace<Self::Label, Self>>, String>;
|
fn traces(&self, n: usize)
|
||||||
|
-> Result<Vec<Trace<Self::Label, Self>>, String>;
|
||||||
|
|
||||||
|
fn slice_trace(
|
||||||
|
&self,
|
||||||
|
) -> Result<SlicingTrace<Self::Set, Self::Reaction, Self>, String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: BasicSystem> ExtensionsSystem for T {
|
impl<T: BasicSystem> ExtensionsSystem for T {
|
||||||
@ -242,14 +257,18 @@ impl<T: BasicSystem> ExtensionsSystem for T {
|
|||||||
/// Return the first n traces. Equivalent to visiting the execution tree
|
/// Return the first n traces. Equivalent to visiting the execution tree
|
||||||
/// depth first and returning the first n leaf nodes and their path to the
|
/// depth first and returning the first n leaf nodes and their path to the
|
||||||
/// root.
|
/// root.
|
||||||
fn traces(self, n: usize) -> Result<Vec<Trace<Self::Label, Self>>, String> {
|
fn traces(
|
||||||
|
&self,
|
||||||
|
n: usize,
|
||||||
|
) -> Result<Vec<Trace<Self::Label, Self>>, String> {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return Ok(vec![]);
|
return Ok(vec![]);
|
||||||
}
|
}
|
||||||
|
let sys = self.clone();
|
||||||
let mut n = n;
|
let mut n = n;
|
||||||
let mut res: Vec<Trace<Self::Label, Self>> = vec![];
|
let mut res: Vec<Trace<Self::Label, Self>> = vec![];
|
||||||
let mut current_trace: Trace<Self::Label, Self> = Trace::default();
|
let mut current_trace: Trace<Self::Label, Self> = Trace::default();
|
||||||
current_trace.push((None, Rc::new(self)));
|
current_trace.push((None, Rc::new(sys)));
|
||||||
let mut branch = vec![0];
|
let mut branch = vec![0];
|
||||||
let mut depth = 0;
|
let mut depth = 0;
|
||||||
let mut new_branch = true;
|
let mut new_branch = true;
|
||||||
@ -293,6 +312,57 @@ impl<T: BasicSystem> ExtensionsSystem for T {
|
|||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::field_reassign_with_default)]
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
|
fn slice_trace(
|
||||||
|
&self,
|
||||||
|
) -> Result<SlicingTrace<Self::Set, Self::Reaction, Self>, String> {
|
||||||
|
let mut trace = SlicingTrace::default();
|
||||||
|
|
||||||
|
trace.context_elements = Rc::new(self.context_elements());
|
||||||
|
trace.products_elements = Rc::new(self.products_elements());
|
||||||
|
trace.reactions = Rc::new(self.reactions().clone());
|
||||||
|
trace.systems.push(Rc::new(self.clone()));
|
||||||
|
trace.elements.push(SlicingElement::from((
|
||||||
|
Self::Set::default(),
|
||||||
|
self.available_entities().clone(),
|
||||||
|
)));
|
||||||
|
|
||||||
|
let current: Option<(Self::Set, Self::Set, Vec<usize>, Self)> =
|
||||||
|
self.to_slicing_iterator()?.next();
|
||||||
|
if current.is_none() {
|
||||||
|
return Ok(trace);
|
||||||
|
}
|
||||||
|
let current = current.unwrap();
|
||||||
|
|
||||||
|
let (context, products, enabled_reactions, mut current) = current;
|
||||||
|
trace
|
||||||
|
.elements
|
||||||
|
.push(SlicingElement::from((context, products)));
|
||||||
|
trace
|
||||||
|
.enabled_reactions
|
||||||
|
.push(EnabledReactions::from(enabled_reactions));
|
||||||
|
trace.systems.push(Rc::new(current.clone()));
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let t = current.to_slicing_iterator()?.next();
|
||||||
|
if let Some((context, products, enabled_reactions, next_sys)) = t {
|
||||||
|
current = next_sys;
|
||||||
|
trace
|
||||||
|
.elements
|
||||||
|
.push(SlicingElement::from((context, products)));
|
||||||
|
trace
|
||||||
|
.enabled_reactions
|
||||||
|
.push(EnabledReactions::from(enabled_reactions));
|
||||||
|
trace.systems.push(Rc::new(current.clone()));
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// trace.enabled_reactions.pop();
|
||||||
|
Ok(trace)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -433,6 +503,14 @@ impl BasicSystem for System {
|
|||||||
TransitionsIterator::<Self::Set, Self, Self::Process>::try_from(self)
|
TransitionsIterator::<Self::Set, Self, Self::Process>::try_from(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(refining_impl_trait)] // otherwise impl cannot be resolved to
|
||||||
|
// concrete type and the compiler complains
|
||||||
|
fn to_slicing_iterator(
|
||||||
|
&self,
|
||||||
|
) -> Result<TraceIterator<'_, Self::Set, Self, Self::Process>, String> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
fn environment(&self) -> &Self::Environment {
|
fn environment(&self) -> &Self::Environment {
|
||||||
&self.delta
|
&self.delta
|
||||||
}
|
}
|
||||||
@ -454,7 +532,8 @@ impl BasicSystem for System {
|
|||||||
if c.is_some() {
|
if c.is_some() {
|
||||||
c.as_ref().unwrap().clone()
|
c.as_ref().unwrap().clone()
|
||||||
} else {
|
} else {
|
||||||
let all_elements_context = self.delta
|
let all_elements_context = self
|
||||||
|
.delta
|
||||||
.all_elements()
|
.all_elements()
|
||||||
.union(&self.context_process.all_elements())
|
.union(&self.context_process.all_elements())
|
||||||
.subtraction(&self.products_elements());
|
.subtraction(&self.products_elements());
|
||||||
@ -469,10 +548,12 @@ impl BasicSystem for System {
|
|||||||
if p.is_some() {
|
if p.is_some() {
|
||||||
p.as_ref().unwrap().clone()
|
p.as_ref().unwrap().clone()
|
||||||
} else {
|
} else {
|
||||||
let products_elements = self.reaction_rules
|
let products_elements = self
|
||||||
|
.reaction_rules
|
||||||
.iter()
|
.iter()
|
||||||
.fold(Self::Set::default(), |acc: Self::Set, r|
|
.fold(Self::Set::default(), |acc: Self::Set, r| {
|
||||||
acc.union(&r.products));
|
acc.union(&r.products)
|
||||||
|
});
|
||||||
|
|
||||||
*p = Some(products_elements.clone());
|
*p = Some(products_elements.clone());
|
||||||
products_elements
|
products_elements
|
||||||
@ -729,6 +810,15 @@ impl BasicSystem for PositiveSystem {
|
|||||||
TransitionsIterator::<Self::Set, Self, Self::Process>::try_from(self)
|
TransitionsIterator::<Self::Set, Self, Self::Process>::try_from(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_slicing_iterator(
|
||||||
|
&self,
|
||||||
|
) -> Result<
|
||||||
|
impl Iterator<Item = (Self::Set, Self::Set, Vec<usize>, Self)>,
|
||||||
|
String,
|
||||||
|
> {
|
||||||
|
TraceIterator::<Self::Set, Self, Self::Process>::try_from(self)
|
||||||
|
}
|
||||||
|
|
||||||
fn environment(&self) -> &Self::Environment {
|
fn environment(&self) -> &Self::Environment {
|
||||||
&self.delta
|
&self.delta
|
||||||
}
|
}
|
||||||
@ -750,10 +840,14 @@ impl BasicSystem for PositiveSystem {
|
|||||||
if c.is_some() {
|
if c.is_some() {
|
||||||
c.as_ref().unwrap().clone()
|
c.as_ref().unwrap().clone()
|
||||||
} else {
|
} else {
|
||||||
let all_elements_context = self.delta
|
let all_elements_context = self
|
||||||
|
.delta
|
||||||
.all_elements()
|
.all_elements()
|
||||||
.union(&self.context_process.all_elements())
|
.union(&self.context_process.all_elements())
|
||||||
.subtraction(&self.products_elements());
|
.subtraction(&self.products_elements())
|
||||||
|
.iter()
|
||||||
|
.map(|e| (*e.0, IdState::Positive))
|
||||||
|
.collect::<Self::Set>();
|
||||||
|
|
||||||
*c = Some(all_elements_context.clone());
|
*c = Some(all_elements_context.clone());
|
||||||
all_elements_context
|
all_elements_context
|
||||||
@ -765,10 +859,15 @@ impl BasicSystem for PositiveSystem {
|
|||||||
if p.is_some() {
|
if p.is_some() {
|
||||||
p.as_ref().unwrap().clone()
|
p.as_ref().unwrap().clone()
|
||||||
} else {
|
} else {
|
||||||
let products_elements = self.reaction_rules
|
let products_elements = self
|
||||||
|
.reaction_rules
|
||||||
.iter()
|
.iter()
|
||||||
.fold(Self::Set::default(), |acc: Self::Set, r|
|
.fold(Self::Set::default(), |acc: Self::Set, r| {
|
||||||
acc.union(&r.products));
|
acc.union(&r.products)
|
||||||
|
})
|
||||||
|
.iter()
|
||||||
|
.map(|e| (*e.0, IdState::Positive))
|
||||||
|
.collect::<Self::Set>();
|
||||||
|
|
||||||
*p = Some(products_elements.clone());
|
*p = Some(products_elements.clone());
|
||||||
products_elements
|
products_elements
|
||||||
@ -938,4 +1037,11 @@ impl PositiveSystem {
|
|||||||
products_elements: Rc::new(RefCell::new(None)),
|
products_elements: Rc::new(RefCell::new(None)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn negated_products_elements(&self) -> PositiveSet {
|
||||||
|
self.products_elements()
|
||||||
|
.iter()
|
||||||
|
.map(|el| (*el.0, IdState::Negative))
|
||||||
|
.collect::<PositiveSet>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use super::set::PositiveSet;
|
use super::set::PositiveSet;
|
||||||
use super::system::BasicSystem;
|
use super::system::BasicSystem;
|
||||||
|
use crate::system::ExtensionsSystem;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn one_transition() {
|
fn one_transition() {
|
||||||
@ -344,3 +345,88 @@ fn conversion_entities() {
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn slice_trace() {
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use super::environment::Environment;
|
||||||
|
use super::process::Process;
|
||||||
|
use super::reaction::Reaction;
|
||||||
|
use super::set::Set;
|
||||||
|
use super::system::{PositiveSystem, System};
|
||||||
|
|
||||||
|
let mut translator = crate::translator::Translator::new();
|
||||||
|
|
||||||
|
let mut tr = |a| translator.encode(a);
|
||||||
|
|
||||||
|
let system = System::from(
|
||||||
|
Rc::new(Environment::from([])),
|
||||||
|
Set::from([tr("a"), tr("b")]),
|
||||||
|
Process::EntitySet {
|
||||||
|
entities: Set::from([tr("c")]),
|
||||||
|
next_process: Rc::new(Process::EntitySet {
|
||||||
|
entities: Set::from([]),
|
||||||
|
next_process: Rc::new(Process::Nill),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
Rc::new(vec![Reaction::from(
|
||||||
|
Set::from([tr("a")]),
|
||||||
|
Set::from([]),
|
||||||
|
Set::from([tr("b")]),
|
||||||
|
)]),
|
||||||
|
);
|
||||||
|
|
||||||
|
let system: PositiveSystem = system.into();
|
||||||
|
|
||||||
|
let res_slice = system.slice_trace().unwrap();
|
||||||
|
let res_run = system.run().unwrap();
|
||||||
|
|
||||||
|
assert_eq!(res_slice.systems, res_run);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn slice_trace_2() {
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use super::environment::Environment;
|
||||||
|
use super::process::Process;
|
||||||
|
use super::reaction::Reaction;
|
||||||
|
use super::set::Set;
|
||||||
|
use super::system::{PositiveSystem, System};
|
||||||
|
|
||||||
|
let mut translator = crate::translator::Translator::new();
|
||||||
|
|
||||||
|
let mut tr = |a| translator.encode(a);
|
||||||
|
|
||||||
|
let system = System::from(
|
||||||
|
Rc::new(Environment::from([])),
|
||||||
|
Set::from([tr("a"), tr("b")]),
|
||||||
|
Process::EntitySet {
|
||||||
|
entities: Set::from([tr("c")]),
|
||||||
|
next_process: Rc::new(Process::EntitySet {
|
||||||
|
entities: Set::from([]),
|
||||||
|
next_process: Rc::new(Process::Nill),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
Rc::new(vec![
|
||||||
|
Reaction::from(
|
||||||
|
Set::from([tr("a")]),
|
||||||
|
Set::from([tr("b")]),
|
||||||
|
Set::from([tr("b")]),
|
||||||
|
),
|
||||||
|
Reaction::from(
|
||||||
|
Set::from([tr("b")]),
|
||||||
|
Set::from([tr("a")]),
|
||||||
|
Set::from([tr("a")]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
let system: PositiveSystem = system.into();
|
||||||
|
|
||||||
|
let res_slice = system.slice_trace().unwrap();
|
||||||
|
let res_run = system.run().unwrap();
|
||||||
|
|
||||||
|
assert_eq!(res_slice.systems, res_run);
|
||||||
|
}
|
||||||
|
|||||||
@ -86,6 +86,15 @@ pub struct SlicingElement<S> {
|
|||||||
pub reaction_products: S,
|
pub reaction_products: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S> From<(S, S)> for SlicingElement<S> {
|
||||||
|
fn from(value: (S, S)) -> Self {
|
||||||
|
Self {
|
||||||
|
context: value.0,
|
||||||
|
reaction_products: value.1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S> Debug for SlicingElement<S>
|
impl<S> Debug for SlicingElement<S>
|
||||||
where
|
where
|
||||||
S: Debug,
|
S: Debug,
|
||||||
@ -126,6 +135,28 @@ pub struct EnabledReactions {
|
|||||||
pub data: Vec<usize>,
|
pub data: Vec<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Vec<usize>> for EnabledReactions {
|
||||||
|
fn from(value: Vec<usize>) -> Self {
|
||||||
|
Self { data: value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&[usize]> for EnabledReactions {
|
||||||
|
fn from(value: &[usize]) -> Self {
|
||||||
|
Self {
|
||||||
|
data: value.to_vec(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const N: usize> From<[usize; N]> for EnabledReactions {
|
||||||
|
fn from(value: [usize; N]) -> Self {
|
||||||
|
Self {
|
||||||
|
data: value.to_vec(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PrintableWithTranslator for EnabledReactions {
|
impl PrintableWithTranslator for EnabledReactions {
|
||||||
fn print(
|
fn print(
|
||||||
&self,
|
&self,
|
||||||
@ -160,10 +191,11 @@ impl EnabledReactions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SlicingTrace<S: BasicSet,
|
pub struct SlicingTrace<
|
||||||
R: BasicReaction<Set = S>,
|
S: BasicSet,
|
||||||
Sys: BasicSystem<Set = S, Reaction = R>>
|
R: BasicReaction<Set = S>,
|
||||||
{
|
Sys: BasicSystem<Set = S, Reaction = R>,
|
||||||
|
> {
|
||||||
pub elements: Vec<SlicingElement<S>>,
|
pub elements: Vec<SlicingElement<S>>,
|
||||||
pub enabled_reactions: Vec<EnabledReactions>,
|
pub enabled_reactions: Vec<EnabledReactions>,
|
||||||
|
|
||||||
@ -174,10 +206,11 @@ pub struct SlicingTrace<S: BasicSet,
|
|||||||
pub products_elements: Rc<S>,
|
pub products_elements: Rc<S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BasicSet,
|
impl<
|
||||||
R: BasicReaction<Set = S>,
|
S: BasicSet,
|
||||||
Sys: BasicSystem<Set = S, Reaction = R>>
|
R: BasicReaction<Set = S>,
|
||||||
Default for SlicingTrace<S, R, Sys>
|
Sys: BasicSystem<Set = S, Reaction = R>,
|
||||||
|
> Default for SlicingTrace<S, R, Sys>
|
||||||
{
|
{
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -191,10 +224,11 @@ impl<S: BasicSet,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BasicSet + Debug,
|
impl<
|
||||||
R: BasicReaction<Set = S>,
|
S: BasicSet + Debug,
|
||||||
Sys: BasicSystem<Set = S, Reaction = R>>
|
R: BasicReaction<Set = S>,
|
||||||
SlicingTrace<S, R, Sys>
|
Sys: BasicSystem<Set = S, Reaction = R>,
|
||||||
|
> SlicingTrace<S, R, Sys>
|
||||||
{
|
{
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.elements.is_empty()
|
self.elements.is_empty()
|
||||||
@ -205,7 +239,6 @@ impl<S: BasicSet + Debug,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl SlicingTrace<Set, Reaction, System> {
|
impl SlicingTrace<Set, Reaction, System> {
|
||||||
pub fn slice(&self, marking: Set) -> Result<Self, String> {
|
pub fn slice(&self, marking: Set) -> Result<Self, String> {
|
||||||
let mut reversed_elements = Vec::with_capacity(self.elements.len());
|
let mut reversed_elements = Vec::with_capacity(self.elements.len());
|
||||||
@ -295,7 +328,8 @@ impl SlicingTrace<PositiveSet, PositiveReaction, PositiveSystem> {
|
|||||||
for r in self.enabled_reactions[i].iter() {
|
for r in self.enabled_reactions[i].iter() {
|
||||||
if !reversed_elements[reverse_i - 1]
|
if !reversed_elements[reverse_i - 1]
|
||||||
.reaction_products
|
.reaction_products
|
||||||
.intersection(self.reactions[*r].products()).is_empty()
|
.intersection(self.reactions[*r].products())
|
||||||
|
.is_empty()
|
||||||
{
|
{
|
||||||
reversed_enabled_reactions[reverse_i - 1].data.push(*r);
|
reversed_enabled_reactions[reverse_i - 1].data.push(*r);
|
||||||
reversed_elements[reverse_i].context.push(
|
reversed_elements[reverse_i].context.push(
|
||||||
@ -328,11 +362,11 @@ impl SlicingTrace<PositiveSet, PositiveReaction, PositiveSystem> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
impl<S: BasicSet,
|
S: BasicSet,
|
||||||
R: BasicReaction<Set = S>,
|
R: BasicReaction<Set = S>,
|
||||||
Sys: BasicSystem<Set = S, Reaction = R>,>
|
Sys: BasicSystem<Set = S, Reaction = R>,
|
||||||
PrintableWithTranslator for SlicingTrace<S, R, Sys>
|
> PrintableWithTranslator for SlicingTrace<S, R, Sys>
|
||||||
{
|
{
|
||||||
fn print(
|
fn print(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use crate::element::IdState;
|
use crate::element::IdState;
|
||||||
use crate::reaction::{BasicReaction, PositiveReaction, Reaction};
|
use crate::reaction::{BasicReaction, PositiveReaction, Reaction};
|
||||||
use crate::set::{ExtensionsSet, PositiveSet, Set, BasicSet};
|
use crate::set::{BasicSet, ExtensionsSet, PositiveSet, Set};
|
||||||
use crate::system::{PositiveSystem, System};
|
use crate::system::{PositiveSystem, System};
|
||||||
use crate::trace::*;
|
use crate::trace::*;
|
||||||
use crate::translator::Translator;
|
use crate::translator::Translator;
|
||||||
@ -82,13 +82,14 @@ fn slice_atoi() {
|
|||||||
.map(|el| translator.encode(*el))
|
.map(|el| translator.encode(*el))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into();
|
.into();
|
||||||
let products_elements =
|
let products_elements = [
|
||||||
["rorgt", "stat3", "il21r", "il6r", "nfat", "stat1", "tbet", "il21",
|
"rorgt", "stat3", "il21r", "il6r", "nfat", "stat1", "tbet", "il21",
|
||||||
"il23r"]
|
"il23r",
|
||||||
.iter()
|
]
|
||||||
.map(|el| translator.encode(*el))
|
.iter()
|
||||||
.collect::<Vec<_>>()
|
.map(|el| translator.encode(*el))
|
||||||
.into();
|
.collect::<Vec<_>>()
|
||||||
|
.into();
|
||||||
|
|
||||||
let trace: SlicingTrace<Set, Reaction, System> = SlicingTrace {
|
let trace: SlicingTrace<Set, Reaction, System> = SlicingTrace {
|
||||||
elements,
|
elements,
|
||||||
@ -205,72 +206,129 @@ fn slice_positive_atoi() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let converted_system: PositiveSystem = system.into();
|
let converted_system: PositiveSystem = system.into();
|
||||||
let mut reactions = Rc::try_unwrap(converted_system.reaction_rules).unwrap();
|
let mut reactions =
|
||||||
reactions.sort_by(|a, b| a.reactants.cmp(&b.reactants)
|
Rc::try_unwrap(converted_system.reaction_rules).unwrap();
|
||||||
.then(a.products.cmp(&b.products)));
|
reactions.sort_by(|a, b| {
|
||||||
|
a.reactants
|
||||||
|
.cmp(&b.reactants)
|
||||||
|
.then(a.products.cmp(&b.products))
|
||||||
|
});
|
||||||
|
|
||||||
println!("Computed Reactions:");
|
println!("Computed Reactions:");
|
||||||
for (pos, r) in reactions.iter().enumerate() {
|
for (pos, r) in reactions.iter().enumerate() {
|
||||||
println!("\t({pos}) {},", crate::translator::Formatter::from(&translator, r));
|
println!(
|
||||||
|
"\t({pos}) {},",
|
||||||
|
crate::translator::Formatter::from(&translator, r)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
reactions
|
reactions
|
||||||
};
|
};
|
||||||
|
|
||||||
let elements = [
|
let elements = [
|
||||||
(vec![("il23r", IdState::Positive), ("il21", IdState::Positive),
|
(
|
||||||
("rorgt", IdState::Negative), ("stat3", IdState::Negative),
|
vec![
|
||||||
("il21r", IdState::Negative), ("il6r", IdState::Negative),
|
("il23r", IdState::Positive),
|
||||||
("nfat", IdState::Negative), ("stat1", IdState::Negative),
|
("il21", IdState::Positive),
|
||||||
("tbet", IdState::Negative), ("tgfbr", IdState::Negative),
|
("rorgt", IdState::Negative),
|
||||||
("foxp3", IdState::Negative)],
|
("stat3", IdState::Negative),
|
||||||
vec![("tcr", IdState::Positive), ("tgfb", IdState::Negative),
|
("il21r", IdState::Negative),
|
||||||
("il6", IdState::Negative), ("il27", IdState::Negative)]),
|
("il6r", IdState::Negative),
|
||||||
(vec![("il21r", IdState::Positive), ("stat3", IdState::Positive),
|
("nfat", IdState::Negative),
|
||||||
("nfat", IdState::Positive), ("rorgt", IdState::Negative),
|
("stat1", IdState::Negative),
|
||||||
("il6r", IdState::Negative), ("stat1", IdState::Negative),
|
("tbet", IdState::Negative),
|
||||||
("tbet", IdState::Negative), ("il21", IdState::Negative),
|
("tgfbr", IdState::Negative),
|
||||||
("il23r", IdState::Negative), ("tgfbr", IdState::Negative),
|
("foxp3", IdState::Negative),
|
||||||
("foxp3", IdState::Negative)],
|
],
|
||||||
vec![("il27", IdState::Positive), ("tgfb", IdState::Negative),
|
vec![
|
||||||
("il6", IdState::Negative), ("tcr", IdState::Negative)]),
|
("tcr", IdState::Positive),
|
||||||
(vec![("stat1", IdState::Positive), ("rorgt", IdState::Negative),
|
("tgfb", IdState::Negative),
|
||||||
("stat3", IdState::Negative), ("il21r", IdState::Negative),
|
("il6", IdState::Negative),
|
||||||
("il6r", IdState::Negative), ("nfat", IdState::Negative),
|
("il27", IdState::Negative),
|
||||||
("tbet", IdState::Negative), ("il21", IdState::Negative),
|
],
|
||||||
("il23r", IdState::Negative), ("tgfbr", IdState::Negative),
|
),
|
||||||
("foxp3", IdState::Negative)],
|
(
|
||||||
vec![("il27", IdState::Negative), ("tgfb", IdState::Negative),
|
vec![
|
||||||
("il6", IdState::Negative), ("tcr", IdState::Negative)]),
|
("il21r", IdState::Positive),
|
||||||
(vec![("tbet", IdState::Positive), ("rorgt", IdState::Negative),
|
("stat3", IdState::Positive),
|
||||||
("stat3", IdState::Negative), ("il21r", IdState::Negative),
|
("nfat", IdState::Positive),
|
||||||
("il6r", IdState::Negative), ("nfat", IdState::Negative),
|
("rorgt", IdState::Negative),
|
||||||
("stat1", IdState::Negative), ("il21", IdState::Negative),
|
("il6r", IdState::Negative),
|
||||||
("il23r", IdState::Negative), ("tgfbr", IdState::Negative),
|
("stat1", IdState::Negative),
|
||||||
("foxp3", IdState::Negative)],
|
("tbet", IdState::Negative),
|
||||||
vec![]),
|
("il21", IdState::Negative),
|
||||||
|
("il23r", IdState::Negative),
|
||||||
|
("tgfbr", IdState::Negative),
|
||||||
|
("foxp3", IdState::Negative),
|
||||||
|
],
|
||||||
|
vec![
|
||||||
|
("il27", IdState::Positive),
|
||||||
|
("tgfb", IdState::Negative),
|
||||||
|
("il6", IdState::Negative),
|
||||||
|
("tcr", IdState::Negative),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
vec![
|
||||||
|
("stat1", IdState::Positive),
|
||||||
|
("rorgt", IdState::Negative),
|
||||||
|
("stat3", IdState::Negative),
|
||||||
|
("il21r", IdState::Negative),
|
||||||
|
("il6r", IdState::Negative),
|
||||||
|
("nfat", IdState::Negative),
|
||||||
|
("tbet", IdState::Negative),
|
||||||
|
("il21", IdState::Negative),
|
||||||
|
("il23r", IdState::Negative),
|
||||||
|
("tgfbr", IdState::Negative),
|
||||||
|
("foxp3", IdState::Negative),
|
||||||
|
],
|
||||||
|
vec![
|
||||||
|
("il27", IdState::Negative),
|
||||||
|
("tgfb", IdState::Negative),
|
||||||
|
("il6", IdState::Negative),
|
||||||
|
("tcr", IdState::Negative),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
vec![
|
||||||
|
("tbet", IdState::Positive),
|
||||||
|
("rorgt", IdState::Negative),
|
||||||
|
("stat3", IdState::Negative),
|
||||||
|
("il21r", IdState::Negative),
|
||||||
|
("il6r", IdState::Negative),
|
||||||
|
("nfat", IdState::Negative),
|
||||||
|
("stat1", IdState::Negative),
|
||||||
|
("il21", IdState::Negative),
|
||||||
|
("il23r", IdState::Negative),
|
||||||
|
("tgfbr", IdState::Negative),
|
||||||
|
("foxp3", IdState::Negative),
|
||||||
|
],
|
||||||
|
vec![],
|
||||||
|
),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|elements| SlicingElement {
|
.map(|elements| SlicingElement {
|
||||||
context: Into::<PositiveSet>::into(
|
context: Into::<PositiveSet>::into(
|
||||||
elements
|
elements
|
||||||
.1
|
.1
|
||||||
.iter()
|
.iter()
|
||||||
.map(|el| (translator.encode(el.0), el.1))
|
.map(|el| (translator.encode(el.0), el.1))
|
||||||
.collect::<Vec<_>>()),
|
.collect::<Vec<_>>(),
|
||||||
reaction_products: Into::<PositiveSet>::into(
|
),
|
||||||
elements
|
reaction_products: Into::<PositiveSet>::into(
|
||||||
.0
|
elements
|
||||||
.iter()
|
.0
|
||||||
.map(|el| (translator.encode(el.0), el.1))
|
.iter()
|
||||||
.collect::<Vec<_>>()),
|
.map(|el| (translator.encode(el.0), el.1))
|
||||||
})
|
.collect::<Vec<_>>(),
|
||||||
.collect::<Vec<_>>();
|
),
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let enabled_reactions = {
|
let enabled_reactions = {
|
||||||
let mut enabled_reactions = vec![];
|
let mut enabled_reactions = vec![];
|
||||||
for slice_el in elements.iter().rev().skip(1).rev() {
|
for slice_el in elements.iter().rev().skip(1).rev() {
|
||||||
let available_enteties = slice_el.context.union(&slice_el.reaction_products);
|
let available_enteties =
|
||||||
|
slice_el.context.union(&slice_el.reaction_products);
|
||||||
enabled_reactions.push(vec![]);
|
enabled_reactions.push(vec![]);
|
||||||
for (pos, r) in reactions.iter().enumerate() {
|
for (pos, r) in reactions.iter().enumerate() {
|
||||||
if r.enabled(&available_enteties) {
|
if r.enabled(&available_enteties) {
|
||||||
@ -278,28 +336,29 @@ fn slice_positive_atoi() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enabled_reactions.into_iter()
|
enabled_reactions
|
||||||
.map(|r| EnabledReactions {
|
.into_iter()
|
||||||
data: r,
|
.map(|r| EnabledReactions { data: r })
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
};
|
};
|
||||||
|
|
||||||
let context_elements =
|
let context_elements = Into::<Set>::into(
|
||||||
Into::<Set>::into(
|
["tgfb", "il6", "tcr", "il27"]
|
||||||
["tgfb", "il6", "tcr", "il27"]
|
.iter()
|
||||||
.iter()
|
.map(|el| translator.encode(*el))
|
||||||
.map(|el| translator.encode(*el))
|
.collect::<Vec<_>>(),
|
||||||
.collect::<Vec<_>>()
|
)
|
||||||
).to_positive_set(IdState::Positive);
|
.to_positive_set(IdState::Positive);
|
||||||
let products_elements =
|
let products_elements = Into::<Set>::into(
|
||||||
Into::<Set>::into(
|
[
|
||||||
["rorgt", "stat3", "il21r", "il6r", "nfat", "stat1", "tbet", "il21",
|
"rorgt", "stat3", "il21r", "il6r", "nfat", "stat1", "tbet", "il21",
|
||||||
"il23r", "tgfbr", "foxp3"]
|
"il23r", "tgfbr", "foxp3",
|
||||||
.iter()
|
]
|
||||||
.map(|el| translator.encode(*el))
|
.iter()
|
||||||
.collect::<Vec<_>>()
|
.map(|el| translator.encode(*el))
|
||||||
).to_positive_set(IdState::Positive);
|
.collect::<Vec<_>>(),
|
||||||
|
)
|
||||||
|
.to_positive_set(IdState::Positive);
|
||||||
|
|
||||||
let trace: SlicingTrace<PositiveSet, PositiveReaction, PositiveSystem> =
|
let trace: SlicingTrace<PositiveSet, PositiveReaction, PositiveSystem> =
|
||||||
SlicingTrace {
|
SlicingTrace {
|
||||||
@ -312,13 +371,13 @@ fn slice_positive_atoi() {
|
|||||||
products_elements: Rc::new(products_elements),
|
products_elements: Rc::new(products_elements),
|
||||||
};
|
};
|
||||||
|
|
||||||
let marking =
|
let marking = Into::<Set>::into(
|
||||||
Into::<Set>::into(
|
["tbet"]
|
||||||
["tbet"]
|
.iter()
|
||||||
.iter()
|
.map(|el| translator.encode(*el))
|
||||||
.map(|el| translator.encode(*el))
|
.collect::<Vec<_>>(),
|
||||||
.collect::<Vec<_>>()
|
)
|
||||||
).to_positive_set(IdState::Positive);
|
.to_positive_set(IdState::Positive);
|
||||||
|
|
||||||
let sliced = trace.slice(marking).unwrap();
|
let sliced = trace.slice(marking).unwrap();
|
||||||
|
|
||||||
@ -334,14 +393,19 @@ fn slice_positive_atoi() {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
reaction_products.iter_mut().for_each(|x| x.sort());
|
reaction_products.iter_mut().for_each(|x| x.sort());
|
||||||
let mut correct_reaction_products: Vec<Vec<(String, IdState)>> =
|
let mut correct_reaction_products: Vec<Vec<(String, IdState)>> = [
|
||||||
[vec![("foxp3", IdState::Negative)],
|
vec![("foxp3", IdState::Negative)],
|
||||||
vec![("nfat", IdState::Positive), ("tgfbr", IdState::Negative)],
|
vec![("nfat", IdState::Positive), ("tgfbr", IdState::Negative)],
|
||||||
vec![("stat1", IdState::Positive), ("foxp3", IdState::Negative),
|
vec![
|
||||||
("rorgt", IdState::Negative)],
|
("stat1", IdState::Positive),
|
||||||
vec![("tbet", IdState::Positive)]]
|
("foxp3", IdState::Negative),
|
||||||
.iter().map(|x| x.iter().map(|y| (y.0.to_string(), y.1))
|
("rorgt", IdState::Negative),
|
||||||
.collect::<Vec<_>>()).collect::<Vec<_>>();
|
],
|
||||||
|
vec![("tbet", IdState::Positive)],
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.iter().map(|y| (y.0.to_string(), y.1)).collect::<Vec<_>>())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
correct_reaction_products.iter_mut().for_each(|x| x.sort());
|
correct_reaction_products.iter_mut().for_each(|x| x.sort());
|
||||||
|
|
||||||
assert_eq!(reaction_products, correct_reaction_products);
|
assert_eq!(reaction_products, correct_reaction_products);
|
||||||
@ -358,13 +422,15 @@ fn slice_positive_atoi() {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
context.iter_mut().for_each(|x| x.sort());
|
context.iter_mut().for_each(|x| x.sort());
|
||||||
let mut correct_context =
|
let mut correct_context = [
|
||||||
[vec![("tcr", IdState::Positive)],
|
vec![("tcr", IdState::Positive)],
|
||||||
vec![("il27", IdState::Positive)],
|
vec![("il27", IdState::Positive)],
|
||||||
vec![],
|
vec![],
|
||||||
vec![]]
|
vec![],
|
||||||
.iter().map(|x| x.iter().map(|y| (y.0.to_string(), y.1))
|
]
|
||||||
.collect::<Vec<_>>()).collect::<Vec<_>>();
|
.iter()
|
||||||
|
.map(|x| x.iter().map(|y| (y.0.to_string(), y.1)).collect::<Vec<_>>())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
correct_context.iter_mut().for_each(|x| x.sort());
|
correct_context.iter_mut().for_each(|x| x.sort());
|
||||||
|
|
||||||
assert_eq!(context, correct_context);
|
assert_eq!(context, correct_context);
|
||||||
|
|||||||
@ -187,6 +187,7 @@ impl<'a> Iterator
|
|||||||
);
|
);
|
||||||
let new_system = PositiveSystem::from(
|
let new_system = PositiveSystem::from(
|
||||||
Rc::clone(&self.system.delta),
|
Rc::clone(&self.system.delta),
|
||||||
|
// products.add_unique(&self.system.negated_products_elements()),
|
||||||
products,
|
products,
|
||||||
(*k).clone(),
|
(*k).clone(),
|
||||||
Rc::clone(&self.system.reaction_rules),
|
Rc::clone(&self.system.reaction_rules),
|
||||||
@ -224,6 +225,14 @@ impl<'a> TryFrom<&'a PositiveSystem>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> Iterator for TraceIterator<'a, Set, System, Process> {
|
||||||
|
type Item = (Set, Set, Vec<usize>, System);
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Iterator
|
impl<'a> Iterator
|
||||||
for TraceIterator<'a, PositiveSet, PositiveSystem, PositiveProcess>
|
for TraceIterator<'a, PositiveSet, PositiveSystem, PositiveProcess>
|
||||||
{
|
{
|
||||||
@ -249,14 +258,16 @@ impl<'a> Iterator
|
|||||||
|
|
||||||
let new_system = PositiveSystem::from(
|
let new_system = PositiveSystem::from(
|
||||||
Rc::clone(&self.system.delta),
|
Rc::clone(&self.system.delta),
|
||||||
all_products,
|
// all_products.add_unique(&self.system.
|
||||||
|
// negated_products_elements()),
|
||||||
|
all_products.clone(),
|
||||||
(*k).clone(),
|
(*k).clone(),
|
||||||
Rc::clone(&self.system.reaction_rules),
|
Rc::clone(&self.system.reaction_rules),
|
||||||
);
|
);
|
||||||
|
|
||||||
Some((
|
Some((
|
||||||
context.as_ref().clone(),
|
context.as_ref().clone(),
|
||||||
self.system.available_entities().clone(),
|
all_products.mask(&self.system.products_elements()),
|
||||||
enabled_reaction_positions,
|
enabled_reaction_positions,
|
||||||
new_system,
|
new_system,
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user