Java 使用Jenetics,只有一条染色体显示出良好的结果

Java 使用Jenetics,只有一条染色体显示出良好的结果,java,genetic-algorithm,jenetics,Java,Genetic Algorithm,Jenetics,我正在使用Jenetics库来解决遗传算法的一个问题。我正在扩展官方示例,以使用如下几种染色体: List<BitChromosome> arr = new ArrayList<>(); arr.add(BitChromosome.of(16, 0.5)); arr.add(BitChromosome.of(16, 0.5)); arr.add(BitChromosome.of(16, 0.5)); Factory<Genot

我正在使用
Jenetics
库来解决遗传算法的一个问题。我正在扩展官方示例,以使用如下几种染色体:

    List<BitChromosome> arr = new ArrayList<>();
    arr.add(BitChromosome.of(16, 0.5));
    arr.add(BitChromosome.of(16, 0.5));
    arr.add(BitChromosome.of(16, 0.5));
    Factory<Genotype<BitGene>> gtf = Genotype.of(arr);
其他部分保持不变:

    // 3.) Create the execution environment.
    Engine<BitGene, Integer> engine = Engine
            .builder(Test1::eval, gtf)
            .build();

    // 4.) Start the execution (evolution) and
    //     collect the result.
    Genotype<BitGene> result = engine.stream()
            .limit(100)
            .collect(EvolutionResult.toBestGenotype());

如您所见,只有第一个结果满足条件。如何扩展此示例,使所有染色体都能最大化求值函数?

这正是我在查看适应度函数后所期望的。您仅使用第一条染色体来计算适合度。方法返回第一条染色体。这是基因型的快捷方式。获取染色体(0)。在你的适应度函数中不考虑其他两条染色体

    // 3.) Create the execution environment.
    Engine<BitGene, Integer> engine = Engine
            .builder(Test1::eval, gtf)
            .build();

    // 4.) Start the execution (evolution) and
    //     collect the result.
    Genotype<BitGene> result = engine.stream()
            .limit(100)
            .collect(EvolutionResult.toBestGenotype());
[01110010|00010111,01000000|00000100,10011101|01110110]