Create a new
EvolutionStream from the given
startpopulation and
evolution function. The main purpose of this
factory method is to simplify the creation of an
EvolutionStreamfrom an own evolution (GA) engine.
final Supplier> start = ...
A more complete example for would look like as:
public final class SpecialEngine // Create new evolution start object.
private static EvolutionStart
start(final int populationSize, final long generation)
final Population population =
Genotype.of(DoubleChromosome.of(0, 1)).instances()
.map(gt -> Phenotype.of(gt, generation, SpecialEngine::fitness))
.limit(populationSize)
.collect(Population.toPopulation());
return EvolutionStart.of(population, generation);
}
// The special evolution function.
private static EvolutionResult
evolve(final EvolutionStart start)
// Your special evolution implementation comes here!
return null;
}
public static void main(final String[] args)
final Genotype best = EvolutionStream
.of(() -> start(50, 0), SpecialEngine::evolve)
.limit(Limits.bySteadyFitness(10))
.limit(1000)
.collect(EvolutionResult.toBestGenotype());
System.out.println(String.format("Best Genotype: %s", best));
}
}
}