Advertisement
Guest User

mutate method

a guest
Dec 11th, 2011
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. private Candidate mutate(Candidate c) {
  2.     int swapPos1, swapPos2;
  3.     swapPos1 = rnd.nextInt(numElements);
  4.     swapPos2 = rnd.nextInt(numElements);
  5.     while(swapPos1 == swapPos2) {
  6.         swapPos2 = rnd.nextInt(numElements);
  7.     }
  8.    
  9.     int temp = c.genotype[swapPos1];
  10.     c.genotype[swapPos1] = c.genotype[swapPos2];
  11.     c.genotype[swapPos2] = temp;
  12.    
  13.     return c;
  14. }
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement