MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().getBestPhenotype() : null );
MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().getBestPhenotype() != null ? decoder.apply(mm.getMax().getBestPhenotype().getGenotype()) : null : null
MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().getBestPhenotype() != null ? mm.getMax().getBestPhenotype().getGenotype() : null : null
public static void main(final String[] args) { final ISeq<Genotype<DoubleGene>> population = RandomRegistry.with(new Random(123), r -> CODEC.encoding().instances() .limit(10) .collect(ISeq.toISeq()) ); final Engine<DoubleGene, Double> engine = Engine.builder(Function.identity(), CODEC) .executor(Runnable::run) .build(); final EvolutionResult<DoubleGene, Double> result = RandomRegistry.with(new Random(456), r -> engine.stream(population) .limit(100) .collect(EvolutionResult.toBestEvolutionResult()) ); System.out.println(result.getBestPhenotype()); }
private void onNewResult( final EvolutionResult<PolygonGene, Double> current, final EvolutionResult<PolygonGene, Double> best ) { invokeLater(() -> { final Genotype<PolygonGene> gt = best .getBestPhenotype() .getGenotype(); bestEvolutionResultPanel.update(best); currentevolutionResultPanel.update(current); _polygonPanel.setChromosome((PolygonChromosome)gt.getChromosome()); _polygonPanel.repaint(); }); }
); final Phenotype<PolygonGene, Double> pt = best.getBestPhenotype(); if (latest.get() == null || latest.get().compareTo(pt) < 0) { log(
public static void main(final String[] args) { final Factory<Genotype<DoubleGene>> gtf = Genotype.of(DoubleChromosome.of(0, 1)); final Engine<DoubleGene, Double> engine = Engine .builder(/*Dummy fitness function*/gt -> Double.NaN, gtf) .evaluator(new RxEvaluator<>(RxEvaluator::fitness)) .build(); final EvolutionResult<DoubleGene, Double> result = engine.stream() .limit(100) .collect(EvolutionResult.toBestEvolutionResult()); System.out.println(result.getBestPhenotype()); }
public static void main(final String[] args) { final Factory<Genotype<DoubleGene>> gtf = Genotype.of(DoubleChromosome.of(0, 1)); final Engine<DoubleGene, Double> engine = Engine .builder(/*Dummy fitness function*/gt -> Double.NaN, gtf) .evaluator(new FutureEvaluator<>(FutureEvaluator::fitness)) .build(); final EvolutionResult<DoubleGene, Double> result = engine.stream() .limit(100) .collect(EvolutionResult.toBestEvolutionResult()); System.out.println(result.getBestPhenotype()); }
public static void main(final String[] args) { RandomRegistry.setRandom(new Random()); final Engine<EnumGene<Integer>, Integer> engine = Engine .builder( Sorting::length, PermutationChromosome.ofInteger(20)) .optimize(Optimize.MINIMUM) .populationSize(1000) //.survivorsSelector(new RouletteWheelSelector<>()) //.offspringSelector(new TruncationSelector<>()) .offspringFraction(0.9) .alterers( new SwapMutator<>(0.01), new PartiallyMatchedCrossover<>(0.3)) .build(); final EvolutionStatistics<Integer, DoubleMomentStatistics> statistics = EvolutionStatistics.ofNumber(); final EvolutionResult<EnumGene<Integer>, Integer> result = engine.stream() .limit(Limits.bySteadyFitness(100)) .limit(2500) .peek(statistics) .collect(EvolutionResult.toBestEvolutionResult()); System.out.println(statistics); System.out.println(result.getBestPhenotype()); }
public static void main(final String[] args) { final Knapsack knapsack = Knapsack.of(15, new Random(123)); // The base engine tries to approximate to good solution in current // environment. final Engine<BitGene, Double> baseEngine = Engine.builder(knapsack) .populationSize(500) .alterers( new Mutator<>(0.115), new SinglePointCrossover<>(0.16)) .build(); // The 'diversity' engine tries to broaden the search space again. final Engine<BitGene, Double> diversityEngine = baseEngine.builder() .alterers(new Mutator<>(0.5)) .build(); // Concatenates the two engines into one cyclic engine. final EvolutionStreamable<BitGene, Double> engine = CyclicEngine.of( // This engine stops the evolution after 10 non-improving // generations and hands over to the diversity engine. baseEngine.limit(() -> Limits.bySteadyFitness(10)), // The higher mutation rate of this engine broadens the search // space for 15 generations and hands over to the base engine. diversityEngine.limit(15) ); final EvolutionResult<BitGene, Double> best = engine.stream() // The evolution is stopped after 50 non-improving generations. .limit(bySteadyFitness(50)) .collect(toBestEvolutionResult()); System.out.println(best.getTotalGenerations()); System.out.println(best.getBestPhenotype()); }
public static void main(String[] args) throws Exception { final CharSeq chars = CharSeq.of("A-Z "); final Factory<Genotype<CharacterGene>> gtf = Genotype.of( CharacterChromosome.of(chars, TARGET.length()) ); final Engine<CharacterGene, Integer> engine = Engine .builder(WeaselProgram::score, gtf) .populationSize(150) .selector(new WeaselSelector<>()) .offspringFraction(1) .alterers(new WeaselMutator<>(0.05)) .build(); final Phenotype<CharacterGene, Integer> result = engine.stream() .limit(byFitnessThreshold(TARGET.length() - 1)) .peek(r -> System.out.println( r.getTotalGenerations() + ": " + r.getBestPhenotype())) .collect(toBestPhenotype()); System.out.println(result); }