Skip to content

Commit

Permalink
Removed computation of population statistics while constant rate is used
Browse files Browse the repository at this point in the history
for crossover and mutation.
  • Loading branch information
avbasak1 committed Feb 10, 2022
1 parent 3af8602 commit 6f1ee0a
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -20,9 +20,11 @@
import org.apache.commons.math4.ga.chromosome.Chromosome;
import org.apache.commons.math4.ga.chromosome.ChromosomePair;
import org.apache.commons.math4.ga.crossover.CrossoverPolicy;
import org.apache.commons.math4.ga.crossover.rategenerator.ConstantCrossoverRateGenerator;
import org.apache.commons.math4.ga.crossover.rategenerator.CrossoverRateGenerator;
import org.apache.commons.math4.ga.internal.stats.PopulationStatisticalSummaryImpl;
import org.apache.commons.math4.ga.mutation.MutationPolicy;
import org.apache.commons.math4.ga.mutation.rategenerator.ConstantMutationRateGenerator;
import org.apache.commons.math4.ga.mutation.rategenerator.MutationRateGenerator;
import org.apache.commons.math4.ga.population.Population;
import org.apache.commons.math4.ga.selection.SelectionPolicy;
Expand Down Expand Up @@ -94,7 +96,8 @@ protected Population<P> nextGeneration(Population<P> current) {
LOGGER.debug("Reproducing next generation.");

// compute statistics of current generation chromosomes.
PopulationStatisticalSummary<P> populationStats = new PopulationStatisticalSummaryImpl<>(current);
PopulationStatisticalSummary<P> populationStats = ConstantCrossoverRateGenerator.class.isAssignableFrom(
this.crossoverRateGenerator.getClass()) ? null : new PopulationStatisticalSummaryImpl<>(current);

// Initialize the next generation with elit chromosomes from previous
// generation.
Expand Down Expand Up @@ -132,7 +135,9 @@ protected Population<P> nextGeneration(Population<P> current) {
LOGGER.debug("Performing adaptive mutation of offsprings.");

// recompute the statistics of the offspring population.
populationStats = new PopulationStatisticalSummaryImpl<>(offspringPopulation);
populationStats = ConstantMutationRateGenerator.class.isAssignableFrom(this.mutationRateGenerator.getClass()) ?
null :
new PopulationStatisticalSummaryImpl<>(offspringPopulation);

// apply mutation policy to the offspring chromosomes and add the mutated
// chromosomes to next generation.
Expand Down

0 comments on commit 6f1ee0a

Please sign in to comment.