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 <eoOp.h>
#include <acceptCrit/moAcceptanceCriterion.h>
#include <algo/moDummyLS.h>
/**
* Explorer for Variiable Neighborhood Search
@ -55,7 +56,7 @@ public:
moVNSexplorer(
moVariableNeighborhoodSelection<EOT> & _selection,
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
*/
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<Neighbor> dummyLS;
moVariableNeighborhoodSelection<EOT>& selection;
eoMonOp<EOT>* ls;
eoMonOp<EOT>* shake;
moAcceptanceCriterion<Neighbor>& acceptCrit;
eoMonOp<EOT>* ls;
eoMonOp<EOT>& shake;
bool stop;
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
* @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)));
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<EOT>& _shake, eoMonOp<EOT>& _ls){
virtual void init(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>*& _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<EOT>& _shake, eoMonOp<EOT>& _ls){
virtual void next(EOT& _solution, eoMonOp<EOT>& _shake, eoMonOp<EOT>*& _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:

View file

@ -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<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
*/
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
*/
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;
}
void addLS(eoMonOp<EOT>& _otherLS, eoMonOp<EOT>& _otherShake){
void add(eoMonOp<EOT>& _otherLS, eoMonOp<EOT>& _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<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
*/
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
*/
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:
std::vector<eoMonOp<EOT>* > LSvector;

View file

@ -39,13 +39,16 @@ using namespace std;
#include <neighborhood/moRndWithoutReplNeighborhood.h>
#include <neighborhood/moOrderNeighborhood.h>
#include <explorer/moVNSexplorer.h>
#include <neighborhood/moBackwardVectorVNSelection.h>
//#include <neighborhood/moBackwardVectorVNSelection.h>
#include <neighborhood/moForwardVectorVNSelection.h>
#include <neighborhood/moRndVectorVNSelection.h>
//#include <neighborhood/moRndVectorVNSelection.h>
//Algorithm and its components
#include <coolingSchedule/moCoolingSchedule.h>
#include <algo/moSA.h>
#include <algo/moSimpleHC.h>
#include <algo/moLocalSearch.h>
#include <continuator/moTimeContinuator.h>
//comparator
#include <comparator/moSolNeighborComparator.h>
@ -57,6 +60,11 @@ using namespace std;
#include <utils/eoFileMonitor.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
@ -143,6 +151,7 @@ void main_function(int argc, char **argv)
* ========================================================= */
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));
swapNeighborhood swapNH(100);
Queen sol;
init(sol);
shiftNeighbor n;
/* =========================================================
*
* the local search algorithm
*
* ========================================================= */
// moSA<shiftNeighbor> 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<shiftNeighbor> ls1(shiftNH, fullEval, shiftEval);
moSimpleHC<swapNeighbor> ls2(swapNH, fullEval, swapEval);
eoSwapMutation<Queen> swapMut;
eoShiftMutation<Queen> shiftMut;
moForwardVectorVNSelection<Queen> selectNH(ls1, shiftMut, true);
selectNH.add(ls2, swapMut);
moAlwaysAcceptCrit<shiftNeighbor> acceptCrit;
moVNSexplorer<shiftNeighbor> explorer(selectNH, acceptCrit);
moTimeContinuator<shiftNeighbor> cont(5);
moLocalSearch<shiftNeighbor> 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;
//
//
// /* =========================================================