From 80439eac4e5fd9493d4067a37c174e6db8a6b646 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Mon, 3 May 2010 15:36:22 +0000 Subject: [PATCH] moTS + test added git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1772 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-mo/src/algo/moSA.h | 7 +- trunk/paradiseo-mo/src/algo/moTS.h | 133 ++++++++++++++++++ .../src/continuator/moTimeContinuator.h | 2 +- trunk/paradiseo-mo/src/mo.h | 1 + trunk/paradiseo-mo/test/CMakeLists.txt | 1 + trunk/paradiseo-mo/test/t-moTS.cpp | 72 ++++++++++ .../tutorial/Lesson4/testSimpleTS.cpp | 18 ++- 7 files changed, 227 insertions(+), 7 deletions(-) create mode 100644 trunk/paradiseo-mo/src/algo/moTS.h create mode 100644 trunk/paradiseo-mo/test/t-moTS.cpp diff --git a/trunk/paradiseo-mo/src/algo/moSA.h b/trunk/paradiseo-mo/src/algo/moSA.h index 1420744f8..f05232ed7 100644 --- a/trunk/paradiseo-mo/src/algo/moSA.h +++ b/trunk/paradiseo-mo/src/algo/moSA.h @@ -46,8 +46,9 @@ public: typedef typename Neighbor::EOT EOT; typedef moNeighborhood Neighborhood ; + /** - * Simple constructor for a simulated annealing + * Basic constructor for a simulated annealing * @param _neighborhood the neighborhood * @param _fullEval the full evaluation function * @param _eval neighbor's evaluation function @@ -76,7 +77,7 @@ public: {} /** - * Simple constructor for a simulated annealing + * General constructor for a simulated annealing * @param _neighborhood the neighborhood * @param _fullEval the full evaluation function * @param _eval neighbor's evaluation function @@ -90,6 +91,8 @@ public: explorer(_neighborhood, _eval, _comp, _cool) {} + + private: moTrueContinuator trueCont; moSimpleCoolingSchedule defaultCool; diff --git a/trunk/paradiseo-mo/src/algo/moTS.h b/trunk/paradiseo-mo/src/algo/moTS.h new file mode 100644 index 000000000..6d78dfe4d --- /dev/null +++ b/trunk/paradiseo-mo/src/algo/moTS.h @@ -0,0 +1,133 @@ +/* + +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 _moTS_h +#define _moTS_h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +class moTS: public moLocalSearch +{ +public: + + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Basic constructor for a tabu search + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _time the time limit for stopping criteria + * @param _tabuListSize the size of the tabu list + */ + moTS(Neighborhood& _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _time, + unsigned int _tabuListSize + ): + moLocalSearch(explorer, timeCont, _fullEval), + timeCont(_time), + tabuList(_tabuListSize,0), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, tabuList, dummyIntensification, dummyDiversification, defaultAspiration) + {} + + /** + * Simple constructor for a tabu search + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _time the time limit for stopping criteria + * @param _tabuList the tabu list + */ + moTS(Neighborhood& _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _time, + moTabuList& _tabuList): + moLocalSearch(explorer, timeCont, _fullEval), + timeCont(_time), + tabuList(0,0), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _tabuList, dummyIntensification, dummyDiversification, defaultAspiration) + {} + + /** + * General constructor for a tabu search + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _neighborComp a comparator between 2 neighbors + * @param _solNeighborComp a solution vs neighbor comparator + * @param _cont an external continuator + * @param _tabuList the tabu list + * @param _intensification the intensification strategy + * @param _diversification the diversification strategy + * @param _aspiration the aspiration Criteria + */ + moTS(Neighborhood& _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + moNeighborComparator& _neighborComp, + moSolNeighborComparator& _solNeighborComp, + moContinuator& _cont, + moTabuList& _tabuList, + moIntensification& _intensification, + moDiversification& _diversification, + moAspiration& _aspiration): + moLocalSearch(explorer, _cont, _fullEval), + timeCont(0), + tabuList(0,0), + explorer(_neighborhood, _eval, _neighborComp, _solNeighborComp, _tabuList, _intensification, _diversification, _aspiration) + {} + + +private: + moTimeContinuator timeCont; + moNeighborComparator defaultNeighborComp; + moSolNeighborComparator defaultSolNeighborComp; + moNeighborVectorTabuList tabuList; + moDummyIntensification dummyIntensification; + moDummyDiversification dummyDiversification; + moBestImprAspiration defaultAspiration; + moTSexplorer explorer; +}; +#endif diff --git a/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h b/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h index bd7b36975..563b786e7 100644 --- a/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h @@ -30,7 +30,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr #ifndef _moTimeContinuator_h #define _moTimeContinuator_h -#include +#include /** * Termination condition until a running time is reached. diff --git a/trunk/paradiseo-mo/src/mo.h b/trunk/paradiseo-mo/src/mo.h index 6499891cb..7cc8d429c 100755 --- a/trunk/paradiseo-mo/src/mo.h +++ b/trunk/paradiseo-mo/src/mo.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include diff --git a/trunk/paradiseo-mo/test/CMakeLists.txt b/trunk/paradiseo-mo/test/CMakeLists.txt index caae4978f..51a3904f9 100644 --- a/trunk/paradiseo-mo/test/CMakeLists.txt +++ b/trunk/paradiseo-mo/test/CMakeLists.txt @@ -80,6 +80,7 @@ SET (TEST_LIST t-moRandomBestHC t-moNeighborVectorTabuList t-moMonOpDiversification + t-moTS ) FOREACH (test ${TEST_LIST}) diff --git a/trunk/paradiseo-mo/test/t-moTS.cpp b/trunk/paradiseo-mo/test/t-moTS.cpp new file mode 100644 index 000000000..a91827942 --- /dev/null +++ b/trunk/paradiseo-mo/test/t-moTS.cpp @@ -0,0 +1,72 @@ +/* + +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 +*/ + +#include +#include +#include + +#include +#include "moTestClass.h" +#include +#include +#include +#include +#include + +int main(){ + + std::cout << "[t-moTS] => START" << std::endl; + + bitNeighborhood nh(4); + oneMaxEval fullEval; + evalOneMax eval(4); + + //test first constructor + moTS test1(nh, fullEval, eval, 1, 7); + + //test second constructor + moSolVectorTabuList tl(7,0); + moTS test2(nh, fullEval, eval, 1, tl); + + //test third constructor + moTrueContinuator cont; + moSolNeighborComparator sncomp; + moNeighborComparator ncomp; + moDummyIntensification intens; + moDummyDiversification div; + moBestImprAspiration aspir; + + moTS test3(nh, fullEval, eval, ncomp, sncomp, cont, tl, intens, div, aspir); + + + std::cout << "[t-moTS] => OK" << std::endl; + + return EXIT_SUCCESS; +} + diff --git a/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp b/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp index c1aca862b..f27235cbf 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp @@ -88,6 +88,16 @@ void main_function(int argc, char **argv) parser.processParam( vecSizeParam, "Representation" ); unsigned vecSize = vecSizeParam.value(); + // size tabu list + eoValueParam sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T'); + parser.processParam( sizeTabuListParam, "Search Parameters" ); + unsigned sizeTabuList = sizeTabuListParam.value(); + + // Time Limit + eoValueParam timeLimitParam(1, "timeLimit", "time limits", 'T'); + parser.processParam( timeLimitParam, "Search Parameters" ); + unsigned timeLimit = timeLimitParam.value(); + // the name of the "status" file where all actual parameter values will be saved string str_status = parser.ProgramName() + ".status"; // default value eoValueParam statusParam(str_status.c_str(), "status", "Status file"); @@ -168,11 +178,11 @@ void main_function(int argc, char **argv) * * ========================================================= */ - moNeighborVectorTabuList tl(10,10); + moNeighborVectorTabuList tl(sizeTabuList,0); moDummyIntensification inten; moDummyDiversification div; moBestImprAspiration asp; - moTSexplorer explorer(rndShiftNH, shiftEval, comparator, solComparator, tl, inten, div, asp); + //moTSexplorer explorer(rndShiftNH, shiftEval, comparator, solComparator, tl, inten, div, asp); /* ========================================================= @@ -181,9 +191,9 @@ void main_function(int argc, char **argv) * * ========================================================= */ - moTrueContinuator continuator;//always continue + moTimeContinuator continuator(timeLimit); - moLocalSearch localSearch(explorer, continuator, fullEval); + moTS localSearch(rndShiftNH, fullEval, shiftEval, comparator, solComparator, continuator, tl, inten, div, asp); /* ========================================================= *