dlugolecki.net.pl
Dziennik
Polecane
Software
projects
/
genetic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Apply small optimizations.
[genetic.git]
/
src
/
selection
/
selection.h
diff --git
a/src/selection/selection.h
b/src/selection/selection.h
index f519ca1eebdb47e0a05636db9d85db452cdb984d..dd6e846299b0ae34c159843e883b63a5b6c43082 100644
(file)
--- a/
src/selection/selection.h
+++ b/
src/selection/selection.h
@@
-9,27
+9,69
@@
using namespace std;
namespace genetic {
// namespace selection {
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:
template < typename _Chromosome >
class Selection {
public:
+ /**
+ * Type representing Fitness function
+ */
typedef Fitness<_Chromosome> GeneticFitness;
typedef Fitness<_Chromosome> GeneticFitness;
+
+ /**
+ * Value type returned by the Fitness function
+ */
typedef typename GeneticFitness::ValueType FitnessValueType;
protected:
typedef typename GeneticFitness::ValueType FitnessValueType;
protected:
+ /**
+ * Generation over which the Selection will be applied
+ */
Generation<_Chromosome> generation;
Generation<_Chromosome> generation;
+
+ /**
+ * Fitness which will be used in selection
+ */
GeneticFitness& fitness;
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();
}
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:
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) {
}
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();
}
Generation<_Chromosome> draw() {
return this->do_draw();
}