1 using System; 2 3 class GeneticAlgorithmParameters { 4 public GeneticAlgorithmParameters(uint populationSize, 5 float reproductionFraction, 6 float mutationFractionOfReproduction) { 7 populationSize_ = populationSize; 8 reproductionFraction_ = reproductionFraction; 9 mutationFractionOfReproduction_ = mutationFractionOfReproduction; 10 reproductionSize_ = (int)(reproductionFraction_ * populationSize_); 11 mutationSize_ = (int)(mutationFractionOfReproduction_ * reproductionSize_); 12 crossoverSize_ = reproductionSize_ - mutationSize_; 13 } 14 15 public override string ToString() { 16 return String.Format("Genetic Algorithm Parameters:" 17 + "\n\tPopulation size: {0:###,###,##0}" 18 + "\n\tReproduction percent: {1:0.#}" 19 + "\n\tMutation percent of reproduction: {2:0.#}" 20 + "\n\tMutation size: {3:###,###,###}" 21 + "\n\tCrossover size: {4:###,###,###}\n\n", 22 populationSize_, 100 * reproductionFraction_, 23 100 * mutationFractionOfReproduction_, mutationSize_, crossoverSize_); 24 } 25 26 public uint populationSize_; 27 private float reproductionFraction_; 28 private float mutationFractionOfReproduction_; 29 public int reproductionSize_; 30 public int mutationSize_; 31 public int crossoverSize_; 32 }