Package org.encog.ml.genetic.genome

Examples of org.encog.ml.genetic.genome.ArrayGenome


   */
  @Override
  public void performOperation(Random rnd, Genome[] parents, int parentIndex,
      Genome[] offspring, int offspringIndex) {
   
    ArrayGenome mother = (ArrayGenome)parents[parentIndex];
    ArrayGenome father = (ArrayGenome)parents[parentIndex+1];
    ArrayGenome offspring1 = (ArrayGenome)this.owner.getPopulation().getGenomeFactory().factor();
    ArrayGenome offspring2 = (ArrayGenome)this.owner.getPopulation().getGenomeFactory().factor();
   
    offspring[offspringIndex] = offspring1;
    offspring[offspringIndex+1] = offspring2;
   
    final int geneLength = mother.size();

    // the chromosome must be cut at two positions, determine them
    final int cutpoint1 = (int) (rnd.nextInt(geneLength - this.cutLength));
    final int cutpoint2 = cutpoint1 + this.cutLength;

    // handle cut section
    for (int i = 0; i < geneLength; i++) {
      if (!((i < cutpoint1) || (i > cutpoint2))) {
        offspring1.copy(father,i,i);
        offspring2.copy(mother,i,i);
      }
    }

    // handle outer sections
    for (int i = 0; i < geneLength; i++) {
      if ((i < cutpoint1) || (i > cutpoint2)) {
        offspring1.copy(mother,i,i);
        offspring2.copy(father,i,i);
      }
    }
  }
View Full Code Here


   */
  @Override
  public void performOperation(final Random rnd, final Genome[] parents,
      final int parentIndex, final Genome[] offspring,
      final int offspringIndex) {
    final ArrayGenome parent = (ArrayGenome) parents[parentIndex];
    offspring[offspringIndex] = this.owner.getPopulation()
        .getGenomeFactory().factor();
    final ArrayGenome child = (ArrayGenome) offspring[offspringIndex];

    child.copy(parent);

    final int length = parent.size();
    int iswap1 = (int) (rnd.nextDouble() * length);
    int iswap2 = (int) (rnd.nextDouble() * length);

    // can't be equal
    if (iswap1 == iswap2) {
      // move to the next, but
      // don't go out of bounds
      if (iswap1 > 0) {
        iswap1--;
      } else {
        iswap1++;
      }

    }

    // make sure they are in the right order
    if (iswap1 > iswap2) {
      final int temp = iswap1;
      iswap1 = iswap2;
      iswap2 = temp;
    }

    child.swap(iswap1, iswap2);
  }
View Full Code Here

TOP

Related Classes of org.encog.ml.genetic.genome.ArrayGenome

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.