- 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 <eoPopEvalFunc.h>
    00018 #include <eoContinue.h>
    00019 #include <eoTransform.h>
    00020 #include <eoBreed.h>
    00021 #include <eoMergeReduce.h>
    00022 #include <moeoEA.h>
    00023 #include <eoReplacement.h>
    00024 #include <moeoFitnessAssignment.h>
    00025 #include <moeoDiversityAssignment.h>
    00026
    00030 template < class MOEOT >
    00031 class moeoEasyEA: public moeoEA < MOEOT >
    00032 {
    00033 public:
    00034
    00045     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoReplacement < MOEOT > & _replace,
    00046                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
    00047             :
    00048             continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), breed(_breed), replace(_replace), fitnessEval(_fitnessEval),
    00049             diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
    00050     {}
    00051
    00052
    00057     virtual void operator()(eoPop < MOEOT > & _pop)
    00058     {
    00059         eoPop < MOEOT > offspring, empty_pop;
    00060         popEval(empty_pop, _pop); // A first eval of pop.
    00061         bool firstTime = true;
    00062         do
    00063         {
    00064             try
    00065             {
    00066                 unsigned pSize = _pop.size();
    00067                 offspring.clear(); // new offspring
    00068                 // fitness and diversity assignment (if you want to or if it is the first generation)
    00069                 if (evalFitAndDivBeforeSelection || firstTime)
    00070                 {
    00071                     firstTime = false;
    00072                     fitnessEval(_pop);
    00073                     diversityEval(_pop);
    00074                 }
    00075                 breed(_pop, offspring);
    00076                 popEval(_pop, offspring); // eval of parents + offspring if necessary
    00077                 replace(_pop, offspring); // after replace, the new pop. is in _pop
    00078                 if (pSize > _pop.size())
    00079                 {
    00080                     throw std::runtime_error("Population shrinking!");
    00081                 }
    00082                 else if (pSize < _pop.size())
    00083                 {
    00084                     throw std::runtime_error("Population growing!");
    00085                 }
    00086             }
    00087             catch (std::exception& e)
    00088             {
    00089                 std::string s = e.what();
    00090                 s.append( " in moeoEasyEA");
    00091                 throw std::runtime_error( s );
    00092             }
    00093         } while (continuator(_pop));
    00094     }
    00095
    00096
    00097 protected:
    00098
    00100     eoContinue < MOEOT > & continuator;
    00102     eoEvalFunc < MOEOT > & eval;
    00104     eoPopLoopEval < MOEOT > loopEval;
    00106     eoPopEvalFunc < MOEOT > & popEval;
    00108     eoBreed < MOEOT > & breed;
    00110     eoReplacement < MOEOT > & replace;
    00112     moeoFitnessAssignment < MOEOT > & fitnessEval;
    00114     moeoDiversityAssignment < MOEOT > & diversityEval;
    00116     bool evalFitAndDivBeforeSelection;
    00117
    00118 };
    00119
    00120 #endif /*MOEOEASYEA_H_*/