Print

Print


Salem, it's probably not that ECJ's using the same individual, but  
rather that your gene's clone() operation has some problems.   
Specifically, clone() by default only does light cloning -- it clones  
instance variables that are numbers and booleans, but more complex  
instance variables (arrays for example) are not cloned but rather just  
pointer-copied.  You have several such arrays (FIELD, allele) in your  
gene and need to copy those arrays yourself in your clone() method.   
Secondly, these arrays appear to be static -- that is, they're shared  
among all instances of MatrixGene.  That's almost certainly what you  
do NOT want to do.  ECJ has almost no static non-final members in its  
entire library on purpose: it's troublesome to serialize them.  And it  
will also create this "same gene" affect.

Sean

On Mar 5, 2010, at 4:27 AM, Salem Adra wrote:

> Hi Everyone,
>
> I am very new to ECJ, and Java as a matter of fact.
>
> I am currently having a problem with my GA population using ECJ. The  
> problem
> is that although my algorithm seems to be creating several individuals
> (genotypes at least), it is populating the GA population with the same
> individual (last genotype generated by reset() method in  
> matrixgene.java
> attached). I spent loads of time trying to understand the problem (i  
> tried
> to trace the function executions including the cloning functions and
> printing all sort of testing statements) but unfortunately i am stuck.
> Anyone know what might be causing this or shed some light.
>
> My individuals are GeneVectorIndividuals and my gene representation is
> defined in the attached file. I basically followed the instructions on
> http://cvalcarcel.wordpress.com/tag/ecj/ which define a  
> CharVectorGene,
> except in my case, my individuals have only one gene, which is a  
> matrix.
>
> many thanks in advance,
>
> Salem