freESRandomMultiParentSelector.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: freESRandomMultiParentSelector.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 _freESRandomMultiParentSelector_txx
00023 #define _freESRandomMultiParentSelector_txx
00024 
00025 #include "freESRandomMultiParentSelector.h"
00026 
00027 #include <time.h>
00028 
00029 namespace FREE
00030 {
00031   namespace ES
00032   {
00033 
00034     template <class TIndividual>
00035     RandomMultiParentSelector<TIndividual>
00036       ::RandomMultiParentSelector()
00037     {
00038       m_RandomGenerator = VariateGeneratorType::New();
00039       m_RandomGenerator->Initialize((int)clock());
00040       m_AllowRedraw = true;
00041       m_NumberOfSelections = 1;
00042     }
00043 
00044     template <class TIndividual>
00045     typename RandomMultiParentSelector<TIndividual>::ParentSelectionType
00046       RandomMultiParentSelector<TIndividual>
00047       ::Select(const PopulationType& population) const
00048     {
00049       if (!m_AllowRedraw && (population.size()<m_NumberOfSelections)) throwExceptionMacro("Error. No redrawing allowed, but size of population is smaller the number of draws. Population size: "<<population.size()<<"; number of draws: "<<m_NumberOfSelections);
00050 
00051       //create index pool to draw from
00052       typedef typename PopulationType::ElementIdentifier PopulationElementIdentifier;
00053       typedef std::vector<PopulationElementIdentifier> IdentifierListType;
00054       IdentifierListType indexPool;
00055       IdentifierListType selection;
00056 
00057       for (PopulationElementIdentifier index = 0; index<population.size(); indexPool.push_back(index++));
00058 
00059       //draw
00060       for (unsigned int count = 0; count<m_NumberOfSelections; count++)
00061       {
00062         VariateGeneratorType::IntegerType selectedIndex = m_RandomGenerator->GetIntegerVariate(indexPool.size()-1);
00063         selection.push_back(indexPool[selectedIndex]);
00064         if (!m_AllowRedraw)
00065         { //remove selected index from pool
00066           indexPool.erase(indexPool.begin()+selectedIndex);
00067         }
00068       }
00069 
00070       ParentSelectionType selectedIndividuals;
00071       
00072       for (typename IdentifierListType::const_iterator pos = selection.begin(); pos!=selection.end(); pos++)
00073       {
00074         selectedIndividuals.push_back(population.ElementAt(*pos));
00075       }
00076 
00077       return selectedIndividuals;
00078     }
00079 
00080   } // end of namespace ES
00081 } // end of namespace FREE
00082 
00083 #endif

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