如何使用Java中的jenetics.io库增加遗传算法的种群规模?

时间:2018-03-26 17:27:09

标签: java genetic-algorithm

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.

1 个答案:

答案 0 :(得分:0)

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

final Engine<IntegerGene, Integer> engine = Engine.builder(Main::eval, gtf)
    .populationSize(150)
    .build();