freESPlusSelection.txx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freESPlusSelection.txx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef _freESPlusSelection_txx
00023 #define _freESPlusSelection_txx
00024 
00025 #include "freESPlusSelection.h"
00026 
00027 namespace FREE
00028 {
00029   namespace ES
00030   {
00031 
00032     template <class TIndividual>
00033     PlusSelection<TIndividual>
00034       ::PlusSelection()
00035     {
00036     }
00037 
00038     template <class TIndividual>
00039     typename PlusSelection<TIndividual>::PopulationPointer
00040     PlusSelection<TIndividual>
00041     ::Select(PopulationType* pPopulation, PopulationSizeType newSize) const
00042     {
00043       if (!pPopulation) throwExceptionMacro("Error. Passed population is NULL.");
00044       if (pPopulation->Size()<newSize) throwExceptionMacro("Error. Passed population is already smaller the prefered size, nothing to select. Population size: "<<pPopulation->Size()<<"; new size: "<<newSize);
00045 
00046       PopulationPointer removedPopulation = PopulationType::New();
00047 
00048       while (pPopulation->Size()>newSize)
00049       {
00050         typename IndividualType::ObjectiveValueType worstValue = ((*pPopulation)[0])->GetObjectiveValue();
00051         unsigned long worstIndex = 0;
00052 
00053         for (unsigned long index = 1; index < pPopulation->Size(); index++)
00054         { //find worst individual
00055           if (this->GetMaximumIsBest())
00056           {
00057             if (worstValue>((*pPopulation)[index])->GetObjectiveValue())
00058             {
00059               worstValue = ((*pPopulation)[index])->GetObjectiveValue();
00060               worstIndex = index;
00061             }
00062           }
00063           else
00064           {
00065             if (worstValue<((*pPopulation)[index])->GetObjectiveValue())
00066             {
00067               worstValue = ((*pPopulation)[index])->GetObjectiveValue();
00068               worstIndex = index;
00069             }
00070           }
00071         }
00072         //remove worst individual and add it to the population of removed individuals
00073         removedPopulation->push_back((*pPopulation)[worstIndex]);
00074         pPopulation->erase(pPopulation->begin()+worstIndex);
00075       }
00076 
00077       return removedPopulation;
00078     };
00079 
00080   } // end of namespace ES
00081 } // end of namespace FREE
00082 
00083 #endif

Generated at Sat Oct 13 15:53:44 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000