X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fselection%2Fselection.h;h=dd6e846299b0ae34c159843e883b63a5b6c43082;hb=cb1db4f6f0e4d6c65e09013c21df12b67d05d0b0;hp=f519ca1eebdb47e0a05636db9d85db452cdb984d;hpb=12625bb2d19ee89abacc2456bff57dc22aa3a526;p=genetic.git diff --git a/src/selection/selection.h b/src/selection/selection.h index f519ca1..dd6e846 100644 --- a/src/selection/selection.h +++ b/src/selection/selection.h @@ -9,27 +9,69 @@ using namespace std; namespace genetic { // namespace selection { + /** + * Base Selection template class. It should be a base class for any + * custom selection functions. + */ template < typename _Chromosome > class Selection { public: + /** + * Type representing Fitness function + */ typedef Fitness<_Chromosome> GeneticFitness; + + /** + * Value type returned by the Fitness function + */ typedef typename GeneticFitness::ValueType FitnessValueType; protected: + /** + * Generation over which the Selection will be applied + */ Generation<_Chromosome> generation; + + /** + * Fitness which will be used in selection + */ GeneticFitness& fitness; - + + /** + * Checks Fitness for the given Chromosome + * + * @param chromosome Chromosome for which the selection fitness is + * checked. + * @return Value of the Fitness function + */ FitnessValueType checkChromosomeFitness(_Chromosome chromosome) { this->fitness.chromosome = chromosome; return fitness.calculate(); } + /** + * Selection calculations should be done here. + * + * @return new Generation of Chromosome's that passed the Selection + */ virtual Generation<_Chromosome> do_draw() = 0; public: + /** + * Class constructor. Initializes required variables and constants + * + * @param _generation Generation over which the Selection will be + * applied + * @param _fitness Fitness function to use in Selection + */ Selection(Generation<_Chromosome> _generation, GeneticFitness& _fitness) : generation(_generation), fitness(_fitness) { } + /** + * Invokes Selection calculations + * + * @return new Generation of Chromosome's that passed the Selection + */ Generation<_Chromosome> draw() { return this->do_draw(); }