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
This commit is contained in:
jhumeau 2010-08-27 15:59:23 +00:00
commit 7631f6e040
5 changed files with 85 additions and 49 deletions

View file

@ -34,6 +34,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <neighborhood/moVariableNeighborhoodSelection.h> #include <neighborhood/moVariableNeighborhoodSelection.h>
#include <eoOp.h> #include <eoOp.h>
#include <acceptCrit/moAcceptanceCriterion.h> #include <acceptCrit/moAcceptanceCriterion.h>
#include <algo/moDummyLS.h>
/** /**
* Explorer for Variiable Neighborhood Search * Explorer for Variiable Neighborhood Search
@ -55,7 +56,7 @@ public:
moVNSexplorer( moVNSexplorer(
moVariableNeighborhoodSelection<EOT> & _selection, moVariableNeighborhoodSelection<EOT> & _selection,
moAcceptanceCriterion<Neighbor>& _acceptCrit): moAcceptanceCriterion<Neighbor>& _acceptCrit):
moNeighborhoodExplorer<Neighbor>(), selection(_selection), shake(NULL), ls(NULL), acceptCrit(_acceptCrit), stop(false) moNeighborhoodExplorer<Neighbor>(),dummyLS(dummyEval), selection(_selection), acceptCrit(_acceptCrit), ls(&dummyLS), shake(dummyLS), stop(false)
{} {}
/** /**
@ -68,7 +69,7 @@ public:
* initParam: NOTHING TO DO * initParam: NOTHING TO DO
*/ */
virtual void initParam(EOT& _solution) { 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) { virtual void updateParam(EOT & _solution) {
if ((*this).moveApplied()) { if ((*this).moveApplied()) {
selection.init(_solution, *shake, *ls); selection.init(current, shake, ls);
} }
else if (selection.cont(_solution, *shake, *ls)){ else if (selection.cont(current, shake, ls)){
selection.next(_solution, *shake, *ls); selection.next(current, shake, ls);
} }
else else
stop=true; stop=true;
@ -96,8 +97,11 @@ public:
*/ */
virtual void operator()(EOT & _solution) { virtual void operator()(EOT & _solution) {
current=_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); (*ls)(current);
std::cout << "current apres ls: "<< ls->className() << " " << current << std::endl;
}; };
/** /**
@ -135,14 +139,19 @@ public:
} }
private: private:
moDummyLS<Neighbor> dummyLS;
moVariableNeighborhoodSelection<EOT>& selection; moVariableNeighborhoodSelection<EOT>& selection;
eoMonOp<EOT>* ls;
eoMonOp<EOT>* shake;
moAcceptanceCriterion<Neighbor>& acceptCrit; moAcceptanceCriterion<Neighbor>& acceptCrit;
eoMonOp<EOT>* ls;
eoMonOp<EOT>& shake;
bool stop; bool stop;
EOT current; EOT current;
class moDummyEval: public eoEvalFunc<EOT>{
public:
void operator()(EOT& hop){}
}dummyEval;
}; };

View file

@ -55,26 +55,34 @@ public:
* test if there is still some neighborhood to explore * test if there is still some neighborhood to explore
* @return true if there is some neighborhood to explore * @return true if there is some neighborhood to explore
*/ */
virtual bool cont(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>& _ls){ virtual bool cont(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>*& _ls){
return (cycle || (current <= (LSvector.size()-2))); 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 * put the current neighborhood on the first one
*/ */
virtual void init(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>& _ls){ virtual void init(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>*& _ls){
current=0; current=0;
_ls = *(LSvector[current]); _ls = LSvector[current];
_shake = *(shakeVector[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 * put the current neighborhood on the next one
*/ */
virtual void next(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>& _ls){ virtual void next(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>*& _ls){
current = (current+1) % LSvector.size(); current = (current+1) % LSvector.size();
_ls = *(LSvector[current]); _ls = LSvector[current];
_shake = *(shakeVector[current]); _shake = *(shakeVector[current]);
std::cout << "current LS: " << current << std::endl;
std::cout << _solution << std::endl;
} }
private: private:

View file

@ -50,17 +50,17 @@ public:
* test if there is still some neighborhood to explore * test if there is still some neighborhood to explore
* @return true if there is some neighborhood to explore * @return true if there is some neighborhood to explore
*/ */
virtual bool cont(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>& _ls) = 0; virtual bool cont(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>*& _ls) = 0;
/** /**
* put the current neighborhood on the first one * put the current neighborhood on the first one
*/ */
virtual void init(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>& _ls) = 0; virtual void init(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>*& _ls) = 0;
/** /**
* put the current neighborhood on the next one * put the current neighborhood on the next one
*/ */
virtual void next(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>& _ls) = 0; virtual void next(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>*& _ls) = 0;
}; };

View file

@ -44,7 +44,7 @@ public:
current=0; current=0;
} }
void addLS(eoMonOp<EOT>& _otherLS, eoMonOp<EOT>& _otherShake){ void add(eoMonOp<EOT>& _otherLS, eoMonOp<EOT>& _otherShake){
LSvector.push_back(&_otherLS); LSvector.push_back(&_otherLS);
shakeVector.push_back(&_otherShake); shakeVector.push_back(&_otherShake);
} }
@ -61,17 +61,17 @@ public:
* test if there is still some neighborhood to explore * test if there is still some neighborhood to explore
* @return true if there is some neighborhood to explore * @return true if there is some neighborhood to explore
*/ */
virtual bool cont(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>& _ls) = 0; virtual bool cont(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>*& _ls) = 0;
/** /**
* put the current neighborhood on the first one * put the current neighborhood on the first one
*/ */
virtual void init(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>& _ls) = 0; virtual void init(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>*& _ls) = 0;
/** /**
* put the current neighborhood on the next one * put the current neighborhood on the next one
*/ */
virtual void next(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>& _ls) = 0; virtual void next(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>*& _ls) = 0;
protected: protected:
std::vector<eoMonOp<EOT>* > LSvector; std::vector<eoMonOp<EOT>* > LSvector;

View file

@ -39,13 +39,16 @@ using namespace std;
#include <neighborhood/moRndWithoutReplNeighborhood.h> #include <neighborhood/moRndWithoutReplNeighborhood.h>
#include <neighborhood/moOrderNeighborhood.h> #include <neighborhood/moOrderNeighborhood.h>
#include <explorer/moVNSexplorer.h> #include <explorer/moVNSexplorer.h>
#include <neighborhood/moBackwardVectorVNSelection.h> //#include <neighborhood/moBackwardVectorVNSelection.h>
#include <neighborhood/moForwardVectorVNSelection.h> #include <neighborhood/moForwardVectorVNSelection.h>
#include <neighborhood/moRndVectorVNSelection.h> //#include <neighborhood/moRndVectorVNSelection.h>
//Algorithm and its components //Algorithm and its components
#include <coolingSchedule/moCoolingSchedule.h> #include <coolingSchedule/moCoolingSchedule.h>
#include <algo/moSA.h> #include <algo/moSimpleHC.h>
#include <algo/moLocalSearch.h>
#include <continuator/moTimeContinuator.h>
//comparator //comparator
#include <comparator/moSolNeighborComparator.h> #include <comparator/moSolNeighborComparator.h>
@ -57,6 +60,11 @@ using namespace std;
#include <utils/eoFileMonitor.h> #include <utils/eoFileMonitor.h>
#include <continuator/moCounterMonitorSaver.h> #include <continuator/moCounterMonitorSaver.h>
#include <eoSwapMutation.h>
#include <eoShiftMutation.h>
#include <acceptCrit/moBetterAcceptCrit.h>
#include <acceptCrit/moAlwaysAcceptCrit.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Define types of the representation solution, different neighbors and neighborhoods // Define types of the representation solution, different neighbors and neighborhoods
@ -143,6 +151,7 @@ void main_function(int argc, char **argv)
* ========================================================= */ * ========================================================= */
moFullEvalByCopy<shiftNeighbor> shiftEval(fullEval); moFullEvalByCopy<shiftNeighbor> shiftEval(fullEval);
moFullEvalByCopy<swapNeighbor> swapEval(fullEval);
/* ========================================================= /* =========================================================
* *
@ -153,40 +162,50 @@ void main_function(int argc, char **argv)
shiftNeighborhood shiftNH((vecSize-1) * (vecSize-1)); shiftNeighborhood shiftNH((vecSize-1) * (vecSize-1));
swapNeighborhood swapNH(100); swapNeighborhood swapNH(100);
Queen sol;
init(sol);
shiftNeighbor n;
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
// moSA<shiftNeighbor> localSearch1(shiftNH, fullEval, shiftEval); moSimpleHC<shiftNeighbor> ls1(shiftNH, fullEval, shiftEval);
// moSimpleHC<swapNeighbor> ls2(swapNH, fullEval, swapEval);
// /* =========================================================
// * eoSwapMutation<Queen> swapMut;
// * execute the local search from random solution eoShiftMutation<Queen> shiftMut;
// *
// * ========================================================= */ moForwardVectorVNSelection<Queen> selectNH(ls1, shiftMut, true);
//
// Queen solution1, solution2; selectNH.add(ls2, swapMut);
//
// init(solution1); moAlwaysAcceptCrit<shiftNeighbor> acceptCrit;
//
// fullEval(solution1); moVNSexplorer<shiftNeighbor> explorer(selectNH, acceptCrit);
//
// std::cout << "#########################################" << std::endl; moTimeContinuator<shiftNeighbor> cont(5);
// std::cout << "initial solution1: " << solution1 << std::endl ;
// moLocalSearch<shiftNeighbor> vns(explorer, cont, fullEval);
// localSearch1(solution1);
//
// std::cout << "final solution1: " << solution1 << std::endl ; /* =========================================================
// std::cout << "#########################################" << std::endl; *
* 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;
// //
// //
// /* ========================================================= // /* =========================================================