t-eoproblem.cpp

00001 //-----------------------------------------------------------------------------
00002 // t-eoproblem.cpp
00003 // (c) GeNeura Team 1998
00004 //-----------------------------------------------------------------------------
00005 
00006 #include <time.h>    // time
00007 #include <math.h>    // fabs
00008 #include <iostream>  // std::cout
00009 #include <eo>        // eoVector, eoProblem
00010 
00011 //-----------------------------------------------------------------------------
00012 
00013 typedef eoVector<float, float> Chrom;
00014 
00015 //-----------------------------------------------------------------------------
00016 
00017 std::ostream& operator<<(std::ostream& os, const Chrom& chrom)
00018 {
00019   copy(chrom.begin(), chrom.end(), std::ostream_iterator<int>(os));
00020   return os;
00021 }
00022 
00023 //-----------------------------------------------------------------------------
00024 
00025 class Easy//: public eoProblem<Chrom>
00026 {
00027 public:
00028   static const unsigned size;
00029   
00030   float operator()(const Chrom& chrom)
00031     {
00032       return 1.0 / (fabs(chrom[0]) + 1.0);
00033     }
00034 };
00035 const unsigned Easy::size = 1;
00036 
00037 //-----------------------------------------------------------------------------
00038 
00039 int main()
00040 {
00041   Easy easy;
00042   Chrom chrom(Easy::size);
00043   
00044   srand(time(0));
00045   
00046   chrom[0] = ((float)rand()) / ((float)RAND_MAX);
00047   chrom.fitness(easy(chrom));
00048   
00049   std::cout << "chrom = " << chrom << std::endl
00050        << "chrom.fitness() = " << chrom.fitness() << std::endl;
00051 
00052   return 0;
00053 }
00054 
00055 //-----------------------------------------------------------------------------

Generated on Thu Oct 19 05:06:43 2006 for EO by  doxygen 1.3.9.1