// Create a random number generator
GenerateRandom rnd = new MersenneTwisterGenerateRandom();
// Create a new population.
Population pop = new BasicPopulation();
pop.setGenomeFactory(new IntegerArrayGenomeFactory(10));
// Create a trainer with a very simple score function. We do not care
// about the calculation of the score, as they will never be calculated.
EvolutionaryAlgorithm train = new BasicEA(pop, new ScoreFunction() {
@Override
public double calculateScore(MLMethod method) {
return 0;
}
@Override
public boolean shouldMinimize() {
return false;
}
});
// Create a splice (no repeat) operator, length = 5. Use it 1.0 (100%) of the time.
SpliceNoRepeat opp = new SpliceNoRepeat(5);
train.addOperation(1.0, opp);
// Create two parents, the genes are set to 1,2,3,4,5,7,8,9,10
// and 10,9,8,7,6,5,4,3,2,1.
IntegerArrayGenome[] parents = new IntegerArrayGenome[2];
parents[0] = (IntegerArrayGenome) pop.getGenomeFactory().factor();
parents[1] = (IntegerArrayGenome) pop.getGenomeFactory().factor();
for (int i = 1; i <= 10; i++) {
parents[0].getData()[i - 1] = i;
parents[1].getData()[i - 1] = 11 - i;
}