From 585d90b082a316ecaaaf1e894ba98ce7122234b3 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Fri, 4 Jun 2010 13:06:35 +0000 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20des=20travaux=20sur=20les=20popula?= =?UTF-8?q?tions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1837 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-mo/doc/index.h | 44 +++++++++ .../paradiseo-mo/src/eval/moFullEvalByCopy.h | 2 +- .../paradiseo-mo/src/eval/moFullEvalByModif.h | 3 +- .../src/problems/bitString/moPopBitNeighbor.h | 28 +++--- .../src/problems/eval/moPopBitEval.h | 85 +++++++++++++++++ .../tutorial/Lesson8/moPopFitContinuator.h | 95 +++++++++++++++++++ .../tutorial/Lesson8/testPopLS.cpp | 11 ++- 7 files changed, 246 insertions(+), 22 deletions(-) create mode 100644 trunk/paradiseo-mo/doc/index.h create mode 100644 trunk/paradiseo-mo/src/problems/eval/moPopBitEval.h create mode 100644 trunk/paradiseo-mo/tutorial/Lesson8/moPopFitContinuator.h diff --git a/trunk/paradiseo-mo/doc/index.h b/trunk/paradiseo-mo/doc/index.h new file mode 100644 index 000000000..b59421284 --- /dev/null +++ b/trunk/paradiseo-mo/doc/index.h @@ -0,0 +1,44 @@ +/** @mainpage Welcome to ParadisEO-MO + +@section Introduction + +ParadisEO-MO is a white-box object-oriented generic framework dedicated to the flexible design of local search algorithms. + + +@section LICENSE + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + ParadisEO WebSite : http://paradiseo.gforge.inria.fr + Contact: paradiseo-help@lists.gforge.inria.fr + +*/ + +/** @page webpages Related webpages + +- ParadisEO homepage +- INRIA GForge project page +- README +*/ diff --git a/trunk/paradiseo-mo/src/eval/moFullEvalByCopy.h b/trunk/paradiseo-mo/src/eval/moFullEvalByCopy.h index 4c5fe2ae2..701a7b951 100644 --- a/trunk/paradiseo-mo/src/eval/moFullEvalByCopy.h +++ b/trunk/paradiseo-mo/src/eval/moFullEvalByCopy.h @@ -1,4 +1,4 @@ -/* + /* Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 diff --git a/trunk/paradiseo-mo/src/eval/moFullEvalByModif.h b/trunk/paradiseo-mo/src/eval/moFullEvalByModif.h index 8386cd494..80ee94d1c 100644 --- a/trunk/paradiseo-mo/src/eval/moFullEvalByModif.h +++ b/trunk/paradiseo-mo/src/eval/moFullEvalByModif.h @@ -40,6 +40,8 @@ /** * Full evaluation to use with a moBackableNeighbor + * !!!WARNING!!! Use only when your solution is composed by a fitness Value and a "genotype" + * */ template class moFullEvalByModif : public moEval @@ -64,7 +66,6 @@ public: // tmp fitness value of the current solution Fitness tmpFit; - // save current fitness value tmpFit = _sol.fitness(); diff --git a/trunk/paradiseo-mo/src/problems/bitString/moPopBitNeighbor.h b/trunk/paradiseo-mo/src/problems/bitString/moPopBitNeighbor.h index 883ffa921..028aedd25 100644 --- a/trunk/paradiseo-mo/src/problems/bitString/moPopBitNeighbor.h +++ b/trunk/paradiseo-mo/src/problems/bitString/moPopBitNeighbor.h @@ -40,12 +40,13 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Neighbor related to a vector of Bit */ template< class Fitness > -class moPopBitNeighbor : public moBackableNeighbor< moPopSol > >, public moIndexNeighbor< moPopSol > > +class moPopBitNeighbor : public moIndexNeighbor< moPopSol > > { public: typedef moPopSol > EOT ; + typedef eoBit SUBEOT; - using moBackableNeighbor::fitness; + using moIndexNeighbor::fitness; using moIndexNeighbor::key; /** @@ -53,23 +54,18 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - if(_solution.size()>0){ - size=_solution[0].size(); - _solution[key/size][key%size] = !_solution[key/size][key%size]; -// fit=_solution[key/size].fitness(); - _solution[key/size].invalidate(); -// fitSol=_solution.fitness(); + if(_solution[0].size()>0){ + unsigned size=_solution[0].size(); + unsigned s = key/size; + unsigned b = key%size; + _solution[s][b] = !_solution[s][b]; + _solution[s].fitness(subfit); _solution.invalidate(); } } - /** - * move back the solution (useful for the evaluation by modif) - * @param _solution the solution to move back - */ - virtual void moveBack(EOT & _solution) { - _solution[key/size][key%size] = !_solution[key/size][key%size]; -// _solution[key/size].fitness(fit); + void setSubFit(Fitness _subfit){ + subfit=_subfit; } /** @@ -113,7 +109,7 @@ public: } private: - unsigned int size; + Fitness subfit; }; #endif diff --git a/trunk/paradiseo-mo/src/problems/eval/moPopBitEval.h b/trunk/paradiseo-mo/src/problems/eval/moPopBitEval.h new file mode 100644 index 000000000..4780a7f6c --- /dev/null +++ b/trunk/paradiseo-mo/src/problems/eval/moPopBitEval.h @@ -0,0 +1,85 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + ParadisEO WebSite : http://paradiseo.gforge.inria.fr + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef moPopBitEval_H +#define moPopBitEval_H + +#include +#include + +/** + * Abstract class for the evaluation + */ +template +class moPopBitEval : public moEval +{ +public: + typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::SUBEOT SUBEOT; + + typedef typename EOT::Fitness Fitness; + + moPopBitEval(eoEvalFunc& _eval, unsigned int _p):eval(_eval), p(_p){ + + } + + void operator()(EOT& _sol, Neighbor& _n){ + if(_sol[0].size()>0){ + unsigned int size=_sol[0].size(); + unsigned int s=_n.index()/size; + unsigned int b=_n.index()%size; + subfit=_sol[s].fitness(); + _sol[s][b]=!_sol[s][b]; + _sol[s].invalidate(); + eval(_sol[s]); + double fit=0; + for (unsigned int i = 0; i < _sol.size(); i++){ + fit+=pow(_sol[i].fitness(), p); + } + fit=pow(fit, (double)1/p); + _n.setSubFit(_sol[s].fitness()); + _n.fitness(fit); + _sol[s][b]=!_sol[s][b]; + _sol[s].fitness(subfit); + } + } + +private: + eoEvalFunc & eval; + unsigned int p; + Fitness subfit; + +}; + +#endif diff --git a/trunk/paradiseo-mo/tutorial/Lesson8/moPopFitContinuator.h b/trunk/paradiseo-mo/tutorial/Lesson8/moPopFitContinuator.h new file mode 100644 index 000000000..0e1874d7b --- /dev/null +++ b/trunk/paradiseo-mo/tutorial/Lesson8/moPopFitContinuator.h @@ -0,0 +1,95 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef _moPopFitContinuator_h +#define _moPopFitContinuator_h + +#include + +/** + * Termination condition until a running time is reached. + */ +template < class Neighbor > +class moPopFitContinuator: public moContinuator +{ +public: + + typedef typename Neighbor::EOT EOT; + typedef typename EOT::Fitness Fitness; + + /** + * Constructor + * @param _fit fitness to reach + * @param _verbose verbose mode true/false -> on/off + */ + moPopFitContinuator(Fitness _fit, bool _verbose=true): fit(_fit), verbose(_verbose) {} + + + /** + * Returns false when the running time is reached. + * @param _sol the current solution + */ + virtual bool operator() (EOT& _sol) + { + unsigned int i=0; + bool res=true; + while (res && i<_sol.size()){ + res= (_sol[i].fitness() < fit); + i++; + } + if (!res && verbose) + std::cout << "STOP in moPopFitContinuator: Reached maximum fitness [" << fit << "]" << std::endl; + return res; + } + + /** + * reset the start time + * @param _solution a solution + */ + virtual void init(EOT & _solution) {} + + + /** + * Class name + */ + virtual std::string className(void) const + { + return "moPopFitContinuator"; + } + + +private: + + Fitness fit; + /** verbose mode */ + bool verbose; + +}; + +#endif diff --git a/trunk/paradiseo-mo/tutorial/Lesson8/testPopLS.cpp b/trunk/paradiseo-mo/tutorial/Lesson8/testPopLS.cpp index 5afb4e7d1..979bf73e5 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson8/testPopLS.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson8/testPopLS.cpp @@ -52,7 +52,7 @@ using namespace std; // fitness function #include -#include +#include //Neighbors and Neighborhoods #include @@ -72,6 +72,8 @@ using namespace std; #include #include +#include "moPopFitContinuator.h" + //----------------------------------------------------------------------------- // Define types of the representation solution, different neighbors and neighborhoods @@ -100,7 +102,7 @@ void main_function(int argc, char **argv) unsigned seed = seedParam.value(); // description of genotype - eoValueParam vecSizeParam(4, "vecSize", "Genotype size", 'V'); + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); parser.processParam( vecSizeParam, "Representation" ); unsigned vecSize = vecSizeParam.value(); @@ -174,7 +176,7 @@ void main_function(int argc, char **argv) * * ========================================================= */ - moFullEvalByModif moEval(popEval); + moPopBitEval evalNeighbor(eval,2); // Neighbor n; // @@ -196,6 +198,7 @@ void main_function(int argc, char **argv) Neighborhood neighborhood(vecSize*popSize); + moPopFitContinuator cont(vecSize); /* ========================================================= * @@ -203,7 +206,7 @@ void main_function(int argc, char **argv) * * ========================================================= */ - moSimpleHC ls(neighborhood, popEval, moEval); + moSimpleHC ls(neighborhood, popEval, evalNeighbor, cont); /* ========================================================= *