Пример #1
0
 public void GetTestSetCountTest()
 {
     Position particlePosition = new Position(3, 4, 89) { OnePositions = new[,] { { 0, 1, 2, 3 }, { 2, 1, 0, 2 }, { 1, 1, 3, 3 } } };
     List<string> wordsSet = new List<string>();
     wordsSet.Add("012");
     TargetFunction f = new TargetFunction(new Automaton(particlePosition), wordsSet, wordsSet);
     Assert.AreEqual(TargetFunction.GetTestSetCount(), 1);
 }
Пример #2
0
 public void MoveParticleTest()
 {
     Position bestPosition = new Position(3, 4, 23) { OnePositions = new[,] { { 1, 1, 3, 1 }, { 2, 1, 3, 2 }, { 2, 1, 2, 2 } } };
     List<string> wordsSet = new List<string>();
     wordsSet.Add("012");
     TargetFunction f = new TargetFunction(new Automaton(bestPosition), wordsSet, wordsSet);
     Particle firstParticle = new Particle(3, 4) { Position = bestPosition };
     firstParticle.MoveParticle(bestPosition, 2, 2);
     Assert.AreEqual(firstParticle.Position.CompareTo(bestPosition), 0);
 }
Пример #3
0
 public void GetFunctionValueTest2()
 {
     Position automatonPosition = new Position(3, 4, 89) { OnePositions = new[,] { { 0, 1, 2, 3 }, { 2, 1, 0, 2 }, { 1, 1, 3, 3 } } };
     Position particlePosition = new Position(3, 4, 89) { OnePositions = new[,] { { 1, 1, 2, 2 }, { 1, 0, 0, 0 }, { 3, 2, 0, 0 } } };
     List<string> wordsSet = new List<string>();
     wordsSet.Add("012");
     wordsSet.Add("0");
     wordsSet.Add("1");
     wordsSet.Add("2");
     TargetFunction f = new TargetFunction(new Automaton(automatonPosition), wordsSet, wordsSet);
     Assert.AreEqual(TargetFunction.GetFunctionValue(particlePosition), 3);
 }
Пример #4
0
        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);
        }
Пример #5
0
 public void IsInitializedTest()
 {
     Position automatonPosition = new Position(3, 4, 89) { OnePositions = new[,] { { 0, 1, 2, 3 }, { 2, 1, 0, 2 }, { 1, 1, 3, 3 } } };
     TargetFunction f = new TargetFunction(new Automaton(automatonPosition), new List<string>(), new List<string>());
     Assert.AreEqual(TargetFunction.IsInitialized(), true);
 }