paradiseo/test/eo/t-eoInitPermutation.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

68 lines
1.8 KiB
C++
Executable file

//-----------------------------------------------------------------------------
// t-eoInitPermutation.cpp
//-----------------------------------------------------------------------------
#include <paradiseo/eo.h>
#include <paradiseo/eo/eoInt.h>
//-----------------------------------------------------------------------------
typedef eoInt<double> Chrom;
//-----------------------------------------------------------------------------
double real_value(const Chrom & _chrom)
{
double sum = 0;
for (unsigned i = 0; i < _chrom.size(); i++)
sum += _chrom[i];
return sum/_chrom.size();
}
// Return true if the given chromosome corresponds to a permutation
// There must be an nicer way to do it (set?) ...
bool check_permutation(const Chrom & _chrom)
{
for (unsigned i = 0; i < _chrom.size(); ++i)
for (unsigned j = 0; j < _chrom.size(); ++j)
if(i!=j)
if(_chrom[i]==_chrom[j]){
std::cout << " Error: Wrong permutation !" << std::endl;
std::string s;
s.append( " Wrong permutation in t-eoInitPermutation");
throw std::runtime_error( s );
}
return true;
}
int main()
{
const unsigned POP_SIZE = 8, CHROM_SIZE = 16;
unsigned i;
// a chromosome randomizer
eoInitPermutation <Chrom> random(CHROM_SIZE);
// the population:
eoPop<Chrom> pop;
// Evaluation
eoEvalFuncPtr<Chrom> eval( real_value );
for (i = 0; i < POP_SIZE; ++i)
{
Chrom chrom(CHROM_SIZE);
std::cout << " Initial chromosome n°" << i << " : " << chrom << "..." << std::endl;
random(chrom);
eval(chrom);
std::cout << " ... becomes : " << chrom << " after initialization" << std::endl;
check_permutation(chrom);
pop.push_back(chrom);
}
return 0;
}
//-----------------------------------------------------------------------------