From 7631f6e04054485bd1e1178d95e0c38ab27864e7 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Fri, 27 Aug 2010 15:59:23 +0000 Subject: [PATCH] mon dernier commit :) On en a chier encore jusqu'au bout !!! git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1926 331e1502-861f-0410-8da2-ba01fb791d7f --- .../paradiseo-mo/src/explorer/moVNSexplorer.h | 27 ++++--- .../neighborhood/moForwardVectorVNSelection.h | 18 +++-- .../moVariableNeighborhoodSelection.h | 6 +- .../src/neighborhood/moVectorVNSelection.h | 8 +- trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp | 81 ++++++++++++------- 5 files changed, 88 insertions(+), 52 deletions(-) diff --git a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h index 5049d9173..58c4b5a26 100644 --- a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h @@ -34,6 +34,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include #include +#include /** * Explorer for Variiable Neighborhood Search @@ -55,7 +56,7 @@ public: moVNSexplorer( moVariableNeighborhoodSelection & _selection, moAcceptanceCriterion& _acceptCrit): - moNeighborhoodExplorer(), selection(_selection), shake(NULL), ls(NULL), acceptCrit(_acceptCrit), stop(false) + moNeighborhoodExplorer(),dummyLS(dummyEval), selection(_selection), acceptCrit(_acceptCrit), ls(&dummyLS), shake(dummyLS), stop(false) {} /** @@ -68,7 +69,7 @@ public: * initParam: NOTHING TO DO */ virtual void initParam(EOT& _solution) { - selection.init(_solution, *shake, *ls); + selection.init(current, shake, ls); }; /** @@ -76,10 +77,10 @@ public: */ virtual void updateParam(EOT & _solution) { if ((*this).moveApplied()) { - selection.init(_solution, *shake, *ls); + selection.init(current, shake, ls); } - else if (selection.cont(_solution, *shake, *ls)){ - selection.next(_solution, *shake, *ls); + else if (selection.cont(current, shake, ls)){ + selection.next(current, shake, ls); } else stop=true; @@ -96,8 +97,11 @@ public: */ virtual void operator()(EOT & _solution) { current=_solution; - (*shake)(current); + std::cout << "current avec shake: "<< current << std::endl; + shake(current); + std::cout << "current apres shake: "<< current << std::endl; (*ls)(current); + std::cout << "current apres ls: "<< ls->className() << " " << current << std::endl; }; /** @@ -135,14 +139,19 @@ public: } private: + moDummyLS dummyLS; moVariableNeighborhoodSelection& selection; - eoMonOp* ls; - eoMonOp* shake; moAcceptanceCriterion& acceptCrit; - + eoMonOp* ls; + eoMonOp& shake; bool stop; EOT current; + class moDummyEval: public eoEvalFunc{ + public: + void operator()(EOT& hop){} + }dummyEval; + }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h index ea897240f..b8d2fbb61 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h +++ b/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h @@ -55,26 +55,34 @@ public: * test if there is still some neighborhood to explore * @return true if there is some neighborhood to explore */ - virtual bool cont(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + virtual bool cont(EOT& _solution, eoMonOp& _shake, eoMonOp*& _ls){ return (cycle || (current <= (LSvector.size()-2))); + std::cout << "current LS: " << current << std::endl; + std::cout << _solution << std::endl; + } /** * put the current neighborhood on the first one */ - virtual void init(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + virtual void init(EOT& _solution, eoMonOp& _shake, eoMonOp*& _ls){ current=0; - _ls = *(LSvector[current]); + _ls = LSvector[current]; _shake = *(shakeVector[current]); + std::cout << "current LS: " << _ls->className() << " " << current << std::endl; + std::cout << _solution << std::endl; + } /** * put the current neighborhood on the next one */ - virtual void next(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + virtual void next(EOT& _solution, eoMonOp& _shake, eoMonOp*& _ls){ current = (current+1) % LSvector.size(); - _ls = *(LSvector[current]); + _ls = LSvector[current]; _shake = *(shakeVector[current]); + std::cout << "current LS: " << current << std::endl; + std::cout << _solution << std::endl; } private: diff --git a/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhoodSelection.h b/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhoodSelection.h index ec2954e21..a3694c519 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhoodSelection.h +++ b/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhoodSelection.h @@ -50,17 +50,17 @@ public: * test if there is still some neighborhood to explore * @return true if there is some neighborhood to explore */ - virtual bool cont(EOT& _solution, eoMonOp& _skake, eoMonOp& _ls) = 0; + virtual bool cont(EOT& _solution, eoMonOp& _skake, eoMonOp*& _ls) = 0; /** * put the current neighborhood on the first one */ - virtual void init(EOT& _solution, eoMonOp& _skake, eoMonOp& _ls) = 0; + virtual void init(EOT& _solution, eoMonOp& _skake, eoMonOp*& _ls) = 0; /** * put the current neighborhood on the next one */ - virtual void next(EOT& _solution, eoMonOp& _skake, eoMonOp& _ls) = 0; + virtual void next(EOT& _solution, eoMonOp& _skake, eoMonOp*& _ls) = 0; }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h index 1fe14590d..0823662f5 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h +++ b/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h @@ -44,7 +44,7 @@ public: current=0; } - void addLS(eoMonOp& _otherLS, eoMonOp& _otherShake){ + void add(eoMonOp& _otherLS, eoMonOp& _otherShake){ LSvector.push_back(&_otherLS); shakeVector.push_back(&_otherShake); } @@ -61,17 +61,17 @@ public: * test if there is still some neighborhood to explore * @return true if there is some neighborhood to explore */ - virtual bool cont(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls) = 0; + virtual bool cont(EOT& _solution, eoMonOp& _shake, eoMonOp*& _ls) = 0; /** * put the current neighborhood on the first one */ - virtual void init(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls) = 0; + virtual void init(EOT& _solution, eoMonOp& _shake, eoMonOp*& _ls) = 0; /** * put the current neighborhood on the next one */ - virtual void next(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls) = 0; + virtual void next(EOT& _solution, eoMonOp& _shake, eoMonOp*& _ls) = 0; protected: std::vector* > LSvector; diff --git a/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp b/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp index 964333e40..d0c0107df 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp @@ -39,13 +39,16 @@ using namespace std; #include #include #include -#include +//#include #include -#include +//#include //Algorithm and its components #include -#include +#include +#include + +#include //comparator #include @@ -57,6 +60,11 @@ using namespace std; #include #include +#include +#include + +#include +#include //----------------------------------------------------------------------------- // Define types of the representation solution, different neighbors and neighborhoods @@ -143,6 +151,7 @@ void main_function(int argc, char **argv) * ========================================================= */ moFullEvalByCopy shiftEval(fullEval); + moFullEvalByCopy swapEval(fullEval); /* ========================================================= * @@ -153,40 +162,50 @@ void main_function(int argc, char **argv) shiftNeighborhood shiftNH((vecSize-1) * (vecSize-1)); swapNeighborhood swapNH(100); - - Queen sol; - - init(sol); - shiftNeighbor n; - - /* ========================================================= * * the local search algorithm * * ========================================================= */ -// moSA localSearch1(shiftNH, fullEval, shiftEval); -// -// /* ========================================================= -// * -// * execute the local search from random solution -// * -// * ========================================================= */ -// -// Queen solution1, solution2; -// -// init(solution1); -// -// fullEval(solution1); -// -// std::cout << "#########################################" << std::endl; -// std::cout << "initial solution1: " << solution1 << std::endl ; -// -// localSearch1(solution1); -// -// std::cout << "final solution1: " << solution1 << std::endl ; -// std::cout << "#########################################" << std::endl; + moSimpleHC ls1(shiftNH, fullEval, shiftEval); + moSimpleHC ls2(swapNH, fullEval, swapEval); + + eoSwapMutation swapMut; + eoShiftMutation shiftMut; + + moForwardVectorVNSelection selectNH(ls1, shiftMut, true); + + selectNH.add(ls2, swapMut); + + moAlwaysAcceptCrit acceptCrit; + + moVNSexplorer explorer(selectNH, acceptCrit); + + moTimeContinuator cont(5); + + moLocalSearch vns(explorer, cont, fullEval); + + + /* ========================================================= + * + * execute the local search from random solution + * + * ========================================================= */ + + Queen sol; + + init(sol); + + fullEval(sol); + + std::cout << "#########################################" << std::endl; + std::cout << "initial sol: " << sol << std::endl ; + + vns(sol); + + std::cout << "final sol: " << sol << std::endl ; + std::cout << "#########################################" << std::endl; // // // /* =========================================================