コード例 #1
0
 /**
  * @param $population Population
  * @param $target Person
  * @return Population
  */
 public static function evolve($population, $target, $depth)
 {
     $id = 1;
     $newPopulation = new Population();
     if (self::$ELITISM) {
         $newPopulation->addPerson($population->getFittest($target));
     }
     $pool = Algorithm::selection($population, $target);
     //        var_dump('pool');
     //        var_dump($pool);
     //Do crossover here
     for ($i = 0; $i < count($pool) - 1; $i++) {
         for ($j = $i + 1; $j < count($pool); $j++) {
             $child = Algorithm::crossover($pool[$i], $pool[$j]);
             $child->setId($depth . '_' . $id);
             $id++;
             //                var_dump('CHILD');
             //                var_dump($child);
             $newPopulation->addPerson($child);
         }
     }
     //Do mutations here
     return $newPopulation;
 }