paradiseo new mo added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1712 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
e2546ca8d5
commit
d7496cafff
116 changed files with 12034 additions and 0 deletions
19
trunk/paradiseo-mo/src/memory/moAspiration.h
Normal file
19
trunk/paradiseo-mo/src/memory/moAspiration.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef _moAspiration_h
|
||||
#define _moAspiration_h
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
/**
|
||||
* Abstract class for Aspiration Criteria
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moAspiration : public eoBF<typename Neighbor::EOT &, Neighbor &, bool>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
virtual void init(EOT & _sol) = 0;
|
||||
virtual void update(EOT & _sol, Neighbor & _neighbor) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
57
trunk/paradiseo-mo/src/memory/moBestImprAspiration.h
Normal file
57
trunk/paradiseo-mo/src/memory/moBestImprAspiration.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef _moBestImprAspiration_h
|
||||
#define _moBestImprAspiration_h
|
||||
|
||||
#include <memory/moAspiration.h>
|
||||
|
||||
/**
|
||||
* Aspiration criteria accepts a solution better than the best so far
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moBestImprAspiration : public moAspiration<Neighbor>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* init the best solution
|
||||
* @param _sol the best solution found
|
||||
*/
|
||||
void init(EOT & _sol){
|
||||
bestFoundSoFar = _sol;
|
||||
}
|
||||
|
||||
/**
|
||||
* update the "bestFoundSoFar" if a best solution is found
|
||||
* @param _sol a solution
|
||||
* @param _neighbor a neighbor
|
||||
*/
|
||||
void update(EOT & _sol, Neighbor & _neighbor){
|
||||
if (bestFoundSoFar.fitness() < _sol.fitness())
|
||||
bestFoundSoFar = _sol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the tabu feature of the neighbor:
|
||||
* test if the neighbor's fitness is better than the "bestFoundSoFar" fitness
|
||||
* @param _sol a solution
|
||||
* @param _neighbor a neighbor
|
||||
* @return true if _neighbor fitness is better than the "bestFoundSoFar"
|
||||
*/
|
||||
bool operator()(EOT & _sol, Neighbor & _neighbor){
|
||||
return (bestFoundSoFar.fitness() < _neighbor.fitness());
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter
|
||||
* @return a reference on the best found so far solution
|
||||
*/
|
||||
EOT& getBest(){
|
||||
return bestFoundSoFar;
|
||||
}
|
||||
|
||||
private:
|
||||
EOT bestFoundSoFar;
|
||||
};
|
||||
|
||||
#endif
|
||||
14
trunk/paradiseo-mo/src/memory/moDiversification.h
Normal file
14
trunk/paradiseo-mo/src/memory/moDiversification.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef _moDiversification_h
|
||||
#define _moDiversification_h
|
||||
|
||||
#include <memory/moMemory.h>
|
||||
#include <eoFunctor.h>
|
||||
|
||||
/**
|
||||
* Abstract class for diversification strategy
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moDiversification : public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool>
|
||||
{};
|
||||
|
||||
#endif
|
||||
43
trunk/paradiseo-mo/src/memory/moDummyDiversification.h
Normal file
43
trunk/paradiseo-mo/src/memory/moDummyDiversification.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef _moDummyDiversification_h
|
||||
#define _moDummyDiversification_h
|
||||
|
||||
#include <memory/moDiversification.h>
|
||||
|
||||
/**
|
||||
* Dummy diversification strategy
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moDummyDiversification : public moDiversification<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Init : NOTHIING TO DO
|
||||
*/
|
||||
void init(EOT & _sol) {}
|
||||
|
||||
/**
|
||||
* Add : NOTHIING TO DO
|
||||
*/
|
||||
void add(EOT & _sol, Neighbor & _neighbor) {}
|
||||
|
||||
/**
|
||||
* Update : NOTHIING TO DO
|
||||
*/
|
||||
void update(EOT & _sol, Neighbor & _neighbor) {}
|
||||
|
||||
/**
|
||||
* ClearMemory : NOTHIING TO DO
|
||||
*/
|
||||
void clearMemory() {}
|
||||
|
||||
/**
|
||||
* @return always false
|
||||
*/
|
||||
bool operator()(EOT &){
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
43
trunk/paradiseo-mo/src/memory/moDummyIntensification.h
Normal file
43
trunk/paradiseo-mo/src/memory/moDummyIntensification.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef _moDummyIntensification_h
|
||||
#define _moDummyIntensification_h
|
||||
|
||||
#include <memory/moIntensification.h>
|
||||
|
||||
/**
|
||||
* Dummy intensification strategy
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moDummyIntensification : public moIntensification<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Init : NOTHIING TO DO
|
||||
*/
|
||||
void init(EOT & _sol) {}
|
||||
|
||||
/**
|
||||
* Add : NOTHIING TO DO
|
||||
*/
|
||||
void add(EOT & _sol, Neighbor & _neighbor) {}
|
||||
|
||||
/**
|
||||
* Update : NOTHIING TO DO
|
||||
*/
|
||||
void update(EOT & _sol, Neighbor & _neighbor) {}
|
||||
|
||||
/**
|
||||
* ClearMemory : NOTHIING TO DO
|
||||
*/
|
||||
void clearMemory() {}
|
||||
|
||||
/**
|
||||
* @return always false
|
||||
*/
|
||||
bool operator()(EOT &){
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
14
trunk/paradiseo-mo/src/memory/moIntensification.h
Normal file
14
trunk/paradiseo-mo/src/memory/moIntensification.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef _moIntensification_h
|
||||
#define _moIntensification_h
|
||||
|
||||
#include <memory/moMemory.h>
|
||||
#include <eoFunctor.h>
|
||||
|
||||
/**
|
||||
* Abstract class for intensification strategy
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moIntensification : public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool>
|
||||
{};
|
||||
|
||||
#endif
|
||||
40
trunk/paradiseo-mo/src/memory/moMemory.h
Normal file
40
trunk/paradiseo-mo/src/memory/moMemory.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef _moMemory_h
|
||||
#define _moMemory_h
|
||||
|
||||
/**
|
||||
* Abstract class for different memory
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moMemory //: public eoObject
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Init the memory
|
||||
* @param _sol the current solution
|
||||
*/
|
||||
virtual void init(EOT & _sol) = 0;
|
||||
|
||||
/**
|
||||
* Add data in the memory
|
||||
* @param _sol the current solution
|
||||
* @param _neighbor the current neighbor
|
||||
*/
|
||||
virtual void add(EOT & _sol, Neighbor & _neighbor) = 0;
|
||||
|
||||
/**
|
||||
* update the memory
|
||||
* @param _sol the current solution
|
||||
* @param _neighbor the current neighbor
|
||||
*/
|
||||
virtual void update(EOT & _sol, Neighbor & _neighbor) = 0;
|
||||
|
||||
/**
|
||||
* clear the memory
|
||||
*/
|
||||
virtual void clearMemory() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
103
trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h
Normal file
103
trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#ifndef _moSolVectorTabuList_h
|
||||
#define _moSolVectorTabuList_h
|
||||
|
||||
#include <memory/moTabuList.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* Tabu List of solution stocked in a vector
|
||||
*/
|
||||
template<class Neighbor >
|
||||
class moSolVectorTabuList : public moTabuList<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _maxSize maximum size of the tabu list
|
||||
* @param _howlong how many iteration a move is tabu
|
||||
*/
|
||||
moSolVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong){
|
||||
tabuList.reserve(_maxSize);
|
||||
tabuList.resize(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* init the tabuList by clearing the memory
|
||||
* @param _sol the current solution
|
||||
*/
|
||||
virtual void init(EOT & _sol){
|
||||
clearMemory();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add a new solution in the tabuList
|
||||
* @param _sol the current solution
|
||||
* @param _neighbor the current neighbor (unused)
|
||||
*/
|
||||
virtual void add(EOT & _sol, Neighbor & _neighbor){
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* update the tabulist: NOTHING TO DO
|
||||
* @param _sol the current solution
|
||||
* @param _neighbor the current neighbor (unused)
|
||||
*/
|
||||
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
|
||||
* @param _sol the current solution
|
||||
* @param _neighbor the current neighbor (unused)
|
||||
* @return true if tabuList contains _sol
|
||||
*/
|
||||
virtual bool check(EOT & _sol, Neighbor & _neighbor){
|
||||
EOT tmp=_sol;
|
||||
_neighbor.move(tmp);
|
||||
for(unsigned int i=0; i<tabuList.size(); i++){
|
||||
if ((howlong > 0 && tabuList[i].second > 0 && tabuList[i].first == tmp) || (howlong==0 && tabuList[i].first==tmp))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* clearMemory: remove all solution of the tabuList
|
||||
*/
|
||||
virtual void clearMemory(){
|
||||
tabuList.resize(0);
|
||||
index = 0;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
//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;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
24
trunk/paradiseo-mo/src/memory/moTabuList.h
Normal file
24
trunk/paradiseo-mo/src/memory/moTabuList.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef _moTabuList_h
|
||||
#define _moTabuList_h
|
||||
|
||||
#include <memory/moMemory.h>
|
||||
|
||||
/**
|
||||
* Abstract class for the Tabu List
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moTabuList : public moMemory<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Check if a neighbor is tabu or not
|
||||
* @param _sol the current solution
|
||||
* @param _neighbor the neighbor
|
||||
* @return true if the neighbor is tabu
|
||||
*/
|
||||
virtual bool check(EOT & _sol, Neighbor & _neighbor) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue