From dab81d17c8c661d253bce52615f079b10f115a9c Mon Sep 17 00:00:00 2001 From: nojhan Date: Fri, 19 Nov 2010 21:08:18 +0100 Subject: [PATCH] test binary for dual fitness --- eo/test/t-eoDualFitness.cpp | 90 +++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 eo/test/t-eoDualFitness.cpp diff --git a/eo/test/t-eoDualFitness.cpp b/eo/test/t-eoDualFitness.cpp new file mode 100644 index 000000000..90b35ed7e --- /dev/null +++ b/eo/test/t-eoDualFitness.cpp @@ -0,0 +1,90 @@ + +#include + +#include +#include +#include + +typedef eoVector,double> DualVector; + +template +class DualSphere : public eoEvalFunc +{ +public: + virtual void operator()( EOT & x ) + { + if( x.invalid() ) { return; } + + double sum = 0; + int sign = 1; + for( unsigned int i=0, s=x.size(); i0 ? true : false ) ); + } +}; + + +double test( eoPop& pop, double target_value ) +{ + DualSphere eval; + + eoPopLoopEval pop_eval(eval); + + pop_eval(pop,pop); + + eoInterquartileRangeStat iqr_stat( std::make_pair(0.0,false), "IQR" ); + + iqr_stat( pop ); + + std::cout << iqr_stat.longName() << "=" << iqr_stat.value() << " should be " << target_value << std::endl; + + return iqr_stat.value().value(); +} + + +int main() +{ + eoPop pop; + + // fixed test + DualVector sol1(2,-1); + DualVector sol2(2,-1); + DualVector sol3(2,1); + DualVector sol4(2,1); + pop.push_back( sol1 ); + pop.push_back( sol2 ); + pop.push_back( sol3 ); + pop.push_back( sol4 ); + // on the sphere function everyone has the same fitness of 1 + if( test(pop, 0) != 0 ) { + exit(1); + } + + pop.erase(pop.begin(),pop.end()); + + // fixed test + sol1 = DualVector(2,0); + sol2 = DualVector(2,0); + sol3 = DualVector(2,1); + sol4 = DualVector(2,1); + pop.push_back( sol1 ); + pop.push_back( sol2 ); + pop.push_back( sol3 ); + pop.push_back( sol4 ); + if( test(pop, 1) != 1 ) { + exit(1); + } + + // test on a random normal distribution + eoNormalGenerator normal(1,rng); + eoInitFixedLength init_N(2, normal); + pop = eoPop( 1000000, init_N ); + double iqr = test(pop, 1.09); + if( iqr < 1.08 || iqr > 1.11 ) { + exit(1); + } +} +