1 /*
2 ================================================================================
3 PROJECT:
4
5 John Eddy's Genetic Algorithms (JEGA) Configuration File Front End
6
7 CONTENTS:
8
9 Implementation of class ConfigFileFrontEndApp.
10
11 NOTES:
12
13 See notes of ConfigFileFrontEndApp.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 2.1.0
30
31 CHANGES:
32
33 Mon Oct 30 14:23:13 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 ConfigFileFrontEndApp class.
48 */
49
50
51
52
53
54 /*
55 ================================================================================
56 Includes
57 ================================================================================
58 */
59 // JEGAConfig.hpp should be the first include in all JEGA files.
60 #include <../Utilities/include/JEGAConfig.hpp>
61
62 #include <map>
63 #include <memory>
64 #include <vector>
65 #include <fstream>
66 #include <iostream>
67 #include <iterator>
68 #include <algorithm>
69 #include <Evaluators/ExternalEvaluator.hpp>
70 #include <../Utilities/include/JEGATypes.hpp>
71 #include <../FrontEnd/Core/include/Driver.hpp>
72 #include <utilities/include/EDDY_DebugScope.hpp>
73 #include <../Utilities/include/ConstraintInfo.hpp>
74 #include <../Utilities/include/DesignMultiSet.hpp>
75 #include <../FrontEnd/Core/include/ConfigHelper.hpp>
76 #include <../FrontEnd/Core/include/ProblemConfig.hpp>
77 #include <../Utilities/include/DesignVariableInfo.hpp>
78 #include <../FrontEnd/Core/include/AlgorithmConfig.hpp>
79 #include <../Utilities/include/BasicParameterDatabaseImpl.hpp>
80 #include <../FrontEnd/Core/include/GenericEvaluatorCreator.hpp>
81 #include <../FrontEnd/ConfigFile/include/ConfigFileFrontEndApp.hpp>
82
83 #include <boost/mpl/at.hpp>
84 #include <boost/tuple/tuple.hpp>
85 #include <boost/mpl/map/map40.hpp>
86 #include <boost/program_options.hpp>
87
88 #include <boost/preprocessor/tuple/elem.hpp>
89 #include <boost/preprocessor/control/if.hpp>
90 #include <boost/preprocessor/repetition/for.hpp>
91 #include <boost/preprocessor/arithmetic/inc.hpp>
92 #include <boost/preprocessor/comparison/equal.hpp>
93 #include <boost/preprocessor/facilities/empty.hpp>
94 #include <boost/preprocessor/punctuation/comma.hpp>
95 #include <boost/preprocessor/comparison/not_equal.hpp>
96 #include <boost/preprocessor/repetition/enum_params.hpp>
97
98
99 /*
100 ================================================================================
101 Namespace Using Directives
102 ================================================================================
103 */
104 using namespace std;
105
106 using namespace boost;
107 using namespace boost::tuples;
108 using namespace boost::program_options;
109
110 using namespace JEGA;
111 using namespace JEGA::Logging;
112 using namespace JEGA::FrontEnd;
113 using namespace JEGA::Utilities;
114 using namespace JEGA::Algorithms;
115
116 namespace bt = boost::tuples;
117
118 /*
119 ================================================================================
120 Options Map Macros
121 ================================================================================
122 */
123 /// A macro to resolve to the type tags used in the lookup map of option types.
124 /**
125 * Currently, this is done using character arrays of varying size.
126 *
127 * \param tag The tag for the size value for the character array to be created.
128 */
129 #define CFFE_CHVEC(tag) char[IXS::tag]
130
131 /// A macro to shorten the syntax of a retrieval from the all_opt_types map.
132 /**
133 * \param tag The tag the type in the all_opt_types map.
134 * \return Resolves to the type associated with the supplied index.
135 */
136 #define CFFE_TYPEOF(tag) mpl::at<all_opt_types, CFFE_CHVEC(tag)>::type
137
138 /// A macro to retrieve a variable value from the variables map.
139 /**
140 * This returns the actual reference to a value, not a
141 * boost::program_options::variable_value.
142 *
143 * \param tag The tag used to get the index in the all_opt_types map and the
144 * string name of the option value of interest.
145 * \return The value provided on the command line and/or in a config file for
146 * option identified by \a tag.
147 */
148 #define CFFE_GETVAR(tag) GetValueOf<CFFE_TYPEOF(tag)>(ITS::tag)
149
150
151
152 /*
153 ================================================================================
154 Pre-Namespace File Scope Typedefs
155 ================================================================================
156 */
157
158
159
160
161
162
163 /*
164 ================================================================================
165 Global Utility Functions
166 ================================================================================
167 */
168
169 // This just might take the stupid cake. It seems that in order for the vc80
170 // compiler to handle these stream insertion/extraction operators properly,
171 // they must be put in the std namespace. Global scope does not work and
172 // neither does inside the JEGA namespaces.
173 namespace std {
174
175 /// Eats all leading whitespace off the supplied input stream and returns it.
176 /**
177 * \param stream The stream from which to remove all leading whitespace.
178 * \return The stream after all leading whitespace has been removed.
179 */
180 inline
181 istream&
eat_white(istream & stream)182 eat_white(
183 istream& stream
184 )
185 {
186 EDDY_FUNC_DEBUGSCOPE
187 while(!stream.eof() && ::isspace(stream.peek())) stream.ignore();
188 return stream;
189 }
190
191 /// Replaces all occurrences of "&lb" with the pound (#) character.
192 /**
193 * \param in The string in which to do the replacing.
194 * \return The supplied \a in string is returned for convenience.
195 */
196 string&
process_pounds(string & in)197 process_pounds(
198 string& in
199 )
200 {
201 static const char* lbstr = "&lb";
202 string::size_type next(in.find(lbstr));
203
204 while(next != string::npos)
205 {
206 in.replace(next, 3, "#");
207 next = in.find(lbstr, next+1);
208 }
209
210 return in;
211 }
212
213 /// Reads a variable in from an input stream and stores it in \a into.
214 /**
215 * The default implementation is to simply use the stream extraction operator
216 * >> to read and store the value. See any specializations provided for any
217 * different behaviors.
218 *
219 * \param stream The input stream from which to read a value.
220 * \param into The variable in which to store the read in value.
221 * \return The supplied stream after extraction of the variable.
222 */
223 template <typename T>
224 inline
225 istream&
read(istream & stream,T & into)226 read(
227 istream& stream,
228 T& into
229 )
230 {
231 EDDY_FUNC_DEBUGSCOPE
232 return stream >> into;
233 }
234
235 /// A specialization of the read template for std::strings.
236 /**
237 * This specialization will account for the possibility that the string may
238 * contains spaces if enclosed in quotation marks. It also allows for the
239 * inclusion of quotation marks if they are escaped (\").
240 *
241 * \param stream The input stream from which to read a value.
242 * \param into The string in which to store the read in value.
243 * \return The supplied stream after extraction of the string.
244 */
245 template <>
246 istream&
read(istream & stream,string & into)247 read<string>(
248 istream& stream,
249 string& into
250 )
251 {
252 EDDY_FUNC_DEBUGSCOPE
253
254 eat_white(stream);
255
256 // if the first char is a ", then read until the next ". Otherwise,
257 // do a regular string read.
258 if(stream.peek() != '\"') stream >> into;
259
260 else
261 {
262 // if we get here, we found a ". Now we must read up to and pop off
263 // the next ". start by ignoring the current "
264 stream.ignore();
265
266 // now start reading. Watch for the \" sequence which is a literal ".
267 char last = '\0';
268 while(!stream.eof())
269 {
270 const char next = stream.peek();
271
272 // if we found a " and it is not escaped, we are done.
273 if(next == '\"' && last != '\\') { stream.ignore(); break; }
274
275 // if we make it here and last is an escape, then we will put it in
276 // since we only heed it in front of ".
277 if(last == '\\') into.push_back(last);
278
279 // no matter what at this point, we put in next which we will obtain
280 // with a get to move past it.
281 into.push_back(stream.get());
282
283 // now update our last.
284 last = next;
285 }
286 }
287
288 // process any # indicators.
289 process_pounds(into);
290
291 return stream;
292 }
293
294 /// A specialization of the read template for bools.
295 /**
296 * This specialization will read the input as a string (not using the read
297 * specialization for strings, just using the std::operator >>) and then see
298 * if it is a valid representation for a Boolean. Valid representations for
299 * true include "t", "true", and "1" (case insensitive). Valid representations
300 * for false include "f", "false", and "0", also case insensitive. If a
301 * representation other than any of these is provided, then an exception is
302 * thrown.
303 *
304 * \param stream The input stream from which to read a value.
305 * \param into The Boolean in which to store the read in value.
306 * \return The supplied stream after extraction of the Boolean.
307 */
308 template <>
309 istream&
read(istream & stream,bool & into)310 read<bool>(
311 istream& stream,
312 bool& into
313 )
314 {
315 EDDY_FUNC_DEBUGSCOPE
316
317 // do this the brute force way.
318 string temp;
319 stream >> temp;
320 string orig(temp);
321 transform(temp.begin(), temp.end(), temp.begin(), &::tolower);
322 if (temp == "t" || temp == "true" || temp == "1") into = true;
323 else if(temp == "f" || temp == "false" || temp == "0") into = false;
324 else throw runtime_error(
325 "Unrecognized input for Boolean \"" + orig + "\"."
326 );
327 return stream;
328 }
329
330 /// Writes a variable into a supplied output stream.
331 /**
332 * The default implementation is to simply use the stream insertion operator
333 * << to write the value. See any specializations provided for any
334 * different behaviors.
335 *
336 * \param stream The output stream into which to write a value.
337 * \param t The value to write into the \a stream.
338 * \return The supplied stream after insertion of the variable.
339 */
340 template <typename T>
341 inline
342 ostream&
write(ostream & stream,const T & t)343 write(
344 ostream& stream,
345 const T& t
346 )
347 {
348 EDDY_FUNC_DEBUGSCOPE
349 return stream << t;
350 }
351
352 /// A specialization of the write template for strings.
353 /**
354 * This specialization writes the string wrapped in quotation marks and any
355 * quotation marks that are already in the string are escaped.
356 *
357 * \param stream The output stream into which to write a string.
358 * \param str The string to write into the \a stream.
359 * \return The supplied stream after insertion of the string.
360 */
361 template<>
362 ostream&
write(ostream & stream,const string & str)363 write<string>(
364 ostream& stream,
365 const string& str
366 )
367 {
368 EDDY_FUNC_DEBUGSCOPE
369 stream << '\"';
370 // replace all " with \" and write it out wrapped in quotes.
371 for(string::const_iterator it(str.begin()); it!=str.end(); ++it) {
372 if(*it == '\"') stream << '\\';
373 stream << *it;
374 }
375
376 return stream << '\"';
377 }
378
379 /// A specialization of the write template for bools.
380 /**
381 * This specialization writes bools as alpha (boolalpha) but returns the stream
382 * to non-boolalpha if that is what it was prior to this call.
383 *
384 * \param stream The output stream into which to write a bool.
385 * \param str The bool to write into the \a stream.
386 * \return The supplied stream after insertion of the bool.
387 */
388 template<>
389 ostream&
write(ostream & stream,const bool & str)390 write<bool>(
391 ostream& stream,
392 const bool& str
393 )
394 {
395 EDDY_FUNC_DEBUGSCOPE
396
397 // see if the supplied stream is boolalpha.
398 bool isba = (stream.flags() & ios_base::boolalpha) != 0;
399
400 // if it is not, make it for now.
401 if(!isba) boolalpha(stream);
402
403 // now write our data.
404 stream << str;
405
406 // now set it back to noboolalpha if appropriate.
407 if(!isba) noboolalpha(stream);
408
409 // now return our stream
410 return stream;
411 }
412
413 /**
414 * \brief A predicate for preprocessor enumerations that progress from some
415 * lower bound integral value to an upper bound such as when using
416 * BOOST_PP_FOR with a tuple.
417 *
418 * \param r Not Used.
419 * \param state The current enumeration value.
420 */
421 #define ENUM_PRED(r, state) \
422 BOOST_PP_NOT_EQUAL( \
423 BOOST_PP_TUPLE_ELEM(2, 0, state), \
424 BOOST_PP_TUPLE_ELEM(2, 1, state) \
425 )
426
427 /**
428 * \brief An operator for preprocessor enumerations that progress from some
429 * lower bound integral value to an upper bound such as when using
430 * BOOST_PP_FOR with a tuple.
431 *
432 * \param r Not Used.
433 * \param state The current enumeration value.
434 */
435 #define ENUM_OP(r, state) \
436 ( \
437 BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 0, state)), \
438 BOOST_PP_TUPLE_ELEM(2, 1, state) \
439 )
440
441 #define WRITE(r, state) \
442 write(stream, p.get< BOOST_PP_TUPLE_ELEM(2, 0, state) >()) \
443 BOOST_PP_IF(BOOST_PP_EQUAL( \
444 BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 0, state)), \
445 BOOST_PP_TUPLE_ELEM(2, 1, state) \
446 ), ;, << " "; )
447
448 #define READ(r, state) \
449 read (stream, p.get< BOOST_PP_TUPLE_ELEM(2, 0, state) >()) \
450 BOOST_PP_IF(BOOST_PP_EQUAL( \
451 BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 0, state)), \
452 BOOST_PP_TUPLE_ELEM(2, 1, state) \
453 ), ;, >> eat_white; )
454
455 #define TUPLE_STREAM_INSERT(N) \
456 template < BOOST_PP_ENUM_PARAMS(N, typename T) > \
457 inline ostream& operator << ( \
458 ostream& stream, \
459 const bt::tuple< BOOST_PP_ENUM_PARAMS(N, T) >& p \
460 ) { \
461 EDDY_FUNC_DEBUGSCOPE \
462 BOOST_PP_FOR((0, N), ENUM_PRED, ENUM_OP, WRITE) \
463 return stream; \
464 }
465
466 #define TUPLE_STREAM_EXTRACT(N) \
467 template < BOOST_PP_ENUM_PARAMS(N, typename T) > \
468 inline istream& operator >> ( \
469 istream& stream, \
470 bt::tuple< BOOST_PP_ENUM_PARAMS(N, T) >& p \
471 ) { \
472 EDDY_FUNC_DEBUGSCOPE \
473 BOOST_PP_FOR((0, N), ENUM_PRED, ENUM_OP, READ) \
474 return stream; \
475 }
476
477 /// The stream insertion for a 5-tuple
478 TUPLE_STREAM_INSERT(5)
479 /// The stream insertion for a 4-tuple
480 TUPLE_STREAM_INSERT(4)
481 /// The stream insertion for a 3-tuple
482 TUPLE_STREAM_INSERT(3)
483 /// The stream insertion for a 2-tuple
484 TUPLE_STREAM_INSERT(2)
485
486 /// The stream extraction for a 5-tuple
487 TUPLE_STREAM_EXTRACT(5)
488 /// The stream extraction for a 4-tuple
489 TUPLE_STREAM_EXTRACT(4)
490 /// The stream extraction for a 3-tuple
491 TUPLE_STREAM_EXTRACT(3)
492 /// The stream extraction for a 2-tuple
493 TUPLE_STREAM_EXTRACT(2)
494
495 // Keep the pred and op for further use.
496 //#undef ENUM_PRED
497 //#undef ENUM_OP
498 #undef WRITE
499 #undef READ
500 #undef TUPLE_STREAM_INSERT
501 #undef TUPLE_STREAM_EXTRACT
502
503 /**
504 * \brief This stream insertion operator writes each element of a vector of
505 * T on a separate line.
506 *
507 * \param stream The stream into which to write the vector elements.
508 * \param vec The vector whose elements are to be written into the stream.
509 */
510 template <typename T>
511 ostream&
operator <<(ostream & stream,const vector<T> & vec)512 operator << (
513 ostream& stream,
514 const vector<T>& vec
515 )
516 {
517 EDDY_FUNC_DEBUGSCOPE
518 if(vec.empty()) return stream;
519 write(stream, *vec.begin());
520 for(typename vector<T>::const_iterator it(++vec.begin());
521 it!=vec.end(); ++it) write(stream << '\n', *it);
522 return stream;
523 }
524
525 /**
526 * \brief This stream insertion operator reads each element of a vector of T.
527 *
528 * The elements must be delimited by whitespace.
529 *
530 * \param stream The stream from which to read the vector elements.
531 * \param vec The vector into which to store the read elements.
532 */
533 template <typename T>
534 istream&
operator >>(istream & stream,vector<T> & vec)535 operator >> (
536 istream& stream,
537 vector<T>& vec
538 )
539 {
540 EDDY_FUNC_DEBUGSCOPE
541 if(stream.eof()) return stream;
542 for(T temp; !stream.eof(); eat_white(stream)) {
543 if(!(read(stream, temp))) return stream;
544 vec.push_back(temp);
545 }
546 return stream;
547 }
548
549 } // namespace std
550
551
552 /*
553 ================================================================================
554 Begin Namespace
555 ================================================================================
556 */
557 namespace JEGA {
558 namespace FrontEnd {
559 namespace ConfigFile {
560
561
562
563 class ConfigFileFrontEndApp::InputDescriptors
564 {
565 /*
566 ============================================================================
567 Nested Inner Class Forward Declares
568 ============================================================================
569 */
570 public:
571
572 class Indices;
573 class InputTags;
574 class DefaultValues;
575
576 }; // class ConfigFileFrontEndApp::InputDescriptors
577
578 /// A shorthand for the input description type map indices.
579 typedef ConfigFileFrontEndApp::InputDescriptors::Indices IXS;
580
581 /// A shorthand for the input description name tags.
582 typedef ConfigFileFrontEndApp::InputDescriptors::InputTags ITS;
583
584 /// A shorthand for the default values of the inputs.
585 typedef ConfigFileFrontEndApp::InputDescriptors::DefaultValues DVS;
586
587 class ConfigFileFrontEndApp::InputDescriptors::Indices
588 {
589 /*
590 ============================================================================
591 Member Data Declarations
592 ============================================================================
593 */
594 public:
595
596 /**
597 * \brief A general purpose constant for the (very common) case where
598 * the input is a simple, single string.
599 */
600 static const char _plainString;
601
602 /// The constant used to identify the configuration filename input.
603 static const char _cfgFile;
604
605 /// The constant used to identify the help request input.
606 static const char _help;
607
608 /// The constant used to identify the version request input.
609 static const char _version;
610
611 static const char _assessor ;
612 static const char _initializer ;
613 static const char _mutator ;
614 static const char _crosser ;
615 static const char _nicher ;
616 static const char _postprocessor;
617 static const char _mainloop ;
618 static const char _selector ;
619 static const char _converger ;
620
621 static const char _intParams ;
622 static const char _dblParams ;
623 static const char _sztParams ;
624 static const char _boolParams ;
625 static const char _strParams ;
626 static const char _intVecParams;
627 static const char _dblVecParams;
628 static const char _strVecParams;
629 static const char _dblMatParams;
630
631 static const char _rndSeed ;
632 static const char _globLogFile ;
633 static const char _globLogLevel;
634 static const char _algType ;
635
636 static const char _contRealVar;
637 static const char _discRealVar;
638 static const char _contIntVar ;
639 static const char _discIntVar ;
640 static const char _boolVar ;
641 static const char _varBounds ;
642 static const char _varDiscVals;
643
644 static const char _linMinObj ;
645 static const char _nonLinMinObj ;
646 static const char _linMaxObj ;
647 static const char _nonLinMaxObj ;
648 static const char _linSkValObj ;
649 static const char _nonLinSkValObj;
650 static const char _linSkRngObj ;
651 static const char _nonLinSkRngObj;
652
653 static const char _linInEqCon ;
654 static const char _nonLinInEqCon ;
655 static const char _linEqCon ;
656 static const char _nonLinEqCon ;
657 static const char _linTwoSideIneqCon ;
658 static const char _nonLinTwoSideIneqCon;
659 static const char _linNotEqCon ;
660 static const char _nonLinNotEqCon ;
661
662
663 }; // class ConfigFileFrontEndApp::InputDescriptors::Indices
664
665 const char IXS::_plainString (0);
666
667 const char IXS::_cfgFile (IXS::_plainString);
668 const char IXS::_help (IXS::_plainString);
669 const char IXS::_version (IXS::_plainString);
670
671 const char IXS::_assessor (IXS::_plainString);
672 const char IXS::_initializer (IXS::_plainString);
673 const char IXS::_mutator (IXS::_plainString);
674 const char IXS::_crosser (IXS::_plainString);
675 const char IXS::_nicher (IXS::_plainString);
676 const char IXS::_postprocessor (IXS::_plainString);
677 const char IXS::_selector (IXS::_plainString);
678 const char IXS::_mainloop (IXS::_plainString);
679 const char IXS::_converger (IXS::_plainString);
680
681 const char IXS::_intParams (IXS::_plainString + 1);
682 const char IXS::_dblParams (IXS::_intParams + 1);
683 const char IXS::_sztParams (IXS::_dblParams + 1);
684 const char IXS::_boolParams (IXS::_sztParams + 1);
685 const char IXS::_strParams (IXS::_boolParams + 1);
686 const char IXS::_intVecParams (IXS::_strParams + 1);
687 const char IXS::_dblVecParams (IXS::_intVecParams + 1);
688 const char IXS::_strVecParams (IXS::_dblVecParams + 1);
689 const char IXS::_dblMatParams (IXS::_strVecParams + 1);
690
691 const char IXS::_rndSeed (IXS::_dblMatParams + 1 );
692 const char IXS::_globLogFile (IXS::_plainString );
693 const char IXS::_globLogLevel (IXS::_plainString );
694 const char IXS::_algType (IXS::_plainString );
695
696 const char IXS::_contRealVar (IXS::_rndSeed + 1);
697 const char IXS::_discRealVar (IXS::_contRealVar + 1);
698 const char IXS::_contIntVar (IXS::_discRealVar + 1);
699 const char IXS::_discIntVar (IXS::_contIntVar + 1);
700 const char IXS::_boolVar (IXS::_discIntVar + 1);
701
702 const char IXS::_linMinObj (IXS::_boolVar + 1);
703 const char IXS::_nonLinMinObj (IXS::_linMinObj + 1);
704 const char IXS::_linMaxObj (IXS::_nonLinMinObj + 1);
705 const char IXS::_nonLinMaxObj (IXS::_linMaxObj + 1);
706 const char IXS::_linSkValObj (IXS::_nonLinMaxObj + 1);
707 const char IXS::_nonLinSkValObj (IXS::_linSkValObj + 1);
708 const char IXS::_linSkRngObj (IXS::_nonLinSkValObj + 1);
709 const char IXS::_nonLinSkRngObj (IXS::_linSkRngObj + 1);
710
711 const char IXS::_linInEqCon (IXS::_nonLinSkRngObj + 1);
712 const char IXS::_nonLinInEqCon (IXS::_linInEqCon + 1);
713 const char IXS::_linEqCon (IXS::_nonLinInEqCon + 1);
714 const char IXS::_nonLinEqCon (IXS::_linEqCon + 1);
715 const char IXS::_linTwoSideIneqCon (IXS::_nonLinEqCon + 1);
716 const char IXS::_nonLinTwoSideIneqCon (IXS::_linTwoSideIneqCon + 1);
717 const char IXS::_linNotEqCon (IXS::_nonLinTwoSideIneqCon + 1);
718 const char IXS::_nonLinNotEqCon (IXS::_linNotEqCon + 1);
719
720 /**
721 *\brief The map that stores input option types keyed on character arrays of
722 * the size specified by the index tag of the option.
723 */
724 typedef mpl::map32<
725
726 // A reusable type entry for all inputs that are simple, unnamed strings.
727 mpl::pair<CFFE_CHVEC(_plainString),
728 // string - The string value of the corresponding input.
729 string
730 >,
731
732 // An entry for all inputs that are named integral parameters.
733 mpl::pair<CFFE_CHVEC(_intParams),
734 // string - The name of the integer parameter
735 // int - The value of the integer parameter
736 vector<bt::tuple<string, int> >
737 >,
738
739 // An entry for all inputs that are named double parameters.
740 mpl::pair<CFFE_CHVEC(_dblParams),
741 // string - The name of the double parameter
742 // double - The value of the double parameter
743 vector<bt::tuple<string, double> >
744 >,
745
746 // An entry for all inputs that are named size-type parameters.
747 mpl::pair<CFFE_CHVEC(_sztParams),
748 // string - The name of the size_t parameter
749 // size_t - The value of the size_t parameter
750 vector<bt::tuple<string, size_t> >
751 >,
752
753 // An entry for all inputs that are named Boolean parameters.
754 mpl::pair<CFFE_CHVEC(_boolParams),
755 // string - The name of the Boolean parameter
756 // bool - The value of the Boolean parameter
757 vector<bt::tuple<string, bool> >
758 >, // 5
759
760 // An entry for all inputs that are named string parameters.
761 mpl::pair<CFFE_CHVEC(_strParams),
762 // string - The name of the string parameter
763 // string - The value of the string parameter
764 vector<bt::tuple<string, string> >
765 >,
766
767 // An entry for all inputs that are named integer vector parameters.
768 mpl::pair<CFFE_CHVEC(_intVecParams),
769 // string - The name of the int vector parameter
770 // IntVector - The vector of values of the int vector parameter
771 vector<bt::tuple<string, IntVector> >
772 >,
773
774 // An entry for all inputs that are named double vector parameters.
775 mpl::pair<CFFE_CHVEC(_dblVecParams),
776 // string - The name of the double vector parameter
777 // DoubleVector - The vector of values of the double vector parameter
778 vector<bt::tuple<string, DoubleVector> >
779 >,
780
781 // An entry for all inputs that are named string vector parameters.
782 mpl::pair<CFFE_CHVEC(_strVecParams),
783 // string - The name of the string vector parameter
784 // StringVector - The vector of values of the string vector parameter
785 vector<bt::tuple<string, StringVector> >
786 >,
787
788 // An entry for all inputs that are named double matrix parameters.
789 mpl::pair<CFFE_CHVEC(_dblMatParams),
790 // string - The name of the double matrix parameter for which this is
791 // a row
792 // DoubleVector - The vector of values of the row of this double matrix
793 // parameter
794 vector<bt::tuple<string, DoubleVector> >
795 >, // 10
796
797 // An entry for the type of the random seed input.
798 mpl::pair<CFFE_CHVEC(_rndSeed),
799 // size_t - The value for the random number generator seed.
800 size_t
801 >,
802
803 // An entry for all inputs that describe a continuous real variable.
804 mpl::pair<CFFE_CHVEC(_contRealVar),
805 // size_t - The zero based index of this variable.
806 // string - The label for the new variable.
807 // double - The lower bound on the range of this variable.
808 // double - The upper bound on the range of this variable.
809 // int - The desired decimal precision of this real variable.
810 vector<bt::tuple<size_t, string, double, double, int> >
811 >,
812
813 // An entry for all inputs that describe a discrete real variable.
814 mpl::pair<CFFE_CHVEC(_discRealVar),
815 // size_t - The zero based index of this variable.
816 // string - The label for the new variable.
817 // DoubleVector - The vector of discrete values for this variable.
818 vector<bt::tuple<size_t, string, DoubleVector> >
819 >,
820
821 // An entry for all inputs that describe a continuous integer variable.
822 mpl::pair<CFFE_CHVEC(_contIntVar),
823 // size_t - The zero based index of this variable.
824 // string - The label for the new variable.
825 // int - The lower bound on the range of this variable.
826 // int - The upper bound on the range of this variable.
827 vector<bt::tuple<size_t, string, int, int> >
828 >,
829
830 // An entry for all inputs that describe a discrete integer variable.
831 mpl::pair<CFFE_CHVEC(_discIntVar),
832 // size_t - The zero based index of this variable.
833 // string - The label for the new variable.
834 // IntVector - The vector of discrete values for this variable.
835 vector<bt::tuple<size_t, string, IntVector> >
836 >, // 15
837
838 // An entry for all inputs that describe a Boolean variable.
839 mpl::pair<CFFE_CHVEC(_boolVar),
840 // size_t - The zero based index of this variable.
841 // string - The label for the new variable.
842 vector<bt::tuple<size_t, string> >
843 >,
844
845 // An entry for all inputs that describe a linear minimization objective.
846 mpl::pair<CFFE_CHVEC(_linMinObj),
847 // size_t - The zero based index of this objective.
848 // string - The label for the new objective.
849 // DoubleVector - The vector of variable coefficients used to evaluate
850 // this linear function.
851 vector<bt::tuple<size_t, string, DoubleVector> >
852 >,
853
854 // An entry for all inputs that describe a nonlinear minimization
855 // objective.
856 mpl::pair<CFFE_CHVEC(_nonLinMinObj),
857 // size_t - The zero based index of this objective.
858 // string - The label for the new objective.
859 vector<bt::tuple<size_t, string> >
860 >,
861
862 // An entry for all inputs that describe a linear maximization objective.
863 mpl::pair<CFFE_CHVEC(_linMaxObj),
864 // size_t - The zero based index of this objective.
865 // string - The label for the new objective.
866 // DoubleVector - The vector of variable coefficients used to evaluate
867 // this linear function.
868 vector<bt::tuple<size_t, string, DoubleVector> >
869 >,
870
871 // An entry for all inputs that describe a nonlinear maximization
872 // objective.
873 mpl::pair<CFFE_CHVEC(_nonLinMaxObj),
874 // size_t - The zero based index of this objective.
875 // string - The label for the new objective.
876 vector<bt::tuple<size_t, string> >
877 >, // 20
878
879 // An entry for all inputs that describe a linear seek value objective.
880 mpl::pair<CFFE_CHVEC(_linSkValObj),
881 // size_t - The zero based index of this objective.
882 // string - The label for the new objective.
883 // double - The value being sought by the objective.
884 // DoubleVector - The vector of variable coefficients used to evaluate
885 // this linear function.
886 vector<bt::tuple<size_t, string, obj_val_t, DoubleVector> >
887 >,
888
889 // An entry for all inputs that describe a nonlinear seek value objective.
890 mpl::pair<CFFE_CHVEC(_nonLinSkValObj),
891 // size_t - The zero based index of this objective.
892 // string - The label for the new objective.
893 // double - The value being sought by the objective.
894 vector<bt::tuple<size_t, string, obj_val_t> >
895 >,
896
897 // An entry for all inputs that describe a linear seek range objective.
898 mpl::pair<CFFE_CHVEC(_linSkRngObj),
899 // size_t - The zero based index of this objective.
900 // string - The label for the new objective.
901 // double - The lower bound on the range sought by this objective.
902 // double - The upper bound on the range sought by this objective.
903 // DoubleVector - The vector of variable coefficients used to evaluate
904 // this linear function.
905 vector<bt::tuple<size_t, string, obj_val_t, obj_val_t, DoubleVector> >
906 >,
907
908 // An entry for all inputs that describe a nonlinear seek range objective.
909 mpl::pair<CFFE_CHVEC(_nonLinSkRngObj),
910 // size_t - The zero based index of this objective.
911 // string - The label for the new objective.
912 // double - The lower bound on the range sought by this objective.
913 // double - The upper bound on the range sought by this objective.
914 vector<bt::tuple<size_t, string, obj_val_t, obj_val_t> >
915 >,
916
917 // An entry for all inputs that describe a linear inequality constraint.
918 mpl::pair<CFFE_CHVEC(_linInEqCon),
919 // size_t - The zero based index of this constraint.
920 // string - The label for the new constraint.
921 // double - The upper limiting value for this constraint function.
922 // DoubleVector - The vector of variable coefficients used to evaluate
923 // this linear function.
924 vector<bt::tuple<size_t, string, con_val_t, DoubleVector> >
925 >, // 25
926
927 // An entry for all inputs that describe a nonlinear inequality constraint.
928 mpl::pair<CFFE_CHVEC(_nonLinInEqCon),
929 // size_t - The zero based index of this constraint.
930 // string - The label for the new constraint.
931 // double - The upper limiting value for this constraint function.
932 vector<bt::tuple<size_t, string, con_val_t> >
933 >,
934
935 // An entry for all inputs that describe a linear equality constraint.
936 mpl::pair<CFFE_CHVEC(_linEqCon),
937 // size_t - The zero based index of this constraint.
938 // string - The label for the new constraint.
939 // double - The target value for this constraint function.
940 // double - The allowable violation from target value for this
941 // constraint function.
942 // DoubleVector - The vector of variable coefficients used to evaluate
943 // this linear function.
944 vector<bt::tuple<size_t, string, con_val_t, double, DoubleVector> >
945 >,
946
947 // An entry for all inputs that describe a nonlinear equality constraint.
948 mpl::pair<CFFE_CHVEC(_nonLinEqCon),
949 // size_t - The zero based index of this constraint.
950 // string - The label for the new constraint.
951 // double - The target value for this constraint function.
952 // double - The allowable violation from target value for this
953 // constraint function.
954 vector<bt::tuple<size_t, string, con_val_t, double> >
955 >,
956
957 // An entry for all inputs that describe a linear 2-sided inequality
958 // constraint.
959 mpl::pair<CFFE_CHVEC(_linTwoSideIneqCon),
960 // size_t - The zero based index of this constraint.
961 // string - The label for the new constraint.
962 // double - The lower limiting value for this constraint function.
963 // double - The upper limiting value for this constraint function.
964 // DoubleVector - The vector of variable coefficients used to evaluate
965 // this linear function.
966 vector<bt::tuple<size_t, string, con_val_t, con_val_t, DoubleVector> >
967 >,
968
969 // An entry for all inputs that describe a nonlinear 2-sided inequality
970 // constraint.
971 mpl::pair<CFFE_CHVEC(_nonLinTwoSideIneqCon),
972 // size_t - The zero based index of this constraint.
973 // string - The label for the new constraint.
974 // double - The lower limiting value for this constraint function.
975 // double - The upper limiting value for this constraint function.
976 vector<bt::tuple<size_t, string, con_val_t, con_val_t> >
977 >, // 30
978
979 // An entry for all inputs that describe a linear not-equality constraint.
980 mpl::pair<CFFE_CHVEC(_linNotEqCon),
981 // size_t - The zero based index of this constraint.
982 // string - The label for the new constraint.
983 // double - The taboo value for this constraint function.
984 // DoubleVector - The vector of variable coefficients used to evaluate
985 // this linear function.
986 vector<bt::tuple<size_t, string, con_val_t, DoubleVector> >
987 >,
988
989 // An entry for all inputs that describe a nonlinear not-equality
990 // constraint.
991 mpl::pair<CFFE_CHVEC(_nonLinNotEqCon),
992 // size_t - The zero based index of this constraint.
993 // string - The label for the new constraint.
994 // double - The taboo value for this constraint function.
995 vector<bt::tuple<size_t, string, con_val_t> >
996 >
997 >
998 all_opt_types;
999
1000
1001 class ConfigFileFrontEndApp::InputDescriptors::InputTags
1002 {
1003 /*
1004 ============================================================================
1005 Member Data Declarations
1006 ============================================================================
1007 */
1008 public:
1009
1010 static const string _cfgFile;
1011 static const string _help ;
1012 static const string _version;
1013
1014 static const string _assessor ;
1015 static const string _initializer ;
1016 static const string _mutator ;
1017 static const string _crosser ;
1018 static const string _nicher ;
1019 static const string _postprocessor;
1020 static const string _mainloop ;
1021 static const string _selector ;
1022 static const string _converger ;
1023
1024 static const string _intParams ;
1025 static const string _dblParams ;
1026 static const string _sztParams ;
1027 static const string _boolParams ;
1028 static const string _strParams ;
1029 static const string _intVecParams;
1030 static const string _dblVecParams;
1031 static const string _strVecParams;
1032 static const string _dblMatParams;
1033
1034 static const string _rndSeed ;
1035 static const string _globLogFile ;
1036 static const string _globLogLevel;
1037 static const string _algType ;
1038
1039 static const string _contRealVar;
1040 static const string _discRealVar;
1041 static const string _contIntVar ;
1042 static const string _discIntVar ;
1043 static const string _boolVar ;
1044 static const string _varBounds ;
1045 static const string _varDiscVals;
1046
1047 static const string _linMinObj ;
1048 static const string _nonLinMinObj ;
1049 static const string _linMaxObj ;
1050 static const string _nonLinMaxObj ;
1051 static const string _linSkValObj ;
1052 static const string _nonLinSkValObj;
1053 static const string _linSkRngObj ;
1054 static const string _nonLinSkRngObj;
1055
1056 static const string _linInEqCon ;
1057 static const string _nonLinInEqCon ;
1058 static const string _linEqCon ;
1059 static const string _nonLinEqCon ;
1060 static const string _linTwoSideIneqCon ;
1061 static const string _nonLinTwoSideIneqCon;
1062 static const string _linNotEqCon ;
1063 static const string _nonLinNotEqCon ;
1064
1065 static const string _dummyTag;
1066
1067 }; // class ConfigFileFrontEndApp::InputDescriptors::InputTags
1068
1069 class ConfigFileFrontEndApp::InputDescriptors::DefaultValues
1070 {
1071 /*
1072 ============================================================================
1073 Member Data Declarations
1074 ============================================================================
1075 */
1076 public:
1077
1078 static const CFFE_TYPEOF(_cfgFile ) _cfgFile;
1079 static const CFFE_TYPEOF(_help ) _help ;
1080 static const CFFE_TYPEOF(_version ) _version;
1081
1082 static const CFFE_TYPEOF(_assessor ) _assessor ;
1083 static const CFFE_TYPEOF(_initializer ) _initializer ;
1084 static const CFFE_TYPEOF(_mutator ) _mutator ;
1085 static const CFFE_TYPEOF(_crosser ) _crosser ;
1086 static const CFFE_TYPEOF(_nicher ) _nicher ;
1087 static const CFFE_TYPEOF(_postprocessor ) _postprocessor;
1088 static const CFFE_TYPEOF(_mainloop ) _mainloop ;
1089 static const CFFE_TYPEOF(_selector ) _selector ;
1090 static const CFFE_TYPEOF(_converger ) _converger ;
1091
1092 static const CFFE_TYPEOF(_intParams ) _intParams ;
1093 static const CFFE_TYPEOF(_dblParams ) _dblParams ;
1094 static const CFFE_TYPEOF(_sztParams ) _sztParams ;
1095 static const CFFE_TYPEOF(_boolParams ) _boolParams ;
1096 static const CFFE_TYPEOF(_strParams ) _strParams ;
1097 static const CFFE_TYPEOF(_intVecParams ) _intVecParams;
1098 static const CFFE_TYPEOF(_dblVecParams ) _dblVecParams;
1099 static const CFFE_TYPEOF(_strVecParams ) _strVecParams;
1100 static const CFFE_TYPEOF(_dblMatParams ) _dblMatParams;
1101
1102 static const CFFE_TYPEOF(_rndSeed ) _rndSeed ;
1103 static const CFFE_TYPEOF(_globLogFile ) _globLogFile ;
1104 static const CFFE_TYPEOF(_globLogLevel ) _globLogLevel;
1105 static const CFFE_TYPEOF(_algType ) _algType ;
1106
1107 static const CFFE_TYPEOF(_contRealVar ) _contRealVar;
1108 static const CFFE_TYPEOF(_discRealVar ) _discRealVar;
1109 static const CFFE_TYPEOF(_contIntVar ) _contIntVar ;
1110 static const CFFE_TYPEOF(_discIntVar ) _discIntVar ;
1111 static const CFFE_TYPEOF(_boolVar ) _boolVar ;
1112
1113 static const CFFE_TYPEOF(_linMinObj ) _linMinObj ;
1114 static const CFFE_TYPEOF(_nonLinMinObj ) _nonLinMinObj ;
1115 static const CFFE_TYPEOF(_linMaxObj ) _linMaxObj ;
1116 static const CFFE_TYPEOF(_nonLinMaxObj ) _nonLinMaxObj ;
1117 static const CFFE_TYPEOF(_linSkValObj ) _linSkValObj ;
1118 static const CFFE_TYPEOF(_nonLinSkValObj) _nonLinSkValObj;
1119 static const CFFE_TYPEOF(_linSkRngObj ) _linSkRngObj ;
1120 static const CFFE_TYPEOF(_nonLinSkRngObj) _nonLinSkRngObj;
1121
1122 static const CFFE_TYPEOF(_linInEqCon ) _linInEqCon ;
1123 static const CFFE_TYPEOF(_nonLinInEqCon ) _nonLinInEqCon ;
1124 static const CFFE_TYPEOF(_linEqCon ) _linEqCon ;
1125 static const CFFE_TYPEOF(_nonLinEqCon ) _nonLinEqCon ;
1126 static const CFFE_TYPEOF(_linTwoSideIneqCon ) _linTwoSideIneqCon ;
1127 static const CFFE_TYPEOF(_nonLinTwoSideIneqCon) _nonLinTwoSideIneqCon;
1128 static const CFFE_TYPEOF(_linNotEqCon ) _linNotEqCon ;
1129 static const CFFE_TYPEOF(_nonLinNotEqCon ) _nonLinNotEqCon ;
1130
1131 }; // class ConfigFileFrontEndApp::InputDescriptors::DefaultValues
1132
1133
1134
1135
1136
1137
1138
1139 /*
1140 ================================================================================
1141 Static Member Data Definitions
1142 ================================================================================
1143 */
1144 const string ITS::_cfgFile ("cfgfile");
1145 const string ITS::_help ("help" );
1146 const string ITS::_version ("version");
1147
1148 const string ITS::_assessor ("FITNESS_ASSESSOR");
1149 const string ITS::_initializer ("INITIALIZER" );
1150 const string ITS::_mutator ("MUTATOR" );
1151 const string ITS::_crosser ("CROSSER" );
1152 const string ITS::_nicher ("NICHER" );
1153 const string ITS::_postprocessor ("POST_PROCESSOR" );
1154 const string ITS::_mainloop ("MAIN_LOOP" );
1155 const string ITS::_selector ("SELECTOR" );
1156 const string ITS::_converger ("CONVERGER" );
1157
1158 const string ITS::_intParams ("INT_PARAMS" );
1159 const string ITS::_dblParams ("DBL_PARAMS" );
1160 const string ITS::_sztParams ("SIZE_T_PARAMS" );
1161 const string ITS::_boolParams ("BOOL_PARAMS" );
1162 const string ITS::_strParams ("STRING_PARAMS" );
1163 const string ITS::_intVecParams ("INT_VEC_PARAMS" );
1164 const string ITS::_dblVecParams ("DBL_VEC_PARAMS" );
1165 const string ITS::_strVecParams ("STRING_VEC_PARAMS");
1166 const string ITS::_dblMatParams ("DBL_MAT_PARAMS" );
1167
1168 const string ITS::_rndSeed ("RANDOM_SEED" );
1169 const string ITS::_globLogFile ("GLOBAL_LOG_FILE" );
1170 const string ITS::_globLogLevel ("GLOBAL_LOG_LEVEL");
1171 const string ITS::_algType ("ALGORITHM_TYPE" );
1172
1173 const string ITS::_contRealVar ("CONT_REAL_VAR");
1174 const string ITS::_discRealVar ("DISC_REAL_VAR");
1175 const string ITS::_contIntVar ("CONT_INT_VAR" );
1176 const string ITS::_discIntVar ("DISC_INT_VAR" );
1177 const string ITS::_boolVar ("BOOL_VAR" );
1178
1179 const string ITS::_linMinObj ("LIN_MIN_OBJ" );
1180 const string ITS::_nonLinMinObj ("NONLIN_MIN_OBJ" );
1181 const string ITS::_linMaxObj ("LIN_MAX_OBJ" );
1182 const string ITS::_nonLinMaxObj ("NONLIN_MAX_OBJ" );
1183 const string ITS::_linSkValObj ("LIN_SK_VAL_OBJ" );
1184 const string ITS::_nonLinSkValObj("NONLIN_SK_VAL_OBJ");
1185 const string ITS::_linSkRngObj ("LIN_SK_RNG_OBJ" );
1186 const string ITS::_nonLinSkRngObj("NONLIN_SK_RNG_OBJ");
1187
1188 const string ITS::_linInEqCon ("LIN_INEQ_CON" );
1189 const string ITS::_nonLinInEqCon ("NONLIN_INEQ_CON" );
1190 const string ITS::_linEqCon ("LIN_EQ_CON" );
1191 const string ITS::_nonLinEqCon ("NONLIN_EQ_CON" );
1192 const string ITS::_linTwoSideIneqCon ("LIN_2_SIDE_INEQ_CON" );
1193 const string ITS::_nonLinTwoSideIneqCon("NONLIN_2_SIDE_INEQ_CON");
1194 const string ITS::_linNotEqCon ("LIN_NOT_EQ_CON" );
1195 const string ITS::_nonLinNotEqCon ("NONLIN_NOT_EQ_CON" );
1196
1197 const string ITS::_dummyTag ("DUMMY");
1198
1199
1200
1201 const CFFE_TYPEOF(_cfgFile) DVS::_cfgFile ("RUNJEGA");
1202 const CFFE_TYPEOF(_help ) DVS::_help ("" );
1203
1204 const CFFE_TYPEOF(_assessor)
1205 DVS::_assessor("domination_count");
1206
1207 const CFFE_TYPEOF(_initializer)
1208 DVS::_initializer("unique_random");
1209
1210 const CFFE_TYPEOF(_mutator)
1211 DVS::_mutator("replace_uniform");
1212
1213 const CFFE_TYPEOF(_crosser)
1214 DVS::_crosser("shuffle_random");
1215
1216 const CFFE_TYPEOF(_nicher)
1217 DVS::_nicher("distance");
1218
1219 const CFFE_TYPEOF(_postprocessor)
1220 DVS::_postprocessor("null_postprocessor");
1221
1222 const CFFE_TYPEOF(_mainloop)
1223 DVS::_mainloop("duplicate_free");
1224
1225 const CFFE_TYPEOF(_selector)
1226 DVS::_selector("below_limit");
1227
1228 const CFFE_TYPEOF(_converger)
1229 DVS::_converger("metric_tracker");
1230
1231 const CFFE_TYPEOF(_intParams)
1232 DVS::_intParams(1, bt::make_tuple(ITS::_dummyTag, 0));
1233
1234 const CFFE_TYPEOF(_dblParams)
1235 DVS::_dblParams (1, bt::make_tuple(ITS::_dummyTag, 0.0));
1236
1237 const CFFE_TYPEOF(_sztParams)
1238 DVS::_sztParams (1, bt::make_tuple(ITS::_dummyTag, 0));
1239
1240 const CFFE_TYPEOF(_boolParams)
1241 DVS::_boolParams(1, bt::make_tuple(ITS::_dummyTag, false));
1242
1243 const CFFE_TYPEOF(_strParams)
1244 DVS::_strParams (1, bt::make_tuple(ITS::_dummyTag, string()));
1245
1246 const CFFE_TYPEOF(_intVecParams)
1247 DVS::_intVecParams(1, bt::make_tuple(ITS::_dummyTag, IntVector(1, 0)));
1248
1249 const CFFE_TYPEOF(_dblVecParams)
1250 DVS::_dblVecParams(1, bt::make_tuple(ITS::_dummyTag, DoubleVector(1, 0.0)));
1251
1252 const CFFE_TYPEOF(_strVecParams)
1253 DVS::_strVecParams(1,
1254 bt::make_tuple(ITS::_dummyTag, StringVector(1, ITS::_dummyTag))
1255 );
1256
1257 const CFFE_TYPEOF(_dblMatParams)
1258 DVS::_dblMatParams(1, bt::make_tuple(ITS::_dummyTag, DoubleVector(1, 0.0)));
1259
1260 const CFFE_TYPEOF(_rndSeed)
1261 DVS::_rndSeed (0);
1262
1263 const CFFE_TYPEOF(_globLogFile)
1264 DVS::_globLogFile ("JEGAGlobal.log");
1265
1266 const CFFE_TYPEOF(_globLogLevel)
1267 DVS::_globLogLevel("Default");
1268
1269 const CFFE_TYPEOF(_algType)
1270 DVS::_algType ("MOGA");
1271
1272 const CFFE_TYPEOF(_contRealVar)
1273 DVS::_contRealVar(1, bt::make_tuple(0, ITS::_dummyTag, 0.0, 0.0, 0));
1274
1275 const CFFE_TYPEOF(_discRealVar)
1276 DVS::_discRealVar(1, bt::make_tuple(
1277 0, ITS::_dummyTag, DoubleVector(1, 0.0))
1278 );
1279
1280 const CFFE_TYPEOF(_contIntVar)
1281 DVS::_contIntVar(1, bt::make_tuple(0, ITS::_dummyTag, 0, 0));
1282
1283 const CFFE_TYPEOF(_discIntVar)
1284 DVS::_discIntVar(1, bt::make_tuple(0, ITS::_dummyTag, IntVector(1, 0)));
1285
1286 const CFFE_TYPEOF(_boolVar)
1287 DVS::_boolVar(1, bt::make_tuple(0, ITS::_dummyTag));
1288
1289 const CFFE_TYPEOF(_linMinObj)
1290 DVS::_linMinObj(1, bt::make_tuple(0, ITS::_dummyTag, DoubleVector(1, 0.0)));
1291
1292 const CFFE_TYPEOF(_nonLinMinObj)
1293 DVS::_nonLinMinObj(1, bt::make_tuple(0, ITS::_dummyTag));
1294
1295 const CFFE_TYPEOF(_linMaxObj)
1296 DVS::_linMaxObj(1, bt::make_tuple(0, ITS::_dummyTag, DoubleVector(1, 0.0)));
1297
1298 const CFFE_TYPEOF(_nonLinMaxObj)
1299 DVS::_nonLinMaxObj(1, bt::make_tuple(0, ITS::_dummyTag));
1300
1301 const CFFE_TYPEOF(_linSkValObj)
1302 DVS::_linSkValObj(
1303 1,
1304 bt::make_tuple(0, ITS::_dummyTag, obj_val_t(0), DoubleVector(1, 0.0))
1305 );
1306
1307 const CFFE_TYPEOF(_nonLinSkValObj)
1308 DVS::_nonLinSkValObj(1, bt::make_tuple(0, ITS::_dummyTag, obj_val_t(0)));
1309
1310 const CFFE_TYPEOF(_linSkRngObj)
1311 DVS::_linSkRngObj(
1312 1,
1313 bt::make_tuple(
1314 0, ITS::_dummyTag, obj_val_t(0), obj_val_t(0), DoubleVector(1, 0.0)
1315 )
1316 );
1317
1318 const CFFE_TYPEOF(_nonLinSkRngObj) DVS::_nonLinSkRngObj(
1319 1, bt::make_tuple(0, ITS::_dummyTag, obj_val_t(0), obj_val_t(0))
1320 );
1321
1322 const CFFE_TYPEOF(_linInEqCon)
1323 DVS::_linInEqCon(
1324 1,
1325 bt::make_tuple(0, ITS::_dummyTag, con_val_t(0), DoubleVector(1, 0.0))
1326 );
1327
1328 const CFFE_TYPEOF(_nonLinInEqCon)
1329 DVS::_nonLinInEqCon(1, bt::make_tuple(0, ITS::_dummyTag, con_val_t(0)));
1330
1331 const CFFE_TYPEOF(_linEqCon)
1332 DVS::_linEqCon(
1333 1,
1334 bt::make_tuple(
1335 0, ITS::_dummyTag, con_val_t(0), con_val_t(0), DoubleVector(1, 0.0)
1336 )
1337 );
1338
1339 const CFFE_TYPEOF(_nonLinEqCon)
1340 DVS::_nonLinEqCon(1, bt::make_tuple(0, ITS::_dummyTag, con_val_t(0), 0.0));
1341
1342 const CFFE_TYPEOF(_linTwoSideIneqCon)
1343 DVS::_linTwoSideIneqCon(1,
1344 bt::make_tuple(
1345 0, ITS::_dummyTag, con_val_t(0), con_val_t(0), DoubleVector(1, 0.0)
1346 )
1347 );
1348
1349 const CFFE_TYPEOF(_nonLinTwoSideIneqCon) DVS::_nonLinTwoSideIneqCon(
1350 1, bt::make_tuple(0, ITS::_dummyTag, con_val_t(0), con_val_t(0))
1351 );
1352
1353 const CFFE_TYPEOF(_linNotEqCon)
1354 DVS::_linNotEqCon(
1355 1,
1356 bt::make_tuple(0, ITS::_dummyTag, con_val_t(0), DoubleVector(1, 0.0))
1357 );
1358
1359 const CFFE_TYPEOF(_nonLinNotEqCon)
1360 DVS::_nonLinNotEqCon(1, bt::make_tuple(0, ITS::_dummyTag, con_val_t(0)));
1361
1362
1363 /*
1364 ================================================================================
1365 Private Template Method Implementations
1366 ================================================================================
1367 */
1368 template <typename T>
1369 const T&
GetValueOf(const string & param) const1370 ConfigFileFrontEndApp::GetValueOf(
1371 const string& param
1372 ) const
1373 {
1374 EDDY_FUNC_DEBUGSCOPE
1375 // Keep this broken up into two statements for compilation with gcc.
1376 const variable_value& vv = this->GetVariableValue(param);
1377 return vv.as<T>();
1378 }
1379
1380 template <typename T, const char I>
1381 vector<T>
ConcatenateVector(const string & tag)1382 ConfigFileFrontEndApp::ConcatenateVector(
1383 const string& tag
1384 )
1385 {
1386 typedef typename mpl::at<all_opt_types, char[I]>::type BVT;
1387 const BVT& all = this->GetValueOf<BVT>(tag);
1388
1389 // if all is empty, there is nothing to do.
1390 if(all.empty()) return vector<T>();
1391
1392 // !!!!!what about the dummy entry!!!!!
1393 //// if all is size 1, return that 1 entry.
1394 //if(all.size() == 1) return all[0].get<1>();
1395
1396 // Otherwise, we have to gather them up and append them in order.
1397 vector<T> gathered;
1398
1399 for(typename BVT::const_iterator it(all.begin()); it!=all.end(); ++it)
1400 {
1401 // Skip the default dummy entry(ies).
1402 if((*it).get<0>() == ITS::_dummyTag) continue;
1403
1404 const vector<T>& curr = (*it).get<1>();
1405
1406 // add the values in "it" to our gathered.
1407 gathered.reserve(gathered.size() + curr.size());
1408 gathered.insert(gathered.end(), curr.begin(), curr.end());
1409 }
1410
1411 return gathered;
1412 }
1413
1414 template <typename InfoT>
1415 void
AddInfoToMap(map<size_t,InfoT * > & theMap,size_t index,InfoT * theInfo,const string & type)1416 ConfigFileFrontEndApp::AddInfoToMap(
1417 map<size_t, InfoT*>& theMap,
1418 size_t index,
1419 InfoT* theInfo,
1420 const string& type
1421 )
1422 {
1423 EDDY_FUNC_DEBUGSCOPE
1424
1425 typename map<size_t, InfoT*>::iterator loc(theMap.find(index));
1426
1427 if(loc != theMap.end()) throw runtime_error(
1428 "Attempt to add multiple " + type + " with index " +
1429 lexical_cast<string, size_t>(index) + " is illegal. "
1430 "Please correct your file at inputs \"" +
1431 (*loc).second->GetLabel() + "\" and \"" + theInfo->GetLabel() + "\"."
1432 );
1433
1434 theMap.insert(typename map<size_t, InfoT*>::value_type(index, theInfo));
1435 }
1436
1437
1438
1439
1440
1441
1442
1443 /*
1444 ================================================================================
1445 Mutators
1446 ================================================================================
1447 */
1448
1449
1450
1451
1452
1453
1454
1455
1456 /*
1457 ================================================================================
1458 Accessors
1459 ================================================================================
1460 */
1461
1462
1463
1464
1465
1466
1467
1468
1469 /*
1470 ================================================================================
1471 Public Methods
1472 ================================================================================
1473 */
1474
1475 int
Run(int argc,char * argv[])1476 ConfigFileFrontEndApp::Run(
1477 int argc,
1478 char* argv[]
1479 )
1480 {
1481 EDDY_FUNC_DEBUGSCOPE
1482
1483 try
1484 {
1485 // Begin by retrieving all user input.
1486 this->RetrieveAllInput(argc, argv);
1487
1488 this->ValidateAllInput();
1489
1490 // All programs must initialize JEGA once and only once.
1491 if(!Driver::IsJEGAInitialized())
1492 {
1493 Driver::InitializeJEGA(
1494 CFFE_GETVAR(_globLogFile),
1495 this->ResolveLogLevel(CFFE_GETVAR(_globLogLevel)),
1496 static_cast<unsigned int>(CFFE_GETVAR(_rndSeed))
1497 );
1498 }
1499 else
1500 {
1501 //Driver::FlushGlobalLogStreams();
1502 Driver::ResetGlobalLoggingLevel(
1503 this->ResolveLogLevel(CFFE_GETVAR(_globLogLevel))
1504 );
1505 Driver::ReSeed(static_cast<unsigned int>(CFFE_GETVAR(_rndSeed)));
1506 }
1507
1508 this->LoadParameterDatabase();
1509 this->LoadProblemConfig();
1510
1511 // Now that the parameter database and the problem configuration
1512 // are loaded, we can solve our problem!
1513
1514 // start by creating our algorithm config. To do that, we need an
1515 // evaluator creator
1516 unique_ptr<EvaluatorCreator> evalCreator(this->GetEvaluatorCreator());
1517 AlgorithmConfig aConfig(*evalCreator, *this->_theParamDB);
1518 this->LoadAlgorithmParameters(aConfig);
1519
1520 Driver app(*this->_theProbConfig);
1521 DesignOFSortSet res(app.ExecuteAlgorithm(aConfig));
1522
1523 // WE MUST FLUSH THE RETURNED SET OF SOLUTIONS
1524 // TO AVOID A MEMORY LEAK!!
1525 res.flush();
1526 }
1527 catch(const std::exception& e)
1528 {
1529 cerr << "JEGA Configuration file front end caught an exception at "
1530 "the application level reading:\n\n"
1531 << e.what() << "\n\nAborting with value of 1.\n";
1532 exit(1);
1533 }
1534 catch(int e)
1535 {
1536 cerr << "JEGA Configuration file front end caught an integer "
1537 "exception at the application level with value " << e
1538 << ". Aborting with that code.\n";
1539 exit(e);
1540 }
1541 catch(...)
1542 {
1543 cerr << "JEGA Configuration file front end caught an unknown "
1544 "exception at the application level. Aborting with value of "
1545 "1.\n";
1546 exit(1);
1547 }
1548
1549 return 0;
1550 }
1551
1552 const options_description&
CommandLineOnlyInputOptions()1553 ConfigFileFrontEndApp::CommandLineOnlyInputOptions(
1554 )
1555 {
1556 EDDY_FUNC_DEBUGSCOPE
1557 static const options_description options(
1558 CreateCommandLineOnlyInputOptions()
1559 );
1560 return options;
1561 }
1562
1563 const options_description&
AllCommandLineInputOptions()1564 ConfigFileFrontEndApp::AllCommandLineInputOptions(
1565 )
1566 {
1567 EDDY_FUNC_DEBUGSCOPE
1568
1569 static const options_description options(
1570 CreateAllCommandLineInputOptions()
1571 );
1572
1573 return options;
1574 }
1575
1576 const options_description&
ConfigFileOnlyInputOptions()1577 ConfigFileFrontEndApp::ConfigFileOnlyInputOptions(
1578 )
1579 {
1580 EDDY_FUNC_DEBUGSCOPE
1581 static const options_description options(
1582 CreateConfigFileOnlyInputOptions()
1583 );
1584 return options;
1585 }
1586
1587 const options_description&
AllConfigFileInputOptions()1588 ConfigFileFrontEndApp::AllConfigFileInputOptions(
1589 )
1590 {
1591 EDDY_FUNC_DEBUGSCOPE
1592 static const options_description options(
1593 CreateAllConfigFileInputOptions()
1594 );
1595 return options;
1596 }
1597
1598 const options_description&
SharedInputOptions()1599 ConfigFileFrontEndApp::SharedInputOptions(
1600 )
1601 {
1602 EDDY_FUNC_DEBUGSCOPE
1603 static const options_description options(CreateSharedInputOptions());
1604 return options;
1605 }
1606
1607 const options_description&
AllInputOptions()1608 ConfigFileFrontEndApp::AllInputOptions(
1609 )
1610 {
1611 EDDY_FUNC_DEBUGSCOPE
1612 static options_description options(CreateAllInputOptions());
1613 return options;
1614 }
1615
1616 bool
HasInputValueFor(const string & param) const1617 ConfigFileFrontEndApp::HasInputValueFor(
1618 const string& param
1619 ) const
1620 {
1621 EDDY_FUNC_DEBUGSCOPE
1622 return this->_vMap->count(param) != 0;
1623 }
1624
1625 void
PrintAllInputArgs(ostream & stream) const1626 ConfigFileFrontEndApp::PrintAllInputArgs(
1627 ostream& stream
1628 ) const
1629 {
1630 EDDY_FUNC_DEBUGSCOPE
1631 this->PrintSuppliedCommandLineArgs(stream);
1632 this->PrintSuppliedConfigFileArgs(stream);
1633 }
1634
1635 #define PRINT_CFI(stream, tag) \
1636 if(this->HasInputValueFor(ITS::tag)) \
1637 stream << ITS::tag << ": " << CFFE_GETVAR(tag) << "\n";
1638
1639 void
PrintSuppliedCommandLineArgs(ostream & stream) const1640 ConfigFileFrontEndApp::PrintSuppliedCommandLineArgs(
1641 ostream& stream
1642 ) const
1643 {
1644 EDDY_FUNC_DEBUGSCOPE
1645
1646 stream << "Command line supplied arguments:\n"
1647 << "================================\n";
1648
1649 PRINT_CFI(stream, _cfgFile);
1650 PRINT_CFI(stream, _help);
1651 PRINT_CFI(stream, _version);
1652
1653 stream << "\n";
1654 }
1655
1656 void
PrintSuppliedConfigFileArgs(ostream & stream) const1657 ConfigFileFrontEndApp::PrintSuppliedConfigFileArgs(
1658 ostream& stream
1659 ) const
1660 {
1661 EDDY_FUNC_DEBUGSCOPE
1662
1663 stream << "Configuration file supplied arguments:\n"
1664 << "======================================\n";
1665
1666 PRINT_CFI(stream, _assessor );
1667 PRINT_CFI(stream, _initializer );
1668 PRINT_CFI(stream, _mutator );
1669 PRINT_CFI(stream, _crosser );
1670 PRINT_CFI(stream, _nicher );
1671 PRINT_CFI(stream, _postprocessor);
1672 PRINT_CFI(stream, _mainloop );
1673 PRINT_CFI(stream, _selector );
1674 PRINT_CFI(stream, _converger );
1675
1676 PRINT_CFI(stream, _intParams );
1677 PRINT_CFI(stream, _dblParams );
1678 PRINT_CFI(stream, _sztParams );
1679 PRINT_CFI(stream, _boolParams );
1680 PRINT_CFI(stream, _strParams );
1681 PRINT_CFI(stream, _intVecParams );
1682 PRINT_CFI(stream, _dblVecParams );
1683 PRINT_CFI(stream, _strVecParams );
1684
1685 PRINT_CFI(stream, _rndSeed );
1686 PRINT_CFI(stream, _globLogFile );
1687 PRINT_CFI(stream, _globLogLevel );
1688 PRINT_CFI(stream, _algType );
1689
1690 PRINT_CFI(stream, _contRealVar );
1691 PRINT_CFI(stream, _discRealVar );
1692 PRINT_CFI(stream, _contIntVar );
1693 PRINT_CFI(stream, _discIntVar );
1694 PRINT_CFI(stream, _boolVar );
1695
1696 PRINT_CFI(stream, _linMinObj );
1697 PRINT_CFI(stream, _nonLinMinObj );
1698 PRINT_CFI(stream, _linMaxObj );
1699 PRINT_CFI(stream, _nonLinMaxObj );
1700 PRINT_CFI(stream, _linSkValObj );
1701 PRINT_CFI(stream, _nonLinSkValObj);
1702 PRINT_CFI(stream, _linSkRngObj );
1703 PRINT_CFI(stream, _nonLinSkRngObj);
1704
1705 PRINT_CFI(stream, _linInEqCon );
1706 PRINT_CFI(stream, _nonLinInEqCon );
1707 PRINT_CFI(stream, _linEqCon );
1708 PRINT_CFI(stream, _nonLinEqCon );
1709 PRINT_CFI(stream, _linTwoSideIneqCon );
1710 PRINT_CFI(stream, _nonLinTwoSideIneqCon);
1711 PRINT_CFI(stream, _linNotEqCon );
1712 PRINT_CFI(stream, _nonLinNotEqCon );
1713
1714 stream << "\n";
1715 }
1716
1717 #undef PRINT_CFI
1718
1719
1720
1721 /*
1722 ================================================================================
1723 Subclass Visible Methods
1724 ================================================================================
1725 */
1726
1727 const variable_value&
GetVariableValue(const string & param) const1728 ConfigFileFrontEndApp::GetVariableValue(
1729 const string& param
1730 ) const
1731 {
1732 EDDY_FUNC_DEBUGSCOPE
1733 return this->_vMap->operator[](param);
1734 }
1735
1736 void
PrintHelpMessage(ostream & into) const1737 ConfigFileFrontEndApp::PrintHelpMessage(
1738 ostream& into
1739 ) const
1740 {
1741 EDDY_FUNC_DEBUGSCOPE
1742
1743 // print a message indicating what is being shown and how to use
1744 // the configuration file utility.
1745 into << "\n\nThe following is a listing of the allowable command "
1746 "line input arguments for JEGA. Some arguments are reserved "
1747 "only for the command line and others are reserved for input "
1748 "through the configuration file only. See the listings below for "
1749 "a complete reference of available inputs.\n\n"
1750
1751 "Inputs to the command line are preceded with two hyphens when "
1752 "no abbreviation is used and with a single hyphen if using an "
1753 "accepted abbreviation. For example:\n\n"
1754
1755 "\t>> jega --help\n"
1756 "\t>> jega -h\n\n"
1757
1758 "are equivalent and will print this message.\n\n"
1759
1760 "Inputs to the configuration file are quite different. Each is "
1761 "identified using an all-caps identifier. See the listing below "
1762 "for a complete reference of available identifiers. The majority "
1763 "of the configuration file inputs are tuples meaning that "
1764 "multiple pieces of information are supplied on a single line. "
1765 "Some of them are also vector valued meaning that one of the "
1766 "inputs is a vector. Consider for example the input for "
1767 "declaring a discrete real variable. The required inputs in "
1768 "order are the index of the variable, the name of the variable, "
1769 "and the values that it may have. The values that it may have is "
1770 "read in as a vector. It has no predefined size and so each of "
1771 "the following is perfectly legal input:\n\n"
1772
1773 "\tDISC_REAL_VAR = 0 X1 0.0\n"
1774 "\tDISC_REAL_VAR = 0 X1 0.0 1.0\n"
1775 "\tDISC_REAL_VAR = 0 X1 0.0 1.0 3.4 5.6 7.1\n\n"
1776
1777 // output the allowable command line input arguments for this application.
1778 << "The following are the COMMAND LINE ONLY input options:\n"
1779 "=======================================================\n"
1780 << this->CommandLineOnlyInputOptions()
1781 << "\n\n"
1782
1783 << "The following are the CONFIGURATION FILE ONLY input options:\n"
1784 "=======================================================\n"
1785 << this->ConfigFileOnlyInputOptions()
1786 << "\n\n"
1787
1788 << "There are currently no SHARED input options.\n\n";
1789
1790 // << "The following are the SHARED input options:\n"
1791 // "=======================================================\n"
1792 // << SharedInputOptions()
1793 // << "\n\n";
1794 }
1795
1796 void
PrintVersionMessage(ostream & into) const1797 ConfigFileFrontEndApp::PrintVersionMessage(
1798 ostream& into
1799 ) const
1800 {
1801 EDDY_FUNC_DEBUGSCOPE
1802
1803 // This date stuff is very temporary since it only gets updated when this
1804 // file gets built. Need a more robust and correct solution.
1805 into << JEGA_PACKAGE << " built on " << __DATE__ << '\n';
1806 }
1807
1808 #define LOAD_DB_PARAMS(tag, meth) { \
1809 const CFFE_TYPEOF(tag)& prms = CFFE_GETVAR(tag); \
1810 for(CFFE_TYPEOF(tag)::const_iterator it(prms.begin()); \
1811 it!=prms.end(); ++it) if((*it).get<0>() != ITS::_dummyTag) \
1812 this->_theParamDB->meth((*it).get<0>(), (*it).get<1>()); \
1813 }
1814
1815 void
LoadParameterDatabase()1816 ConfigFileFrontEndApp::LoadParameterDatabase(
1817 )
1818 {
1819 EDDY_FUNC_DEBUGSCOPE
1820
1821 // Start by loading in all the singular valued parameters.
1822 LOAD_DB_PARAMS(_intParams , AddIntegralParam );
1823 LOAD_DB_PARAMS(_dblParams , AddDoubleParam );
1824 LOAD_DB_PARAMS(_sztParams , AddSizeTypeParam );
1825 LOAD_DB_PARAMS(_boolParams , AddBooleanParam );
1826 LOAD_DB_PARAMS(_strParams , AddStringParam );
1827 LOAD_DB_PARAMS(_intVecParams, AddIntVectorParam );
1828 LOAD_DB_PARAMS(_dblVecParams, AddDoubleVectorParam );
1829 LOAD_DB_PARAMS(_strVecParams, AddStringVectorParam );
1830
1831 // There is an additional requirement that we make the output an integral
1832 // parameter since that is what the driver will be looking for.
1833 // Fortunately, this should be quick and easy since it is already in as
1834 // a string parameter labeled "method.log_level" (if at all).
1835 if(this->_theParamDB->HasStringParam("method.log_level"))
1836 this->_theParamDB->AddIntegralParam(
1837 "method.output",
1838 ResolveLogLevel(this->_theParamDB->GetString("method.log_level"))
1839 );
1840
1841 LoadDoubleMatrices();
1842 }
1843
1844 #undef LOAD_DB_PARAMS
1845
1846 void
LoadProblemConfig()1847 ConfigFileFrontEndApp::LoadProblemConfig(
1848 )
1849 {
1850 EDDY_FUNC_DEBUGSCOPE
1851 this->LoadDesignVariables();
1852 this->LoadObjectiveFunctions();
1853 this->LoadConstraints();
1854
1855 // Find out if we should store discards or not.
1856 bool doStore = true;
1857
1858 try {
1859 doStore = this->_theParamDB->GetBoolean("method.jega.store_discards");
1860 }
1861 catch(...) { doStore = true; }
1862
1863 this->_theProbConfig->SetDiscardTracking(doStore);
1864 }
1865
1866 #define GET(r, state) \
1867 (*it).get< BOOST_PP_TUPLE_ELEM(2, 0, state) >() \
1868 BOOST_PP_IF( \
1869 BOOST_PP_EQUAL( \
1870 BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 0, state)), \
1871 BOOST_PP_TUPLE_ELEM(2, 1, state) \
1872 ), BOOST_PP_EMPTY, BOOST_PP_COMMA )()
1873
1874 #define ADD_INFO(tag, mapName, infoType, infoTypeDesc, getFunc, N) \
1875 { \
1876 const CFFE_TYPEOF(tag)& vname = CFFE_GETVAR(tag); \
1877 for(CFFE_TYPEOF(tag)::const_iterator it(vname.begin()); \
1878 it!=vname.end(); ++it) \
1879 if((*it).get<1>() != ITS::_dummyTag) \
1880 AddInfoToMap<infoType>(mapName, (*it).get<0>(), \
1881 ConfigHelper::getFunc( \
1882 target, BOOST_PP_FOR((1, N), ENUM_PRED, ENUM_OP, GET) \
1883 ), infoTypeDesc \
1884 ); \
1885 }
1886
1887 #define ADD_DV_INFO(tag, mapName, getFunc, N) \
1888 ADD_INFO(tag, mapName, DesignVariableInfo, "design variables", getFunc, N)
1889
1890 void
LoadDesignVariables()1891 ConfigFileFrontEndApp::LoadDesignVariables(
1892 )
1893 {
1894 EDDY_FUNC_DEBUGSCOPE
1895
1896 // The design variables must all be given unique indices. We will sort by
1897 // index and add them in the order in which they end up.
1898
1899 // In order to sort them by index, we will use a map. We will map indices
1900 // to newly created design variable infos. If any index is repeated,
1901 // throw an error.
1902 typedef std::map<size_t, DesignVariableInfo*> DVMap;
1903 DVMap dvMap;
1904
1905 // We are going to need the design target for all of this.
1906 DesignTarget& target = this->_theProbConfig->GetDesignTarget();
1907
1908 ADD_DV_INFO(_contRealVar, dvMap, GetContinuumRealVariable, 5)
1909 ADD_DV_INFO(_discRealVar, dvMap, GetDiscreteRealVariable, 3)
1910 ADD_DV_INFO(_contIntVar, dvMap, GetContinuumIntegerVariable, 4)
1911 ADD_DV_INFO(_discIntVar, dvMap, GetDiscreteIntegerVariable, 3)
1912 ADD_DV_INFO(_boolVar, dvMap, GetBooleanVariable, 2)
1913
1914 // If we make it here, all our infos loaded up. Now stick them into the
1915 // target.
1916 for(DVMap::const_iterator it(dvMap.begin()); it!=dvMap.end(); ++it)
1917 target.AddDesignVariableInfo(*(*it).second);
1918 }
1919
1920 #define ADD_OF_INFO(tag, mapName, getFunc, N) \
1921 ADD_INFO(tag, mapName, ObjectiveFunctionInfo, \
1922 "objective functions", getFunc, N)
1923
1924 void
LoadObjectiveFunctions()1925 ConfigFileFrontEndApp::LoadObjectiveFunctions(
1926 )
1927 {
1928 EDDY_FUNC_DEBUGSCOPE
1929
1930 // The objective functions must all be given unique indices. We will sort
1931 // by index and add them in the order in which they end up.
1932
1933 // In order to sort them by index, we will use a map. We will map indices
1934 // to newly created objective function infos. If any index is repeated,
1935 // throw an error.
1936 typedef std::map<size_t, ObjectiveFunctionInfo*> OFMap;
1937 OFMap ofMap;
1938
1939 // We are going to need the design target for all of this.
1940 DesignTarget& target = this->_theProbConfig->GetDesignTarget();
1941
1942 // Start with the linear minimize objectives.
1943 ADD_OF_INFO(_linMinObj, ofMap, GetLinearMinimizeObjective, 3)
1944 ADD_OF_INFO(_nonLinMinObj, ofMap, GetNonlinearMinimizeObjective, 2)
1945 ADD_OF_INFO(_linMaxObj, ofMap, GetLinearMaximizeObjective, 3)
1946 ADD_OF_INFO(_nonLinMaxObj, ofMap, GetNonlinearMaximizeObjective, 2)
1947 ADD_OF_INFO(_linSkValObj, ofMap, GetLinearSeekValueObjective, 4)
1948 ADD_OF_INFO(_nonLinSkValObj, ofMap, GetNonlinearSeekValueObjective, 3)
1949 ADD_OF_INFO(_linSkRngObj, ofMap, GetLinearSeekRangeObjective, 5)
1950 ADD_OF_INFO(_nonLinSkRngObj, ofMap, GetNonlinearSeekRangeObjective, 4)
1951
1952 // If we make it here, all our infos loaded up. Now stick them into the
1953 // target.
1954 for(OFMap::const_iterator it(ofMap.begin()); it!=ofMap.end(); ++it)
1955 target.AddObjectiveFunctionInfo(*(*it).second);
1956 }
1957
1958 #define ADD_CN_INFO(tag, mapName, getFunc, N) \
1959 ADD_INFO(tag, mapName, ConstraintInfo, "constraints", getFunc, N)
1960
1961 void
LoadConstraints()1962 ConfigFileFrontEndApp::LoadConstraints(
1963 )
1964 {
1965 EDDY_FUNC_DEBUGSCOPE
1966
1967 // The constraint functions must all be given unique indices. We will sort
1968 // by index and add them in the order in which they end up.
1969
1970 // In order to sort them by index, we will use a map. We will map indices
1971 // to newly created constraint function infos. If any index is repeated,
1972 // throw an error.
1973 typedef std::map<size_t, ConstraintInfo*> CNMap;
1974 CNMap cnMap;
1975
1976 // We are going to need the design target for all of this.
1977 DesignTarget& target = this->_theProbConfig->GetDesignTarget();
1978
1979 // Start with the linear inequality constraints.
1980 ADD_CN_INFO(_linInEqCon, cnMap, GetLinearInequalityConstraint, 4)
1981 ADD_CN_INFO(_nonLinInEqCon, cnMap, GetNonlinearInequalityConstraint, 3)
1982 ADD_CN_INFO(_linEqCon, cnMap, GetLinearEqualityConstraint, 5)
1983 ADD_CN_INFO(_nonLinEqCon, cnMap, GetNonlinearEqualityConstraint, 4)
1984
1985 ADD_CN_INFO(_linTwoSideIneqCon, cnMap,
1986 GetLinearTwoSidedInequalityConstraint, 5
1987 )
1988
1989 ADD_CN_INFO(
1990 _nonLinTwoSideIneqCon, cnMap,
1991 GetNonlinearTwoSidedInequalityConstraint, 4
1992 )
1993
1994 ADD_CN_INFO(_linNotEqCon, cnMap, GetLinearNotEqualityConstraint, 4)
1995 ADD_CN_INFO(_nonLinNotEqCon, cnMap, GetNonlinearNotEqualityConstraint, 3)
1996
1997 // If we make it here, all our infos loaded up. Now stick them into the
1998 // target.
1999 for(CNMap::const_iterator it(cnMap.begin()); it!=cnMap.end(); ++it)
2000 target.AddConstraintInfo(*(*it).second);
2001 }
2002
2003 #undef ADD_CN_INFO
2004 #undef ADD_OF_INFO
2005 #undef ADD_DV_INFO
2006 #undef ADD_INFO
2007 #undef GET
2008
2009 void
LoadDoubleMatrices()2010 ConfigFileFrontEndApp::LoadDoubleMatrices(
2011 )
2012 {
2013 EDDY_FUNC_DEBUGSCOPE
2014
2015 // to do this, we must gather all vectors input with the same tag via
2016 // DBL_MAT_PARAM into matrices.
2017 typedef CFFE_TYPEOF(_dblMatParams) StrVecPairVec;
2018 const StrVecPairVec& all = CFFE_GETVAR(_dblMatParams);
2019
2020 // create a map of strings to matrices to gather these up.
2021 typedef std::map<string, DoubleMatrix> MatMap;
2022
2023 MatMap matrices;
2024
2025 for(StrVecPairVec::const_iterator it(all.begin()); it!=all.end(); ++it)
2026 {
2027 // Skip the default dummy entry(ies).
2028 if((*it).get<0>() == ITS::_dummyTag) continue;
2029
2030 MatMap::iterator curr(matrices.find((*it).get<0>()));
2031
2032 // if we have a running matrix entry, then add on to it. Otherwise,
2033 // put in a new entry.
2034 if(curr != matrices.end()) (*curr).second.push_back((*it).get<1>());
2035
2036 else matrices[(*it).get<0>()] = DoubleMatrix(1, (*it).get<1>());
2037 }
2038
2039 // now we've gathered up and created all our matrices, now put them in
2040 // the database.
2041 for(MatMap::const_iterator it(matrices.begin()); it!=matrices.end(); ++it)
2042 this->_theParamDB->AddDoubleMatrixParam((*it).first, (*it).second);
2043
2044 }
2045
2046 void
ValidateAlgorithmType()2047 ConfigFileFrontEndApp::ValidateAlgorithmType(
2048 )
2049 {
2050 EDDY_FUNC_DEBUGSCOPE
2051
2052 const string& algType = CFFE_GETVAR(_algType);
2053 if(algType != "MOGA" && algType != "SOGA") throw runtime_error(
2054 "Invalid algorithm type supplied \"" + algType +
2055 "\". Must be one of MOGA or SOGA."
2056 );
2057 }
2058
2059 void
LoadAlgorithmParameters(AlgorithmConfig & aConfig)2060 ConfigFileFrontEndApp::LoadAlgorithmParameters(
2061 AlgorithmConfig& aConfig
2062 )
2063 {
2064 EDDY_FUNC_DEBUGSCOPE
2065
2066 // Start by getting the algorithm type.
2067 const CFFE_TYPEOF(_algType)& aType = CFFE_GETVAR(_algType);
2068
2069 if(aType == "MOGA") aConfig.SetAlgorithmType(AlgorithmConfig::MOGA);
2070 else if(aType == "SOGA") aConfig.SetAlgorithmType(AlgorithmConfig::SOGA);
2071 else throw runtime_error(
2072 "Invalid algorithm type supplied \"" + aType + "\""
2073 );
2074
2075 aConfig.SetMutatorName(CFFE_GETVAR(_mutator));
2076 aConfig.SetFitnessAssessorName(CFFE_GETVAR(_assessor));
2077 aConfig.SetInitializerName(CFFE_GETVAR(_initializer));
2078 aConfig.SetCrosserName(CFFE_GETVAR(_crosser));
2079 aConfig.SetNichePressureApplicatorName(CFFE_GETVAR(_nicher));
2080 aConfig.SetPostProcessorName(CFFE_GETVAR(_postprocessor));
2081 aConfig.SetSelectorName(CFFE_GETVAR(_selector));
2082 aConfig.SetMainLoopName(CFFE_GETVAR(_mainloop));
2083 aConfig.SetConvergerName(CFFE_GETVAR(_converger));
2084 }
2085
2086
2087 /*
2088 ================================================================================
2089 Subclass Overridable Methods
2090 ================================================================================
2091 */
2092
2093
2094 void
RetrieveAllInput(int argc,char * argv[])2095 ConfigFileFrontEndApp::RetrieveAllInput(
2096 int argc,
2097 char* argv[]
2098 )
2099 {
2100 EDDY_FUNC_DEBUGSCOPE
2101
2102 // start with the command line input.
2103 this->RetrieveCommandLineInput(argc, argv);
2104
2105 // now, if a configuration file was not supplied, we are screwed!
2106 if(!this->HasInputValueFor(ITS::_cfgFile)) throw runtime_error(
2107 "The JEGA configuration file front end must be supplied an "
2108 "input file via the command line. Use --help to see how."
2109 );
2110
2111 this->RetrieveConfigFileInput();
2112 }
2113
2114
2115 void
RetrieveCommandLineInput(int argc,char * argv[])2116 ConfigFileFrontEndApp::RetrieveCommandLineInput(
2117 int argc,
2118 char* argv[]
2119 )
2120 {
2121 EDDY_FUNC_DEBUGSCOPE
2122
2123 // Start by parsing and storing the input.
2124 store(parse_command_line(
2125 argc, argv, AllCommandLineInputOptions()
2126 ), *this->_vMap);
2127
2128 // now notify all callback handlers for the variables.
2129 notify(*this->_vMap);
2130
2131 // under certain circumstances, we needn't go any further in
2132 // the program than this.
2133
2134 // The help flag is the first such instance we will look for.
2135 if(this->HasInputValueFor(ITS::_help))
2136 {
2137 this->PrintHelpMessage(cerr);
2138 exit(0);
2139 }
2140 // The version flag is the second such instance we will look for.
2141 if(this->HasInputValueFor(ITS::_version))
2142 {
2143 this->PrintVersionMessage(cerr);
2144 exit(0);
2145 }
2146 }
2147
2148 void
RetrieveConfigFileInput()2149 ConfigFileFrontEndApp::RetrieveConfigFileInput(
2150 )
2151 {
2152 EDDY_FUNC_DEBUGSCOPE
2153
2154 // otherwise, open the file.
2155 string cfgFileName(this->GetValueOf<string>(ITS::_cfgFile));
2156 ifstream ifile(cfgFileName.c_str());
2157
2158 // if it didn't open, there is some other sort of problem that
2159 // we cannot resolve.
2160 if(!ifile.is_open()) throw runtime_error(
2161 "Unable to open configuration file \"" + cfgFileName +
2162 "\" for parsing."
2163 );
2164
2165 // now parse the file and store the input.
2166 store(parse_config_file(ifile, AllConfigFileInputOptions()), *this->_vMap);
2167
2168 // now close the file for good measure.
2169 ifile.close();
2170
2171 // now notify all callback handlers for the variable map.
2172 notify(*this->_vMap);
2173 }
2174
2175 void
ValidateAllInput()2176 ConfigFileFrontEndApp::ValidateAllInput(
2177 )
2178 {
2179 EDDY_FUNC_DEBUGSCOPE
2180 this->ValidateAlgorithmType();
2181 }
2182
2183 EvaluatorCreator*
GetEvaluatorCreator()2184 ConfigFileFrontEndApp::GetEvaluatorCreator(
2185 )
2186 {
2187 EDDY_FUNC_DEBUGSCOPE
2188 return new GenericEvaluatorCreator<ExternalEvaluator>();
2189 }
2190
2191 LogLevel
ResolveLogLevel(const string & input) const2192 ConfigFileFrontEndApp::ResolveLogLevel(
2193 const string& input
2194 ) const
2195 {
2196 EDDY_FUNC_DEBUGSCOPE
2197
2198 // Use the LevelClass to resolve. any unrecognized input will result in
2199 // the use of the Default level.
2200 return LevelClass::get_level_of(input);
2201 }
2202
2203
2204
2205 /*
2206 ================================================================================
2207 Private Methods
2208 ================================================================================
2209 */
2210
2211
2212 options_description
CreateAllCommandLineInputOptions()2213 ConfigFileFrontEndApp::CreateAllCommandLineInputOptions(
2214 )
2215 {
2216 EDDY_FUNC_DEBUGSCOPE
2217 options_description options("All Command Line Input Options");
2218 options.add(CommandLineOnlyInputOptions()).add(SharedInputOptions());
2219 return options;
2220 }
2221
2222 #define OPTION_ND(id, d) ( ITS::id, value<CFFE_TYPEOF(id)>(), d )
2223 #define OPTION_WD(id, d) \
2224 ( ITS::id.c_str(), value<CFFE_TYPEOF(id)>()->default_value(DVS::id), d )
2225
2226 options_description
CreateCommandLineOnlyInputOptions()2227 ConfigFileFrontEndApp::CreateCommandLineOnlyInputOptions(
2228 )
2229 {
2230 EDDY_FUNC_DEBUGSCOPE
2231
2232 options_description options("Command Line Only Input Options");
2233
2234 options.add_options()
2235 (
2236 (ITS::_cfgFile + ",c").c_str(),
2237 value<CFFE_TYPEOF(_cfgFile)>()->default_value(DVS::_cfgFile),
2238 "The file from which to retrieve the configuration settings."
2239 )
2240 (
2241 (ITS::_help + ",h").c_str(),
2242 "Prints the help message to the standard output stream."
2243 )
2244 (
2245 (ITS::_version + ",v").c_str(),
2246 "Prints the current JEGA version and build date."
2247 );
2248
2249 return options;
2250 }
2251
2252 options_description
CreateConfigFileOnlyInputOptions()2253 ConfigFileFrontEndApp::CreateConfigFileOnlyInputOptions(
2254 )
2255 {
2256 EDDY_FUNC_DEBUGSCOPE
2257
2258 options_description options("Configuration File Only Input Options");
2259
2260 options.add_options()
2261
2262 OPTION_WD(_assessor,
2263 "The name of the fitness assessment operator to use (string)."
2264 )
2265
2266 OPTION_WD(_initializer,
2267 "The name of the initialization operator to use (string)."
2268 )
2269
2270 OPTION_WD(_mutator,
2271 "The name of the mutation operator to use (string)."
2272 )
2273
2274 OPTION_WD(_crosser,
2275 "The name of the crossover operator to use (string)."
2276 )
2277
2278 OPTION_WD(_nicher,
2279 "The name of the niche pressure operator to use (string)."
2280 )
2281
2282 OPTION_WD(_postprocessor,
2283 "The name of the post processing operator to use (string)."
2284 )
2285
2286 OPTION_WD(_mainloop,
2287 "The name of the main loop operator to use (string)."
2288 )
2289
2290 OPTION_WD(_selector,
2291 "The name of the selection operator to use (string)."
2292 )
2293
2294 OPTION_WD(_converger,
2295 "The name of the convergence operator to use (string)."
2296 )
2297
2298 OPTION_WD(_intParams,
2299 "Integral parameters as name value pairs (string, integer)."
2300 )
2301
2302 OPTION_WD(_dblParams,
2303 "Floating point parameters as name value pairs (string, real)."
2304 )
2305
2306 OPTION_WD(_sztParams,
2307 "Size type parameters as name value pairs "
2308 "(string, unsigned integer)."
2309 )
2310
2311 OPTION_WD(_boolParams,
2312 "Boolean parameters as name value pairs (string, Boolean)."
2313 )
2314
2315 OPTION_WD(_strParams,
2316 "String parameters as name value pairs (string, string)."
2317 )
2318
2319 OPTION_WD(_intVecParams,
2320 "Integral vector parameters as name vector-value pairs "
2321 "(string, vector of integer)."
2322 )
2323
2324 OPTION_WD(_dblVecParams,
2325 "Double vector parameters as name vector-value pairs "
2326 "(string, vector of real)."
2327 )
2328
2329 OPTION_WD(_strVecParams,
2330 "String vector parameters as name vector-value pairs "
2331 "(string, vector of string)."
2332 )
2333
2334 OPTION_WD(_dblMatParams,
2335 "Double matrix parameters as multiple name vector-value pairs "
2336 "(multiple (string, vector of real) each with the same string)."
2337 )
2338
2339 OPTION_WD(_rndSeed,
2340 "The seed for the random number generator (unsigned integer)."
2341 )
2342
2343 OPTION_WD(_globLogFile,
2344 "The name of the file for the global logger to write to (string)."
2345 )
2346
2347 OPTION_WD(_globLogLevel,
2348 "The level at which to log entries to the global log "
2349 "(string-one of debug, verbose, quiet, silent, or fatal)."
2350 )
2351
2352 OPTION_WD(_algType,
2353 "The type of the algorithm to run (string-one of MOGA or SOGA)."
2354 )
2355
2356 OPTION_WD(_contRealVar,
2357 "Declaration of a continuous real variable "
2358 "(unsigned integer, string, real, real, integer)."
2359 )
2360
2361 OPTION_WD(_discRealVar,
2362 "Declaration of a discrete real variable "
2363 "(unsigned integer, string, vector of real)."
2364 )
2365
2366 OPTION_WD(_contIntVar,
2367 "Declaration of a continuous integer variable "
2368 "(unsigned integer, string, integer, integer)."
2369 )
2370
2371 OPTION_WD(_discIntVar,
2372 "Declaration of a discrete integer variable "
2373 "(unsigned integer, string, vector of integer)."
2374 )
2375
2376 OPTION_WD(_boolVar,
2377 "Declaration of a Boolean variable "
2378 "(unsigned integer, string-one of t, f, true, false, 1, 0)."
2379 )
2380
2381 OPTION_WD(_linMinObj,
2382 "Declaration of a linear minimization objective "
2383 "(unsigned integer, string, vector of real)."
2384 )
2385
2386 OPTION_WD(_nonLinMinObj,
2387 "Declaration of a non-linear minimization objective "
2388 "(unsigned integer, string)."
2389 )
2390
2391 OPTION_WD(_linMaxObj,
2392 "Declaration of a linear maximization objective "
2393 "(unsigned integer, string, vector of real)."
2394 )
2395
2396 OPTION_WD(_nonLinMaxObj,
2397 "Declaration of a non-linear maximization objective "
2398 "(unsigned integer, string)."
2399 )
2400
2401 OPTION_WD(_linSkValObj,
2402 "Declaration of a linear seek value objective "
2403 "(unsigned integer, string, real, vector of real)."
2404 )
2405
2406 OPTION_WD(_nonLinSkValObj,
2407 "Declaration of a non-linear seek value objective "
2408 "(unsigned integer, string, real)."
2409 )
2410
2411 OPTION_WD(_linSkRngObj,
2412 "Declaration of a linear seek range objective "
2413 "(unsigned integer, string, real, real, vector of real)."
2414 )
2415
2416 OPTION_WD(_nonLinSkRngObj,
2417 "Declaration of a non-linear seek range objective "
2418 "(unsigned integer, string, real, real)."
2419 )
2420
2421 OPTION_WD(_linInEqCon,
2422 "Declaration of a linear inequality constraint "
2423 "(unsigned integer, string, real, vector of real)."
2424 )
2425
2426 OPTION_WD(_nonLinInEqCon,
2427 "Declaration of a non-linear inequality constraint "
2428 "(unsigned integer, string, real)."
2429 )
2430
2431 OPTION_WD(_linEqCon,
2432 "Declaration of a linear equality constraint "
2433 "(unsigned integer, string, real, real, vector of real)."
2434 )
2435
2436 OPTION_WD(_nonLinEqCon,
2437 "Declaration of a non-linear equality constraint "
2438 "(unsigned integer, string, real, real)."
2439 )
2440
2441 OPTION_WD(_linTwoSideIneqCon,
2442 "Declaration of a linear 2-sided inequality constraint "
2443 "(unsigned integer, string, real, real, vector of real)."
2444 )
2445
2446 OPTION_WD(_nonLinTwoSideIneqCon,
2447 "Declaration of a non-linear 2-sided inequality constraint "
2448 "(unsigned integer, string, real, real)."
2449 )
2450
2451 OPTION_WD(_linNotEqCon,
2452 "Declaration of a linear not-equality constraint "
2453 "(unsigned integer, string, real, vector of real)."
2454 )
2455
2456 OPTION_WD(_nonLinNotEqCon,
2457 "Declaration of a non-linear not-equality constraint "
2458 "(unsigned integer, string, real)."
2459 );
2460
2461 return options;
2462 }
2463
2464 #undef ADD_OPTION_ND
2465 #undef ADD_OPTION_WD
2466
2467 program_options::options_description
CreateAllConfigFileInputOptions()2468 ConfigFileFrontEndApp::CreateAllConfigFileInputOptions(
2469 )
2470 {
2471 EDDY_FUNC_DEBUGSCOPE
2472
2473 options_description options("All Configuration File Input Options");
2474 options.add(ConfigFileOnlyInputOptions()).add(SharedInputOptions());
2475 return options;
2476 }
2477
2478 options_description
CreateSharedInputOptions()2479 ConfigFileFrontEndApp::CreateSharedInputOptions(
2480 )
2481 {
2482 EDDY_FUNC_DEBUGSCOPE
2483 options_description options("Shared Input Options");
2484 return options;
2485 }
2486
2487 options_description
CreateAllInputOptions()2488 ConfigFileFrontEndApp::CreateAllInputOptions(
2489 )
2490 {
2491 EDDY_FUNC_DEBUGSCOPE
2492
2493 // create the options_description object with the desired caption.
2494 options_description options("All Input Options");
2495
2496 // now add the command line only, config file only, and shared options.
2497 options.add(CommandLineOnlyInputOptions());
2498 options.add(ConfigFileOnlyInputOptions());
2499 options.add(SharedInputOptions());
2500
2501 // finally, return our options object.
2502 return options;
2503 }
2504
2505 /*
2506 ================================================================================
2507 Structors
2508 ================================================================================
2509 */
2510
ConfigFileFrontEndApp()2511 ConfigFileFrontEndApp::ConfigFileFrontEndApp(
2512 ) :
2513 _vMap(new variables_map()),
2514 _theParamDB(new BasicParameterDatabaseImpl()),
2515 _theProbConfig(new ProblemConfig())
2516 {
2517 EDDY_FUNC_DEBUGSCOPE
2518 }
2519
~ConfigFileFrontEndApp()2520 ConfigFileFrontEndApp::~ConfigFileFrontEndApp(
2521 )
2522 {
2523 EDDY_FUNC_DEBUGSCOPE
2524 delete this->_vMap;
2525 delete this->_theParamDB;
2526 delete this->_theProbConfig;
2527 }
2528
2529 /*
2530 ================================================================================
2531 End Namespace
2532 ================================================================================
2533 */
2534 } // namespace ConfigFile
2535 } // namespace FrontEnd
2536 } // namespace JEGA
2537