public static Automata <String> testReverse(Automata <String> automata) { AutomataConverter c = new AutomataConverter(); Automata <String> a = c.reverseAutomata(automata); return(a); }
public Automata <String> Minimization(Automata <String> Automaton) { AutomataConverter c = new AutomataConverter(); Automata <String> miniantwoord = c.NDFAToDFA(c.reverseAutomata(c.NDFAToDFA(c.reverseAutomata(Automaton)))); return(c.renameStates(miniantwoord)); }
static public void Minimalization() { Console.Clear(); Console.WriteLine("1. Minimalization DFA" + Environment.NewLine + "2. Minimalization Random DFA"); var ans = Console.ReadLine(); AutomataMinimalization m = new AutomataMinimalization(); AutomataConverter c = new AutomataConverter(); int choice = 0; if (int.TryParse(ans, out choice)) { switch (choice) { case 1: Console.Clear(); Automata <string> a = Tester.TestDFA2(); Console.WriteLine("De volgende DFA: "); a.printTransitions(); Tester.generateAutomataImage(a); Console.WriteLine("Is in Minimalisatie: (druk op een knop)"); Console.ReadLine(); Automata <String> mini = m.Minimization(a); mini.printTransitions(); Tester.generateAutomataImage(mini); ResetToMenu(); break; case 2: Console.Clear(); Automata <string> b = c.renameStates(Tester.generateRandomDfa()); Console.WriteLine("De volgende DFA: "); b.printTransitions(); Tester.generateAutomataImage(b); Console.WriteLine("Is in Minimalisatie: (druk op een knop)"); Console.ReadLine(); Automata <String> mini2 = m.Minimization(b); mini2.printTransitions(); Tester.generateAutomataImage(mini2); ResetToMenu(); break; default: Console.WriteLine("Deze optie is niet beschikbaar." + Environment.NewLine + "Druk op een knop om terug te gaan"); ResetToMenu(); break; } } else { Console.WriteLine("Vul alstublieft het nummer van de keuze in." + Environment.NewLine + "Druk op een knop om terug te gaan"); ResetToMenu(); } }
static public Automata <String> generateRandomDfa() { int num = 0; Automata <String> auto = new Automata <String>(); char[] alfabet = { 'a', 'b' }; RegularExpression b = Tester.generateRandomRegex(alfabet, 5); Console.WriteLine(b.ToString() + Environment.NewLine + "Geeft:"); b.regexToNDFA(ref num, ref auto); AutomataConverter c = new AutomataConverter(); Automata <String> auto2 = c.NDFAToDFA(auto); return(auto2); }
static public void BevatWoord() { Console.Clear(); Console.WriteLine("1. Bevat woord"); Automata <string> a = new Automata <string>(); AutomataConverter c = new AutomataConverter(); var ans = Console.ReadLine(); int choice = 0; if (int.TryParse(ans, out choice)) { switch (choice) { case 1: Console.Clear(); Console.WriteLine("De volgende NDFA/DFA is gegenereerd:"); a = c.renameStates(Tester.generateRandomNdfa()); // a.printTransitions(); Tester.generateAutomataImage(a); Console.WriteLine("Geef een string mee en kijk of hij word geaccepteerd. (BV: aaabaabaaa)"); var input = Console.ReadLine(); if (a.isStringAccepted(input)) { Console.WriteLine("De string word geaccepteerd."); } else { Console.WriteLine("De string word NIET geaccepteerd."); } ResetToMenu(); break; default: Console.WriteLine("Deze optie is niet beschikbaar." + Environment.NewLine + "Druk op een knop om terug te gaan"); ResetToMenu(); break; } } else { Console.WriteLine("Vul alstublieft het nummer van de keuze in." + Environment.NewLine + "Druk op een knop om terug te gaan"); ResetToMenu(); } }
static public void NdfaToDfa() { Console.Clear(); Console.WriteLine("1. NDFA -> DFA (zonder Epsilon)" + Environment.NewLine + "2. NDFA -> DFA (met Epsilon)" + Environment.NewLine + "3. NDFA -> DFA (Random NDFA)"); var ans = Console.ReadLine(); AutomataConverter c = new AutomataConverter(); int choice = 0; if (int.TryParse(ans, out choice)) { switch (choice) { case 1: Console.Clear(); Automata <string> a = Tester.TestNDFA(); Console.WriteLine("De volgende NDFA:"); a.printTransitions(); Tester.generateAutomataImage(a); Console.WriteLine("is deze DFA: (Druk op een knop)"); Console.ReadLine(); c.NDFAToDFA(a).printTransitions(); Tester.generateAutomataImage(c.NDFAToDFA(a)); ResetToMenu(); break; case 2: Console.Clear(); Automata <string> b = Tester.TestNDFA2(); Console.WriteLine("De volgende NDFA:"); b.printTransitions(); Tester.generateAutomataImage(b); Console.WriteLine("is deze DFA: (Druk op een knop)"); Console.ReadLine(); c.NDFAToDFA(b).printTransitions(); Tester.generateAutomataImage(c.NDFAToDFA(b)); ResetToMenu(); break; case 3: Console.Clear(); Automata <string> d = Tester.generateRandomNdfa(); Console.WriteLine("De volgende NDFA:"); d.printTransitions(); Tester.generateAutomataImage(d); Console.WriteLine("is deze DFA: (Druk op een knop)"); Console.ReadLine(); c.NDFAToDFA(d).printTransitions(); Tester.generateAutomataImage(c.NDFAToDFA(d)); ResetToMenu(); break; default: Console.WriteLine("Deze optie is niet beschikbaar." + Environment.NewLine + "Druk op een knop om terug te gaan"); ResetToMenu(); break; } } else { Console.WriteLine("Vul alstublieft het nummer van de keuze in." + Environment.NewLine + "Druk op een knop om terug te gaan"); ResetToMenu(); } }
public static Automata <String> testConverter(Automata <String> ndfa) { AutomataConverter c = new AutomataConverter(); return(c.NDFAToDFA(ndfa)); }
public void generateLaTeXExam() { String tentamenText = frontpageLatex(); // Folder creation String mainExamFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/TentamenGenerator/"; String currentExamFolder = ""; String imagesFolder = ""; String date = DateTime.Now.ToString("dd-MM-yyyy_hh:mm:ss"); if (Directory.Exists(mainExamFolder) == false) { System.IO.Directory.CreateDirectory(mainExamFolder); } if (Directory.Exists(mainExamFolder + "Tentamen_" + date + "/") == false) { Console.WriteLine("Created folder: " + "Tentamen_" + date); System.IO.Directory.CreateDirectory(mainExamFolder + date + "/"); currentExamFolder = mainExamFolder + date + "/"; } if (currentExamFolder == "") { return; } imagesFolder = currentExamFolder + "Images/"; System.IO.Directory.CreateDirectory(imagesFolder); AutomataConverter c = new AutomataConverter(); AutomataMinimalization m = new AutomataMinimalization(); // defining regexes char[] alfabet = { 'a', 'b' }; RegularExpression tentamenRegex_regexDFA = Tester.generateRandomRegex(alfabet, 2); RegularExpression tentamenRegex_regexNDFA = Tester.generateRandomRegex(alfabet, 2); RegularExpression tentamenRegex_DFAregex = Tester.generateRandomRegex(alfabet, 2); RegularExpression tentamenRegex_NDFAregex = Tester.generateRandomRegex(alfabet, 2); RegularExpression tentamenRegex_DFAToGrammar = Tester.generateRandomRegex(alfabet, 2); RegularExpression tentamenRegex_NDFAToGrammar = Tester.generateRandomRegex(alfabet, 2); // Generating exam images Tester.generateAutomataImage(Tester.TestNDFA2(), imagesFolder + "NDFA_FOR_NDFA_TO_DFA.pdf", "pdf"); Tester.generateAutomataImage(c.NDFAToDFA(Tester.TestNDFA2()), imagesFolder + "DFA_FOR_NDFA_TO_DFA.pdf", "pdf"); Tester.generateAutomataImage(c.renameStates(c.NDFAToDFA(tentamenRegex_regexDFA.regexToNDFA())), imagesFolder + "DFA_FOR_REGEX_TO_DFA.pdf", "pdf"); Tester.generateAutomataImage(c.renameStates(tentamenRegex_regexNDFA.regexToNDFA()), imagesFolder + "NDFA_FOR_REGEX_TO_NDFA.pdf", "pdf"); Tester.generateAutomataImage(c.renameStates(c.NDFAToDFA(tentamenRegex_DFAregex.regexToNDFA())), imagesFolder + "DFA_FOR_DFA_TO_REGEX.pdf", "pdf"); Tester.generateAutomataImage(c.renameStates(tentamenRegex_NDFAregex.regexToNDFA()), imagesFolder + "NDFA_FOR_NDFA_TO_REGEX.pdf", "pdf"); Tester.generateAutomataImage(Tester.TestDFA(), imagesFolder + "DFA_FOR_MINIMALISE_DFA.pdf", "pdf"); Tester.generateAutomataImage(m.Minimization(Tester.TestDFA()), imagesFolder + "MINIMALISED_DFA_FOR_MINIMALISE_DFA.pdf", "pdf"); Tester.generateAutomataImage(c.renameStates(c.NDFAToDFA(tentamenRegex_DFAToGrammar.regexToNDFA())), imagesFolder + "DFA_FOR_DFA_TO_GRAMMAR.pdf", "pdf"); Tester.generateAutomataImage(c.renameStates(tentamenRegex_NDFAToGrammar.regexToNDFA()), imagesFolder + "NDFA_FOR_NDFA_TO_GRAMMAR.pdf", "pdf"); // Add questions to exam string tentamenText += exerciseNDFAToDFA(); //NDFA to DFA tentamenText += exerciseRegexToDFA(tentamenRegex_regexDFA); //Regex to DFA tentamenText += exerciseRegexToNDFA(tentamenRegex_regexNDFA); //Regex to NDFA tentamenText += exerciseDFAToRegex(); //DFA to regex tentamenText += exerciseNDFAToRegex(); //NDFA to regex tentamenText += exerciseMinimaliseDFA(); //Minimalise DFA tentamenText += exerciseDFAToGrammar(); //DFA to grammar tentamenText += exerciseNDFAToGrammar(); //NDFA to grammar // Add answers to exam string tentamenText += answersIntro(); tentamenText += answerNDFAToDFA(); tentamenText += answerRegexToDFA(); tentamenText += answerRegexToNDFA(); tentamenText += answerDFAToRegex(tentamenRegex_DFAregex); tentamenText += answerNDFAToRegex(tentamenRegex_NDFAregex); tentamenText += answerMinimaliseDFA(); tentamenText += answerDFAToGrammar(c.renameStates(c.NDFAToDFA(tentamenRegex_DFAToGrammar.regexToNDFA()))); tentamenText += answerNDFAToGrammar(c.renameStates(c.NDFAToDFA(tentamenRegex_NDFAToGrammar.regexToNDFA()))); // End exam string tentamenText += endOfDocument(); // Writing exam to file System.IO.StreamWriter file = new System.IO.StreamWriter(currentExamFolder + "proeftentamen.tex"); file.WriteLine(tentamenText); file.Close(); buildAndOpenLaTeXPDF(currentExamFolder); }