The Chromosome classes.

POWER JAVA
Genetic Programming in Java—A Scheduling Example
Peter Winzell
Listing 1. The Chromosome classes.


public abstract class Chromosome {
  protected static double mutationProb = 0.01;
  protected static double crossOverProb = 1.0;
  protected static int crossOverPoints = 1;
  private java.util.BitSet bitVector = null;
  ...
  Chromosome(int nBits){
    bitVector = new java.util.BitSet(nBits);
    ...
  }

  abstract long fitness();

  protected boolean crossover(double prob);
  protected boolean mutation(double prob);
  public void reproduce(Chromosome mate, Chromosome
                                             child1,Chromosome child2){
  ... 
}
  ...
}

public class MyChromosome extends Chromosome {
  ...
  private static ArrayList points = new ArrayList(10);
  static{
    setPoints();
  }
  ...
public long fitness(){
    int activityCounter = 0;
    long partSum = 0;
    int size = TestData.size()*no_decodingBits;
    for (int i = 0; i < size; i = i + no_decodingBits){
      int position = binarytoint(i,i+(no_decodingBits-1));
      Activity currentA = (Activity)
      TestData.activities.get(activityCounter);
      PartSum  += currentA.getCurrentPoint(position % 10);
      activityCounter++;
    }
    restorePointLists();
    fitnessValue = partSum;
    return partSum;
  }
...
}

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.