public override void Select(Population population, SelectionBuffer selection, GeneticAlgorithm.NextStepDelegate callback) { int size = 0; // TODO: Implement settings for how to truncate. float cutoff = 0; switch (truncationMode) { case TruncationMode.AboveMiddle: cutoff = population.MinFitness + (population.MaxFitness - population.MinFitness)/2; break; case TruncationMode.AboveMean: cutoff = population.MeanFitness; break; case TruncationMode.AboveMedian: cutoff = population.MedianFitness; break; } for (int i = 0; i < population.Size; i++) { if (population[i].Fitness > cutoff) { selection[size].CloneFrom(population[i].Genome); size++; } } selection.Size = size; callback(); }
public override void Select(Population population, SelectionBuffer selection, GeneticAlgorithm.NextStepDelegate callback) { int size = 0; // TODO: Implement settings for how to truncate. float cutoff = 0; switch (truncationMode) { case TruncationMode.AboveMiddle: cutoff = population.MinFitness + (population.MaxFitness - population.MinFitness) / 2; break; case TruncationMode.AboveMean: cutoff = population.MeanFitness; break; case TruncationMode.AboveMedian: cutoff = population.MedianFitness; break; } for (int i = 0; i < population.Size; i++) { if (population[i].Fitness > cutoff) { selection[size].CloneFrom(population[i].Genome); size++; } } selection.Size = size; callback(); }
public override void Mate(SelectionBuffer selected, Population newPopulation, GeneticAlgorithm.NextStepDelegate callback) { // The new population is populated with 2 children each iteration. for (int i = 0; i < newPopulation.Size; i+=2) { BaseGenome mom = selected[Random.Range(0, selected.Size)]; // TODO: mom and dad can be the same.. BaseGenome dad = selected[Random.Range(0, selected.Size)]; int point = Random.Range(0, mom.Length); newPopulation[i].Genome.OnePointCrossover(mom, dad, point); newPopulation[i+1].Genome.OnePointCrossover(mom, dad, point); } callback(); }
public override void Mate(SelectionBuffer selected, Population newPopulation, GeneticAlgorithm.NextStepDelegate callback) { // The new population is populated with 2 children each iteration. for (int i = 0; i < newPopulation.Size; i += 2) { BaseGenome mom = selected[Random.Range(0, selected.Size)]; // TODO: mom and dad can be the same.. BaseGenome dad = selected[Random.Range(0, selected.Size)]; int point = Random.Range(0, mom.Length); newPopulation[i].Genome.OnePointCrossover(mom, dad, point); newPopulation[i + 1].Genome.OnePointCrossover(mom, dad, point); } callback(); }
public override void Select(Population population, SelectionBuffer selection, GeneticAlgorithm.NextStepDelegate callback) { int size = 0; DebugAux.Assert(population.MaxFitness != 0, "[RouletteWheelSA] Can't have a MaxFitness of zero!"); // The algorithm states that we should pick one at random for consideration with probability 1/N. int nrConsiderations = Mathf.RoundToInt(population.Size * Settings.SelectionProportion); for (int i = 0; i < nrConsiderations; i++) { int index = Random.Range(0, population.Size); float probability = population[index].Fitness / population.MaxFitness; if (Random.value <= probability) { selection[size].CloneFrom(population[index].Genome); size++; } } selection.Size = size; callback(); }
public override void Select(Population population, SelectionBuffer selection, GeneticAlgorithm.NextStepDelegate callback) { int size = 0; DebugAux.Assert(population.MaxFitness != 0, "[RouletteWheelSA] Can't have a MaxFitness of zero!"); // The algorithm states that we should pick one at random for consideration with probability 1/N. int nrConsiderations = Mathf.RoundToInt(population.Size * Settings.SelectionProportion); for (int i = 0; i < nrConsiderations; i++) { int index = Random.Range(0, population.Size); float probability = population[index].Fitness / population.MaxFitness; if (Random.value <= probability) { selection[size].CloneFrom(population[index].Genome); size++; } } selection.Size = size; callback(); }
// Adaptive GAs // In CAGA (clustering-based adaptive genetic algorithm) void Start() { settings = GetComponent <GASettings>(); populationSize = settings.PopulationSize; nrGenerations = settings.NumberOfGenerations; blocking = settings.RunAsFastAsPossible; environment.Settings = settings; selectionStrategy.Settings = settings; matingStrategy.Settings = settings; mutationStrategy.Settings = settings; population = new Population(populationSize); selectionBuffer = new SelectionBuffer(populationSize); statistics = GetComponent <Statistics>(); if (statistics == null) { statistics = gameObject.AddComponent <Statistics>(); } statistics.Population = population; BasePhenome phenomeTemplate = Helper.InstansiateAndGet <BasePhenome>(phenomePrefab); BaseGenome genomeTemplate = phenomeTemplate.Genome; for (int i = 0; i < populationSize; i++) { BaseGenome genome = genomeTemplate.CreateRandom(); // Should be possible to generate these by hand (seeded) population[i] = new PhenomeDescription(genome); } for (int i = 0; i < populationSize; i++) { BaseGenome genome = genomeTemplate.CreateRandom(); // Should be possible to generate these by hand (seeded) selectionBuffer[i] = genome; } nextStepDelegate = NextStep; currentState = State.FitnessTest; }
// Should produce two children! public abstract void Mate(SelectionBuffer selected, Population newPopulation, GeneticAlgorithm.NextStepDelegate callback);
// rate only a random sample of the population, as the former process may be very time-consuming. public abstract void Select(Population population, SelectionBuffer selected, GeneticAlgorithm.NextStepDelegate callback);
// Adaptive GAs // In CAGA (clustering-based adaptive genetic algorithm) void Start() { settings = GetComponent<GASettings>(); populationSize = settings.PopulationSize; nrGenerations = settings.NumberOfGenerations; blocking = settings.RunAsFastAsPossible; environment.Settings = settings; selectionStrategy.Settings = settings; matingStrategy.Settings = settings; mutationStrategy.Settings = settings; population = new Population(populationSize); selectionBuffer = new SelectionBuffer(populationSize); statistics = GetComponent<Statistics>(); if (statistics == null) statistics = gameObject.AddComponent<Statistics>(); statistics.Population = population; BasePhenome phenomeTemplate = Helper.InstansiateAndGet<BasePhenome>(phenomePrefab); BaseGenome genomeTemplate = phenomeTemplate.Genome; for (int i = 0; i < populationSize; i++) { BaseGenome genome = genomeTemplate.CreateRandom(); // Should be possible to generate these by hand (seeded) population[i] = new PhenomeDescription(genome); } for (int i = 0; i < populationSize; i++) { BaseGenome genome = genomeTemplate.CreateRandom(); // Should be possible to generate these by hand (seeded) selectionBuffer[i] = genome; } nextStepDelegate = NextStep; currentState = State.FitnessTest; }
// Should produce two children! public abstract void Mate(SelectionBuffer selected, Population newPopulation, GeneticAlgorithm.NextStepDelegate callback);
// rate only a random sample of the population, as the former process may be very time-consuming. public abstract void Select(Population population, SelectionBuffer selected, GeneticAlgorithm.NextStepDelegate callback);