Exemplo n.º 1
0
        public static CEclosureAlgorithm Init(FA g, HashSet <CGraphNode> set)
        {
            //Make some checks on the input arguments

            // Create algorithm
            CEclosureAlgorithm newObjectAlgorithm = new CEclosureAlgorithm(g, set);



            return(newObjectAlgorithm);
        }
Exemplo n.º 2
0
        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);
        }