Пример #1
0
        public void Output()
        {
            Determ det = new Determ();

            det = NewMashine();

            string writePath = @"C:\temp\MyTest.txt";

            try
            {
                using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default))
                {
                    sw.Write("Alphabet: ");

                    for (int i = 0; i < det.Alphabet.Length; i++)
                    {
                        sw.Write(det.Alphabet[i] + ", ");
                    }
                    sw.Write("\n\n");

                    sw.Write("StateMachine: ");
                    for (int i = 0; i < det.StateMachine.Count; i++)
                    {
                        sw.Write(det.StateMachine[i] + ", ");
                    }
                    sw.Write("\n\n");

                    sw.Write("InitialStateMachine: ");
                    for (int i = 0; i < det.InitialStateMachine.Length; i++)
                    {
                        sw.Write(det.InitialStateMachine[i] + ", ");
                    }
                    sw.Write("\n\n");

                    sw.Write("FinalStateMachine: ");
                    for (int i = 0; i < det.FinalStateMachine.Count; i++)
                    {
                        sw.Write(det.FinalStateMachine[i] + ", ");
                    }
                    sw.Write("\n\n");

                    sw.Write("Transitions: ");
                    sw.Write("\n\n");
                    for (int i = 0; i < det.transitions.Count; i++)
                    {
                        sw.Write(det.transitions[i].ToString() + "\n");
                    }
                }
                Console.WriteLine("Запись выполнена");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #2
0
        public Determ NewMashine()
        {
            Determ result = new Determ();

            List <List <string> > CompositeState = new List <List <string> >();
            HashSet <string>      TmpStates      = new HashSet <string>();

            result.Alphabet            = Alphabet;
            result.InitialStateMachine = InitialStateMachine;
            result.StateMachine.Add(InitialStateMachine);
            var l = new List <string>();

            l.Add(InitialStateMachine);
            CompositeState.Add(l);

            for (int i = 0; i <= result.StateMachine.Count - 1; i++)
            {
                for (int j = 0; j < Alphabet.Length; j++)
                {
                    if (Alphabet[j] != "_")
                    {
                        TmpStates.Clear();
                        for (int k = 0; k < transitions.Count; k++)
                        {
                            if (CompositeState[i].Contains(transitions[k].From) && transitions[k].Symb == Alphabet[j])
                            {
                                TmpStates.Add(transitions[k].To);
                            }
                        }
                        EpsilonTransition(TmpStates);
                        List <string> names = new List <string>(TmpStates);
                        names.Sort();
                        if (names.Count > 0)
                        {
                            string statename = null;
                            for (int t = 0; t < CompositeState.Count; t++)
                            {
                                if (names.SequenceEqual(CompositeState[t]))
                                {
                                    statename = result.StateMachine[t];
                                    break;
                                }
                            }
                            if (statename == null)
                            {
                                statename = string.Join("_", names);
                                result.StateMachine.Add(statename);
                                CompositeState.Add(names);
                                TmpStates.IntersectWith(FinalStateMachine);
                                if (TmpStates.Count > 0)
                                {
                                    result.FinalStateMachine.Add(statename);
                                }
                            }
                            DTransition tr = new DTransition();
                            tr.From = result.StateMachine[i];
                            tr.Symb = Alphabet[j];
                            tr.To   = statename;
                            result.transitions.Add(tr);
                        }
                    }
                }
            }
            return(result);
        }