OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
SimulatedBinaryCrossover.h
Go to the documentation of this file.
1 //
2 // Struct SimulatedBinaryCrossover
3 // Deb (1995) Simulated Binary Crossover (SBX)
4 // Respects interval schemata.
5 // Offspring are symmetric around parent solutions.
6 //
7 // Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
8 // All rights reserved
9 //
10 // Implemented as part of the PhD thesis
11 // "Toward massively parallel multi-objective optimization with application to
12 // particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
13 //
14 // This file is part of OPAL.
15 //
16 // OPAL is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
23 //
24 #include <cmath>
25 
26 #include "boost/smart_ptr.hpp"
27 #include "Util/CmdArguments.h"
28 
29 
30 template <class T> struct SimulatedBinaryCrossover
31 {
32  void crossover(boost::shared_ptr<T> ind1, boost::shared_ptr<T> ind2,
33  CmdArguments_t args) {
34 
35  double nu_c = args->getArg<double>("simbin-crossover-nu", 2.0, false);
36 
37  for(std::size_t i = 0; i < ind1->genes_m.size(); i++) {
38 
39  double ui = (double) rand() / (RAND_MAX + 1.0);
40  double beta_qi = 0.0;
41  if(ui <= 0.5) {
42  beta_qi = pow(2 * ui, 1.0/(nu_c + 1.0));
43  } else {
44  beta_qi = pow(1.0/(2 * (1.0 - ui)), 1.0/(nu_c + 1.0));
45  }
46 
47  double ming = std::min(ind1->genes_m[i], ind2->genes_m[i]);
48  double maxg = std::max(ind1->genes_m[i], ind2->genes_m[i]);
49 
50  ind1->genes_m[i] = 0.5 * ((1 + beta_qi) * ming + (1 - beta_qi) * maxg);
51  ind2->genes_m[i] = 0.5 * ((1 - beta_qi) * ming + (1 + beta_qi) * maxg);
52  }
53  }
54 };
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
void crossover(boost::shared_ptr< T > ind1, boost::shared_ptr< T > ind2, CmdArguments_t args)