/// <summary> /// Creates a unique dfa node for a given configuration /// The method assures that the configuration-dfa node mapping /// is unique /// </summary> /// <param name="q">The q.</param> /// <returns></returns> public CGraphNode CreateDFANode(HashSet <CGraphNode> q) { CGraphNode DFAnode = null; HashSet <string> prefixes = new HashSet <string>(); string prefix = ""; //check if q configuration corresponds to a DFA state DFAnode = GetDFANode(q); //if not create a new DFA node if (DFAnode == null) { DFAnode = m_DFA.CreateGraphNode <CGraphNode>(); foreach (CGraphNode node in q) { if (!prefixes.Contains(m_NFAStateInfo.Info(node).M_NodeLabelPrefix)) { prefixes.Add(m_NFAStateInfo.Info(node).M_NodeLabelPrefix); m_DFAStateInfo.Info(DFAnode).M_NodeLabelPrefix = m_NFAStateInfo.Info(node).M_NodeLabelPrefix; } foreach (uint lineDependency in m_NFAStateInfo.Info(node).M_LineDependencies) { m_DFA.SetFANodeLineDependency(lineDependency, DFAnode); } } foreach (string s in prefixes) { prefix += s; } m_DFA.PrefixElementLabel(prefix, DFAnode); if (ContainsFinalState(q)) { m_DFA.SetFinalState(DFAnode); } if (ContainsInitialState(q)) { m_DFA.M_Initial = DFAnode; } m_mappings[DFAnode] = q; } //else return the existing DFA node return(DFAnode); }
internal FA Synthesize(CCharRangeSet set) { FAGraphQueryInfo FAInfo; m_currentFA = new FA(); m_ThompsonInfo = new ThompsonInfo(m_currentFA, m_ThompsonInfoKey); FAInfo = new FAGraphQueryInfo(m_currentFA, FA.m_FAINFOKEY); //2.Create nodes initial-final CGraphNode init = m_currentFA.CreateGraphNode <CGraphNode>(); CGraphNode final = m_currentFA.CreateGraphNode <CGraphNode>(); m_ThompsonInfo.InitNodeInfo(init, new ThompsonNodeFAInfo()); m_ThompsonInfo.InitNodeInfo(final, new ThompsonNodeFAInfo()); m_currentFA.M_Initial = init; m_currentFA.SetFinalState(final); m_currentFA.M_Alphabet.AddSet(set); //3.Draw the edge including the character CGraphEdge newEdge = m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED); FAInfo.Info(newEdge).M_TransitionCharSet = set; return(m_currentFA); }
public override FA VisitRange(CASTElement currentNode) { CRange rangeNode = currentNode as CRange; FAGraphQueryInfo FAInfo; //1.Create FA m_NFA = new FA(); FAInfo = new FAGraphQueryInfo(m_NFA, FA.m_FAINFOKEY); //2.Create nodes initial-final CGraphNode init = m_NFA.CreateGraphNode <CGraphNode>(); CGraphNode final = m_NFA.CreateGraphNode <CGraphNode>(); m_NFA.M_Initial = init; m_NFA.SetFinalState(final); m_NFA.M_Alphabet.AddRange(rangeNode.MRange); //3.Draw the edge including the character CGraphEdge newEdge = m_NFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED); FAInfo.Info(newEdge).M_TransitionCharSet = (CCharRangeSet)rangeNode.MRange; newEdge.SetLabel(rangeNode.MRange.ToString()); m_ReportingServices.ExctractThompsonStep(m_NFA, @"../Debug/Range_" + rangeNode.MRange.ToString() + ".dot"); m_ReportingServices.AddThompsonStepToReporting(m_NFA); //4.Pass FA to the predecessor return(m_NFA); }
public override FA VisitRegexpbasicSet(CASTElement currentNode) { CRegexpbasicSet setNode = currentNode as CRegexpbasicSet; FAGraphQueryInfo FAInfo; //Create FA m_NFA = new FA(); FAInfo = new FAGraphQueryInfo(m_NFA, FA.m_FAINFOKEY); CGraphNode init = m_NFA.CreateGraphNode <CGraphNode>(); CGraphNode final = m_NFA.CreateGraphNode <CGraphNode>(); m_NFA.M_Initial = init; m_NFA.SetFinalState(final); m_NFA.M_Alphabet.AddSet(setNode.MSet); CGraphEdge newEdge = m_NFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED); FAInfo.Info(newEdge).M_TransitionCharSet = setNode.MSet; //4.Pass FA to the predecessor m_NFA.PrefixGraphElementLabels(m_currentRegularExpression.M_StatementID, GraphElementType.ET_NODE); m_ReportingServices.ExctractThompsonStep(m_NFA, @"../Debug/BasicSet_" + setNode.MSet.ToString() + ".dot"); m_ReportingServices.AddThompsonStepToReporting(m_NFA); return(m_NFA); }
public override StringBuilder Print() { StringBuilder FAText = new StringBuilder(1000); // Output Nodes CIt_GraphNodes itn = new CIt_GraphNodes(m_graph); for (itn.Begin(); !itn.End(); itn.Next()) { FAText.Append(itn.M_CurrentItem.M_Label); if (!itn.M_LastItem) { FAText.Append(", "); } else { FAText.Append("\n\n"); } } // Output edges CIt_GraphEdges ite = new CIt_GraphEdges(m_graph); for (ite.Begin(); !ite.End(); ite.Next()) { FAText.Append("\n" + ite.M_CurrentItem.M_Source.M_Label + "---" + m_FAInfo.Info(ite.M_CurrentItem).M_TransitionCharSet.ToString() + "---->" + ite.M_CurrentItem.M_Target.M_Label); } return(FAText); }
public override StringBuilder Print() { StringBuilder graphvizStringBuilder = new StringBuilder(1000); string header = "digraph G" + m_graph.M_SerialNumber + "{\r\n"; string graphedge_operator = "->"; CIt_GraphNodes itn = new CIt_GraphNodes(m_graph); CIt_GraphEdges itg = new CIt_GraphEdges(m_graph); FA fa = m_graph as FA; // Print header if necessary // Print the header if the graph is printed alone independently and not // in the context for example of a multigraph printing if (!m_options.IsSet(ThompsonOptions.TO_COMBINEGRAPHS)) { graphvizStringBuilder.Append(header); } for (itn.Begin(); !itn.End(); itn.Next()) { if (fa.GetFinalStates().Count != 0 && fa.GetFinalStates().Contains(itn.M_CurrentItem)) { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [peripheries=2];\n"); } else if (itn.M_CurrentItem == fa.M_Initial) { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=green];\n"); } else if (m_thompsonInfo.IsNodeClosureEntrance(itn.M_CurrentItem)) { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=red];\n"); } else if (m_thompsonInfo.IsNodeClosureExit(itn.M_CurrentItem)) { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=purple];\n"); } else { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\";\n"); } } // Print all edges of the graph for (itg.Begin(); !itg.End(); itg.Next()) { CGraphEdge g = itg.M_CurrentItem; string source, target; source = g.M_Source.M_Label; target = g.M_Target.M_Label; graphvizStringBuilder.AppendFormat("\"{0}\"" + graphedge_operator + "\"{1}\"", source, target); string s = m_FAInfo.Info(g).M_TransitionCharSet?.ToString(); if (s != null) { graphvizStringBuilder.AppendFormat(" [style = bold, label = \"" + m_FAInfo.Info(g).M_TransitionCharSet?.ToString() + "\"]"); } else { if (m_thompsonInfo.IsNodeClosureExit(g.M_Source) && m_thompsonInfo.IsNodeClosureEntrance(g.M_Target)) { graphvizStringBuilder.AppendFormat(" [color=red,style = bold, label = \"" + m_FAInfo.Info(g).M_TransitionCharSet?.ToString() + "\"]"); } } graphvizStringBuilder.Append(";\r\n"); } // Print footer if necessary // Print the header if the graph is printed alone independently and not // in the context for example of a multigraph printing if (!m_options.IsSet(ThompsonOptions.TO_COMBINEGRAPHS)) { graphvizStringBuilder.Append("}\r\n"); } return(graphvizStringBuilder); }
/// <summary> /// Prints the graph into a StringBuilder object. /// Optionally the header and footer of the .dot file can be ommited for use of the /// graph edges in the multi layer graph printer. /// </summary> /// <param name="onlyedges">if set to <c>true</c> [onlyedges] the graph is printed as a standalone graph.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override StringBuilder Print() { // Allocate a stringbuiler object and allocate space for 1000 characters StringBuilder graphvizStringBuilder = new StringBuilder(1000); string graphedge_operator = " "; string header = ""; string headerProperties = ""; CIt_GraphNodes itn = new CIt_GraphNodes(m_graph); CIt_GraphEdges itg = new CIt_GraphEdges(m_graph); FA fa = m_graph as FA; switch (m_graph.M_GraphType) { case GraphType.GT_UNDIRECTED: graphedge_operator = "--"; header = "graph G" + m_graph.M_SerialNumber + "{\r\n"; header += headerProperties; break; case GraphType.GT_DIRECTED: graphedge_operator = "->"; header = "digraph G" + m_graph.M_SerialNumber + "{\r\n"; header += headerProperties; break; case GraphType.GT_MIXED: break; } // Print header if necessary // Print the header if the graph is printed alone independently and not // in the context for example of a multigraph printing if (!m_options.IsSet(ThompsonOptions.TO_COMBINEGRAPHS)) { graphvizStringBuilder.Append(header); } // Print all nodes for (itn.Begin(); !itn.End(); itn.Next()) { if (fa.GetFinalStates().Count != 0 && fa.GetFinalStates().Contains(itn.M_CurrentItem)) { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [peripheries=2];\n"); } else if (itn.M_CurrentItem == fa.M_Initial) { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=green];\n"); } else { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\";\n"); } } // Print all edges of the graph for (itg.Begin(); !itg.End(); itg.Next()) { CGraphEdge g = itg.M_CurrentItem; string source, target; source = g.M_Source.M_Label; target = g.M_Target.M_Label; graphvizStringBuilder.AppendFormat("\"{0}\"" + graphedge_operator + "\"{1}\"", source, target); string s = m_FAInfo.Info(g).M_TransitionCharSet?.ToString(); if (s != null) { graphvizStringBuilder.AppendFormat(" [style = bold, label = \"" + m_FAInfo.Info(g).M_TransitionCharSet?.ToString() + "\"]"); } else { } graphvizStringBuilder.Append(";\r\n"); } // Print footer if necessary // Print the header if the graph is printed alone independently and not // in the context for example of a multigraph printing if (!m_options.IsSet(ThompsonOptions.TO_COMBINEGRAPHS)) { graphvizStringBuilder.Append("}\r\n"); } return(graphvizStringBuilder); }
public override StringBuilder Print() { // Allocate a stringbuiler object and allocate space for 1000 characters StringBuilder graphvizStringBuilder = new StringBuilder(1000); CIt_GraphNodes itn = new CIt_GraphNodes(m_graph); CIt_GraphEdges itg = new CIt_GraphEdges(m_graph); CSubsetConstructionInfo subsetInfo = new CSubsetConstructionInfo(m_graph, m_subsetInfoKey); Dictionary <int, List <CGraphNode> > closuresMap; FA fa = m_graph as FA; string graphedge_operator = "->"; closuresMap = subsetInfo.GetClosureNodesMapping(); //1. generate header string header = "digraph G" + m_graph.M_SerialNumber + "{\r\n"; graphvizStringBuilder.Append(header); foreach (KeyValuePair <int, List <CGraphNode> > closure in closuresMap) { string subgraphHeader = "\tsubgraph cluster" + closure.Key + " {\r\n"; string subgraphBody = "\t\tnode [style=filled];\r\n" + "\t\tstyle=filled;\r\n" + "\t\tcolor=lightgrey;\r\n" + "\t\tlabel =\"" + subsetInfo.Info(closure.Value[0]).M_ClosureExpression + "\";\r\n\t\t"; graphvizStringBuilder.Append(subgraphHeader + subgraphBody); foreach (CGraphNode node in closure.Value) { graphvizStringBuilder.Append(node.M_Label + ";"); } graphvizStringBuilder.AppendLine(); graphvizStringBuilder.Append("\t}"); } // Print all nodes for (itn.Begin(); !itn.End(); itn.Next()) { if (fa.GetFinalStates().Count != 0 && fa.GetFinalStates().Contains(itn.M_CurrentItem)) { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [peripheries=2];\n"); } else if (itn.M_CurrentItem == fa.M_Initial) { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=green];\n"); } else { graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\";\n"); } } // Print all edges of the graph for (itg.Begin(); !itg.End(); itg.Next()) { CGraphEdge g = itg.M_CurrentItem; string source, target; source = g.M_Source.M_Label; target = g.M_Target.M_Label; graphvizStringBuilder.AppendFormat("\"{0}\"" + graphedge_operator + "\"{1}\"", source, target); string s = m_FAInfo.Info(g).M_TransitionCharSet?.ToString(); if (s != null) { graphvizStringBuilder.AppendFormat(" [style = bold, label = \"" + m_FAInfo.Info(g).M_TransitionCharSet?.ToString() + "\"]"); } else { } graphvizStringBuilder.Append(";\r\n"); } graphvizStringBuilder.Append("}\r\n"); return(graphvizStringBuilder); }