This commit is contained in:
elvis
2025-10-28 14:01:49 +01:00
parent 975b67bc79
commit f90308a11e
11 changed files with 474 additions and 197 deletions

View File

@ -59,7 +59,6 @@ impl<'a> MapEdges<'a, System, Label, Directed, u32> for SystemGraph {
}
}
/// Very inelegant way to provide our graph with a map method where the edges
/// are mapped until the first error.
pub trait PositiveMapEdges<'a, N: 'a, E, Ty, Ix>
@ -71,16 +70,33 @@ where
&self,
edge_map: &assert::positive_relabel::PositiveAssert,
translator: &mut translator::Translator,
) -> Result<Graph<PositiveSystem, assert::positive_relabel::PositiveAssertReturnValue, Ty, Ix>, String>;
) -> Result<
Graph<
PositiveSystem,
assert::positive_relabel::PositiveAssertReturnValue,
Ty,
Ix,
>,
String,
>;
}
impl<'a> PositiveMapEdges<'a, PositiveSystem, PositiveLabel, Directed, u32> for PositiveSystemGraph {
impl<'a> PositiveMapEdges<'a, PositiveSystem, PositiveLabel, Directed, u32>
for PositiveSystemGraph
{
fn map_edges(
&self,
edge_map: &assert::positive_relabel::PositiveAssert,
translator: &mut translator::Translator,
) -> Result<Graph<PositiveSystem, assert::positive_relabel::PositiveAssertReturnValue, Directed, u32>, String>
{
) -> Result<
Graph<
PositiveSystem,
assert::positive_relabel::PositiveAssertReturnValue,
Directed,
u32,
>,
String,
> {
use petgraph::graph::EdgeIndex;
let mut g = Graph::with_capacity(self.node_count(), self.edge_count());
@ -109,16 +125,16 @@ impl<'a> PositiveMapEdges<'a, PositiveSystem, PositiveLabel, Directed, u32> for
}
}
/// Given a graph and a function that identifies nodes of the graph, merges
/// nodes with the same identifier.
pub fn grouping(
graph: &mut Graph<System, Label>,
group: &assert::grouping::Assert,
translator: &mut rsprocess::translator::Translator
translator: &mut rsprocess::translator::Translator,
) -> Result<(), String> {
let mut buckets = std::collections::HashMap::new();
let mut leader: std::collections::HashMap<petgraph::prelude::NodeIndex, _> = std::collections::HashMap::new();
let mut leader: std::collections::HashMap<petgraph::prelude::NodeIndex, _> =
std::collections::HashMap::new();
for node in graph.node_indices() {
let val = group.execute(graph, &node, translator)?;
@ -167,10 +183,11 @@ pub fn grouping(
pub fn positive_grouping(
graph: &mut Graph<PositiveSystem, PositiveLabel>,
group: &assert::positive_grouping::PositiveAssert,
translator: &mut rsprocess::translator::Translator
translator: &mut rsprocess::translator::Translator,
) -> Result<(), String> {
let mut buckets = std::collections::HashMap::new();
let mut leader: std::collections::HashMap<petgraph::prelude::NodeIndex, _> = std::collections::HashMap::new();
let mut leader: std::collections::HashMap<petgraph::prelude::NodeIndex, _> =
std::collections::HashMap::new();
for node in graph.node_indices() {
let val = group.execute(graph, &node, translator)?;

View File

@ -628,9 +628,7 @@ where
/// Computes the LTS.
/// equivalent to main_do(digraph, Arcs) or to main_do(advdigraph, Arcs)
pub fn digraph(
system: &mut EvaluatedSystem,
) -> Result<(), String> {
pub fn digraph(system: &mut EvaluatedSystem) -> Result<(), String> {
if let (Some(sys), true) = (&system.sys, system.graph.is_none()) {
let graph = sys.digraph()?;
system.graph = Some(graph);
@ -651,7 +649,7 @@ pub fn grouping(
super::data::grouping(
system.graph.as_mut().unwrap(),
group,
&mut system.translator
&mut system.translator,
)
} else {
Err("Grouping can be done only on graphs.".into())