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

Binh2.cpp

Go to the documentation of this file.
00001 
00010 #include <Binh2.h>
00011 
00012 
00016 Binh2::Binh2(VariableType variableType) {
00017 
00018   problemName_ = "Binh2-MOP-C1" ;
00019 
00020   numberOfVariables_   = 2 ;
00021   numberOfFunctions_   = 2 ;
00022   numberOfConstraints_ = 2 ;
00023 
00024   const double upperLimit[] = {30.0, 30.0} ;
00025   const double lowerLimit[] = {-15.0, -15.0} ;
00026   const int partitions[]    = {100, 100, 100} ;
00027   const int precision[]     = {5, 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 
00042   initializeRealVariableType(variableType) ;
00043   cout << "Created a " << problemName_ << " problem" << endl ;
00044 } // Binh2::Binh2
00045 
00046 
00047 void Binh2::evaluate(Individual * individual) {
00048   // First function
00049   double result ;
00050 
00051   result =  4 * (individual->chromosome_->gene_[0])->getRealAllele() *
00052                 (individual->chromosome_->gene_[0])->getRealAllele() +
00053             4 * (individual->chromosome_->gene_[1])->getRealAllele() *
00054                 (individual->chromosome_->gene_[1])->getRealAllele() ;
00055   individual->fitness_[0] = result ;
00056 
00057   // Second function
00058   result =  ((individual->chromosome_->gene_[0])->getRealAllele() - 5) *
00059             ((individual->chromosome_->gene_[0])->getRealAllele() - 5) +
00060             ((individual->chromosome_->gene_[1])->getRealAllele() - 5) *
00061             ((individual->chromosome_->gene_[1])->getRealAllele() - 5) ;
00062 
00063   individual->fitness_[1] = result ;
00064 } // Bihn2::evaluate
00065 
00066 
00067 bool Binh2::constraintsAreSatisfied(Individual * individual) {
00068   double x[2]   ;
00069   bool   result ; 
00070   
00071   x[0] = (individual->chromosome_->gene_[0])->getRealAllele() ;
00072   x[1] = (individual->chromosome_->gene_[1])->getRealAllele() ;
00073     
00074   result = false ;
00075 
00076   if (0 >= ((x[0]-5)*(x[0]-5) + x[1]*x[1] - 25))
00077     if (0 >= (-((x[0]-8)*(x[0]-8)) - (x[1]+3)*(x[1]+3)+7.7))
00078       result = true ;
00079 
00080   return result ;    
00081 } // Binh2::constraintsAreSafisfied
00082 
00083 int Binh2::numberOfNonSatisfiedConstraints(Individual * individual) {
00084   int    counter ;
00085   double x[2]    ;
00086  
00087   counter = 0 ;
00088   x[0] = (individual->chromosome_->gene_[0])->getRealAllele() ;
00089   x[1] = (individual->chromosome_->gene_[1])->getRealAllele() ;
00090   
00091   if (0 < ((x[0]-5)*(x[0]-5) + x[1]*x[1] - 25))
00092     counter ++ ;
00093   if (0 < (-((x[0]-8)*(x[0]-8)) - (x[1]+3)*(x[1]+3)+7.7))
00094     counter ++ ;
00095 
00096   return counter ;  
00097 } // Binh2::numberOfNonSatisfiedConstraints

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