refactoring
This commit is contained in:
@ -42,9 +42,7 @@ pub fn digraph(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn common_entities(
|
pub fn common_entities(graph: &RSgraph) -> RSset {
|
||||||
graph: &RSgraph
|
|
||||||
) -> RSset {
|
|
||||||
graph.node_references().fold(
|
graph.node_references().fold(
|
||||||
None,
|
None,
|
||||||
|acc, node|
|
|acc, node|
|
||||||
@ -73,28 +71,28 @@ pub enum GraphMapNodes {
|
|||||||
Context,
|
Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
type GraphMapNodesFnTy =
|
type GraphMapNodesFnTy<'a> =
|
||||||
dyn Fn(petgraph::prelude::NodeIndex, &RSsystem) -> String;
|
dyn Fn(petgraph::prelude::NodeIndex, &'a RSsystem) -> String + 'a;
|
||||||
/// Helper structure that holds a formatting function from node as RSsystem to
|
/// Helper structure that holds a formatting function from node as RSsystem to
|
||||||
/// string
|
/// string
|
||||||
pub struct GraphMapNodesTy {
|
pub struct GraphMapNodesTy<'a> {
|
||||||
functions: Vec<Box<GraphMapNodesFnTy>>,
|
functions: Vec<Box<GraphMapNodesFnTy<'a>>>,
|
||||||
translator: Rc<translator::Translator>
|
translator: Rc<translator::Translator>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> From<([GraphMapNodes; N], Rc<translator::Translator>)> for GraphMapNodesTy {
|
impl<'a, const N: usize> From<([GraphMapNodes; N], Rc<translator::Translator>)> for GraphMapNodesTy<'a> {
|
||||||
fn from(value: ([GraphMapNodes; N], Rc<translator::Translator>)) -> Self {
|
fn from(value: ([GraphMapNodes; N], Rc<translator::Translator>)) -> Self {
|
||||||
Self::from((value.0.to_vec(), value.1))
|
Self::from((value.0.to_vec(), value.1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(&[GraphMapNodes], Rc<translator::Translator>)> for GraphMapNodesTy {
|
impl<'a> From<(&[GraphMapNodes], Rc<translator::Translator>)> for GraphMapNodesTy<'a> {
|
||||||
fn from(value: (&[GraphMapNodes], Rc<translator::Translator>)) -> Self {
|
fn from(value: (&[GraphMapNodes], Rc<translator::Translator>)) -> Self {
|
||||||
Self::from((value.0.to_vec(), value.1))
|
Self::from((value.0.to_vec(), value.1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(Vec<GraphMapNodes>, Rc<translator::Translator>)> for GraphMapNodesTy {
|
impl<'a> From<(Vec<GraphMapNodes>, Rc<translator::Translator>)> for GraphMapNodesTy<'a> {
|
||||||
fn from(value: (Vec<GraphMapNodes>, Rc<translator::Translator>)) -> Self {
|
fn from(value: (Vec<GraphMapNodes>, Rc<translator::Translator>)) -> Self {
|
||||||
use GraphMapNodes::*;
|
use GraphMapNodes::*;
|
||||||
use super::format_helpers::graph_map_nodes_ty_from::*;
|
use super::format_helpers::graph_map_nodes_ty_from::*;
|
||||||
@ -140,12 +138,9 @@ impl From<(Vec<GraphMapNodes>, Rc<translator::Translator>)> for GraphMapNodesTy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphMapNodesTy {
|
impl<'a> GraphMapNodesTy<'a> {
|
||||||
pub fn generate<'a>(
|
pub fn generate(self) -> Box<GraphMapNodesFnTy<'a>> {
|
||||||
self
|
let mut accumulator: Box<GraphMapNodesFnTy<'a>> =
|
||||||
) -> Box<GraphMapNodesFnTy>
|
|
||||||
{
|
|
||||||
let mut accumulator: Box<GraphMapNodesFnTy> =
|
|
||||||
super::format_helpers::graph_map_nodes_ty_from::format_hide(
|
super::format_helpers::graph_map_nodes_ty_from::format_hide(
|
||||||
Rc::clone(&self.translator)
|
Rc::clone(&self.translator)
|
||||||
);
|
);
|
||||||
@ -184,27 +179,28 @@ pub enum GraphMapEdges {
|
|||||||
MaskEntitiesAdded { mask: RSset },
|
MaskEntitiesAdded { mask: RSset },
|
||||||
}
|
}
|
||||||
|
|
||||||
type GraphMapEdgesFnTy = dyn Fn(petgraph::prelude::EdgeIndex, &RSlabel) -> String;
|
type GraphMapEdgesFnTy<'a> =
|
||||||
|
dyn Fn(petgraph::prelude::EdgeIndex, &'a RSlabel) -> String + 'a;
|
||||||
/// Helper structure that holds a formatting function from node as RSsystem to
|
/// Helper structure that holds a formatting function from node as RSsystem to
|
||||||
/// string
|
/// string
|
||||||
pub struct GraphMapEdgesTy {
|
pub struct GraphMapEdgesTy<'a> {
|
||||||
functions: Vec<Box<GraphMapEdgesFnTy>>,
|
functions: Vec<Box<GraphMapEdgesFnTy<'a>>>,
|
||||||
translator: Rc<translator::Translator>
|
translator: Rc<translator::Translator>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> From<([GraphMapEdges; N], Rc<translator::Translator>)> for GraphMapEdgesTy {
|
impl<'a, const N: usize> From<([GraphMapEdges; N], Rc<translator::Translator>)> for GraphMapEdgesTy<'a> {
|
||||||
fn from(value: ([GraphMapEdges; N], Rc<translator::Translator>)) -> Self {
|
fn from(value: ([GraphMapEdges; N], Rc<translator::Translator>)) -> Self {
|
||||||
Self::from((value.0.to_vec(), value.1))
|
Self::from((value.0.to_vec(), value.1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(&[GraphMapEdges], Rc<translator::Translator>)> for GraphMapEdgesTy {
|
impl<'a> From<(&[GraphMapEdges], Rc<translator::Translator>)> for GraphMapEdgesTy<'a> {
|
||||||
fn from(value: (&[GraphMapEdges], Rc<translator::Translator>)) -> Self {
|
fn from(value: (&[GraphMapEdges], Rc<translator::Translator>)) -> Self {
|
||||||
Self::from((value.0.to_vec(), value.1))
|
Self::from((value.0.to_vec(), value.1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(Vec<GraphMapEdges>, Rc<translator::Translator>)> for GraphMapEdgesTy {
|
impl<'a> From<(Vec<GraphMapEdges>, Rc<translator::Translator>)> for GraphMapEdgesTy<'a> {
|
||||||
fn from(value: (Vec<GraphMapEdges>, Rc<translator::Translator>)) -> Self {
|
fn from(value: (Vec<GraphMapEdges>, Rc<translator::Translator>)) -> Self {
|
||||||
use GraphMapEdges::*;
|
use GraphMapEdges::*;
|
||||||
use super::format_helpers::graph_map_edges_ty_from::*;
|
use super::format_helpers::graph_map_edges_ty_from::*;
|
||||||
@ -292,11 +288,9 @@ impl From<(Vec<GraphMapEdges>, Rc<translator::Translator>)> for GraphMapEdgesTy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphMapEdgesTy {
|
impl<'a> GraphMapEdgesTy<'a> {
|
||||||
pub fn generate(
|
pub fn generate(self) -> Box<GraphMapEdgesFnTy<'a>> {
|
||||||
self
|
let mut accumulator: Box<GraphMapEdgesFnTy<'a>> =
|
||||||
) -> Box<GraphMapEdgesFnTy> {
|
|
||||||
let mut accumulator: Box<GraphMapEdgesFnTy> =
|
|
||||||
super::format_helpers::graph_map_edges_ty_from::format_hide(
|
super::format_helpers::graph_map_edges_ty_from::format_hide(
|
||||||
Rc::clone(&self.translator)
|
Rc::clone(&self.translator)
|
||||||
);
|
);
|
||||||
@ -317,11 +311,16 @@ impl GraphMapEdgesTy {
|
|||||||
use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences};
|
use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences};
|
||||||
|
|
||||||
type RSdotGraph = Graph<String, String, Directed, u32>;
|
type RSdotGraph = Graph<String, String, Directed, u32>;
|
||||||
type RSformatNodeTy =
|
type RSformatNodeTy<'a> =
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
&RSdotGraph,
|
&'a RSdotGraph,
|
||||||
<&RSdotGraph as IntoNodeReferences>::NodeRef
|
<&'a RSdotGraph as IntoNodeReferences>::NodeRef
|
||||||
) -> Option<String>;
|
) -> String + 'a;
|
||||||
|
type RSformatNodeTyOpt<'a> =
|
||||||
|
dyn Fn(
|
||||||
|
&'a RSdotGraph,
|
||||||
|
<&'a RSdotGraph as IntoNodeReferences>::NodeRef
|
||||||
|
) -> Option<String> + 'a;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum OperationType {
|
pub enum OperationType {
|
||||||
@ -373,9 +372,10 @@ pub enum NodeColorConditional {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct NodeColor {
|
pub struct NodeColor {
|
||||||
pub conditionals: Vec<(NodeColorConditional, String)>,
|
pub conditionals: Vec<(NodeColorConditional, String)>,
|
||||||
pub base_color: String
|
pub base_color: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn node_formatter_base_color(
|
pub fn node_formatter_base_color(
|
||||||
base_color: String
|
base_color: String
|
||||||
) -> String
|
) -> String
|
||||||
@ -383,44 +383,89 @@ pub fn node_formatter_base_color(
|
|||||||
", fillcolor=".to_string() + &base_color
|
", fillcolor=".to_string() + &base_color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn node_formatter(
|
fn match_node_color_conditional<'a>(
|
||||||
|
rule: &NodeColorConditional,
|
||||||
|
color: &String,
|
||||||
original_graph: Rc<RSgraph>,
|
original_graph: Rc<RSgraph>,
|
||||||
rule: NodeColorConditional,
|
star: Option<IdType>
|
||||||
color: String,
|
) -> Box<RSformatNodeTyOpt<'a>> {
|
||||||
star: Option<IdType>,
|
|
||||||
) -> Box<RSformatNodeTy>
|
|
||||||
{
|
|
||||||
use super::format_helpers::node_formatter::*;
|
use super::format_helpers::node_formatter::*;
|
||||||
match rule {
|
match rule {
|
||||||
NodeColorConditional::ContextConditional(ccc) => {
|
NodeColorConditional::ContextConditional(ccc) => {
|
||||||
match ccc {
|
match ccc {
|
||||||
ContextColorConditional::Nill => {
|
ContextColorConditional::Nill => {
|
||||||
format_nill(original_graph, color, star)
|
format_nill(Rc::clone(&original_graph),
|
||||||
|
color.to_string(),
|
||||||
|
star)
|
||||||
},
|
},
|
||||||
ContextColorConditional::RecursiveIdentifier(s) => {
|
ContextColorConditional::RecursiveIdentifier(s) => {
|
||||||
format_recursive_identifier(original_graph, color, star, s)
|
format_recursive_identifier(Rc::clone(&original_graph),
|
||||||
|
color.to_string(),
|
||||||
|
star,
|
||||||
|
*s)
|
||||||
},
|
},
|
||||||
ContextColorConditional::EntitySet(ot, set) => {
|
ContextColorConditional::EntitySet(ot, set) => {
|
||||||
format_entity_set(original_graph, color, star, ot, set)
|
format_entity_set(Rc::clone(&original_graph),
|
||||||
|
color.to_string(),
|
||||||
|
star,
|
||||||
|
*ot,
|
||||||
|
set.clone())
|
||||||
},
|
},
|
||||||
ContextColorConditional::NonDeterministicChoice => {
|
ContextColorConditional::NonDeterministicChoice => {
|
||||||
format_non_deterministic_choice(original_graph, color, star)
|
format_non_deterministic_choice(Rc::clone(&original_graph),
|
||||||
|
color.to_string(),
|
||||||
|
star)
|
||||||
},
|
},
|
||||||
ContextColorConditional::Summation => {
|
ContextColorConditional::Summation => {
|
||||||
format_summation(original_graph, color, star)
|
format_summation(Rc::clone(&original_graph),
|
||||||
|
color.to_string(),
|
||||||
|
star)
|
||||||
},
|
},
|
||||||
ContextColorConditional::WaitEntity => {
|
ContextColorConditional::WaitEntity => {
|
||||||
format_wait_entity(original_graph, color, star)
|
format_wait_entity(Rc::clone(&original_graph),
|
||||||
|
color.to_string(),
|
||||||
|
star)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NodeColorConditional::EntitiesConditional(ot, set) => {
|
NodeColorConditional::EntitiesConditional(ot, set) => {
|
||||||
format_entities_conditional(original_graph, color, star, ot, set)
|
format_entities_conditional(Rc::clone(&original_graph),
|
||||||
|
color.to_string(),
|
||||||
|
star,
|
||||||
|
*ot,
|
||||||
|
set.clone())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl NodeColor {
|
||||||
|
pub fn generate<'a>(
|
||||||
|
self,
|
||||||
|
original_graph: Rc<RSgraph>,
|
||||||
|
star: Option<IdType>
|
||||||
|
) -> Box<RSformatNodeTy<'a>> {
|
||||||
|
Box::new(
|
||||||
|
move |i, n| {
|
||||||
|
for (rule, color) in &self.conditionals {
|
||||||
|
let f = match_node_color_conditional(
|
||||||
|
rule,
|
||||||
|
color,
|
||||||
|
Rc::clone(&original_graph),
|
||||||
|
star
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some(s) = (f)(i, n) {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node_formatter_base_color(self.base_color.clone())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type RSformatEdgeTy =
|
type RSformatEdgeTy =
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
&RSdotGraph,
|
&RSdotGraph,
|
||||||
|
|||||||
@ -556,16 +556,21 @@ pub fn bisimilar(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Output Functions
|
// Output Functions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
type GraphMapNodesFnTy<'a> =
|
||||||
|
dyn Fn(petgraph::prelude::NodeIndex, &'a RSsystem) -> String + 'a;
|
||||||
fn generate_node_printing_fn<'a>(
|
fn generate_node_printing_fn<'a>(
|
||||||
node_display: &[NodeDisplay],
|
node_display: &[NodeDisplay],
|
||||||
graph: &graph::RSgraph,
|
graph: &graph::RSgraph,
|
||||||
translator: Rc<Translator>,
|
translator: Rc<Translator>,
|
||||||
) -> Box<dyn Fn(petgraph::prelude::NodeIndex, &'a RSsystem) -> String + 'a> {
|
) -> Box<GraphMapNodesFnTy<'a>> {
|
||||||
// The type cannot be aliased since rust doesnt like generics.
|
// The type cannot be aliased since rust doesnt like generics.
|
||||||
// We are iterating over the node_display and constructing a function
|
// We are iterating over the node_display and constructing a function
|
||||||
// (accumulator) that prints out our formatted nodes. So at each step we
|
// (accumulator) that prints out our formatted nodes. So at each step we
|
||||||
@ -601,11 +606,13 @@ fn generate_node_printing_fn<'a>(
|
|||||||
gmnt.generate()
|
gmnt.generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
|
||||||
|
type GraphMapEdgesFnTy<'a> =
|
||||||
|
dyn Fn(petgraph::prelude::EdgeIndex, &'a RSlabel) -> String + 'a;
|
||||||
fn generate_edge_printing_fn<'a>(
|
fn generate_edge_printing_fn<'a>(
|
||||||
edge_display: &[EdgeDisplay],
|
edge_display: &[EdgeDisplay],
|
||||||
translator: Rc<Translator>,
|
translator: Rc<Translator>,
|
||||||
) -> Box<dyn Fn(petgraph::prelude::EdgeIndex, &'a RSlabel) -> String + 'a> {
|
) -> Box<GraphMapEdgesFnTy<'a>> {
|
||||||
// The type cannot be aliased since rust doesnt like generics.
|
// The type cannot be aliased since rust doesnt like generics.
|
||||||
// We are iterating over the edge_display and constructing a function
|
// We are iterating over the edge_display and constructing a function
|
||||||
// (accumulator) that prints out our formatted nodes. So at each step we
|
// (accumulator) that prints out our formatted nodes. So at each step we
|
||||||
@ -630,34 +637,6 @@ fn generate_edge_printing_fn<'a>(
|
|||||||
gmet.generate()
|
gmet.generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
use petgraph::visit::IntoNodeReferences;
|
|
||||||
#[allow(clippy::type_complexity)]
|
|
||||||
fn generate_node_color_fn<'a>(
|
|
||||||
node_color: &'a graph::NodeColor,
|
|
||||||
original_graph: Rc<graph::RSgraph>,
|
|
||||||
translator: Rc<Translator>,
|
|
||||||
) -> Box<dyn Fn(
|
|
||||||
&Graph<String, String>,
|
|
||||||
<&Graph<String, String, petgraph::Directed, u32> as IntoNodeReferences>::NodeRef
|
|
||||||
) -> String + 'a>
|
|
||||||
{
|
|
||||||
Box::new(
|
|
||||||
move |i, n| {
|
|
||||||
let cloned_node_color = node_color.clone();
|
|
||||||
for (rule, color) in cloned_node_color.conditionals {
|
|
||||||
if let Some(s) = graph::node_formatter(
|
|
||||||
original_graph.clone(),
|
|
||||||
rule,
|
|
||||||
color,
|
|
||||||
translator.encode_not_mut("*")
|
|
||||||
)(i, n) {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
graph::node_formatter_base_color(node_color.base_color.to_string())
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn generate_edge_color_fn<'a>(
|
fn generate_edge_color_fn<'a>(
|
||||||
@ -691,7 +670,7 @@ pub fn dot(
|
|||||||
system: &EvaluatedSystem,
|
system: &EvaluatedSystem,
|
||||||
node_display: Vec<NodeDisplay>,
|
node_display: Vec<NodeDisplay>,
|
||||||
edge_display: Vec<EdgeDisplay>,
|
edge_display: Vec<EdgeDisplay>,
|
||||||
node_color: &graph::NodeColor,
|
node_color: graph::NodeColor,
|
||||||
edge_color: &graph::EdgeColor
|
edge_color: &graph::EdgeColor
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
match system {
|
match system {
|
||||||
@ -715,9 +694,8 @@ pub fn dot(
|
|||||||
let graph = Rc::new(graph.to_owned());
|
let graph = Rc::new(graph.to_owned());
|
||||||
|
|
||||||
let node_formatter =
|
let node_formatter =
|
||||||
generate_node_color_fn(node_color,
|
node_color.generate(Rc::clone(&graph),
|
||||||
Rc::clone(&graph),
|
translator.encode_not_mut("*"));
|
||||||
rc_translator);
|
|
||||||
let edge_formatter =
|
let edge_formatter =
|
||||||
generate_edge_color_fn(edge_color, graph);
|
generate_edge_color_fn(edge_color, graph);
|
||||||
|
|
||||||
@ -878,7 +856,7 @@ fn execute(
|
|||||||
edge_color: ec,
|
edge_color: ec,
|
||||||
so,
|
so,
|
||||||
} => {
|
} => {
|
||||||
save_options!(dot(system, nd, ed, &nc, &ec)?, so);
|
save_options!(dot(system, nd, ed, nc, &ec)?, so);
|
||||||
}
|
}
|
||||||
GraphSaveOptions::GraphML {
|
GraphSaveOptions::GraphML {
|
||||||
node_display: nd,
|
node_display: nd,
|
||||||
|
|||||||
Reference in New Issue
Block a user