Use the variable selectedNeighbor in moTSexplorer and moRandomWalkExplorer

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2561 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
verel 2011-12-10 13:08:07 +00:00
commit 856bec93f9
4 changed files with 19 additions and 43 deletions

View file

@ -119,7 +119,6 @@ public:
//perturb solution exept at the first iteration
if (!firstIteration) {
perturb(currentSol);
}
else
firstIteration=false;

View file

@ -58,6 +58,7 @@ public:
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
@ -108,10 +109,10 @@ public:
//Test if _solution has a Neighbor
if (neighborhood.hasNeighbor(_solution)) {
//init the first neighbor
neighborhood.init(_solution, currentNeighbor);
neighborhood.init(_solution, selectedNeighbor);
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, currentNeighbor);
eval(_solution, selectedNeighbor);
isAccept = true;
}
@ -130,17 +131,6 @@ public:
return isAccept ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
currentNeighbor.move(_solution);
//update its fitness
_solution.fitness(currentNeighbor.fitness());
};
/**
* accept test if an amelirated neighbor was be found
* @param _solution the solution

View file

@ -154,7 +154,6 @@ public:
isAccept = (rng.uniform() < alpha) ;
}
}
isAccept = true;
return isAccept;
};

View file

@ -54,6 +54,7 @@ public:
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
@ -108,16 +109,16 @@ public:
virtual void updateParam(EOT& _solution)
{
if ((*this).moveApplied()) {
tabuList.add(_solution, best);
intensification.add(_solution, best);
diversification.add(_solution, best);
tabuList.add(_solution, selectedNeighbor);
intensification.add(_solution, selectedNeighbor);
diversification.add(_solution, selectedNeighbor);
if (_solution.fitness() > bestSoFar.fitness())
bestSoFar = _solution;
}
tabuList.update(_solution, best);
intensification.update(_solution, best);
diversification.update(_solution, best);
aspiration.update(_solution, best);
tabuList.update(_solution, selectedNeighbor);
intensification.update(_solution, selectedNeighbor);
diversification.update(_solution, selectedNeighbor);
aspiration.update(_solution, selectedNeighbor);
};
@ -147,8 +148,8 @@ public:
//Find the first non-tabu element
if ( (!tabuList.check(_solution, currentNeighbor)) || aspiration(_solution, currentNeighbor) ) {
// set best
best = currentNeighbor;
// set selectedNeighbor
selectedNeighbor = currentNeighbor;
found=true;
}
while (neighborhood.cont(_solution) && !found) {
@ -158,8 +159,8 @@ public:
eval(_solution, currentNeighbor);
if ( (!tabuList.check(_solution, currentNeighbor)) || aspiration(_solution, currentNeighbor) ) {
// set best
best = currentNeighbor;
// set selectedNeighbor
selectedNeighbor = currentNeighbor;
found=true;
}
}
@ -172,9 +173,9 @@ public:
//eval
eval(_solution, currentNeighbor);
//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, currentNeighbor) || aspiration(_solution, currentNeighbor)) && neighborComparator(best, currentNeighbor)) {
// set best
best = currentNeighbor;
if ( (!tabuList.check(_solution, currentNeighbor) || aspiration(_solution, currentNeighbor)) && neighborComparator(selectedNeighbor, currentNeighbor)) {
// set selectedNeighbor
selectedNeighbor = currentNeighbor;
}
}
}
@ -198,19 +199,6 @@ public:
return true;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
best.move(_solution);
//update its fitness
_solution.fitness(best.fitness());
};
/**
* accept test if an ameliorated neighbor was found
* @param _solution the solution
@ -245,7 +233,7 @@ protected:
moAspiration<Neighbor> & aspiration;
// Best neighbor
Neighbor best;
// Neighbor best;
//Best so far Solution
EOT bestSoFar;