[java] jenetics
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- import io.jenetics.BitChromosome;
- import io.jenetics.BitGene;
- import io.jenetics.Genotype;
- import io.jenetics.engine.Engine;
- import io.jenetics.engine.EvolutionResult;
- import io.jenetics.util.Factory;
- public class HelloWorld {
- // 2.) Definition of the fitness function.
- private static int eval(Genotype<BitGene> gt) {
- return gt.chromosome()
- .as(BitChromosome.class)
- .bitCount();
- }
- public static void main(String[] args) {
- // 1.) Define the genotype (factory) suitable
- // for the problem.
- Factory<Genotype<BitGene>> gtf =
- Genotype.of(BitChromosome.of(10, 0.5));
- // 3.) Create the execution environment.
- Engine<BitGene, Integer> engine = Engine
- .builder(HelloWorld::eval, gtf)
- .build();
- // 4.) Start the execution (evolution) and
- // collect the result.
- Genotype<BitGene> result = engine.stream()
- .limit(100)
- .collect(EvolutionResult.toBestGenotype());
- System.out.println("Hello World:\n" + result);
- }
- }
Editor
You can edit this paste and save as new:
File Description
- jenetics
- Paste Code
- 05 Jun-2023
- 1.11 Kb
You can Share it:
Latest Code Pastes