1 /*
2 ================================================================================
3 PROJECT:
4
5 John Eddy's Genetic Algorithms (JEGA) Front End
6
7 CONTENTS:
8
9 Implementation of class Driver.
10
11 NOTES:
12
13 See notes of Driver.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 Fri Jan 06 07:40:17 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 Driver 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/JEGATypes.hpp>
60 #include <../Utilities/include/JEGAConfig.hpp>
61
62 #include <ctime>
63 #include <csignal>
64 #include <iostream>
65 #include <stdexcept>
66 #include <../FrontEnd/Core/include/Driver.hpp>
67 #include <../FrontEnd/Core/include/ProblemConfig.hpp>
68 #include <../FrontEnd/Core/include/AlgorithmConfig.hpp>
69 #include <../FrontEnd/Core/include/EvaluatorCreator.hpp>
70
71 #include <../MOGA/include/MOGA.hpp>
72 #include <../SOGA/include/SOGA.hpp>
73
74 #include <utilities/include/EDDY_DebugScope.hpp>
75 #include <../Utilities/include/ParameterDatabase.hpp>
76 #include <utilities/include/RandomNumberGenerator.hpp>
77
78 #include <GeneticAlgorithmMutator.hpp>
79 #include <GeneticAlgorithmCrosser.hpp>
80 #include <GeneticAlgorithmMainLoop.hpp>
81 #include <GeneticAlgorithmSelector.hpp>
82 #include <GeneticAlgorithmEvaluator.hpp>
83 #include <GeneticAlgorithmConverger.hpp>
84 #include <GeneticAlgorithmInitializer.hpp>
85 #include <GeneticAlgorithmPostProcessor.hpp>
86 #include <GeneticAlgorithmFitnessAssessor.hpp>
87 #include <GeneticAlgorithmNichePressureApplicator.hpp>
88
89 #include <OperatorGroups/AllOperators.hpp>
90
91
92 /*
93 ================================================================================
94 Namespace Using Directives
95 ================================================================================
96 */
97 using namespace std;
98 using namespace JEGA::Logging;
99 using namespace JEGA::Utilities;
100 using namespace eddy::utilities;
101 using namespace JEGA::Algorithms;
102
103
104
105
106 /*
107 ================================================================================
108 Begin Namespace
109 ================================================================================
110 */
111 namespace JEGA {
112 namespace FrontEnd {
113
114
115
116
117
118 /*
119 ================================================================================
120 Static Member Data Definitions
121 ================================================================================
122 */
123 bool Driver::_initialized = false;
124 unsigned int Driver::_rSeed = 0;
125
126
127
128
129
130
131
132 /*
133 ================================================================================
134 Mutators
135 ================================================================================
136 */
137
138
139
140
141
142
143
144
145 /*
146 ================================================================================
147 Accessors
148 ================================================================================
149 */
150
151 unsigned int
GetRandomSeed()152 Driver::GetRandomSeed(
153 )
154 {
155 EDDY_FUNC_DEBUGSCOPE
156 return _rSeed;
157 }
158
159 const std::string&
GetGlobalLogFilename()160 Driver::GetGlobalLogFilename(
161 )
162 {
163 EDDY_FUNC_DEBUGSCOPE
164 JEGA_LOGGING_IF_OFF(
165 static const std::string ret;
166 return ret;
167 )
168 JEGA_LOGGING_IF_ON(return Logger::Global().GetFilename();)
169 }
170
171 bool
IsJEGAInitialized()172 Driver::IsJEGAInitialized(
173 )
174 {
175 EDDY_FUNC_DEBUGSCOPE
176 return _initialized;
177 }
178
179 const char*
GetXType()180 Driver::GetXType(
181 )
182 {
183 EDDY_FUNC_DEBUGSCOPE
184 return typeid(var_rep_t).name();
185 }
186
187 const char*
GetGType()188 Driver::GetGType(
189 )
190 {
191 EDDY_FUNC_DEBUGSCOPE
192 return typeid(con_val_t).name();
193 }
194
195 const char*
GetFType()196 Driver::GetFType(
197 )
198 {
199 EDDY_FUNC_DEBUGSCOPE
200 return typeid(obj_val_t).name();
201 }
202
203
204
205
206
207 /*
208 ================================================================================
209 Public Methods
210 ================================================================================
211 */
212 bool
InitializeJEGA(const string & globalLogFilename,const LogLevel & globalLogDefLevel,unsigned int rSeed,Logger::FatalBehavior onFatal,bool registerSignalHandlers)213 Driver::InitializeJEGA(
214 const string& globalLogFilename,
215 const LogLevel& globalLogDefLevel,
216 unsigned int rSeed,
217 Logger::FatalBehavior onFatal,
218 bool registerSignalHandlers
219 )
220 {
221 EDDY_FUNC_DEBUGSCOPE
222
223 if(IsJEGAInitialized()) throw runtime_error(
224 "Attempt to re-initialize JEGA is illegal. InitializeJEGA can be "
225 "called once and only once."
226 );
227
228 // The handle_signal method will give the debugscope project it's chance.
229 // So there are no EDDY_DEBUGSIGNAL calls in this method.
230 if (registerSignalHandlers)
231 {
232 ::signal(SIGSEGV, &Driver::handle_signal);
233 EDDY_IF_NO_WINDOWS(::signal(SIGINT, &Driver::handle_signal);)
234 ::signal(SIGILL, &Driver::handle_signal);
235 ::signal(SIGFPE, &Driver::handle_signal);
236 ::signal(SIGTERM, &Driver::handle_signal);
237 ::signal(SIGABRT, &Driver::handle_signal);
238 }
239
240 // Start by initializing the logger
241 JEGA_LOGGING_INIT(globalLogFilename, globalLogDefLevel);
242 Logger::SetFatalBehavior(onFatal);
243
244 // make sure the operator groups are instantiated.
245 AllOperators::FullInstance();
246
247 _rSeed =
248 (rSeed == 0) ? static_cast<unsigned int>(clock() + time(0x0)) : rSeed;
249
250 SeedRandomGenerator(_rSeed);
251
252 return _initialized = true;
253 }
254
255 unsigned int
ReSeed(unsigned int rSeed)256 Driver::ReSeed(
257 unsigned int rSeed
258 )
259 {
260 EDDY_FUNC_DEBUGSCOPE
261
262 _rSeed =
263 (rSeed == 0) ? static_cast<unsigned int>(clock() + time(0x0)) : rSeed;
264
265 SeedRandomGenerator(_rSeed);
266
267 return _rSeed;
268 }
269
270 void
ResetGlobalLoggingLevel(const JEGA::Logging::LogLevel & globalLogDefLevel)271 Driver::ResetGlobalLoggingLevel(
272 const JEGA::Logging::LogLevel& globalLogDefLevel
273 )
274 {
275 EDDY_FUNC_DEBUGSCOPE
276
277 JEGA_LOGGING_IF_ON(
278 Logger::Global().Gate().set_default_level(globalLogDefLevel);
279 )
280
281 JEGA_LOGGING_IF_ON(
282 Logger::Global().Gate().get_log().log(
283 Logger::Global().GetName() +
284 JEGA_LOGGING_AS_STRING_LITERAL(" default level reset to \"") +
285 LevelClass::to_ostreamable(
286 Logger::Global().Gate().get_default_level()
287 ) +
288 JEGA_LOGGING_AS_STRING_LITERAL("\".")
289 );
290 )
291
292 }
293
294 void
FlushGlobalLogStreams()295 Driver::FlushGlobalLogStreams(
296 )
297 {
298 EDDY_FUNC_DEBUGSCOPE
299 JEGA_LOGGING_IF_ON(Logger::Global().FlushStreams();)
300 }
301
302 DesignOFSortSet
ExecuteAlgorithm(const AlgorithmConfig & algConfig)303 Driver::ExecuteAlgorithm(
304 const AlgorithmConfig& algConfig
305 )
306 {
307 EDDY_FUNC_DEBUGSCOPE
308
309 try
310 {
311 GeneticAlgorithm* theGA = this->ExtractAllData(algConfig);
312 DesignOFSortSet ret(this->PerformIterations(theGA));
313 this->DestroyAlgorithm(theGA);
314 return ret;
315 }
316 catch(const exception& e)
317 {
318 JEGALOG_II_G_F(this,
319 text_entry(lfatal(),
320 "JEGA Front End Error: Exception caught at application "
321 "level reading: \"") << e.what() << "\"."
322 )
323 }
324
325 return DesignOFSortSet();
326 }
327
328 JEGA::Algorithms::GeneticAlgorithm*
InitializeAlgorithm(const AlgorithmConfig & algConfig)329 Driver::InitializeAlgorithm(
330 const AlgorithmConfig& algConfig
331 )
332 {
333 EDDY_FUNC_DEBUGSCOPE
334
335 GeneticAlgorithm* theGA = this->ExtractAllData(algConfig);
336
337 JEGAIFLOG_CF_II_G_F(theGA == 0x0, this,
338 text_entry(lfatal(),
339 "JEGA Front End Error: Attempt to initialize a null algorithm.")
340 )
341
342 JEGAIFLOG_CF_II_G_F(!theGA->AlgorithmInitialize(), this,
343 text_entry(lfatal(),
344 "JEGA Front End Error: Unable to initialize the GA " +
345 theGA->GetName() + '.')
346 )
347
348 return theGA;
349 }
350
351 bool
PerformNextIteration(JEGA::Algorithms::GeneticAlgorithm * theGA)352 Driver::PerformNextIteration(
353 JEGA::Algorithms::GeneticAlgorithm* theGA
354 )
355 {
356 EDDY_FUNC_DEBUGSCOPE
357
358 JEGAIFLOG_CF_II_G_F(theGA == 0x0, this,
359 text_entry(lfatal(),
360 "JEGA Front End Error: Attempt to perform an iteration on a "
361 "null algorithm.")
362 )
363
364 return theGA->AlgorithmProcess();
365 }
366
367 DesignOFSortSet
FinalizeAlgorithm(JEGA::Algorithms::GeneticAlgorithm * theGA)368 Driver::FinalizeAlgorithm(
369 JEGA::Algorithms::GeneticAlgorithm* theGA
370 )
371 {
372 EDDY_FUNC_DEBUGSCOPE
373
374 JEGAIFLOG_CF_II_G_F(theGA == 0x0, this,
375 text_entry(lfatal(),
376 "JEGA Front End Error: Attempt to finalize a null algorithm.")
377 )
378
379 theGA->AlgorithmFinalize();
380 DesignOFSortSet ret(this->DeepDuplicate(theGA->GetCurrentSolution()));
381 this->DestroyAlgorithm(theGA);
382 return ret;
383 }
384
385 /*
386 ================================================================================
387 Subclass Visible Methods
388 ================================================================================
389 */
390
391 GeneticAlgorithm*
ExtractAllData(const AlgorithmConfig & algConfig)392 Driver::ExtractAllData(
393 const AlgorithmConfig& algConfig
394 )
395 {
396 EDDY_FUNC_DEBUGSCOPE
397
398 EDDY_DEBUG(!this->_initialized, "Must call Driver::InitializeJEGA prior to "
399 "extracting data for an algorithm.")
400
401 try
402 {
403 if(!this->_initialized)
404 {
405 cerr << "JEGA Front End Error: Attempt to run JEGA prior to call "
406 "to Driver::InitializeJEGA. Please modify your code.\n";
407 exit(4);
408 }
409
410 JEGAIFLOG_CF_II_G_F(this->_probConfig.GetDesignTarget().GetNOF() == 0,
411 this,
412 text_entry(lfatal(), "JEGA Front End Error: Attempt to run a JEGA "
413 "algorithm with no objective functions defined. You must "
414 "create at least 1 objective.")
415 )
416
417 Logger* newLog = 0x0;
418
419 #ifdef JEGA_LOGGING_ON
420
421 // prepare the logger to use for this algorithm. If the logging
422 // filename in the algConfig object is non-empty, then the logger used
423 // is a new one created to log to the file. Otherwise, it is
424 // the global logger.
425
426 // if we wind up creating a new log, it will have to be named. See
427 // if the algorithm was given a name and if so, use it. Otherwise
428 // call it "unnamed".
429
430 // figure out if we will be creating a new Logger. To do so, we will
431 // need the supplied algorithm name and logging file name.
432 string logfile(this->GetAlgorithmLogFilename(algConfig));
433 string algname(this->GetAlgorithmName(algConfig));
434
435 if(!logfile.empty())
436 {
437 string logName(
438 (!algname.empty() ? algname : string("Unknown GA")) + " Logger"
439 );
440
441 newLog = new Logger(
442 logfile, logName, GetAlgorithmDefaultLogLevel(algConfig)
443 );
444 newLog->Init();
445 }
446
447 Logger& tLog = (newLog == 0x0) ? Logger::Global() : *newLog;
448
449 #else
450
451 Logger tLog;
452
453 #endif
454
455 GeneticAlgorithm* theGA = this->CreateNewAlgorithm(algConfig, tLog);
456
457 JEGAIFLOG_CF_II_G_F(theGA == 0x0, this,
458 text_entry(lfatal(),
459 "JEGA Front End Error: Unable to create a genetic algorithm.")
460 )
461
462 // now make use of the configuration object to load up the GA.
463 this->LoadAlgorithm(*theGA, algConfig);
464
465 // Add newLog to the list of logs that we are responsible for
466 // destroying iff it is non-null.
467 if(newLog != 0x0)
468 this->_myLogs.insert(GALoggerMap::value_type(theGA, newLog));
469
470 // We put newLog in here because it only has a non-null value if it
471 // needs to be destroyed at some later time.
472 return theGA;
473 }
474 catch(const exception& e)
475 {
476 JEGALOG_II_G_F(this,
477 text_entry(lfatal(),
478 "JEGA Front End Error: Exception caught at application "
479 "level reading: \"") << e.what() << "\"."
480 )
481 return 0x0;
482 }
483 }
484
485 DesignOFSortSet
PerformIterations(JEGA::Algorithms::GeneticAlgorithm * theGA)486 Driver::PerformIterations(
487 JEGA::Algorithms::GeneticAlgorithm* theGA
488 )
489 {
490 EDDY_FUNC_DEBUGSCOPE
491
492 try
493 {
494 // prepare to time this run.
495 JEGA_LOGGING_IF_ON(clock_t start = clock();)
496
497 theGA->AlgorithmInitialize();
498 while(this->PerformNextIteration(theGA));
499 theGA->AlgorithmFinalize();
500
501 JEGA_LOGGING_IF_ON(
502 double elapsed =
503 static_cast<double>((clock() - start)) / CLOCKS_PER_SEC;
504 )
505
506 JEGALOG_II(theGA->GetLogger(), lquiet(), this,
507 ostream_entry(
508 lquiet(), "JEGA Front End: " + theGA->GetName() +
509 " execution took ") << elapsed << " seconds."
510 )
511
512 JEGALOG_II_G(lquiet(), this,
513 ostream_entry(lquiet(), "JEGA Front End: Execution took ")
514 << elapsed << " seconds."
515 )
516
517 return this->DeepDuplicate(theGA->GetCurrentSolution());
518 }
519 catch(const exception& e)
520 {
521 JEGALOG_II_G_F(this,
522 text_entry(lfatal(),
523 "JEGA Front End Error: Exception caught at application "
524 "level reading: \"") << e.what() << "\"."
525 )
526 }
527
528 return DesignOFSortSet();
529 }
530
531 void
DestroyAlgorithm(GeneticAlgorithm * theGA)532 Driver::DestroyAlgorithm(
533 GeneticAlgorithm* theGA
534 )
535 {
536 EDDY_FUNC_DEBUGSCOPE
537
538 // Begin by finding theGA in the logger map.
539 GALoggerMap::iterator loc(this->_myLogs.find(theGA));
540
541 // Destroy the GA before destroying the log in case it wants to write
542 // from the destructor.
543 delete theGA;
544
545 // if we found it, delete the associated log and remove the map entry.
546 if(loc != this->_myLogs.end())
547 {
548 delete (*loc).second;
549 this->_myLogs.erase(loc);
550 }
551
552 }
553
554 string
GetAlgorithmName(const AlgorithmConfig & from)555 Driver::GetAlgorithmName(
556 const AlgorithmConfig& from
557 )
558 {
559 EDDY_FUNC_DEBUGSCOPE
560 try {
561 return from.GetParameterDB().GetString("method.jega.algorithm_name");
562 }
563 catch(...) { return string(); }
564 }
565
566 string
GetAlgorithmLogFilename(const AlgorithmConfig & from)567 Driver::GetAlgorithmLogFilename(
568 const AlgorithmConfig& from
569 )
570 {
571 EDDY_FUNC_DEBUGSCOPE
572 try {
573 return from.GetParameterDB().GetString("method.log_file");
574 }
575 catch(...) { return string(); }
576 }
577
578 string
GetAlgorithmType(const AlgorithmConfig & from)579 Driver::GetAlgorithmType(
580 const AlgorithmConfig& from
581 )
582 {
583 EDDY_FUNC_DEBUGSCOPE
584 try {
585 return from.GetParameterDB().GetString("method.algorithm");
586 }
587 catch(...) { return string(); }
588 }
589
590 LogLevel
GetAlgorithmDefaultLogLevel(const AlgorithmConfig & from)591 Driver::GetAlgorithmDefaultLogLevel(
592 const AlgorithmConfig& from
593 )
594 {
595 EDDY_FUNC_DEBUGSCOPE
596 try {
597 return static_cast<LogLevel>(
598 from.GetParameterDB().GetIntegral("method.output")
599 );
600 }
601 catch(...) { return LevelClass::Default; }
602 }
603
604 GeneticAlgorithm*
CreateNewAlgorithm(const AlgorithmConfig & algConfig,Logger & logger)605 Driver::CreateNewAlgorithm(
606 const AlgorithmConfig& algConfig,
607 Logger& logger
608 )
609 {
610 EDDY_FUNC_DEBUGSCOPE
611
612 // Start by trying to retrieve the algorithm type from the algorithm
613 // config.
614 AlgorithmConfig::AlgType algType = AlgorithmConfig::MOGA;
615
616 string algTypeStr(this->GetAlgorithmType(algConfig));
617
618 if(algTypeStr == "moga") algType = AlgorithmConfig::MOGA;
619 else if(algTypeStr == "soga") algType = AlgorithmConfig::SOGA;
620
621 else if(algTypeStr.empty()) JEGALOG_II_G_F(this,
622 ostream_entry(lfatal(), "JEGA Front End Error: "
623 "Algorithm type not supplied.")
624 )
625 else JEGALOG_II_G_F(this,
626 ostream_entry(lfatal(), "JEGA Front End Error: "
627 "Invalid algorithm type supplied: ") << algTypeStr
628 )
629
630 GeneticAlgorithm* theGA = 0x0;
631
632 if(algType == AlgorithmConfig::MOGA)
633 {
634 JEGALOG_II_G(
635 lverbose(), this, text_entry(lverbose(),
636 "JEGA Front End: Creating a MOGA")
637 )
638 theGA = new MOGA(this->_probConfig.GetDesignTarget(), logger);
639 }
640
641 else if(algType == AlgorithmConfig::SOGA)
642 {
643 JEGALOG_II_G(
644 lverbose(), this, text_entry(lverbose(),
645 "JEGA Front End: Creating a SOGA")
646 )
647 theGA = new SOGA(this->_probConfig.GetDesignTarget(), logger);
648 }
649 else
650 JEGALOG_II_G_F(this,
651 ostream_entry(lfatal(), "JEGA Front End Error: "
652 "Unknown algorithm type: ") << algType
653 )
654
655 return theGA;
656 }
657
658 void
SeedRandomGenerator(unsigned int seed)659 Driver::SeedRandomGenerator(
660 unsigned int seed
661 )
662 {
663 EDDY_FUNC_DEBUGSCOPE
664 RandomNumberGenerator::Seed(seed);
665
666 JEGALOG_IT_G(lquiet(), Driver,
667 ostream_entry(lquiet(), "JEGA Front End: Random seed = ") << seed
668 )
669 }
670
671 void
LoadAlgorithm(GeneticAlgorithm & theGA,const AlgorithmConfig & algConfig)672 Driver::LoadAlgorithm(
673 GeneticAlgorithm& theGA,
674 const AlgorithmConfig& algConfig
675 )
676 {
677 EDDY_FUNC_DEBUGSCOPE
678
679 // Store the parameter database for repeated use by this method
680 const ParameterDatabase& pdb = algConfig.GetParameterDB();
681
682 // begin by creating the operators and loading them into an operator
683 // set. The set will be validated by the GeneticAlgorithm after it
684 // is completely loaded. The Set<operator> methods put the newly created
685 // operators into the supplied set.
686 GeneticAlgorithmOperatorSet theOps(theGA);
687
688 SetConverger(pdb.GetString("method.jega.convergence_type"), theOps);
689 SetCrosser(pdb.GetString("method.crossover_type"), theOps);
690 SetNichePressureApplicator(
691 pdb.GetString("method.jega.niching_type"), theOps
692 );
693 SetFitnessAssessor(pdb.GetString("method.fitness_type"), theOps);
694 SetInitializer(pdb.GetString("method.initialization_type"), theOps);
695 SetMainLoop(pdb.GetString("method.jega.mainloop_type"), theOps);
696 SetMutator(pdb.GetString("method.mutation_type"), theOps);
697 SetSelector(pdb.GetString("method.replacement_type"), theOps);
698 SetPostProcessor(
699 pdb.GetString("method.jega.postprocessor_type"), theOps
700 );
701
702 // handle the evaluator specially b/c it is not in a group.
703 EvaluatorCreator& ector = algConfig.GetTheEvaluatorCreator();
704 GeneticAlgorithmEvaluator* evaler = ector.CreateEvaluator(theGA);
705 VerifyValidOperator(evaler, "Evaluator", "Custom Evaluator");
706 theOps.SetEvaluator(evaler);
707
708 // now inform the genetic algorithm of the operator set and let it
709 // determine if it is a valid set.
710 JEGAIFLOG_CF_IT_G_F(!theGA.SetOperatorSet(theOps), Driver,
711 text_entry(lfatal(), "JEGA Front End Error: Failed to match a group "
712 "to the chosen operators.")
713 );
714
715 // Now get the parameters extracted for all operators and the GA.
716 theGA.ExtractParameters(algConfig.GetParameterDB());
717 }
718
719 void
VerifyValidOperator(GeneticAlgorithmOperator * op,const string & type,const string & name)720 Driver::VerifyValidOperator(
721 GeneticAlgorithmOperator* op,
722 const string& type,
723 const string& name
724 )
725 {
726 EDDY_FUNC_DEBUGSCOPE
727 JEGAIFLOG_CF_IT_G_F(op == 0x0, Driver,
728 text_entry(lfatal(), "JEGA Front End Error: Unable to resolve ")
729 << type << " \"" << name << "\""
730 );
731 }
732
733 #define SET_OP_METHOD(optype) \
734 GeneticAlgorithm##optype* \
735 Driver::Set##optype( \
736 const string& name, \
737 GeneticAlgorithmOperatorSet& into \
738 ) \
739 { \
740 EDDY_FUNC_DEBUGSCOPE \
741 GeneticAlgorithm##optype* op = \
742 AllOperators::FullInstance().Get##optype( \
743 name, into.GetAlgorithm() \
744 ); \
745 VerifyValidOperator(op, #optype, name); \
746 into.Set##optype(op); \
747 return op; \
748 }
749
750 SET_OP_METHOD(Converger)
SET_OP_METHOD(Crosser)751 SET_OP_METHOD(Crosser)
752 SET_OP_METHOD(FitnessAssessor)
753 SET_OP_METHOD(Initializer)
754 SET_OP_METHOD(MainLoop)
755 SET_OP_METHOD(Mutator)
756 SET_OP_METHOD(Selector)
757 SET_OP_METHOD(PostProcessor)
758 SET_OP_METHOD(NichePressureApplicator)
759
760
761 DesignOFSortSet
762 Driver::DeepDuplicate(
763 const DesignOFSortSet& from,
764 bool moveTags
765 )
766 {
767 EDDY_FUNC_DEBUGSCOPE
768
769 DesignOFSortSet ret;
770 if(from.empty()) return ret;
771
772 const DesignTarget& target = from.front()->GetDesignTarget();
773
774 DesignOFSortSet::const_iterator it(from.begin());
775 DesignOFSortSet::iterator where(ret.end());
776
777 for(; it!=from.end(); ++it)
778 {
779 const Design& toCopy = **it;
780 Design* des = target.GetNewDesign(toCopy);
781 if(moveTags)
782 {
783 des->SetTag(toCopy.GetTag());
784 const_cast<Design&>(toCopy).SetTag(0x0);
785 }
786 where = ret.insert(where, des);
787 }
788
789 return ret;
790 }
791
792 /*
793 ================================================================================
794 Subclass Overridable Methods
795 ================================================================================
796 */
797
798
799
800
801
802
803
804
805 /*
806 ================================================================================
807 Private Methods
808 ================================================================================
809 */
810
811 void
handle_signal(int val)812 Driver::handle_signal(
813 int val
814 ) throw()
815 {
816 EDDY_FUNC_DEBUGSCOPE
817
818 JEGA_LOGGING_IF_OFF(return;)
819
820 ostream_entry ose(lsilent(), "JEGA Front End: signal caught: value = ");
821 ose << val << ' ';
822
823 switch(val)
824 {
825 case SIGSEGV: ose << "(SIGSEGV)"; break;
826 case SIGINT : ose << "(SIGINT)"; break;
827 case SIGFPE : ose << "(SIGFPE)"; break;
828 case SIGILL : ose << "(SIGILL)"; break;
829 case SIGTERM: ose << "(SIGTERM)"; break;
830 case SIGABRT: ose << "(SIGABRT)"; break;
831 default: ose << "(UNKNOWN)";
832 }
833
834 JEGALOG_G(lsilent(), ose);
835
836 // Now, if we have debugging enabled, let it do it's thing.
837 #ifdef JEGA_OPTION_DEBUG
838 eddy::utilities::EDDY_Debug::_Signal(val);
839 #endif
840 }
841
842
843
844
845
846
847
848 /*
849 ================================================================================
850 Structors
851 ================================================================================
852 */
853
854
Driver(const ProblemConfig & probConfig)855 Driver::Driver(
856 const ProblemConfig& probConfig
857 ) :
858 _probConfig(probConfig)
859 {
860 EDDY_FUNC_DEBUGSCOPE
861 }
862
~Driver()863 Driver::~Driver(
864 )
865 {
866 EDDY_FUNC_DEBUGSCOPE
867
868 // If there is anything left in the map, clean it out. The call to
869 // DestroyAlgorithm will remove an entry from the _myLogs map.
870 while(!this->_myLogs.empty())
871 DestroyAlgorithm((*this->_myLogs.begin()).first);
872 }
873
874
875
876
877 /*
878 ================================================================================
879 End Namespace
880 ================================================================================
881 */
882 } // namespace FrontEnd
883 } // namespace JEGA
884
885