GA - 1.2.1
Utilities
Configuration
GA
NNFW
WorldSim
Total 99%
Experiments
Main Page
Related Pages
Modules
Classes
Files
File List
ga
src
genotypes
doublegenotype.cpp
1
/********************************************************************************
2
* FARSA Genetic Algorithm Library *
3
* Copyright (C) 2007-2009 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 "genotypes/doublegenotype.h"
21
#include <cmath>
22
23
namespace
farsa {
24
25
DoubleGenotype::DoubleGenotype
(
unsigned
int
numGenes,
double
min,
double
max,
unsigned
int
bitPrecision )
26
:
Genotype
( numGenes*bitPrecision ) {
27
numgenes
=
numGenes
;
28
bitprec
=
bitPrecision
;
29
maxv
= max;
30
minv
= min;
31
}
32
33
DoubleGenotype::~DoubleGenotype
() {
34
//--- nothing to do
35
}
36
37
DoubleGenotype::DoubleGenotype
(
const
DoubleGenotype
& genotype )
38
:
Genotype
( genotype ) {
39
this->
numgenes
= genotype.
numgenes
;
40
this->
bitprec
= genotype.
bitprec
;
41
this->
maxv
= genotype.
maxv
;
42
this->
minv
= genotype.
minv
;
43
}
44
45
unsigned
int
DoubleGenotype::numGenes
() {
46
return
numgenes
;
47
}
48
49
double
DoubleGenotype::maxValue
() {
50
return
maxv
;
51
}
52
53
double
DoubleGenotype::minValue
() {
54
return
minv
;
55
}
56
57
unsigned
int
DoubleGenotype::bitPrecision
() {
58
return
bitprec
;
59
}
60
61
unsigned
int
DoubleGenotype::geneToBitIndex
(
unsigned
int
gene )
const
{
62
return
gene *
bitprec
;
63
}
64
65
unsigned
int
DoubleGenotype::bitToGeneIndex
(
unsigned
int
bit )
const
{
66
return
bit /
bitprec
;
67
}
68
}
// end namespace farsa