evaluation.h
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 #ifndef EVALUATION_H
21 #define EVALUATION_H
22 
23 #include "gaconfig.h"
24 #include "parametersettable.h"
25 
26 namespace farsa {
27 
28 class Genotype;
29 class Genome;
30 class GeneticAlgo;
31 
45 public:
47  Evaluation();
49  virtual ~Evaluation();
53  void initialize( Genotype* genotypeToEvaluate );
58  void evaluateStep();
62  void evaluate();
67  virtual void initGeneration(int /*generation*/) { };
72  virtual void endGeneration(int /*generation*/) { };
74  void finalize();
76  bool isEvaluationDone();
79  return genotypev;
80  };
82  unsigned int genotypeID() {
83  return genotypeid;
84  };
86  void setGenome( Genome* g ) {
87  genomev = g;
88  };
91  return genomev;
92  };
94  void setGA( GeneticAlgo* g ) {
95  ga = g;
96  };
99  return ga;
100  };
102  const GeneticAlgo* GA() const {
103  return ga;
104  };
105 
107  virtual Evaluation* clone() const = 0;
108 
109 protected:
111  virtual void init() = 0;
113  virtual void step() = 0;
115  virtual void fini() = 0;
116 
120  void evaluationDone();
121 
122 private:
124  bool isDone;
126  bool isInitialized;
128  bool isFinalized;
130  Genotype* genotypev;
132  unsigned int genotypeid;
134  Genome* genomev;
136  GeneticAlgo* ga;
137 };
138 
139 } // end namespace farsa
140 
141 #endif