rustfmt, fixed prohibiting set generation

This commit is contained in:
elvis
2025-09-07 17:55:53 +02:00
parent bf8bfd0d17
commit 49051358f0
27 changed files with 6138 additions and 6462 deletions

View File

@ -2,27 +2,30 @@
use std::rc::Rc;
use super::environment::BasicEnvironment;
use super::label::{Label, PositiveLabel};
use super::process::{BasicProcess, PositiveProcess, Process};
use super::reaction::BasicReaction;
use super::set::{BasicSet, PositiveSet, Set};
use super::system::{BasicSystem, PositiveSystem, System};
use super::reaction::BasicReaction;
use super::environment::BasicEnvironment;
#[derive(Clone, Debug)]
pub struct TransitionsIterator<'a, S: BasicSet,
Sys: BasicSystem<Set = S>,
Proc: BasicProcess<Set = S>> {
pub struct TransitionsIterator<
'a,
S: BasicSet,
Sys: BasicSystem<Set = S>,
Proc: BasicProcess<Set = S>,
> {
choices_iterator: std::vec::IntoIter<(Rc<S>, Rc<Proc>)>,
system: &'a Sys,
}
impl<'a> TransitionsIterator<'a, Set, System, Process> {
pub fn from(
system: &'a System
) -> Result<Self, String> {
match system.environment().unfold(system.context(),
system.available_entities()) {
pub fn from(system: &'a System) -> Result<Self, String> {
match system
.environment()
.unfold(system.context(), system.available_entities())
{
Ok(o) => Ok(TransitionsIterator {
choices_iterator: o.into_iter(),
system,
@ -39,13 +42,7 @@ impl<'a> Iterator for TransitionsIterator<'a, Set, System, Process> {
fn next(&mut self) -> Option<(Label, System)> {
let (c, k) = self.choices_iterator.next()?;
let t = self.system.available_entities.union(c.as_ref());
let (
reactants,
reactants_absent,
inhibitors,
inhibitors_present,
products
) =
let (reactants, reactants_absent, inhibitors, inhibitors_present, products) =
self.system.reaction_rules.iter().fold(
(
Set::default(), // reactants
@ -56,13 +53,13 @@ impl<'a> Iterator for TransitionsIterator<'a, Set, System, Process> {
),
|acc, reaction| {
if reaction.enabled(&t) {
(
(
acc.0.union(&reaction.reactants),
acc.1,
acc.2.union(&reaction.inhibitors),
acc.3,
acc.4.union(&reaction.products),
)
)
} else {
(
acc.0,
@ -98,56 +95,50 @@ impl<'a> Iterator for TransitionsIterator<'a, Set, System, Process> {
// -----------------------------------------------------------------------------
impl<'a> TransitionsIterator<'a, PositiveSet, PositiveSystem, PositiveProcess> {
pub fn from(
system: &'a PositiveSystem
) -> Result<Self, String> {
match system.environment().unfold(system.context(),
system.available_entities()) {
pub fn from(system: &'a PositiveSystem) -> Result<Self, String> {
match system
.environment()
.unfold(system.context(), system.available_entities())
{
Ok(o) => Ok(TransitionsIterator {
choices_iterator: o.into_iter(),
system,
}),
}),
Err(e) => Err(e),
}
}
}
impl<'a> Iterator for
TransitionsIterator<'a, PositiveSet, PositiveSystem, PositiveProcess> {
impl<'a> Iterator for TransitionsIterator<'a, PositiveSet, PositiveSystem, PositiveProcess> {
type Item = (PositiveLabel, PositiveSystem);
/// Creates the next arc from the current system.
fn next(&mut self) -> Option<Self::Item> {
let (c, k) = self.choices_iterator.next()?;
let (c, k) = self.choices_iterator.next()?;
let t = self.system.available_entities.union(c.as_ref());
let (
reactants,
reactants_absent,
products
) =
self.system.reaction_rules.iter().fold(
(
PositiveSet::default(), // reactants
PositiveSet::default(), // reactants_absent
PositiveSet::default(), // products
),
|acc, reaction| {
if reaction.enabled(&t) {
(
acc.0.union(&reaction.reactants),
acc.1,
acc.2.union(&reaction.products),
)
} else {
(
acc.0,
// TODO is this right?
acc.1.union(&reaction.reactants.intersection(&t)),
acc.2,
)
}
},
);
let (reactants, reactants_absent, products) = self.system.reaction_rules.iter().fold(
(
PositiveSet::default(), // reactants
PositiveSet::default(), // reactants_absent
PositiveSet::default(), // products
),
|acc, reaction| {
if reaction.enabled(&t) {
(
acc.0.union(&reaction.reactants),
acc.1,
acc.2.union(&reaction.products),
)
} else {
(
acc.0,
// TODO is this right?
acc.1.union(&reaction.reactants.intersection(&t)),
acc.2,
)
}
},
);
let label = PositiveLabel::from(
self.system.available_entities.clone(),