Print

Print


On Mar 22, 2012, at 9:24 AM, Danielle wrote:

> I would like to create my own gene that contains one integer and one boolean
> value for my genetic algorithm. I found an example of how to do this on page
> 99-102 in the owners manual and I implemented this. The only problem is that
> when I program the problem I cannot figure out how to call the two varaibles
> I put in my custome gene object. I can only get to the VectorGene individual
> by calling individual.genome[i] in a loop. I want to use these two variables
> to calculate the fitness of the individual but I don't know how to get to
> them in my problem class.

Daniele, I'm not sure what you're referring to by "calling" a variable.  In the Problem class you have full access to your custom genotype.  For example, if your gene subclass is called MyGene, you can get the sixth such gene out of an individual like this:

GeneVectorIndividual gind = (GeneVectorIndividual) ind;
MyGene myGene = (MyGene)(gind.genome[5]);

Sean