예제 #1
0
파일: Form1.cs 프로젝트: wgwjifeng/windows
        private void RedefineNumberOfSymbols(TuringMachine tm)
        {
            ArrayList     list = new ArrayList();
            StateTableRow row;

            for (int c = 0; c < (tm.NumberOfSymbols); c++)
            {
                row = new StateTableRow(
                    c,
                    "P#,R/L,go to S",
                    "P#,R/L,go to S",
                    "P#,R/L,go to S",
                    "P#,R/L,go to S",
                    "P#,R/L,go to S",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    ""
                    );
                list.Add(row);
            }
            dataGridView1.DataSource = list;
        }
예제 #2
0
파일: Form1.cs 프로젝트: wgwjifeng/windows
        private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            PropertyValueChangedEventArgs PropValue = (PropertyValueChangedEventArgs)e;

            System.Windows.Forms.PropertyGrid p = (System.Windows.Forms.PropertyGrid)s;
            TuringMachine tm = (TuringMachine)propertyGrid1.SelectedObject;

            switch (PropValue.ChangedItem.Label)
            {
            case ("NumberOfSymbols"):

                RedefineNumberOfSymbols(tm);
                break;

            case ("NumberOfStates"):

                //RedefineNumberOfSymbols(tm);
                RedefineNumberOfStates(tm);
                break;

            default:
                break;
            }
            ;
        }
예제 #3
0
파일: Form1.cs 프로젝트: wgwjifeng/windows
        private void newToolStripButton_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = null;

            propertyGrid1.SelectedObject = null;
            TM = null;
            CreateEmptyMachine();
            this.Refresh();
            toolStripComboBB.SelectedIndex = 0;
        }
예제 #4
0
        public TuringMachine ReplacingTM(string input)
        {
            TuringMachine tm = new TuringMachine(input);

            tm.control.AddTransition("start", "_", "*", "r", "q0");
            tm.control.AddTransition("q0", "0", "1", "r", "q0");
            tm.control.AddTransition("q0", "1", "0", "r", "q0");
            tm.control.AddTransition("q0", "_", "*", "*", "accept");

            return(tm);
        }
        static void Main(string[] args)
        {
            // Turing Machine for the language:
            // L = {0^n1^n : n >= 1}

            State[] q =
            {
                new State("q0", false),
                new State("q1", false),
                new State("q2", false),
                new State("q3", false),
                new State("q4", true)
            };

            HashSet <State> states = new HashSet <State>(q);


            HashSet <char> alphabet = new HashSet <char>();

            alphabet.Add('0');
            alphabet.Add('1');

            char blank = ' ';

            HashSet <char> tape_symbols = new HashSet <char>();

            tape_symbols.Add('0');
            tape_symbols.Add('1');
            tape_symbols.Add('X');
            tape_symbols.Add('Y');
            tape_symbols.Add(blank);

            State start_state = q[0];

            TuringMachine M = new TuringMachine(states, alphabet, tape_symbols, start_state, blank);

            M.AddTransition(new TransitionInput(q[0], '0'), new TransitionOutput(q[1], 'X', Directions.Right));
            M.AddTransition(new TransitionInput(q[1], '0'), new TransitionOutput(q[1], '0', Directions.Right));
            M.AddTransition(new TransitionInput(q[1], 'Y'), new TransitionOutput(q[1], 'Y', Directions.Right));
            M.AddTransition(new TransitionInput(q[1], '1'), new TransitionOutput(q[2], 'Y', Directions.Left));
            M.AddTransition(new TransitionInput(q[2], 'Y'), new TransitionOutput(q[2], 'Y', Directions.Left));
            M.AddTransition(new TransitionInput(q[2], '0'), new TransitionOutput(q[2], '0', Directions.Left));
            M.AddTransition(new TransitionInput(q[2], 'X'), new TransitionOutput(q[0], 'X', Directions.Right));
            M.AddTransition(new TransitionInput(q[0], 'Y'), new TransitionOutput(q[3], 'Y', Directions.Right));
            M.AddTransition(new TransitionInput(q[3], 'Y'), new TransitionOutput(q[3], 'Y', Directions.Right));
            M.AddTransition(new TransitionInput(q[3], blank), new TransitionOutput(q[4], blank, Directions.Right));

            M.Execute("0000111", false);

            Console.WriteLine();
        }
예제 #6
0
        static void Main(string[] args)
        {
            int    option;
            string input;

            TuringMachine tm = new TuringMachine("");
            Program       p  = new Program();


            Console.WriteLine(
                "1. replace 1s with 0s in a string and vice versa\n" +
                "2. concatenate 2 strings of symbols x, y,z\n" +
                "3. reverse a string of 0s and 1s\n" +
                "\nenter number of chosen TM:"
                );

            option = Int32.Parse(Console.ReadLine());

            switch (option)
            {
            case 1:
                Console.WriteLine("enter input\nuse only 0s and 1s");
                input = Console.ReadLine();
                tm    = p.ReplacingTM(input);
                break;

            case 2:
                Console.WriteLine("enter input\nuse only x, y and z, separate strings with '_'");
                input = Console.ReadLine();
                tm    = p.ConcatenatingTM(input);
                break;

            case 3:
                Console.WriteLine("enter input\nuse only 0s and 1s");
                input = Console.ReadLine();
                tm    = p.ReversingTM(input);
                break;
            }

            tm.TurnOn();

            Console.WriteLine("finished");
            Console.Read();
        }
예제 #7
0
        public TuringMachine ReversingTM(string input)
        {
            TuringMachine tm = new TuringMachine(input);

            tm.control.AddTransition("start", "_", "*", "r", "q0");
            tm.control.AddTransition("q0", "*", "*", "r", "q0");
            tm.control.AddTransition("q0", "_", "#", "l", "q1");
            tm.control.AddTransition("q1", "0", "#", "r", "q2x");
            tm.control.AddTransition("q1", "1", "#", "r", "q2y");
            tm.control.AddTransition("q1", "#", "*", "l", "q1");
            tm.control.AddTransition("q1", "_", "*", "*", "accept");
            tm.control.AddTransition("q2x", "_", "0", "l", "q3");
            tm.control.AddTransition("q2y", "_", "1", "l", "q3");
            tm.control.AddTransition("q2x", "*", "*", "r", "q2x");
            tm.control.AddTransition("q2y", "*", "*", "r", "q2y");
            tm.control.AddTransition("q3", "*", "*", "l", "q3");
            tm.control.AddTransition("q3", "#", "*", "l", "q1");

            return(tm);
        }
예제 #8
0
파일: Form1.cs 프로젝트: wgwjifeng/windows
        private void CreateEmptyMachine()
        {
            if (TM == null)
            {
                TM = new TuringMachine();

                TM.MachineHeadMove   += new MachineHeadMoveEventHandler(TuringMachine_HeadMove);
                TM.MachineHalt       += new MachineHaltEventHandler(TuringMachine_Halt);
                TM.MachineProcess    += new MachineProcessEventHandler(TuringMachine_Process);
                TM.MachineStart      += new MachineStartEventHandler(TuringMachine_Start);
                TM.MachineTapeResize += new MachineTapeResizeEventHandler(TuringMachine_TapeResize);
                TM.MachineException  += new MachineExceptionEventHandler(TuringMachine_Exception);

                propertyGrid1.SelectedObject = TM;
            }

            CreateGraphicTapeAndHead();

            txtConsole.BackColor = System.Drawing.Color.FromArgb(255, 224, 192);
        }
예제 #9
0
파일: Form1.cs 프로젝트: wgwjifeng/windows
        private void LoadSampleMachine()
        {
            TM = null;
            CreateEmptyMachine();

            try
            {
                switch (toolStripComboBB.SelectedIndex)
                {
                case 1:
                    TM.TapeLength = 150;
                    CreateBB32();
                    writeConsole("Busy Beaver Machine 3 states 2 symbols loaded");
                    break;

                case 2:
                    TM.TapeLength = 150;
                    CreateBB42();
                    writeConsole("Busy Beaver Machine 4 states 2 symbols loaded");
                    break;

                case 3:
                    TM.TapeLength = 150;
                    CreateBB52();
                    writeConsole("Busy Beaver Machine 5 states 2 symbols loaded");
                    break;

                case 4:
                    TM.TapeLength = 150;
                    CreateBB62();
                    TM.StepThrough = true;
                    writeConsole("Busy Beaver Machine 6 states 2 symbols loaded");
                    break;
                }
                ;
            }
            catch (Exception ex)
            {
                writeConsole(ex.Message);
            }
        }
예제 #10
0
        public TuringMachine ConcatenatingTM(string input)
        {
            TuringMachine tm = new TuringMachine(input);

            tm.control.AddTransition("start", "_", "*", "r", "q0");
            tm.control.AddTransition("q0", "_", "#", "r", "q1");
            tm.control.AddTransition("q0", "*", "*", "r", "q0");
            tm.control.AddTransition("q1", "_", "*", "*", "q4");
            tm.control.AddTransition("q1", "x", "0", "l", "q2x");
            tm.control.AddTransition("q1", "y", "1", "l", "q2y");
            tm.control.AddTransition("q1", "z", "2", "l", "q2z");
            tm.control.AddTransition("q2x", "#", "x", "r", "q3");
            tm.control.AddTransition("q2x", "*", "*", "l", "q2x");
            tm.control.AddTransition("q2y", "#", "y", "r", "q3");
            tm.control.AddTransition("q2y", "*", "*", "l", "q2y");
            tm.control.AddTransition("q2z", "#", "z", "r", "q3");
            tm.control.AddTransition("q2z", "*", "*", "l", "q2z");
            tm.control.AddTransition("q3", "*", "#", "r", "q1");
            tm.control.AddTransition("q4", "*", "*", "l", "q4");
            tm.control.AddTransition("q4", "#", "_", "*", "accept");

            return(tm);
        }
예제 #11
0
파일: Form1.cs 프로젝트: wgwjifeng/windows
        private void RedefineNumberOfStates(TuringMachine tm)
        {
            if (tm.NumberOfStates > 12)
            {
                tm.NumberOfStates = 12;
            }

            if (tm.NumberOfStates < 2)
            {
                tm.NumberOfStates = 2;
            }

            for (int c = 0; c < (dataGridView1.ColumnCount); c++)
            {
                if (c > tm.NumberOfStates)
                {
                    dataGridView1.Columns[c].Visible = false;
                }
                else
                {
                    dataGridView1.Columns[c].Visible = true;
                }
            }
        }