00001 #include "NSGAII_Steady_MIES.h" 00002 00003 //------------------------------------------------------------------------------ 00004 // Class NSGAII_Steady_MIES 00005 //------------------------------------------------- 00006 // Protected Members 00007 00008 /* Create lambda offspring by mutation of a single (recombined) parent */ 00009 void NSGAII_Steady_MIES::recombineMutate() 00010 { 00011 #ifdef DEBUG 00012 cout << "NSGAII_Steady_MIES::recombineMutate()" << endl; 00013 #endif 00014 00015 MixedIntegerES::recombineMutateSingleParent(); 00016 } 00017 00018 /* Select mu Individuals from O and optionally P to form new population P */ 00019 void NSGAII_Steady_MIES::select() 00020 { 00021 #ifdef DEBUG 00022 cout << "NSGAII_Steady_MIES::select()" << endl; 00023 #endif 00024 00025 /* Select "best" offspring individual, is placed at position 0 in offspring vector O */ 00026 preSelect(); 00027 00028 NSGAII_MIES::select(); 00029 } 00030 00031 /* Select the "best" offspring Individual from the offspring pool of size lambda, using comparison score */ 00032 void NSGAII_Steady_MIES::preSelect() 00033 { 00034 #ifdef DEBUG 00035 cout << "NSGAII_Steady_MIES::preSelect()" << endl; 00036 #endif 00037 00038 /* Build pool for comparing offspring Individuals */ 00039 vector<Individual*> Q; 00040 for (unsigned i = (excludeParent) ? 1 : 0; i < mu; i++) 00041 Q.push_back(P[i]); 00042 for (unsigned i = 0; i < lambda; i++) 00043 Q.push_back(O[i]); 00044 00045 /* Calculate scores for comparing the offspring Individuals */ 00046 map<int, double> score; 00047 prepComparisonScore(Q); // Prepare for calculating comparison scores (if necessary) 00048 for (unsigned i = 0; i < lambda; i++) 00049 score[i] = calcComparisonScore(i); 00050 00051 vector<int> indices; // Indices of the lambda offspring Individuals in O 00052 for (unsigned i = 0; i < lambda; i++) 00053 indices.push_back(i); 00054 00055 /* Sort indices based on comparsison score, in descending order */ 00056 quickSort(indices, 0, lambda-1, NULL, -1, &score); 00057 00058 /* Move best offspring individual to position 0 in offspring vector O */ 00059 if (indices[0] != 0) 00060 { 00061 delete O[0]; 00062 O[0] = O[indices[0]]; 00063 O[indices[0]] = NULL; 00064 } 00065 00066 /* Cleanup rest of vector */ 00067 for (unsigned i = 1; i < lambda; i++) 00068 { 00069 delete O[i]; 00070 O[i] = NULL; 00071 } 00072 } 00073 00074