Maleesha Perera
Maleesha Perera

Reputation: 38

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() is where I get the error.I need to change the default value of 50 to 150.

Upvotes: -1

Views: 218

Answers (1)

As far as I can see, you have to remove the int keyword from the populationSize method call:

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

Upvotes: 0

Related Questions