freESIntermediateRecombinator.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: freESIntermediateRecombinator.h,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 _freESIntermediateRecombinator_txx
00023 #define _freESIntermediateRecombinator_txx
00024 
00025 #include "freESIntermediateRecombinator.h"
00026 
00027 namespace FREE
00028 {
00029   namespace ES
00030   {
00031 
00032 
00033     template <class TIndividual>
00034     IntermediateRecombinator<TIndividual>
00035       ::IntermediateRecombinator()
00036     {
00037     }
00038 
00039     template <class TIndividual>
00040     typename IntermediateRecombinator<TIndividual>::IndividualPointer
00041       IntermediateRecombinator<TIndividual>
00042       ::Recombine(const ParentSelectionType& parents) const
00043     {
00044       if (!(parents.size()>0)) throwExceptionMacro("Error. At least one parent is needed for recombination.");
00045 
00046       IndividualPointer newIndividual = parents[0]->Clone();
00047 
00048       for (unsigned int index = 0; index<newIndividual->ObjectiveParameters().size(); index++)
00049       { //objective parameter
00050         try
00051         {
00052           typename IndividualType::ObjectiveParameterType newValue = 0;
00053           for (unsigned int count = 0; count<parents.size(); count++)
00054           {
00055             newValue += (parents[count]->ObjectiveParameters())[index];
00056           }
00057           newValue /= parents.size();
00058 
00059           (newIndividual->ObjectiveParameters())[index] = newValue;
00060         }
00061         catchAllNPassMacro("Error while recombining objectiv parameter #"+Convert::ToStr(index)+".");
00062 
00063       }
00064 
00065       for (unsigned int index = 0; index<newIndividual->StrategicParameters().size(); index++)
00066       { //strategic parameter
00067         if ( newIndividual->StrategicParameters().at(index)->GetHandling()!= IndividualType::StrategicParameterType::HDynamic)
00068         {
00069           try
00070           {
00071             typename IndividualType::StrategicParameterType::ParameterValueType newValue = 0;
00072             for (unsigned int count = 0; count<parents.size(); count++)
00073             {
00074               newValue += ((parents[count]->StrategicParameters())[index])->GetValue();
00075             }
00076             newValue /= parents.size();
00077 
00078             ((newIndividual->StrategicParameters())[index])->SetValue(newValue);
00079           }
00080           catchAllNPassMacro("Error while recombining strategic parameter #"+Convert::ToStr(index)+".");
00081         }
00082       }
00083 
00084       return newIndividual;
00085     }
00086 
00087     template <class TIndividual>
00088     typename IntermediateRecombinator<TIndividual>::WeightVectorType
00089     IntermediateRecombinator<TIndividual>
00090     ::GetWeights(const unsigned long lParentCount) const
00091     {
00092       WeightVectorType weights;
00093       if (lParentCount)
00094       {
00095         weights.resize(lParentCount,1.0/lParentCount);
00096       }
00097       return weights;
00098     };
00099 
00100   } // end of namespace ES
00101 } // end of namespace FREE
00102 
00103 #endif

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