From b97a685fd0d2fda3a246c89627b48206d70641c5 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Thu, 26 Aug 2010 09:16:29 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1915 331e1502-861f-0410-8da2-ba01fb791d7f --- .../paradiseo-mo/src/explorer/moVNSexplorer.h | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h index 1887d1fe0..f60ceb5f4 100644 --- a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h @@ -31,22 +31,18 @@ Contact: paradiseo-help@lists.gforge.inria.fr #define _moVNSexplorer_h #include -#include -#include +#include +#include /** * Explorer for Variiable Neighborhood Search */ -template< class EOT > -class moVNSexplorer : public moNeighborhoodExplorer< moNeighborhood< moNeighbor > > +template< class Neighbor> +class moVNSexplorer : public moNeighborhoodExplorer< Neighbor > { public: - typedef typename EOT::Fitness Fitness ; - typedef moNeighbor Neighbor ; - typedef moNeighborhood Neighborhood ; - using moNeighborhoodExplorer::neighborhood; - using moNeighborhoodExplorer::eval; + typedef typename Neighbor::EOT EOT; /** * Constructor @@ -55,8 +51,11 @@ public: * @param _neighborComparator a neighbor comparator * @param _solNeighborComparator solution vs neighbor comparator */ - moVNSexplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { - } + moVNSexplorer( + moVariableNeighborhoodSelection & _selection, + moAcceptanceCriterion& _acceptCrit): + moNeighborhoodExplorer(), selection(_selection), shake(NULL), ls(NULL), acceptCrit(_acceptCrit), stop(false) + {} /** * Destructor @@ -67,23 +66,37 @@ public: /** * initParam: NOTHING TO DO */ - virtual void initParam(EOT & solution) {}; + virtual void initParam(EOT & _solution) { + _selection.init(_solution, *shake, *ls); + }; /** * updateParam: NOTHING TO DO */ - virtual void updateParam(EOT & solution) {}; + virtual void updateParam(EOT & _solution) { + if ((*this).moveApplied()) { + _selection.init(_solution, *shake, *ls); + } + else if (_selection.cont(_solution, *shake, *ls)){ + _selection.next(_solution, *shake, *ls); + } + else + stop=true; + }; /** * terminate: NOTHING TO DO */ - virtual void terminate(EOT & solution) {}; + virtual void terminate(EOT & _solution) {}; /** * Explore the neighborhood of a solution * @param _solution */ virtual void operator()(EOT & _solution) { + current=_solution; + (*shake)(current); + (*ls)(current); }; /** @@ -92,7 +105,7 @@ public: * @return true if an ameliorated neighbor was be found */ virtual bool isContinue(EOT & _solution) { - return isAccept ; + return !stop; }; /** @@ -100,10 +113,7 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - //move the solution - (*best).move(_solution); - //update its fitness - _solution.fitness((*best).fitness()); + _solution=current; }; /** @@ -112,6 +122,7 @@ public: * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { + return acceptCrit(_solution, current); }; /** @@ -123,9 +134,13 @@ public: } private: - // comparator betwenn solution and neighbor or between neighbors - moNeighborComparator& neighborComparator; - moSolNeighborComparator& solNeighborComparator; + moVariableNeighborhoodSelection& selection; + eoMonOp* ls; + eoMonOp* shake; + moAcceptanceCriterion& acceptCrit; + + bool stop; + EOT current; };