GA - 1.2.1
Utilities
Configuration
GA
NNFW
WorldSim
Total 99%
Experiments
Main Page
Related Pages
Modules
Classes
Files
File List
ga
src
mutations
randomfloat.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/randomfloat.h"
21
#include "core/genotype.h"
22
#include "randomgenerator.h"
23
#include "genotypes/doublegenotype.h"
24
25
namespace
farsa {
26
27
RandomFloat::RandomFloat
()
28
:
Mutation
() {
29
}
30
31
RandomFloat::~RandomFloat
() {
32
//--- nothing to do
33
}
34
35
void
RandomFloat::mutate
(
Genotype
* gen ) {
36
DoubleGenotype
* rgen =
dynamic_cast<
DoubleGenotype
*
>
( gen );
37
Q_ASSERT_X( rgen != 0,
38
"RandomFloat::mutate"
,
39
"In order to use RandomFloat mutation the Genotypes must be a subclass of DoubleGenotype"
);
40
double
min = rgen->
minValue
();
41
double
max = rgen->
maxValue
();
42
for
(
unsigned
int
i=0; i<rgen->
numGenes
(); i++ ) {
43
if
(
globalRNG
->getBool(
mutationRate
( rgen->
geneToBitIndex
(i) ) ) ) {
44
rgen->
set
( i,
globalRNG
->getDouble( min, max ) );
45
}
46
}
47
}
48
49
void
RandomFloat::describe
( QString type ) {
50
Mutation::describe
( type );
51
addTypeDescription
( type,
"Mutation operator"
,
"Replace a real value with a random one with the probability specified by mutation_rate parameter"
);
52
}
53
54
}
// end namespace farsa