public override HashSet <CGraphNode> Visit(CGraphNode node) { CCharRangeSet set; CIt_Successors it = new CIt_Successors(node); for (it.Begin(); !it.End(); it.Next()) { CGraphEdge edge = m_graph.Edge(node, it.M_CurrentItem); set = m_graph.GetFAEdgeInfo(edge); if (set != null && set.IsCharInSet(m_character)) { m_outputSet.Add(it.M_CurrentItem); } } return(m_outputSet); }
public override HashSet <CGraphNode> Visit(CGraphNode node) { m_outputSet.Add(node); //1.For each successor scan the nodes that have outgoing e transitions CIt_Successors it = new CIt_Successors(node); for (it.Begin(); !it.End(); it.Next()) { //Find the edge between node and its successor CGraphEdge edge = m_graph.Edge(node, it.M_CurrentItem); //if the edge label is e then visit the successor and append the output set including this successor if (TransitionLabel(edge) == null) { Visit(it.M_CurrentItem); } } // return(m_outputSet); }
public HashSet <CGraphNode> Start() { GraphLibrary.CGraphNode Qprime, Q; CGraphEdge e; CCharRangeSet set; //q0 ← -closure({n0}); HashSet <CGraphNode> q0 = CEclosureAlgorithm.Init(m_NFA, new HashSet <CGraphNode>() { m_NFA.M_Initial }).Start(); m_NFA.UpdateAlphabet(); // Create DFA m_DFA = new FA(); // DEBUG m_reporting.AddDFA(0, m_DFA); m_DFAInfo = new FAGraphQueryInfo(m_DFA, FA.m_FAINFOKEY); m_configurations = new CConfigurations(m_DFA, m_NFA); m_configurations.CreateDFANode(q0); //WorkList ← { q0}; m_workList.Enqueue(q0); while (m_workList.Count != 0) { HashSet <CGraphNode> q = m_workList.Dequeue(); Q = m_configurations.GetDFANode(q); // ********* DEBUG ************* CSubsetConstructionReporting.IterationRecord cRecord = m_reporting.AddIteration(0, q, Q); // for each NFA alphabet character foreach (CCharRange range in m_NFA.M_Alphabet) { foreach (Int32 i in range) { CDeltaAlgorithm delta = CDeltaAlgorithm.Init(m_NFA, i, q); HashSet <CGraphNode> deltaResult = delta.Start(); CEclosureAlgorithm eClosure = CEclosureAlgorithm.Init(m_NFA, deltaResult); HashSet <CGraphNode> qprime = eClosure.Start(); if (qprime.Count != 0) { Qprime = m_configurations.GetDFANode(qprime); if (Qprime == null) { m_workList.Enqueue(qprime); Qprime = m_configurations.CreateDFANode(qprime); } // Check if an edge between Q and Qprime alredy exists e = m_DFA.Edge(Q, Qprime); if (e == null) { e = m_DFA.AddGraphEdge <CGraphEdge, CGraphNode>(Q, Qprime, GraphType.GT_DIRECTED); set = new CCharRangeSet(false); m_DFAInfo.SetDFAEdgeTransitionCharacterSet(e, set); } else { set = m_DFAInfo.GetDFAEdgeTransitionCharacterSet(e); } set.AddRange(i); // ********** DEBUG ************ CSubsetConstructionReporting.EdgeRecord charRecord = cRecord.AddEdgeRecord(deltaResult, qprime, e); charRecord.AddCharacterCode(i); } } } } m_DFA.UpdateAlphabet(); m_DFA.RegisterGraphPrinter(new FAGraphVizPrinter(m_DFA, new UOPCore.Options <ThompsonOptions>())); m_DFA.Generate(@"mergeDFA.dot", true); // DEBUG m_reporting.Report("SubsetREPORT.txt"); return(null); }
public void Init() { // List of DFA nodes in minimized DFA node List <CGraphNode> configurationAcc, configurationNonAcc; // Create configuration (min-DFA node) for accepted nodes CGraphNode acceptedConf = m_minimizedDFA.CreateGraphNode <CGraphNode>(); // Create a list of initial-DFA nodes that are registered as accepted nodes configurationAcc = new List <CGraphNode>(); // Store the list for initial-DFA accepted nodes in the min-DFA for accepted nodes SetNodesInConfiguration(acceptedConf, configurationAcc); // Create configuration (min-DFA node) for non-accepted nodes CGraphNode non_acceptedConf = m_minimizedDFA.CreateGraphNode <CGraphNode>(); // Create a list for initial-DFA nodes that are registered as non-accepted nodes configurationNonAcc = new List <CGraphNode>(); // Store the list of initial-DFA non-accepted node in the min-DFA for accepted nodes SetNodesInConfiguration(non_acceptedConf, configurationNonAcc); // Separate accepted from non-accepted nodes into two distinct // configurations. Iterate over the input DFA and place the // accepted node into configurationAcc and none accepted nodes // into configurationNonAcc CIt_GraphNodes it = new CIt_GraphNodes(m_DFA); for (it.Begin(); !it.End(); it.Next()) { if (m_DFA.GetFinalStates().Contains(it.M_CurrentItem)) { // Record in the input DFA node the in which minimized DFA node // will be placed SetNodeConfiguration(it.M_CurrentItem, acceptedConf); configurationAcc.Add(it.M_CurrentItem); } else { // Record in the input DFA node the in which minimized DFA node // will be placed SetNodeConfiguration(it.M_CurrentItem, non_acceptedConf); configurationNonAcc.Add(it.M_CurrentItem); } } // ************************* Debug Initialization *************************** m_DFA.RegisterGraphPrinter(new FATextPrinter(m_DFA)); m_DFA.Generate("HopCroft_InitialDFA_.txt"); m_reporting.SetInitialMinDFAStatesContents(acceptedConf, configurationAcc, non_acceptedConf, configurationNonAcc); int nodeCount = 0; int iteration_count = 0; CIt_GraphNodes minDFA_it = new CIt_GraphNodes(m_minimizedDFA); // Iterate while the algorithm reaches a fixed point state while (nodeCount != m_minimizedDFA.M_NumberOfNodes) { nodeCount = m_minimizedDFA.M_NumberOfNodes; // ************************* Debug *************************** CIterationRecord currentIteration = m_reporting.AddIteration(iteration_count); for (minDFA_it.Begin(); !minDFA_it.End(); minDFA_it.Next()) { // ************************* Debug *************************** currentIteration.M_NodesToInspect.Add(minDFA_it.M_CurrentItem); currentIteration.M_InitialNodesConfiguration.Add(minDFA_it.M_CurrentItem, new List <CGraphNode>(GetNodesInConfiguration(minDFA_it.M_CurrentItem))); Split(minDFA_it.M_CurrentItem); } } // Draw the final edges // Edges between nodes of the initial DFA are mapped to edges between // configurations in minimized-DFA. Thus, edges are drawn between two // min-DFA related configurations when their corresponding nodes are // connected and their transition character set is combined CIt_GraphNodes minit1 = new CIt_GraphNodes(m_minimizedDFA); CIt_GraphNodes minit2 = new CIt_GraphNodes(m_minimizedDFA); List <CGraphNode> confs, conft; CGraphEdge edge, newedge; for (minit1.Begin(); !minit1.End(); minit1.Next()) { for (minit2.Begin(); !minit2.End(); minit2.Next()) { confs = GetNodesInConfiguration(minit1.M_CurrentItem); conft = GetNodesInConfiguration(minit2.M_CurrentItem); foreach (CGraphNode snode in confs) { foreach (CGraphNode tnode in conft) { edge = m_DFA.Edge(snode, tnode); if (edge != null) { // Disallow duplicate edges between nodes of the minimized DFA newedge = m_minimizedDFA.Edge(minit1.M_CurrentItem, minit2.M_CurrentItem); if (newedge == null) { newedge = m_minimizedDFA.AddGraphEdge <CGraphEdge, CGraphNode>(minit1.M_CurrentItem, minit2.M_CurrentItem, GraphType.GT_DIRECTED); } // Add transition characters if (GetMinDFAStateTransitionCharacterSet(newedge) == null) { SetMinDFAStateTransitionCharacterSet(newedge, new CCharRangeSet(false)); m_minimizedDFA.SetFAEdgeInfo(newedge, new CCharRangeSet(false)); } CCharRangeSet charset = GetMinDFAStateTransitionCharacterSet(newedge); m_minimizedDFA.GetFAEdgeInfo(newedge).AddSet(m_DFA.GetFAEdgeInfo(edge)); } } } } } // Detect accepted nodes in minimized DFA CIt_GraphNodes it1 = new CIt_GraphNodes(m_minimizedDFA); for (it1.Begin(); !it1.End(); it1.Next()) { List <CGraphNode> configuration = GetNodesInConfiguration(it1.M_CurrentItem); List <CGraphNode> finals = m_DFA.GetFinalStates(); foreach (CGraphNode node in configuration) { if (finals.Contains(node)) { m_minimizedDFA.SetFinalState(it1.M_CurrentItem); } } } // Detect initial state of minimized DFA for (it1.Begin(); !it1.End(); it1.Next()) { List <CGraphNode> configuration = GetNodesInConfiguration(it1.M_CurrentItem); CGraphNode initial = m_DFA.M_Initial; foreach (CGraphNode node in configuration) { if (initial == node) { m_minimizedDFA.M_Initial = it1.M_CurrentItem; } } } // Set Final minimized-DFA labels for (it1.Begin(); !it1.End(); it1.Next()) { List <CGraphNode> conf = GetNodesInConfiguration(it1.M_CurrentItem); foreach (CGraphNode iNode in conf) { HashSet <string> prefs = m_DFA.GetFANodePrefixLabels(iNode); foreach (string s in prefs) { m_minimizedDFA.SetFANodePrefix(s, it1.M_CurrentItem); } foreach (uint dependency in m_DFA.GetFANodeLineDependencies(iNode)) { m_minimizedDFA.SetFANodeLineDependency(dependency, it1.M_CurrentItem); } } m_minimizedDFA.PrefixElementLabel(m_minimizedDFA.GetFANodePrefix(it1.M_CurrentItem), it1.M_CurrentItem); } m_reporting.Report("HOPCROFTReport.txt"); FASerializer serializer = new FASerializer(m_minimizedDFA); serializer.Print(); m_DFA.RegisterGraphPrinter(new FAGraphVizPrinter(m_minimizedDFA, new UOPCore.Options <ThompsonOptions>())); m_DFA.Generate(@"minimizedDFA.dot", true); }