JGAP IntegerGene returning null on calling getAllele() method

215 views Asked by At

I am using JGAP library for my GA..

I am creating the chromosome like this

Gene[] genes[i] = new IntegerGene(conf,someInteger, someInteger);
Chromosome mChromosome = new Chromosome(conf, genes);
conf.setSampleChromosome(mChromosome);

But when I try to retrieve the Gene Values of the chromosome. I get null

Gene[] genes = chromosome.getGenes();
int value = (Integer)genes[someIndex].getAllele();
1

There are 1 answers

0
AudioBubble On BEST ANSWER

I found the solution

IntegerGene is created after evolving the population

If I tried to access the chromosome after the evolution like this

Gentype population = Genotype.randomInitialGenotype(conf);
population.evolove();
Ichromosome chromosome = population.getFittestChromosome();
Gene[] genes = chromosome.getGenes();
int value = (Integer)genes[someIndex].getAllele();

It will work