Exemple #1
0
        public void Evolve_SimpleSudokuPermutationsChromosome_Solved()
        {
            var sudoku = SudokuTestHelper.CreateBoard();

            IChromosome chromosome = new SudokuPermutationsChromosome(sudoku);
            var         fitness    = SudokuTestHelper.Eval(chromosome, sudoku, 1000, 0, 50);

            Assert.AreEqual(fitness, 0);
        }
Exemple #2
0
        public void Evolve_RandomPermutationsChromosome_EasySudoku_Solved()
        {
            var sudoku = SudokuTestHelper.CreateBoard(SudokuTestDifficulty.Easy);

            IChromosome chromosome = new SudokuPermutationsChromosome(sudoku);
            var         fitness    = SudokuTestHelper.Eval(chromosome, sudoku, 1000, 0, 40);

            Assert.AreEqual(0, fitness);
        }
        public void Evolve_SimpleSudokuCellsChromosome_NearlySolved()
        {
            var sudoku = SudokuTestHelper.CreateBoard();

            //the cells chromosome should solve the sudoku or nearly in less than 50 generations with 500 chromosomes
            var chromosome = new SudokuCellsChromosome(sudoku);
            var fitness    = SudokuTestHelper.Eval(chromosome, sudoku, 500, -20, 30);

            Assert.GreaterOrEqual(fitness, -20);
        }
        public void Evolve_CellsChromosome_VeryEasySudoku_Solved()
        {
            var sudoku = SudokuTestHelper.CreateBoard(SudokuTestDifficulty.VeryEasy);

            //the cells chromosome should solve the sudoku in less than 30 generations with 500 chromosomes
            var chromosome = new SudokuCellsChromosome(sudoku);
            var fitness    = SudokuTestHelper.Eval(chromosome, sudoku, 500, 0, 30);

            Assert.GreaterOrEqual(0, fitness);
        }
        public void Evolve_SimpleSudokuRandomPermutationsChromosome_Progressed()
        {
            var sudoku = SudokuTestHelper.CreateBoard();

            //the Random permutations chromosome should make significant progresses over 3 generations with 5 individuals

            var chromosome = new SudokuRandomPermutationsChromosome(sudoku, 2, 3);
            var fitness1   = new SudokuFitness(sudoku).Evaluate((ISudokuChromosome)chromosome);
            var fitness2   = SudokuTestHelper.Eval(chromosome, sudoku, 5, fitness1 + 20, 3);

            Assert.GreaterOrEqual(fitness2, fitness1 + 20);
        }