Hello, I'm trying to implement the following genetic algorithm usign JGAP.
I downloaded the 3.2 version and I have created a class to assign the fittness values according to the algorithm. Attached is the code that I'm using to initialize the structures. When running it, I'm
getting the following error:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 2
at java.util.Vector.get(Vector.java:694)
at org.jgap.Population.getChromosome(Population.java:257)
at org.jgap.impl.GABreeder.evolve(GABreeder.java:87)
at org.jgap.Genotype.evolve(Genotype.java:224)
at cna.example.selection.program.WSSelectionAlgorithm.findBestSelectionGenetic(WSSelectionAlgorithm.java:105)
at cna.example.selection.program.WSSelectionAlgorithm.main(WSSelectionAlgorithm.java:289)
Executing the some unit tests also I get the same error. I've downgraded to 3.1 and it seems to work now.
Main class
Logged In: YES
user_id=722855
Originator: NO
Hmmm, I'll check that. Sorry for the later answer, had been on a busines trip.
After running the unit tests, none failed on my machine. Could you tell me which one you mean? Possibly the code changed since you downloaded JGAP 3.2, and the CVS version is correct.
Logged In: YES
user_id=722855
Originator: NO
OK, I think you mean the Fibonacci example. When running it I get the error you described.
Fix: Either check out from CVS or change class GABreeder in method evolve(Population, Configuration) as follows:
---
OLD:
// Increase age of all chromosomes which are not modified by genetic
// operations.
// -----------------------------------------------------------------
for (int i = 0; i < originalSize; i++) {
--
NEW:
// Increase age of all chromosomes which are not modified by genetic
// operations.
// -----------------------------------------------------------------
int size = Math.min(originalPopSize, currentPopSize);
for (int i = 0; i < size; i++) {
---
HTH
Klaus
Logged In: YES
user_id=722855
Originator: NO
I'm setting this to fixed as I believe it is. A new unit test testEvolve_10 in class GenotypeTest exposes the bug.
The next release 3.2.1 to appear soon contains the fix of course.