Advertisement
Guest User

Mutation Scrambler

a guest
May 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. @Override
  2. public void run(I ind) {
  3. /** Scramble Mutation
  4.  
  5. Scramble mutation is also popular with permutation representations.
  6. In this, from the entire chromosome, a subset of genes is chosen
  7. and their values are scrambled or shuffled randomly.
  8. **/
  9.  
  10. if(GeneticAlgorithm.random.nextDouble()<=probability) {
  11. int p1 = GeneticAlgorithm.random.nextInt(ind.getGenome().length+1-0)-0;
  12.  
  13. int p2= GeneticAlgorithm.random.nextInt(p1+1-0)-0;
  14. System.out.println(p2+"-"+p1);
  15.  
  16. for (int i = p2; i < p1; i++) {
  17. int pos1=GeneticAlgorithm.random.nextInt(p1-i)+i;
  18. System.out.println(pos1+" "+i);
  19. ind.swapGenesMutation(ind, i, pos1);
  20. }
  21.  
  22.  
  23. }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement