OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
BlendCrossover.h
Go to the documentation of this file.
1//
2// Struct BlendCrossover
3// BLX-alpha (interval schemata)
4// Eshelman and Schaffer (1993)
5// Pick random solution in interval
6//
7// [ x_i^(1,t) - \alpha(x_i^(2,t) - x_i^(1,t)),
8// x_i^(2,t) + \alpha((x_i^(2,t) - x_i^(1,t)) ]
9//
10// at generation t.
11//
12// Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
13// All rights reserved
14//
15// Implemented as part of the PhD thesis
16// "Toward massively parallel multi-objective optimization with application to
17// particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
18//
19// This file is part of OPAL.
20//
21// OPAL is free software: you can redistribute it and/or modify
22// it under the terms of the GNU General Public License as published by
23// the Free Software Foundation, either version 3 of the License, or
24// (at your option) any later version.
25//
26// You should have received a copy of the GNU General Public License
27// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
28//
29#include "boost/smart_ptr.hpp"
30#include "Util/CmdArguments.h"
31#include <cmath>
32
33
34template <class T> struct BlendCrossover
35{
36 void crossover(boost::shared_ptr<T> ind1, boost::shared_ptr<T> ind2,
37 CmdArguments_t /*args*/) {
38
39 // BLX-0.5 performs better than BLX operators with any other \alpha
40 // value
41 const double alpha = 0.5;
42
43 for(size_t i = 0; i < ind1->genes_m.size(); i++) {
44
45 double ming = std::min(ind1->genes_m[i], ind2->genes_m[i]);
46 double maxg = std::max(ind1->genes_m[i], ind2->genes_m[i]);
47 double gamma1 = (1 + 2 * alpha) *
48 static_cast<double>(rand() / (RAND_MAX + 1.0)) - alpha;
49 double gamma2 = (1 + 2 * alpha) *
50 static_cast<double>(rand() / (RAND_MAX + 1.0)) - alpha;
51 ind1->genes_m[i] = (1 - gamma1) * ming + gamma1 * maxg;
52 ind2->genes_m[i] = (1 - gamma2) * ming + gamma2 * maxg;
53 }
54 }
55};
56
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
constexpr double alpha
The fine structure constant, no dimension.
Definition: Physics.h:72
void crossover(boost::shared_ptr< T > ind1, boost::shared_ptr< T > ind2, CmdArguments_t)