5 #ifndef ROCKY_ZAGROS_GENETIC_STRATEGY
6 #define ROCKY_ZAGROS_GENETIC_STRATEGY
7 #include <rocky/zagros/strategies/strategy.h>
18 template<
typename T_e,
int T_dim>
25 template<
typename T_e,
int T_dim>
40 this->problem_ = problem;
41 this->target_container_ = tgt_container;
42 this->candidates_ = cnd_container;
44 this->n_mutations_ = cnd_container->n_particles();
46 virtual void tweak(
int p_ind,
int dim) = 0;
48 tbb::parallel_for(0, n_mutations_, [
this](
int p){
51 std::copy(this->target_container_->
particle(samples[0]),
52 this->target_container_->particle(samples[0])+T_dim,
53 this->candidates_->particle(p));
55 for(
int d=0; d<k_; d++){
57 int dim = this->target_container_->
sample_dim();
71 template<
typename T_e,
int T_dim>
84 static std::normal_distribution<T_e> dist(mu_, sigma_);
85 auto z = dist(rocky::utils::random::prng());
88 virtual void tweak(
int p_ind,
int dim){
89 this->candidates_->particles[p_ind][dim] += gaussian_noise();
97 template<
typename T_e,
int T_dim>
104 template<
typename T_e,
int T_dim>
120 this->problem_ = problem;
121 this->container_ = container;
122 this->candidates_ = candidates;
123 this->n_crossovers_ = candidates->n_particles() / 2;
125 virtual void apply(){
126 tbb::parallel_for(0, n_crossovers_, [
this](
int p){
130 for(
int i=0; i<2; i++)
131 std::copy(this->container_->
particle(parents[i]),
132 this->container_->particle(parents[i])+T_dim,
133 this->candidates_->particle(2*p+i));
136 for(
int d=0; d<k_; d++)
137 dims.insert(this->container_->sample_dim());
140 std::swap(this->candidates_->particles[parents[0]][dim],
141 this->candidates_->particles[parents[1]][dim]);
148 template<
typename T_e,
int T_dim>
163 this->n_crossovers_ = cnd_container->n_particles() / 2;
164 this->segment_length_ = segment_length;
165 this->problem_ = problem;
166 this->container_ = container;
167 this->candidates_ = cnd_container;
169 virtual void apply(){
170 tbb::parallel_for(0, n_crossovers_, [
this](
auto ci){
175 std::uniform_int_distribution<> point_dist(0, T_dim - segment_length_ - 1);
176 int point = point_dist(rocky::utils::random::prng());
178 for(
int i=0; i<2; i++){
180 std::copy(this->container_->
particle(parents[i]),
181 this->container_->particle(parents[i])+T_dim,
182 this->candidates_->particle(2*ci+i));
184 std::copy(this->container_->
particle(parents[1-i])+point,
185 this->container_->particle(parents[1-i])+point+segment_length_,
186 this->candidates_->particle(2*ci+i)+point);