Esempio n. 1
0
        public override IChromosome CreateNew()

        {
            var toReturn = new SudokuPermutationsChromosome(TargetSudoku);

            return(toReturn);
        }
Esempio n. 2
0
        public Sudoku ResoudreSudoku(Sudoku s)
        {
            var populationSize = 100000;

            var sudokuChromosome = new SudokuPermutationsChromosome(s);


            var fitness = new SudokuFitness(s);

            var selection = new EliteSelection();

            var crossover = new UniformCrossover();

            var mutation = new UniformMutation();



            var population = new Population(populationSize, populationSize, sudokuChromosome);

            var ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation)

            {
                Termination = new OrTermination(new ITermination[]

                {
                    new FitnessThresholdTermination(0),

                    new GenerationNumberTermination(80)
                })
            };



            ga.Start();



            var bestIndividual = (ISudokuChromosome)(ga.Population.BestChromosome);

            var solutions = bestIndividual.GetSudokus();

            return(solutions[0]);
        }