From e6baefd199b868b4b11c4671dab8ddf2e36ef42d Mon Sep 17 00:00:00 2001 From: verel Date: Tue, 6 Dec 2011 13:29:01 +0000 Subject: [PATCH] Add the notion of currentNeighbor in the moMetropolisHastingexplorer git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2541 331e1502-861f-0410-8da2-ba01fb791d7f --- .../explorer/moMetropolisHastingExplorer.h | 24 ++++++++----------- .../src/explorer/moNeighborhoodExplorer.h | 10 +++++++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h b/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h index 49bb78fdd..47529b2a5 100644 --- a/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h @@ -58,6 +58,7 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; + using moNeighborhoodExplorer::currentNeighbor; /** * Constructor @@ -69,7 +70,6 @@ public: */ moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer(_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; } @@ -79,7 +79,6 @@ public: * Destructor */ ~moMetropolisHastingExplorer() { - delete current; } /** @@ -113,10 +112,10 @@ 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); } else { //if _solution hasn't neighbor, @@ -139,9 +138,9 @@ public: */ virtual void move(EOT & _solution) { //move the solution - (*current).move(_solution); + currentNeighbor.move(_solution); //update its fitness - _solution.fitness((*current).fitness()); + _solution.fitness(currentNeighbor.fitness()); }; /** @@ -152,18 +151,18 @@ public: virtual bool accept(EOT & _solution) { double alpha=0.0; if (neighborhood.hasNeighbor(_solution)) { - if (solNeighborComparator(_solution, *current)) + if (solNeighborComparator(_solution, currentNeighbor) isAccept = true; else { if (_solution.fitness() != 0) { - if ( (double)current->fitness() < (double)_solution.fitness()) // maximizing - alpha = (double) current->fitness() / (double) _solution.fitness(); + if ( (double)currentNeighbor.fitness() < (double)_solution.fitness()) // maximizing + alpha = (double) currentNeighbor.fitness() / (double) _solution.fitness(); else //minimizing - alpha = (double) _solution.fitness() / (double) current->fitness(); + alpha = (double) _solution.fitness() / (double) currentNeighbor.fitness(); isAccept = (rng.uniform() < alpha) ; } else { - if ( (double)current->fitness() < (double)_solution.fitness()) // maximizing + if ( (double)currentNeighbor.fitness() < (double)_solution.fitness()) // maximizing isAccept = true; else isAccept = false; @@ -184,9 +183,6 @@ private: // maximum number of steps to do unsigned int nbStep; - //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/moNeighborhoodExplorer.h b/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h index 334210a53..20cba925a 100644 --- a/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h @@ -44,7 +44,15 @@ #include /** - * Explore the neighborhood + * Explore the neighborhood according to the local search algorithm + * + * During this exploration, + * the parameters are updated + * 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 + * */ template< class Neighbor > class moNeighborhoodExplorer : public eoUF