Package org.encog.ml.genetic.genome

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


public class TestMinimizeAdjustedScoreComp {
  @Test
  public void testCompare() {
   
    BasicGenome genome1 = new IntegerArrayGenome(1);
    genome1.setAdjustedScore(10);
    genome1.setScore(4);
   
    BasicGenome genome2 = new IntegerArrayGenome(1);
    genome2.setAdjustedScore(4);
    genome2.setScore(10);

    MinimizeAdjustedScoreComp comp = new MinimizeAdjustedScoreComp();
   
    Assert.assertTrue(comp.compare(genome1, genome2)>0);
  }
View Full Code Here


public class TestMinimizeScoreComp {
  @Test
  public void testCompare() {
   
    BasicGenome genome1 = new IntegerArrayGenome(1);
    genome1.setAdjustedScore(10);
    genome1.setScore(4);
   
    BasicGenome genome2 = new IntegerArrayGenome(1);
    genome2.setAdjustedScore(4);
    genome2.setScore(10);

    MinimizeScoreComp comp = new MinimizeScoreComp();
   
    Assert.assertTrue(comp.compare(genome1, genome2)<0);
  }
View Full Code Here

public class TestMaximizeAdjustedScoreComp {
 
  @Test
  public void testCompare() {
   
    BasicGenome genome1 = new IntegerArrayGenome(1);
    genome1.setAdjustedScore(10);
    genome1.setScore(4);
   
    BasicGenome genome2 = new IntegerArrayGenome(1);
    genome2.setAdjustedScore(4);
    genome2.setScore(10);

    MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();
   
    Assert.assertTrue(comp.compare(genome1, genome2)<0);
  }
View Full Code Here

public class TestMaximizeScoreComp {
  @Test
  public void testCompare() {
   
    BasicGenome genome1 = new IntegerArrayGenome(1);
    genome1.setAdjustedScore(10);
    genome1.setScore(4);
   
    BasicGenome genome2 = new IntegerArrayGenome(1);
    genome2.setAdjustedScore(4);
    genome2.setScore(10);

    MaximizeScoreComp comp = new MaximizeScoreComp();
   
    Assert.assertTrue(comp.compare(genome1, genome2)>0);
  }
View Full Code Here

   */
  @Override
  public void performOperation(Random rnd, Genome[] parents, int parentIndex,
      Genome[] offspring, int offspringIndex) {
   
    IntegerArrayGenome mother = (IntegerArrayGenome)parents[parentIndex];
    IntegerArrayGenome father = (IntegerArrayGenome)parents[parentIndex+1];
    IntegerArrayGenome offspring1 = (IntegerArrayGenome)this.owner.getPopulation().getGenomeFactory().factor();
    IntegerArrayGenome offspring2 = (IntegerArrayGenome)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;

    // keep track of which genes have been taken in each of the two
    // offspring, defaults to false.
    final Set<Integer> taken1 = new HashSet<Integer>();
    final Set<Integer> taken2 = new HashSet<Integer>();

    // 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);
        taken1.add(father.getData()[i]);
        taken2.add(mother.getData()[i]);
      }
    }

    // handle outer sections
    for (int i = 0; i < geneLength; i++) {
      if ((i < cutpoint1) || (i > cutpoint2)) {

        offspring1.getData()[i] = SpliceNoRepeat.getNotTaken(mother, taken1);
        offspring2.getData()[i] = SpliceNoRepeat.getNotTaken(father, taken2);

      }
    }
  }
View Full Code Here

TOP

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

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.