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:
parent
9cf796d2e0
commit
6e73110a91
3 changed files with 41 additions and 47 deletions
|
|
@ -114,18 +114,18 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void operator()(EOT & _solution) {
|
virtual void operator()(EOT & _solution) {
|
||||||
//copy the solution to perform new local search
|
//copy the solution to perform new local search
|
||||||
current=_solution;
|
currentSol=_solution;
|
||||||
|
|
||||||
//perturb solution exept at the first iteration
|
//perturb solution exept at the first iteration
|
||||||
if (!firstIteration) {
|
if (!firstIteration) {
|
||||||
perturb(current);
|
perturb(currentSol);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
firstIteration=false;
|
firstIteration=false;
|
||||||
|
|
||||||
//apply the local search on the copy
|
//apply the local search on the copy
|
||||||
ls(current);
|
ls(currentSol);
|
||||||
|
|
||||||
// std::cout << "(solution)\t" << current << std::endl;
|
// std::cout << "(solution)\t" << current << std::endl;
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ public:
|
||||||
* @param _solution the solution
|
* @param _solution the solution
|
||||||
*/
|
*/
|
||||||
virtual void move(EOT & _solution) {
|
virtual void move(EOT & _solution) {
|
||||||
_solution=current;
|
_solution=currentSol;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -154,7 +154,7 @@ public:
|
||||||
* @return true if acceptance criteria is verified
|
* @return true if acceptance criteria is verified
|
||||||
*/
|
*/
|
||||||
virtual bool accept(EOT & _solution) {
|
virtual bool accept(EOT & _solution) {
|
||||||
return acceptCrit(_solution, current);
|
return acceptCrit(_solution, currentSol);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -168,7 +168,7 @@ public:
|
||||||
private:
|
private:
|
||||||
//Usefull to use the momory of tabuSearch
|
//Usefull to use the momory of tabuSearch
|
||||||
Neighbor emptyNeighbor;
|
Neighbor emptyNeighbor;
|
||||||
EOT current;
|
EOT currentSol;
|
||||||
moLocalSearch<Neighbor>& ls;
|
moLocalSearch<Neighbor>& ls;
|
||||||
moPerturbation<Neighbor> & perturb;
|
moPerturbation<Neighbor> & perturb;
|
||||||
moAcceptanceCriterion<Neighbor>& acceptCrit;
|
moAcceptanceCriterion<Neighbor>& acceptCrit;
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ public:
|
||||||
|
|
||||||
using moNeighborhoodExplorer<Neighbor>::neighborhood;
|
using moNeighborhoodExplorer<Neighbor>::neighborhood;
|
||||||
using moNeighborhoodExplorer<Neighbor>::eval;
|
using moNeighborhoodExplorer<Neighbor>::eval;
|
||||||
|
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
|
@ -71,14 +72,12 @@ public:
|
||||||
neighborComparator(_neighborComparator),
|
neighborComparator(_neighborComparator),
|
||||||
solNeighborComparator(_solNeighborComparator) {
|
solNeighborComparator(_solNeighborComparator) {
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
current=new Neighbor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
~moRandomBestHCexplorer() {
|
~moRandomBestHCexplorer() {
|
||||||
delete current;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -114,29 +113,29 @@ public:
|
||||||
//Test if _solution has a Neighbor
|
//Test if _solution has a Neighbor
|
||||||
if (neighborhood.hasNeighbor(_solution)) {
|
if (neighborhood.hasNeighbor(_solution)) {
|
||||||
//init the first neighbor
|
//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 the _solution moved with the neighbor and stock the result in the neighbor
|
||||||
eval(_solution, (*current));
|
eval(_solution, currentNeighbor);
|
||||||
|
|
||||||
//initialize the best neighbor
|
//initialize the best neighbor
|
||||||
bestVector.push_back(*current);
|
bestVector.push_back(currentNeighbor);
|
||||||
|
|
||||||
//test all others neighbors
|
//test all others neighbors
|
||||||
while (neighborhood.cont(_solution)) {
|
while (neighborhood.cont(_solution)) {
|
||||||
//next neighbor
|
//next neighbor
|
||||||
neighborhood.next(_solution, (*current));
|
neighborhood.next(_solution, currentNeighbor);
|
||||||
|
|
||||||
//eval
|
//eval
|
||||||
eval(_solution, (*current));
|
eval(_solution, currentNeighbor);
|
||||||
|
|
||||||
//if we found a better neighbor, update the best
|
//if we found a better neighbor, update the best
|
||||||
if (neighborComparator(bestVector[0], (*current))) {
|
if (neighborComparator(bestVector[0], currentNeighbor)) {
|
||||||
bestVector.clear();
|
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
|
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(*current);
|
bestVector.push_back(currentNeighbor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -187,8 +186,6 @@ protected:
|
||||||
|
|
||||||
// the best solutions in the neighborhood
|
// the best solutions in the neighborhood
|
||||||
std::vector<Neighbor> bestVector;
|
std::vector<Neighbor> bestVector;
|
||||||
//Pointer on the current neighbor
|
|
||||||
Neighbor* current;
|
|
||||||
|
|
||||||
// true if the move is accepted
|
// true if the move is accepted
|
||||||
bool isAccept ;
|
bool isAccept ;
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@ public:
|
||||||
typedef typename Neighbor::EOT EOT ;
|
typedef typename Neighbor::EOT EOT ;
|
||||||
typedef moNeighborhood<Neighbor> Neighborhood ;
|
typedef moNeighborhood<Neighbor> Neighborhood ;
|
||||||
|
|
||||||
|
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
|
|
@ -77,16 +79,12 @@ public:
|
||||||
tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration)
|
tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration)
|
||||||
{
|
{
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
current=new Neighbor();
|
|
||||||
best=new Neighbor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
~moTSexplorer() {
|
~moTSexplorer() {
|
||||||
delete current;
|
|
||||||
delete best;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,16 +108,16 @@ public:
|
||||||
virtual void updateParam(EOT& _solution)
|
virtual void updateParam(EOT& _solution)
|
||||||
{
|
{
|
||||||
if ((*this).moveApplied()) {
|
if ((*this).moveApplied()) {
|
||||||
tabuList.add(_solution, *best);
|
tabuList.add(_solution, best);
|
||||||
intensification.add(_solution, *best);
|
intensification.add(_solution, best);
|
||||||
diversification.add(_solution, *best);
|
diversification.add(_solution, best);
|
||||||
if (_solution.fitness() > bestSoFar.fitness())
|
if (_solution.fitness() > bestSoFar.fitness())
|
||||||
bestSoFar = _solution;
|
bestSoFar = _solution;
|
||||||
}
|
}
|
||||||
tabuList.update(_solution, *best);
|
tabuList.update(_solution, best);
|
||||||
intensification.update(_solution, *best);
|
intensification.update(_solution, best);
|
||||||
diversification.update(_solution, *best);
|
diversification.update(_solution, best);
|
||||||
aspiration.update(_solution, *best);
|
aspiration.update(_solution, best);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -143,25 +141,25 @@ public:
|
||||||
if (neighborhood.hasNeighbor(_solution))
|
if (neighborhood.hasNeighbor(_solution))
|
||||||
{
|
{
|
||||||
//init the current neighbor
|
//init the current neighbor
|
||||||
neighborhood.init(_solution, *current);
|
neighborhood.init(_solution, currentNeighbor);
|
||||||
//eval the current neighbor
|
//eval the current neighbor
|
||||||
eval(_solution, *current);
|
eval(_solution, currentNeighbor);
|
||||||
|
|
||||||
//Find the first non-tabu element
|
//Find the first non-tabu element
|
||||||
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) {
|
if ( (!tabuList.check(_solution, currentNeighbor)) || aspiration(_solution, currentNeighbor) ) {
|
||||||
// set best
|
// set best
|
||||||
(*best)= (*current);
|
best = currentNeighbor;
|
||||||
found=true;
|
found=true;
|
||||||
}
|
}
|
||||||
while (neighborhood.cont(_solution) && !found) {
|
while (neighborhood.cont(_solution) && !found) {
|
||||||
//next neighbor
|
//next neighbor
|
||||||
neighborhood.next(_solution, (*current));
|
neighborhood.next(_solution, currentNeighbor);
|
||||||
//eval
|
//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
|
// set best
|
||||||
(*best)=(*current);
|
best = currentNeighbor;
|
||||||
found=true;
|
found=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -170,13 +168,13 @@ public:
|
||||||
isAccept=true;
|
isAccept=true;
|
||||||
while (neighborhood.cont(_solution)) {
|
while (neighborhood.cont(_solution)) {
|
||||||
//next neighbor
|
//next neighbor
|
||||||
neighborhood.next(_solution, (*current));
|
neighborhood.next(_solution, currentNeighbor);
|
||||||
//eval
|
//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)
|
//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
|
// set best
|
||||||
(*best)=(*current);
|
best = currentNeighbor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -207,9 +205,9 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void move(EOT & _solution) {
|
virtual void move(EOT & _solution) {
|
||||||
//move the solution
|
//move the solution
|
||||||
best->move(_solution);
|
best.move(_solution);
|
||||||
//update its fitness
|
//update its fitness
|
||||||
_solution.fitness(best->fitness());
|
_solution.fitness(best.fitness());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -246,9 +244,8 @@ protected:
|
||||||
moDiversification<Neighbor> & diversification;
|
moDiversification<Neighbor> & diversification;
|
||||||
moAspiration<Neighbor> & aspiration;
|
moAspiration<Neighbor> & aspiration;
|
||||||
|
|
||||||
//Current and best neighbor
|
// Best neighbor
|
||||||
Neighbor* best;
|
Neighbor best;
|
||||||
Neighbor* current;
|
|
||||||
|
|
||||||
//Best so far Solution
|
//Best so far Solution
|
||||||
EOT bestSoFar;
|
EOT bestSoFar;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue