Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
0
  /** It initializes each individual in the population */
  void initializePopulation() {
    int i, j, num;
    double u;

    for (j = 0; 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[i] =
            // Randomize.RanddoubleClosed(train.getMin(i) - 45.0, train.getMax(i) + 45.0);
            //                        Poblacion.get(j).consecuente[i] =
            // 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(
          // - 45.0, 45.0);
          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));
          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);
    }
  }
Ejemplo n.º 3
0
  /** It applies mutation genetic operator */
  void Mutation() {
    int i, j, aux1, num;
    double u, u2;

    for (j = 0; j < tamPoblacion; j++) {
      /* First, the antecedent */
      for (i = 0; i < entradas; i++) {
        u = Randomize.RandClosed();
        if (u < probMut) {
          Poblacion.get(j).antecedente[i].m =
              Randomize.RanddoubleClosed(train.getMin(i), train.getMax(i));
        }

        u = Randomize.RandClosed();
        if (u < probMut) {
          aux1 = Poblacion.get(j).antecedente[i].sigma;
          do {
            Poblacion.get(j).antecedente[i].sigma = Randomize.RandintClosed(1, 4);
          } while (aux1 == Poblacion.get(j).antecedente[i].sigma);
        }
      }

      /* Secondly, the consequent */
      num = 0;
      for (i = 0; i <= entradas; i++) {
        if (Poblacion.get(j).consecuente[i] != 0.0) {
          num++;
        }
      }

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

      u = Randomize.RandClosed();
      if (u < probMut) {
        u2 = Randomize.RandClosed();
        if (u2 < 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);
        }
        /* The term is NOT used in the consequent */
        else {
          if (num != 1) {
            Poblacion.get(j).consecuente[entradas] = 0.0;
            num--;
          }
        }
      }
    }
  }