loop_confluent, strong_confluent

This commit is contained in:
elvis
2025-06-23 17:07:46 +02:00
parent 454f1760ed
commit aa33e25771
2 changed files with 53 additions and 0 deletions

View File

@ -11,6 +11,7 @@ use super::perpetual::{
use super::structure::{RSenvironment, RSreaction, RSset}; use super::structure::{RSenvironment, RSreaction, RSset};
use super::translator::IdType; use super::translator::IdType;
use std::cmp; use std::cmp;
use std::collections::HashSet;
// see confluent, confluents // see confluent, confluents
@ -101,5 +102,46 @@ pub fn invariant_named(
} }
invariant.append(&mut new_prefix.clone()); invariant.append(&mut new_prefix.clone());
} }
// remove duplicates, maybe better with sorting?
invariant =
invariant
.iter()
.cloned()
.collect::<HashSet<_>>()
.iter()
.cloned()
.collect::<Vec<_>>();
Some((invariant, hoop)) Some((invariant, hoop))
} }
// -----------------------------------------------------------------------------
pub fn loop_confluent_named(
deltas: &[RSenvironment],
reaction_rules: &[RSreaction],
entities: &[RSset],
symb: IdType
) -> Option<Vec<(usize, usize, Vec<RSset>)>> {
deltas.iter()
.map(|q| confluent_named(q, reaction_rules, entities, symb))
.collect::<Option<Vec<_>>>()
}
#[allow(clippy::type_complexity)]
pub fn strong_confluent_named(
deltas: &[RSenvironment],
reaction_rules: &[RSreaction],
entities: &[RSset],
symb: IdType
) -> Option<Vec<(Vec<RSset>, usize, Vec<RSset>)>> {
deltas.iter()
.map(|q| {
let (invariant, hoop) = invariant_named(q,
reaction_rules,
entities,
symb)?;
let length = invariant.len();
Some((invariant, length, hoop)) }
)
.collect::<Option<Vec<_>>>()
}

View File

@ -1,6 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::hash::{Hash, Hasher};
use std::rc::Rc; use std::rc::Rc;
use super::translator::{IdType}; use super::translator::{IdType};
@ -79,6 +80,16 @@ impl RSset {
} }
} }
impl Hash for RSset {
fn hash<H: Hasher>(&self, state: &mut H) {
let mut a: Vec<&_> = self.identifiers.iter().collect();
a.sort();
for s in a.iter() {
s.hash(state);
}
}
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// RSreaction // RSreaction