示例#1
0
  /** It applies the migration stage */
  void Migration() {
    int i, j, num;
    double u;

    /* First, the individual in the population are ordered according to their fitness */
    Collections.sort(Poblacion);

    /* The second half (the worst one) is radomly initialized again */
    for (j = (tamPoblacion / 2); j < tamPoblacion; j++) {
      /* First, the antecedent */
      for (i = 0; i < entradas; i++) {
        Poblacion.get(j).antecedente[i].m =
            Randomize.RanddoubleClosed(train.getMin(i), train.getMax(i));
        Poblacion.get(j).antecedente[i].sigma = Randomize.RandintClosed(1, 4);
      }

      /* Secondly, the consequent */
      do {
        num = 0;

        for (i = 0; i < entradas; i++) {
          u = Randomize.RandClosed();
          /* The term is used in the consequent */
          if (u < 0.5) {
            Poblacion.get(j).consecuente[i] = Randomize.RanddoubleClosed(-1.0, 1.0);
            //                    Poblacion.get(j).consecuente[entradas] =
            // Randomize.RanddoubleClosed(-45.0, 45.0);
            if (Poblacion.get(j).consecuente[i] != 0.0) {
              num++;
            }
          }
          /* The term is NOT used in the consequent */
          else {
            Poblacion.get(j).consecuente[i] = 0.0;
          }
        }

        u = Randomize.RandClosed();
        /* The term is used in the consequent */
        if (u < 0.5) {
          Poblacion.get(j).consecuente[entradas] =
              Randomize.RanddoubleClosed(
                  -1.0 * ((train.getMax(entradas) - train.getMin(entradas)) / 2.0),
                  ((train.getMax(entradas) - train.getMin(entradas)) / 2.0));
          //                    Poblacion.get(j).consecuente[entradas] =
          // Randomize.RanddoubleClosed(-45.0, 45.0);
          //                Poblacion.get(j).consecuente[entradas] =
          // Randomize.RanddoubleClosed(train.getMin(entradas), train.getMax(entradas));
          if (Poblacion.get(j).consecuente[entradas] != 0.0) {
            num++;
          }
        }
        /* The term is NOT used in the consequent */
        else {
          Poblacion.get(j).consecuente[entradas] = 0.0;
        }
      } while (num == 0);
    }
  }
示例#2
0
  /** It applies the reproduction stage */
  void Reproduction() {
    int i, madre, padre;

    /* First, the individual in the population are ordered according to their fitness */
    Collections.sort(Poblacion);

    /* Create the new population */
    Poblacion2.clear();
    Hijos.clear();

    /* Top-half best-performing individuals will advance to the next generation */
    for (i = 0; i < (tamPoblacion / 2); i++) {
      Individual indi = new Individual(Poblacion.get(i));
      Poblacion2.add(indi);
    }

    /* The remaining half is generated by performing crossover operations on individuals
    in the top half */
    while (Poblacion.size() != (Poblacion2.size() + Hijos.size())) {
      /* 2 parents are selected */
      madre = Selection();
      do {
        padre = Selection();
      } while (madre == padre);

      /* 2 children are created by crossover operator */
      Crossover(madre, padre);
    }

    /* Create the population for the next generation */
    Poblacion.clear();
    for (i = 0; i < Poblacion2.size(); i++) {
      Individual indi = new Individual(Poblacion2.get(i));
      Poblacion.add(indi);
    }
    for (i = 0; i < Hijos.size(); i++) {
      Individual indi = new Individual(Hijos.get(i));
      Poblacion.add(indi);
    }
  }
示例#3
0
 /** Function to sort the rule base */
 public void sort() {
   Collections.sort(this.ruleBase);
 }