now working bisimilarity

This commit is contained in:
elvis
2025-07-16 01:35:57 +02:00
parent e5f81301c6
commit 0ef51200e5
3 changed files with 55 additions and 29 deletions

View File

@ -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>(_: &T) {
println!("type: {}", std::any::type_name::<T>());
}
use petgraph::visit::{ EdgeIndexable,
EdgeRef,
IntoEdgeReferences,
IntoEdges,
IntoNodeReferences,
NodeIndexable };
struct GraphPartition<'a, G>
where
@ -30,6 +20,25 @@ where
blocks: BTreeSet<u32>
}
fn equal_vectors<T>(a: &Vec<T>, b: &Vec<T>) -> 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<u32>
where <G as IntoEdgeReferences>::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);
}
}
if b2.is_empty() {

View File

@ -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<IdType>,
}
@ -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<Self::Item>;
@ -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
// -----------------------------------------------------------------------------

View File

@ -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
Bisimilarity ("testing/first.system") > Print