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

RobustLHSR.cpp

Go to the documentation of this file.
00001 #include "RobustLHSR.h"
00002 
00003 //------------------------------------------------------------------------------
00004 // Class RobustMEM
00005 //-------------------------------------------------
00006 // Public Members
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 // Class RobustMEM
00022 //-------------------------------------------------
00023 // Protected Members
00024 
00025 void RobustLHSR::robustSimulate(Individual* I, int* xnom, int numVar) // FIXME: noise not on diameters, but on demands and pipe roughness coefficients
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   /* Approximate Latin Hypercube reference set by selecting suitable ArchiveTuples */ 
00036   archiveSelection(I, xnom, numVar);
00037 
00038   /* Evaluate candidate Points for extra sampling */
00039   Individual tmpI;        
00040   unsigned size = candidates.size();
00041   for (unsigned i = 0; i < size; i++)
00042   {
00043     /* Simulate using object variables in candidate Point */      
00044     tmpI->D = candidates[i]->D;
00045     simulate(tmpI, NULL, numVar, NULL);
00046     evalsUsed++;
00047     
00048     /* Add new ArchiveTuple to archive and 'assign' it to Point in reference set */
00049     selectedArchiveTuples.push_back(archive.size());
00050     archive.push_back(new ArchiveTuple((*candidates[i]), F));
00051   }
00052 
00053   /* Determine effective fitness */
00054   vector<double> F_eff(numF, 0);
00055   double weight, totalWeight = 0;
00056   for (unsigned i = 0; i < sampleSetSize; i++)
00057   {
00058     /* Retrieve probability of I->D (or xnom) being perturbed into archive[selectedArchiveTuples[i]]->D */        
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 /* Approximate Latin Hypercube reference set by selecting suitable ArchiveTuples */ 
00076 void RobustLHSR::archiveSelection(Individual* I, int* xnom, int numVar)
00077 {
00078   /* Generate Latin Hypercube reference set based on supplied object variables and Robust::noise() */   
00079   LHS(I, xnom, numVar);
00080 
00081   /* Determine the need for extra sampling per Point in the reference set */
00082   unsigned archiveIndex;
00083   for (unsigned refSetIndex = 0; refSetIndex < sampleSetSize; refSetIndex++)
00084   {
00085     /* Retrieve ArchiveTuple closest to Point refSetIndex in the reference set */
00086     archiveIndex = getClosestArchiveTuple(refSetIndex);
00087 
00088     /* Check that ArchiveTuple archiveIndex is not closer to another Point in the reference set */
00089     if (noCloserRefPoint(refSetIndex, archiveIndex))   // If check succeeds, 'assign' ArchiveTuple to Point 
00090       selectedArchiveTuples.push_back(archiveIndex);   // refSetIndex
00091     else                                               // Otherwise, add point refsetindex                                          
00092       candidates.push_back(referenceSet[refSetIndex]); // to candidates for extra sampling
00093   }
00094 }
00095 
00096 /* Generate Latin Hypercube reference set based on supplied object variables and stdInputNoise; 
00097  * for discrete nominal object variables 
00098  */     
00099 void RobustLHSR::LHS(Individual* I, int* xnom, int numVar) 
00100 {
00101   
00102 }
00103 
00104 /* Retrieve ArchiveTuple closest to Point refSetIndex in the reference set */
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 /* Calculate Euclidian distance between Point refSetIndex in the reference set and 
00124  * ArchiveTuple archiveIndex in the archive; for discrete nominal object variables
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 /* Check that ArchiveTuple archiveIndex is not closer to another Point in the reference set */
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     /* Closer Point found in reference set */
00146     if (EuclidianDistanceD(i, archiveIndex) < distance)
00147       return false;    
00148   }
00149 
00150   /* No closer Point found in reference set */
00151   return true;
00152 }
00153 
00154 /* Retrieve probability of I->D (or xnom) being perturbed into archive[selectedArchiveTuples[i]]->D */   
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 

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