1 /*
2 ================================================================================
3     PROJECT:
4 
5         John Eddy's Genetic Algorithms (JEGA) Front End
6 
7     CONTENTS:
8 
9         Implementation of class AlgorithmConfig.
10 
11     NOTES:
12 
13         See notes of AlgorithmConfig.hpp.
14 
15     PROGRAMMERS:
16 
17         John Eddy (jpeddy@sandia.gov) (JE)
18 
19     ORGANIZATION:
20 
21         Sandia National Laboratories
22 
23     COPYRIGHT:
24 
25         See the LICENSE file in the top level JEGA directory.
26 
27     VERSION:
28 
29         1.0.0
30 
31     CHANGES:
32 
33         Tue Feb 07 15:40:43 2006 - Original Version (JE)
34 
35 ================================================================================
36 */
37 
38 
39 
40 
41 /*
42 ================================================================================
43 Document This File
44 ================================================================================
45 */
46 /** \file
47  * \brief Contains the implementation of the AlgorithmConfig class.
48  */
49 
50 
51 
52 
53 /*
54 ================================================================================
55 Includes
56 ================================================================================
57 */
58 // JEGAConfig.hpp should be the first include in all JEGA files.
59 #include <../Utilities/include/JEGAConfig.hpp>
60 
61 #include <utilities/include/EDDY_DebugScope.hpp>
62 #include <../Utilities/include/ParameterDatabase.hpp>
63 #include <../Utilities/include/ParameterExtractor.hpp>
64 #include <../FrontEnd/Core/include/AlgorithmConfig.hpp>
65 
66 
67 
68 
69 
70 
71 
72 
73 /*
74 ================================================================================
75 Namespace Using Directives
76 ================================================================================
77 */
78 using namespace std;
79 using namespace JEGA::Logging;
80 using namespace JEGA::Utilities;
81 
82 
83 
84 
85 
86 
87 
88 /*
89 ================================================================================
90 Begin Namespace
91 ================================================================================
92 */
93 namespace JEGA {
94     namespace FrontEnd {
95 
96 
97 
98 
99 
100 /*
101 ================================================================================
102 Static Member Data Definitions
103 ================================================================================
104 */
105 
106 
107 
108 
109 
110 
111 
112 
113 /*
114 ================================================================================
115 Mutators
116 ================================================================================
117 */
118 
119 
120 
121 
122 
123 
124 /*
125 ================================================================================
126 Accessors
127 ================================================================================
128 */
129 ParameterDatabase&
GetParameterDB()130 AlgorithmConfig::GetParameterDB(
131     )
132 {
133     EDDY_FUNC_DEBUGSCOPE
134     return this->_theParamDB;
135 }
136 
137 const ParameterDatabase&
GetParameterDB() const138 AlgorithmConfig::GetParameterDB(
139     ) const
140 {
141     EDDY_FUNC_DEBUGSCOPE
142     return this->_theParamDB;
143 }
144 
145 EvaluatorCreator&
GetTheEvaluatorCreator() const146 AlgorithmConfig::GetTheEvaluatorCreator(
147     ) const
148 {
149     EDDY_FUNC_DEBUGSCOPE
150     return this->_theEvalCreator;
151 }
152 
153 
154 /*
155 ================================================================================
156 Public Methods
157 ================================================================================
158 */
159 bool
SetAlgorithmName(const string & name)160 AlgorithmConfig::SetAlgorithmName(
161     const string& name
162     )
163 {
164     EDDY_FUNC_DEBUGSCOPE
165     return this->_theParamDB.AddStringParam("method.jega.algorithm_name", name);
166 }
167 
168 bool
SetPrintPopEachGen(bool doPrint)169 AlgorithmConfig::SetPrintPopEachGen(
170     bool doPrint
171     )
172 {
173     EDDY_FUNC_DEBUGSCOPE
174     return this->_theParamDB.AddBooleanParam("method.print_each_pop", doPrint);
175 }
176 
177 bool
SetAlgorithmType(AlgType algType)178 AlgorithmConfig::SetAlgorithmType(
179     AlgType algType
180     )
181 {
182     EDDY_FUNC_DEBUGSCOPE
183 
184     JEGAIFLOG_CF_II_G_F(algType != MOGA && algType != SOGA, this,
185         ostream_entry(lfatal(), "Invalid algorithm type ") << algType
186         )
187 
188     return this->_theParamDB.AddStringParam(
189         "method.algorithm", algType == MOGA ? "moga" : "soga"
190         );
191 }
192 
193 bool
SetDefaultLoggingLevel(const LevelType & defLevel)194 AlgorithmConfig::SetDefaultLoggingLevel(
195     const LevelType& defLevel
196     )
197 {
198     EDDY_FUNC_DEBUGSCOPE
199     return this->_theParamDB.AddIntegralParam("method.output", defLevel);
200 }
201 
202 bool
SetLoggingFilename(const string & filename)203 AlgorithmConfig::SetLoggingFilename(
204     const string& filename
205     )
206 {
207     EDDY_FUNC_DEBUGSCOPE
208     return this->_theParamDB.AddStringParam("method.log_file", filename);
209 }
210 
211 bool
SetOutputFilenamePattern(const std::string & fpattern)212 AlgorithmConfig::SetOutputFilenamePattern(
213     const std::string& fpattern
214     )
215 {
216     EDDY_FUNC_DEBUGSCOPE
217     return this->_theParamDB.AddStringParam(
218         "method.jega.final_data_filename", fpattern
219         );
220 }
221 
222 
223 #define SET_OPNAME_METHOD(opname, keystr) \
224     bool \
225     AlgorithmConfig::Set##opname##Name( \
226         const string& name \
227         ) \
228     { \
229         EDDY_FUNC_DEBUGSCOPE \
230         return this->_theParamDB.AddStringParam(keystr, name); \
231     }
232 
233 SET_OPNAME_METHOD(Mutator, "method.mutation_type")
234 SET_OPNAME_METHOD(Converger, "method.jega.convergence_type")
235 SET_OPNAME_METHOD(Crosser, "method.crossover_type")
236 SET_OPNAME_METHOD(NichePressureApplicator, "method.jega.niching_type")
237 SET_OPNAME_METHOD(FitnessAssessor, "method.fitness_type")
238 SET_OPNAME_METHOD(Selector, "method.replacement_type")
239 SET_OPNAME_METHOD(Initializer, "method.initialization_type")
240 SET_OPNAME_METHOD(MainLoop, "method.jega.mainloop_type")
241 SET_OPNAME_METHOD(PostProcessor, "method.jega.postprocessor_type")
242 
243 
244 
245 string
GetAlgorithmName() const246 AlgorithmConfig::GetAlgorithmName(
247     ) const
248 {
249     EDDY_FUNC_DEBUGSCOPE
250     return this->_theParamDB.GetString("method.jega.algorithm_name");
251 }
252 
253 bool
GetPrintPopEachGen() const254 AlgorithmConfig::GetPrintPopEachGen(
255     ) const
256 {
257     EDDY_FUNC_DEBUGSCOPE
258     return this->_theParamDB.GetBoolean("method.print_each_pop");
259 }
260 
261 AlgorithmConfig::AlgType
GetAlgorithmType() const262 AlgorithmConfig::GetAlgorithmType(
263     ) const
264 {
265     EDDY_FUNC_DEBUGSCOPE
266 
267     string algType(this->_theParamDB.GetString("method.algorithm"));
268 
269     JEGAIFLOG_CF_II_G_F(algType != "moga" && algType != "soga", this,
270         text_entry(lfatal(), "Invalid algorithm type ") << algType
271         )
272 
273     return algType == "moga" ? MOGA : SOGA;
274 }
275 
276 AlgorithmConfig::LevelType
GetDefaultLoggingLevel() const277 AlgorithmConfig::GetDefaultLoggingLevel(
278     ) const
279 {
280     EDDY_FUNC_DEBUGSCOPE
281     return this->_theParamDB.GetIntegral("method.output");
282 }
283 
284 string
GetLoggingFilename() const285 AlgorithmConfig::GetLoggingFilename(
286     ) const
287 {
288     EDDY_FUNC_DEBUGSCOPE
289     return this->_theParamDB.GetString("method.log_file");
290 }
291 
292 
293 #define GET_OPNAME_METHOD(opname, keystr) \
294     string \
295     AlgorithmConfig::Get##opname##Name( \
296         ) const \
297     { \
298         EDDY_FUNC_DEBUGSCOPE \
299         return this->_theParamDB.GetString(keystr); \
300     }
301 
302 GET_OPNAME_METHOD(Mutator, "method.mutation_type")
303 GET_OPNAME_METHOD(Converger, "method.jega.convergence_type")
304 GET_OPNAME_METHOD(Crosser, "method.crossover_type")
305 GET_OPNAME_METHOD(NichePressureApplicator, "method.jega.niching_type")
306 GET_OPNAME_METHOD(FitnessAssessor, "method.fitness_type")
307 GET_OPNAME_METHOD(Selector, "method.replacement_type")
308 GET_OPNAME_METHOD(Initializer, "method.initialization_type")
309 GET_OPNAME_METHOD(MainLoop, "method.jega.mainloop_type")
310 GET_OPNAME_METHOD(PostProcessor, "method.jega.postprocessor_type")
311 
312 
313 
314 
315 
316 /*
317 ================================================================================
318 Subclass Visible Methods
319 ================================================================================
320 */
321 
322 
323 
324 
325 
326 
327 
328 
329 /*
330 ================================================================================
331 Subclass Overridable Methods
332 ================================================================================
333 */
334 
335 
336 
337 
338 
339 
340 
341 
342 /*
343 ================================================================================
344 Private Methods
345 ================================================================================
346 */
347 
348 
349 
350 
351 
352 
353 
354 /*
355 ================================================================================
356 Structors
357 ================================================================================
358 */
AlgorithmConfig(EvaluatorCreator & creator,JEGA::Utilities::ParameterDatabase & pdb)359 AlgorithmConfig::AlgorithmConfig(
360     EvaluatorCreator& creator,
361     JEGA::Utilities::ParameterDatabase& pdb
362     ) :
363         _theParamDB(pdb),
364         _theEvalCreator(creator)
365 {
366     EDDY_FUNC_DEBUGSCOPE
367 }
368 
369 
370 
371 
372 
373 
374 
375 /*
376 ================================================================================
377 End Namespace
378 ================================================================================
379 */
380     } // namespace FrontEnd
381 } // namespace JEGA
382 
383