From 5a992685e2e12bf6f28c798310b102876cfb307c Mon Sep 17 00:00:00 2001 From: verel Date: Sun, 29 Aug 2010 14:16:23 +0000 Subject: [PATCH] Ajout des commentaires autour de VNS git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1930 331e1502-861f-0410-8da2-ba01fb791d7f --- .../paradiseo-mo/src/explorer/moVNSexplorer.h | 31 ++----- .../moBackwardVectorVNSelection.h | 37 +++++--- .../neighborhood/moForwardVectorVNSelection.h | 42 +++++---- .../src/neighborhood/moRndVectorVNSelection.h | 40 ++++++-- .../moVariableNeighborhoodSelection.h | 91 ++++++++++--------- .../src/neighborhood/moVectorVNSelection.h | 42 +++++---- 6 files changed, 161 insertions(+), 122 deletions(-) diff --git a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h index 515fc9949..26822d889 100644 --- a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h @@ -34,7 +34,6 @@ #include #include #include -#include /** * Explorer for the "Variable Neighborhood Search" metaheuristic @@ -47,11 +46,9 @@ public: typedef typename Neighbor::EOT EOT; /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator solution vs neighbor comparator + * Default constructor + * @param _selection selection the "neighborhood" search heuristics during the search + * @param _acceptCrit acceptance criteria which compare and accept or not the two solutions */ moVNSexplorer(moVariableNeighborhoodSelection & _selection, moAcceptanceCriterion& _acceptCrit): @@ -59,7 +56,7 @@ public: {} /** - * Destructor + * Empty destructor */ ~moVNSexplorer() { } @@ -92,7 +89,7 @@ public: virtual void terminate(EOT & _solution) {}; /** - * Explore the neighborhood of a solution + * Explore the neighborhood of a solution by the "neighborhood" search heuristics * @param _solution the current solution */ virtual void operator()(EOT & _solution) { @@ -100,12 +97,8 @@ public: eoMonOp & ls = selection.getLocalSearch(); current = _solution; - std::cout << "current avec shake: "<< current << std::endl; shake(current); - std::cout << "current apres shake: "<< current << std::endl; ls(current); - std::cout << "current apres ls: "<< ls.className() ; - std::cout << " sol: " << current << std::endl; } /** @@ -118,7 +111,7 @@ public: }; /** - * move the solution with the best neighbor + * move the solution with to current accepted solution * @param _solution the solution to move */ virtual void move(EOT & _solution) { @@ -128,7 +121,7 @@ public: /** * accept test if an amelirated neighbor was be found according to acceptance criteria * @param _solution the solution - * @return true if the best neighbor ameliorate the fitness + * @return true if the neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { return acceptCrit(_solution, current); @@ -143,21 +136,11 @@ public: } private: - //moDummyLS dummyLS; moVariableNeighborhoodSelection& selection; moAcceptanceCriterion& acceptCrit; - //eoMonOp* ls; - //eoMonOp& shake; bool stop; EOT current; - - /* - class moDummyEval: public eoEvalFunc{ - public: - void operator()(EOT& hop){} - }dummyEval; - */ }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moBackwardVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moBackwardVectorVNSelection.h index dd20cf97a..b3050c439 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moBackwardVectorVNSelection.h +++ b/trunk/paradiseo-mo/src/neighborhood/moBackwardVectorVNSelection.h @@ -32,16 +32,28 @@ #include +/** + * This class is used for the Variable Neighborhood Search explorer inherits from moVectorVNSelection + * The search heuristics are saved in vectors + * They are given in backward order from the last ones to the first ones + * + */ template< class EOT > class moBackwardVectorVNSelection: public moVectorVNSelection{ using moVectorVNSelection::LSvector; - using moVectorVNSelection::shakeVector; using moVectorVNSelection::current; public: - moBackwardVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake, bool _cycle):moVectorVNSelection(_firstLS, _firstShake), cycle(_cycle){} + /** + * Default constructor with first search heuristics + * + * @param _firstLS first local search + * @param _firstShake first heuristic which perturbs the solution + * @param _cycle when true, the first heuristics follows the last ones. Otherwise the search stop. + */ + moBackwardVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake, bool _cycle = true) : moVectorVNSelection(_firstLS, _firstShake), cycle(_cycle){} /** * Return the class id. @@ -52,34 +64,35 @@ public: } /** - * test if there is still some neighborhood to explore - * @return true if there is some neighborhood to explore + * test if there is still some heuristics + * + * @param _solution the current solution + * @return true if there is some heuristics */ virtual bool cont(EOT& _solution){ return (cycle || (current > 0)); } /** - * put the current neighborhood on the first one + * put the current heuristics on the first ones + * + * @param _solution the current solution */ virtual void init(EOT& _solution){ current = LSvector.size() - 1; - std::cout << "current LS: " << current << std::endl; - std::cout << _solution << std::endl; - } /** - * put the current neighborhood on the next one + * put the current heuristics on the next ones + * + * @param _solution the current solution */ virtual void next(EOT& _solution){ current = (current + LSvector.size() -1) % LSvector.size(); - std::cout << "current LS: " << current << std::endl; - std::cout << _solution << std::endl; - } private: + // boolean to indicate the last heuristics follow the first ones bool cycle; }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h index 6e11fe7d6..d7d3546cb 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h +++ b/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h @@ -32,16 +32,28 @@ #include +/** + * This class is used for the Variable Neighborhood Search explorer inherits from moVectorVNSelection + * The search heuristics are saved in vectors + * They are given in forward order from the first ones to the last ones + * + */ template< class EOT > class moForwardVectorVNSelection: public moVectorVNSelection{ using moVectorVNSelection::LSvector; - using moVectorVNSelection::shakeVector; using moVectorVNSelection::current; public: - moForwardVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake, bool _cycle):moVectorVNSelection(_firstLS, _firstShake), cycle(_cycle){} + /** + * Default constructor with first search heuristics + * + * @param _firstLS first local search + * @param _firstShake first heuristic which perturbs the solution + * @param _cycle when true, the first heuristics follows the last ones. Otherwise the search stop. + */ + moForwardVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake, bool _cycle = true) : moVectorVNSelection(_firstLS, _firstShake), cycle(_cycle){} /** * Return the class id. @@ -52,37 +64,35 @@ public: } /** - * test if there is still some neighborhood to explore - * @return true if there is some neighborhood to explore + * test if there is still some heuristics + * + * @param _solution the current solution + * @return true if there is some heuristics */ virtual bool cont(EOT& _solution){ - return (cycle || (current <= (LSvector.size()-2))); - std::cout << "current LS: " << current << std::endl; - std::cout << _solution << std::endl; - + return (cycle || (current <= (LSvector.size() - 2))); } /** - * put the current neighborhood on the first one + * put the current heuristics on the first ones + * + * @param _solution the current solution */ virtual void init(EOT& _solution){ current = 0; - // std::cout << "current LS: " << _ls->className() << " " << current << std::endl; - // std::cout << _solution << std::endl; - } /** - * put the current neighborhood on the next one + * put the current heuristics on the next ones + * + * @param _solution the current solution */ virtual void next(EOT& _solution){ current = (current + 1) % LSvector.size(); - std::cout << "current LS: " << current << std::endl; - std::cout << _solution << std::endl; } private: - + // boolean to indicate the first heuristics follow the last ones bool cycle; }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moRndVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moRndVectorVNSelection.h index e7b7d2e0c..fb307fad8 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moRndVectorVNSelection.h +++ b/trunk/paradiseo-mo/src/neighborhood/moRndVectorVNSelection.h @@ -35,16 +35,29 @@ #include +/** + * This class is used for the Variable Neighborhood Search explorer inherits from moVectorVNSelection + * The search heuristics are saved in vectors + * They are given in random order (at each initialization the order is changed) + * + */ template< class EOT > -class moRndVectorVNSelection: public moVectorVNSelection{ - +class moRndVectorVNSelection: public moVectorVNSelection +{ using moVectorVNSelection::LSvector; - using moVectorVNSelection::shakeVector; + // using moVectorVNSelection::shakeVector; using moVectorVNSelection::current; public: - moRndVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake, bool _cycle = true):moVectorVNSelection(_firstLS, _firstShake), cycle(_cycle){} + /** + * Default constructor with first search heuristics + * + * @param _firstLS first local search + * @param _firstShake first heuristic which perturbs the solution + * @param _cycle when true, the first heuristics follows the last ones. Otherwise the search stop. + */ + moRndVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake, bool _cycle = true) : moVectorVNSelection(_firstLS, _firstShake), cycle(_cycle){} /** * Return the class id. @@ -55,15 +68,19 @@ public: } /** - * test if there is still some neighborhood to explore - * @return true if there is some neighborhood to explore + * test if there is still some heuristics + * + * @param _solution the current solution + * @return true if there is some heuristics */ virtual bool cont(EOT& _solution){ return ( cycle || (currentOrder <= (order.size() - 2)) ); } /** - * put the current neighborhood on the first one + * put the current heuristics on the first ones + * + * @param _solution the current solution */ virtual void init(EOT& _solution) { if(order.size() == 0) @@ -77,7 +94,9 @@ public: } /** - * put the current neighborhood on the next one + * put the current heuristics on the next ones + * + * @param _solution the current solution */ virtual void next(EOT& _solution){ currentOrder = (currentOrder + 1) % order.size(); @@ -86,10 +105,13 @@ public: } private: - + // boolean to indicate the first heuristics follow the last ones bool cycle; + // index in order vector unsigned int currentOrder; + // the index of heuristics in random order std::vector order; + // random generator UF_random_generator gen; }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhoodSelection.h b/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhoodSelection.h index 5c4ee4f28..99af9a98d 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhoodSelection.h +++ b/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhoodSelection.h @@ -1,30 +1,30 @@ /* - -Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 -Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau + Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can ue, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can ue, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. -ParadisEO WebSite : http://paradiseo.gforge.inria.fr -Contact: paradiseo-help@lists.gforge.inria.fr + ParadisEO WebSite : http://paradiseo.gforge.inria.fr + Contact: paradiseo-help@lists.gforge.inria.fr */ #ifndef _moVariableNeighborhoodSelection_h @@ -33,34 +33,41 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include +/** + * This class is used for the Variable Neighborhood Search explorer + * It gives the sequence of search heuristics based on the different "neighborhoods" + * The class is built such as the moNeighborhood" with init, next, cont + * and two methods to get the heuristics which shake the solution, and which give the local search + * + */ template< class EOT > class moVariableNeighborhoodSelection { public: - /** - * Return the class id. - * @return the class name as a std::string - */ - virtual std::string className() const { - return "moVariableNeighborhoodSelection"; - } + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moVariableNeighborhoodSelection"; + } - /** - * test if there is still some neighborhood to explore - * @return true if there is some neighborhood to explore - */ - virtual bool cont(EOT& _solution) = 0; + /** + * test if there is still some search heuristics to use + * @return true if there is some neighborhood to explore + */ + virtual bool cont(EOT& _solution) = 0; - /** - * put the current neighborhood on the first one - */ - virtual void init(EOT& _solution) = 0; + /** + * put on the first search heuristics + */ + virtual void init(EOT& _solution) = 0; - /** - * put the current neighborhood on the next one - */ - virtual void next(EOT& _solution) = 0; + /** + * put the next search heuristics + */ + virtual void next(EOT& _solution) = 0; /** * Get the current "shake" operator based on the current neighborhood diff --git a/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h index 83a7f394c..3070e0e9a 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h +++ b/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h @@ -33,17 +33,36 @@ #include #include +/** + * This class is used for the Variable Neighborhood Search explorer inherits from moVariableNeighborhoodSelection + * The search heuristics are saved in vectors + * The way to croos the vector is not defined here + * + */ template< class EOT > class moVectorVNSelection: public moVariableNeighborhoodSelection{ public: + /** + * Default constructor with first search heuristics + * + * @param _firstLS first local search + * @param _firstShake first heuristic which perturbs the solution + */ moVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake){ LSvector.push_back(&_firstLS); shakeVector.push_back(&_firstShake); - current=0; + + current = 0; } + /** + * Add some search heuristics + * + * @param _otherLS the added local search + * @param _otherShake the added heuristic which perturbs the solution + */ void add(eoMonOp& _otherLS, eoMonOp& _otherShake){ LSvector.push_back(&_otherLS); shakeVector.push_back(&_otherShake); @@ -72,30 +91,15 @@ public: * @return current local search */ virtual eoMonOp & getLocalSearch() { - std::cout << "getLS : " << current << " sur " << LSvector.size() << std::endl; - std::cout << "getLS : ls = " << LSvector[current]->className() << std::endl; return *(LSvector[current]); } - /** - * test if there is still some neighborhood to explore - * @return true if there is some neighborhood to explore - */ - virtual bool cont(EOT& _solution) = 0; - - /** - * put the current neighborhood on the first one - */ - virtual void init(EOT& _solution) = 0; - - /** - * put the current neighborhood on the next one - */ - virtual void next(EOT& _solution) = 0; - protected: + // vector of local searches std::vector* > LSvector; + // vector of "shake" heiristics which perturbs the current solution std::vector* > shakeVector; + // index of the current search heuristics which is applied unsigned int current; };