Пример #1
0
  private void copyElements(int index1, int index2, int cutPoint) {
    // to modify the first chromosome between the index1 to index2, which genes
    // is from chromosome 2.
    int counter = 0;

    for (int i = 0; i < chromosomeLength; i++) {
      if (i < cutPoint) {
        // System.out.print(i+":
        // "+originalPop.getSingleChromosome(index1).genes[i]+"->"+originalPop.getSingleChromosome(index2).genes[i]+"\t");
        newPop.setGene(index1, i, originalPop.getSingleChromosome(index2).genes[i]);
      }
    }
    // System.out.println();
  }
Пример #2
0
  public void setData(double crossoverRate, populationI originalPop) {
    this.originalPop = originalPop;
    popSize = originalPop.getPopulationSize();
    // System.out.println("originalPop.getLengthOfChromosome()
    // "+originalPop.getLengthOfChromosome());
    newPop = new population();
    newPop.setGenotypeSizeAndLength(
        originalPop.getEncodedType(),
        popSize,
        originalPop.getLengthOfChromosome(),
        originalPop.getNumberOfObjectives());
    newPop.initNewPop();

    for (int i = 0; i < popSize; i++) {
      newPop.setSingleChromosome(i, originalPop.getSingleChromosome(i));
    }
    this.crossoverRate = crossoverRate;
    chromosomeLength = originalPop.getSingleChromosome(0).genes.length;
  }