diff --git a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h new file mode 100644 index 000000000..33d0d774a --- /dev/null +++ b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h @@ -0,0 +1,142 @@ +/* + +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 _moVNSexplorer_h +#define _moVNSexplorer_h + +#include +#include +#include + +/** + * Explorer for Variiable Neighborhood Search + */ +template< class Neighborhood > +class moVNSexplorer : public moNeighborhoodExplorer +{ +public: + typedef typename Neighborhood::EOT EOT ; + typedef typename Neighborhood::Neighbor Neighbor ; + + using moNeighborhoodExplorer::neighborhood; + using moNeighborhoodExplorer::eval; + + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @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) { + } + + /** + * Destructor + */ + ~moVNSexplorer() { + } + + /** + * initParam: NOTHING TO DO + */ + virtual void initParam(EOT & solution) {}; + + /** + * updateParam: NOTHING TO DO + */ + virtual void updateParam(EOT & solution) {}; + + /** + * terminate: NOTHING TO DO + */ + virtual void terminate(EOT & solution) {}; + + /** + * Explore the neighborhood of a solution + * @param _solution + */ + virtual void operator()(EOT & _solution) { + }; + + /** + * continue if a move is accepted + * @param _solution the solution + * @return true if an ameliorated neighbor was be found + */ + virtual bool isContinue(EOT & _solution) { + 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 + * @return true if the best neighbor ameliorate the fitness + */ + virtual bool accept(EOT & _solution) { + if (neighborhood.hasNeighbor(_solution)) { + isAccept = solNeighborComparator(_solution, (*best)) ; + } + return isAccept; + }; + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moVNSexplorer"; + } + +private: + // comparator betwenn solution and neighbor or between neighbors + moNeighborComparator& neighborComparator; + moSolNeighborComparator& solNeighborComparator; + + //Pointer on the best and the current neighbor + Neighbor* best; + Neighbor* current; + + // true if the move is accepted + bool isAccept ; +}; + + +#endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moBackwardVariableNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moBackwardVariableNeighborhood.h new file mode 100644 index 000000000..25978990d --- /dev/null +++ b/trunk/paradiseo-mo/src/neighborhood/moBackwardVariableNeighborhood.h @@ -0,0 +1,87 @@ +/* + +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 _moBackwardVariableNeighborhood_h +#define _moBackwardVariableNeighborhood_h + +#include + +/** + * A variable Neighborhood Search (VNS) in the Backward manner + */ +template< class Neighbor > +class moBackwardVariableNeighborhood : public moVariableNeighborhood +{ +public: + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; + + using moVariableNeighborhood::currentNH; + using moVariableNeighborhood::neighborhoodVector; + + /** + * Construction of at least one neighborhood + * @param _firstNH first neighborhood in the vector + */ + moBackwardVariableNeighborhood(moNeighborhood& _firstNH) : moVariableNeighborhood(_firstNH) { } + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moBackwardVariableNeighborhood"; + } + + /** + * test if there is still some neighborhood to explore + * @return true if there is some neighborhood to explore + */ + virtual bool contNeighborhood() { + return (currentNH > 0); + } + + /** + * put the current neighborhood on the last one + */ + virtual void initNeighborhood() { + currentNH = neighborhoodVector.size() - 1; + } + + /** + * put the current neighborhood on the next one + */ + virtual void nextNeighborhood() { + currentNH--; + } + +}; +#endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moForwardVariableNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moForwardVariableNeighborhood.h new file mode 100644 index 000000000..410caf44f --- /dev/null +++ b/trunk/paradiseo-mo/src/neighborhood/moForwardVariableNeighborhood.h @@ -0,0 +1,88 @@ +/* + +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 _moForwardVariableNeighborhood_h +#define _moForwardVariableNeighborhood_h + +#include + +/** + * A variable Neighborhood Search (VNS) in the forward manner + */ +template< class Neighbor > +class moForwardVariableNeighborhood : public moVariableNeighborhood +{ +public: + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; + + using moVariableNeighborhood::currentNH; + using moVariableNeighborhood::neighborhoodVector; + + /** + * Construction of at least one neighborhood + * @param _firstNH first neighborhood in the vector + */ + moForwardVariableNeighborhood(moNeighborhood& _firstNH) : moVariableNeighborhood(_firstNH) { } + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moForwardVariableNeighborhood"; + } + + /** + * test if there is still some neighborhood to explore + * @return true if there is some neighborhood to explore + */ + virtual bool contNeighborhood() { + return (currentNH < neighborhoodVector.size() - 1); + } + + /** + * put the current neighborhood on the first one + */ + virtual void initNeighborhood() { + currentNH = 0; + } + + /** + * put the current neighborhood on the next one + */ + virtual void nextNeighborhood() { + currentNH++; + } + +}; + +#endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moRndVariableNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moRndVariableNeighborhood.h new file mode 100644 index 000000000..e6d3fd83e --- /dev/null +++ b/trunk/paradiseo-mo/src/neighborhood/moRndVariableNeighborhood.h @@ -0,0 +1,107 @@ +/* + +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 _moRndVariableNeighborhood_h +#define _moRndVariableNeighborhood_h + +#include +#include + +/** + * A variable Neighborhood Search (VNS) in the random manner + */ +template< class Neighbor > +class moRndVariableNeighborhood : public moVariableNeighborhood +{ +public: + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; + + using moVariableNeighborhood::currentNH; + using moVariableNeighborhood::neighborhoodVector; + + /** + * Construction of at least one neighborhood + * @param _firstNH first neighborhood in the vector + */ + moRndVariableNeighborhood(moNeighborhood& _firstNH) : moVariableNeighborhood(_firstNH) { + indexVector.push_back(0); + } + + /** + * to add a neighborhood in the vector + * @param _nh the neighborhood to add at the end of the vector of neighborhood + */ + virtual void add(moNeighborhood& _nh) { + neighborhoodVector.push_back(_nh); + indexVector.push_back(indexVector.size()); + } + + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moRndVariableNeighborhood"; + } + + /** + * test if there is still some neighborhood to explore + * @return true if there is some neighborhood to explore + */ + virtual bool contNeighborhood() { + return (index < neighborhoodVector.size() - 1); + } + + /** + * put the current neighborhood on the first one + */ + virtual void initNeighborhood() { + std::random_shuffle(indexVector.begin(), indexVector.end()); + index = 0; + currentNH = indexVector[index]; + } + + /** + * put the current neighborhood on the next one + */ + virtual void nextNeighborhood() { + index++; + currentNH = indexVector[index]; + } + +private: + unsigned int index; + std::vector indexVector; +}; + +#endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhood.h new file mode 100644 index 000000000..82ae82645 --- /dev/null +++ b/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhood.h @@ -0,0 +1,139 @@ +/* + +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 _moVariableNeighborhood_h +#define _moVariableNeighborhood_h + +#include + +/** + * A vector of neighborhood for the Variable Neighborhood Search (VNS) + */ +template< class Neighbor > +class moVariableNeighborhood : public moNeighborhood +{ +public: + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; + + /** + * Construction of at least one neighborhood + * @param _firstNH first neighborhood in the vector + */ + moVariableNeighborhood(moNeighborhood& _firstNH) { + neighborhoodVector.push_back(_firstNH); + // the current neighborhood + currentNH = 0; + } + + /** + * @return if the current neighborhood is random + */ + virtual bool isRandom() { + return neighborhoodVector[currentNH].isRandom(); + } + + /** + * Test if a solution has a Neighbor in the current neighborhood + * @param _solution the related solution + * @return if _solution has a Neighbor in the current neighborhood + */ + virtual bool hasNeighbor(EOT & _solution) { + return neighborhoodVector[currentNH].hasNeighbor(_solution); + } + + /** + * Initialization of the current neighborhood + * @param _solution the solution to explore + * @param _current the first neighbor in the current neighborhood + */ + virtual void init(EOT & _solution, Neighbor & _current) { + neighborhoodVector[currentNH].init(_solution, _current); + } + + /** + * Give the next neighbor in the current neighborhood + * @param _solution the solution to explore + * @param _current the next neighbor in the current neighborhood + */ + virtual void next(EOT & _solution, Neighbor & _current) { + neighborhoodVector[currentNH].next(_solution, _current); + } + + /** + * Test if there is again a neighbor in the current neighborhood + * @param _solution the solution to explore + * @return if there is still a neighbor not explored in the current neighborhood + */ + virtual bool cont(EOT & _solution) { + neighborhoodVector[currentNH].cont(_solution); + } + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moVariableNeighborhood"; + } + + /** + * to add a neighborhood in the vector + * @param _nh the neighborhood to add at the end of the vector of neighborhood + */ + virtual void add(moNeighborhood& _nh) { + neighborhoodVector.push_back(_nh); + } + + /** + * test if there is still some neighborhood to explore + * @return true if there is some neighborhood to explore + */ + virtual bool contNeighborhood() = 0; + + /** + * put the current neighborhood on the first one + */ + virtual void initNeighborhood() = 0; + + /** + * put the current neighborhood on the next one + */ + virtual void nextNeighborhood() = 0; + +private: + // the vector of neighborhoods + std::vector& > neighborhoodVector; + // the index of the current neighborhood + unsigned int currentNH; + +}; +#endif