示例#1
0
        /// <summary>
        /// Determinizes the given automaton using the given set of initial states.
        /// </summary>
        /// <param name="a">The automaton.</param>
        /// <param name="initialset">The initial states.</param>
        internal static void Determinize(Automaton a, List <State> initialset)
        {
            char[] points = a.GetStartPoints();

            var comparer = new ListEqualityComparer <State>();

            // Subset construction.
            var sets     = new Dictionary <List <State>, List <State> >(comparer);
            var worklist = new LinkedList <List <State> >();
            var newstate = new Dictionary <List <State>, State>();

            sets.Add(initialset, initialset);
            worklist.AddLast(initialset);
            a.Initial = new State();
            newstate.Add(initialset, a.Initial);

            while (worklist.Count > 0)
            {
                List <State> s = worklist.RemoveAndReturnFirst();
                State        r;
                newstate.TryGetValue(s, out r);
                foreach (State q in s)
                {
                    if (q.Accept)
                    {
                        r.Accept = true;
                        break;
                    }
                }

                for (int n = 0; n < points.Length; n++)
                {
                    var p = (from qq in s from t in qq.Transitions where t.Min <= points[n] && points[n] <= t.Max select t.To).ToList();

                    if (!sets.ContainsKey(p))
                    {
                        sets.Add(p, p);
                        worklist.AddLast(p);
                        newstate.Add(p, new State());
                    }

                    State q;
                    newstate.TryGetValue(p, out q);
                    char min = points[n];
                    char max;
                    if (n + 1 < points.Length)
                    {
                        max = (char)(points[n + 1] - 1);
                    }
                    else
                    {
                        max = char.MaxValue;
                    }

                    r.Transitions.Add(new Transition(min, max, q));
                }
            }

            a.IsDeterministic = true;
            a.RemoveDeadTransitions();
        }
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.
 ///                 </param>
 public bool Equals(ListEqualityComparer <T> other)
 {
     return(!object.ReferenceEquals(null, other));
 }