Example #1
0
 @Override
 public Genotype clone() {
   Genotype retValue = new Genotype(token.clone());
   retValue.left = left == null ? null : left.clone();
   retValue.right = right == null ? null : right.clone();
   return retValue;
 }
Example #2
0
 /**
  * This function fixes any branches ending with a condition by adding the missing cases to this
  * node.
  *
  * @param g The root node.
  */
 private void fixupTree(Genotype g) {
   if (g.token.getToken() == TOKENS.H_LT_N || g.token.getToken() == TOKENS.H_GT_N) {
     if (g.left == null) g.left = new Genotype(new Token(false));
     if (g.right == null) g.right = new Genotype(new Token(false));
   }
   if (g.left != null) fixupTree(g.left);
   if (g.right != null) fixupTree(g.right);
 }
Example #3
0
 /**
  * A recursive function that converts a string into a genotype.
  *
  * @param g The current node.
  * @param s The string (array to pass by reference).
  * @return The filled node.
  */
 private Genotype decodeString(Genotype g, String[] s) {
   char in = s[0].charAt(0);
   if (in == ';') {
     s[0] = s[0].substring(1);
     return null;
   }
   int token = Integer.parseInt(s[0].substring(0, 2));
   int amount = Integer.parseInt(s[0].substring(2, 4));
   if (g != null) g.token = new Token(TokenMap.get(token), amount);
   else g = new Genotype(new Token(TokenMap.get(token), amount));
   s[0] = s[0].substring(4);
   g.left = decodeString(g.left, s);
   g.right = decodeString(g.right, s);
   return g;
 }
Example #4
0
 /**
  * This function tries to place a new node in a tree at the correct location.
  *
  * @param g The node to place.
  * @param previous The previous node.
  */
 private void place(Genotype g, Genotype previous) {
   if (g == null) {
     g = new Genotype(new Token(true));
     if (previous.left == null) previous.left = g;
     else previous.right = g;
     return;
   }
   if (g.left == null) place(g.left, g);
   else if (g.right == null) place(g.right, g);
   else {
     int cleft = count(g.left);
     int cright = count(g.right);
     if (cleft <= cright) place(g.left, g);
     else place(g.right, g);
   }
 }