Advertisement
Guest User

Untitled

a guest
May 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package snake.snakeAI.ga.geneticOperators;
  2.  
  3. import snake.snakeAI.ga.GeneticAlgorithm;
  4. import snake.snakeAI.ga.RealVectorIndividual;
  5.  
  6.  
  7. //PLEASE, MODIFY THE CLASS NAME
  8. public class MutationDouble <I extends RealVectorIndividual> extends Mutation<I> {
  9.     private double deviation;
  10.    
  11.     public MutationDouble(double probability, double deviation) {
  12.         super(probability);
  13.         this.deviation = deviation;
  14.     }
  15.  
  16.     @Override
  17.     public void run(I ind) {
  18.         // TODO
  19.         for (int i = 0; i < ind.getNumGenes(); i++){
  20.             if (GeneticAlgorithm.random.nextDouble() < probability) {
  21.                 //double newGenome = ind.getGene(i) + deviation * r.nextGaussian();
  22.                 double newGenome = ind.getGene(i) + deviation * (GeneticAlgorithm.random.nextDouble() * 2 - 1);
  23.                 ind.setGene(i, newGenome);
  24.             }
  25.         }
  26.     }
  27.     //copiar do projeto anterior run da mutação uniforme (em vez de substituir 1 po 0 e vice versa meter randoms)
  28.     //individual.setgene(i, Geneticalgorithm.random.nexdouble()*2 - 1
  29.     @Override
  30.     public String toString(){
  31.         return "Uniform distribution mutation (" + probability /* + TODO?*/;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement