summaryrefslogtreecommitdiff
path: root/src/tests/maxima/fitnessfunctioneq.cpp
blob: c64e87abcfd6ff73329661752eec359aae01ac3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "fitnessfunctioneq.h"
#include "genetic/phenotypebinary.h"

FitnessFunctionEq::FitnessFunctionEq()
{
}

FitnessFunctionEq::~FitnessFunctionEq()
{
}

double FitnessFunctionEq::operator()( Genetic::Phenotype *pTest )
{
	Genetic::PhenotypeBinary *pbTest =
		dynamic_cast<Genetic::PhenotypeBinary *>( pTest );
	if( pbTest == NULL )
		return 0.0;

	uint32_t uRaw;
	pbTest->extractBits( uRaw, 0, 32 );
	double x = ((double)uRaw / (double)(0xfffffffful))*5.0 - 2.5;

	return -1.8*(x*x*x*x) + 0.86*(x*x*x) + 4.0*(x*x);
}

Genetic::FitnessFunction *FitnessFunctionEq::clone() const
{
	return new FitnessFunctionEq();
}