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         } while (continuator(_pop));
00197     }
00198 
00199 
00200 protected:
00201 
00203     eoContinue < MOEOT > & continuator;
00205     eoEvalFunc < MOEOT > & eval;
00207     eoPopLoopEval < MOEOT > loopEval;
00209     eoPopEvalFunc < MOEOT > & popEval;
00211     eoSelectTransform < MOEOT > selectTransform;
00213     eoBreed < MOEOT > & breed;
00215     eoMergeReduce < MOEOT > mergeReduce;
00217     moeoReplacement < MOEOT > & replace;
00219     moeoFitnessAssignment < MOEOT > & fitnessEval;
00221     moeoDiversityAssignment < MOEOT > & diversityEval;
00223     bool evalFitAndDivBeforeSelection;
00225     class eoDummyEval : public eoEvalFunc < MOEOT >
00226     { public: 
00227         void operator()(MOEOT &) {}} dummyEval;
00229     class eoDummySelect : public eoSelect < MOEOT >
00230     { public: 
00231         void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &) {} } dummySelect;
00233     class eoDummyTransform : public eoTransform < MOEOT >
00234     { public: 
00235         void operator()(eoPop < MOEOT > &) {} } dummyTransform;
00237     eoNoElitism < MOEOT > dummyMerge;
00239     eoTruncate < MOEOT > dummyReduce;
00240 
00241 };
00242 
00243 #endif /*MOEOEASYEA_H_*/

Generated on Fri Oct 12 15:16:04 2007 for ParadisEO-MOEO:MultiObjectiveEvolvingObjects by  doxygen 1.4.7