OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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 "Util/CmdArguments.h"
27
28
29template <class T> struct SimulatedBinaryCrossover
30{
31 void crossover(std::shared_ptr<T> ind1, std::shared_ptr<T> ind2,
32 CmdArguments_t args) {
33
34 double nu_c = args->getArg<double>("simbin-crossover-nu", 2.0, false);
35
36 for(std::size_t i = 0; i < ind1->genes_m.size(); i++) {
37
38 double ui = (double) rand() / (RAND_MAX + 1.0);
39 double beta_qi = 0.0;
40 if(ui <= 0.5) {
41 beta_qi = pow(2 * ui, 1.0/(nu_c + 1.0));
42 } else {
43 beta_qi = pow(1.0/(2 * (1.0 - ui)), 1.0/(nu_c + 1.0));
44 }
45
46 double ming = std::min(ind1->genes_m[i], ind2->genes_m[i]);
47 double maxg = std::max(ind1->genes_m[i], ind2->genes_m[i]);
48
49 ind1->genes_m[i] = 0.5 * ((1 + beta_qi) * ming + (1 - beta_qi) * maxg);
50 ind2->genes_m[i] = 0.5 * ((1 - beta_qi) * ming + (1 + beta_qi) * maxg);
51 }
52 }
53};
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition TpsMath.h:76
std::shared_ptr< CmdArguments > CmdArguments_t
void crossover(std::shared_ptr< T > ind1, std::shared_ptr< T > ind2, CmdArguments_t args)
T getArg(const std::string name, bool isFatal=false)