Add the notion of currentNeighbor in the moTSExplorer

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2544 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
verel 2011-12-06 13:48:11 +00:00
commit 6e73110a91
3 changed files with 41 additions and 47 deletions

View file

@ -114,18 +114,18 @@ public:
*/
virtual void operator()(EOT & _solution) {
//copy the solution to perform new local search
current=_solution;
currentSol=_solution;
//perturb solution exept at the first iteration
if (!firstIteration) {
perturb(current);
perturb(currentSol);
}
else
firstIteration=false;
//apply the local search on the copy
ls(current);
ls(currentSol);
// std::cout << "(solution)\t" << current << std::endl;
@ -145,7 +145,7 @@ public:
* @param _solution the solution
*/
virtual void move(EOT & _solution) {
_solution=current;
_solution=currentSol;
};
/**
@ -154,7 +154,7 @@ public:
* @return true if acceptance criteria is verified
*/
virtual bool accept(EOT & _solution) {
return acceptCrit(_solution, current);
return acceptCrit(_solution, currentSol);
};
/**
@ -168,7 +168,7 @@ public:
private:
//Usefull to use the momory of tabuSearch
Neighbor emptyNeighbor;
EOT current;
EOT currentSol;
moLocalSearch<Neighbor>& ls;
moPerturbation<Neighbor> & perturb;
moAcceptanceCriterion<Neighbor>& acceptCrit;

View file

@ -55,6 +55,7 @@ public:
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
/**
* Constructor
@ -71,14 +72,12 @@ public:
neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator) {
isAccept = false;
current=new Neighbor();
}
/**
* Destructor
*/
~moRandomBestHCexplorer() {
delete current;
}
/**
@ -114,29 +113,29 @@ public:
//Test if _solution has a Neighbor
if (neighborhood.hasNeighbor(_solution)) {
//init the first neighbor
neighborhood.init(_solution, (*current));
neighborhood.init(_solution, currentNeighbor);
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
eval(_solution, currentNeighbor);
//initialize the best neighbor
bestVector.push_back(*current);
bestVector.push_back(currentNeighbor);
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, (*current));
eval(_solution, currentNeighbor);
//if we found a better neighbor, update the best
if (neighborComparator(bestVector[0], (*current))) {
if (neighborComparator(bestVector[0], currentNeighbor)) {
bestVector.clear();
bestVector.push_back(*current);
bestVector.push_back(currentNeighbor);
}
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 (neighborComparator.equals(currentNeighbor, bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution
bestVector.push_back(currentNeighbor);
}
}
else {
@ -187,8 +186,6 @@ protected:
// the best solutions in the neighborhood
std::vector<Neighbor> bestVector;
//Pointer on the current neighbor
Neighbor* current;
// true if the move is accepted
bool isAccept ;

View file

@ -53,6 +53,8 @@ public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
/**
* Constructor
* @param _neighborhood the neighborhood
@ -77,16 +79,12 @@ public:
tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration)
{
isAccept = false;
current=new Neighbor();
best=new Neighbor();
}
/**
* Destructor
*/
~moTSexplorer() {
delete current;
delete best;
}
/**
@ -110,16 +108,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, 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);
tabuList.update(_solution, best);
intensification.update(_solution, best);
diversification.update(_solution, best);
aspiration.update(_solution, best);
};
@ -143,25 +141,25 @@ public:
if (neighborhood.hasNeighbor(_solution))
{
//init the current neighbor
neighborhood.init(_solution, *current);
neighborhood.init(_solution, currentNeighbor);
//eval the current neighbor
eval(_solution, *current);
eval(_solution, currentNeighbor);
//Find the first non-tabu element
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) {
if ( (!tabuList.check(_solution, currentNeighbor)) || aspiration(_solution, currentNeighbor) ) {
// set best
(*best)= (*current);
best = currentNeighbor;
found=true;
}
while (neighborhood.cont(_solution) && !found) {
//next neighbor
neighborhood.next(_solution, (*current));
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, (*current));
eval(_solution, currentNeighbor);
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) {
if ( (!tabuList.check(_solution, currentNeighbor)) || aspiration(_solution, currentNeighbor) ) {
// set best
(*best)=(*current);
best = currentNeighbor;
found=true;
}
}
@ -170,13 +168,13 @@ public:
isAccept=true;
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, (*current));
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, *current) || aspiration(_solution, (*current))) && neighborComparator((*best),(*current))) {
if ( (!tabuList.check(_solution, currentNeighbor) || aspiration(_solution, currentNeighbor)) && neighborComparator(best, currentNeighbor)) {
// set best
(*best)=(*current);
best = currentNeighbor;
}
}
}
@ -207,9 +205,9 @@ public:
*/
virtual void move(EOT & _solution) {
//move the solution
best->move(_solution);
best.move(_solution);
//update its fitness
_solution.fitness(best->fitness());
_solution.fitness(best.fitness());
};
@ -246,9 +244,8 @@ protected:
moDiversification<Neighbor> & diversification;
moAspiration<Neighbor> & aspiration;
//Current and best neighbor
Neighbor* best;
Neighbor* current;
// Best neighbor
Neighbor best;
//Best so far Solution
EOT bestSoFar;