示例#1
0
  // Crossover individuals
  private static Individual crossover(Individual indiv1, Individual indiv2, EventList eventList) {
    Individual newSol = new Individual(indiv1.geneSize(), eventList);

    for (int i = 0; i < indiv1.geneSize(); i++) {
      // Crossover
      if (Math.random() <= uniformRate) {
        newSol.setGene(i, indiv1.getGene(i));
      } else {
        newSol.setGene(i, indiv2.getGene(i));
      }
    }
    return newSol;
  }
示例#2
0
 // Mutate an individual
 private static void mutate(EventList eventList, Individual indiv) {
   for (int i = 0; i < indiv.geneSize(); i++)
     if (Math.random() <= mutationRate) indiv.setGene(i, eventList.getRandomEventID());
 }