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 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); }
.optimize(Optimize.MAXIMUM) .maximalPhenotypeAge(50) .survivorsSelector(new TruncationSelector<>()) .offspringSelector(new TournamentSelector<>(param.getTournamentSize())) .alterers(
new MeanAlterer<>()) .offspringSelector(new TournamentSelector<>(2)) .survivorsSelector(UFTournamentSelector.ofVec()) .minimizing() .build();
.builder(fitness(kssize), Codecs.ofSubSet(items)) .populationSize(500) .survivorsSelector(new TournamentSelector<>(5)) .offspringSelector(new RouletteWheelSelector<>()) .alterers(
.builder(fitnessFunction, genotypeFactory) .offspringSelector(offspringSelector) .survivorsSelector(survivorsSelector) .alterers(alterer) .optimize(optimize)
/** * 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(); }
/** * Create a new builder, with the current configuration. * * @since 3.1 * * @return a new builder, with the current configuration */ @Override public Builder<G, C> copy() { return new Builder<G, C>(_genotypeFactory, _fitnessFunction) .alterers(_alterer) .clock(_clock) .executor(_executor) .evaluator(_evaluator) .fitnessScaler(_fitnessScaler) .maximalPhenotypeAge(_maximalPhenotypeAge) .offspringFraction(_offspringFraction) .offspringSelector(_offspringSelector) .phenotypeValidator(_validator) .optimize(_optimize) .populationSize(_populationSize) .survivorsSelector(_survivorsSelector) .individualCreationRetries(_individualCreationRetries) .mapping(_mapper); }
/** * Create a new evolution {@code Engine.Builder} initialized with the values * of the current evolution {@code Engine}. With this method, the evolution * engine can serve as a template for a new one. * * @return a new engine builder */ public Builder<G, C> builder() { return new Builder<G, C>(_genotypeFactory, _fitnessFunction) .alterers(_alterer) .clock(_clock) .evaluator(_evaluator) .executor(_executor.get()) .fitnessScaler(_fitnessScaler) .maximalPhenotypeAge(_maximalPhenotypeAge) .offspringFraction((double)_offspringCount/(double)getPopulationSize()) .offspringSelector(_offspringSelector) .optimize(_optimize) .phenotypeValidator(_validator) .populationSize(getPopulationSize()) .survivorsSelector(_survivorsSelector) .individualCreationRetries(_individualCreationRetries) .mapping(_mapper); }
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); }