79531896

Date: 2025-03-24 18:46:58
Score: 0.5
Natty:
Report link

One line in your fitness function looks suspicious.

private long fitness(Genotype<BitGene> genotype) {
    var bitChromosome = genotype.chromosome().as(BitChromosome.class);
    // Is this a field in your class? Should be a local variable.
    variables = bitChromosome.stream()
        .mapToInt(gene -> gene.bit() ? 1 : 0)
        .toArray();
    var objects = dataModel.getObjects();
    ...
}

If variable is defined outside your the fitness function, it will be shared between several threads during the evaluation. This will lead to an undefined behavior and might explain your results. The fitness function must thread safe and/or re-entrant.

private long fitness(Genotype<BitGene> genotype) {
    var bitChromosome = genotype.chromosome().as(BitChromosome.class);
    // Make it a local variable.
    var variables = bitChromosome.stream()
        .mapToInt(gene -> gene.bit() ? 1 : 0)
        .toArray();
    var objects = dataModel.getObjects();
    ...
}

Regards, Franz

Reasons:
  • Blacklisted phrase (1): Regards
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Franz Wilhelmstötter