Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. int childnumber = 0;
  2.  
  3. for(int father=0; father<20; father++){
  4. for(int j=0; j<5; j++){
  5. char[] child = new char[TARGET.length()];
  6. childnumber++;
  7. int mother = (int) Math.random()*19 +1;
  8. if(mother!=father){
  9. int crosspoint = (int) Math.random()*10 +1;
  10.  
  11. for(int x = 0; x<crosspoint+1; x++){
  12.  
  13. child[x] = population[father].genoToPhenotype().charAt(x);
  14.  
  15. }
  16. for(int y = crosspoint; y<TARGET.length(); y++){
  17.  
  18. child[y] = population[mother].genoToPhenotype().charAt(y);
  19. }
  20. }
  21. if(mother==father){
  22. mother--;
  23. int crosspoint = (int) Math.random()*10;
  24.  
  25. for(int x = 0; x<crosspoint+1; x++){
  26.  
  27. child[x] = population[father].genoToPhenotype().charAt(x);
  28.  
  29. }
  30. for(int y = crosspoint; y<TARGET.length(); y++){
  31.  
  32. child[y] = population[mother].genoToPhenotype().charAt(y);
  33. }
  34. }
  35. population[childnumber] = new Individual(child);
  36. }
  37. }
  38.  
  39. for (int i = 0; i < population.length; i++) {
  40. System.out.println(population[i].genoToPhenotype());
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement