Exemplo n.º 1
0
        public Automaton <T> ConvertToDFA()
        {
            Console.WriteLine("Converting from NDFA to DFA...");

            var starters = new CombinedState <T>(epsilonClosure2(startStates));
            var result   = new Automaton <T>(alphabet);

            var set = new SortedSet <CombinedState <T> >();

            set.Add(starters);
            var res = ConvertToDFAInner(starters, set);

            result.AddTransition(res);

            result.DefineAsStartState(starters.ToT());

            //SortedSet<CombinedState<T>> endstates = new SortedSet<CombinedState<T>>();
            //endstates.Add(new CombinedState<T>(finalStates));
            var s         = new CombinedState <T>(finalStates);
            var endstates = result.transitions.Where(t => ListContainsElement(finalStates, t.ToState)).Select(t => t.ToState).ToList <T>();

            foreach (var item in endstates)
            {
                result.DefineAsFinalState(item);
            }

            Console.WriteLine("Conversion succesful\n");
            return(result);
        }
Exemplo n.º 2
0
        private SortedSet <Transition <T> > ConvertToDFAInner(CombinedState <T> starters, SortedSet <CombinedState <T> > total)
        {
            var result = new SortedSet <Transition <T> >();
            var combis = new SortedSet <CombinedState <T> >();

            foreach (var state in starters)
            {
                foreach (var c in alphabet)
                {
                    var states = new SortedSet <T>(GetToStates(state, c).Select(t => t.ToState).ToList <T>());
                    var temp   = new CombinedState <T>(epsilonClosure2(states));
                    if (temp.Count == 0)
                    {
                        continue;
                    }
                    combis.Add(temp);
                    var tran = new Transition <T>(starters.ToT(), c, temp.ToT());
                    //if (!String.IsNullOrEmpty(tran.FromState.ToString()) && !String.IsNullOrEmpty(tran.ToState.ToString()))
                    //{
                    result.Add(tran);
                    //}
                }
            }

            foreach (var item in combis)
            {
                //if (!(item.ToString() == starters.ToString()))
                if (!total.Contains(item))
                {
                    total.Add(item);
                    var tempres = ConvertToDFAInner(item, total);
                    foreach (var itm in tempres)
                    {
                        result.Add(itm);
                    }
                }
            }
            return(result);
        }