This repository has been archived on 2026-03-28. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
eodev/eo/test/t-eoproblem.cpp
1999-09-10 12:03:51 +00:00

52 lines
1.3 KiB
C++

//-----------------------------------------------------------------------------
// 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;
}
//-----------------------------------------------------------------------------