diff options
| author | Mike Buland <mike@xagasoft.com> | 2012-07-09 08:39:37 -0600 | 
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2012-07-09 08:39:37 -0600 | 
| commit | 40ee7ad5aeadeb9823e1cd6e1218a1999c608a65 (patch) | |
| tree | 6e819d8406d818eaa63cb6f04e2a129b8561c213 /src/tests | |
| download | libgenetic-40ee7ad5aeadeb9823e1cd6e1218a1999c608a65.tar.gz libgenetic-40ee7ad5aeadeb9823e1cd6e1218a1999c608a65.tar.bz2 libgenetic-40ee7ad5aeadeb9823e1cd6e1218a1999c608a65.tar.xz libgenetic-40ee7ad5aeadeb9823e1cd6e1218a1999c608a65.zip | |
New libgenetic.  Genetic algorithms, only good.
Diffstat (limited to '')
| -rw-r--r-- | src/tests/binary.cpp | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/src/tests/binary.cpp b/src/tests/binary.cpp new file mode 100644 index 0000000..717c171 --- /dev/null +++ b/src/tests/binary.cpp | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | #include "genetic/phenotypebinary.h" | ||
| 2 | #include "genetic/operatorbasic.h" | ||
| 3 | |||
| 4 | #include <bu/sio.h> | ||
| 5 | #include <bu/random.h> | ||
| 6 | #include <bu/randomcmwc.h> | ||
| 7 | #include <time.h> | ||
| 8 | |||
| 9 | using namespace Bu; | ||
| 10 | |||
| 11 | int main( int argc, char *argv[] ) | ||
| 12 | { | ||
| 13 | Bu::Random::setGenerator<Bu::RandomCmwc>(); | ||
| 14 | Bu::Random::seed( time( NULL ) ); | ||
| 15 | |||
| 16 | Genetic::OperatorBasic op( new Genetic::PhenotypeBinary( 45 ), 0.1 ); | ||
| 17 | Genetic::Phenotype *pPb1 = op.random(); | ||
| 18 | Genetic::Phenotype *pPb2 = op.random(); | ||
| 19 | Genetic::Phenotype *pPb3; | ||
| 20 | |||
| 21 | sio << pPb1->toString() << sio.nl; | ||
| 22 | sio << pPb2->toString() << sio.nl; | ||
| 23 | |||
| 24 | Genetic::PhenotypeList lParents; | ||
| 25 | lParents.append( pPb1 ); | ||
| 26 | lParents.append( pPb2 ); | ||
| 27 | pPb3 = op.mate( lParents ); | ||
| 28 | |||
| 29 | sio << pPb3->toString() << sio.nl; | ||
| 30 | |||
| 31 | delete pPb1; | ||
| 32 | delete pPb2; | ||
| 33 | delete pPb3; | ||
| 34 | |||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | |||
