The Fib multimedia system
Fib is a system for storing multimedia data (like images or films).
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cObjectFitnessAlgorithm.h
Go to the documentation of this file.
1 /**
2  * @file cObjectFitnessAlgorithm
3  * file name: cObjectFitnessAlgorithm.h
4  * @author Betti Oesterholz
5  * @date 26.02.2010
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This header specifies the abstract basisclass of enviroment object
11  * creating fitness objects.
12  * Copyright (C) @c GPL3 2010 Betti Oesterholz
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License (GPL) as
16  * published by the Free Software Foundation, either version 3 of the
17  * License, or any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  *
27  * @see cObjectFitness
28  * This header specifies the abstract basisclass of enviroment algorithm
29  * for creating fitness objects.
30  * The better (higher) the fitness the better the object, the more likly
31  * it should live and children should be created from it.
32  *
33  */
34 /*
35 History:
36 26.02.2010 Oesterholz created
37 02.11.2012 Oesterholz Bugfix: mutex for original individual
38 */
39 
40 #ifndef ___C_OBJECT_FITNESS_ALGORITHMUS_H__
41 #define ___C_OBJECT_FITNESS_ALGORITHMUS_H__
42 
43 #include "version.h"
44 
45 #include "cObjectFitness.h"
46 
47 #include <string>
48 #include <pthread.h>
49 
50 
51 using std::string;
52 
53 namespace enviroment{
54 
55 
56 class cIndividual;//cyclic dependencie
57 
58 
60 
61 protected:
62 
63  /**
64  * The individual with which the fitness should be evalued.
65  * The more similar the given individual is to this (originalIndividual)
66  * the higher its fitness will be, if it's other properties (e.g. size)
67  * are the same.
68  */
70 
71 #ifdef WINDOWS
72  mutable HANDLE mutexOriginalIndividual;
73 #else //WINDOWS
74  mutable pthread_mutex_t mutexOriginalIndividual;
75 #endif //WINDOWS
76 
77 public:
78 
79  /**
80  * constructor
81  */
83 
84  /**
85  * constructor
86  *
87  * @param pInOriginalIndividual the individual with which the fitness
88  * should be evalued;
89  * Beware: this object won't be copied, so don't delete it as long
90  * as this object exists
91  */
92  cObjectFitnessAlgorithm( cIndividual * pInOriginalIndividual );
93 
94  /**
95  * copyconstructor
96  *
97  * @param objectFitnessAlgorithm the cObjectFitnessAlgorithm object to copy
98  */
100  objectFitnessAlgorithm );
101 
102  /**
103  * Destructor of the class cObjectFitnessAlgorithm.
104  */
105  virtual ~cObjectFitnessAlgorithm() = 0;
106 
107  /**
108  * This function evalues the fitness for the given individual.
109  * Beware: You have to delete the returned fitness after usage.
110  *
111  * @see pOriginalIndividual
112  * @param individual the cIndividual for which a fitnessobject should
113  * be created
114  * @return a pointer to a fitnessobject for the fitness of the given individual or
115  * NULL, if no fitness could be created
116  */
117  virtual cObjectFitness * evalueFitness( const cIndividual & individual ) const = 0;
118 
119  /**
120  * @return the name of this class
121  */
122  virtual string getClassName() const;
123 
124  /**
125  * This method sets the originalindividual.
126  * The originalindividual is the individual with which the fitness
127  * should be evalued.
128  *
129  * @see getOriginalIndividual()
130  * @see pOriginalIndividual
131  * @param pInOriginalIndividual a point to the originalindividual to set
132  * Beware: this object won't be copied, so don't delete it as long
133  * as this object exists
134  * @return true if the originalindividual is set to originalIndividum,
135  * else false
136  */
137  virtual bool setOriginalIndividual( cIndividual * pInOriginalIndividual );
138 
139  /**
140  * @see setOriginalIndividual()
141  * @see pOriginalIndividual
142  * @return a pointer to the originalindividual or NULL if non exists
143  * The originalindividual is the individual with which the
144  * fitness is evalued.
145  */
147 
148  /**
149  * @see setOriginalIndividual()
150  * @see pOriginalIndividual
151  * @return a pointer to the originalindividual or NULL if non exists
152  * The originalindividual is the individual with which the
153  * fitness is evalued.
154  */
155  const cIndividual * getOriginalIndividual() const;
156 
157  /**
158  * This Method clones this object.
159  *
160  * @return a clone of this object
161  */
162  virtual cObjectFitnessAlgorithm * clone() const = 0;
163 
164  /**
165  * This Method returns the best possible fitness the algorithm can create.
166  * No individual with a better/ higher fitness can be created with this
167  * algorithm.
168  * Normaly this would be an indivudual which represents the original
169  * individual perfectly and don't use recources.
170  * If no best possible fitness can be evalued NULL is returned.
171  *
172  * @return a refernce to the best possible fitness or NULL, if non can be creted
173  */
174  virtual const cObjectFitness * getBestFitness() const = 0;
175 
176  /**
177  * This Method returns the worst case fitness for the algorithm and
178  * originalindividual.
179  * An individual with the worst case fitness can easyly be created.
180  * Normaly this would be the fitness of the originalindividual.
181  * If no worst case fitness can be evalued NULL is returned.
182  *
183  * @return a refernce to the worst case fitness or NULL, if non can be created
184  */
185  virtual const cObjectFitness * getWorstCaseFitness() const = 0;
186 
187 protected:
188 
189 #ifdef WINDOWS
190  /**
191  * Wraper function for windows.
192  * Wait till the given mutex is free and than locks it.
193  * @param pMutexHandle pointer to the mutex to lock.
194  */
195  static void pthread_mutex_lock( HANDLE * pMutexHandle );
196 
197  /**
198  * Wraper function for windows.
199  * Unlocks the given mutex.
200  * @param pMutexHandle pointer to the mutex to unlock.
201  */
202  static void pthread_mutex_unlock( HANDLE * pMutexHandle );
203 #endif //WINDOWS
204 
205 };//end class cObjectFitnessAlgorithm
206 
207 
208 };//end namespace enviroment
209 
210 #endif //___C_OBJECT_FITNESS_ALGORITHMUS_H__
211 
212 
213 
214 
215 
216 
217