Exemple #1
0
        public static Automaton <String> getExampleSlide8Lesson2()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("q0", 'a', "q1"));
            m.AddTransition(new Transition <String>("q0", 'b', "q4"));

            m.AddTransition(new Transition <String>("q1", 'a', "q4"));
            m.AddTransition(new Transition <String>("q1", 'b', "q2"));

            m.AddTransition(new Transition <String>("q2", 'a', "q3"));
            m.AddTransition(new Transition <String>("q2", 'b', "q4"));

            m.AddTransition(new Transition <String>("q3", 'a', "q1"));
            m.AddTransition(new Transition <String>("q3", 'b', "q2"));

            // the error state, loops for a and b:
            m.AddTransition(new Transition <String>("q4", 'a'));
            m.AddTransition(new Transition <String>("q4", 'b'));

            // only on start state in a dfa:
            m.DefineAsStartState("q0");

            // two final states:
            m.DefineAsFinalState("q2");
            m.DefineAsFinalState("q3");

            return(m);
        }
Exemple #2
0
        public static Automaton <String> getExampleSlide14Lesson2()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("A", 'a', "C"));
            m.AddTransition(new Transition <String>("A", 'b', "B"));
            m.AddTransition(new Transition <String>("A", 'b', "C"));

            m.AddTransition(new Transition <String>("B", 'b', "C"));
            m.AddTransition(new Transition <String>("B", "C"));

            m.AddTransition(new Transition <String>("C", 'a', "D"));
            m.AddTransition(new Transition <String>("C", 'a', "E"));
            m.AddTransition(new Transition <String>("C", 'b', "D"));

            m.AddTransition(new Transition <String>("D", 'a', "B"));
            m.AddTransition(new Transition <String>("D", 'a', "C"));

            m.AddTransition(new Transition <String>("E", 'a'));
            m.AddTransition(new Transition <String>("E", "D"));

            // only on start state in a dfa:
            m.DefineAsStartState("A");

            // two final states:
            m.DefineAsFinalState("C");
            m.DefineAsFinalState("E");

            return(m);
        }
Exemple #3
0
        public static Automaton <String> Opdracht5Checklist()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("A", 'b', "B"));
            m.AddTransition(new Transition <String>("A", 'a', "C"));
            m.AddTransition(new Transition <String>("A", 'b', "C"));

            m.AddTransition(new Transition <String>("B", 'b', "C"));
            m.AddTransition(new Transition <String>("B", "C"));

            m.AddTransition(new Transition <String>("C", 'a', "E"));
            m.AddTransition(new Transition <String>("C", 'a', "D"));
            m.AddTransition(new Transition <String>("C", 'b', "D"));

            m.AddTransition(new Transition <String>("D", 'a', "B"));
            m.AddTransition(new Transition <String>("D", 'a', "C"));

            m.AddTransition(new Transition <String>("E", "D"));
            m.AddTransition(new Transition <String>("E", 'b', "E"));


            m.DefineAsStartState("A");

            m.DefineAsFinalState("C");
            m.DefineAsFinalState("E");

            return(m);
        }
Exemple #4
0
        public static Automaton <String> Opdracht6Checklist()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("q0", 'a', "q2"));
            m.AddTransition(new Transition <String>("q0", 'b', "q3"));

            m.AddTransition(new Transition <String>("q1", 'a', "q3"));
            m.AddTransition(new Transition <String>("q1", 'b', "q2"));

            m.AddTransition(new Transition <String>("q2", 'a', "q0"));
            m.AddTransition(new Transition <String>("q2", 'b', "q4"));

            m.AddTransition(new Transition <String>("q3", 'a', "q1"));
            m.AddTransition(new Transition <String>("q3", 'b', "q5"));

            m.AddTransition(new Transition <String>("q4", 'a', "q6"));
            m.AddTransition(new Transition <String>("q4", 'b', "q5"));

            m.AddTransition(new Transition <String>("q5", 'a', "q2"));
            m.AddTransition(new Transition <String>("q5", 'b', "q0"));

            m.AddTransition(new Transition <String>("q6", 'a', "q4"));
            m.AddTransition(new Transition <String>("q6", 'b', "q0"));

            m.DefineAsStartState("q0");

            m.DefineAsFinalState("q1");
            m.DefineAsFinalState("q3");
            m.DefineAsFinalState("q4");
            m.DefineAsFinalState("q6");

            return(m);
        }
Exemple #5
0
        public static Automaton <String> bevatEvenAantalBsOfOnevenAantalAs()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("q1", 'a', "q2"));
            m.AddTransition(new Transition <String>("q1", 'b', "q3"));

            m.AddTransition(new Transition <String>("q2", 'a', "q1"));
            m.AddTransition(new Transition <String>("q2", 'b', "q4"));

            m.AddTransition(new Transition <String>("q3", 'a', "q3"));
            m.AddTransition(new Transition <String>("q3", 'b', "q1"));

            m.AddTransition(new Transition <String>("q4", 'a', "q3"));
            m.AddTransition(new Transition <String>("q4", 'b', "q2"));

            m.DefineAsStartState("q1");

            m.DefineAsFinalState("q1");
            m.DefineAsFinalState("q2");
            m.DefineAsFinalState("q4");

            return(m);
        }
Exemple #6
0
        public static Automaton <String> begintMetABBOfEindigtOpBAAB()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("q0", 'a', "q1"));
            m.AddTransition(new Transition <String>("q0", 'b', "q4"));

            m.AddTransition(new Transition <String>("q1", 'a', "q4"));
            m.AddTransition(new Transition <String>("q1", 'b', "q2"));

            m.AddTransition(new Transition <String>("q2", 'a', "q3"));
            m.AddTransition(new Transition <String>("q2", 'b', "q5"));

            m.AddTransition(new Transition <String>("q3", 'a', "q1"));
            m.AddTransition(new Transition <String>("q3", 'b', "q2"));

            m.AddTransition(new Transition <String>("q4", 'a'));
            m.AddTransition(new Transition <String>("q4", 'b'));

            m.DefineAsStartState("q0");

            m.DefineAsFinalState("q5");
            m.DefineAsFinalState("q6");

            return(m);
        }
Exemple #7
0
        public static Automaton <String> SampleNDFA()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("q1", 'a', "q1"));
            m.AddTransition(new Transition <String>("q1", 'a', "q2"));
            m.AddTransition(new Transition <String>("q1", "q2"));

            m.AddTransition(new Transition <String>("q2", 'b', "q3"));
            m.AddTransition(new Transition <String>("q2", 'a', "q1"));


            //m.AddTransition(new Transition<String>("q3", 'a', "q3"));
            //m.AddTransition(new Transition<String>("q3", "q1"));

            //m.AddTransition(new Transition<String>("q4", 'a', "q3"));
            //m.AddTransition(new Transition<String>("q4", 'b', "q2"));

            m.DefineAsStartState("q1");

            m.DefineAsFinalState("q3");

            return(m);
        }
Exemple #8
0
        public static Automaton <String> bevatEvenAantalBsEnEindigtOpAAB()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("q1", 'a', "q2"));
            m.AddTransition(new Transition <String>("q1", 'b', "q5"));

            m.AddTransition(new Transition <String>("q2", 'a', "q3"));
            m.AddTransition(new Transition <String>("q2", 'b', "q5"));

            m.AddTransition(new Transition <String>("q3", 'a', "q3"));
            m.AddTransition(new Transition <String>("q3", 'b', "q8"));

            m.AddTransition(new Transition <String>("q4", 'a', "q2"));
            m.AddTransition(new Transition <String>("q4", 'b', "q5"));

            m.AddTransition(new Transition <String>("q5", 'a', "q6"));
            m.AddTransition(new Transition <String>("q5", 'b', "q1"));

            m.AddTransition(new Transition <String>("q6", 'a', "q7"));
            m.AddTransition(new Transition <String>("q6", 'b', "q1"));

            m.AddTransition(new Transition <String>("q7", 'a', "q7"));
            m.AddTransition(new Transition <String>("q7", 'b', "q4"));

            m.AddTransition(new Transition <String>("q8", 'a', "q6"));
            m.AddTransition(new Transition <String>("q8", 'b', "q1"));

            m.DefineAsStartState("q1");

            m.DefineAsFinalState("q4");

            return(m);
        }
Exemple #9
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);
        }
Exemple #10
0
        public Automaton <String> GetAutomaton()
        {
            char[] alphabet  = { 'a', 'b' };
            var    automaton = new Automaton <String>(alphabet);

            var transitions = GetAutomatonInner(this, 0);

            foreach (var item in transitions.Item1)
            {
                automaton.AddTransition(item);
            }

            automaton.DefineAsStartState("q" + transitions.Item2);

            automaton.DefineAsFinalState("q" + transitions.Item3);
            //automaton.DefineAsFinalState("q6");

            return(automaton);
        }
Exemple #11
0
        public static Automaton <String> begintMetABBEnBevatBAAB()
        {
            char[]             alphabet = { 'a', 'b' };
            Automaton <String> m        = new Automaton <String>(alphabet);

            m.AddTransition(new Transition <String>("q1", 'a', "q6"));
            m.AddTransition(new Transition <String>("q1", 'b', "q22"));

            m.AddTransition(new Transition <String>("q2", 'a', "q8"));
            m.AddTransition(new Transition <String>("q2", 'b', "q22"));

            m.AddTransition(new Transition <String>("q3", 'a', "q9"));
            m.AddTransition(new Transition <String>("q3", 'b', "q22"));

            m.AddTransition(new Transition <String>("q4", 'a', "q6"));
            m.AddTransition(new Transition <String>("q4", 'b', "q25"));

            m.AddTransition(new Transition <String>("q5", 'a', "q10"));
            m.AddTransition(new Transition <String>("q5", 'b', "q25"));

            m.AddTransition(new Transition <String>("q6", 'a', "q21"));
            m.AddTransition(new Transition <String>("q6", 'b', "q12"));

            m.AddTransition(new Transition <String>("q7", 'a', "q23"));
            m.AddTransition(new Transition <String>("q7", 'b', "q12"));

            m.AddTransition(new Transition <String>("q8", 'a', "q24"));
            m.AddTransition(new Transition <String>("q8", 'b', "q12"));

            m.AddTransition(new Transition <String>("q9", 'a', "q21"));
            m.AddTransition(new Transition <String>("q9", 'b', "q15"));

            m.AddTransition(new Transition <String>("q10", 'a', "q25"));
            m.AddTransition(new Transition <String>("q10", 'b', "q15"));

            m.AddTransition(new Transition <String>("q11", 'a', "q21"));
            m.AddTransition(new Transition <String>("q11", 'b', "q17"));

            m.AddTransition(new Transition <String>("q12", 'a', "q23"));
            m.AddTransition(new Transition <String>("q12", 'b', "q17"));

            m.AddTransition(new Transition <String>("q13", 'a', "q24"));
            m.AddTransition(new Transition <String>("q13", 'b', "q17"));

            m.AddTransition(new Transition <String>("q14", 'a', "q21"));
            m.AddTransition(new Transition <String>("q14", 'b', "q20"));

            m.AddTransition(new Transition <String>("q15", 'a', "q25"));
            m.AddTransition(new Transition <String>("q15", 'b', "q20"));

            m.AddTransition(new Transition <String>("q16", 'a', "q16"));
            m.AddTransition(new Transition <String>("q16", 'b', "q17"));

            m.AddTransition(new Transition <String>("q17", 'a', "q18"));
            m.AddTransition(new Transition <String>("q17", 'b', "q17"));

            m.AddTransition(new Transition <String>("q18", 'a', "q19"));
            m.AddTransition(new Transition <String>("q18", 'b', "q17"));

            m.AddTransition(new Transition <String>("q19", 'a', "q16"));
            m.AddTransition(new Transition <String>("q19", 'b', "q20"));

            m.AddTransition(new Transition <String>("q20", 'a', "q20"));
            m.AddTransition(new Transition <String>("q20", 'b', "q20"));

            m.AddTransition(new Transition <String>("q21", 'a', "q21"));
            m.AddTransition(new Transition <String>("q21", 'b', "q22"));

            m.AddTransition(new Transition <String>("q22", 'a', "q23"));
            m.AddTransition(new Transition <String>("q22", 'b', "q22"));

            m.AddTransition(new Transition <String>("q23", 'a', "q24"));
            m.AddTransition(new Transition <String>("q23", 'b', "q22"));

            m.AddTransition(new Transition <String>("q24", 'a', "q21"));
            m.AddTransition(new Transition <String>("q24", 'b', "q25"));

            m.AddTransition(new Transition <String>("q25", 'a', "q25"));
            m.AddTransition(new Transition <String>("q25", 'b', "q25"));

            m.DefineAsStartState("q1");

            m.DefineAsFinalState("q20");

            return(m);
        }