diff --git a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h index 4a64c0e74..5049d9173 100644 --- a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h @@ -33,6 +33,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include #include +#include /** * Explorer for Variiable Neighborhood Search diff --git a/trunk/paradiseo-mo/src/mo.h b/trunk/paradiseo-mo/src/mo.h index 2ad853626..96a519072 100755 --- a/trunk/paradiseo-mo/src/mo.h +++ b/trunk/paradiseo-mo/src/mo.h @@ -142,6 +142,10 @@ #include #include #include +#include +#include +#include +#include #include #include diff --git a/trunk/paradiseo-mo/src/neighborhood/moBackwardVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moBackwardVectorVNSelection.h new file mode 100644 index 000000000..52d52e925 --- /dev/null +++ b/trunk/paradiseo-mo/src/neighborhood/moBackwardVectorVNSelection.h @@ -0,0 +1,86 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie 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". + +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 +*/ + +#ifndef _moBackwardVectorVNSelection_h +#define _moBackwardVectorVNSelection_h + +#include + +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){} + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moBackwardVectorVNSelection"; + } + + /** + * test if there is still some neighborhood to explore + * @return true if there is some neighborhood to explore + */ + virtual bool cont(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + return (cycle || (current >0 )); + } + + /** + * put the current neighborhood on the first one + */ + virtual void init(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + current=LSvector.size()-1; + _ls=LSvector[current]; + _shake = shakeVector[current]; + } + + /** + * put the current neighborhood on the next one + */ + virtual void next(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + current= (current + LSvector.size() -1) % LSvector.size(); + _ls=LSvector[current]; + _shake = shakeVector[current]; + } + +private: + + bool cycle; + +}; + +#endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h new file mode 100644 index 000000000..5f9e4703a --- /dev/null +++ b/trunk/paradiseo-mo/src/neighborhood/moForwardVectorVNSelection.h @@ -0,0 +1,86 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie 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". + +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 +*/ + +#ifndef _moForwardVectorVNSelection_h +#define _moForwardVectorVNSelection_h + +#include + +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){} + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moForwardVectorVNSelection"; + } + + /** + * test if there is still some neighborhood to explore + * @return true if there is some neighborhood to explore + */ + virtual bool cont(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + return (cycle || (current <= (LSvector.size()-2))); + } + + /** + * put the current neighborhood on the first one + */ + virtual void init(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + current=0; + _ls = LSvector[current]; + _shake = shakeVector[current]; + } + + /** + * put the current neighborhood on the next one + */ + virtual void next(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + current = (current+1) % LSvector.size(); + _ls = LSvector[current]; + _shake = shakeVector[current]; + } + +private: + + bool cycle; + +}; + +#endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moRndVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moRndVectorVNSelection.h new file mode 100644 index 000000000..247eaa725 --- /dev/null +++ b/trunk/paradiseo-mo/src/neighborhood/moRndVectorVNSelection.h @@ -0,0 +1,96 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie 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". + +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 +*/ + +#ifndef _moRndVectorVNSelection_h +#define _moRndVectorVNSelection_h + +#include +#include + +#include + +template< class EOT > +class moRndVectorVNSelection: public moVectorVNSelection{ + + using moVectorVNSelection::LSvector; + using moVectorVNSelection::shakeVector; + using moVectorVNSelection::current; + +public: + + moRndVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake, bool _cycle):moVectorVNSelection(_firstLS, _firstShake), cycle(_cycle){} + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moRndVectorVNSelection"; + } + + /** + * test if there is still some neighborhood to explore + * @return true if there is some neighborhood to explore + */ + virtual bool cont(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + return (cycle || (current <= (LSvector.size()-2))); + } + + /** + * put the current neighborhood on the first one + */ + virtual void init(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls){ + if(order.size()==0){ + for(unsigned int i=0; i& _shake, eoMonOp& _ls){ + current= (current+1) % LSvector.size(); + _ls=LSvector[order[current]]; + _shake=shakeVector[order[current]]; + } + +private: + + bool cycle; + std::vector order; + UF_random_generator gen; + +}; + +#endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h b/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h new file mode 100644 index 000000000..1fe14590d --- /dev/null +++ b/trunk/paradiseo-mo/src/neighborhood/moVectorVNSelection.h @@ -0,0 +1,84 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sébastien Verel, Arnaud Liefooghe, Jérémie 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". + +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 +*/ + +#ifndef _moVectorVNSelection_h +#define _moVectorVNSelection_h + +#include +#include + +template< class EOT > +class moVectorVNSelection: public moVariableNeighborhoodSelection{ + +public: + + moVectorVNSelection(eoMonOp& _firstLS, eoMonOp& _firstShake){ + LSvector.push_back(&_firstLS); + shakeVector.push_back(&_firstShake); + current=0; + } + + void addLS(eoMonOp& _otherLS, eoMonOp& _otherShake){ + LSvector.push_back(&_otherLS); + shakeVector.push_back(&_otherShake); + } + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moVectorVNSelection"; + } + + /** + * test if there is still some neighborhood to explore + * @return true if there is some neighborhood to explore + */ + virtual bool cont(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls) = 0; + + /** + * put the current neighborhood on the first one + */ + virtual void init(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls) = 0; + + /** + * put the current neighborhood on the next one + */ + virtual void next(EOT& _solution, eoMonOp& _shake, eoMonOp& _ls) = 0; + +protected: + std::vector* > LSvector; + std::vector* > shakeVector; + unsigned int current; + +}; + + +#endif diff --git a/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp b/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp index adc2d8195..964333e40 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp @@ -38,6 +38,10 @@ using namespace std; #include #include #include +#include +#include +#include +#include //Algorithm and its components #include @@ -149,33 +153,12 @@ void main_function(int argc, char **argv) shiftNeighborhood shiftNH((vecSize-1) * (vecSize-1)); swapNeighborhood swapNH(100); - moForwardVariableNeighborhood< moIndexNeighbor > varNH( dynamic_cast > *>(&shiftNH)); - varNH.add(dynamic_cast > *>(&swapNH)); - - varNH.initNeighborhood(); Queen sol; init(sol); shiftNeighbor n; - varNH.init(sol, n); - - n.move(sol); - - n.print(); - - varNH.next(sol, n); - n.move(sol); - n.print(); - - varNH.nextNeighborhood(); - - swapNeighbor n2; - varNH.init(sol, n2); - std::cout << "key: " << n2.index() << std::endl; - varNH.next(sol, n2); - std::cout << "key: " << n2.index() << std::endl; /* ========================================================= *