diff --git a/branches/ParadisEO-GPU/tutorial/CMakeLists.txt b/branches/ParadisEO-GPU/tutorial/CMakeLists.txt new file mode 100644 index 000000000..263d57b41 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/CMakeLists.txt @@ -0,0 +1,6 @@ +ADD_SUBDIRECTORY(OneMax) +ADD_SUBDIRECTORY(Kswap-OneMax) +ADD_SUBDIRECTORY(PPP_GPU) +ADD_SUBDIRECTORY(QAP_GPU) +ADD_SUBDIRECTORY(QAP_CPU) + diff --git a/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/CMakeLists.txt b/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/CMakeLists.txt new file mode 100644 index 000000000..170f43cfa --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/CMakeLists.txt @@ -0,0 +1,50 @@ +############################################################################### +## +## CMakeLists file for OneMax Example/application +## +############################################################################### + + +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES( + + # include CUDA source directory + ${CUDA_SRC_DIR} + # include EO source directory + ${PARADISEO_EO_SRC_DIR}/src + # include MO source directory + ${PARADISEO_MO_SRC_DIR}/src + # include problems directory + ${PARADISEO_PROBLEMS_SRC_DIR} + # include GPU directory + ${PARADISEO_GPU_SRC_DIR} + # include your source directory + ${CMAKE_CURRENT_SOURCE_DIR}/../src + ) + +###################################################################################### + +###################################################################################### +### 2) Specify where CMake can find the libraries +###################################################################################### + +LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${CUDA_LIB_DIR} ) + +###################################################################################### + +###################################################################################### +### 3) Define your targets and link the librairies +###################################################################################### + +CUDA_ADD_EXECUTABLE(GPUtestKswapHCByModif testKswapHCByModif.cu) +CUDA_ADD_EXECUTABLE(GPUtestKswapHCByCpy testKswapHCByCpy.cu) + +TARGET_LINK_LIBRARIES(GPUtestKswapHCByModif eoutils ga eo) +TARGET_LINK_LIBRARIES(GPUtestKswapHCByCpy eoutils ga eo) + + + +###################################################################################### diff --git a/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/moGPUConfig.h b/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/moGPUConfig.h new file mode 100644 index 000000000..8cbc8ed2a --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/moGPUConfig.h @@ -0,0 +1,50 @@ +/* + + 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 __moGPUConfig_H +#define __moGPUConfig_H + +#define BLOCK_SIZE 8 +#ifndef NB_POS +#define NB_POS 2 +#endif +#ifndef SIZE +#define SIZE 60 +#endif +#endif + + + + + diff --git a/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/testKswapHCByCpy.cu b/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/testKswapHCByCpy.cu new file mode 100644 index 000000000..72affd32b --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/testKswapHCByCpy.cu @@ -0,0 +1,210 @@ +/* + + 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 +*/ + +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" +// The general include for eo +#include +#include +// OneMax full eval function +#include +// OneMax incremental eval function +#include +#include +// One Max solution +#include +// One Max neighbor +#include +//To compute execution time +#include +//Utils to compute size Mapping of x-change position +#include +// Use an ordered neighborhood without mapping, with local copy of solution +#include +// The Solution and neighbor comparator +#include +#include +// The continuator +#include +// Local search algorithm +#include +// The simple HC algorithm explorer +#include + +// REPRESENTATION +typedef moGPUBitVector solution; +typedef moGPUXBitFlippingNeighbor Neighbor; +typedef moGPUXChangeNeighborhoodByCpy Neighborhood; + +void main_function(int argc, char **argv) +{ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(SIZE); + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + EvalOneMax eval; + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + unsigned long int sizeMap=sizeMapping(SIZE,NB_POS); + OneMaxIncrEval incr_eval; + moGPUMappingEvalByCpy > cueval(sizeMap,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(sizeMap,NB_POS,cueval); + + /* ========================================================= + * + * An explorer of solution neighborhood's + * + * ========================================================= */ + + moSimpleHCexplorer explorer(neighborhood, cueval, + comparator, solComparator); + + /* ========================================================= + * + * The local search algorithm + * + * ========================================================= */ + + //True continuator <=> Always continue + moTrueContinuator continuator; + moLocalSearch localSearch(explorer,continuator, eval); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + // Create timer for timing CUDA calculation + moGPUTimer timer; + timer.start(); + localSearch(sol); + timer.stop(); + std::cout << "final: " << sol<< std::endl; + printf("Execution time = %f ms\n",timer.getTime()); +} + +// A main that catches the exceptions + +int main(int argc, char **argv) +{ + try{ + main_function(argc, argv); + } + catch(exception& e){ + cout << "Exception: " << e.what() << '\n'; + } + return 1; +} diff --git a/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/testKswapHCByModif.cu b/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/testKswapHCByModif.cu new file mode 100644 index 000000000..4a00f7c92 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/Kswap-OneMax/testKswapHCByModif.cu @@ -0,0 +1,220 @@ +/* + + 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 +*/ + +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" +// The general include for eo +#include +#include +// OneMax full eval function +#include +// OneMax incremental eval function +#include +#include +// One Max solution +#include +// One Max neighbor +#include +//To compute execution time +#include +//Utils to compute size Mapping of x-change position +#include +// One Max ordered neighborhood +#include +// The Solution and neighbor comparator +#include +#include +// The continuator +#include +// Local search algorithm +#include +// The simple HC algorithm explorer +#include + +// REPRESENTATION +typedef moGPUBitVector solution; +typedef moGPUXBitFlippingNeighbor Neighbor; +typedef moGPUXChangeNeighborhoodByModif Neighborhood; + +void main_function(int argc, char **argv) +{ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // description of genotype + /*eoValueParam vecSizeParam(100, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value();*/ + + //Number of position to change + /* eoValueParam nbPosParam(1, "nbPos", "X Change", 'N'); + parser.processParam( nbPosParam, "Exchange" ); + unsigned nbPos = nbPosParam.value();*/ + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(SIZE); + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + EvalOneMax eval; + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + unsigned long int sizeMap=sizeMapping(SIZE,NB_POS); + OneMaxIncrEval incr_eval; + moGPUMappingEvalByModif > cueval(sizeMap,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(sizeMap,NB_POS,cueval); + + /* ========================================================= + * + * An explorer of solution neighborhood's + * + * ========================================================= */ + + moSimpleHCexplorer explorer(neighborhood, cueval, + comparator, solComparator); + + /* ========================================================= + * + * The local search algorithm + * + * ========================================================= */ + + //True continuator <=> Always continue + moTrueContinuator continuator; + moLocalSearch localSearch(explorer,continuator, eval); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + // Create timer for timing CUDA calculation + moGPUTimer timer; + timer.start(); + localSearch(sol); + timer.stop(); + std::cout << "final: " << sol<< std::endl; + printf("Execution time = %f ms\n",timer.getTime()); +} + +// A main that catches the exceptions + +int main(int argc, char **argv) +{ + try{ + main_function(argc, argv); + } + catch(exception& e){ + cout << "Exception: " << e.what() << '\n'; + } + return 1; +} diff --git a/branches/ParadisEO-GPU/tutorial/OneMax/CMakeLists.txt b/branches/ParadisEO-GPU/tutorial/OneMax/CMakeLists.txt new file mode 100644 index 000000000..1d3422c68 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/OneMax/CMakeLists.txt @@ -0,0 +1,56 @@ +############################################################################### +## +## CMakeLists file for OneMax Example/application +## +############################################################################### + + +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES( + + # include CUDA source directory + ${CUDA_SRC_DIR} + # include EO source directory + ${PARADISEO_EO_SRC_DIR}/src + # include MO source directory + ${PARADISEO_MO_SRC_DIR}/src + # include problems directory + ${PARADISEO_PROBLEMS_SRC_DIR} + # include GPU directory + ${PARADISEO_GPU_SRC_DIR} + # include your source directory + ${CMAKE_CURRENT_SOURCE_DIR}/../src + ) + +###################################################################################### + +###################################################################################### +### 2) Specify where CMake can find the libraries +###################################################################################### + +LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${CUDA_LIB_DIR} ) + +###################################################################################### + +###################################################################################### +### 3) Define your targets and link the librairies +###################################################################################### + +CUDA_ADD_EXECUTABLE(GPUtestFirstImpr testFirstImpr.cu) +CUDA_ADD_EXECUTABLE(GPUtestNeutralHC testNeutralHC.cu) +CUDA_ADD_EXECUTABLE(GPUtestSimpleHC testSimpleHC.cu) +CUDA_ADD_EXECUTABLE(GPUtestSimpleHCByCpy testSimpleHCByCpy.cu) +CUDA_ADD_EXECUTABLE(GPUtestSimpleTS testSimpleTS.cu) +CUDA_ADD_EXECUTABLE(GPUtestSimulatedAnnealing testSimulatedAnnealing.cu) + +TARGET_LINK_LIBRARIES(GPUtestFirstImpr eoutils ga eo) +TARGET_LINK_LIBRARIES(GPUtestNeutralHC eoutils ga eo) +TARGET_LINK_LIBRARIES(GPUtestSimpleHC eoutils ga eo) +TARGET_LINK_LIBRARIES(GPUtestSimpleHCByCpy eoutils ga eo) +TARGET_LINK_LIBRARIES(GPUtestSimpleTS eoutils ga eo) +TARGET_LINK_LIBRARIES(GPUtestSimulatedAnnealing eoutils ga eo) + +###################################################################################### diff --git a/branches/ParadisEO-GPU/tutorial/OneMax/moGPUConfig.h b/branches/ParadisEO-GPU/tutorial/OneMax/moGPUConfig.h new file mode 100644 index 000000000..726e0db0d --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/OneMax/moGPUConfig.h @@ -0,0 +1,50 @@ +/* + + 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 __moGPUConfig_H +#define __moGPUConfig_H + +#define BLOCK_SIZE 8 +#ifndef NB_POS +#define NB_POS 1 +#endif +#ifndef SIZE +#define SIZE 60 +#endif +#endif + + + + + diff --git a/branches/ParadisEO-GPU/tutorial/OneMax/testFirstImpr.cu b/branches/ParadisEO-GPU/tutorial/OneMax/testFirstImpr.cu new file mode 100644 index 000000000..b57ab02fc --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/OneMax/testFirstImpr.cu @@ -0,0 +1,241 @@ +/* + + 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 +*/ + +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" +// The general include for eo +#include +#include +// OneMax full eval function +#include +//Parallel evaluation of neighborhood on GPU +#include +// OneMax increment evaluation function +#include +// One Max solution +#include +// Bit neighbor +#include +// Ordered neighborhood +#include +// The Solution and neighbor comparator +#include +#include +// The continuator +#include +// Local search algorithm +#include +// First improvment algorithm +#include +// The First Improvment algorithm explorer +#include +//To compute execution time +#include + +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ + +typedef moGPUBitVector solution; +typedef moGPUBitNeighbor Neighbor; +typedef moGPUOrderNeighborhoodByModif Neighborhood; + +void main_function(int argc, char **argv) +{ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll always get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(SIZE); + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + EvalOneMax eval; + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + OneMaxIncrEval incr_eval; + moGPUEvalByModif > gpuEval(SIZE,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(SIZE,gpuEval); + + /* ========================================================= + * + * An explorer of solution neighborhood's + * + * ========================================================= */ + + moFirstImprHCexplorer explorer(neighborhood, gpuEval, comparator, solComparator); + + + /* ========================================================= + * + * The local search algorithm + * + * ========================================================= */ + // True continuator <=> Always continue + + moTrueContinuator continuator; + + moLocalSearch localSearch(explorer,continuator, eval); + + /* ========================================================= + * + * The First improvment algorithm + * + * ========================================================= */ + + moFirstImprHC firstImprHC(neighborhood,eval,gpuEval); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + moGPUTimer timer; + timer.start(); + localSearch(sol); + timer.stop(); + std::cout << "final: " << sol << std::endl; + printf("Execution time = %.2lf s\n",timer.getTime()); + + /* ========================================================= + * + * Execute the first improvment from random sollution + * + * ========================================================= */ + + solution sol1(SIZE); + eval(sol1); + std::cout<< std::endl; + std::cout << "initial: " << sol1<< std::endl; + + moGPUTimer timer1; + timer1.start(); + firstImprHC(sol1); + timer1.stop(); + std::cout << "final: " << sol1 << std::endl; + printf("Execution time = %.2lf s\n",timer1.getTime()); + +} + +// A main that catches the exceptions + +int main(int argc, char **argv) +{ + try{ + main_function(argc, argv); + } + catch(exception& e){ + cout << "Exception: " << e.what() << '\n'; + } + return 1; +} diff --git a/branches/ParadisEO-GPU/tutorial/OneMax/testNeutralHC.cu b/branches/ParadisEO-GPU/tutorial/OneMax/testNeutralHC.cu new file mode 100644 index 000000000..9973e7bb9 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/OneMax/testNeutralHC.cu @@ -0,0 +1,208 @@ +/* + + 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 +*/ + +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" +// The general include for eo +#include +#include +// OneMax full eval function +#include +//Parallel evaluation of neighborhood on GPU +#include +// OneMax increment evaluation function +#include +// One Max solution +#include +// Bit neighbor +#include +// Ordered neighborhood +#include +// The Solution and neighbor comparator +#include +#include +// The continuator +#include +// Neutral HC algorithm +#include +//To compute execution time +#include + +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ + +typedef moGPUBitVector solution; +typedef moGPUBitNeighbor Neighbor; +typedef moGPUOrderNeighborhoodByModif Neighborhood; + +void main_function(int argc, char **argv) +{ + + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + //nbStep maximum step to do + eoValueParam nbStepParam(10, "nbStep", "maximum number of step", 'n'); + parser.processParam( nbStepParam, "numberStep" ); + unsigned nbStep = nbStepParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(SIZE); + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + EvalOneMax eval; + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + OneMaxIncrEval incr_eval; + moGPUEvalByModif > gpuEval(SIZE,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(SIZE,gpuEval); + + /* ========================================================= + * + * The neutral Hill Climbing algorithm + * + * ========================================================= */ + //True continuator <=> Always continue + + moTrueContinuator continuator; + + moNeutralHC neutralHC(neighborhood,eval,gpuEval,nbStep,continuator); + + /* ========================================================= + * + * Execute the neutral Hill climbing from random sollution + * + * ========================================================= */ + + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + moGPUTimer timer; + timer.start(); + neutralHC(sol); + timer.stop(); + std::cout << "final: " << sol << std::endl; + printf("Execution time = %.2lf s\n",timer.getTime()); + +} + +// A main that catches the exceptions + +int main(int argc, char **argv) +{ + try{ + main_function(argc, argv); + } + catch(exception& e){ + cout << "Exception: " << e.what() << '\n'; + } + return 1; +} diff --git a/branches/ParadisEO-GPU/tutorial/OneMax/testSimpleHC.cu b/branches/ParadisEO-GPU/tutorial/OneMax/testSimpleHC.cu new file mode 100644 index 000000000..fd52384ea --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/OneMax/testSimpleHC.cu @@ -0,0 +1,243 @@ +/* + + 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 +*/ + + +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" +// The general include for eo +#include +#include +// OneMax full eval function +#include +//Parallel evaluation of neighborhood on GPU +#include +// OneMax increment evaluation function +#include +// One Max solution +#include +// Bit neighbor +#include +// Ordered neighborhood +#include +// The Solution and neighbor comparator +#include +#include +// The continuator +#include +// Local search algorithm +#include +// Simple HC algorithm +#include +// The simple HC algorithm explorer +#include +//To compute execution time +#include + +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ + +typedef moGPUBitVector solution; +typedef moGPUBitNeighbor Neighbor; +typedef moGPUOrderNeighborhoodByModif Neighborhood; + +void main_function(int argc, char **argv) +{ + + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(SIZE); + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + EvalOneMax eval; + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + OneMaxIncrEval incr_eval; + moGPUEvalByModif > cueval(SIZE,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(SIZE,cueval); + + /* ========================================================= + * + * An explorer of solution neighborhood's + * + * ========================================================= */ + + moSimpleHCexplorer explorer(neighborhood, cueval, + comparator, solComparator); + + /* ========================================================= + * + * The local search algorithm + * + * ========================================================= */ + //True continuator <=> Always continue + + moTrueContinuator continuator; + + moLocalSearch localSearch(explorer,continuator, eval); + + /* ========================================================= + * + * The simple Hill Climbing algorithm + * + * ========================================================= */ + + moSimpleHC simpleHC(neighborhood,eval,cueval); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + // Create timer for timing CUDA calculation + moGPUTimer timer; + timer.start(); + localSearch(sol); + timer.stop(); + std::cout << "final: " << sol << std::endl; + printf("Execution time = %0.2lf s\n",timer.getTime()); + + + /* ========================================================= + * + * Execute the Simple Hill climbing from random sollution + * + * ========================================================= */ + cout< + 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 +*/ + + +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" +// The general include for eo +#include +#include +// One Max full eval function +#include +//Parallel evaluation of neighborhood on GPU +#include +// One Max increment evaluation function +#include +// One Max solution +#include +// Bit neighbor +#include +// Ordered neighborhood +#include +// The Solution and neighbor comparator +#include +#include +// The continuator +#include +// Local search algorithm +#include +// Simple HC algorithm +#include +// The simple HC algorithm explorer +#include +//To compute execution time +#include + +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ + +typedef moGPUBitVector solution; +typedef moGPUBitNeighbor Neighbor; +typedef moGPUOrderNeighborhoodByCpy Neighborhood; + +void main_function(int argc, char **argv) +{ + + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + srand(seed); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(SIZE); + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + EvalOneMax eval; + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + OneMaxIncrEval incr_eval; + moGPUEvalByCpy > gpuEval(SIZE,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(SIZE,gpuEval); + + /* ========================================================= + * + * An explorer of solution neighborhood's + * + * ========================================================= */ + + moSimpleHCexplorer explorer(neighborhood, gpuEval, + comparator, solComparator); + + /* ========================================================= + * + * The local search algorithm + * + * ========================================================= */ + //True continuator <=> Always continue + + moTrueContinuator continuator; + + moLocalSearch localSearch(explorer,continuator, eval); + + /* ========================================================= + * + * The simple Hill Climbing algorithm + * + * ========================================================= */ + + moSimpleHC simpleHC(neighborhood,eval,gpuEval); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + // Create timer for timing GPU calculation + moGPUTimer timer; + timer.start(); + //Run the local search with Simple Hill climbing explorer + localSearch(sol); + timer.stop(); + std::cout << "final: " << sol << std::endl; + printf("Execution time = %0.2lf s\n",timer.getTime()); + + /* ========================================================= + * + * Execute the Simple Hill climbing from random sollution + * + * ========================================================= */ + cout< + 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 +*/ + +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" +// The general include for eo +#include +#include +// OneMax full eval function +#include +//Parallel evaluation of neighborhood on GPU +#include +// OneMax increment evaluation function +#include +// One Max solution +#include +// Bit neighbor +#include +// Ordered neighborhood +#include +// The Solution and neighbor comparator +#include +#include +// The time continuator +#include +// Local search algorithm +#include +// The Tabou Search algorithm explorer +#include +//Algorithm and its components +#include +//Tabu list +#include +//Memories +#include +#include +#include +//To compute execution time +#include + + +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ + +typedef moGPUBitVector solution; +typedef moGPUBitNeighbor Neighbor; +typedef moGPUOrderNeighborhoodByModif Neighborhood; + + +void main_function(int argc, char **argv) +{ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // size tabu list + eoValueParam sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T'); + parser.processParam( sizeTabuListParam, "Search Parameters" ); + unsigned sizeTabuList = sizeTabuListParam.value(); + + // time Limit + eoValueParam timeLimitParam(1, "timeLimit", "time limits", 't'); + parser.processParam( timeLimitParam, "Search Parameters" ); + unsigned timeLimit = timeLimitParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + EvalOneMax eval; + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + OneMaxIncrEval incr_eval; + moGPUEvalByModif > gpuEval(SIZE,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(SIZE,gpuEval); + + /* ========================================================= + * + * continuator + * + * ========================================================= */ + + moTimeContinuator continuator(timeLimit); + + /* ========================================================= + * + * tabu list + * + * ========================================================= */ + + moNeighborVectorTabuList tl(sizeTabuList,0); + + /* ========================================================= + * + * Memories + * + * ========================================================= */ + + moDummyIntensification inten; + moDummyDiversification div; + moBestImprAspiration asp; + + /* ========================================================= + * + * An explorer of solution neighborhood's + * + * ========================================================= */ + + moTSexplorer explorer(neighborhood, gpuEval, comparator, solComparator, tl, inten, div, asp); + + + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ + + moLocalSearch localSearch1(explorer, continuator, eval); + + //Basic Constructor + moTS localSearch2(neighborhood,eval, gpuEval, 2, 7); + + //Simple Constructor + moTS localSearch3(neighborhood, eval, gpuEval, 5, tl); + + //General Constructor + moTS localSearch4(neighborhood, eval, gpuEval, comparator, solComparator, continuator, tl, inten, div, asp); + + /* ========================================================= + * + * Execute the local search(TS) from random sollution + * + * ========================================================= */ + + //Initilisation of the solution + solution sol1(SIZE); + eval(sol1); + std::cout << "\nTabu Search 1:" << std::endl; + std::cout << "---------------------" << std::endl; + std::cout << "initial: " << sol1<< std::endl; + moGPUTimer timer1; + timer1.start(); + localSearch1(sol1); + timer1.stop(); + std::cout << "final: " << sol1 < + 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 +*/ + +//Init the number of threads per block +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" +// The general include for eo +#include +#include +// OneMax full eval function +#include +//Parallel evaluation of neighborhood on GPU +#include +// OneMax increment eval function +#include +// One Max solution +#include +// Bit neighbor +#include +// Random with replacement neighborhood +#include +// The Solution and neighbor comparator +#include +#include +//To compute execution time +#include +//Algorithm and its components +#include +#include +// The simulated annealing algorithm explorer +#include +//continuators +#include +#include +#include +#include +#include + +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ + +typedef moGPUBitVector solution; +typedef moGPUBitNeighbor Neighbor; +typedef moGPURndWithReplNeighborhoodByModif Neighborhood; + +void main_function(int argc, char **argv) +{ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll always get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(SIZE); + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + EvalOneMax eval; + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + OneMaxIncrEval incr_eval; + moGPUEvalByModif > gpuEval(SIZE,incr_eval); + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(SIZE,gpuEval); + + /* ========================================================= + * + * the cooling schedule of the process + * + * ========================================================= */ + + + // initial temp, factor of decrease, number of steps without decrease, final temp. + moSimpleCoolingSchedule coolingSchedule(500, 0.9, 1000, 0.01); + + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ + + moSA SA(neighborhood, eval, gpuEval,coolingSchedule); + + /* ========================================================= + * + * execute the local search from random solution + * + * ========================================================= */ + + //init(solution); + eval(sol); + std::cout << "initial : " << sol << std::endl; + moGPUTimer timer; + timer.start(); + SA(sol); + timer.stop(); + std::cout << "final : " << sol << std::endl; + printf("Execution time = %.2lf s\n",timer.getTime()); + +} + +// A main that catc hes the exceptions + +int main(int argc, char **argv) +{ + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; +} diff --git a/branches/ParadisEO-GPU/tutorial/PPP_GPU/CMakeLists.txt b/branches/ParadisEO-GPU/tutorial/PPP_GPU/CMakeLists.txt new file mode 100644 index 000000000..3dffa681e --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/PPP_GPU/CMakeLists.txt @@ -0,0 +1,47 @@ +############################################################################## +## +## CMakeLists file for OneMax Example/application +## +############################################################################### + + +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES( + + # include CUDA source directory + ${CUDA_SRC_DIR} + # include EO source directory + ${PARADISEO_EO_SRC_DIR}/src + # include MO source directory + ${PARADISEO_MO_SRC_DIR}/src + # include problems directory + ${PARADISEO_PROBLEMS_SRC_DIR} + # include GPU directory + ${PARADISEO_GPU_SRC_DIR} + # include your source directory + ${CMAKE_CURRENT_SOURCE_DIR}/../src + ) + +###################################################################################### + +###################################################################################### +### 2) Specify where CMake can find the libraries +###################################################################################### + +LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${CUDA_LIB_DIR} ) + +###################################################################################### + +###################################################################################### +### 3) Define your targets and link the librairies +###################################################################################### + +CUDA_ADD_EXECUTABLE(GPUtestSimpleTS_PPP testSimpleTS_PPP.cu) + +TARGET_LINK_LIBRARIES(GPUtestSimpleTS_PPP eoutils ga eo) + + + diff --git a/branches/ParadisEO-GPU/tutorial/PPP_GPU/moGPUConfig.h b/branches/ParadisEO-GPU/tutorial/PPP_GPU/moGPUConfig.h new file mode 100644 index 000000000..d556dfd08 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/PPP_GPU/moGPUConfig.h @@ -0,0 +1,56 @@ +/* + + 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 __moGPUConfig_H +#define __moGPUConfig_H + +#define BLOCK_SIZE 8 +#ifndef NB_POS +#define NB_POS 2 +#endif +#ifndef SIZE +#define SIZE 73 + +#define Nd 73 +#define Md 73 +#define ca 30 +#define cb 1 + +#endif +#endif + + + + + diff --git a/branches/ParadisEO-GPU/tutorial/PPP_GPU/testSimpleTS_PPP.cu b/branches/ParadisEO-GPU/tutorial/PPP_GPU/testSimpleTS_PPP.cu new file mode 100644 index 000000000..b3fc250ee --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/PPP_GPU/testSimpleTS_PPP.cu @@ -0,0 +1,252 @@ +/* + + 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 +*/ + +#include "moGPUConfig.h" +#include +#include +#include +using namespace std; + +__device__ int * dev_a; +__device__ int * dev_h; + +// The general include for eo +#include +#include +// Fitness function +#include +// GPU Fitness function +#include +#include +//Specific data to PPP problem +#include +// PPP solution +#include +// PPP neighbor +#include +//To compute execution time +#include +//Utils to compute size Mapping of x-change position +#include +//x-Change neighborhood +#include +// The Solution and neighbor comparator +#include +#include +// The Iter continuator +#include +// The Tabou Search algorithm +#include +//Tabu list +#include +//Memories +#include +#include +#include + +typedef PPPSolution solution; +typedef PPPNeighbor Neighbor; +typedef moGPUXChangeNeighborhoodByModif Neighborhood; + + +int main(int argc, char **argv) +{ + + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // Iteration number + eoValueParam nbIterationParam(1, "nbIteration", "TS Iteration number", 'I'); + parser.processParam( nbIterationParam, "TS Iteration number" ); + unsigned nbIteration = nbIterationParam.value(); + + // size tabu list + eoValueParam sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T'); + parser.processParam( sizeTabuListParam, "Search Parameters" ); + unsigned sizeTabuList = sizeTabuListParam.value(); + + // duration tabu list + eoValueParam durationParam(7, "duration", "duration of the tabu list", 'D'); + parser.processParam( durationParam, "Search Parameters" ); + unsigned duration = durationParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of QAP data + * + * ========================================================= */ + + PPPData _data; + _data.load(); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(Nd); + _data.GPUObject.memCopyGlobalVariable(dev_a,_data.a_d); + _data.GPUObject.memCopyGlobalVariable(dev_h,_data.H_d); + + /*========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + PPPEval eval(_data); + unsigned long int sizeMap=sizeMapping(Nd,NB_POS); + PPPIncrEval incr_eval; + moGPUMappingEvalByModif > cueval(sizeMap,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(sizeMap,NB_POS,cueval); + + /* ========================================================= + * + * continuator + * + * ========================================================= */ + + moIterContinuator continuator(nbIteration); + + /* ========================================================= + * + * tabu list + * + * ========================================================= */ + + sizeTabuList=sizeMap; + duration=sizeTabuList/8; + // tabu list + moIndexedVectorTabuList tl(sizeTabuList,duration); + + /* ========================================================= + * + * Memories + * + * ========================================================= */ + + moDummyIntensification inten; + moDummyDiversification div; + moBestImprAspiration asp; + + /* ========================================================= + * + * The Tabu search algorithm + * + * ========================================================= */ + + moTS tabuSearch(neighborhood, eval, cueval, comparator, solComparator, continuator, tl, inten, div, asp); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + moGPUTimer timer; + timer.start(); + tabuSearch(sol); + std::cout << "final: " << sol << std::endl; + timer.stop(); + printf("Execution time = %.2lf s\n",timer.getTime()); + + + _data.GPUObject.free(dev_a); + _data.GPUObject.free(dev_h); + + return 0; +} diff --git a/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/CMakeLists.txt b/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/CMakeLists.txt new file mode 100644 index 000000000..9e68a1683 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/CMakeLists.txt @@ -0,0 +1,39 @@ +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES( + + # include CUDA source directory + ${CUDA_SRC_DIR} + # include EO source directory + ${PARADISEO_EO_SRC_DIR}/src + # include MO source directory + ${PARADISEO_MO_SRC_DIR}/src + # include problems directory + ${PARADISEO_PROBLEMS_SRC_DIR} + # include GPU directory + ${PARADISEO_GPU_SRC_DIR} + # include your source directory + ${CMAKE_CURRENT_SOURCE_DIR}/../src + ) + +###################################################################################### + +###################################################################################### +### 2) Specify where CMake can find the libraries +###################################################################################### + +LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${CUDA_LIB_DIR} ) + +###################################################################################### + +###################################################################################### +### 3) Define your targets and link the librairies +###################################################################################### + +CUDA_ADD_EXECUTABLE(CutestSimpleTS_CPU testSimpleTS_CPU.cu) +CUDA_ADD_EXECUTABLE(CutestSimpleHC_CPU testSimpleHC_CPU.cu) + +TARGET_LINK_LIBRARIES(CutestSimpleTS_CPU eoutils ga eo) +TARGET_LINK_LIBRARIES(CutestSimpleHC_CPU eoutils ga eo) \ No newline at end of file diff --git a/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/testSimpleHC_CPU.cu b/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/testSimpleHC_CPU.cu new file mode 100644 index 000000000..68dfa07c9 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/testSimpleHC_CPU.cu @@ -0,0 +1,217 @@ +/* + + 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 +*/ + +#include +#include +#include +using namespace std; + +//Specific data problem +unsigned * a; +unsigned * b; +unsigned n; + +// The general include for eo +#include +#include +// Fitness function +#include +// Cuda Fitness function +#include +// QAP solution +#include +#include +//QAP neighbor +#include +//QAP neighborhood +#include +//QAP data +#include +// The Solution and neighbor comparator +#include +#include +// The Iter continuator +#include +// Local search algorithm +#include +// The Tabou Search algorithm explorer +#include +//To compute execution time +#include + + +typedef eoInt solution; +typedef moIndexedSwapNeighbor Neighbor; +typedef moOrderNeighborhood Neighborhood; + + +int main(int argc, char **argv) +{ + + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of QAP data + * + * ========================================================= */ + + load(argv[1]); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + eoInitPermutation init(n); + solution sol; + init(sol); + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + QapEval eval; + QapIncrEval incr_eval; + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood((n*(n-1))/2); + + /* ========================================================= + * + * continuator + * + * ========================================================= */ + + moTrueContinuator continuator; + + /* ========================================================= + * + * An explorer of solution neighborhood's + * + * ========================================================= */ + + moSimpleHCexplorer explorer(neighborhood, incr_eval, comparator, solComparator); + + + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ + + moLocalSearch localSearch(explorer, continuator, eval); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + // Create timer for timing CUDA calculation + moGPUTimer timer; + timer.start(); + localSearch(sol); + timer.stop(); + std::cout << "final: " << sol << std::endl; + printf("CUDA execution time = %f ms\n",timer.getTime()); + timer.deleteTimer(); + + delete[] a; + delete[] b; + + + return 0; +} diff --git a/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/testSimpleTS_CPU.cu b/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/testSimpleTS_CPU.cu new file mode 100644 index 000000000..8ec4eb52f --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_CPU/application/testSimpleTS_CPU.cu @@ -0,0 +1,251 @@ +/* + + 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 +*/ + +#include +#include +#include +using namespace std; + +//Specific data problem +unsigned * a; +unsigned * b; +unsigned n; + +// The general include for eo +#include +#include +// Fitness function +#include +// Cuda Fitness function +#include +// QAP solution +#include +#include +//QAP neighbor +#include +//QAP neighborhood +#include +//QAP data +#include +// The Solution and neighbor comparator +#include +#include +// The Iter continuator +#include +// Local search algorithm +#include +//Algorithm and its components +#include +//Tabu list +#include +//Memories +#include +#include +#include +//To compute execution time +#include + +typedef eoInt solution; +typedef moIndexedSwapNeighbor Neighbor; +typedef moOrderNeighborhood Neighborhood; + +int main(int argc, char **argv) +{ + + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // Iteration number + eoValueParam nbIterationParam(1, "nbIteration", "TS Iteration number", 'I'); + parser.processParam( nbIterationParam, "TS Iteration number" ); + unsigned nbIteration = nbIterationParam.value(); + + // size tabu list + eoValueParam sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T'); + parser.processParam( sizeTabuListParam, "Search Parameters" ); + unsigned sizeTabuList = sizeTabuListParam.value(); + + // duration tabu list + eoValueParam durationParam(7, "duration", "duration of the tabu list", 'D'); + parser.processParam( durationParam, "Search Parameters" ); + unsigned duration = durationParam.value(); + + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of QAP data + * + * ========================================================= */ + + load(argv[1]); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + eoInitPermutation init(n); + solution sol; + init(sol); + + /*========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + QapEval eval; + QapIncrEval incr_eval; + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(n*(n-1)/2); + + /* ========================================================= + * + * continuator + * + * ========================================================= */ + + moIterContinuator continuator(nbIteration); + + /*========================================================= + * + * Tabu list + * + * ========================================================= */ + + sizeTabuList=(n*(n-1))/2; + duration=sizeTabuList/8; + // tabu list + moIndexedVectorTabuList tl(sizeTabuList,duration); + + /* ========================================================= + * + * Memories + * + * ========================================================= */ + + moDummyIntensification inten; + moDummyDiversification div; + moBestImprAspiration asp; + + /* ========================================================= + * + * the Tabu search algorithm + * + * ========================================================= */ + + //General Constructor + moTS tabuSearch(neighborhood, eval, incr_eval, comparator, solComparator, continuator, tl, inten, div, asp); + + /* ========================================================= + * + * Execute the Tabu search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + // Create timer for timing CUDA calculation + moGPUTimer timer; + timer.start(); + tabuSearch(sol); + timer.stop(); + std::cout << "final: " << sol << std::endl; + printf("CUDA execution time = %f ms\n",timer.getTime()); + timer.deleteTimer(); + + delete[] a; + delete[] b; + + +return 0; +} diff --git a/branches/ParadisEO-GPU/tutorial/QAP_CPU/src/Problem.h b/branches/ParadisEO-GPU/tutorial/QAP_CPU/src/Problem.h new file mode 100644 index 000000000..86f645e0c --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_CPU/src/Problem.h @@ -0,0 +1,62 @@ +/* + + 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 __Problem +#define __Problem +/** + * Function to load a QAP data from a specific file + * @param _fileName the name of file containing specific QAP data + */ + +void load(char * _fileName) { + + fstream file(_fileName, ios::in); + if (!file) { + + string str = "QAPData: Could not open file [" + (string)_fileName + "]."; + throw runtime_error(str); + } + unsigned i, j; + file >> n; + a = new unsigned[n * n]; + b = new unsigned[n * n]; + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + file >> a[i * n + j]; + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + file >> b[i * n + j]; +} + +#endif diff --git a/branches/ParadisEO-GPU/tutorial/QAP_CPU/src/QapEval.h b/branches/ParadisEO-GPU/tutorial/QAP_CPU/src/QapEval.h new file mode 100644 index 000000000..223bdcbf1 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_CPU/src/QapEval.h @@ -0,0 +1,75 @@ +/* + + 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 __QapEval +#define __QapEval + +/** + * Full Evaluation of QAP + */ + +template +class QapEval : public eoEvalFunc +{ + + public: + + /** + * Constructor + */ + + QapEval(){} + + /** + * Destructor + */ + + ~QapEval(){} + + /** + * Functor for full evaluation of the solution + * @param _sol the solution to evaluate + */ + + void operator() (EOT & _sol) { + int cost=0; + for (int i=0; i + 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 __QapIncrEval +#define __QapIncrEval + +#include + +/** + * Incremental Evaluation of QAP + */ + +template +class QapIncrEval : public moEval{ + + public: + + typedef typename moEval::EOT EOT; + typedef typename moEval::Fitness Fitness; + + /** + * Constructor + */ + + QapIncrEval(){} + + /** + * Destructor + */ + + ~QapIncrEval(){} + + /** + * Functor for incremental evaluation of the solution + * @param _sol the solution + * @param _neighbor the neighbor of solution to evaluate + */ + + void operator() (EOT & _sol, Neighbor & _neighbor){ + + unsigned int cost=0; + unsigned i,j; + _neighbor.getIndices(n,i,j); + cost = _sol.fitness() +compute_delta(_sol,i,j); + _neighbor.fitness(cost); + } + + /** + * Specific to the QAP incremental evaluation (part of algorithmic) + * @param _sol the solution to evaluate + * @param i the first position of swap + * @param j the second position of swap + */ + + unsigned int compute_delta(EOT & _sol,unsigned i,unsigned j) + { + int d; + int k; + + d = (a[i*n+i]-a[j*n+j])*(b[_sol[j]*n+_sol[j]]-b[_sol[i]*n+_sol[i]]) + + (a[i*n+j]-a[j*n+i])*(b[_sol[j]*n+_sol[i]]-b[_sol[i]*n+_sol[j]]); + for (k = 0; k < n; k = k + 1) + if (k!=i && k!=j) + d = d + (a[k*n+i]-a[k*n+j])*(b[_sol[k]*n+_sol[j]]-b[_sol[k]*n+_sol[i]]) + + (a[i*n+k]-a[j*n+k])*(b[_sol[j]*n+_sol[k]]-b[_sol[i]*n+_sol[k]]); + return(d); + } +}; +#endif diff --git a/branches/ParadisEO-GPU/tutorial/QAP_GPU/CMakeLists.txt b/branches/ParadisEO-GPU/tutorial/QAP_GPU/CMakeLists.txt new file mode 100644 index 000000000..ea603f56d --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_GPU/CMakeLists.txt @@ -0,0 +1,50 @@ +############################################################################## +## +## CMakeLists file for OneMax Example/application +## +############################################################################### + + +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES( + + # include CUDA source directory + ${CUDA_SRC_DIR} + # include NVIDIA source directory + ${NVIDIA_SRC_DIR} + # include EO source directory + ${PARADISEO_EO_SRC_DIR}/src + # include MO source directory + ${PARADISEO_MO_SRC_DIR}/src + # include problems directory + ${PARADISEO_PROBLEMS_SRC_DIR} + # include GPU directory + ${PARADISEO_GPU_SRC_DIR} + # include your source directory + ${CMAKE_CURRENT_SOURCE_DIR}/../src + ) + +###################################################################################### + +###################################################################################### +### 2) Specify where CMake can find the libraries +###################################################################################### + +LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${NVIDIA_LIB_DIR} ${CUDA_LIB_DIR} ) + +###################################################################################### + +###################################################################################### +### 3) Define your targets and link the librairies +###################################################################################### + +CUDA_ADD_EXECUTABLE(GPU_testSimpleHC testSimpleHC.cu) +CUDA_ADD_EXECUTABLE(GPU_testSimpleTS testSimpleTS.cu) + +TARGET_LINK_LIBRARIES(GPU_testSimpleHC eoutils ga eo ${cutil}) +TARGET_LINK_LIBRARIES(GPU_testSimpleTS eoutils ga eo ${cutil}) + + diff --git a/branches/ParadisEO-GPU/tutorial/QAP_GPU/moGPUConfig.h b/branches/ParadisEO-GPU/tutorial/QAP_GPU/moGPUConfig.h new file mode 100644 index 000000000..baa4718a1 --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_GPU/moGPUConfig.h @@ -0,0 +1,48 @@ +/* + + 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 ou accept its terms. + + ParadisEO WebSite : http://paradiseo.gforge.inria.fr + Contact: paradiseo-help@lists.gforge.inria.fr + */ + +#ifndef __moGPUConfig_H +#define __moGPUConfig_H + +#define BLOCK_SIZE 8 +#ifndef NB_POS +#define NB_POS 2 +#endif +#ifndef SIZE +#define SIZE 100 +#endif +#endif + + + diff --git a/branches/ParadisEO-GPU/tutorial/QAP_GPU/testSimpleHC.cu b/branches/ParadisEO-GPU/tutorial/QAP_GPU/testSimpleHC.cu new file mode 100644 index 000000000..34a0724cf --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_GPU/testSimpleHC.cu @@ -0,0 +1,228 @@ +/* + + 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 +*/ + + +#include +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" + +__device__ int * dev_a; +__device__ int * dev_b; + +// The general include for eo +#include +#include +// Fitness function +#include +// Cuda Fitness function +#include +#include +//Specific data to QAP problem +#include +// QAP solution +#include +// Swap neighbor +#include +//To compute execution time +#include +//Utils to compute size Mapping of x-change position +#include +// Use an ordered neighborhood without mapping, with local copy of solution +#include +// The Solution and neighbor comparator +#include +#include +// The continuator +#include +// Local search algorithm +#include +// Simple HC algorithm +#include +// The simple HC algorithm explorer +#include + + +typedef moGPUPermutationVector solution; +typedef moGPUXSwapNeighbor Neighbor; +typedef moGPUXChangeNeighborhoodByCpy Neighborhood; + + +int main(int argc, char **argv) +{ + + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + if (argc < 2){ + printf("Saisissez le nom de fichier dat à manipuler \n"); + exit(1); + } + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of QAP data + * + * ========================================================= */ + + QAPData _data(argv[1]); + + /* ========================================================= + * + * Initilisation of the solution and specific data + * + * ========================================================= */ + + solution sol(_data.sizeData); + _data.GPUObject.memCopyGlobalVariable(dev_a,_data.a_d); + _data.GPUObject.memCopyGlobalVariable(dev_b,_data.b_d); + + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + QAPEval eval(_data); + unsigned long int sizeMap=sizeMapping(_data.sizeData,NB_POS); + QAPIncrEval incr_eval; + moGPUMappingEvalByCpy > cueval(sizeMap,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(sizeMap,NB_POS,cueval); + + /* ========================================================= + * + * An explorer of solution neighborhood's + * + * ========================================================= */ + + moSimpleHCexplorer explorer(neighborhood, cueval, + comparator, solComparator); + + /* ========================================================= + * + * The local search algorithm + * + * ========================================================= */ + //True continuator <=> Always continue + + moTrueContinuator continuator; + + moLocalSearch localSearch(explorer,continuator, eval); + + /* ========================================================= + * + * The simple Hill Climbing algorithm + * + * ========================================================= */ + + moSimpleHC simpleHC(neighborhood,eval,cueval); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + std::cout << "initial: " << sol<< std::endl; + // Create timer for timing CUDA calculation + moGPUTimer timer; + timer.start(); + localSearch(sol); + std::cout << "final: " << sol << std::endl; + timer.stop(); + printf("Execution time = %f ms\n",timer.getTime()); + timer.deleteTimer(); + + _data.GPUObject.free(dev_a); + _data.GPUObject.free(dev_b); + + return 0; +} diff --git a/branches/ParadisEO-GPU/tutorial/QAP_GPU/testSimpleTS.cu b/branches/ParadisEO-GPU/tutorial/QAP_GPU/testSimpleTS.cu new file mode 100644 index 000000000..928a8b08e --- /dev/null +++ b/branches/ParadisEO-GPU/tutorial/QAP_GPU/testSimpleTS.cu @@ -0,0 +1,247 @@ +/* + + 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 +*/ + +#include +#include +#include +using namespace std; + +//Include GPU Config File +#include "moGPUConfig.h" + +__device__ int * dev_a; +__device__ int * dev_b; + +// The general include for eo +#include +#include +// Fitness function +#include +// Cuda Fitness function +#include +#include +//Specific data to QAP problem +#include +// QAP solution +#include +// Swap neighbor +#include +//To compute execution time +#include +//Utils to compute size Mapping of x-change position +#include +// Use an ordered neighborhood without mapping, with local copy of solution +#include +// The Solution and neighbor comparator +#include +#include +// The Iter continuator +#include +// The Tabou Search algorithm +#include +//Tabu list +#include +//Memories +#include +#include +#include + + +typedef moGPUPermutationVector solution; +typedef moGPUXSwapNeighbor Neighbor; +typedef moGPUXChangeNeighborhoodByCpy Neighborhood; + + +int main(int argc, char **argv) +{ + + /* ========================================================= + * + * Parameters + * + * ========================================================= */ + + // First define a parser from the command-line arguments + eoParser parser(argc, argv); + + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable + + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // Iteration number + eoValueParam nbIterationParam(1, "nbIteration", "TS Iteration number", 'I'); + parser.processParam( nbIterationParam, "TS Iteration number" ); + unsigned nbIteration = nbIterationParam.value(); + + // duration tabu list + eoValueParam durationParam(7, "duration", "duration of the tabu list", 'D'); + parser.processParam( durationParam, "Search Parameters" ); + unsigned duration = durationParam.value(); + + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); + + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); + + /* ========================================================= + * + * Initilisation of QAP data + * + * ========================================================= */ + + QAPData _data(argv[1]); + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + solution sol(_data.sizeData); + _data.GPUObject.memCopyGlobalVariable(dev_a,_data.a_d); + _data.GPUObject.memCopyGlobalVariable(dev_b,_data.b_d); + + /*========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ + + QAPEval eval(_data); + unsigned long int sizeMap=sizeMapping(_data.sizeData,NB_POS); + QAPIncrEval incr_eval; + moGPUMappingEvalByCpy > cueval(sizeMap,incr_eval); + + /* ========================================================= + * + * Comparator of solutions and neighbors + * + * ========================================================= */ + + moNeighborComparator comparator; + moSolNeighborComparator solComparator; + + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ + + Neighborhood neighborhood(sizeMap,NB_POS,cueval); + + /* ========================================================= + * + * continuator + * + * ========================================================= */ + + moIterContinuator continuator(nbIteration); + + /* ========================================================= + * + * tabu list + * + * ========================================================= */ + + moIndexedVectorTabuList tl(sizeMap,(sizeMap/8)); + + /* ========================================================= + * + * Memories + * + * ========================================================= */ + + moDummyIntensification inten; + moDummyDiversification div; + moBestImprAspiration asp; + + /* ========================================================= + * + * The Tabu search algorithm + * + * ========================================================= */ + + moTS tabuSearch(neighborhood, eval, cueval, comparator, solComparator, continuator, tl, inten, div, asp); + + /* ========================================================= + * + * Execute the local search from random sollution + * + * ========================================================= */ + + //Can be eval here, else it will be done at the beginning of the localSearch + eval(sol); + + std::cout << "initial: " << sol<< std::endl; + moGPUTimer timer; + timer.start(); + tabuSearch(sol); + std::cout << "final: " << sol << std::endl; + timer.stop(); + printf("Execution time = %f ms\n",timer.getTime()); + timer.deleteTimer(); + + + _data.GPUObject.free(dev_a); + _data.GPUObject.free(dev_b); + + return 0; +}