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

Golinski.cpp

Go to the documentation of this file.
00001 
00010 #include <Golinski.h>
00011 
00015 Golinski::Golinski(VariableType variableType) {
00016   problemName_ = "Golinski" ;
00017 
00018   numberOfVariables_   = 7 ;
00019   numberOfFunctions_   = 2 ;
00020   numberOfConstraints_ = 11 ;
00021 
00022   const double upperLimit[] = {3.6, 0.8, 28.0, 8.3, 8.3, 3.9, 5.5} ;
00023   const double lowerLimit[] = {2.6, 0.7, 17.0, 7.3, 7.3, 2.9, 5.0} ;
00024   const int partitions[]    = {30, 30, 30, 30, 30, 30, 30} ;
00025   const int precision[]     = {5, 5, 5, 5, 5, 5, 5} ;
00026 
00027   upperLimit_      = new double[numberOfVariables_] ;
00028   lowerLimit_      = new double[numberOfVariables_] ;
00029   partitions_      = new int[numberOfVariables_]    ;
00030   precision_       = new int[numberOfVariables_]    ;
00031   bitsPerVariable_ = new int[numberOfVariables_]    ;
00032   
00033   memcpy(upperLimit_, upperLimit, numberOfVariables_ * sizeof(double)) ;
00034   memcpy(lowerLimit_, lowerLimit, numberOfVariables_ * sizeof(double)) ;
00035   memcpy(partitions_, partitions_, numberOfVariables_ * sizeof(int)) ;
00036   memcpy(precision_, precision, numberOfVariables_ * sizeof(int)) ;
00037 
00038   variable_ = new VariableType[numberOfVariables_] ;
00039 
00040   initializeRealVariableType(variableType) ;
00041   cout << "Created a " << problemName_ << " problem" << endl ;
00042 
00043 } // Golinski::Golinski
00044 
00045 
00046 void Golinski::evaluate(Individual * individual) {
00047   double x[7] ;
00048 
00049   x[0] = (individual->chromosome_->gene_[0])->getRealAllele() ;
00050   x[1] = (individual->chromosome_->gene_[1])->getRealAllele() ;
00051   x[2] = (individual->chromosome_->gene_[2])->getRealAllele() ;
00052   x[3] = (individual->chromosome_->gene_[3])->getRealAllele() ;
00053   x[4] = (individual->chromosome_->gene_[4])->getRealAllele() ;
00054   x[5] = (individual->chromosome_->gene_[5])->getRealAllele() ;
00055   x[6] = (individual->chromosome_->gene_[6])->getRealAllele() ;
00056   
00057   // First function
00058   individual->fitness_[0] = 0.7854 * x[0]*x[1]*x[1]*(10*x[2]*x[2]/3 + 
00059                                      14.933*x[2]-43.0934) -
00060                                      1.508*x[0]*(x[5]*x[5]+x[6]*x[6]) +
00061                                      7.477*(x[5]*x[5]*x[5] + x[6]*x[6]*x[6]) +
00062                                      0.7854*(x[3]*x[5]*x[5] + x[4]*x[6]*x[6]) ;
00063 
00064   // Second function
00065   double aux = 745.0 * x[3] / (x[1] * x[2]) ; 
00066   individual->fitness_[1] = sqrt((aux*aux + 1.69e7)) / (0.1*x[5]*x[5]*x[5]) ;
00067 } // Golinski::evaluate
00068 
00069 
00070 bool Golinski::constraintsAreSatisfied(Individual * individual) {
00071   double x[7]      ;
00072   bool   result    ;
00073   double aux       ;
00074   double function2 ;
00075 
00076   x[0] = (individual->chromosome_->gene_[0])->getRealAllele() ;
00077   x[1] = (individual->chromosome_->gene_[1])->getRealAllele() ;
00078   x[2] = (individual->chromosome_->gene_[2])->getRealAllele() ;
00079   x[3] = (individual->chromosome_->gene_[3])->getRealAllele() ;
00080   x[4] = (individual->chromosome_->gene_[4])->getRealAllele() ;
00081   x[5] = (individual->chromosome_->gene_[5])->getRealAllele() ;
00082   x[6] = (individual->chromosome_->gene_[6])->getRealAllele() ;
00083 
00084   aux = 745.0 * x[3] / (x[1] * x[2]) ; 
00085   function2 = sqrt((aux*aux + 1.69e7)) / (0.1*x[5]*x[5]*x[5]) ;
00086 
00087   result = false ;
00088   if (0 >= ((1.0/(x[0]*x[1]*x[1]*x[2])) - 1.0/27.0))       // g1
00089   if (0 >= ((1.0/(x[0]*x[1]*x[1]*x[2]*x[2])) - 1.0/397.5)) // g2
00090   if (0 >= (x[3]*x[3]*x[3]/(x[1]*x[2]*x[5]*x[5]*x[5]*x[5]) - 1.0/1.93))  // g3
00091   if (0 >= (x[4]*x[4]*x[4]/(x[1]*x[2]*x[6]*x[6]*x[6]*x[6]) - 1.0/1.93))  // g4
00092   if (0 >= (x[1]*x[2] - 40.0))                              // g5
00093   if (0 >= (x[0]/x[1] - 12.0))                              // g6
00094   if (0 >= (5.0 - x[0]/x[1]))                               // g7
00095   if (0 >= (1.9 - x[3] + 1.5*x[5]))                         // g8
00096   if (0 >= (1.9 - x[4] + 1.1*x[6]))                         // g9
00097   if (1300 >= function2)                                       // g10
00098   if (1100 >= (sqrt((745*x[4]/(x[1]*x[2]))*(745*x[4]/(x[1]*x[2]))+1.575e8)/
00099                (.1*x[6]*x[6]*x[6])))                       // g11
00100     result = true  ;
00101     
00102   return result ;
00103 } // Golinski::constraintsAreSafisfied
00104 
00105 int Golinski::numberOfNonSatisfiedConstraints(Individual * individual) {
00106   int    counter   ;
00107   double x[7]      ;
00108   double aux       ;
00109   double function2 ;
00110   
00111   x[0] = (individual->chromosome_->gene_[0])->getRealAllele() ;
00112   x[1] = (individual->chromosome_->gene_[1])->getRealAllele() ;
00113   x[2] = (individual->chromosome_->gene_[2])->getRealAllele() ;
00114   x[3] = (individual->chromosome_->gene_[3])->getRealAllele() ;
00115   x[4] = (individual->chromosome_->gene_[4])->getRealAllele() ;
00116   x[5] = (individual->chromosome_->gene_[5])->getRealAllele() ;
00117   x[6] = (individual->chromosome_->gene_[6])->getRealAllele() ; 
00118 
00119   aux = 745.0 * x[3] / (x[1] * x[2]) ; 
00120   function2 = sqrt((aux*aux + 1.69e7)) / (0.1*x[5]*x[5]*x[5]) ;
00121 
00122   counter = 0 ;  
00123   if (0 < ((1.0/(x[0]*x[1]*x[1]*x[2])) - 1.0/27.0))       // g1
00124     counter ++ ;
00125   if (0 < ((1.0/(x[0]*x[1]*x[1]*x[2]*x[2])) - 1.0/397.5)) // g2
00126     counter ++ ;
00127   if (0 < (x[3]*x[3]*x[3]/(x[1]*x[2]*x[5]*x[5]*x[5]*x[5]) - 1.0/1.93))  // g3
00128     counter ++ ;
00129   if (0 < (x[4]*x[4]*x[4]/(x[1]*x[2]*x[6]*x[6]*x[6]*x[6]) - 1.0/1.93))  // g4
00130     counter ++ ;
00131   if (0 < (x[1]*x[2] - 40.0))                              // g5
00132     counter ++ ;
00133   if (0 < (x[0]/x[1] - 12.0))                              // g6
00134     counter ++ ;
00135   if (0 < (5.0 - x[0]/x[1]))                               // g7
00136     counter ++ ;
00137   if (0 < (1.9 - x[3] + 1.5*x[5]))                         // g8
00138     counter ++ ;
00139   if (0 < (1.9 - x[4] + 1.1*x[6]))                         // g9
00140     counter ++ ;
00141   if (1300 < function2)                                       // g10
00142     counter ++ ;
00143   if (1100 < (sqrt((745*x[4]/(x[1]*x[2]))*(745*x[4]/(x[1]*x[2]))+1.575e8)/
00144                (.1*x[6]*x[6]*x[6])))                       // g11
00145     counter ++ ;
00146 
00147   return counter ;  
00148 } // Golinski::numberOfNonSatisfiedConstraints
00149 
00150 

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