public void GetGraphTest() { string testingWord = "01212"; string autonatonName = "testowyAutomat"; string[] alphabetLetters = new string[] { "0", "1", "2" }; string[][] states = new string[][] { new string[] { "1", "0", "0" }, new string[] { "1", "1", "2" }, new string[] { "2", "2", "3" }, new string[] { "3", "3", "3"} }; Automaton automaton = new Automaton(alphabetLetters, states); int finalState = automaton.GetFinalState(testingWord); Assert.AreEqual(3, finalState); File.Create(autonatonName).Close(); AdjacencyGraph<int, TaggedEdge<int, string>> graph; automaton.GetGraph(autonatonName, out graph); File.Delete(autonatonName); }
private void findResultButton_Click(object sender, EventArgs e) { if(wordsInTrainingSet.Value > defaultTrainingWordMaxLength) { wordsInTrainingSet.Value = defaultTrainingWordMaxLength; } trainingWordMaxLength = (int) wordsInTrainingSet.Value; if(wordsInTestSet.Value > defaultTestingWordMaxLength) { wordsInTestSet.Value = defaultTestingWordMaxLength; } if (wordsInTestSet.Value < defaultTestingWordMinLength) { wordsInTestSet.Value = defaultTestingWordMinLength; } testingWordMaxLength = (int) wordsInTestSet.Value; // Prepare word sets string[] trainingLetters = prepareAlphabet(trainingWordMaxLength); string[] testingLetters = prepareAlphabet(testingWordMaxLength); WordSetGenerator w = new WordSetGenerator(testingLetters, trainingLetters, defaultTestingWordMinLength); Console.WriteLine("Generating training words!"); // Generate training set w.GenerateTrainingWordsSet(new StringBuilder(), 0, trainingWordMaxLength); Console.WriteLine("Generating testing words!"); // Generate testing set w.GenerateTestingWordsSet(new StringBuilder(), 0, testingWordMaxLength, new bool[testingLetters.Length]); for(int i = 0; i< NoOfWords.Value; i++) { StringBuilder word = new StringBuilder(); StringBuilder word2 = new StringBuilder(); Random random = new Random(); int length = random.Next((int)wordsInTrainingSet.Value, (int)WordLenght.Value + 1); for(int j = 0; j < length; j++) { word.Append(alphabetLetters[random.Next() % alphabetLetters.Length]); word2.Append(alphabetLetters[random.Next() % alphabetLetters.Length]); } w.TrainingWords.Add(word.ToString()); w.TestingWords.Add(word2.ToString()); } Console.WriteLine("Go go go!"); TargetFunction targetFunction = new TargetFunction(automaton, w.TrainingWords, w.TestingWords); // Start algorithm and then remove unreached states PsoAlgorithm pso = new PsoAlgorithm((double)minErrLevel.Value, (int)maxIterationCount.Value, (int)minStateNumber.Value, (int)maxStateNumber.Value, alphabetLetters.Length, (int)ParticlesNumber.Value); System.Tuple<Automaton, double> result = pso.RunAlgorithm(); foundAutomaton = result.Item1; showOutputPictureButton.Enabled = true; string errorRate = result.Item2.ToString("N2"); //MessageBox.Show($"Best automaton found with error rate: {errorRate}", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); AdjacencyGraph<int, TaggedEdge<int, string>> g; foundAutomaton.GetGraph("OutputAutomaton" + automatoncounter, out g); GenerateFile(g, errorRate, automaton.States.Count); }