adding examples for eoBin & other stuff
This commit is contained in:
parent
50062e7c30
commit
0f4ff4691c
10 changed files with 1306 additions and 0 deletions
52
eo/test/t-eoproblem.cpp
Normal file
52
eo/test/t-eoproblem.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eoproblem.cpp
|
||||
// (c) GeNeura Team 1998
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <time.h> // time
|
||||
#include <math.h> // fabs
|
||||
#include <iostream> // cout
|
||||
#include <eo> // eoVector, eoProblem
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoVector<float, float> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ostream& operator<<(ostream& os, const Chrom& chrom)
|
||||
{
|
||||
copy(chrom.begin(), chrom.end(), ostream_iterator<int>(os));
|
||||
return os;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class Easy//: public eoProblem<Chrom>
|
||||
{
|
||||
public:
|
||||
const size = 1;
|
||||
|
||||
float operator()(const Chrom& chrom)
|
||||
{
|
||||
return 1.0 / (fabs(chrom[0]) + 1.0);
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
main()
|
||||
{
|
||||
Easy easy;
|
||||
Chrom chrom(Easy::size);
|
||||
|
||||
srand(time(0));
|
||||
|
||||
chrom[0] = ((float)rand()) / ((float)RAND_MAX);
|
||||
chrom.fitness(easy(chrom));
|
||||
|
||||
cout << "chrom = " << chrom << endl
|
||||
<< "chrom.fitness() = " << chrom.fitness() << endl;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Reference in a new issue