Advertisement
Guest User

Mutation Swap

a guest
May 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. @Override
  2. public void run(I ind) {
  3. /*
  4. for (int i = 0; i <ind.getNumGenes() ; i++) {
  5. if(GeneticAlgorithm.random.nextDouble()<probability){
  6. ind.swapGenes(ind,i);
  7. }
  8. }*/
  9.  
  10. /** Swap Mutation
  11.  
  12. In swap mutation, we select two positions on the genome at random,
  13. and interchange the values.
  14. **/
  15.  
  16. if(GeneticAlgorithm.random.nextDouble()<=probability) {
  17. int p1 = GeneticAlgorithm.random.nextInt(ind.getGenome().length);
  18. int p2;
  19. do{
  20. p2= GeneticAlgorithm.random.nextInt(ind.getGenome().length);
  21. }while(p2==p1);
  22. System.out.println(p1+" "+p2);
  23.  
  24. ind.swapGenesMutation(ind, p1, p2);
  25.  
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement