GPLIB++
GeneralPropagation.cpp
Go to the documentation of this file.
1 #include "GeneralPropagation.h"
2 
3 namespace gplib
4  {
6  GeneralPopulation* const LocalPopulation, GeneralRNG* const LocalRandom) :
7  Select(LocalSelect), Population(LocalPopulation), Random(LocalRandom)
8  {
9  MutationProb = 0.001;
10  CrossoverProb = 0.5;
11  }
12 
14  Select(Old.Select), Population(Old.Population), Random(Old.Random)
15  {
18  }
19 
21  {
22 
23  }
24 
26  {
28  {
29  tpopmember tempstore(father);
30  int crosspoint = Random->GetNumber(father.size() - 2) + 1;
31  //cout << "Crosspoint: " << crosspoint << endl;
32  copy(mother.begin() + crosspoint, mother.end(), father.begin()
33  + crosspoint);
34  copy(tempstore.begin() + crosspoint, tempstore.end(),
35  mother.begin() + crosspoint);
36  }
37  }
38 
40  {
41  for (unsigned int i = 0; i < child.size(); ++i)
42  {
43  if (Random->GetNumber() < MutationProb)
44  {
45  child(i) = !(child(i));
46  }
47 
48  }
49  }
50  }
The base class for the population of a genetic algorithm, implements storage and access functions...
GeneralPropagation(GeneralSelect *const LocalSelect, GeneralPopulation *const LocalPopulation, GeneralRNG *const LocalRandom)
GeneralSelect is the abstract base class for any selection mechanism in genetic algorithms.
Definition: GeneralSelect.h:16
The base class for genetic algorithm propagation methods.
virtual void Mutation(tpopmember &child)
ublas::vector< bool > tpopmember
Definition: gentypes.h:22
virtual float GetNumber()=0
virtual void Crossover(tpopmember &father, tpopmember &mother)
The base class for all random number generators, defines the basic interface.
Definition: GeneralRNG.h:9