eoOneMaxEvalFunc.h

00001 
00006 /*
00007 Template for evaluator in EO, a functor that computes the fitness of an EO
00008 ==========================================================================
00009 */
00010  
00011 #ifndef _eoOneMaxEvalFunc_h
00012 #define _eoOneMaxEvalFunc_h
00013 
00014 // include whatever general include you need
00015 #include <stdexcept>
00016 #include <fstream>
00017 
00018 // include the base definition of eoEvalFunc
00019 #include "eoEvalFunc.h"
00020 
00025 template <class EOT>
00026 class eoOneMaxEvalFunc : public eoEvalFunc<EOT>
00027 {
00028 public:
00030 // START eventually add or modify the anyVariable argument
00031   eoOneMaxEvalFunc()
00032   //  eoOneMaxEvalFunc( varType  _anyVariable) : anyVariable(_anyVariable) 
00033 // END eventually add or modify the anyVariable argument
00034   {
00035     // START Code of Ctor of an eoOneMaxEvalFunc object
00036     // END   Code of Ctor of an eoOneMaxEvalFunc object
00037   }
00038 
00045   void operator()(EOT & _eo)
00046   {
00047     // test for invalid to avoid recomputing fitness of unmodified individuals
00048     if (_eo.invalid())
00049       {
00050         double fit;                // to hold fitness value
00051     // START Code of computation of fitness of the eoOneMax object
00052         const vector<bool> & b = _eo.B();
00053         fit = 0;
00054         for (unsigned i=0; i<b.size(); i++)
00055           fit += (b[i]?0:1);
00056     // END   Code of computation of fitness of the eoOneMax object
00057         _eo.fitness(fit);
00058       }
00059   }
00060 
00061 private:
00062 // START Private data of an eoOneMaxEvalFunc object
00063   //  varType anyVariable;                 // for example ...
00064 // END   Private data of an eoOneMaxEvalFunc object
00065 };
00066 
00067 
00068 #endif

Generated on Thu Apr 19 11:02:27 2007 for EO by  doxygen 1.4.7