コード例 #1
0
ファイル: Best1BinDEBreeder.java プロジェクト: swapon15/ecj-1
  public DoubleVectorIndividual createIndividual(
      final EvolutionState state, int subpop, int index, int thread) {
    Individual[] inds = state.population.subpops[subpop].individuals;

    DoubleVectorIndividual v =
        (DoubleVectorIndividual)
            (state.population.subpops[subpop].species.newIndividual(state, thread));
    int retry = -1;
    do {
      retry++;

      // select three indexes different from each other and from that of the current parent
      int r0, r1, r2;
      // do
      {
        r0 = bestSoFarIndex[subpop];
      }
      // while( r0 == index );
      do {
        r1 = state.random[thread].nextInt(inds.length);
      } while (r1 == r0 || r1 == index);
      do {
        r2 = state.random[thread].nextInt(inds.length);
      } while (r2 == r1 || r2 == r0 || r2 == index);

      DoubleVectorIndividual g0 = (DoubleVectorIndividual) (inds[r0]);
      DoubleVectorIndividual g1 = (DoubleVectorIndividual) (inds[r1]);
      DoubleVectorIndividual g2 = (DoubleVectorIndividual) (inds[r2]);

      for (int i = 0; i < v.genome.length; i++)
        v.genome[i] =
            g0.genome[i]
                + (F + state.random[thread].nextDouble() * F_NOISE - (F_NOISE / 2.0))
                    * (g1.genome[i] - g2.genome[i]);
    } while (!valid(v) && retry < retries);
    if (retry >= retries && !valid(v)) // we reached our maximum
    {
      // completely reset and be done with it
      v.reset(state, thread);
    }

    return crossover(state, (DoubleVectorIndividual) (inds[index]), v, thread);
  }
コード例 #2
0
 /** Make a copy of the BitVectorIndividual. */
 public Object clone() {
   DoubleVectorIndividual tmp = (DoubleVectorIndividual) (super.clone());
   tmp.genome = (double[]) genome.clone();
   tmp.genome_size = genome_size;
   return tmp;
 }