/// <summary> /// Minimize a dfa by using Brozozowski's algorithm /// </summary> /// <param name="dfaToMinimize">The dfa to minimize.</param> /// <returns>The minimal dfa.</returns> public Automata <T> MinimizeUsingBrzozowski(Automata <T> dfaToMinimize) { Automata <T> reversedDfa = mutator.ReverseDfa(dfaToMinimize); Automata <T> remappedDfa = RemapStates(reversedDfa); Automata <T> firstPassDfa = transformer.TransformNdfaIntoDfa(remappedDfa); Automata <T> reversedFirstPass = mutator.ReverseDfa(firstPassDfa); Automata <T> remappedPass = RemapStates(reversedFirstPass); Automata <T> minimalDfa = transformer.TransformNdfaIntoDfa(remappedPass); return(minimalDfa); }
private static void TestMutationAndMinimalization() { Automata <string> L1 = TestAutomata.dfaMutationTestL1(); Automata <string> L4 = TestAutomata.dfaMutationTestL4(); Console.WriteLine("L1 is dfa? " + L1.IsDfa()); Console.WriteLine("-----------------------------------------"); L1.PrintTransitions(); Console.WriteLine("-----------------------------------------"); foreach (string state in L1.StartStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); foreach (string state in L1.FinalStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); Console.WriteLine("L4 is dfa? " + L4.IsDfa()); Console.WriteLine("-----------------------------------------"); L4.PrintTransitions(); Console.WriteLine("-----------------------------------------"); foreach (string state in L4.StartStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); foreach (string state in L4.FinalStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); //Not L1 DfaMutation <string> dfaMutator = new DfaMutation <string>(); Automata <string> notL1 = dfaMutator.NotDfa(L1); foreach (string state in notL1.StartStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); foreach (string state in notL1.FinalStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); //Reverted L4 Automata <string> revertedL4 = dfaMutator.ReverseDfa(L4); Console.WriteLine("revertedL4 is dfa? " + revertedL4.IsDfa()); Console.WriteLine("-----------------------------------------"); revertedL4.PrintTransitions(); Console.WriteLine("-----------------------------------------"); foreach (string state in revertedL4.StartStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); foreach (string state in revertedL4.FinalStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); Automata <string> L1AndL4 = dfaMutator.CombineAutomataAnd(L1, L4); Console.WriteLine("L1AndL4 is dfa? " + L1AndL4.IsDfa()); Console.WriteLine("-----------------------------------------"); L1AndL4.PrintTransitions(); Console.WriteLine("-----------------------------------------"); foreach (string state in L1AndL4.StartStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); foreach (string state in L1AndL4.FinalStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); Automata <string> L1OrL4 = dfaMutator.CombinaAutomataOr(L1, L4); Console.WriteLine("L1OrL4 is dfa? " + L1OrL4.IsDfa()); Console.WriteLine("-----------------------------------------"); L1OrL4.PrintTransitions(); Console.WriteLine("-----------------------------------------"); foreach (string state in L1OrL4.StartStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); foreach (string state in L1OrL4.FinalStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); Minimizer <string> minimizer = new Minimizer <string>(); Automata <string> L1AndL4Minimal = minimizer.MinimizeUsingBrzozowski(L1AndL4); Console.WriteLine("L1AndL4Minimal is dfa? " + L1AndL4Minimal.IsDfa()); Console.WriteLine("-----------------------------------------"); L1AndL4Minimal.PrintTransitions(); Console.WriteLine("-----------------------------------------"); foreach (string state in L1AndL4Minimal.StartStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); foreach (string state in L1AndL4Minimal.FinalStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); }