GA - 1.2.3
Utilities
Configuration
GA
NNFW
WorldSim
Total 99%
Experiments
Main Page
Related Pages
Modules
Classes
Files
File List
ga
src
mutations
flipbit.cpp
1
/********************************************************************************
2
* FARSA Genetic Algorithm Library *
3
* Copyright (C) 2007-2008 Gianluca Massera <emmegian@yahoo.it> *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
9
* *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
14
* *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the Free Software *
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18
********************************************************************************/
19
20
#include "mutations/flipbit.h"
21
#include "core/genotype.h"
22
#include "randomgenerator.h"
23
24
namespace
farsa {
25
26
FlipBit::FlipBit
()
27
:
Mutation
() {
28
}
29
30
FlipBit::~FlipBit
() {
31
//--- nothing to do
32
}
33
34
void
FlipBit::mutate
(
Genotype
* gen ) {
35
Genotype
& genref = *gen;
36
for
(
unsigned
int
i=0; i<genref.
size
(); i++ ) {
37
if
(
globalRNG
->getBool(
mutationRate
( i ) ) ) {
38
genref.
toggle
(i);
39
}
40
}
41
}
42
43
void
FlipBit::describe
( QString type ) {
44
Mutation::describe
( type );
45
addTypeDescription
( type,
"Mutation operator"
,
"Flip a bit with the probability specified by mutation_rate parameter"
);
46
}
47
48
}
// end namespace farsa