GeneralPropagation.cpp
Go to the documentation of this file.00001 #include "GeneralPropagation.h"
00002
00003 namespace gplib
00004 {
00005 GeneralPropagation::GeneralPropagation(GeneralSelect* const LocalSelect,
00006 GeneralPopulation* const LocalPopulation, GeneralRNG* const LocalRandom) :
00007 Select(LocalSelect), Population(LocalPopulation), Random(LocalRandom)
00008 {
00009 MutationProb = 0.001;
00010 CrossoverProb = 0.5;
00011 }
00012
00013 GeneralPropagation::GeneralPropagation(GeneralPropagation &Old) :
00014 Select(Old.Select), Population(Old.Population), Random(Old.Random)
00015 {
00016 MutationProb = Old.MutationProb;
00017 CrossoverProb = Old.CrossoverProb;
00018 }
00019
00020 GeneralPropagation::~GeneralPropagation()
00021 {
00022
00023 }
00024
00025 void GeneralPropagation::Crossover(tpopmember &father, tpopmember &mother)
00026 {
00027 if (Random->GetNumber() < CrossoverProb)
00028 {
00029 tpopmember tempstore(father);
00030 int crosspoint = Random->GetNumber(father.size() - 2) + 1;
00031
00032 copy(mother.begin() + crosspoint, mother.end(), father.begin()
00033 + crosspoint);
00034 copy(tempstore.begin() + crosspoint, tempstore.end(),
00035 mother.begin() + crosspoint);
00036 }
00037 }
00038
00039 void GeneralPropagation::Mutation(tpopmember &child)
00040 {
00041 for (unsigned int i = 0; i < child.size(); ++i)
00042 {
00043 if (Random->GetNumber() < MutationProb)
00044 {
00045 child(i) = !(child(i));
00046 }
00047
00048 }
00049 }
00050 }