diff --git a/trunk/paradiseo-mo/src/explorer/moFirstImprHCexplorer.h b/trunk/paradiseo-mo/src/explorer/moFirstImprHCexplorer.h index d51aff6a3..4689ca9f0 100644 --- a/trunk/paradiseo-mo/src/explorer/moFirstImprHCexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moFirstImprHCexplorer.h @@ -53,6 +53,7 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; using moNeighborhoodExplorer::currentNeighbor; + using moNeighborhoodExplorer::selectedNeighbor; /** * Constructor @@ -110,6 +111,9 @@ public: //eval eval(_solution, currentNeighbor); } + + // the selected neighbor + selectedNeighbor = currentNeighbor; } else { //if _solution hasn't neighbor, @@ -126,17 +130,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 ameliorated neighbor was found * @param _solution the solution @@ -144,7 +137,7 @@ public: */ virtual bool accept(EOT & _solution) { if (neighborhood.hasNeighbor(_solution)) { - isAccept = solNeighborComparator(_solution, currentNeighbor) ; + isAccept = solNeighborComparator(_solution, selectedNeighbor) ; } return isAccept; }; @@ -154,9 +147,6 @@ private: moNeighborComparator& neighborComparator; moSolNeighborComparator& solNeighborComparator; - //Pointer on the best and the current neighbor - // Neighbor* current; - // true if the move is accepted bool isAccept ; }; diff --git a/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h b/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h index 2b6064585..3123c4914 100644 --- a/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h @@ -58,7 +58,7 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; - using moNeighborhoodExplorer::currentNeighbor; + using moNeighborhoodExplorer::selectedNeighbor; /** * Constructor @@ -112,10 +112,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); } else { //if _solution hasn't neighbor, @@ -132,17 +132,6 @@ public: return (step < nbStep) ; }; - /** - * 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 ameliorated neighbor was found * @param _solution the solution @@ -151,18 +140,18 @@ public: virtual bool accept(EOT & _solution) { double alpha=0.0; if (neighborhood.hasNeighbor(_solution)) { - if (solNeighborComparator(_solution, currentNeighbor)) + if (solNeighborComparator(_solution, selectedNeighbor)) isAccept = true; else { if (_solution.fitness() != 0) { - if ( (double)currentNeighbor.fitness() < (double)_solution.fitness()) // maximizing - alpha = (double) currentNeighbor.fitness() / (double) _solution.fitness(); + if ( (double)selectedNeighbor.fitness() < (double)_solution.fitness()) // maximizing + alpha = (double) selectedNeighbor.fitness() / (double) _solution.fitness(); else //minimizing - alpha = (double) _solution.fitness() / (double) currentNeighbor.fitness(); + alpha = (double) _solution.fitness() / (double) selectedNeighbor.fitness(); isAccept = (rng.uniform() < alpha) ; } else { - if ( (double)currentNeighbor.fitness() < (double)_solution.fitness()) // maximizing + if ( (double) selectedNeighbor.fitness() < (double) _solution.fitness()) // maximizing isAccept = true; else isAccept = false; diff --git a/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h b/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h index c9be41188..8b4113b7a 100644 --- a/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h @@ -51,8 +51,11 @@ * one neighbor is selected * a comparason with the solution is made to acccept or not this new neighbor * - * the current neighbor is the neighbor under consideration during the search - * + * The current neighbor (currentNeigbor) is the neighbor under consideration during the search (in operator()(EOT &)) + * + * The selected neighbor (selectedNeighbor) is the neighbor selected in method operator()(EOT &). + * If this neighbor is accepted, then the solution is moved on this neighbor (in move(EOT &)) + * */ template< class Neighbor > class moNeighborhoodExplorer : public eoUF @@ -91,10 +94,18 @@ public: virtual bool isContinue(EOT& _solution) = 0 ; /** - * Move a solution + * Move a solution on the selected neighbor + * This method can be re-defined according to the metaheuritic + * * @param _solution the solution to explore */ - virtual void move(EOT& _solution) = 0 ; + virtual void move(EOT& _solution) { + // move the solution + selectedNeighbor.move(_solution); + + // update the fitness + _solution.fitness(selectedNeighbor.fitness()); + } /** * Test if a solution is accepted @@ -133,6 +144,14 @@ public: return currentNeighbor; } + /** + * Getter of the selected neighbor + * @return selected neighbor + */ + Neighbor & getSelectedNeighbor() { + return selectedNeighbor; + } + protected: // default class for the empty constructor moDummyNeighborhood dummyNeighborhood; @@ -151,6 +170,9 @@ protected: // the current neighbor of the exploration : common features of algorithm Neighbor currentNeighbor; + + // the selected neighbor after the exploration of the neighborhood + Neighbor selectedNeighbor; }; #endif diff --git a/trunk/paradiseo-mo/src/explorer/moSimpleHCexplorer.h b/trunk/paradiseo-mo/src/explorer/moSimpleHCexplorer.h index edc319726..573881d2f 100644 --- a/trunk/paradiseo-mo/src/explorer/moSimpleHCexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moSimpleHCexplorer.h @@ -53,6 +53,7 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; using moNeighborhoodExplorer::currentNeighbor; + using moNeighborhoodExplorer::selectedNeighbor; /** * Constructor @@ -103,7 +104,7 @@ public: eval(_solution, currentNeighbor); //initialize the best neighbor - best = currentNeighbor; + selectedNeighbor = currentNeighbor; //test all others neighbors while (neighborhood.cont(_solution)) { @@ -112,8 +113,8 @@ public: //eval eval(_solution, currentNeighbor); //if we found a better neighbor, update the best - if (neighborComparator(best, currentNeighbor)) { - best = currentNeighbor; + if (neighborComparator(selectedNeighbor, currentNeighbor)) { + selectedNeighbor = currentNeighbor; } } @@ -133,19 +134,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 - best.move(_solution); - - //update its fitness - _solution.fitness(best.fitness()); - - }; - /** * accept test if an amelirated neighbor was be found * @param _solution the solution @@ -153,7 +141,7 @@ public: */ virtual bool accept(EOT & _solution) { if (neighborhood.hasNeighbor(_solution)) { - isAccept = solNeighborComparator(_solution, best) ; + isAccept = solNeighborComparator(_solution, selectedNeighbor) ; } return isAccept; }; @@ -171,10 +159,6 @@ private: moNeighborComparator& neighborComparator; moSolNeighborComparator& solNeighborComparator; - // the best and the current neighbor - Neighbor best; - // Neighbor current; - // true if the move is accepted bool isAccept ; };