public float computeFitness(Individual individual) {
   for (int i = 0; i < Problem.n; ) { // Empty increment
     char c = individual.getAllele(i++);
     for (int j = 1; j < 6; j++) if (individual.getAllele(i++) != c) return (float) 0;
   }
   return (float) 1;
 }
Пример #2
0
  // Compute scores for new leaf0 and leaf1, and add them to scoreList.
  private void computeNewLeafScores(SelectedSet selectedSet, int i, int j) {
    int NS = selectedSet.getN();
    for (int a = 0; a < NS; a++) {
      Individual individual = selectedSet.getIndividual(a);
      IGraph iterator = decisionGraphs[i].getGraph();
      while (!(iterator
          instanceof Leaf)) { // Iterator is a variable because we are still traversing the DG.
        int x = ((Variable) iterator).getVariable();
        char alleleX = individual.getAllele(x);
        if (alleleX == '0') {
          iterator = ((Variable) iterator).getZero();
        } else {
          iterator = ((Variable) iterator).getOne();
        }
      }
      int itrPosition = decisionGraphs[i].getLeafs().indexOf((Leaf) iterator);
      if (itrPosition == j || itrPosition == j + 1) { // We've reached one of the new leafs.
        int mZero = ((Leaf) iterator).getMZero();
        int mOne = ((Leaf) iterator).getMOne();
        if (mZero > 0 && mOne > 0) { // It's still "interesting" to split.
          char alleleI = individual.getAllele(i); // Value of Xi in individual a.
          for (int split : splitList[i]) {
            char alleleS = individual.getAllele(split); // Value of Xsplit in individual a.
            if (alleleI == '0') {
              if (alleleS == '0') {
                ((Leaf) iterator).addPossibleSplitFrequency(0, split); // m00[split]++;
              } else {
                ((Leaf) iterator).addPossibleSplitFrequency(1, split); // m01[split]++;
              }
            } else if (alleleS == '0') {
              ((Leaf) iterator).addPossibleSplitFrequency(2, split); // m10[split]++;
            } else {
              ((Leaf) iterator).addPossibleSplitFrequency(3, split); // m11[split]++;			
            }
          }
        }
      }
    }

    for (int a = 0; a <= 1; a++) {
      Leaf newLeaf =
          decisionGraphs[i].getLeaf(j + a); // The two new leafs are at positions 'j' and 'j+1'.
      int mZero = newLeaf.getMZero();
      int mOne = newLeaf.getMOne();
      if (mZero > 0 && mOne > 0) {
        for (int s : splitList[i]) {
          int m00 = newLeaf.getPossibleSplitFrequency(0, s);
          int m01 = newLeaf.getPossibleSplitFrequency(1, s);
          int m10 = newLeaf.getPossibleSplitFrequency(2, s);
          int m11 = newLeaf.getPossibleSplitFrequency(3, s);
          double scoreGain = bayesianMetric.computeScoreGain(mZero, mOne, m00, m01, m10, m11);
          newLeaf.setScoreGain(s, scoreGain);
          newLeaf.updateBestSplit(
              s,
              scoreGain); // Responsible for updating the value of the best split score gain in this
          // leaf.
        }
      }
    } // END: for(int a = 0 ...)
  } // END: computeNewLeafScores(...)
 public float computeFitness(Individual individual) {
   int six;
   float fit = 0;
   for (int i = 0; i < Problem.n; ) { // Empty increment
     six = Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     six += Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     six += Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     six += Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     six += Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     six += Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     six = Math.abs(six - 3);
     switch (six) {
       case 0:
         fit += 0.9;
         break;
       case 1:
         fit += 0.8;
         break;
       case 3:
         fit += 1;
         break;
       default:
         break;
     }
   }
   return fit;
 }
 public float computeFitness(Individual individual) {
   int k;
   float fit = 0;
   for (int i = 0; i < Problem.n; ) { // Empty increment
     k = Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     for (int j = 1; j < kay; j++)
       k += Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     if (k < kay) fit += kay - 1 - k;
     else fit += kay;
   }
   return fit;
 }
 public float computeFitness(Individual individual) {
   float fit = 0;
   for (int i = 0; i < Problem.n; ) { // Empty increment
     char a = individual.getAllele(i++);
     char b = individual.getAllele(i++);
     if (a == '1' && b == '1') fit += 0.9;
     if (a == '0' && b == '0') fit += 1;
   }
   return fit;
 }
 public float computeFitness(Individual individual) {
   int three;
   float fit = 0;
   for (int i = 0; i < Problem.n; ) { // Empty increment
     three = Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     three += Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     three += Integer.parseInt(String.valueOf(individual.getAllele(i++)));
     switch (three) {
       case 0:
         fit += 1;
         break;
       case 2:
         fit += 0.8;
         break;
       case 3:
         fit += 0.9;
         break;
       default:
         break;
     }
   }
   return fit;
 }
 public float computeFitness(Individual individual) {
   int fit = 0;
   for (int i = 0; i < Problem.n; i++) if (individual.getAllele(i) == '0') fit++;
   return (float) fit;
 }