diff --git a/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h b/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h new file mode 100644 index 000000000..bd7b36975 --- /dev/null +++ b/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h @@ -0,0 +1,88 @@ +/* + +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 _moTimeContinuator_h +#define _moTimeContinuator_h + +#include + +/** + * Termination condition until a running time is reached. + */ +template < class Neighbor > +class moTimeContinuator: public moContinuator +{ +public: + + typedef typename Neighbor::EOT EOT; + + /** + * Ctor. + * @param _max maximum running time + */ + moTimeContinuator(time_t _max): max(_max){ + start = time(NULL); + } + + + /** + * Returns false when the running time is reached. + * @param _sol the current solution + */ + virtual bool operator() (EOT& _sol) + { + time_t elapsed = (time_t) difftime(time(NULL), start); + if (elapsed >= max) + { + std::cout << "STOP in moTimeContinuator: Reached maximum time [" << elapsed << "/" << max << "]" << std::endl; + return false; + } + return true; + } + + + /** + * Class name + */ + virtual std::string className(void) const + { + return "moTimeContinuator"; + } + + +private: + + /** maximum running time */ + time_t max; + /** starting time */ + time_t start; + +}; + +#endif diff --git a/trunk/paradiseo-mo/src/mo.h b/trunk/paradiseo-mo/src/mo.h index e9aa9fce4..6499891cb 100755 --- a/trunk/paradiseo-mo/src/mo.h +++ b/trunk/paradiseo-mo/src/mo.h @@ -69,6 +69,7 @@ #include #include #include +#include #include #include diff --git a/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp b/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp index 4d6f80bfe..c1aca862b 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp @@ -22,27 +22,48 @@ using namespace std; //----------------------------------------------------------------------------- -// fitness function -#include -#include +//Representation and initializer #include +#include +#include + +// fitness function +#include +#include +#include + +//Neighbors and Neighborhoods +#include +#include #include +//Algorithm and its components +#include +//#include + +//comparator +#include +#include + +//continuators +#include +#include +#include +#include +#include + +//mo eval +#include +#include + #include -#include -#include -#include -#include -#include -#include -#include - // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; -typedef moBitNeighbor Neighbor ; // incremental evaluation -typedef moOrderNeighborhood Neighborhood ; +typedef eoInt Queen; //Permutation (Queen's problem representation) + +typedef moShiftNeighbor shiftNeighbor; //shift Neighbor +typedef moOrderNeighborhood orderShiftNeighborhood; //rnd shift Neighborhood (Indexed) void main_function(int argc, char **argv) { @@ -100,7 +121,7 @@ void main_function(int argc, char **argv) * * ========================================================= */ - oneMaxEval fulleval; + queenEval fullEval; /* ========================================================= @@ -109,9 +130,7 @@ void main_function(int argc, char **argv) * * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + eoInitPermutation init(vecSize); /* ========================================================= @@ -120,30 +139,28 @@ void main_function(int argc, char **argv) * * ========================================================= */ - moFullEvalByModif eval(fulleval); + moFullEvalByCopy shiftEval(fullEval); //An eval by copy can be used instead of the eval by modif //moFullEvalByCopy fulleval(eval); - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ - - moNeighborComparator comparator; - moSolNeighborComparator solComparator; - - /* ========================================================= * * the neighborhood of a solution * * ========================================================= */ - Neighborhood neighborhood(vecSize); + orderShiftNeighborhood rndShiftNH(pow(vecSize-1, 2)); + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ + + moSolNeighborComparator solComparator; + moNeighborComparator comparator; /* ========================================================= * @@ -151,11 +168,11 @@ void main_function(int argc, char **argv) * * ========================================================= */ - moSolVectorTabuList tl(10,10); - moDummyIntensification inten; - moDummyDiversification div; - moBestImprAspiration asp; - moTSexplorer explorer(neighborhood, eval, comparator, solComparator, tl, inten, div, asp); + moNeighborVectorTabuList tl(10,10); + moDummyIntensification inten; + moDummyDiversification div; + moBestImprAspiration asp; + moTSexplorer explorer(rndShiftNH, shiftEval, comparator, solComparator, tl, inten, div, asp); /* ========================================================= @@ -164,9 +181,9 @@ void main_function(int argc, char **argv) * * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moLocalSearch localSearch(explorer, continuator, fulleval); + moLocalSearch localSearch(explorer, continuator, fullEval); /* ========================================================= * @@ -174,9 +191,9 @@ void main_function(int argc, char **argv) * * ========================================================= */ - Indi solution; + Queen solution; - random(solution); + init(solution); //Can be eval here, else it will be done at the beginning of the localSearch //eval(solution);