virtual public void ResetSimulation() { population = new ArrayList(this.populationSize); while (this.population.Count < this.populationSize) { Chromosome <Gene> chromosome = new Chromosome <Gene>(this.defaultChromosomeLength); chromosome.computeFitness(this.fitnessComputer); this.population.Add(chromosome); } populateStatistics(); }
virtual public void RunSimulation() { ArrayList newPopulation = new ArrayList(populationSize); Chromosome <Gene> newChromosome = null; while (newPopulation.Count < this.populationSize) { try { newChromosome = this.selectMaleChromosome().Recombine(this.selectFemaleChromosome(), this.recombinator); for (int i = 0; i < newChromosome.GeneCount; i++) { if (this.randomizer.NextDouble() < this.geneMutationRate) { newChromosome[i].Mutate(); } if (this.randomizer.NextDouble() < this.geneDuplicationRate) { newChromosome.DuplicateGene(i); } if (newChromosome.GeneCount > 1 && this.randomizer.NextDouble() < this.geneDropRate) { newChromosome.DropGene(i); } } newChromosome.computeFitness(this.fitnessComputer); newPopulation.Add(newChromosome); } catch (GenesIncompatibleException ignore) { } } this.population = newPopulation; this.populateStatistics(); if (SimulationTurn != null) { SimulationTurn(this, EventArgs.Empty); } }