diff options
| author | Mike Buland <mike@xagasoft.com> | 2012-07-09 12:01:50 -0600 |
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2012-07-09 12:01:50 -0600 |
| commit | 1f7c135934b6604c5409d4b6f34861105c0a64cb (patch) | |
| tree | cc421e2e8620b72e202f0eddf2cd5f1478d3bc06 /src/tests/maxima/fitnessfunctioneq.cpp | |
| parent | 40ee7ad5aeadeb9823e1cd6e1218a1999c608a65 (diff) | |
| download | libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.gz libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.bz2 libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.xz libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.zip | |
It works well enough to solve polynomial maxima.
Diffstat (limited to 'src/tests/maxima/fitnessfunctioneq.cpp')
| -rw-r--r-- | src/tests/maxima/fitnessfunctioneq.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/tests/maxima/fitnessfunctioneq.cpp b/src/tests/maxima/fitnessfunctioneq.cpp new file mode 100644 index 0000000..5694507 --- /dev/null +++ b/src/tests/maxima/fitnessfunctioneq.cpp | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #include "fitnessfunctioneq.h" | ||
| 2 | #include "genetic/phenotypebinary.h" | ||
| 3 | |||
| 4 | FitnessFunctionEq::FitnessFunctionEq() | ||
| 5 | { | ||
| 6 | } | ||
| 7 | |||
| 8 | FitnessFunctionEq::~FitnessFunctionEq() | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | double FitnessFunctionEq::operator()( Genetic::Phenotype *pTest ) | ||
| 13 | { | ||
| 14 | Genetic::PhenotypeBinary *pbTest = | ||
| 15 | dynamic_cast<Genetic::PhenotypeBinary *>( pTest ); | ||
| 16 | if( pbTest == NULL ) | ||
| 17 | return 0.0; | ||
| 18 | |||
| 19 | uint32_t uRaw; | ||
| 20 | pbTest->extractBits( uRaw, 0, 32 ); | ||
| 21 | double x = ((double)uRaw / (double)(0xfffffffful))*5.0 - 2.5; | ||
| 22 | |||
| 23 | return -1.8*(x*x*x*x) + 0.86*(x*x*x) + 4.0*(x*x); | ||
| 24 | } | ||
| 25 | |||
