From a127bf39f2c4d13ffd72347b0e4c68900b76c678 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Tue, 4 May 2010 13:27:40 +0000 Subject: [PATCH] Lesson 4 modified git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1773 331e1502-861f-0410-8da2-ba01fb791d7f --- .../tutorial/Lesson4/testSimpleTS.cpp | 117 ++++++++++++------ 1 file changed, 77 insertions(+), 40 deletions(-) diff --git a/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp b/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp index f27235cbf..6a39018dd 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson4/testSimpleTS.cpp @@ -2,7 +2,7 @@ /** testSimpleHC.cpp * * SV - 12/01/10 - * + * JH - 03/05/10 */ //----------------------------------------------------------------------------- @@ -38,32 +38,19 @@ using namespace std; #include //Algorithm and its components -#include -//#include - -//comparator -#include -#include - -//continuators -#include -#include -#include -#include -#include +#include //mo eval #include #include -#include // REPRESENTATION //----------------------------------------------------------------------------- typedef eoInt Queen; //Permutation (Queen's problem representation) typedef moShiftNeighbor shiftNeighbor; //shift Neighbor -typedef moOrderNeighborhood orderShiftNeighborhood; //rnd shift Neighborhood (Indexed) +typedef moOrderNeighborhood orderShiftNeighborhood; //order shift Neighborhood (Indexed) void main_function(int argc, char **argv) { @@ -79,6 +66,7 @@ void main_function(int argc, char **argv) // For each parameter, define Parameter, read it through the parser, // and assign the value to the variable + // seed eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); parser.processParam( seedParam ); unsigned seed = seedParam.value(); @@ -93,7 +81,7 @@ void main_function(int argc, char **argv) parser.processParam( sizeTabuListParam, "Search Parameters" ); unsigned sizeTabuList = sizeTabuListParam.value(); - // Time Limit + // time Limit eoValueParam timeLimitParam(1, "timeLimit", "time limits", 'T'); parser.processParam( timeLimitParam, "Search Parameters" ); unsigned timeLimit = timeLimitParam.value(); @@ -127,7 +115,7 @@ void main_function(int argc, char **argv) /* ========================================================= * - * Eval fitness function + * Full evaluation fitness function * * ========================================================= */ @@ -136,13 +124,33 @@ void main_function(int argc, char **argv) /* ========================================================= * - * Initilisation of the solution + * Initializer of a solution * * ========================================================= */ eoInitPermutation init(vecSize); + /* ========================================================= + * + * Declare and init solutions + * + * ========================================================= */ + + Queen sol1; + Queen sol2; + Queen sol3; + + //random initialization + init(sol1); + init(sol2); + init(sol3); + + //evaluation + fullEval(sol1); + fullEval(sol2); + fullEval(sol3); + /* ========================================================= * * evaluation of a neighbor solution @@ -151,21 +159,17 @@ void main_function(int argc, char **argv) moFullEvalByCopy shiftEval(fullEval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); - - /* ========================================================= * * the neighborhood of a solution * * ========================================================= */ - orderShiftNeighborhood rndShiftNH(pow(vecSize-1, 2)); + orderShiftNeighborhood orderShiftNH(pow(vecSize-1, 2)); /* ========================================================= * - * Comparator of neighbors + * Comparator of neighbors and solutions * * ========================================================= */ @@ -174,45 +178,78 @@ void main_function(int argc, char **argv) /* ========================================================= * - * a neighborhood explorer solution + * tabu list * * ========================================================= */ moNeighborVectorTabuList tl(sizeTabuList,0); - moDummyIntensification inten; - moDummyDiversification div; - moBestImprAspiration asp; - //moTSexplorer explorer(rndShiftNH, shiftEval, comparator, solComparator, tl, inten, div, asp); - /* ========================================================= * - * the local search algorithm + * Memories + * + * ========================================================= */ + + moDummyIntensification inten; + moDummyDiversification div; + moBestImprAspiration asp; + + /* ========================================================= + * + * continuator * * ========================================================= */ moTimeContinuator continuator(timeLimit); - moTS localSearch(rndShiftNH, fullEval, shiftEval, comparator, solComparator, continuator, tl, inten, div, asp); /* ========================================================= * - * execute the local search from random sollution + * the local search algorithms * * ========================================================= */ - Queen solution; + //Basic Constructor + moTS localSearch1(orderShiftNH, fullEval, shiftEval, 2, 7); + + //Simple Constructor + moTS localSearch2(orderShiftNH, fullEval, shiftEval, 3, tl); + + //General Constructor + moTS localSearch3(orderShiftNH, fullEval, shiftEval, comparator, solComparator, continuator, tl, inten, div, asp); + + /* ========================================================= + * + * execute the local search from random solution + * + * ========================================================= */ + + + - init(solution); //Can be eval here, else it will be done at the beginning of the localSearch - //eval(solution); + //fullEval(solution); - std::cout << "initial: " << solution << std::endl ; - localSearch(solution); + //Run the three Tabu Search and print initial and final solutions + std::cout << "Tabu Search 1:" << std::endl; + std::cout << "--------------" << std::endl; + std::cout << "initial: " << sol1 << std::endl ; + localSearch1(sol1); + std::cout << "final: " << sol1 << std::endl << std::endl; - std::cout << "final: " << solution << std::endl ; + std::cout << "Tabu Search 2:" << std::endl; + std::cout << "--------------" << std::endl; + std::cout << "initial: " << sol2 << std::endl ; + localSearch2(sol2); + std::cout << "final: " << sol2 << std::endl << std::endl; + + std::cout << "Tabu Search 3:" << std::endl; + std::cout << "--------------" << std::endl; + std::cout << "initial: " << sol3 << std::endl ; + localSearch3(sol3); + std::cout << "final: " << sol3 << std::endl ; }