public function __construct($target, $size = 1024, $crossover = 0.8, $elitism = 0.1, $mutation = 0.03) { $this->crossover = $crossover; $this->elitism = $elitism; $this->mutation = $mutation; $this->maxSize = $this->currentSize = $size; $this->targetGene = $target; while ($size--) { $this->population[] = Chromosome::genRandom($this); } $this->sortPopulation(); }
/** * @todo Implement testMutate(). */ public function testMutate() { $i = 1000; while ($i--) { $c1 = Chromosome::genRandom($this->population); $c2 = $c1->mutate(); $this->assertEquals(strlen($c1->gene), strlen($c2->gene)); $diff = levenshtein($c1->gene, $c2->gene); $this->assertTrue($diff <= 1); } }