00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _freESDominantRecombinator_txx
00023 #define _freESDominantRecombinator_txx
00024
00025 #include "freESDominantRecombinator.h"
00026
00027 namespace FREE
00028 {
00029 namespace ES
00030 {
00031
00032
00033 template <class TIndividual>
00034 DominantRecombinator<TIndividual>
00035 ::DominantRecombinator()
00036 {
00037 m_RandomGenerator = VariateGeneratorType::New();
00038 m_RandomGenerator->Initialize((int)clock());
00039 }
00040
00041 template <class TIndividual>
00042 typename DominantRecombinator<TIndividual>::IndividualPointer
00043 DominantRecombinator<TIndividual>
00044 ::Recombine(const ParentSelectionType& parents) const
00045 {
00046 if (!(parents.size()>0)) throwExceptionMacro("Error. At least one parent is needed for recombination.");
00047
00048 IndividualPointer newIndividual = parents[0]->Clone();
00049
00050 for (unsigned int index = 0; index<newIndividual->ObjectiveParameters().size(); index++)
00051 {
00052 VariateGeneratorType::IntegerType parentIndex = m_RandomGenerator->GetIntegerVariate(parents.size()-1);
00053 (newIndividual->ObjectiveParameters())[index] = (parents[parentIndex]->ObjectiveParameters())[index];
00054 }
00055
00056 for (unsigned int index = 0; index<newIndividual->StrategicParameters().size(); index++)
00057 {
00058 if ( newIndividual->StrategicParameters().at(index)->GetHandling()!= IndividualType::StrategicParameterType::HDynamic)
00059 {
00060 VariateGeneratorType::IntegerType parentIndex = m_RandomGenerator->GetIntegerVariate(parents.size()-1);
00061 (newIndividual->StrategicParameters())[index] = (parents[parentIndex]->StrategicParameters())[index];
00062 }
00063 }
00064 return newIndividual;
00065 }
00066
00067 template <class TIndividual>
00068 typename DominantRecombinator<TIndividual>::WeightVectorType
00069 DominantRecombinator<TIndividual>
00070 ::GetWeights(const unsigned long lParentCount) const
00071 {
00072 WeightVectorType weights;
00073 weights.resize(lParentCount,0.0);
00074 if (lParentCount) weights[0] = 1.0;
00075 return weights;
00076 };
00077
00078 }
00079 }
00080
00081 #endif