OPAL (Object Oriented Parallel Accelerator Library)
2024.2
OPAL
IndependentBitMutation.h
Go to the documentation of this file.
1
//
2
// Struct IndependentBitMutation
3
// Mutate each gene with probability p
4
//
5
// Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
6
// All rights reserved
7
//
8
// Implemented as part of the PhD thesis
9
// "Toward massively parallel multi-objective optimization with application to
10
// particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
11
//
12
// This file is part of OPAL.
13
//
14
// OPAL is free software: you can redistribute it and/or modify
15
// it under the terms of the GNU General Public License as published by
16
// the Free Software Foundation, either version 3 of the License, or
17
// (at your option) any later version.
18
//
19
// You should have received a copy of the GNU General Public License
20
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
21
//
22
#include "
Util/CmdArguments.h
"
23
24
template
<
class
T>
struct
IndependentBitMutation
25
{
26
void
mutate
(std::shared_ptr<T> ind,
CmdArguments_t
args) {
27
28
const
double
probability =
29
args->
getArg
<
double
>(
"gene-mutation-probability"
, 0.5);
30
31
for
(
size_t
i = 0; i < ind->genes_m.size(); i++) {
32
double
rval =
static_cast<
double
>
(rand() / (RAND_MAX + 1.0));
33
if
(rval < probability) {
34
ind->new_gene(i);
35
}
36
}
37
}
38
};
CmdArguments.h
CmdArguments_t
std::shared_ptr< CmdArguments > CmdArguments_t
Definition
CmdArguments.h:176
IndependentBitMutation
Definition
IndependentBitMutation.h:25
IndependentBitMutation::mutate
void mutate(std::shared_ptr< T > ind, CmdArguments_t args)
Definition
IndependentBitMutation.h:26
CmdArguments::getArg
T getArg(const std::string name, bool isFatal=false)
Definition
CmdArguments.h:60