Doc and tests added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1706 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
6cb6070df4
commit
baf31d0c30
25 changed files with 159 additions and 26 deletions
|
|
@ -35,6 +35,8 @@
|
|||
#ifndef _moMetropolisHastingExplorer_h
|
||||
#define _moMetropolisHastingExplorer_h
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <explorer/moNeighborhoodExplorer.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
|
|
@ -67,6 +69,9 @@ public:
|
|||
moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
if(!neighborhood.isRandom()){
|
||||
std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@ public:
|
|||
nbStep(_nbStep) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
if(!neighborhood.isRandom()){
|
||||
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -63,6 +63,9 @@ public:
|
|||
current=new Neighbor();
|
||||
// number of step done
|
||||
step = 0;
|
||||
if(!neighborhood.isRandom()){
|
||||
std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -110,8 +110,7 @@ public:
|
|||
*/
|
||||
virtual void updateParam(EOT& _solution)
|
||||
{
|
||||
if ((*this).moveApplied())
|
||||
{
|
||||
if ((*this).moveApplied()){
|
||||
tabuList.add(_solution, *best);
|
||||
intensification.add(_solution, *best);
|
||||
diversification.add(_solution, *best);
|
||||
|
|
@ -126,10 +125,9 @@ public:
|
|||
|
||||
|
||||
/**
|
||||
* terminate : NOTHING TO DO
|
||||
* terminate : _solution becomes the best so far
|
||||
*/
|
||||
virtual void terminate(EOT & _solution)
|
||||
{
|
||||
virtual void terminate(EOT & _solution){
|
||||
_solution= bestSoFar;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@ public:
|
|||
/**
|
||||
* Constructor
|
||||
* @param _maxSize maximum size of the tabu list
|
||||
* @param _howlong how many iteration a move is tabu
|
||||
*/
|
||||
moSolVectorTabuList(unsigned int _maxSize) : maxSize(_maxSize){
|
||||
moSolVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong){
|
||||
tabuList.reserve(_maxSize);
|
||||
tabuList.resize(0);
|
||||
}
|
||||
|
|
@ -38,12 +39,18 @@ public:
|
|||
* @param _neighbor the current neighbor (unused)
|
||||
*/
|
||||
virtual void add(EOT & _sol, Neighbor & _neighbor){
|
||||
if(tabuList.size() < maxSize)
|
||||
tabuList.push_back(_sol);
|
||||
else{
|
||||
tabuList[index%maxSize] = _sol;
|
||||
index++;
|
||||
}
|
||||
|
||||
if(tabuList.size() < maxSize){
|
||||
std::pair<EOT, unsigned int> tmp;
|
||||
tmp.first=_sol;
|
||||
tmp.second=howlong;
|
||||
tabuList.push_back(tmp);
|
||||
}
|
||||
else{
|
||||
tabuList[index%maxSize].first = _sol;
|
||||
tabuList[index%maxSize].second = howlong;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -51,7 +58,10 @@ public:
|
|||
* @param _sol the current solution
|
||||
* @param _neighbor the current neighbor (unused)
|
||||
*/
|
||||
virtual void update(EOT & _sol, Neighbor & _neighbor){}
|
||||
virtual void update(EOT & _sol, Neighbor & _neighbor){
|
||||
for(unsigned int i=0; i<tabuList.size(); i++)
|
||||
tabuList[i].second--;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the solution is tabu
|
||||
|
|
@ -63,7 +73,7 @@ public:
|
|||
EOT tmp=_sol;
|
||||
_neighbor.move(tmp);
|
||||
for(unsigned int i=0; i<tabuList.size(); i++){
|
||||
if (tabuList[i] == tmp)
|
||||
if ((howlong > 0 && tabuList[i].second > 0 && tabuList[i].first == tmp) || (howlong==0 && tabuList[i].first==tmp))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -79,9 +89,13 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
|
||||
std::vector<EOT> tabuList;
|
||||
//tabu list
|
||||
std::vector< std::pair<EOT, unsigned int> > tabuList;
|
||||
//maximum size of the tabu list
|
||||
unsigned int maxSize;
|
||||
//how many iteration a move is tabu
|
||||
unsigned int howlong;
|
||||
//index on the tabulist
|
||||
unsigned long index;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -54,6 +54,13 @@ public:
|
|||
*/
|
||||
moNeighborhood(){}
|
||||
|
||||
/**
|
||||
* @return if the neighborhood is random
|
||||
*/
|
||||
virtual bool isRandom(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a solution has (again) a Neighbor
|
||||
* @param _solution the related solution
|
||||
|
|
|
|||
|
|
@ -33,6 +33,13 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#include <neighborhood/moNeighborhood.h>
|
||||
|
||||
template< class Neighbor >
|
||||
class moRndNeighborhood : virtual public moNeighborhood<Neighbor>{};
|
||||
class moRndNeighborhood : virtual public moNeighborhood<Neighbor>{
|
||||
|
||||
public:
|
||||
|
||||
bool isRandom(){
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue