From 959e9be6e2107ea510c5f4613783c7384cb191ab Mon Sep 17 00:00:00 2001 From: boufaras Date: Mon, 9 Jan 2012 10:31:15 +0000 Subject: [PATCH] independent ParadisEO-GPU package git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2593 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/neighborhood/moGPUBitNeighbor.h | 122 ++++++++++++++++++ .../neighborhood/moGPUMappingNeighborhood.h | 110 ++++++++++++++++ .../moGPUMappingNeighborhoodByCpy.h | 97 ++++++++++++++ .../moGPUMappingNeighborhoodByModif.h | 97 ++++++++++++++ .../moGPUOrderNeighborhoodByCpy.h | 96 ++++++++++++++ .../moGPUOrderNeighborhoodByModif.h | 96 ++++++++++++++ .../moGPURndWithReplNeighborhoodByCpy.h | 88 +++++++++++++ .../moGPURndWithReplNeighborhoodByModif.h | 87 +++++++++++++ .../moGPURndWithoutReplNeighborhoodByCpy.h | 90 +++++++++++++ .../moGPURndWithoutReplNeighborhoodByModif.h | 90 +++++++++++++ .../neighborhood/moGPUXBitFlippingNeighbor.h | 101 +++++++++++++++ .../neighborhood/moGPUXChangeNeighborhood.h | 110 ++++++++++++++++ .../moGPUXChangeNeighborhoodByCpy.h | 97 ++++++++++++++ .../moGPUXChangeNeighborhoodByModif.h | 96 ++++++++++++++ .../src/neighborhood/moGPUXSwapNeighbor.h | 108 ++++++++++++++++ 15 files changed, 1485 insertions(+) create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUBitNeighbor.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhood.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhoodByCpy.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhoodByModif.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUOrderNeighborhoodByCpy.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUOrderNeighborhoodByModif.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithReplNeighborhoodByCpy.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithReplNeighborhoodByModif.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithoutReplNeighborhoodByCpy.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithoutReplNeighborhoodByModif.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXBitFlippingNeighbor.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhood.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhoodByCpy.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhoodByModif.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXSwapNeighbor.h diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUBitNeighbor.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUBitNeighbor.h new file mode 100644 index 000000000..b48753bac --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUBitNeighbor.h @@ -0,0 +1,122 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Jerémie Humeau, Boufaras Karima, Thé Van LUONG + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + 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". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + 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 __moGPUBitNeighbor_h +#define __moGPUBitNeighbor_h + +#include +#include +#include + +/** + * Neighbor related to a solution vector of Bit + */ + +template +class moGPUBitNeighbor: public moBackableNeighbor > , + public moIndexNeighbor > { + +public: + + typedef moGPUBitVector EOT ; + using moBackableNeighbor::fitness; + using moIndexNeighbor::key; + + /** + * move the solution + * @param _solution the solution to move + */ + + virtual void move(EOT & _solution) { + + _solution[key] = !_solution[key]; + _solution.invalidate(); + + } + + /** + * move back the solution (useful for the evaluation by modif) + * @param _solution the solution to move back + */ + + virtual void moveBack(EOT & _solution) { + + move(_solution); + + } + + /** + * Return the class name. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUBitNeighbor"; + } + + /** + * Read object.\ + * Calls base class, just in case that one had something to do. + * The read and print methods should be compatible and have the same format. + * In principle, format is "plain": they just print a number + * @param _is a std::istream. + * @throw runtime_std::exception If a valid object can't be read. + */ + + virtual void readFrom(std::istream& _is) { + std::string fitness_str; + int pos = _is.tellg(); + _is >> fitness_str; + if (fitness_str == "INVALID") { + throw std::runtime_error("invalid fitness"); + } else { + Fitness repFit; + _is.seekg(pos); + _is >> repFit; + _is >> key; + fitness(repFit); + } + } + + /** + * Write object. Called printOn since it prints the object _on_ a stream. + * @param _os A std::ostream. + */ + + virtual void printOn(std::ostream& _os) const { + _os << fitness() << ' ' << key << std::endl; + } + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhood.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhood.h new file mode 100644 index 000000000..08a94d31b --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhood.h @@ -0,0 +1,110 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Karima Boufaras, Thé Van LUONG + + 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 __moGPUMappingNeighborhood_h +#define __moGPUMappingNeighborhood_h + +#include +#include + +template +class moGPUMappingNeighborhood: public moMappingNeighborhood { + +public: + + /** + * Define a Neighbor and type of a solution corresponding + */ + + typedef N Neighbor; + typedef typename Neighbor::EOT EOT; + + using moMappingNeighborhood::neighborhoodSize; + using moMappingNeighborhood::currentIndex; + using moMappingNeighborhood::indices; + using moMappingNeighborhood::mapping; + using moMappingNeighborhood::xChange; + using moMappingNeighborhood::mutex; + + /** + * Constructor + * @param _neighborhoodSize the neighborhood size + * @param _xChange the number of x-change positions + */ + + moGPUMappingNeighborhood(unsigned int _neighborhoodSize, + unsigned int _xChange) : + moMappingNeighborhood (_neighborhoodSize, _xChange) { + sendMapping = false; + cudaMalloc((void**) &device_Mapping, sizeof(unsigned int) + * neighborhoodSize * _xChange); + } + ; + + /** + *Destructor + */ + + ~moGPUMappingNeighborhood() { + + cudaFree(device_Mapping); + } + + /** + * Initialization of the neighborhood and mapping on device + * @param _solution the solution to explore + * @param _current the first neighbor + */ + + virtual void init(EOT& _solution, Neighbor& _current) { + + moMappingNeighborhood::init(_solution, _current); + if (!sendMapping) { + cudaMemcpy(device_Mapping, mapping,xChange * neighborhoodSize + * sizeof(unsigned int), cudaMemcpyHostToDevice); + sendMapping = true; + } + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUMappingNeighborhood"; + } + +protected: + + bool sendMapping; + unsigned int * device_Mapping; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhoodByCpy.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhoodByCpy.h new file mode 100644 index 000000000..68031f6bf --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhoodByCpy.h @@ -0,0 +1,97 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Boufaras Karima, Thé Van Luong + + 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 __moGPUMappingNeighborhoodByCpy_h +#define __moGPUMappingNeighborhoodByCpy_h + +#include +#include + +template +class moGPUMappingNeighborhoodByCpy: public moGPUMappingNeighborhood { + +public: + + /** + * Define a Neighbor and type of a solution corresponding + */ + + typedef N Neighbor; + typedef typename Neighbor::EOT EOT; + + /*A tester*/ + using moGPUMappingNeighborhood::neighborhoodSize; + using moGPUMappingNeighborhood::currentIndex; + using moGPUMappingNeighborhood::indices; + using moGPUMappingNeighborhood::mapping; + using moGPUMappingNeighborhood::xChange; + using moGPUMappingNeighborhood::mutex; + using moGPUMappingNeighborhood::device_Mapping; + + /** + * Constructor + * @param _neighborhoodSize the neighborhood size + * @param _xChange the number of x-change positions + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + + moGPUMappingNeighborhoodByCpy(unsigned int _neighborhoodSize, + unsigned int _xChange,moGPUEval& _eval) : + moGPUMappingNeighborhood (_neighborhoodSize, _xChange), eval(_eval){ + } + + + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _current the first neighbor + */ + + virtual void init(EOT& _solution, Neighbor& _current) { + + moGPUMappingNeighborhood::init(_solution, _current); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution, device_Mapping,1,1); + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUMappingNeighborhoodByCpy"; + } + +protected: + + moGPUEval& eval; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhoodByModif.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhoodByModif.h new file mode 100644 index 000000000..c1bab360e --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUMappingNeighborhoodByModif.h @@ -0,0 +1,97 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Karima Boufaras, Thé Van Luong + + 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 __moGPUMappingNeighborhoodByModif_h +#define __moGPUMappingNeighborhoodByModif_h + +#include +#include + +template +class moGPUMappingNeighborhoodByModif: public moGPUMappingNeighborhood { + +public: + + /** + * Define a Neighbor and type of a solution corresponding + */ + + typedef N Neighbor; + typedef typename Neighbor::EOT EOT; + + /*A tester*/ + using moGPUMappingNeighborhood::neighborhoodSize; + using moGPUMappingNeighborhood::currentIndex; + using moGPUMappingNeighborhood::indices; + using moGPUMappingNeighborhood::mapping; + using moGPUMappingNeighborhood::xChange; + using moGPUMappingNeighborhood::mutex; + using moGPUMappingNeighborhood::device_Mapping; + + /** + * Constructor + * @param _neighborhoodSize the neighborhood size + * @param _xChange the number of x-change positions + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + + moGPUMappingNeighborhoodByModif(unsigned int _neighborhoodSize, + unsigned int _xChange,moGPUEval& _eval) : + moGPUMappingNeighborhood (_neighborhoodSize, _xChange), eval(_eval){ + } + + + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _current the first neighbor + */ + + virtual void init(EOT& _solution, Neighbor& _current) { + + moGPUMappingNeighborhood::init(_solution, _current); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution, device_Mapping,0,1); + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUMappingNeighborhoodByModif"; + } + +protected: + + moGPUEval& eval; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUOrderNeighborhoodByCpy.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUOrderNeighborhoodByCpy.h new file mode 100644 index 000000000..bce7abfb0 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUOrderNeighborhoodByCpy.h @@ -0,0 +1,96 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Karima Boufaras, Thé Van LUONG + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + 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". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + 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 __moGPUOrderNeighborhoodByCpy_h +#define __moGPUOrderNeighborhoodByCpy_h + +#include +#include + +/** + * An ordered neighborhood with parallel evaluation + */ + +template +class moGPUOrderNeighborhoodByCpy: public moOrderNeighborhood { + + public: + + /** + * Define type of a solution corresponding to Neighbor + */ + + typedef N Neighbor; + typedef typename Neighbor::EOT EOT; + + using moOrderNeighborhood::neighborhoodSize; + using moOrderNeighborhood::currentIndex; + + /** + * Constructor + * @param _neighborhoodSize the size of the neighborhood + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + + moGPUOrderNeighborhoodByCpy(unsigned int _neighborhoodSize, + moGPUEval& _eval) : + moOrderNeighborhood (_neighborhoodSize), eval(_eval) { + } + + /** + * Initialization of the neighborhood + *@param _solution the solution to explore + *@param _neighbor the first neighbor + */ + + virtual void init(EOT & _solution, Neighbor & _neighbor) { + + moOrderNeighborhood::init(_solution, _neighbor); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution,1,1); + } + + /** + * Return the class name. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUOrderNeighborhoodByCpy"; + } + + protected: + moGPUEval& eval; +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUOrderNeighborhoodByModif.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUOrderNeighborhoodByModif.h new file mode 100644 index 000000000..7c997a901 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUOrderNeighborhoodByModif.h @@ -0,0 +1,96 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Jerémie Humeau, Thé Van LUONG, Karima Boufaras + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + 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". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + 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 __moGPUOrderNeighborhoodByModif_h +#define __moGPUOrderNeighborhoodByModif_h + +#include +#include + +/** + * An ordered neighborhood with parallel evaluation + */ + +template +class moGPUOrderNeighborhoodByModif: public moOrderNeighborhood { + + public: + + /** + * Define type of a solution corresponding to Neighbor + */ + + typedef N Neighbor; + typedef typename Neighbor::EOT EOT; + + using moOrderNeighborhood::neighborhoodSize; + using moOrderNeighborhood::currentIndex; + + /** + * Constructor + * @param _neighborhoodSize the size of the neighborhood + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + + moGPUOrderNeighborhoodByModif(unsigned int _neighborhoodSize, + moGPUEval& _eval) : + moOrderNeighborhood (_neighborhoodSize), eval(_eval) { + } + + /** + * Initialization of the neighborhood + *@param _solution the solution to explore + *@param _neighbor the first neighbor + */ + + virtual void init(EOT & _solution, Neighbor & _neighbor) { + + moOrderNeighborhood::init(_solution, _neighbor); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution,0,1); + } + + /** + * Return the class name. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUOrderNeighborhoodByModif"; + } + + protected: + moGPUEval& eval; +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithReplNeighborhoodByCpy.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithReplNeighborhoodByCpy.h new file mode 100644 index 000000000..8c99c82b3 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithReplNeighborhoodByCpy.h @@ -0,0 +1,88 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Jerémie Humeau, Karima Boufaras, Thé Van LUONG + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + 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". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + 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 _moGPURndWithReplNeighborhood_h +#define _moGPURndWithReplNeighborhood_h + +#include +#include + +/** + * A Random With replacement Neighborhood with parallel evaluation + */ +template +class moGPURndWithReplNeighborhoodByCpy: public moRndWithReplNeighborhood { + public: + + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; + + using moRndWithReplNeighborhood::neighborhoodSize; + + /** + * Constructor + * @param _neighborhoodSize the size of the neighborhood + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + moGPURndWithReplNeighborhoodByCpy(unsigned int _neighborhoodSize, moGPUEvalByCpy< + Neighbor>& _eval) : + moRndWithReplNeighborhood (_neighborhoodSize), eval(_eval) { + } + + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _neighbor the first neighbor + */ + virtual void init(EOT & _solution, Neighbor & _neighbor) { + moRndWithReplNeighborhood::init(_solution, _neighbor); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution,0,1); + + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPURndWithReplNeighborhoodByCpy"; + } + protected: + moGPUEvalByCpy& eval; +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithReplNeighborhoodByModif.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithReplNeighborhoodByModif.h new file mode 100644 index 000000000..fc64d3288 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithReplNeighborhoodByModif.h @@ -0,0 +1,87 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Jerémie Humeau, Karima Boufaras, Thé Van LUONG + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + 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". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + 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 __moGPURndWithReplNeighborhoodByModif_h +#define __moGPURndWithReplNeighborhoodByModif_h + +#include +#include + +/** + * A Random With replacement Neighborhood with parallel evaluation + */ +template +class moGPURndWithReplNeighborhoodByModif: public moRndWithReplNeighborhood { + public: + + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; + + using moRndWithReplNeighborhood::neighborhoodSize; + + /** + * Constructor + * @param _neighborhoodSize the size of the neighborhood + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + moGPURndWithReplNeighborhoodByModif(unsigned int _neighborhoodSize, moGPUEval& _eval) : + moRndWithReplNeighborhood (_neighborhoodSize), eval(_eval) { + } + + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _neighbor the first neighbor + */ + virtual void init(EOT & _solution, Neighbor & _neighbor) { + moRndWithReplNeighborhood::init(_solution, _neighbor); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution,0,1); + + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPURndWithReplNeighborhood"; + } + protected: + moGPUEval& eval; +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithoutReplNeighborhoodByCpy.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithoutReplNeighborhoodByCpy.h new file mode 100644 index 000000000..69108b8d2 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithoutReplNeighborhoodByCpy.h @@ -0,0 +1,90 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Jerémie Humeau, Boufaras Karima, Thé Van LUONG + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + 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". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + 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 __moGPURndWithoutReplNeighborhood_h +#define __moGPURndWithoutReplNeighborhood_h + +#include +#include + +/** + * A Random without replacement Neighborhood with parallel evaluation + */ +template +class moGPURndWithoutReplNeighborhood: public moRndWithoutReplNeighborhood { + public: + + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; + + using moRndWithoutReplNeighborhood::neighborhoodSize; + using moRndWithoutReplNeighborhood::maxIndex; + using moRndWithoutReplNeighborhood::indexVector; + /** + * Constructor + * @param _neighborhoodSize the size of the neighborhood + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + moGPURndWithoutReplNeighborhood(unsigned int _neighborhoodSize,moGPUEval< + Neighbor>& _eval) : + moRndWithoutReplNeighborhood (_neighborhoodSize),eval(_eval) { + for (unsigned int i = 0; i < neighborhoodSize; i++) + indexVector.push_back(i); + } + + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _neighbor the first neighbor + */ + virtual void init(EOT & _solution, Neighbor & _neighbor) { + moRndWithoutReplNeighborhood::init(_solution, _neighbor); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution,0,1); + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPURndWithoutReplNeighborhood"; + } + + protected: + moGPUEval& eval; +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithoutReplNeighborhoodByModif.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithoutReplNeighborhoodByModif.h new file mode 100644 index 000000000..f1b4ff1cb --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPURndWithoutReplNeighborhoodByModif.h @@ -0,0 +1,90 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Jerémie Humeau, Boufaras Karima, Thé Van LUONG + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + 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". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + 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 __moGPURndWithoutReplNeighborhood_h +#define __moGPURndWithoutReplNeighborhood_h + +#include +#include + +/** + * A Random without replacement Neighborhood with parallel evaluation + */ +template +class moGPURndWithoutReplNeighborhood: public moRndWithoutReplNeighborhood { + public: + + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; + + using moRndWithoutReplNeighborhood::neighborhoodSize; + using moRndWithoutReplNeighborhood::maxIndex; + using moRndWithoutReplNeighborhood::indexVector; + /** + * Constructor + * @param _neighborhoodSize the size of the neighborhood + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + moGPURndWithoutReplNeighborhood(unsigned int _neighborhoodSize,moGPUEvalByModif< + Neighbor>& _eval) : + moRndWithoutReplNeighborhood (_neighborhoodSize),eval(_eval) { + for (unsigned int i = 0; i < neighborhoodSize; i++) + indexVector.push_back(i); + } + + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _neighbor the first neighbor + */ + virtual void init(EOT & _solution, Neighbor & _neighbor) { + moRndWithoutReplNeighborhood::init(_solution, _neighbor); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution,0,1); + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPURndWithoutReplNeighborhood"; + } + + protected: + moGPUEvalByModif& eval; +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXBitFlippingNeighbor.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXBitFlippingNeighbor.h new file mode 100644 index 000000000..4cb649a65 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXBitFlippingNeighbor.h @@ -0,0 +1,101 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Boufaras Karima, Thé Van Luong + + 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 __moGPUXBitFlippingNeighbor_h +#define __moGPUXBitFlippingNeighbor_h + +#include +#include +#include + +/** + * A GPU X-BitFlipping Neighbor + */ + +template< class Fitness > +class moGPUXBitFlippingNeighbor:public moBackableNeighbor< moGPUBitVector > , + public moXChangeNeighbor< moGPUBitVector > { +public: + + typedef moGPUBitVector EOT ; + using moXChangeNeighbor::indices; + using moXChangeNeighbor::xChange; + using moXChangeNeighbor::key; + + /** + *Default Constructor + */ + + moGPUXBitFlippingNeighbor() : + moXChangeNeighbor () { + } + + /** + * Constructor + * @param _xFlip the number of bit to flip + */ + + moGPUXBitFlippingNeighbor(unsigned int _xFlip) : + moXChangeNeighbor (_xFlip) { + } + + /** + * Apply the K-Flip in solution + * @param _solution the solution to move + */ + + virtual void move(EOT& _solution) { + for (unsigned int i = 0; i < xChange; i++) + _solution[indices[i]] = !_solution[indices[i]]; + _solution.invalidate(); + + } + + /** + * apply the K-Flip to restore the solution (use by moFullEvalByModif) + * @param _solution the solution to move back + */ + + virtual void moveBack(EOT& _solution) { + move(_solution); + } + + /** + * Return the class name. + * @return the class name as a std::string + */ + + virtual std::string className() const { + return "moGPUXBitFlippingNeighbor"; + } + +}; + +#endif + diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhood.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhood.h new file mode 100644 index 000000000..1ea85aee7 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhood.h @@ -0,0 +1,110 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Karima Boufaras, Thé Van LUONG + + 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 __moGPUXChangeNeighborhood_h +#define __moGPUXChangeNeighborhood_h + +#include +#include + +template +class moGPUXChangeNeighborhood: public moXChangeNeighborhood { + +public: + + /** + * Define a Neighbor and type of a solution corresponding + */ + + typedef N Neighbor; + typedef typename Neighbor::EOT EOT; + + using moXChangeNeighborhood::neighborhoodSize; + using moXChangeNeighborhood::currentIndex; + using moXChangeNeighborhood::indices; + using moXChangeNeighborhood::mapping; + using moXChangeNeighborhood::xChange; + using moXChangeNeighborhood::mutex; + + /** + * Constructor + * @param _neighborhoodSize the neighborhood size + * @param _xChange the number of x-change positions + */ + + moGPUXChangeNeighborhood(unsigned int _neighborhoodSize, + unsigned int _xChange) : + moXChangeNeighborhood (_neighborhoodSize, _xChange) { + sendMapping = false; + cudaMalloc((void**) &device_Mapping, sizeof(unsigned int) + * neighborhoodSize * _xChange); + } + + + /** + *Destructor + */ + + ~moGPUXChangeNeighborhood() { + + cudaFree(device_Mapping); + } + + /** + * Initialization of the neighborhood and mapping on device + * @param _solution the solution to explore + * @param _current the first neighbor + */ + + virtual void init(EOT& _solution, Neighbor& _current) { + + moXChangeNeighborhood::init(_solution, _current); + if (!sendMapping) { + cudaMemcpy(device_Mapping, mapping, xChange * neighborhoodSize + * sizeof(unsigned int), cudaMemcpyHostToDevice); + sendMapping = true; + } + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUXChangeNeighborhood"; + } + +protected: + + bool sendMapping; + unsigned int * device_Mapping; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhoodByCpy.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhoodByCpy.h new file mode 100644 index 000000000..b417144b3 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhoodByCpy.h @@ -0,0 +1,97 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Boufaras Karima, Thé Van Luong + + 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 __moGPUXChangeNeighborhoodByCpy_h +#define __moGPUXChangeNeighborhoodByCpy_h + +#include +#include + +template +class moGPUXChangeNeighborhoodByCpy: public moGPUXChangeNeighborhood { + +public: + + /** + * Define a Neighbor and type of a solution corresponding + */ + + typedef N Neighbor; + typedef typename Neighbor::EOT EOT; + + /*A tester*/ + using moGPUXChangeNeighborhood::neighborhoodSize; + using moGPUXChangeNeighborhood::currentIndex; + using moGPUXChangeNeighborhood::indices; + using moGPUXChangeNeighborhood::mapping; + using moGPUXChangeNeighborhood::xChange; + using moGPUXChangeNeighborhood::mutex; + using moGPUXChangeNeighborhood::device_Mapping; + + /** + * Constructor + * @param _neighborhoodSize the neighborhood size + * @param _xChange the number of x-change positions + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + + moGPUXChangeNeighborhoodByCpy(unsigned int _neighborhoodSize, + unsigned int _xChange,moGPUEval& _eval) : + moGPUXChangeNeighborhood (_neighborhoodSize, _xChange), eval(_eval){ + } + + + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _current the first neighbor + */ + + virtual void init(EOT& _solution, Neighbor& _current) { + + moGPUXChangeNeighborhood::init(_solution, _current); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution, device_Mapping,1,1); + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUXChangeNeighborhoodByCpy"; + } + +protected: + + moGPUEval& eval; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhoodByModif.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhoodByModif.h new file mode 100644 index 000000000..c1cc224ad --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXChangeNeighborhoodByModif.h @@ -0,0 +1,96 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Karima Boufaras, Thé Van Luong + + 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 __moGPUXChangeNeighborhoodByModif_h +#define __moGPUXChangeNeighborhoodByModif_h + +#include +#include + +template +class moGPUXChangeNeighborhoodByModif: public moGPUXChangeNeighborhood { + +public: + + /** + * Define a Neighbor and type of a solution corresponding + */ + + typedef N Neighbor; + typedef typename Neighbor::EOT EOT; + + using moGPUXChangeNeighborhood::neighborhoodSize; + using moGPUXChangeNeighborhood::currentIndex; + using moGPUXChangeNeighborhood::indices; + using moGPUXChangeNeighborhood::mapping; + using moGPUXChangeNeighborhood::xChange; + using moGPUXChangeNeighborhood::mutex; + using moGPUXChangeNeighborhood::device_Mapping; + + /** + * Constructor + * @param _neighborhoodSize the neighborhood size + * @param _xChange the number of x-change positions + * @param _eval show how to evaluate neighborhood of a solution at one time + */ + + moGPUXChangeNeighborhoodByModif(unsigned int _neighborhoodSize, + unsigned int _xChange,moGPUEval& _eval) : + moGPUXChangeNeighborhood (_neighborhoodSize, _xChange), eval(_eval){ + } + + + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _current the first neighbor + */ + + virtual void init(EOT& _solution, Neighbor& _current) { + + moGPUXChangeNeighborhood::init(_solution, _current); + //Compute all neighbors fitness at one time + eval.neighborhoodEval(_solution, device_Mapping,0,1); + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUXChangeNeighborhoodByModif"; + } + +protected: + + moGPUEval& eval; + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXSwapNeighbor.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXSwapNeighbor.h new file mode 100644 index 000000000..5ddb2cb2a --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/neighborhood/moGPUXSwapNeighbor.h @@ -0,0 +1,108 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Boufaras Karima, Thé Van Luong + + 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 __moGPUXSwapNeighbor_h +#define __moGPUXSwapNeighbor_h +#include +#include +#include + +/** + * A GPU X-Swap Neighbor + */ + +template +class moGPUXSwapNeighbor: public moBackableNeighbor > , + public moXChangeNeighbor > { + +public: + + typedef moGPUPermutationVector EOT ; + using moXChangeNeighbor::indices; + using moXChangeNeighbor::xChange; + using moXChangeNeighbor::key; + + /** + *Default Constructor + */ + + moGPUXSwapNeighbor() : + moXChangeNeighbor () { + } + + /** + * Constructor + * @param _xSwap the number of swap to do + */ + + moGPUXSwapNeighbor(unsigned int _xSwap) : + moXChangeNeighbor (_xSwap) { + } + + /** + * Apply the K-swap + * @param _solution the solution to move + */ + virtual void move(EOT& _solution) { + EOT tmp(1); + for (unsigned int i = 0; i < xChange-1; i++) { + tmp[0] = _solution[indices[i]]; + _solution[indices[i]] = _solution[indices[i + 1]]; + _solution[indices[i + 1]] = tmp[0]; + } + _solution.invalidate(); + + } + + /** + * apply the K-swap to restore the solution (use by moFullEvalByModif) + * @param _solution the solution to move back + */ + virtual void moveBack(EOT& _solution) { + EOT tmp(1); + for (int i = xChange-1; i > 0; i--) { + tmp[0] = _solution[indices[i]]; + _solution[indices[i]] = _solution[indices[i - 1]]; + _solution[indices[i - 1]] = tmp[0]; + } + _solution.invalidate(); + } + + /** + * Return the class name. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moGPUXSwapNeighbor"; + } + +}; + +#endif +