예제 #1
0
 /**
  * Provides implementation-independent means for creating new Gene instances. The new instance
  * that is created and returned should be setup with any implementation-dependent configuration
  * that this Gene instance is setup with (aside from the actual value, of course). For example, if
  * this Gene were setup with bounds on its value, then the Gene instance returned from this method
  * should also be setup with those same bounds. This is important, as the JGAP core will invoke
  * this method on each Gene in the sample Chromosome in order to create each new Gene in the same
  * respective gene position for a new Chromosome.
  *
  * @return a new Gene instance of the same type and with the same setup as this concrete Gene
  * @author Neil Rostan
  * @author Klaus Meffert
  * @since 2.6 (since 1.0 in IntegerGene)
  */
 public Gene newGene() {
   Gene result = newGeneInternal();
   result.setConstraintChecker(getConstraintChecker());
   result.setEnergy(getEnergy());
   /** @todo clone app.data */
   result.setApplicationData(getApplicationData());
   return result;
 }
예제 #2
0
 /**
  * Compares this Gene with the given object and returns true if the other object is a Gene of the
  * same type and has the same value (allele) as this Gene. Otherwise it returns false.
  *
  * @param a_other the object to compare to this Gene for equality
  * @return true if this Gene is equal to the given object, false otherwise
  * @author Klaus Meffert
  * @since 1.1
  */
 public boolean equals(final Object a_other) {
   try {
     int result = compareTo(a_other);
     if (result == 0) {
       if (isCompareApplicationData()) {
         Gene otherGene = (Gene) a_other;
         int resultAppData =
             compareApplicationData(getApplicationData(), otherGene.getApplicationData());
         return resultAppData == 0;
       } else {
         return true;
       }
     } else {
       return false;
     }
   } catch (ClassCastException e) {
     // If the other object isn't an Gene of current type
     // (like IntegerGene for IntegerGene's), then we're not equal.
     // -----------------------------------------------------------
     return false;
   }
 }