00001 #ifndef CBINARYTOURNAMENTSELECT_H_ 00002 #define CBINARYTOURNAMENTSELECT_H_ 00003 00004 #include "GeneralSelect.h" 00005 #include "GeneralRNG.h" 00006 namespace gplib 00007 { 00008 /** \addtogroup gainv Genetic algorithm optimization */ 00009 /* @{ */ 00010 00011 //! Implements binary tournament selection for genetic algorithms 00012 class BinaryTournamentSelect: public GeneralSelect 00013 { 00014 private: 00015 //! The number of members that have been selected because of the crowding distance, purely for monitoring 00016 size_t distancecount; 00017 //! Storage for shuffled indices of the population, set up during DoInit and used to get pairs of member in DoGetOne 00018 std::vector<unsigned int> PopulationIndex; 00019 //! Local storage for the probabilities of the population 00020 tprobabilityv localprobabilities; 00021 //! Local storage for the crowding distance 00022 tcrowddistv localdistances; 00023 //! The random number generator to shuffle the population 00024 GeneralRNG &Random; 00025 //! Pointer to a function that returns the probabilities of the population 00026 tProbabilityFunction ProbabilityFunction; 00027 //! Pointer to a function that returns the crowding distances of the population 00028 tDistanceFunction DistanceFunction; 00029 //! The current index within the population 00030 int ReturnIndex; 00031 //! Initialize PopulationIndex and the local storage fields 00032 virtual void DoInit(); 00033 //! Return the index to a population member 00034 virtual size_t DoGetOne(); 00035 public: 00036 //! The constructor requires a random number generator and access functions for probabilities and crowding distances 00037 BinaryTournamentSelect(GeneralRNG &LocalRandom, 00038 tProbabilityFunction myPF, tDistanceFunction myDF); 00039 virtual ~BinaryTournamentSelect(); 00040 }; 00041 /* @} */ 00042 } 00043 #endif /*CBINARYTOURNAMENTSELECT_H_*/
1.5.8