passage du code dans astyle
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1713 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
d7496cafff
commit
dd66b5e4bd
105 changed files with 3950 additions and 3924 deletions
|
|
@ -52,66 +52,66 @@ public:
|
|||
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
|
||||
using moNeighborhoodExplorer<Neighborhood>::eval;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||
*/
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||
*/
|
||||
moFirstImprExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moFirstImprExplorer(){
|
||||
delete current;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moFirstImprExplorer() {
|
||||
delete current;
|
||||
}
|
||||
|
||||
/**
|
||||
* initParam: NOTHING TO DO
|
||||
*/
|
||||
virtual void initParam(EOT & solution){};
|
||||
/**
|
||||
* initParam: NOTHING TO DO
|
||||
*/
|
||||
virtual void initParam(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* updateParam: NOTHING TO DO
|
||||
*/
|
||||
virtual void updateParam(EOT & solution){};
|
||||
/**
|
||||
* updateParam: NOTHING TO DO
|
||||
*/
|
||||
virtual void updateParam(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution){};
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* Explore the neighborhood of a solution
|
||||
* @param _solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution){
|
||||
virtual void operator()(EOT & _solution) {
|
||||
|
||||
//Test if _solution has a Neighbor
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
//Test if _solution has a Neighbor
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
|
||||
//test all others neighbors
|
||||
while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
}
|
||||
}
|
||||
else{
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
//test all others neighbors
|
||||
while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
}
|
||||
}
|
||||
else {
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -120,7 +120,7 @@ public:
|
|||
* @return true if an ameliorated neighbor was be found
|
||||
*/
|
||||
virtual bool isContinue(EOT & _solution) {
|
||||
return isAccept ;
|
||||
return isAccept ;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -128,10 +128,10 @@ public:
|
|||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
//move the solution
|
||||
(*current).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*current).fitness());
|
||||
//move the solution
|
||||
(*current).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*current).fitness());
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -140,10 +140,10 @@ public:
|
|||
* @return true if the best neighbor ameliorate the fitness
|
||||
*/
|
||||
virtual bool accept(EOT & _solution) {
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
isAccept = solNeighborComparator(_solution, (*current)) ;
|
||||
}
|
||||
return isAccept;
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
isAccept = solNeighborComparator(_solution, (*current)) ;
|
||||
}
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -56,49 +56,49 @@ public:
|
|||
using moSimpleHCneutralExplorer<Neighborhood>::initParam;
|
||||
using moSimpleHCneutralExplorer<Neighborhood>::updateParam;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||
* @param _nbStep maximum step to do
|
||||
*/
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||
* @param _nbStep maximum step to do
|
||||
*/
|
||||
moHCneutralExplorer(Neighborhood& _neighborhood,
|
||||
moEval<Neighbor>& _eval,
|
||||
moNeighborComparator<Neighbor>& _neighborComparator,
|
||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
||||
unsigned _nbStep) :
|
||||
moSimpleHCneutralExplorer<Neighborhood>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
|
||||
nbStep(_nbStep){
|
||||
//Some cycle is possible with equals fitness solutions if the neighborhood is not random
|
||||
if(!neighborhood.isRandom()){
|
||||
std::cout << "moHCneutralExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
moEval<Neighbor>& _eval,
|
||||
moNeighborComparator<Neighbor>& _neighborComparator,
|
||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
||||
unsigned _nbStep) :
|
||||
moSimpleHCneutralExplorer<Neighborhood>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
|
||||
nbStep(_nbStep) {
|
||||
//Some cycle is possible with equals fitness solutions if the neighborhood is not random
|
||||
if (!neighborhood.isRandom()) {
|
||||
std::cout << "moHCneutralExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moHCneutralExplorer(){
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moHCneutralExplorer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* initial number of step
|
||||
*/
|
||||
virtual void initParam(EOT & solution){
|
||||
moSimpleHCneutralExplorer<Neighborhood>::initParam(solution);
|
||||
/**
|
||||
* initial number of step
|
||||
*/
|
||||
virtual void initParam(EOT & solution) {
|
||||
moSimpleHCneutralExplorer<Neighborhood>::initParam(solution);
|
||||
|
||||
step = 0;
|
||||
step = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* one more step
|
||||
*/
|
||||
virtual void updateParam(EOT & solution){
|
||||
moSimpleHCneutralExplorer<Neighborhood>::updateParam(solution);
|
||||
|
||||
step++;
|
||||
/**
|
||||
* one more step
|
||||
*/
|
||||
virtual void updateParam(EOT & solution) {
|
||||
moSimpleHCneutralExplorer<Neighborhood>::updateParam(solution);
|
||||
|
||||
step++;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -107,7 +107,7 @@ public:
|
|||
* @return true there is some steps to do
|
||||
*/
|
||||
virtual bool isContinue(EOT & _solution) {
|
||||
return (step < nbStep) && isAccept ;
|
||||
return (step < nbStep) && isAccept ;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -116,9 +116,9 @@ public:
|
|||
* @return true if the best neighbor ameliorate the fitness or is equals
|
||||
*/
|
||||
virtual bool accept(EOT & _solution) {
|
||||
if(neighborhood.hasNeighbor(_solution))
|
||||
isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ;
|
||||
return isAccept;
|
||||
if (neighborhood.hasNeighbor(_solution))
|
||||
isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ;
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -58,69 +58,69 @@ public:
|
|||
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
|
||||
using moNeighborhoodExplorer<Neighborhood>::eval;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||
* @param _nbStep maximum number of step to do
|
||||
*/
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||
* @param _nbStep maximum number of step to do
|
||||
*/
|
||||
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;
|
||||
}
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
if (!neighborhood.isRandom()) {
|
||||
std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moMetropolisHastingExplorer(){
|
||||
delete current;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moMetropolisHastingExplorer() {
|
||||
delete current;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialization of the number of step to be done
|
||||
* @param _solution the solution (unused here)
|
||||
*/
|
||||
virtual void initParam(EOT & _solution){
|
||||
step = 0;
|
||||
isAccept = true;
|
||||
/**
|
||||
* initialization of the number of step to be done
|
||||
* @param _solution the solution (unused here)
|
||||
*/
|
||||
virtual void initParam(EOT & _solution) {
|
||||
step = 0;
|
||||
isAccept = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* increase the number of step
|
||||
* @param _solution the solution (unused here)
|
||||
*/
|
||||
virtual void updateParam(EOT & _solution){
|
||||
step++;
|
||||
/**
|
||||
* increase the number of step
|
||||
* @param _solution the solution (unused here)
|
||||
*/
|
||||
virtual void updateParam(EOT & _solution) {
|
||||
step++;
|
||||
};
|
||||
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
* @param _solution the solution (unused here)
|
||||
*/
|
||||
virtual void terminate(EOT & _solution){};
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
* @param _solution the solution (unused here)
|
||||
*/
|
||||
virtual void terminate(EOT & _solution) {};
|
||||
|
||||
/**
|
||||
* Explore the neighborhood of a solution
|
||||
* @param _solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution){
|
||||
//Test if _solution has a Neighbor
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
virtual void operator()(EOT & _solution) {
|
||||
//Test if _solution has a Neighbor
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
}
|
||||
else{
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
}
|
||||
else {
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -129,7 +129,7 @@ public:
|
|||
* @return true there is some steps to do
|
||||
*/
|
||||
virtual bool isContinue(EOT & _solution) {
|
||||
return (step < nbStep) ;
|
||||
return (step < nbStep) ;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -137,10 +137,10 @@ public:
|
|||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
//move the solution
|
||||
(*current).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*current).fitness());
|
||||
//move the solution
|
||||
(*current).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*current).fitness());
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -149,27 +149,27 @@ public:
|
|||
* @return true if the best neighbor ameliorate the fitness
|
||||
*/
|
||||
virtual bool accept(EOT & _solution) {
|
||||
double alpha=0.0;
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
if (solNeighborComparator(_solution, *current))
|
||||
isAccept = true;
|
||||
else{
|
||||
if(_solution.fitness() != 0){
|
||||
if( (double)current->fitness() < (double)_solution.fitness()) // maximizing
|
||||
alpha = (double) current->fitness() / (double) _solution.fitness();
|
||||
else //minimizing
|
||||
alpha = (double) _solution.fitness() / (double) current->fitness();
|
||||
isAccept = (rng.uniform() < alpha) ;
|
||||
}
|
||||
else{
|
||||
if( (double)current->fitness() < (double)_solution.fitness()) // maximizing
|
||||
isAccept = true;
|
||||
else
|
||||
isAccept = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isAccept;
|
||||
double alpha=0.0;
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
if (solNeighborComparator(_solution, *current))
|
||||
isAccept = true;
|
||||
else {
|
||||
if (_solution.fitness() != 0) {
|
||||
if ( (double)current->fitness() < (double)_solution.fitness()) // maximizing
|
||||
alpha = (double) current->fitness() / (double) _solution.fitness();
|
||||
else //minimizing
|
||||
alpha = (double) _solution.fitness() / (double) current->fitness();
|
||||
isAccept = (rng.uniform() < alpha) ;
|
||||
}
|
||||
else {
|
||||
if ( (double)current->fitness() < (double)_solution.fitness()) // maximizing
|
||||
isAccept = true;
|
||||
else
|
||||
isAccept = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -102,16 +102,16 @@ public:
|
|||
* Getter for variable "isMoved"
|
||||
* @return true if move is applied
|
||||
*/
|
||||
bool moveApplied(){
|
||||
return isMoved;
|
||||
bool moveApplied() {
|
||||
return isMoved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for variable "isMoved"
|
||||
* @param _isMoved
|
||||
*/
|
||||
void moveApplied(bool _isMoved){
|
||||
isMoved=_isMoved;
|
||||
void moveApplied(bool _isMoved) {
|
||||
isMoved=_isMoved;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,7 +119,7 @@ public:
|
|||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moNeighborhoodExplorer";
|
||||
return "moNeighborhoodExplorer";
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -54,79 +54,79 @@ public:
|
|||
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
|
||||
using moNeighborhoodExplorer<Neighborhood>::eval;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||
* @param _nbStep maximum number of step to do
|
||||
*/
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _solNeighborComparator a solution vs neighbor comparator
|
||||
* @param _nbStep maximum number of step to do
|
||||
*/
|
||||
moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval,
|
||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
||||
unsigned _nbStep):
|
||||
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
|
||||
solNeighborComparator(_solNeighborComparator),
|
||||
nbStep(_nbStep) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
if(!neighborhood.isRandom()){
|
||||
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
||||
unsigned _nbStep):
|
||||
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
|
||||
solNeighborComparator(_solNeighborComparator),
|
||||
nbStep(_nbStep) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
if (!neighborhood.isRandom()) {
|
||||
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moRandomNeutralWalkExplorer(){
|
||||
delete current;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moRandomNeutralWalkExplorer() {
|
||||
delete current;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialization of the number of step to be done
|
||||
*/
|
||||
virtual void initParam(EOT & solution){
|
||||
step = 0;
|
||||
isAccept = true;
|
||||
/**
|
||||
* initialization of the number of step to be done
|
||||
*/
|
||||
virtual void initParam(EOT & solution) {
|
||||
step = 0;
|
||||
isAccept = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* increase the number of step
|
||||
*/
|
||||
virtual void updateParam(EOT & solution){
|
||||
step++;
|
||||
/**
|
||||
* increase the number of step
|
||||
*/
|
||||
virtual void updateParam(EOT & solution) {
|
||||
step++;
|
||||
};
|
||||
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution){};
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* Explore the neighborhood of a solution
|
||||
* @param _solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution){
|
||||
//Test if _solution has a Neighbor
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
virtual void operator()(EOT & _solution) {
|
||||
//Test if _solution has a Neighbor
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
|
||||
//test all others neighbors
|
||||
while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
}
|
||||
}
|
||||
else{
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
//test all others neighbors
|
||||
while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
}
|
||||
}
|
||||
else {
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* continue if there is a neighbor and it is remainds some steps to do
|
||||
|
|
@ -134,7 +134,7 @@ public:
|
|||
* @return true there is some steps to do
|
||||
*/
|
||||
virtual bool isContinue(EOT & _solution) {
|
||||
return (step < nbStep) && isAccept ;
|
||||
return (step < nbStep) && isAccept ;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -142,10 +142,10 @@ public:
|
|||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
//move the solution
|
||||
(*current).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*current).fitness());
|
||||
//move the solution
|
||||
(*current).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*current).fitness());
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -154,9 +154,9 @@ public:
|
|||
* @return true if the best neighbor ameliorate the fitness
|
||||
*/
|
||||
virtual bool accept(EOT & _solution) {
|
||||
if(neighborhood.hasNeighbor(_solution))
|
||||
isAccept = solNeighborComparator.equals(_solution, (*current)) ;
|
||||
return isAccept;
|
||||
if (neighborhood.hasNeighbor(_solution))
|
||||
isAccept = solNeighborComparator.equals(_solution, (*current)) ;
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -52,69 +52,69 @@ public:
|
|||
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
|
||||
using moNeighborhoodExplorer<Neighborhood>::eval;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _nbStep maximum number of step to do
|
||||
*/
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _nbStep maximum number of step to do
|
||||
*/
|
||||
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), nbStep(_nbStep) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
// number of step done
|
||||
step = 0;
|
||||
if(!neighborhood.isRandom()){
|
||||
std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
// number of step done
|
||||
step = 0;
|
||||
if (!neighborhood.isRandom()) {
|
||||
std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moRandomWalkExplorer(){
|
||||
delete current;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moRandomWalkExplorer() {
|
||||
delete current;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialization of the number of step to be done
|
||||
*/
|
||||
virtual void initParam(EOT & solution){
|
||||
step = 0;
|
||||
isAccept = true;
|
||||
/**
|
||||
* initialization of the number of step to be done
|
||||
*/
|
||||
virtual void initParam(EOT & solution) {
|
||||
step = 0;
|
||||
isAccept = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* increase the number of step
|
||||
*/
|
||||
virtual void updateParam(EOT & solution){
|
||||
step++;
|
||||
/**
|
||||
* increase the number of step
|
||||
*/
|
||||
virtual void updateParam(EOT & solution) {
|
||||
step++;
|
||||
};
|
||||
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution){};
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* Explore the neighborhood with only one random solution
|
||||
* @param _solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution){
|
||||
virtual void operator()(EOT & _solution) {
|
||||
|
||||
//Test if _solution has a Neighbor
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
//Test if _solution has a Neighbor
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
|
||||
isAccept = true;
|
||||
}
|
||||
else{
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
isAccept = true;
|
||||
}
|
||||
else {
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -123,7 +123,7 @@ public:
|
|||
* @return true there is some steps to do
|
||||
*/
|
||||
virtual bool isContinue(EOT & _solution) {
|
||||
return (step < nbStep) && isAccept ;
|
||||
return (step < nbStep) && isAccept ;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -131,10 +131,10 @@ public:
|
|||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
//move the solution
|
||||
(*current).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*current).fitness());
|
||||
//move the solution
|
||||
(*current).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*current).fitness());
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -143,9 +143,9 @@ public:
|
|||
* @return true if the best neighbor ameliorate the fitness
|
||||
*/
|
||||
virtual bool accept(EOT & _solution) {
|
||||
if(neighborhood.hasNeighbor(_solution))
|
||||
isAccept = true ;
|
||||
return isAccept;
|
||||
if (neighborhood.hasNeighbor(_solution))
|
||||
isAccept = true ;
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -52,77 +52,77 @@ public:
|
|||
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
|
||||
using moNeighborhoodExplorer<Neighborhood>::eval;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator solution vs neighbor comparator
|
||||
*/
|
||||
moSimpleHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
best=new Neighbor();
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator solution vs neighbor comparator
|
||||
*/
|
||||
moSimpleHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
best=new Neighbor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moSimpleHCexplorer(){
|
||||
delete current;
|
||||
delete best;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moSimpleHCexplorer() {
|
||||
delete current;
|
||||
delete best;
|
||||
}
|
||||
|
||||
/**
|
||||
* initParam: NOTHING TO DO
|
||||
*/
|
||||
virtual void initParam(EOT & solution){};
|
||||
/**
|
||||
* initParam: NOTHING TO DO
|
||||
*/
|
||||
virtual void initParam(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* updateParam: NOTHING TO DO
|
||||
*/
|
||||
virtual void updateParam(EOT & solution){};
|
||||
/**
|
||||
* updateParam: NOTHING TO DO
|
||||
*/
|
||||
virtual void updateParam(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution){};
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* Explore the neighborhood of a solution
|
||||
* @param _solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution){
|
||||
virtual void operator()(EOT & _solution) {
|
||||
|
||||
//est qu'on peut initializer
|
||||
//Test if _solution has a Neighbor
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
//est qu'on peut initializer
|
||||
//Test if _solution has a Neighbor
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
|
||||
//initialize the best neighbor
|
||||
(*best) = (*current);
|
||||
//initialize the best neighbor
|
||||
(*best) = (*current);
|
||||
|
||||
//test all others neighbors
|
||||
while (neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
//if we found a better neighbor, update the best
|
||||
if (neighborComparator((*best), (*current))) {
|
||||
(*best) = (*current);
|
||||
}
|
||||
}
|
||||
//test all others neighbors
|
||||
while (neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
//if we found a better neighbor, update the best
|
||||
if (neighborComparator((*best), (*current))) {
|
||||
(*best) = (*current);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -131,7 +131,7 @@ public:
|
|||
* @return true if an ameliorated neighbor was be found
|
||||
*/
|
||||
virtual bool isContinue(EOT & _solution) {
|
||||
return isAccept ;
|
||||
return isAccept ;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -139,10 +139,10 @@ public:
|
|||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
//move the solution
|
||||
(*best).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*best).fitness());
|
||||
//move the solution
|
||||
(*best).move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness((*best).fitness());
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -151,10 +151,10 @@ public:
|
|||
* @return true if the best neighbor ameliorate the fitness
|
||||
*/
|
||||
virtual bool accept(EOT & _solution) {
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
isAccept = solNeighborComparator(_solution, (*best)) ;
|
||||
}
|
||||
return isAccept;
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
isAccept = solNeighborComparator(_solution, (*best)) ;
|
||||
}
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -162,7 +162,7 @@ public:
|
|||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moSimpleHCexplorer";
|
||||
return "moSimpleHCexplorer";
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -54,91 +54,91 @@ public:
|
|||
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
|
||||
using moNeighborhoodExplorer<Neighborhood>::eval;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator solution vs neighbor comparator
|
||||
*/
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator solution vs neighbor comparator
|
||||
*/
|
||||
moSimpleHCneutralExplorer(Neighborhood& _neighborhood,
|
||||
moEval<Neighbor>& _eval,
|
||||
moNeighborComparator<Neighbor>& _neighborComparator,
|
||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator) :
|
||||
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
|
||||
neighborComparator(_neighborComparator),
|
||||
solNeighborComparator(_solNeighborComparator) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
moEval<Neighbor>& _eval,
|
||||
moNeighborComparator<Neighbor>& _neighborComparator,
|
||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator) :
|
||||
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
|
||||
neighborComparator(_neighborComparator),
|
||||
solNeighborComparator(_solNeighborComparator) {
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moSimpleHCneutralExplorer(){
|
||||
delete current;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moSimpleHCneutralExplorer() {
|
||||
delete current;
|
||||
}
|
||||
|
||||
/**
|
||||
* empty the vector of best solutions
|
||||
*/
|
||||
virtual void initParam(EOT & solution){
|
||||
// delete all the best solutions
|
||||
bestVector.clear();
|
||||
/**
|
||||
* empty the vector of best solutions
|
||||
*/
|
||||
virtual void initParam(EOT & solution) {
|
||||
// delete all the best solutions
|
||||
bestVector.clear();
|
||||
};
|
||||
|
||||
/**
|
||||
* empty the vector of best solutions
|
||||
*/
|
||||
virtual void updateParam(EOT & solution){
|
||||
// delete all the best solutions
|
||||
bestVector.clear();
|
||||
/**
|
||||
* empty the vector of best solutions
|
||||
*/
|
||||
virtual void updateParam(EOT & solution) {
|
||||
// delete all the best solutions
|
||||
bestVector.clear();
|
||||
};
|
||||
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution){};
|
||||
/**
|
||||
* terminate: NOTHING TO DO
|
||||
*/
|
||||
virtual void terminate(EOT & solution) {};
|
||||
|
||||
/**
|
||||
* Explore the neighborhood of a solution
|
||||
* @param _solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution){
|
||||
virtual void operator()(EOT & _solution) {
|
||||
|
||||
//Test if _solution has a Neighbor
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
//Test if _solution has a Neighbor
|
||||
if (neighborhood.hasNeighbor(_solution)) {
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, (*current));
|
||||
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, (*current));
|
||||
|
||||
//initialize the best neighbor
|
||||
bestVector.push_back(*current);
|
||||
//initialize the best neighbor
|
||||
bestVector.push_back(*current);
|
||||
|
||||
//test all others neighbors
|
||||
while (neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
|
||||
//if we found a better neighbor, update the best
|
||||
if (neighborComparator(bestVector[0], (*current))) {
|
||||
bestVector.clear();
|
||||
bestVector.push_back(*current);
|
||||
}
|
||||
else if (neighborComparator.equals((*current), bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution
|
||||
bestVector.push_back(*current);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
//test all others neighbors
|
||||
while (neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
|
||||
//if we found a better neighbor, update the best
|
||||
if (neighborComparator(bestVector[0], (*current))) {
|
||||
bestVector.clear();
|
||||
bestVector.push_back(*current);
|
||||
}
|
||||
else if (neighborComparator.equals((*current), bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution
|
||||
bestVector.push_back(*current);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//if _solution hasn't neighbor,
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* continue if a move is accepted
|
||||
|
|
@ -146,7 +146,7 @@ public:
|
|||
* @return true if an ameliorated neighbor was be found
|
||||
*/
|
||||
virtual bool isContinue(EOT & _solution) {
|
||||
return isAccept ;
|
||||
return isAccept ;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -154,14 +154,14 @@ public:
|
|||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
// choose randomly one of the best solutions
|
||||
unsigned int i = rng.random(bestVector.size());
|
||||
// choose randomly one of the best solutions
|
||||
unsigned int i = rng.random(bestVector.size());
|
||||
|
||||
//move the solution
|
||||
bestVector[i].move(_solution);
|
||||
//move the solution
|
||||
bestVector[i].move(_solution);
|
||||
|
||||
//update its fitness
|
||||
_solution.fitness(bestVector[i].fitness());
|
||||
//update its fitness
|
||||
_solution.fitness(bestVector[i].fitness());
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -170,9 +170,9 @@ public:
|
|||
* @return true if the best neighbor ameliorate the fitness
|
||||
*/
|
||||
virtual bool accept(EOT & _solution) {
|
||||
if(neighborhood.hasNeighbor(_solution))
|
||||
isAccept = solNeighborComparator(_solution, bestVector[0]) ;
|
||||
return isAccept;
|
||||
if (neighborhood.hasNeighbor(_solution))
|
||||
isAccept = solNeighborComparator(_solution, bestVector[0]) ;
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -54,81 +54,81 @@ public:
|
|||
typedef typename Neighborhood::EOT EOT ;
|
||||
typedef typename Neighborhood::Neighbor Neighbor ;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator a comparator between a solution and a neighbor
|
||||
* @param _tabuList the tabu list
|
||||
* @param _intensification the intensification box
|
||||
* @param _diversification the diversification box
|
||||
* @param _aspiration the aspiration criteria
|
||||
*/
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator a comparator between a solution and a neighbor
|
||||
* @param _tabuList the tabu list
|
||||
* @param _intensification the intensification box
|
||||
* @param _diversification the diversification box
|
||||
* @param _aspiration the aspiration criteria
|
||||
*/
|
||||
moTSExplorer(Neighborhood& _neighborhood,
|
||||
moEval<Neighbor>& _eval,
|
||||
moNeighborComparator<Neighbor>& _neighborComparator,
|
||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
||||
moTabuList<Neighbor> & _tabuList,
|
||||
moIntensification<Neighbor> & _intensification,
|
||||
moDiversification<Neighbor> & _diversification,
|
||||
moAspiration<Neighbor> & _aspiration
|
||||
) :
|
||||
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator),
|
||||
tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration)
|
||||
moEval<Neighbor>& _eval,
|
||||
moNeighborComparator<Neighbor>& _neighborComparator,
|
||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
||||
moTabuList<Neighbor> & _tabuList,
|
||||
moIntensification<Neighbor> & _intensification,
|
||||
moDiversification<Neighbor> & _diversification,
|
||||
moAspiration<Neighbor> & _aspiration
|
||||
) :
|
||||
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator),
|
||||
tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration)
|
||||
{
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
best=new Neighbor();
|
||||
isAccept = false;
|
||||
current=new Neighbor();
|
||||
best=new Neighbor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moTSExplorer(){
|
||||
delete current;
|
||||
delete best;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~moTSExplorer() {
|
||||
delete current;
|
||||
delete best;
|
||||
}
|
||||
|
||||
/**
|
||||
* init tabu list, intensification box, diversification box and aspiration criteria
|
||||
* @param _solution
|
||||
*/
|
||||
/**
|
||||
* init tabu list, intensification box, diversification box and aspiration criteria
|
||||
* @param _solution
|
||||
*/
|
||||
virtual void initParam(EOT& _solution)
|
||||
{
|
||||
tabuList.init(_solution);
|
||||
intensification.init(_solution);
|
||||
diversification.init(_solution);
|
||||
aspiration.init(_solution);
|
||||
bestSoFar=_solution;
|
||||
tabuList.init(_solution);
|
||||
intensification.init(_solution);
|
||||
diversification.init(_solution);
|
||||
aspiration.init(_solution);
|
||||
bestSoFar=_solution;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* update params of tabu list, intensification box, diversification box and aspiration criteria
|
||||
* @param _solution
|
||||
*/
|
||||
/**
|
||||
* update params of tabu list, intensification box, diversification box and aspiration criteria
|
||||
* @param _solution
|
||||
*/
|
||||
virtual void updateParam(EOT& _solution)
|
||||
{
|
||||
if ((*this).moveApplied()){
|
||||
tabuList.add(_solution, *best);
|
||||
intensification.add(_solution, *best);
|
||||
diversification.add(_solution, *best);
|
||||
if(_solution.fitness() > bestSoFar.fitness())
|
||||
bestSoFar = _solution;
|
||||
}
|
||||
tabuList.update(_solution, *best);
|
||||
intensification.update(_solution, *best);
|
||||
diversification.update(_solution, *best);
|
||||
aspiration.update(_solution, *best);
|
||||
if ((*this).moveApplied()) {
|
||||
tabuList.add(_solution, *best);
|
||||
intensification.add(_solution, *best);
|
||||
diversification.add(_solution, *best);
|
||||
if (_solution.fitness() > bestSoFar.fitness())
|
||||
bestSoFar = _solution;
|
||||
}
|
||||
tabuList.update(_solution, *best);
|
||||
intensification.update(_solution, *best);
|
||||
diversification.update(_solution, *best);
|
||||
aspiration.update(_solution, *best);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* terminate : _solution becomes the best so far
|
||||
*/
|
||||
virtual void terminate(EOT & _solution){
|
||||
_solution= bestSoFar;
|
||||
/**
|
||||
* terminate : _solution becomes the best so far
|
||||
*/
|
||||
virtual void terminate(EOT & _solution) {
|
||||
_solution= bestSoFar;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -138,56 +138,56 @@ public:
|
|||
*/
|
||||
virtual void operator()(EOT & _solution)
|
||||
{
|
||||
bool found=false;
|
||||
intensification(_solution);
|
||||
diversification(_solution);
|
||||
if(neighborhood.hasNeighbor(_solution))
|
||||
{
|
||||
//init the current neighbor
|
||||
neighborhood.init(_solution, *current);
|
||||
//eval the current neighbor
|
||||
eval(_solution, *current);
|
||||
bool found=false;
|
||||
intensification(_solution);
|
||||
diversification(_solution);
|
||||
if (neighborhood.hasNeighbor(_solution))
|
||||
{
|
||||
//init the current neighbor
|
||||
neighborhood.init(_solution, *current);
|
||||
//eval the current neighbor
|
||||
eval(_solution, *current);
|
||||
|
||||
//Find the first non-tabu element
|
||||
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ){
|
||||
// set best
|
||||
(*best)= (*current);
|
||||
found=true;
|
||||
}
|
||||
while(neighborhood.cont(_solution) && !found){
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
//Find the first non-tabu element
|
||||
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) {
|
||||
// set best
|
||||
(*best)= (*current);
|
||||
found=true;
|
||||
}
|
||||
while (neighborhood.cont(_solution) && !found) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
|
||||
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ){
|
||||
// set best
|
||||
(*best)=(*current);
|
||||
found=true;
|
||||
}
|
||||
}
|
||||
//Explore the neighborhood
|
||||
if(found){
|
||||
isAccept=true;
|
||||
while(neighborhood.cont(_solution)){
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
//check if the current is better than the best and is not tabu or if it is aspirat (by the aspiration criteria of course)
|
||||
if ( (!tabuList.check(_solution, *current) || aspiration(_solution, (*current))) && neighborComparator((*best),(*current))){
|
||||
// set best
|
||||
(*best)=(*current);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
isAccept=false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
isAccept=false;
|
||||
}
|
||||
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) {
|
||||
// set best
|
||||
(*best)=(*current);
|
||||
found=true;
|
||||
}
|
||||
}
|
||||
//Explore the neighborhood
|
||||
if (found) {
|
||||
isAccept=true;
|
||||
while (neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, (*current));
|
||||
//eval
|
||||
eval(_solution, (*current));
|
||||
//check if the current is better than the best and is not tabu or if it is aspirat (by the aspiration criteria of course)
|
||||
if ( (!tabuList.check(_solution, *current) || aspiration(_solution, (*current))) && neighborComparator((*best),(*current))) {
|
||||
// set best
|
||||
(*best)=(*current);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
isAccept=false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -196,8 +196,8 @@ public:
|
|||
* @param _solution the solution
|
||||
* @return true
|
||||
*/
|
||||
virtual bool isContinue(EOT & _solution){
|
||||
return true;
|
||||
virtual bool isContinue(EOT & _solution) {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -206,10 +206,10 @@ public:
|
|||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
//move the solution
|
||||
best->move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness(best->fitness());
|
||||
//move the solution
|
||||
best->move(_solution);
|
||||
//update its fitness
|
||||
_solution.fitness(best->fitness());
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -218,8 +218,8 @@ public:
|
|||
* @param _solution the solution
|
||||
* @return true if the best neighbor ameliorate the fitness
|
||||
*/
|
||||
virtual bool accept(EOT & _solution){
|
||||
return isAccept;
|
||||
virtual bool accept(EOT & _solution) {
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -236,11 +236,11 @@ protected:
|
|||
// Tabu components
|
||||
moTabuList<Neighbor> & tabuList;
|
||||
moIntensification<Neighbor> & intensification;
|
||||
moDiversification<Neighbor> & diversification;
|
||||
moAspiration<Neighbor> & aspiration;
|
||||
moDiversification<Neighbor> & diversification;
|
||||
moAspiration<Neighbor> & aspiration;
|
||||
|
||||
//Current and best neighbor
|
||||
Neighbor* best;
|
||||
//Current and best neighbor
|
||||
Neighbor* best;
|
||||
Neighbor* current;
|
||||
|
||||
//Best so far Solution
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue