public static Individual RandomIndividual(FitnessEstimator fe, double density, EvolutionParams prms) { Individual res = null; do try { List<int> r = new List<int>(); for (int i = 0; i < fe.n; ++i) if (prms.rand.NextDouble() < density) r.Add(i); res = new Individual(r, fe, prms); } catch (CalculationException e) { } while (res == null); return res; }
public Population(FitnessEstimator fe, int population_size, double recombination_rate, double mut_rate_act, double mut_rate_deact, double start_density) { this.population_size = population_size; this.recombination_rate = recombination_rate; EvolutionParams prms = new EvolutionParams(mut_rate_act, mut_rate_deact); population = new SortedList<double, Individual>(); Individual temp; for (int i = 0; i < population_size; ++i) { temp = Individual.RandomIndividual(fe, start_density, prms); population.Add(temp.Fitness, temp); } }
public Individual(List<int> genes, FitnessEstimator fe, EvolutionParams prms) { this.fe = fe; this.prms = prms; this.fitness = fe.CalculateFitness(genes, out this.max, out this.genes, out this.too_many_genes); }