git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1746 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
315ad014ce
commit
7e08ca9892
5 changed files with 175 additions and 8 deletions
|
|
@ -32,23 +32,24 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
|
||||||
#include <eval/moEval.h>
|
#include <eval/moEval.h>
|
||||||
#include <perturb/moPerturbation.h>
|
#include <perturb/moPerturbation.h>
|
||||||
|
#include <neighborhood/moNeighborhood.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Neighborhood Perturbation: explore the neighborhood to perturb the solution (the neighborhood could be different as the one used in the Local Search)
|
* Neighborhood Perturbation: explore the neighborhood to perturb the solution (the neighborhood could be different as the one used in the Local Search)
|
||||||
*/
|
*/
|
||||||
template< class Neighbor, class OtherNH >
|
template< class Neighbor, class OtherNeighbor >
|
||||||
class moNeighborhoodPerturb : public moPerturbation<Neighbor>{
|
class moNeighborhoodPerturb : public moPerturbation<Neighbor>{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef typename Neighbor::EOT EOT;
|
typedef typename Neighbor::EOT EOT;
|
||||||
typedef typename OtherNH::Neighbor OtherN;
|
typedef moNeighborhood<OtherNeighbor> OtherNH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _otherNeighborhood a neighborhood
|
* @param _otherNeighborhood a neighborhood
|
||||||
* @param _eval an Evaluation Function
|
* @param _eval an Evaluation Function
|
||||||
*/
|
*/
|
||||||
moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval<OtherN>& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){}
|
moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval<OtherNeighbor>& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply move on the solution
|
* Apply move on the solution
|
||||||
|
|
@ -101,8 +102,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OtherNH& otherNeighborhood;
|
OtherNH& otherNeighborhood;
|
||||||
moEval<OtherN>& eval;
|
moEval<OtherNeighbor>& eval;
|
||||||
OtherN current;
|
OtherNeighbor current;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ public:
|
||||||
* @param _fullEval a full evaluation function
|
* @param _fullEval a full evaluation function
|
||||||
* @param _threshold maximum number of iteration with no improvement
|
* @param _threshold maximum number of iteration with no improvement
|
||||||
*/
|
*/
|
||||||
moRestartPerturb(eoInit<EOT>& _init, eoEvalFunc<EOT>& _fullEval, unsigned int _threshold):init(_init), fullEval(_fullEval), threshold(_threshold) {}
|
moRestartPerturb(eoInit<EOT>& _initializer, eoEvalFunc<EOT>& _fullEval, unsigned int _threshold):initializer(_initializer), fullEval(_fullEval), threshold(_threshold) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply restart when necessary
|
* Apply restart when necessary
|
||||||
|
|
@ -60,7 +60,7 @@ public:
|
||||||
*/
|
*/
|
||||||
bool operator()(EOT& _solution){
|
bool operator()(EOT& _solution){
|
||||||
if((*this).getCounter()>= threshold){
|
if((*this).getCounter()>= threshold){
|
||||||
init(_solution);
|
initializer(_solution);
|
||||||
fullEval(_solution);
|
fullEval(_solution);
|
||||||
(*this).initCounter();
|
(*this).initCounter();
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +68,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
eoInit<EOT>& init;
|
eoInit<EOT>& initializer;
|
||||||
eoEvalFunc<EOT>& fullEval;
|
eoEvalFunc<EOT>& fullEval;
|
||||||
unsigned int threshold;
|
unsigned int threshold;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ SET (TEST_LIST
|
||||||
t-moCountMoveMemory
|
t-moCountMoveMemory
|
||||||
t-moMonOpPerturb
|
t-moMonOpPerturb
|
||||||
t-moRestartPerturb
|
t-moRestartPerturb
|
||||||
|
t-moNeighborhoodPerturb
|
||||||
)
|
)
|
||||||
|
|
||||||
FOREACH (test ${TEST_LIST})
|
FOREACH (test ${TEST_LIST})
|
||||||
|
|
|
||||||
91
trunk/paradiseo-mo/test/t-moNeighborhoodPerturb.cpp
Normal file
91
trunk/paradiseo-mo/test/t-moNeighborhoodPerturb.cpp
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
<t-moNeighborhoodPerturb.cpp>
|
||||||
|
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 <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "moTestClass.h"
|
||||||
|
|
||||||
|
#include <perturb/moNeighborhoodPerturb.h>
|
||||||
|
#include <problems/eval/oneMaxFullEval.h>
|
||||||
|
#include <eval/moFullEvalByCopy.h>
|
||||||
|
|
||||||
|
typedef moOrderNeighborhood<bitNeighbor> Neighborhood;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
|
||||||
|
std::cout << "[t-moNeighborhoodPerturb] => START" << std::endl;
|
||||||
|
|
||||||
|
oneMaxFullEval<bitVector> eval;
|
||||||
|
|
||||||
|
moFullEvalByCopy<bitNeighbor> moeval(eval);
|
||||||
|
|
||||||
|
bitVector sol;
|
||||||
|
sol.resize(3);
|
||||||
|
sol[0]=0;
|
||||||
|
sol[1]=0;
|
||||||
|
sol[2]=0;
|
||||||
|
|
||||||
|
sol.fitness(0);
|
||||||
|
|
||||||
|
Neighborhood nh(3);
|
||||||
|
|
||||||
|
bitNeighbor n;
|
||||||
|
|
||||||
|
moNeighborhoodPerturb<bitNeighbor, bitNeighbor> test(nh, moeval);
|
||||||
|
|
||||||
|
//test update
|
||||||
|
test.init(sol);
|
||||||
|
test(sol);
|
||||||
|
assert(sol[0]==1 && sol[1]==0 && sol[2]==0);
|
||||||
|
test.update(sol, n);
|
||||||
|
test(sol);
|
||||||
|
assert(sol[0]==1 && sol[1]==1 && sol[2]==0);
|
||||||
|
test.update(sol, n);
|
||||||
|
test(sol);
|
||||||
|
assert(sol[0]==1 && sol[1]==1 && sol[2]==1);
|
||||||
|
test.update(sol, n);
|
||||||
|
test(sol);
|
||||||
|
assert(sol[0]==0 && sol[1]==1 && sol[2]==1);
|
||||||
|
|
||||||
|
//test add
|
||||||
|
|
||||||
|
test.add(sol, n);
|
||||||
|
test(sol);
|
||||||
|
assert(sol[0]==1 && sol[1]==1 && sol[2]==1);
|
||||||
|
|
||||||
|
test.clearMemory();
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "[t-moNeighborhoodPerturb] => OK" << std::endl;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -31,10 +31,84 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <perturb/moRestartPerturb.h>
|
||||||
|
#include <problems/permutation/moShiftNeighbor.h>
|
||||||
|
#include <problems/eval/queenFullEval.h>
|
||||||
|
|
||||||
|
#include <eoInt.h>
|
||||||
|
#include <eoInit.h>
|
||||||
|
|
||||||
|
typedef eoInt<unsigned int> QUEEN;
|
||||||
|
|
||||||
|
class dummyInit : public eoInit<QUEEN>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
dummyInit(unsigned int _size):size(_size){}
|
||||||
|
|
||||||
|
void operator()(QUEEN& _sol){
|
||||||
|
_sol.resize(0);
|
||||||
|
for(unsigned int i=0; i<size; i++)
|
||||||
|
_sol.push_back(i);
|
||||||
|
_sol.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned int size;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
std::cout << "[t-moRestartPerturb] => START" << std::endl;
|
std::cout << "[t-moRestartPerturb] => START" << std::endl;
|
||||||
|
|
||||||
|
QUEEN queen;
|
||||||
|
moShiftNeighbor<QUEEN> n;
|
||||||
|
|
||||||
|
dummyInit initializer(4);
|
||||||
|
|
||||||
|
queenFullEval<QUEEN> eval;
|
||||||
|
|
||||||
|
moRestartPerturb<moShiftNeighbor<QUEEN> > test(initializer, eval, 3);
|
||||||
|
|
||||||
|
queen.resize(4);
|
||||||
|
queen[0]=1;
|
||||||
|
queen[1]=2;
|
||||||
|
queen[2]=0;
|
||||||
|
queen[3]=3;
|
||||||
|
|
||||||
|
test.init(queen);
|
||||||
|
|
||||||
|
test(queen);
|
||||||
|
assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3);
|
||||||
|
test.update(queen,n); //first noMove
|
||||||
|
test(queen);
|
||||||
|
assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3);
|
||||||
|
test.update(queen,n); //second noMove
|
||||||
|
test(queen);
|
||||||
|
assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3);
|
||||||
|
test.update(queen,n); //third noMove
|
||||||
|
test(queen);//here the perturb should be called
|
||||||
|
assert(queen[0]==0 && queen[1]==1 && queen[2]==2 && queen[3]==3);
|
||||||
|
|
||||||
|
queen[0]=1;
|
||||||
|
queen[1]=2;
|
||||||
|
queen[2]=0;
|
||||||
|
queen[3]=3;
|
||||||
|
|
||||||
|
//Retry the same test to verify counter is been reinit to 0
|
||||||
|
|
||||||
|
test(queen);
|
||||||
|
assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3);
|
||||||
|
test.update(queen,n); //first noMove
|
||||||
|
test(queen);
|
||||||
|
assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3);
|
||||||
|
test.update(queen,n); //second noMove
|
||||||
|
test(queen);
|
||||||
|
assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3);
|
||||||
|
test.update(queen,n); //third noMove
|
||||||
|
test(queen); //here the perturb should be called
|
||||||
|
assert(queen[0]==0 && queen[1]==1 && queen[2]==2 && queen[3]==3);
|
||||||
|
|
||||||
std::cout << "[t-moRestartPerturb] => OK" << std::endl;
|
std::cout << "[t-moRestartPerturb] => OK" << std::endl;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue