Exemple #1
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);
    }
  }
Exemple #2
0
  public void removeRules() {
    int i, pos;
    double minRate, rate;
    Rule rule;

    minRate = 1.0;
    pos = -1;
    for (i = 0; i < this.ruleBase.size(); i++) {
      rule = this.ruleBase.get(i);
      if (rule.getRightN() < 1) {
        this.ruleBase.remove(i);
        i--;
      } else {
        rate = (1.0 * rule.getRightN()) / (1.0 * rule.getWrongN() + rule.getRightN());
        if (rate < minRate) {
          minRate = rate;
          pos = i;
        }
      }
    }

    if (ruleBase.size() > 0 && pos > -1) this.ruleBase.remove(pos);
  }