Go to the documentation of this file.00001 #include "RobustLHSR.h"
00002
00003
00004
00005
00006
00007
00008 virtual ~RobustLHSR()
00009 {
00010 unsigned size = archive.size();
00011 for (unsigned i = 0; i < size; i++)
00012 delete archive[i];
00013 }
00014
00015 void RobustLHSR::updateTotalGen(unsigned& totalGen, unsigned currGen, unsigned evaluations, unsigned lambda)
00016 {
00017 totalGen = currGen + (evaluations - evalsUsed) / (lambda * sampleSetSize);
00018 }
00019
00020
00021
00022
00023
00024
00025 void RobustLHSR::robustSimulate(Individual* I, int* xnom, int numVar)
00026 {
00027 #ifdef DEBUG
00028 cout << "RobustLHSR::robustSimulate()" << endl;
00029 #endif
00030
00031 vector<double>* F = getF();
00032 if (numF == 0)
00033 numF = F->size();
00034
00035
00036 archiveSelection(I, xnom, numVar);
00037
00038
00039 Individual tmpI;
00040 unsigned size = candidates.size();
00041 for (unsigned i = 0; i < size; i++)
00042 {
00043
00044 tmpI->D = candidates[i]->D;
00045 simulate(tmpI, NULL, numVar, NULL);
00046 evalsUsed++;
00047
00048
00049 selectedArchiveTuples.push_back(archive.size());
00050 archive.push_back(new ArchiveTuple((*candidates[i]), F));
00051 }
00052
00053
00054 vector<double> F_eff(numF, 0);
00055 double weight, totalWeight = 0;
00056 for (unsigned i = 0; i < sampleSetSize; i++)
00057 {
00058
00059 weight = weightD(archive[selectedArchiveTuples[i]]->D, I, xnom);
00060 totalWeight += weight;
00061
00062 for (int j = 0; j < numF; j++)
00063 F_eff[j] += weight * archive[selectedArchiveTuples[i]]->F[j];
00064 }
00065
00066 for (int j = 0; j < numF; j++)
00067 F->at(j) = F_eff[j] /= totalWeight;
00068
00069 if (I != NULL)
00070 I->F = F_eff;
00071
00072 cleanupAfterSim();
00073 }
00074
00075
00076 void RobustLHSR::archiveSelection(Individual* I, int* xnom, int numVar)
00077 {
00078
00079 LHS(I, xnom, numVar);
00080
00081
00082 unsigned archiveIndex;
00083 for (unsigned refSetIndex = 0; refSetIndex < sampleSetSize; refSetIndex++)
00084 {
00085
00086 archiveIndex = getClosestArchiveTuple(refSetIndex);
00087
00088
00089 if (noCloserRefPoint(refSetIndex, archiveIndex))
00090 selectedArchiveTuples.push_back(archiveIndex);
00091 else
00092 candidates.push_back(referenceSet[refSetIndex]);
00093 }
00094 }
00095
00096
00097
00098
00099 void RobustLHSR::LHS(Individual* I, int* xnom, int numVar)
00100 {
00101
00102 }
00103
00104
00105 unsigned RobustLHSR::getClosestArchiveTuple(unsigned refSetIndex)
00106 {
00107 unsigned size = archive.size();
00108 double distance, distanceClosest = -1;
00109 unsigned archiveIndexClosest;
00110 for (unsigned archiveIndex = 0; archiveIndex < size; archiveIndex++)
00111 {
00112 distance = EuclidianDistanceD(refSetIndex, archiveIndex);
00113 if (distance < distanceClosest || distanceClosest == -1)
00114 {
00115 archiveIndexClosest = archiveIndex;
00116 distanceClosest = distance;
00117 }
00118 }
00119
00120 return archiveIndexClosest;
00121 }
00122
00123
00124
00125
00126 double RobustLHSR::EuclidianDistanceD(unsigned refSetIndex, unsigned archiveIndex)
00127 {
00128 unsigned size = referenceSet[refSetIndex]->D->size();
00129 double distance = 0;
00130 for (unsigned i = 0; i < size; i++)
00131 distance += pow((double) (referenceSet[refSetIndex]->D[i] - archive[archiveIndex]->D[i]), 2);
00132
00133 return sqrt(distance);
00134 }
00135
00136
00137 bool RobustLHSR::noCloserRefPoint(refSetIndex, archiveIndex)
00138 {
00139 double distance = EuclidianDistanceD(refSetIndex, archiveIndex)
00140 for (unsigned i = 0; i < sampleSetSize; i++)
00141 {
00142 if (i == refSetIndex)
00143 continue;
00144
00145
00146 if (EuclidianDistanceD(i, archiveIndex) < distance)
00147 return false;
00148 }
00149
00150
00151 return true;
00152 }
00153
00154
00155 double RobustLHSR::weightD(vector<int>& D, Individual* I, int* xnom)
00156 {
00157
00158 }
00159
00160 void RobustLHSR::cleanupAfterSim()
00161 {
00162 int size = referenceSet.size();
00163 for (int i = 0; i < size; i++)
00164 delete referenceSet[i];
00165 referenceSet.clear();
00166
00167 selectedArchiveTuples.clear();
00168
00169 candidates.clear();
00170 }
00171
00172