GA - 1.4.5
Utilities
Configuration
GA
NNFW
WorldSim
Total 99%
Experiments
Main Page
Related Pages
Modules
Classes
Files
File List
ga
src
crossovers
onepoint.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 "crossovers/onepoint.h"
21
#include "core/genotype.h"
22
#include "randomgenerator.h"
23
#include "configurationparameters.h"
24
25
namespace
farsa {
26
27
OnePoint::OnePoint
() :
Crossover
() {
28
}
29
30
OnePoint::~OnePoint
() {
31
//--- nothing to do
32
}
33
34
void
OnePoint::crossover
(
Genotype
* father,
const
Genotype
* mother ) {
35
int
max
= qMin( father->
size
(), mother->
size
() );
36
int
splitpoint =
globalRNG
->
getInt
( 0, max );
37
for
(
int
i=splitpoint; i<
max
; i++ ) {
38
if
( father->
bit
(i) != mother->
bit
(i) ) {
39
father->
toggle
(i);
40
}
41
}
42
}
43
44
void
OnePoint::configure
(
ConfigurationParameters
& params, QString prefix ) {
45
Q_UNUSED( params );
46
Q_UNUSED( prefix );
47
//--- nothing to do
48
}
49
50
void
OnePoint::save
(
ConfigurationParameters
& params, QString prefix ) {
51
params.
createParameter
( prefix, QString(
"type"
),
"OnePoint"
);
52
}
53
54
void
OnePoint::describe
( QString type ) {
55
addTypeDescription
( type,
"The one point crossover"
,
"It randomly select one point where to split the two Genotypes, and create a new one combining the first part of one Genotype with the second part of the other one"
);
56
}
57
58
}
// end namespace farsa