Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

Tanaka.cpp

Go to the documentation of this file.
00001 
00010 #include <Tanaka.h>
00011 
00017 Tanaka::Tanaka(VariableType variableType) {
00018   problemName_ = "Tanaka-MOP-C4" ;
00019 
00020   numberOfVariables_   = 2 ;
00021   numberOfFunctions_   = 2 ;
00022   numberOfConstraints_ = 2 ;
00023 
00024   const double upperLimit[] = {3.1416, 3.1416} ;
00025   const double lowerLimit[] = {10e-5, 10e-5} ;
00026   const int partitions[]    = {100, 100} ;
00027   const int precision[]     = {5, 5} ;
00028 
00029   upperLimit_      = new double[numberOfVariables_] ;
00030   lowerLimit_      = new double[numberOfVariables_] ;
00031   partitions_      = new int[numberOfVariables_]    ;
00032   precision_       = new int[numberOfVariables_]    ;
00033   bitsPerVariable_ = new int[numberOfVariables_]    ;
00034 
00035   memcpy(upperLimit_, upperLimit, numberOfVariables_ * sizeof(double)) ;
00036   memcpy(lowerLimit_, lowerLimit, numberOfVariables_ * sizeof(double)) ;
00037   memcpy(partitions_, partitions_, numberOfVariables_ * sizeof(int)) ;
00038   memcpy(precision_, precision, numberOfVariables_ * sizeof(int)) ;
00039 
00040   variable_ = new VariableType[numberOfVariables_] ;
00041   int i ;
00042 
00043   initializeRealVariableType(variableType) ;
00044   cout << "Created a " << problemName_ << " problem" << endl ;
00045 } // Constructor
00046 
00047 void Tanaka::evaluate(Individual * individual) {
00048   // First function
00049   individual->fitness_[0] =(individual->chromosome_->gene_[0])->getRealAllele();
00050 
00051   // Second function
00052   individual->fitness_[1] =(individual->chromosome_->gene_[1])->getRealAllele();
00053 
00054 } // Tanaka::evaluate
00055 
00056 
00057 const double a = 0.1  ; 
00058 const double b = 16.0 ; 
00059 
00060 bool Tanaka::constraintsAreSatisfied(Individual * individual) {
00061   double x[2];
00062   
00063   x[0] = (individual->chromosome_->gene_[0])->getRealAllele() ;
00064   x[1] = (individual->chromosome_->gene_[1])->getRealAllele() ;
00065   
00066   if ( ((x[0]*x[0]) + (x[1]*x[1])) >= (1.0 + a * cos(b * atan(x[1]/x[0])))) {
00067     if (0.5 >= ((x[0] - 0.5)*(x[0] - 0.5) + (x[1] - 0.5)*(x[1] - 0.5)))
00068       return true ;
00069     else
00070       return false ;
00071   }
00072   else
00073     return false ;
00074 } // Tanaka::constraintsAreSafisfied
00075 
00076 int Tanaka::numberOfNonSatisfiedConstraints(Individual * individual) {
00077   int    counter ;
00078   double x[2]    ;
00079 
00080   counter = 0 ;
00081   x[0] = (individual->chromosome_->gene_[0])->getRealAllele() ;
00082   x[1] = (individual->chromosome_->gene_[1])->getRealAllele() ;
00083  
00084   if (((x[0]*x[0]) + (x[1]*x[1])) < (1.0 + a * cos(b * atan(x[1]/x[0]))))
00085     counter ++ ;
00086   if (0.5 < ((x[0] - 0.5)*(x[0] - 0.5) + (x[1] - 0.5)*(x[1] - 0.5)))
00087     counter ++ ;
00088 
00089   return counter ;
00090 } // Tanaka::numberOfNonSatisfiedConstraints

Generated on Wed Feb 11 10:38:02 2004 for Paes by doxygen 1.3.3