00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 {
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 {
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 }
00101 }
00102
00103 #endif