private void CalculateFitness() { _fitnessSum = 0; Dna <T> best = Population[0]; Population.ForEach(p => { _fitnessSum += p.CalculateFitness(Population.IndexOf(p)); best = best.Fitness < p.Fitness ? p : best; }); BestFitness = best.Fitness; best.Genes.CopyTo(BestGenes, 0); }
public Chromosome <GeneType> GetBestChromosome() { if (Population == null || Population.Count == 0) { throw new Exception("The genetic algorithm hass not been executed"); } Chromosome <GeneType> ValueReturn = null; double Evaluation = double.MinValue; Population.ForEach(x => { x.Individuals.ForEach(y => { if (y.Fitness > Evaluation) { Evaluation = y.Fitness; ValueReturn = y; } }); }); return(ValueReturn); }