繁体   English   中英

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

[英]How to increase the population size of genetic algorithm using jenetics.io library in Java?

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。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM