/** * Create a new elite selector with elite count 1 and the selector for * selecting the rest of the population is initialized with * {@code TournamentSelector<>(3)} */ public EliteSelector() { this(1, new TournamentSelector<>(3)); }
@Override public ISeq<Phenotype<G, C>> select( final Seq<Phenotype<G, C>> population, final int count, final Optimize opt ) { requireNonNull(population, "Population"); requireNonNull(opt, "Optimization"); if (count < 0) { throw new IllegalArgumentException(format( "Selection count must be greater or equal then zero, but was %s", count )); } final Random random = RandomRegistry.getRandom(); return population.isEmpty() ? ISeq.empty() : MSeq.<Phenotype<G, C>>ofLength(count) .fill(() -> select(population, opt, _sampleSize, random)) .toISeq(); }
/** * Create a new elite selector with the desired number of elites to be * selected. The selector for selecting the rest of the population is * initialized with {@code TournamentSelector<>(3)}. * * @see TournamentSelector * * @param eliteCount the desired number of elite individual to be selected * @throws IllegalArgumentException if {@code eliteCount < 1} */ public EliteSelector(final int eliteCount) { this(eliteCount, new TournamentSelector<>(3)); }
@Override protected Factory<TournamentSelector<DoubleGene, Double>> factory() { return () -> new TournamentSelector<>(3); }
public static void main(final String[] args) throws IOException { final String base = "/home/fwilhelm/Workspace/Development/Projects/" + "Jenetics/jenetics.tool/src/main/resources/io/jenetics/tool/moea"; final Path data = Paths.get(base, "circle_max_front.dat"); final Path output = Paths.get(base, "circle_max_front.svg"); final Engine<DoubleGene, Vec<double[]>> engine = Engine.builder(PROBLEM) .alterers( new Mutator<>(0.1), new MeanAlterer<>()) .offspringSelector(new TournamentSelector<>(3)) .survivorsSelector(UFTournamentSelector.ofVec()) .build(); final ISeq<Phenotype<DoubleGene, Vec<double[]>>> front = engine.stream() .limit(Limits.byFixedGeneration(100)) .collect(MOEA.toParetoSet(IntRange.of(100, 150))); final StringBuilder out = new StringBuilder(); out.append("#x y\n"); front.forEach(p -> { out.append(p.getFitness().data()[0]); out.append(" "); out.append(p.getFitness().data()[1]); out.append("\n"); }); Files.write(data, out.toString().getBytes()); final Gnuplot gnuplot = new Gnuplot(Paths.get(base, "circle_points.gp")); gnuplot.create(data, output); }
public static void main(final String[] args) throws IOException { final String base = "/home/fwilhelm/Workspace/Development/Projects/" + "Jenetics/jenetics.tool/src/main/resources/io/jenetics/tool/moea"; final Path data = Paths.get(base, "circle_min_front.dat"); final Path output = Paths.get(base, "circle_min_front.svg"); final Engine<DoubleGene, Vec<double[]>> engine = Engine.builder(PROBLEM) .alterers( new Mutator<>(0.1), new MeanAlterer<>()) .offspringSelector(new TournamentSelector<>(3)) .survivorsSelector(UFTournamentSelector.ofVec()) .minimizing() .build(); final ISeq<Phenotype<DoubleGene, Vec<double[]>>> front = engine.stream() .limit(Limits.byFixedGeneration(100)) .collect(MOEA.toParetoSet(IntRange.of(100, 150))); final StringBuilder out = new StringBuilder(); out.append("#x y\n"); front.forEach(p -> { out.append(p.getFitness().data()[0]); out.append(" "); out.append(p.getFitness().data()[1]); out.append("\n"); }); Files.write(data, out.toString().getBytes()); final Gnuplot gnuplot = new Gnuplot(Paths.get(base, "circle_points.gp")); gnuplot.create(data, output); }
public static void main(final String[] args) { final Engine<CharacterGene, Integer> engine = Engine.builder(PROBLEM) .populationSize(500) .survivorsSelector(new StochasticUniversalSelector<>()) .offspringSelector(new TournamentSelector<>(5)) .alterers( new Mutator<>(0.1), new SinglePointCrossover<>(0.5)) .build(); final Phenotype<CharacterGene, Integer> result = engine.stream() .limit(100) .collect(toBestPhenotype()); System.out.println(result); }
@Test(dataProvider = "expectedDistribution", groups = {"statistics"}) public void selectDistribution( final Integer tournamentSize, final Named<double[]> expected, final Optimize opt ) { retry(3, () -> { final int loops = 1; final int npopulation = POPULATION_COUNT; using(new Random(), r -> { final Histogram<Double> distribution = SelectorTester.distribution( new TournamentSelector<>(tournamentSize), opt, npopulation, loops ); assertDistribution(distribution, expected.value, 0.001, 20); }); }); }
public static void main(final String[] args) { final Knapsack knapsack = Knapsack.of(15, new Random(123)); // Configure and build the evolution engine. final Engine<BitGene, Double> engine = Engine.builder(knapsack) .populationSize(500) .survivorsSelector(new TournamentSelector<>(5)) .offspringSelector(new RouletteWheelSelector<>()) .alterers( new Mutator<>(0.115), new SinglePointCrossover<>(0.16)) .build(); // Create evolution statistics consumer. final EvolutionStatistics<Double, ?> statistics = EvolutionStatistics.ofNumber(); final Phenotype<BitGene, Double> best = engine.stream() // Truncate the evolution stream after 7 "steady" // generations. .limit(bySteadyFitness(7)) // The evolution will stop after maximal 100 // generations. .limit(100) // Update the evaluation statistics after // each generation .peek(statistics) // Collect (reduce) the evolution stream to // its best phenotype. .collect(toBestPhenotype()); System.out.println(statistics); System.out.println(best); }
.builder(fitness(kssize), Codecs.ofSubSet(items)) .populationSize(500) .survivorsSelector(new TournamentSelector<>(5)) .offspringSelector(new RouletteWheelSelector<>()) .alterers(
.maximalPhenotypeAge(50) .survivorsSelector(new TruncationSelector<>()) .offspringSelector(new TournamentSelector<>(param.getTournamentSize())) .alterers( new MeanAlterer<>(0.175),
/** * Create a new {@link Engine} for solving the {@link Knapsack} problem. The * engine is used for testing purpose. * * @see Knapsack#of(int, Random) * * @param populationSize the population size of the created engine * @param random the random engine used for creating the {@link Knapsack} * problem instance * @return a new {@link Knapsack} solving evolution {@link Engine} */ public static Engine<BitGene, Double> knapsack( final int populationSize, final Random random ) { // Search space fo 2^250 ~ 10^75. final Knapsack knapsack = Knapsack.of(250, random); // Configure and build the evolution engine. return Engine.builder(knapsack) .populationSize(populationSize) .survivorsSelector(new TournamentSelector<>(5)) .offspringSelector(new RouletteWheelSelector<>()) .alterers( new Mutator<>(0.03), new SinglePointCrossover<>(0.125)) .build(); }
new Mutator<>(0.1), new MeanAlterer<>()) .offspringSelector(new TournamentSelector<>(2)) .survivorsSelector(UFTournamentSelector.ofVec()) .minimizing()
@Test public void variableDoubleSum() { final Problem<int[], IntegerGene, Integer> problem = Problem.of( array -> IntStream.of(array).sum(), Codec.of( Genotype.of(IntegerChromosome.of(0, 100, IntRange.of(10, 100))), gt -> gt.getChromosome().as(IntegerChromosome.class).toArray() ) ); final Engine<IntegerGene, Integer> engine = Engine.builder(problem) .alterers( new Mutator<>(), new SwapMutator<>()) .selector(new TournamentSelector<>()) .minimizing() .build(); final int[] result = problem.codec().decode( engine.stream() .limit(100) .collect(EvolutionResult.toBestGenotype()) ); Assert.assertTrue(result.length < 50, "result length: " + result.length); //System.out.println(result.length); //System.out.println(Arrays.toString(result)); }