paradiseo/test/eo/t-eoRoulette.cpp
Adèle Harrissart 490e837f7a * New tree configuration of the project:
.../
   ...           + -- EO
   |             |
   |             |
   +-- src ----- + -- EDO
   |             |
   |             |
   +-- test      + -- MO
   |             |
   |             |
   +-- tutorial  + -- MOEO
   |             |
   |             |
   +-- doc       + -- SMP
   |             |
   |             |
   ...           + -- EOMPI
                 |
                 |
                 + -- EOSERIAL

Question for current maintainers: ./README: new release?

Also:

* Moving out eompi & eoserial modules (issue #2).

* Correction of the errors when executing "make doc" command.

* Adding a solution for the conflicting headers problem (see the two CMake Cache
 Values: PROJECT_TAG & PROJECT_HRS_INSTALL_SUBPATH) (issue #1)

* Header inclusions:
        ** src: changing absolute paths into relative paths ('#include <...>' -> '#include "..."')
        ** test, tutorial: changing relative paths into absolute paths ('#include "..."' -> '#include <...>')

* Moving out some scripts from EDO -> to the root

* Add a new script for compilation and installation (see build_gcc_linux_install)

* Compilation with uBLAS library or EDO module: now ok

* Minor modifications on README & INSTALL files

* Comment eompi failed tests with no end

*** TODO: CPack (debian (DEB) & RedHat (RPM) packages) (issues #6 & #7) ***
2014-09-06 13:04:35 +02:00

66 lines
1.3 KiB
C++
Executable file

#include <paradiseo/eo/eoPop.h>
#include <paradiseo/eo/EO.h>
#include <paradiseo/eo/eoProportionalSelect.h>
#include <paradiseo/eo/eoStochasticUniversalSelect.h>
class TestEO : public EO<double> { public: unsigned index; };
using namespace std;
template <class Select>
int test_select()
{
vector<double> probs(4);
probs[0] = 0.1;
probs[1] = 0.4;
probs[2] = 0.2;
probs[3] = 0.3;
vector<double> counts(4,0.0);
// setup population
eoPop<TestEO> pop;
for (unsigned i = 0; i < probs.size(); ++i)
{
pop.push_back( TestEO());
pop.back().fitness( probs[i] * 2.1232 ); // some number to check scaling
pop.back().index = i;
}
Select select;
unsigned ndraws = 10000;
for (unsigned i = 0; i < ndraws; ++i)
{
const TestEO& eo = select(pop);
counts[eo.index]++;
}
cout << "Threshold = " << 1./sqrt(double(ndraws)) << endl;
for (unsigned i = 0; i < 4; ++i)
{
cout << counts[i]/ndraws << ' ';
double c = counts[i]/ndraws;
if (fabs(c - probs[i]) > 1./sqrt((double)ndraws)) {
cout << "ERROR" << endl;
return 1;
}
}
cout << endl;
return 0;
}
int main()
{
rng.reseed(44);
if (test_select<eoProportionalSelect<TestEO> >()) return 1;
return test_select<eoStochasticUniversalSelect<TestEO> >();
}