Bisimilarity with assert in presets
This commit is contained in:
@ -119,6 +119,49 @@ common_label!(
|
||||
// helper functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// Very inelegant way to provide our graph with a map method where the edges
|
||||
/// are mapped until the first error.
|
||||
pub trait MapEdges<'a, N: 'a, E, Ty, Ix>
|
||||
where
|
||||
Ty: petgraph::EdgeType,
|
||||
Ix: petgraph::graph::IndexType
|
||||
{
|
||||
fn map_edges(
|
||||
&self,
|
||||
edge_map: &super::assert::RSassert,
|
||||
translator: &mut super::translator::Translator
|
||||
) -> Result<Graph<RSsystem, super::assert::AssertReturnValue, Ty, Ix>, String>;
|
||||
}
|
||||
|
||||
impl<'a> MapEdges<'a, RSsystem, RSlabel, Directed, u32>
|
||||
for RSgraph
|
||||
{
|
||||
fn map_edges(
|
||||
&self,
|
||||
edge_map: &super::assert::RSassert,
|
||||
translator: &mut super::translator::Translator
|
||||
)-> Result<Graph<RSsystem, super::assert::AssertReturnValue, Directed, u32>, String> {
|
||||
use petgraph::graph::EdgeIndex;
|
||||
|
||||
let mut g = Graph::with_capacity(self.node_count(), self.edge_count());
|
||||
let nodes = self.raw_nodes();
|
||||
let edges = self.raw_edges();
|
||||
|
||||
let edges = edges.iter().enumerate().map(
|
||||
|(i, edge)|
|
||||
match edge_map.execute(self, &EdgeIndex::new(i), translator) {
|
||||
Err(e) => Err(e),
|
||||
Ok(val) => Ok((edge.source(), edge.target(), val))
|
||||
}
|
||||
).collect::<Result<Vec<_>, _>>()?;
|
||||
nodes.iter().for_each(|node| { g.add_node(node.weight.clone()); });
|
||||
|
||||
edges.into_iter().for_each(|(source, target, v)| { g.add_edge(source, target, v); });
|
||||
|
||||
Ok(g)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Nodes -----------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user