moeoEasyEA.h

00001 /*
00002 * <moeoEasyEA.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 //-----------------------------------------------------------------------------
00037 
00038 #ifndef _MOEOEASYEA_H
00039 #define _MOEOEASYEA_H
00040 
00041 #include <apply.h>
00042 #include <eoBreed.h>
00043 #include <eoContinue.h>
00044 #include <eoMergeReduce.h>
00045 #include <eoPopEvalFunc.h>
00046 #include <eoSelect.h>
00047 #include <eoTransform.h>
00048 #include <algo/moeoEA.h>
00049 #include <diversity/moeoDiversityAssignment.h>
00050 #include <diversity/moeoDummyDiversityAssignment.h>
00051 #include <fitness/moeoFitnessAssignment.h>
00052 #include <replacement/moeoReplacement.h>
00053 
00057 template < class MOEOT >
00058 class moeoEasyEA: public moeoEA < MOEOT >
00059   {
00060   public:
00061 
00072     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
00073                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
00074         :
00075         continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
00076         fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
00077     {}
00078 
00079 
00090     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
00091                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
00092         :
00093         continuator(_continuator), eval (dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
00094         fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
00095     {}
00096 
00097 
00109     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce,
00110                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
00111         :
00112         continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(_merge,_reduce), replace(mergeReduce),
00113         fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
00114     {}
00115 
00116 
00128     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, moeoReplacement < MOEOT > & _replace,
00129                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
00130         :
00131         continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
00132         fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
00133     {}
00134 
00135 
00148     moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce,
00149                moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
00150         :
00151         continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(_merge,_reduce), replace(mergeReduce),
00152         fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
00153     {}
00154 
00155 
00160     virtual void operator()(eoPop < MOEOT > & _pop)
00161     {
00162       eoPop < MOEOT > offspring, empty_pop;
00163       popEval(empty_pop, _pop); // A first eval of pop.
00164       bool firstTime = true;
00165       do
00166         {
00167           try
00168             {
00169               unsigned int pSize = _pop.size();
00170               offspring.clear(); // new offspring
00171               // fitness and diversity assignment (if you want to or if it is the first generation)
00172               if (evalFitAndDivBeforeSelection || firstTime)
00173                 {
00174                   firstTime = false;
00175                   fitnessEval(_pop);
00176                   diversityEval(_pop);
00177                 }
00178               breed(_pop, offspring);
00179               popEval(_pop, offspring); // eval of parents + offspring if necessary
00180               replace(_pop, offspring); // after replace, the new pop. is in _pop
00181               if (pSize > _pop.size())
00182                 {
00183                   throw std::runtime_error("Population shrinking!");
00184                 }
00185               else if (pSize < _pop.size())
00186                 {
00187                   throw std::runtime_error("Population growing!");
00188                 }
00189             }
00190           catch (std::exception& e)
00191             {
00192               std::string s = e.what();
00193               s.append( " in moeoEasyEA");
00194               throw std::runtime_error( s );
00195             }
00196         }
00197       while (continuator(_pop));
00198     }
00199 
00200 
00201   protected:
00202 
00204     eoContinue < MOEOT > & continuator;
00206     eoEvalFunc < MOEOT > & eval;
00208     eoPopLoopEval < MOEOT > loopEval;
00210     eoPopEvalFunc < MOEOT > & popEval;
00212     eoSelectTransform < MOEOT > selectTransform;
00214     eoBreed < MOEOT > & breed;
00216     eoMergeReduce < MOEOT > mergeReduce;
00218     moeoReplacement < MOEOT > & replace;
00220     moeoFitnessAssignment < MOEOT > & fitnessEval;
00222     moeoDiversityAssignment < MOEOT > & diversityEval;
00224     bool evalFitAndDivBeforeSelection;
00226   class eoDummyEval : public eoEvalFunc < MOEOT >
00227       {
00228       public: 
00229         void operator()(MOEOT &)
00230         {}
00231       }
00232     dummyEval;
00234   class eoDummySelect : public eoSelect < MOEOT >
00235       {
00236       public: 
00237         void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &)
00238         {}
00239       }
00240     dummySelect;
00242   class eoDummyTransform : public eoTransform < MOEOT >
00243       {
00244       public: 
00245         void operator()(eoPop < MOEOT > &)
00246         {}
00247       }
00248     dummyTransform;
00250     eoNoElitism < MOEOT > dummyMerge;
00252     eoTruncate < MOEOT > dummyReduce;
00253 
00254   };
00255 
00256 #endif /*MOEOEASYEA_H_*/

Generated on Thu Mar 13 15:54:07 2008 for ParadisEO-MOEO-MultiObjectiveEvolvingObjects by  doxygen 1.4.7