OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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 "Util/CmdArguments.h"
30#include <cmath>
31
32
33template <class T> struct BlendCrossover
34{
35 void crossover(std::shared_ptr<T> ind1, std::shared_ptr<T> ind2,
36 CmdArguments_t /*args*/) {
37
38 // BLX-0.5 performs better than BLX operators with any other \alpha
39 // value
40 const double alpha = 0.5;
41
42 for(size_t i = 0; i < ind1->genes_m.size(); i++) {
43
44 double ming = std::min(ind1->genes_m[i], ind2->genes_m[i]);
45 double maxg = std::max(ind1->genes_m[i], ind2->genes_m[i]);
46 double gamma1 = (1 + 2 * alpha) *
47 static_cast<double>(rand() / (RAND_MAX + 1.0)) - alpha;
48 double gamma2 = (1 + 2 * alpha) *
49 static_cast<double>(rand() / (RAND_MAX + 1.0)) - alpha;
50 ind1->genes_m[i] = (1 - gamma1) * ming + gamma1 * maxg;
51 ind2->genes_m[i] = (1 - gamma2) * ming + gamma2 * maxg;
52 }
53 }
54};
55
std::shared_ptr< CmdArguments > CmdArguments_t
void crossover(std::shared_ptr< T > ind1, std::shared_ptr< T > ind2, CmdArguments_t)