Example #1
0
  /**
   * Adds a classifier with the a given numerosity to the set. It checks if the classifier already
   * exists and increases its numerosity. It also checks for subsumption and updates the set's
   * numerosity.
   *
   * @param thoroughAdd to thoroughly check addition
   * @param macro the macroclassifier to add to the set
   */
  public final void addClassifier(final Macroclassifier macro, final boolean thoroughAdd) {

    final int numerosity = macro.numerosity;
    // Add numerosity to the Set
    this.totalNumerosity += numerosity;

    // Subsume if possible
    if (thoroughAdd) {
      final Classifier aClassifier = macro.myClassifier;
      for (int i = 0; i < myMacroclassifiers.size(); i++) {
        final Classifier theClassifier = myMacroclassifiers.elementAt(i).myClassifier;
        if (theClassifier.canSubsume()) {
          if (theClassifier.isMoreGeneral(aClassifier)) {
            // Subsume and control size...
            myMacroclassifiers.elementAt(i).numerosity += numerosity;
            if (myISizeControlStrategy != null) {
              myISizeControlStrategy.controlPopulation(this);
            }
            return;
          }
        } else if (theClassifier.equals(aClassifier)) { // Or it can't
          // subsume but
          // it is equal
          myMacroclassifiers.elementAt(i).numerosity += numerosity;
          if (myISizeControlStrategy != null) {
            myISizeControlStrategy.controlPopulation(this);
          }
          return;
        }
      }
    }

    /*
     * No matching or subsumable more general classifier found. Add and
     * control size...
     */
    this.myMacroclassifiers.add(macro);
    if (myISizeControlStrategy != null) {
      myISizeControlStrategy.controlPopulation(this);
    }
  }