1 #ifndef FAIF_SEARCH_VECTOR_INDIVIDUAL_H 2 #define FAIF_SEARCH_VECTOR_INDIVIDUAL_H 4 #if defined(_MSC_VER) && (_MSC_VER >= 1400) 6 #pragma warning(disable:4127) 11 #include <boost/concept_check.hpp> 12 #include <boost/bind.hpp> 14 #include "../utils/Random.hpp" 24 typedef typename T::value_type value_type;
37 typedef bool value_type;
38 static value_type generateRandom() {
40 return random() < 0.5;
42 static value_type mutate(
double prob_mutation,
const value_type& val) {
44 if( random() < prob_mutation ) {
59 typedef typename Gene::value_type value_type;
60 typedef std::vector<value_type> Container;
61 typedef typename Container::iterator iterator;
62 typedef typename Container::const_iterator const_iterator;
66 std::generate_n( std::back_inserter( chromosome_ ), size, &Gene::generateRandom );
71 : chromosome_(value) {}
76 chromosome_ = i.chromosome_;
82 std::transform( chromosome_.begin(), chromosome_.end(), chromosome_.begin(),
83 boost::bind( &Gene::mutate, prob_mutation, _1) );
87 return chromosome_ == i.chromosome_;
90 return chromosome_ != i.chromosome_;
95 Container chromosome_;
101 #endif //FAIF_SEARCH_VECTOR_INDIVIDUAL_H
Template to generate individual which is the vector of Genes.
Definition: VectorIndividual.hpp:54
void mutate(double prob_mutation)
change the object at random positions
Definition: VectorIndividual.hpp:81
the uniform distribution for double, in given range, e.g. <0,1), uses RandomSingleton ...
Definition: Random.hpp:74
VectorIndividual(int size)
Definition: VectorIndividual.hpp:65
the concept for evolutionary algorithm gene the type gives the generateRandom method and the mutate m...
Definition: VectorIndividual.hpp:23
Definition: VectorIndividual.hpp:36
VectorIndividual(Container value)
Definition: VectorIndividual.hpp:70
const Container & getChromosome() const
Definition: VectorIndividual.hpp:93