Example #1
0
  public Object clone() {
    CharVectorIndividual myobj = (CharVectorIndividual) (super.clone());

    // must clone the genome
    myobj.genome = (char[]) (genome.clone());

    return myobj;
  }
Example #2
0
  public double distanceTo(Individual otherInd) {
    if (!(otherInd instanceof CharVectorIndividual))
      return super.distanceTo(otherInd); // will return infinity!

    CharVectorIndividual other = (CharVectorIndividual) otherInd;
    char[] otherGenome = other.genome;
    double sumDistance = 0.0;
    for (int i = 0; i < other.genomeLength(); i++) {
      double dist = this.genome[i] - (double) otherGenome[i];
      sumDistance += Math.abs(dist);
    }
    return sumDistance;
  }