public DOTFormat(NODE startNode) { DOTString = new StringBuilder(); DOTString.AppendLine("digraph G {"); getGraphInDOT(startNode); DOTString.AppendLine("}"); }
private E_CLOSURE_NODE Perform_EClosureOperation(Stack <NODE> NFANodesStack, Dictionary <char, Stack <NODE> > moveToDictionary) { HashSet <NODE> visitedNodes = new HashSet <NODE>(); NODE nodeUnderProcess = null; E_CLOSURE_NODE eClosureNode = null; if (NFANodesStack.Count() != 0) { eClosureNode = E_CLOSURE_NODE.Create_Node(NODE_TYPE.TRANSITIONING); while (NFANodesStack.Count() != 0) { nodeUnderProcess = NFANodesStack.Pop(); eClosureNode.NFANodes.Add(nodeUnderProcess); if (nodeUnderProcess.nodeType == NODE_TYPE.END) { eClosureNode.nodeType = NODE_TYPE.END; } if (nodeUnderProcess.nodeType == NODE_TYPE.START) { eClosureNode.nodeType = NODE_TYPE.START; } foreach (EDGE edge in nodeUnderProcess.edges) { if (!visitedNodes.Contains(edge.nextNode)) { visitedNodes.Add(edge.nextNode); if (edge.transitionCharacter == CONSTANTS.EMPTY_SYMBOL) { NFANodesStack.Push(edge.nextNode); } else { if (!moveToDictionary.ContainsKey(edge.transitionCharacter)) { moveToDictionary.Add(edge.transitionCharacter, new Stack <NODE>()); } moveToDictionary[edge.transitionCharacter].Push(edge.nextNode); } } } } eClosureNode.NFANodes.OrderBy(NFANode => NFANode.NodeID); } return(eClosureNode); }
public NFA_GRAPH(string regExp_str) { regExp = regExp_str; NFA_GRAPH nfaGraph = null; nfaGraph = Get_NFAFromRE(0, this.regExp.Length, null); startNode = nfaGraph.startNode; endNode = nfaGraph.endNode; NODE.ClearCount(); }
public DFA_GRAPH(E_CLOSURE_GRAPH eClosureGraph) { if (eClosureGraph != null) { DFASets = new List <NODES_SET>(); DFANodes = new List <NODE>(); Get_DFAGraphFromEClosureGraph(eClosureGraph); Perform_DFAMinimization(); } NODE.ClearCount(); NODES_SET.ClearCount(); }
private bool IsNodeEquivalentToASet(NODE node, List <NODES_SET> sets) { bool isEquivalentToASet = false; foreach (NODES_SET set in sets) { if (AreNodesEquivalent(set.nodesSet.First(), node)) { set.nodesSet.Add(node); node.assignedSet = set; isEquivalentToASet = true; } } return(isEquivalentToASet); }
private void getGraphInDOT(NODE startNode) { NODE processingNode; HashSet <NODE> visitedNodes = new HashSet <NODE>(); Queue <NODE> nodesToProcess = new Queue <NODE>(); StringBuilder GraphInDOT = new StringBuilder(); StringBuilder EndNodes = new StringBuilder(); nodesToProcess.Enqueue(startNode); while (nodesToProcess.Count != 0) { processingNode = nodesToProcess.Dequeue(); visitedNodes.Add(processingNode); if (processingNode.nodeType == NODE_TYPE.END) { EndNodes.AppendLine(processingNode.NodeID + " [shape = doublecircle];"); } else if (processingNode.nodeType == NODE_TYPE.START) { EndNodes.AppendLine(processingNode.NodeID + " [shape = invtriangle];"); } foreach (EDGE edge in processingNode.edges) { if (edge.transitionCharacter != CONSTANTS.EMPTY_SYMBOL) { GraphInDOT.AppendLine(processingNode.NodeID + " -> " + edge.nextNode.NodeID + "[label=\"" + edge.transitionCharacter.ToString() + "\"];"); } else { GraphInDOT.AppendLine(processingNode.NodeID + " -> " + edge.nextNode.NodeID + "[label=\"empty\"];"); } if (!visitedNodes.Contains(edge.nextNode)) { nodesToProcess.Enqueue(edge.nextNode); } } } DOTString.Append(EndNodes); DOTString.Append(GraphInDOT); EndNodes.Clear(); GraphInDOT.Clear(); }
public Image drawGraph(NODE startNode) { DOTFormat graphInDOT = new DOTFormat(startNode); string executable = @"dot.exe"; string output = @".\external\tempgraph"; FileInfo file = new FileInfo(output); file.Directory.Create(); File.WriteAllText(output, graphInDOT.getDOTString()); Process process = new System.Diagnostics.Process(); // Stop the process from opening a new window process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; // Setup executable and parameters process.StartInfo.FileName = executable; process.StartInfo.Arguments = string.Format(@"{0} -Tjpg -O", output); // Go process.Start(); // and wait doe.exe to complete and exit process.WaitForExit(); //Process.Start(output + ".jpg"); Bitmap bitmap = null; using (Stream bmpStream = System.IO.File.Open(output + ".jpg", System.IO.FileMode.Open)) { Image image = Image.FromStream(bmpStream); bitmap = new Bitmap(image); } File.Delete(output); File.Delete(output + ".jpg"); return(bitmap); }
private void Get_DFAGraphFromEClosureGraph(E_CLOSURE_GRAPH eClosureGraph) { HashSet <E_CLOSURE_NODE> visitedNodes = new HashSet <E_CLOSURE_NODE>(); Stack <E_CLOSURE_NODE> EClosureNodesToProcess = new Stack <E_CLOSURE_NODE>(); Stack <NODE> NodesToProcess = new Stack <NODE>(); E_CLOSURE_NODE eClosureNodeInProcess = null; NODE node = null; NODE newNode = null; EClosureNodesToProcess.Push(eClosureGraph.StartNode); startNode = NODE.CreateNode(eClosureGraph.StartNode.nodeType, eClosureGraph.StartNode.NodeID); NodesToProcess.Push(startNode); while (EClosureNodesToProcess.Count != 0) { eClosureNodeInProcess = EClosureNodesToProcess.Pop(); node = NodesToProcess.Pop(); visitedNodes.Add(eClosureNodeInProcess); DFANodes.Add(node); foreach (EDGE edge in eClosureNodeInProcess.edges) { if (!visitedNodes.Contains((E_CLOSURE_NODE)edge.nextNode)) { newNode = NODE.CreateNode(edge.nextNode.nodeType, edge.nextNode.NodeID); } else { newNode = DFANodes.Find(findNode => findNode.NodeID == edge.nextNode.NodeID); } node.edges.Add(new EDGE(edge.transitionCharacter, newNode)); if (!visitedNodes.Contains((E_CLOSURE_NODE)edge.nextNode)) { EClosureNodesToProcess.Push((E_CLOSURE_NODE)edge.nextNode); NodesToProcess.Push(newNode); } } } }
public NFA_GRAPH(NODE assignedStartNode, NODE assignedEndNode) { this.startNode = assignedStartNode; this.endNode = assignedEndNode; }
public EDGE(char transitionChar, NODE next) { this.transitionCharacter = transitionChar; this.nextNode = next; }