- Main Page
- Classes
- Files

- Search for |

# moeoEasyEA.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoEasyEA.h
    00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
    00006 /*
    00007     This library...
    00008
    00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
    00010  */
    00011 //-----------------------------------------------------------------------------
    00012
    00013 #ifndef _MOEOEASYEA_H
    00014 #define _MOEOEASYEA_H
    00015
    00016 #include <apply.h>
    00017 #include <eoBreed.h>
    00018 #include <eoContinue.h>
    00019 #include <eoMergeReduce.h>
    00020 #include <eoPopEvalFunc.h>
    00021 #include <eoSelect.h>
    00022 #include <eoTransform.h>
    00023 #include <algo/moeoEA.h>
    00024 #include <diversity/moeoDiversityAssignment.h>
    00025 #include <diversity/moeoDummyDiversityAssignment.h>
    00026 #include <fitness/moeoFitnessAssignment.h>
    00027 #include <replacement/moeoReplacement.h>
    00028
    00032 template < class MOEOT >
    00033 class moeoEasyEA: public moeoEA < MOEOT >
    00034 {
    00035 public:
    00036
    00047     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
    00048                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
    00049             :
    00050             continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
    00051             fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
    00052     {}
    00053
    00054
    00065     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
    00066                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
    00067             :
    00068             continuator(_continuator), eval (dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
    00069             fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
    00070     {}
    00071
    00072
    00084     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce,
    00085                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
    00086             :
    00087             continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(_merge,_reduce), replace(mergeReduce),
    00088             fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
    00089     {}
    00090
    00091
    00103     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, moeoReplacement < MOEOT > & _replace,
    00104                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
    00105             :
    00106             continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
    00107             fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
    00108     {}
    00109
    00110
    00123     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce,
    00124                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
    00125             :
    00126             continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(_merge,_reduce), replace(mergeReduce),
    00127             fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
    00128     {}
    00129
    00130
    00135     virtual void operator()(eoPop < MOEOT > & _pop)
    00136     {
    00137         eoPop < MOEOT > offspring, empty_pop;
    00138         popEval(empty_pop, _pop); // A first eval of pop.
    00139         bool firstTime = true;
    00140         do
    00141         {
    00142             try
    00143             {
    00144                 unsigned int pSize = _pop.size();
    00145                 offspring.clear(); // new offspring
    00146                 // fitness and diversity assignment (if you want to or if it is the first generation)
    00147                 if (evalFitAndDivBeforeSelection || firstTime)
    00148                 {
    00149                     firstTime = false;
    00150                     fitnessEval(_pop);
    00151                     diversityEval(_pop);
    00152                 }
    00153                 breed(_pop, offspring);
    00154                 popEval(_pop, offspring); // eval of parents + offspring if necessary
    00155                 replace(_pop, offspring); // after replace, the new pop. is in _pop
    00156                 if (pSize > _pop.size())
    00157                 {
    00158                     throw std::runtime_error("Population shrinking!");
    00159                 }
    00160                 else if (pSize < _pop.size())
    00161                 {
    00162                     throw std::runtime_error("Population growing!");
    00163                 }
    00164             }
    00165             catch (std::exception& e)
    00166             {
    00167                 std::string s = e.what();
    00168                 s.append( " in moeoEasyEA");
    00169                 throw std::runtime_error( s );
    00170             }
    00171         } while (continuator(_pop));
    00172     }
    00173
    00174
    00175 protected:
    00176
    00178     eoContinue < MOEOT > & continuator;
    00180     eoEvalFunc < MOEOT > & eval;
    00182     eoPopLoopEval < MOEOT > loopEval;
    00184     eoPopEvalFunc < MOEOT > & popEval;
    00186     eoSelectTransform < MOEOT > selectTransform;
    00188     eoBreed < MOEOT > & breed;
    00190     eoMergeReduce < MOEOT > mergeReduce;
    00192     moeoReplacement < MOEOT > & replace;
    00194     moeoFitnessAssignment < MOEOT > & fitnessEval;
    00196     moeoDiversityAssignment < MOEOT > & diversityEval;
    00198     bool evalFitAndDivBeforeSelection;
    00200     class eoDummyEval : public eoEvalFunc < MOEOT >
    00201     { public:
    00202         void operator()(MOEOT &) {}} dummyEval;
    00204     class eoDummySelect : public eoSelect < MOEOT >
    00205     { public:
    00206         void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &) {} } dummySelect;
    00208     class eoDummyTransform : public eoTransform < MOEOT >
    00209     { public:
    00210         void operator()(eoPop < MOEOT > &) {} } dummyTransform;
    00212     eoNoElitism < MOEOT > dummyMerge;
    00214     eoTruncate < MOEOT > dummyReduce;
    00215
    00216 };
    00217
    00218 #endif /*MOEOEASYEA_H_*/