better lifetime for variables in pohibiting set
This commit is contained in:
@ -206,9 +206,9 @@ impl Set {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Computes minimized prohibiting set from reactants and inhibitors.
|
/// Computes minimized prohibiting set from reactants and inhibitors.
|
||||||
/// Computes the powerset of the smallest reactants ∪ inhibitors set and
|
/// Computes the powerset of the union of all reactants ∪ inhibitors sets
|
||||||
/// checks for each element of that set if they are also in all other
|
/// and checks for each element of that set if they are also in all other
|
||||||
/// unions.
|
/// unions. Then minimizes the result.
|
||||||
pub fn prohibiting_set(
|
pub fn prohibiting_set(
|
||||||
reactants: &[Set],
|
reactants: &[Set],
|
||||||
inhibitors: &[Set],
|
inhibitors: &[Set],
|
||||||
@ -229,43 +229,49 @@ impl Set {
|
|||||||
inhibitors: {:?}",
|
inhibitors: {:?}",
|
||||||
r, i))
|
r, i))
|
||||||
}
|
}
|
||||||
let union = reactants.iter()
|
|
||||||
.zip(inhibitors.iter())
|
let mut t = {
|
||||||
.map(|(sr, si)| {
|
let union = reactants.iter()
|
||||||
sr.to_positive_set(IdState::Negative)
|
.zip(inhibitors.iter())
|
||||||
.union(&si.to_positive_set(IdState::Positive))
|
.map(|(sr, si)| {
|
||||||
})
|
sr.to_positive_set(IdState::Negative)
|
||||||
.collect::<Vec<_>>();
|
.union(&si.to_positive_set(IdState::Positive))
|
||||||
let union_union = union.iter()
|
})
|
||||||
.fold(PositiveSet::default(), |acc, s| acc.union(s));
|
.collect::<Vec<_>>();
|
||||||
let mut t = union_union.powerset();
|
let union_union = union.iter()
|
||||||
for set in union.iter() {
|
.fold(PositiveSet::default(), |acc, s| acc.union(s));
|
||||||
t.retain(|el| !el.intersection(set).is_empty());
|
let mut t = union_union.powerset();
|
||||||
}
|
for set in union.iter() {
|
||||||
|
t.retain(|el| !el.intersection(set).is_empty());
|
||||||
|
}
|
||||||
|
t
|
||||||
|
};
|
||||||
|
|
||||||
// minimization
|
// minimization
|
||||||
// remove sets that contain other sets
|
// remove sets that contain other sets
|
||||||
let mut tmp_t = t.clone().into_iter();
|
{
|
||||||
let mut e = tmp_t.next().unwrap_or_default();
|
let mut tmp_t = t.clone().into_iter();
|
||||||
loop {
|
let mut e = tmp_t.next().unwrap_or_default();
|
||||||
let mut modified = false;
|
loop {
|
||||||
t.retain(|set| {
|
let mut modified = false;
|
||||||
if *set == e {
|
t.retain(|set| {
|
||||||
true
|
if *set == e {
|
||||||
} else if e.is_subset(set) {
|
true
|
||||||
modified = true;
|
} else if e.is_subset(set) {
|
||||||
false
|
modified = true;
|
||||||
} else {
|
false
|
||||||
true
|
} else {
|
||||||
}
|
true
|
||||||
});
|
|
||||||
if !modified {
|
|
||||||
e = {
|
|
||||||
match tmp_t.next() {
|
|
||||||
Some(a) => a,
|
|
||||||
None => break,
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
if !modified {
|
||||||
|
e = {
|
||||||
|
match tmp_t.next() {
|
||||||
|
Some(a) => a,
|
||||||
|
None => break,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user