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();
}