diff options
Diffstat (limited to 'src/operatorbasic.cpp')
| -rw-r--r-- | src/operatorbasic.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/operatorbasic.cpp b/src/operatorbasic.cpp index ce37f78..2ac2b0f 100644 --- a/src/operatorbasic.cpp +++ b/src/operatorbasic.cpp | |||
| @@ -28,21 +28,20 @@ Genetic::Phenotype *Genetic::OperatorBasic::mate( | |||
| 28 | const Genetic::PhenotypeList &lParents ) | 28 | const Genetic::PhenotypeList &lParents ) |
| 29 | { | 29 | { |
| 30 | Genetic::Phenotype *pChild = lParents.first()->makeEmptyOffspring(); | 30 | Genetic::Phenotype *pChild = lParents.first()->makeEmptyOffspring(); |
| 31 | 31 | ||
| 32 | int iBits = lParents.first()->getSize(); | ||
| 32 | // Right now, we assume both parents have the same amount of "DNA" | 33 | // Right now, we assume both parents have the same amount of "DNA" |
| 33 | int iSplitPoint = ((uint32_t)Bu::Random::rand())%lParents.first()->getSize(); | 34 | int iSplitPoint = ((uint32_t)Bu::Random::rand())%iBits; |
| 34 | pChild->copyFrom( *lParents.first(), 0, iSplitPoint ); | 35 | pChild->copyFrom( *lParents.first(), 0, iSplitPoint ); |
| 35 | pChild->copyFrom( *lParents.last(), iSplitPoint, | 36 | pChild->copyFrom( *lParents.last(), iSplitPoint, iBits-iSplitPoint ); |
| 36 | lParents.last()->getSize()-iSplitPoint ); | 37 | |
| 38 | int iChange = iBits * (Bu::Random::randNorm() * fMutationRate * 1.25); | ||
| 37 | 39 | ||
| 38 | // Mutate the child some | 40 | for( int j = 0; j < iChange; j++ ) |
| 39 | for( int j = 0; j < pChild->getSize(); j++ ) | ||
| 40 | { | 41 | { |
| 41 | //sio << Bu::Random::randNorm() << sio.nl; | 42 | pChild->mutate( Bu::Random::rand( 0, iBits ), 1.0 ); |
| 42 | if( Bu::Random::randNorm() <= fMutationRate ) | ||
| 43 | pChild->mutate( j, 1.0 ); | ||
| 44 | } | 43 | } |
| 45 | 44 | ||
| 46 | return pChild; | 45 | return pChild; |
| 47 | } | 46 | } |
| 48 | 47 | ||
