Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int childnumber = 0;
- for(int father=0; father<20; father++){
- for(int j=0; j<5; j++){
- char[] child = new char[TARGET.length()];
- childnumber++;
- int mother = (int) Math.random()*19 +1;
- if(mother!=father){
- int crosspoint = (int) Math.random()*10 +1;
- for(int x = 0; x<crosspoint+1; x++){
- child[x] = population[father].genoToPhenotype().charAt(x);
- }
- for(int y = crosspoint; y<TARGET.length(); y++){
- child[y] = population[mother].genoToPhenotype().charAt(y);
- }
- }
- if(mother==father){
- mother--;
- int crosspoint = (int) Math.random()*10;
- for(int x = 0; x<crosspoint+1; x++){
- child[x] = population[father].genoToPhenotype().charAt(x);
- }
- for(int y = crosspoint; y<TARGET.length(); y++){
- child[y] = population[mother].genoToPhenotype().charAt(y);
- }
- }
- population[childnumber] = new Individual(child);
- }
- }
- for (int i = 0; i < population.length; i++) {
- System.out.println(population[i].genoToPhenotype());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement