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
cEndConditionCheck.h
Go to the documentation of this file.
1 /**
2  * @file cEndConditionCheck
3  * file name: cEndConditionCheck.h
4  * @author Betti Oesterholz
5  * @date 15.03.2010
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This header specifies a class for checking the end condition of the
11  * enviroment.
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  *
28  * This header specifies a class for checking the end condition of the
29  * enviroment.
30  * This includes, if set, checking if:
31  * - if a system signal to end the process was received (for Linux: HUP=1, QUIT=3, TERM=15)
32  * - a maximal number of opertions wher performed
33  * - a maximal fitness was reached
34  * - a maximal CPU -check time was reached
35  * - a realtime runtime was reached
36  * - a specific date was reached
37  *
38  * If one of the checks is positiv the endconditions holds and the
39  * enviroment should be ended.
40  *
41  * @see cEnviroment
42  */
43 /*
44 History:
45 15.03.2010 Oesterholz created
46 */
47 
48 
49 #ifndef ___C_END_CONDITION_CHECK_H__
50 #define ___C_END_CONDITION_CHECK_H__
51 
52 #include "version.h"
53 
54 #include "cObjectFitness.h"
55 
56 #include <ctime>
57 
58 
59 namespace enviroment{
60 
61 
63 protected:
64 
65  /**
66  * The maximal fitness for individuals in the enviroment.
67  * If NULL the maximal fitness condition isn't checked/ is deaktivated.
68  */
70 
71  /**
72  * The maximum calls of operators/ operations executed of the enviroment.
73  * If 0 the maximal operators condition isn't checked/ is deaktivated.
74  */
75  unsigned long lMaxOperationCalls;
76 
77  /**
78  * The maximum cpu -time (in system clocks) the enviroment can consume.
79  * If negativ (-1.0) the maximal cpu -time condition isn't checked/ is deaktivated.
80  */
82 
83  /**
84  * The maximum runtime (in secounds) the enviroment can consume.
85  * If negativ (-1.0) the maximal runtime condition isn't checked/ is deaktivated.
86  */
87  double dMaxRuntime;
88 
89  /**
90  * The (real-)time /date till which the enviroment can run.
91  * If 0 the maximal date condition isn't checked/ is deaktivated.
92  */
93  time_t maxDate;
94 
95 
96  /**
97  * This variable is true if an signal abort was received, else false.
98  */
99  static bool bSignalAbortReceived;
100 
101  /**
102  * This variable is true if an signal interrupt was received, else false.
103  */
105 
106  /**
107  * This variable is true if an signal terminat was received, else false.
108  */
110 
111 
112 public:
113 
114  /**
115  * standardconstructor
116  */
118 
119  /**
120  * copyconstructor
121  */
123 
124  /**
125  * Destructor of the class cEndConditionCheck.
126  */
127  virtual ~cEndConditionCheck();
128 
129  /**
130  * @return the name of this class
131  */
132  virtual string getClassName() const;
133 
134 
135  /**
136  * @return true if the endcondition holds and the enviroment should be
137  * stoped, else false
138  */
139  virtual bool endConditionCheck();
140 
141  /**
142  * @see pMaxFitness
143  * @return The maximal fitness for individuals in the enviroment.
144  * If NULL the maximal fitness condition isn't checked/ is deaktivated.
145  */
146  cObjectFitness * getMaxFitness() const;
147 
148  /**
149  * This method sets the maximal fitness for individuals in the enviroment.
150  * If NULL is set (standardvalue) the maximal fitness condition isn't
151  * checked/ is deaktivated.
152  *
153  * @see pMaxFitness
154  * @param fitness the maximal fitness for individuals in the enviroment
155  * @return true if the fitness was set, else false
156  */
157  bool setMaxFitness( cObjectFitness * fitness=NULL );
158 
159  /**
160  * @see lMaxOperationCalls
161  * @return The maximum calls of operators/ operations executed of the enviroment.
162  * If 0 the maximal operators condition isn't checked/ is deaktivated.
163  */
164  unsigned long getMaxOperationCalls() const;
165 
166  /**
167  * This method sets the maximum calls of operators/ operations
168  * executed of the enviroment.
169  * If 0 is set (standardvalue) the operators fitness condition isn't
170  * checked/ is deaktivated.
171  *
172  * @see lMaxOperationCalls
173  * @param lMaxCalls the maximal calls of operators/ operations executed
174  * of the enviroment
175  * @return true if the maximal calls was set, else false
176  */
177  bool setMaxOperationCalls( unsigned long lMaxCalls=0 );
178 
179  /**
180  * @see dMaxCpuRuntime
181  * @return The maximum cpu -time (in system clocks) the enviroment can
182  * consume. If negativ (-1.0) the maximal cpu -time condition isn't
183  * checked/ is deaktivated.
184  */
185  double getMaxCpuRuntime() const;
186 
187  /**
188  * This method sets the maximum cpu -time (in system clocks) the
189  * enviroment can consume.
190  * If negativ (standardvalue = -1.0) the maximal cpu -time condition
191  * isn't checked/ is deaktivated.
192  *
193  * @see dMaxCpuRuntime
194  * @param dMaxCpuTime the maximal cpu -time the enviroment can consume
195  * of the enviroment
196  * @return true if the maximal cpu -time was set, else false
197  */
198  double setMaxCpuRuntime( double dMaxCpuTime=-1.0 );
199 
200  /**
201  * @see dMaxRuntime
202  * @return The maximum runtime (in secounds) the enviroment can consume.
203  * If negativ (-1.0) the maximal runtime condition isn't checked/ is
204  * deaktivated.
205  */
206  double getMaxRuntime() const;
207 
208  /**
209  * This method sets the maximum runtime (in secounds) the enviroment
210  * can consume.
211  * If negativ (standardvalue = -1.0) the maximal runtime condition
212  * isn't checked/ is deaktivated.
213  *
214  * @see dMaxRuntime
215  * @param dMaxTime the maximal runtime the enviroment can consume
216  * of the enviroment
217  * @return true if the maximal runtime was set, else false
218  */
219  bool setMaxRuntime( double dMaxTime=-1.0 );
220 
221  /**
222  * @see maxDate
223  * @return The (real-)time /date till which the enviroment can run.
224  * If 0 the maximal date condition isn't checked/ is deaktivated.
225  */
226  time_t getMaxDate() const;
227 
228  /**
229  * This method sets the (real-)time /date till which the enviroment can run.
230  * If 0 (standardvalue) the maximal date condition isn't checked/ is deaktivated.
231  *
232  * @see maxDate
233  * @param tMaxDate the maximal date till which the enviroment can run
234  * of the enviroment
235  * @return true if the maximal date was set, else false
236  */
237  bool setMaxDate( time_t tMaxDate=0 );
238 
239  /**
240  * This method clones this object.
241  *
242  * @return a clone of this object
243  */
244  virtual cEndConditionCheck * clone() const;
245 
246 private:
247 
248  /**
249  * This method should catch the signal abort.
250  * @see bSignalAbortReceived
251  */
252  static void catchSignalAbort( int parameter );
253 
254  /**
255  * This method should catch the signal interrupt.
256  * @see bSignalInterruptReceived
257  */
258  static void catchSignalInterrupt( int parameter );
259 
260  /**
261  * This method should catch the signal terminate.
262  * @see bSignalTerminateReceived
263  */
264  static void catchSignalTerminate( int parameter );
265 
266 
267 };//end class cEndConditionCheck
268 
269 
270 };//end namespace enviroment
271 
272 #endif //___C_END_CONDITION_CHECK_H__
273 
274 
275 
276 
277 
278 
279