Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package snake.snakeAI.ga.geneticOperators;
- import snake.snakeAI.ga.GeneticAlgorithm;
- import snake.snakeAI.ga.RealVectorIndividual;
- //PLEASE, MODIFY THE CLASS NAME
- public class MutationDouble <I extends RealVectorIndividual> extends Mutation<I> {
- private double deviation;
- public MutationDouble(double probability, double deviation) {
- super(probability);
- this.deviation = deviation;
- }
- @Override
- public void run(I ind) {
- // TODO
- for (int i = 0; i < ind.getNumGenes(); i++){
- if (GeneticAlgorithm.random.nextDouble() < probability) {
- //double newGenome = ind.getGene(i) + deviation * r.nextGaussian();
- double newGenome = ind.getGene(i) + deviation * (GeneticAlgorithm.random.nextDouble() * 2 - 1);
- ind.setGene(i, newGenome);
- }
- }
- }
- //copiar do projeto anterior run da mutação uniforme (em vez de substituir 1 po 0 e vice versa meter randoms)
- //individual.setgene(i, Geneticalgorithm.random.nexdouble()*2 - 1
- @Override
- public String toString(){
- return "Uniform distribution mutation (" + probability /* + TODO?*/;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement