Skip to content

Commit

Permalink
Fix issue where Mutation was duplicating chromosones
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Salter committed Mar 18, 2019
1 parent 48f1b97 commit cbe0e22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# genetic-algorithm
A simple framework for building and solving genetic algorithms

## Examples

There is an example Travelling Salesman Problem in the `examples/` directory.
Use `php examples/tsp.php` to watch it in action
3 changes: 2 additions & 1 deletion src/Population.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ private function mutate(Organism $a): Organism
$splicePointA = mt_rand(0, count($dna) - 1);
$splicePointB = mt_rand(0, count($dna) - 1);

$dna[$splicePointA] = $dna[$splicePointB];
$dna[$splicePointA] = $a->getDna()[$splicePointB];
$dna[$splicePointB] = $a->getDna()[$splicePointA];

return $this->parameters->getOrganismFactory()->createFromDna($dna);
}
Expand Down

0 comments on commit cbe0e22

Please sign in to comment.