Hey guys, I was wondering if I could get advice on improving the overall effectiveness of a program that implements a genetic algorithm. Yes, this is a question of tasks, but I have already completed the task myself and just looking for a way to make it work better.
Description of the problem
My program is currently reading a given chain of types of components h or p. (Example hphpphhphpphphhpphph). For each H and P, it generated a random move (up, down, left, right) and adds movement to the list of arrays contained in the Chromosome object. At the beginning, the program generates 19 moves for 10,000 chromosomes
SecureRandom sec = new SecureRandom();
byte[] sbuf = sec.generateSeed(8);
ByteBuffer bb = ByteBuffer.wrap(sbuf);
Random numberGen = new Random(bb.getLong());
int numberMoves = chromosoneData.length();
moveList = new ArrayList(numberMoves);
for (int a = 0; a < numberMoves; a++) {
int randomMove = numberGen.nextInt(4);
char typeChro = chromosoneData.charAt(a);
if (randomMove == 0) {
moveList.add(Move.Down);
} else if (randomMove == 1) {
moveList.add(Move.Up);
} else if (randomMove == 2) {
moveList.add(Move.Left);
} else if (randomMove == 3) {
moveList.add(Move.Right);
}
}
. 20% , - 20%. . , , , - . 2d- , , , , . (IE H [2,1] [1,1] [3,1] [2,0] [2,2] H, H , )
, , , , . , .
, , , , , , ( , )
, ( , CS ), , , . , , :
1) . , Comparable.
public int compareTo(Chromosome other) {
if(this.fitness >= other.fitness)
return 1;
if(this.fitness ==other.fitness )
return 0;
else
return -1;
}
2) , 40% .
double topPercentile = highestValue;
topPercentile = topPercentile * .20;
topPercentile = Math.ceil(topPercentile);
randomOne = numberGen.nextInt((int) topPercentile);
int randomTwo = numberGen.nextInt(highestValue - (int) topPercentile);
randomTwo = randomTwo + 25;
Chromosome firstChrom = (Chromosome) populationList.get(randomOne);
Chromosome secondChrom = (Chromosome) populationList.get(randomTwo);
Chromosome resultantChromosome = firstChrom.crossOver(secondChrom);
populationList.add(resultantChromosome);
Collections.sort(populationList);
populationList.remove(highestValue);
Chromosome bestResult = (Chromosome) populationList.get(0);
3) ,