10 BinaryTournamentSelect::BinaryTournamentSelect(
GeneralRNG &LocalRandom,
12 distancecount(0), Random(LocalRandom), ProbabilityFunction(myPF),
13 DistanceFunction(myDF), ReturnIndex(0)
20 cout <<
"Distance Count: " << distancecount << endl;
23 void BinaryTournamentSelect::DoInit()
25 if (ProbabilityFunction().
size() != DistanceFunction().
size())
27 "Probabilities and Crowding distances do not have the same size !");
29 localprobabilities = ProbabilityFunction();
30 localdistances = DistanceFunction();
31 const size_t popsize = localdistances.size();
32 PopulationIndex.assign(popsize * 2, 0);
33 for (
size_t i = 0; i < popsize; ++i)
35 PopulationIndex.at(i) = i;
36 PopulationIndex.at(i + popsize) = i;
38 for (
size_t i = 0; i < popsize; ++i)
40 int CurrentIndex = Random.
GetNumber(popsize - i);
41 swap(PopulationIndex.at(popsize - i - 1), PopulationIndex.at(
43 CurrentIndex = Random.
GetNumber(popsize - i);
44 swap(PopulationIndex.at(2 * popsize - i - 1), PopulationIndex.at(
45 popsize + CurrentIndex));
50 size_t BinaryTournamentSelect::DoGetOne()
52 const double tolerance = 1e-5;
54 const int fatherindex = PopulationIndex.at(ReturnIndex);
55 const int motherindex = PopulationIndex.at(ReturnIndex + 1);
59 const int comparison = fcmp(localprobabilities(fatherindex),
60 localprobabilities(motherindex), tolerance);
69 if (localdistances(fatherindex) >= localdistances(motherindex))
75 "Something went very wrong in CBinaryTournamentSelect::GetOne");
virtual ~BinaryTournamentSelect()
boost::function< const tprobabilityv &()> tProbabilityFunction
virtual float GetNumber()=0
boost::function< const tcrowddistv &()> tDistanceFunction
The base class for all random number generators, defines the basic interface.
The basic exception class for all errors that arise in gplib.