java - N-Queens Genetic Algorithm in regards to Selection and Mutation -
currently program works 8-queens, trying make work 22-queens. takes long when run algorithm 22 queens. believe problem may lie in way of selecting population or mutation.
private chromosome selectchromosome(chromosome[] population) { random random = new random(); double x = random.nextdouble(); double accfit = 0; (int = 0; < population.length; i++) { accfit += population[i].fitness; if (accfit > x && != 0) { return population[i - 1]; } } return population[0]; }
not sure if how mutation part
private chromosome crossover(chromosome x, chromosome y) { random random = new random(); int point = random.nextint(x.state.length); int[] state = new int[x.state.length]; (int = 0; < point; i++) { state[i] = x.state[i]; } (int = point; < y.state.length; i++) { state[i] = y.state[i]; } // mutation double mutaterate = random.nextdouble(); if (mutaterate <= 0.05) { state[random.nextint(state.length)] = random.nextint(state.length); } return new chromosome(state); }
Comments
Post a Comment