• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

D:/LIACS/mies/SerialES/SMSEMOA_3D.cpp

Go to the documentation of this file.
00001 #include "SMSEMOA_3D.h"
00002 
00003 //------------------------------------------------------------------------------
00004 // Class SMSEMOA_3D
00005 //-------------------------------------------------
00006 // Public Members
00007 
00008 SMSEMOA_3D::SMSEMOA_3D(bool dpSelection_, bool steadyState_, unsigned n_f__)
00009 : NSGA_II(n_f__)
00010 { 
00011 #ifdef DEBUG
00012   cout << "SMSEMOA_3D::SMSEMOA_3D" << endl;
00013 #endif
00014 
00015   if (selectDimension != 3)
00016   {
00017     cerr << "Compiled with SMS-EMOA 3D selection, but selectDimension is " << selectDimension << "D! Exiting." << endl;
00018     exit(1);
00019   }
00020 
00021   for (int i = 0; i < 3; i++)
00022     reference[i] = 1.0000001; // Pre-normalized reference point, 1 + epsilon to make sure all points strictly dominate 
00023                               // the reference point, required by fpli_hv()
00024   dpSelection = dpSelection_;
00025   steadyState = steadyState_;
00026 }
00027 
00028 //------------------------------------------------------------------------------
00029 // Class SMSEMOA_3D
00030 //-------------------------------------------------
00031 // Protected Members
00032 
00033 /* Sort Individuals within same front: 3D hypervolume sorting (see Complexity of Hypervolume by Beume, 2007) */
00034 void SMSEMOA_3D::frontSort(vector<int>& currFront, vector<Individual*>& Q, vector<int>& direction)
00035 {
00036 #ifdef DEBUG
00037   cout << "SMSEMOA_3D::frontSort(), 3D hypervolume sorting" << endl;
00038 #endif
00039 
00040   int frontSize = currFront.size();
00041   normalize(currFront, frontSize, Q, direction); // Normalize to [0,1]->min using Ideal and Nadir points of currFront
00042 
00043   /* Prepare dataset to be fed to hv() using normalized F values in normF */
00044   double* data = new double[frontSize*3];
00045   for (int i = 0; i < frontSize; i++)
00046   { 
00047     for (int j = 0; j < 3; j++)
00048       data[3*i + j] = normF[currFront[i]][selectFunction[j]];
00049   }
00050 
00051   /* Determine hypervolume contribution for Individuals in currFront:
00052    * first determine total volume, then substract volume remaining after point has been removed */
00053   double frontVolume = fpli_hv(data, 3, frontSize, reference);
00054 
00055   map<int, double> volume;
00056   for (int i = 0; i < frontSize; i++) 
00057   {
00058     /* 'Remove' Individual i by setting its F values to the reference point values */     
00059     for (int j = 0; j < 3; j++)
00060     {
00061       data[3*i + j] = reference[j];
00062     }
00063 
00064     volume[currFront[i]] = frontVolume - fpli_hv(data, 3, frontSize, reference); 
00065 
00066     /* Restore F values of Individual i */          
00067     for (int j = 0; j < 3; j++)
00068       data[3*i + j] = normF[currFront[i]][selectFunction[j]];
00069   }
00070 
00071   delete [] data;
00072   data = NULL;
00073 
00074   /* Sort front index currFront on hypervolume, in descending order */
00075   if (steadyState) // In case of steady state SMS-EMOA only necessary to place worst individual at the last position in front
00076   {
00077     double worstValue = DBL_MAX;
00078     unsigned worstIndividual;
00079 
00080     for (int i = 0; i < frontSize; i++)
00081     {
00082       if (volume[currFront[i]] < worstValue)
00083       {
00084         worstValue = volume[currFront[i]];
00085         worstIndividual = i;
00086       }       
00087     }    
00088   
00089     unsigned temp = currFront[frontSize-1];
00090     currFront[frontSize-1] = currFront[worstIndividual];
00091     currFront[worstIndividual] = temp;
00092   }
00093   else
00094     quickSort(currFront, 0, frontSize-1, NULL, 0, &volume);
00095 }
00096 
00097 /* Normalize F values for Individuals in currFront to [0,1]->min, using Nadir and Ideal point */
00098 void SMSEMOA_3D::normalize(vector<int>& currFront, int frontSize, vector<Individual*>& Q, vector<int>& direction)
00099 {
00100 #ifdef DEBUG
00101   cout << "SMSEMOA_3D::normalize()" << endl;
00102 #endif
00103 
00104   determineNadirIdeal(currFront, frontSize, Q, direction);
00105 
00106   vector<double> scale(n_f_, 0);
00107   for (unsigned j = 0; j < selectDimension; j++)
00108     scale[selectFunction[j]] = nadir[selectFunction[j]] - ideal[selectFunction[j]]; 
00109 
00110   normF.clear();
00111 
00112   for (int i = 0; i < frontSize; i++)
00113   {
00114     vector<double> temp(selectDimension, 0);
00115 
00116     for (unsigned j = 0; j < selectDimension; j++)
00117     {
00118       if (scale[selectFunction[j]] != 0)              
00119         temp[j] = (Q[currFront[i]]->F[selectFunction[j]] - ideal[selectFunction[j]]) / scale[selectFunction[j]];
00120     }  
00121 
00122     normF[currFront[i]] = temp;
00123   }
00124 }
00125 

Generated on Tue Oct 4 2011 16:25:19 for WDN by  doxygen 1.7.2