예제 #1
0
        private void PerformMutation(IRandomizer randomizer)
        {
            var x        = new ChromosomeSelector(_currentGeneration);
            var parent1  = x.Get(randomizer);
            var strategy = MutationFactory.GetMutationStrategy(randomizer);
            var mutant   = strategy.Mutate(parent1);

            CheckAndAddValidChild(mutant, false, true);
        }
예제 #2
0
        private void PerformReproduction(IRandomizer randomizer)
        {
            var x       = new ChromosomeSelector(_currentGeneration);
            var parent1 = x.Get(randomizer);

            _nextGeneration.Add(parent1);
            if (MovelistCreated != null)
            {
                var args = new MovelistCreatedEventArgs {
                    CreatedThroughMutation     = false,
                    CreatedThroughCrossover    = false,
                    CreatedThroughReproduction = true,
                    //NameSolution = parent1.Name,
                    Score = parent1.Score,
                    Moves = parent1.ToString()
                };
                MovelistCreated(args);
            }
        }
예제 #3
0
        private void PerformCrossover(IRandomizer randomizer)
        {
            var x       = new ChromosomeSelector(_currentGeneration);
            var parent1 = x.Get(randomizer);
            var parent2 = x.Get(randomizer);

            MoveList child1;
            MoveList child2;

            if (parent1.CompareTo(parent2) == 0)
            {
                child1 = Perform2ROG(randomizer);
                child2 = Perform2ROG(randomizer);
                _currentGeneration.Add(child1);
                _currentGeneration.Add(child2);
            }
            else
            {
                if (CrossoverSelected != null)
                {
                    var coEventArgs = new CrossoverEventArgs {
                        MovesParent1 = parent1.ToString(),
                        MovesParent2 = parent2.ToString()
                    };
                    CrossoverSelected(coEventArgs);
                }

                //Get crossover strategy
                var strategy = CrossoverFactory.GetCrossoverStrategy(randomizer);

                //Do crossover
                var children = strategy.DoCrossover(parent1, parent2);

                child1 = children.Item1;
                child2 = children.Item2;

                CheckAndAddValidChild(child1, true, false);
                CheckAndAddValidChild(child2, true, false);
            }
        }