public static Automata <String> GetExampleSlide14Lesson2() { char[] alphabet = { 'a', 'b' }; Automata <string> m = new Automata <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); }
public static Automata <string> GetExampleSlide8Lesson2() { char[] alphabet = { 'a', 'b' }; Automata <string> m = new Automata <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")); m.AddTransition(new Transition <string>("q4", 'a')); m.AddTransition(new Transition <string>("q4", 'b')); m.DefineAsStartState("q0"); m.DefineAsFinalState("q2"); m.DefineAsFinalState("q3"); return(m); }
public Automata <string> CreateAutomata() { char finalState = _lines.Last().First(); finalState++; string finalStateString = finalState.ToString(); Automata <string> m = new Automata <string>(); m.DefineAsStartState(_lines[0].First().ToString()); List <char> symbols = new List <char>(); foreach (string line in _lines) { string[] substrings = line.Split(' '); string fromState = substrings[0]; for (int i = 2; i < substrings.Length; i += 2) { string substring = substrings[i]; char symbol = substring.First(); if (symbol != '$' && !symbols.Contains(symbol)) { symbols.Add(symbol); } if (substring.Length > 1) { string toState = substring[1].ToString(); if (substring.Last() == '*') { m.DefineAsFinalState(toState); } m.AddTransition(new Transition <string>(fromState, symbol, toState)); } else { m.AddTransition(new Transition <string>(fromState, symbol, finalStateString)); if (!m.getEndStates.Contains(finalStateString)) { m.DefineAsFinalState(finalStateString); } } } } m.SetAlphabet(symbols.ToArray()); return(m); }
public static Automata <string> TestAutomata2() { char[] alphabet = { '0', '1' }; Automata <string> m = new Automata <string>(alphabet); m.AddTransition(new Transition <string>("q0", '0', "q0")); m.AddTransition(new Transition <string>("q0", '1', "q1")); m.AddTransition(new Transition <string>("q1", '0', "q0")); m.AddTransition(new Transition <string>("q1", '1', "q1")); m.DefineAsFinalState("q0"); m.DefineAsFinalState("q1"); m.DefineAsStartState("q0"); return(m); }
public static Automata <string> MinimalizationAutomata() { char[] alphabet = { 'a', 'b' }; Automata <string> m = new Automata <string>(alphabet); m.AddTransition(new Transition <string>("0", 'a', "0")); m.AddTransition(new Transition <string>("0", 'b', "1")); m.AddTransition(new Transition <string>("1", 'a', "2")); m.AddTransition(new Transition <string>("1", 'b', "1")); m.AddTransition(new Transition <string>("2", 'a', "0")); m.AddTransition(new Transition <string>("2", 'b', "3")); m.AddTransition(new Transition <string>("3", 'a', "4")); m.AddTransition(new Transition <string>("3", 'b', "1")); m.AddTransition(new Transition <string>("4", 'b', "3")); m.AddTransition(new Transition <string>("4", 'a', "5")); m.AddTransition(new Transition <string>("5", 'a', "0")); m.AddTransition(new Transition <string>("5", 'b', "3")); m.DefineAsStartState("0"); m.DefineAsFinalState("4"); m.DefineAsFinalState("2"); return(m); }
public Automata <string> ToAutomata() { char[] alphabet = { 'a', 'b' }; Automata <string> automata = new Automata <string>(alphabet); automata.DefineAsStartState("S"); automata.DefineAsFinalState("F"); var left = this.GetTransitions("S", "F"); foreach (var transition in left) { automata.AddTransition(transition); } Counter = 'A'; return(automata); }
public static Automata <string> NDfaToDfa2() { char[] alphabet = { '0', '1' }; Automata <string> m = new Automata <string>(alphabet); m.AddTransition(new Transition <string>("a", '0', "a")); m.AddTransition(new Transition <string>("a", '0', "d")); m.AddTransition(new Transition <string>("a", '1', "d")); m.AddTransition(new Transition <string>("a", '0', "e")); m.AddTransition(new Transition <string>("a", '1', "e")); m.AddTransition(new Transition <string>("d", '0', "e")); m.AddTransition(new Transition <string>("a", '0', "b")); m.AddTransition(new Transition <string>("a", '0', "c")); m.AddTransition(new Transition <string>("c", '1', "b")); m.AddTransition(new Transition <string>("b", '0', "c")); m.AddTransition(new Transition <string>("b", '1', "e")); m.DefineAsFinalState("e"); m.DefineAsStartState("a"); return(m); }
public static Automata <string> NdfaToDFa() { char[] alphabet = { 'a', 'b' }; Automata <string> m = new Automata <string>(alphabet); m.AddTransition(new Transition <string>("0", '$', "1")); m.AddTransition(new Transition <string>("0", '$', "7")); m.AddTransition(new Transition <string>("1", '$', "2")); m.AddTransition(new Transition <string>("1", '$', "4")); m.AddTransition(new Transition <string>("2", 'a', "3")); m.AddTransition(new Transition <string>("4", 'b', "5")); m.AddTransition(new Transition <string>("3", '$', "6")); m.AddTransition(new Transition <string>("5", '$', "6")); m.AddTransition(new Transition <string>("6", '$', "1")); m.AddTransition(new Transition <string>("6", '$', "7")); m.AddTransition(new Transition <string>("7", 'a', "8")); m.AddTransition(new Transition <string>("8", 'b', "9")); m.AddTransition(new Transition <string>("9", 'b', "10")); m.DefineAsStartState("0"); m.DefineAsFinalState("10"); return(m); }