Beispiel #1
0
  /**
   * Sets the population size and resets the GA generation count, as well as initializing the
   * population with random individuals.
   *
   * @param inSize the size of the new GA population.
   */
  protected void ResizeAndInitialize(int inSize) throws Exception {
    _populations = new GAIndividual[2][inSize];
    _currentPopulation = 0;
    _generationCount = 0;

    Object iObject = _individualClass.newInstance();

    if (!(iObject instanceof GAIndividual))
      throw new Exception("individual-class must inherit from class GAIndividual");

    GAIndividual individual = (GAIndividual) iObject;

    for (int i = 0; i < inSize; i++) {
      _populations[0][i] = individual.clone();
      InitIndividual(_populations[0][i]);
    }
  }