GA - 1.2.3
Utilities
Configuration
GA
NNFW
WorldSim
Total 99%
Experiments
Main Page
Related Pages
Modules
Classes
Files
File List
ga
src
core
evaluation.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 "core/evaluation.h"
21
#include "core/genome.h"
22
23
namespace
farsa {
24
25
Evaluation::Evaluation
() {
26
isDone =
false
;
27
isInitialized =
false
;
28
isFinalized =
true
;
29
genotypev = 0;
30
genotypeid = -1;
31
genomev = 0;
32
ga = 0;
33
}
34
35
Evaluation::~Evaluation
() {
36
//--- nothing to do
37
}
38
39
void
Evaluation::initialize
(
Genotype
* gen ) {
40
//--- check if it is initialized already and not finalized yet
41
if
( isInitialized && !isFinalized ) {
42
//--- nothing do to
43
return
;
44
}
45
genotypev = gen;
46
if
(
genome
() ) {
47
genotypeid =
genome
()->
find
( gen );
48
}
49
isDone =
false
;
50
init
();
51
isInitialized =
true
;
52
isFinalized =
false
;
53
}
54
55
void
Evaluation::evaluateStep
() {
56
if
( !isInitialized ) {
57
qFatal(
"You Must Initialized Evaluation Process before calling evaluateStep()"
);
58
return
;
59
}
60
step
();
61
}
62
63
void
Evaluation::evaluate
() {
64
while
( !
isEvaluationDone
() ) {
65
evaluateStep
();
66
}
67
}
68
69
void
Evaluation::finalize
() {
70
if
( !isInitialized && isFinalized ) {
71
//--- nothing to do
72
return
;
73
}
74
fini
();
75
isInitialized =
false
;
76
isFinalized =
true
;
77
}
78
79
bool
Evaluation::isEvaluationDone
() {
80
return
isDone;
81
}
82
83
void
Evaluation::evaluationDone
() {
84
isDone =
true
;
85
}
86
87
}
// end namespace farsa