OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
BlendCrossover.h
Go to the documentation of this file.
1 #include "boost/smart_ptr.hpp"
2 #include "Util/CmdArguments.h"
3 #include <cmath>
4 
16 template <class T> struct BlendCrossover
17 {
18  void crossover(boost::shared_ptr<T> ind1, boost::shared_ptr<T> ind2,
19  CmdArguments_t args) {
20 
21  // BLX-0.5 performs better than BLX operators with any other \alpha
22  // value
23  const double alpha = 0.5;
24 
25  for(size_t i = 0; i < ind1->genes_m.size(); i++) {
26 
27  double ming = std::min(ind1->genes_m[i], ind2->genes_m[i]);
28  double maxg = std::max(ind1->genes_m[i], ind2->genes_m[i]);
29  double gamma1 = (1 + 2 * alpha) *
30  static_cast<double>(rand() / (RAND_MAX + 1.0)) - alpha;
31  double gamma2 = (1 + 2 * alpha) *
32  static_cast<double>(rand() / (RAND_MAX + 1.0)) - alpha;
33  ind1->genes_m[i] = (1 - gamma1) * ming + gamma1 * maxg;
34  ind2->genes_m[i] = (1 - gamma2) * ming + gamma2 * maxg;
35  }
36  }
37 };
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:123
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:169
constexpr double alpha
The fine structure constant, no dimension.
Definition: Physics.h:79
void crossover(boost::shared_ptr< T > ind1, boost::shared_ptr< T > ind2, CmdArguments_t args)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:95