I'm writing a genetic algorithm to solve a classification problem.
I'm setting up my configuration exactly how I've seen others do online, but using my own fitness function (required). I generate a random Genotype which holds my population and then evolve this population. However, sometimes I get an error 'Comparison method violates its general contract!'
I understand what this error means, but since it's being called on the framework method .evolve() I'm not sure what I can do...
Any thoughts/help? Thanks.
My Setup:
DefaultConfiguration.reset();
Configuration config = new DefaultConfiguration();
config.setPopulationSize(100);
// Setup fitness function
FitnessFunction fit = new HyperrectFitnessFunction(is);
config.setFitnessFunction(fit);
// Get bounds
double[][] bounds = getInstanceSetBounds(is);
// Setup chromosome
Chromosome sample = new Chromosome(config, createSampleGenes(config, attrCount, bounds));
config.setSampleChromosome(sample);
// Generate initial population
Genotype population = Genotype.randomInitialGenotype(config);
// Evolve
int i = 0;
IChromosome bestSolution = null;
for (i = 1; i < 100 + 1; i++) {
population.evolve();
bestSolution = population.getFittestChromosome();
double bestFitness = bestSolution.getFitnessValue();
if (bestFitness > 0.8)
break;
}