-1

根据我的问题的性质,出于性能原因,我想同时计算人口中所有个人的健康状况。在jenetics中是否有这样做的好方法?

谢谢

4

1 回答 1

1

您可以使用Evaluator界面代替经典的适应度函数。

final var gtf = Genotype.of(DoubleChromosome.of(0, 1));

// Use 'Evaluator' instead of classical fitness function.
final Evaluator<DoubleGene, Double> evaluator = population -> {
    final MSeq<Phenotype<DoubleGene, Double>> result = MSeq.ofLength(population.length());
    for (int i = 0; i < result.length(); ++i) {
        final var pt = population.get(i);
        if (pt.nonEvaluated()) {
            // Do your fitness calculation.
            result.set(i, pt.withFitness(0.1));
        } else {
            result.set(i, pt);
        }
    }
    return result.toISeq();
};

final Engine<DoubleGene, Double> engine = new Engine.Builder<>(evaluator, gtf)
    .build();
于 2021-01-25T14:52:21.827 回答