Advertisement
Guest User

newChild method

a guest
Dec 11th, 2011
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. private Candidate newChild(Candidate c1, Candidate c2, int pivot) {
  2.     Candidate newCandidate = new Candidate(cubeSize);
  3.    
  4.     Set<Integer> usedGenes = new HashSet<Integer>(pivot);
  5.    
  6.     int pivotPointPos = pivot;
  7.     for(int i=0; i<=pivotPointPos; i++) {
  8.         newCandidate.genotype[i] = c1.genotype[i];
  9.         usedGenes.add(c1.genotype[i]);
  10.     }
  11.     for(int i=0; i<numElements; i++) {
  12.         if(!usedGenes.contains(c2.genotype[i])) {
  13.             newCandidate.genotype[++pivotPointPos] = c2.genotype[i];
  14.         }
  15.     }
  16.     return newCandidate;
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement