javajgap

JGAP IntegerGene returning null on calling getAllele() method


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();

Solution

  • 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