diff --git a/trunk/paradiseo-gpu/tutorial/OneMax/CMakeLists.txt b/trunk/paradiseo-gpu/tutorial/OneMax/CMakeLists.txt new file mode 100644 index 000000000..d8396c1b0 --- /dev/null +++ b/trunk/paradiseo-gpu/tutorial/OneMax/CMakeLists.txt @@ -0,0 +1,49 @@ +###################################################################################### +### 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/trunk/paradiseo-gpu/tutorial/OneMax/moGPUConfig.h b/trunk/paradiseo-gpu/tutorial/OneMax/moGPUConfig.h new file mode 100644 index 000000000..726e0db0d --- /dev/null +++ b/trunk/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/trunk/paradiseo-gpu/tutorial/OneMax/testFirstImpr.cu b/trunk/paradiseo-gpu/tutorial/OneMax/testFirstImpr.cu new file mode 100644 index 000000000..b57ab02fc --- /dev/null +++ b/trunk/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/trunk/paradiseo-gpu/tutorial/OneMax/testNeutralHC.cu b/trunk/paradiseo-gpu/tutorial/OneMax/testNeutralHC.cu new file mode 100644 index 000000000..9973e7bb9 --- /dev/null +++ b/trunk/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/trunk/paradiseo-gpu/tutorial/OneMax/testSimpleHC.cu b/trunk/paradiseo-gpu/tutorial/OneMax/testSimpleHC.cu new file mode 100644 index 000000000..fd52384ea --- /dev/null +++ b/trunk/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; +}