-1
I am trying to get started using the Jenetics JAVA library for genetic algorithms and there is something I don't understand from my GA limited background.
I need to change the default value of population size which is set to 50 into a different value using populationSize().

here is my code segment
 public static void main(String[] args)
    {
        initArrays();
        final Factory<Genotype<IntegerGene>> gtf = Genotype.of(IntegerChromosome.of(0, TRUCKS.length - 1, LEN), IntegerChromosome.of(0, LOCATIONS.length - 1, LEN), IntegerChromosome.of(0, TIMES.length - 1, LEN));
        final Engine<IntegerGene, Integer> engine = Engine.builder(Main::eval, gtf)
                .populationSize(int 150)
                .build();
        System.out.println("engine.getPopulationSize() = " + engine.getPopulationSize());
        final EvolutionResult<IntegerGene, Integer> result = engine.stream().limit(1000).collect(EvolutionResult.toBestEvolutionResult());
        Genotype<IntegerGene> genotype = result.getBestPhenotype().getGenotype();
        System.out.println("result = " + genotype);
        System.out.println("result.getBestPhenotype().getFitness() = " + result.getBestPhenotype().getFitness());
    }`enter code here`

populationSize() 是我得到错误的地方。我需要将默认值 50 更改为 150。

4

1 回答 1

0

据我所知,您必须从方法调用中删除int关键字:populationSize

final Engine<IntegerGene, Integer> engine = Engine.builder(Main::eval, gtf)
    .populationSize(150)
    .build();
于 2018-03-26T20:56:12.937 回答