Go to the documentation of this file.00001 #include "SMSEMOA_3D.h"
00002
00003
00004
00005
00006
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;
00023
00024 dpSelection = dpSelection_;
00025 steadyState = steadyState_;
00026 }
00027
00028
00029
00030
00031
00032
00033
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);
00042
00043
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
00052
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
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
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
00075 if (steadyState)
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
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