diff --git a/src/rsprocess/bisimilarity.rs b/src/rsprocess/bisimilarity.rs index 7443e08..372aa14 100644 --- a/src/rsprocess/bisimilarity.rs +++ b/src/rsprocess/bisimilarity.rs @@ -1,21 +1,11 @@ use std::collections::{BTreeSet, HashMap}; -use petgraph::visit::{EdgeIndexable, EdgeRef, IntoEdgeReferences, IntoEdges, IntoNodeReferences, NodeIndexable}; - - - - - - -#[allow(dead_code)] -fn print_type_of(_: &T) { - println!("type: {}", std::any::type_name::()); -} - - - - - +use petgraph::visit::{ EdgeIndexable, + EdgeRef, + IntoEdgeReferences, + IntoEdges, + IntoNodeReferences, + NodeIndexable }; struct GraphPartition<'a, G> where @@ -30,6 +20,25 @@ where blocks: BTreeSet } + +fn equal_vectors(a: &Vec, b: &Vec) -> bool +where + T: PartialEq +{ + for el in a { + if !b.contains(el) { + return false; + } + } + + for el in b { + if !a.contains(el) { + return false; + } + } + true +} + impl<'a, G> GraphPartition<'a, G> where G: EdgeIndexable + NodeIndexable + IntoEdgeReferences + IntoNodeReferences @@ -74,12 +83,13 @@ where &self, label: &G::EdgeRef, s: &(usize, G::NodeId) - ) -> Vec<(usize, G::NodeId)> + ) -> Vec where ::EdgeRef: PartialEq { let mut val = vec![]; for el in self.graphs[s.0].edges(s.1).filter(|x| x == label) { - val.push((s.0, el.target())); + let tmp = (s.0, el.target()); + val.push(*self.node_to_block.get(&tmp).unwrap()); } val } @@ -99,15 +109,13 @@ where let reachable_blocks_s = self.reachable_blocks(label, s); - 'outer: for t in nodes { + for t in nodes { let reachable_blocks_t = self.reachable_blocks(label, t); - for rbt in reachable_blocks_t { - if !reachable_blocks_s.contains(&rbt) { - b2.push(*t); - continue 'outer; - } + if equal_vectors(&reachable_blocks_s, &reachable_blocks_t) { + b1.push(t); + } else { + b2.push(*t); } - b1.push(t); } if b2.is_empty() { diff --git a/src/rsprocess/structure.rs b/src/rsprocess/structure.rs index bb47399..d49b18e 100644 --- a/src/rsprocess/structure.rs +++ b/src/rsprocess/structure.rs @@ -11,8 +11,7 @@ use serde::{Deserialize, Serialize}; // ----------------------------------------------------------------------------- /// Basic set of entities. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, - Deserialize)] +#[derive(Clone, Debug, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)] pub struct RSset { pub identifiers: BTreeSet, } @@ -118,6 +117,12 @@ impl Default for RSset { } } +impl PartialEq for RSset { + fn eq(&self, other: &Self) -> bool { + self.identifiers.eq(&other.identifiers) + } +} + impl IntoIterator for RSset { type Item = IdType; type IntoIter = std::collections::btree_set::IntoIter; @@ -491,7 +496,7 @@ impl Default for RSsystem { // ----------------------------------------------------------------------------- // RSlabel // ----------------------------------------------------------------------------- -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd)] +#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialOrd)] pub struct RSlabel { pub available_entities: RSset, pub context: RSset, @@ -555,6 +560,19 @@ impl Default for RSlabel { } } +impl PartialEq for RSlabel { + fn eq(&self, other: &Self) -> bool { + self.available_entities == other.available_entities && + self.context == other.context && + self.t == other.t && + self.reactants == other.reactants && + self.reactants_absent == other.reactants_absent && + self.inhibitors == other.inhibitors && + self.inhibitors_present == other.inhibitors_present && + self.products == other.products + } +} + // ----------------------------------------------------------------------------- // RSassertOp // ----------------------------------------------------------------------------- diff --git a/testing/first.system b/testing/first.system index f261659..1c7e3ae 100644 --- a/testing/first.system +++ b/testing/first.system @@ -4,4 +4,4 @@ Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)] Reactions: ([{a,b}, {c}, {b}]) -Bisimilarity ("testing/adversarial.system") > Print \ No newline at end of file +Bisimilarity ("testing/first.system") > Print