From 1343b27d98c44e83a34f43541c85a4e7d74f4d15 Mon Sep 17 00:00:00 2001 From: boufaras Date: Tue, 8 Feb 2011 10:54:59 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2117 331e1502-861f-0410-8da2-ba01fb791d7f --- ParadisEO-GPU/tutoriel/OneMax/CMakeLists.txt | 27 +- .../tutoriel/OneMax/testFirstImpr.cu | 36 +-- .../tutoriel/OneMax/testNeutralHC.cu | 24 +- ParadisEO-GPU/tutoriel/OneMax/testSimpleHC.cu | 36 +-- ParadisEO-GPU/tutoriel/OneMax/testSimpleTS.cu | 30 ++- .../tutoriel/OneMax/testSimulatedAnnealing.cu | 250 +++++++----------- 6 files changed, 170 insertions(+), 233 deletions(-) diff --git a/ParadisEO-GPU/tutoriel/OneMax/CMakeLists.txt b/ParadisEO-GPU/tutoriel/OneMax/CMakeLists.txt index 34a2b18d0..8fd27fc1b 100644 --- a/ParadisEO-GPU/tutoriel/OneMax/CMakeLists.txt +++ b/ParadisEO-GPU/tutoriel/OneMax/CMakeLists.txt @@ -9,21 +9,22 @@ ### 1) Include the sources ###################################################################################### -INCLUDE_DIRECTORIES( - # include CUDA source directory - ${CUDA_SRC_DIR} +INCLUDE_DIRECTORIES( + + # include CUDA source directory + ${CUDA_SRC_DIR} # include NVIDIA source directory - ${NVIDIA_SRC_DIR} + ${NVIDIA_SRC_DIR} # include EO source directory - ${PARADISEO_EO_SRC_DIR}/src + ${PARADISEO_EO_SRC_DIR}/src # include MO source directory - ${PARADISEO_MO_SRC_DIR}/src + ${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 + # include your source directory + ${CMAKE_CURRENT_SOURCE_DIR}/../src ) ###################################################################################### @@ -46,10 +47,10 @@ CUDA_ADD_EXECUTABLE(CutestSimpleHC testSimpleHC.cu) CUDA_ADD_EXECUTABLE(CutestSimpleTS testSimpleTS.cu) CUDA_ADD_EXECUTABLE(CutestSimulatedAnnealing testSimulatedAnnealing.cu) -TARGET_LINK_LIBRARIES(CutestFirstImpr eoutils ga eo libcutil.a) -TARGET_LINK_LIBRARIES(CutestNeutralHC eoutils ga eo libcutil.a) -TARGET_LINK_LIBRARIES(CutestSimpleHC eoutils ga eo libcutil.a) -TARGET_LINK_LIBRARIES(CutestSimpleTS eoutils ga eo libcutil.a) -TARGET_LINK_LIBRARIES(CutestSimulatedAnnealing eoutils ga eo libcutil.a) +TARGET_LINK_LIBRARIES(CutestFirstImpr eoutils ga eo ${cutil}) +TARGET_LINK_LIBRARIES(CutestNeutralHC eoutils ga eo ${cutil}) +TARGET_LINK_LIBRARIES(CutestSimpleHC eoutils ga eo ${cutil}) +TARGET_LINK_LIBRARIES(CutestSimpleTS eoutils ga eo ${cutil}) +TARGET_LINK_LIBRARIES(CutestSimulatedAnnealing eoutils ga eo ${cutil}) ###################################################################################### diff --git a/ParadisEO-GPU/tutoriel/OneMax/testFirstImpr.cu b/ParadisEO-GPU/tutoriel/OneMax/testFirstImpr.cu index 09f7d851f..79d374840 100644 --- a/ParadisEO-GPU/tutoriel/OneMax/testFirstImpr.cu +++ b/ParadisEO-GPU/tutoriel/OneMax/testFirstImpr.cu @@ -1,5 +1,5 @@ //Init the number of threads per block -#define BLOCK_SIZE 128 +#define BLOCK_SIZE 256 #include #include @@ -8,15 +8,13 @@ using namespace std; // The general include for eo #include #include -// Fitness function +// OneMax full eval function #include -// Cuda Fitness function +// OneMax increment eval function #include #include // One Max solution #include -//To compute execution time -#include // One Max neighbor #include // One Max ordered neighborhood @@ -32,7 +30,12 @@ using namespace std; #include // The First Improvment algorithm explorer #include +//To compute execution time +#include +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ // REPRESENTATION typedef moCudaBitVector solution; typedef moCudaBitNeighbor Neighbor; @@ -85,10 +88,8 @@ void main_function(int argc, char **argv) * ========================================================= */ //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run + // you'll always get the same result, NOT a random run rng.reseed(seed); - int seed1=time(0); - srand(seed1); /* ========================================================= * @@ -97,9 +98,6 @@ void main_function(int argc, char **argv) * ========================================================= */ solution sol(vecSize); - if(vecSize<64) - for(unsigned i=0;i #include using namespace std; @@ -7,15 +8,13 @@ using namespace std; // The general include for eo #include #include -// Fitness function +// OneMax full eval function #include -// Cuda Fitness function +// OneMax increment eval function #include #include // One Max solution #include -//To compute execution time -#include // One Max neighbor #include // One Max ordered neighborhood @@ -27,8 +26,12 @@ using namespace std; #include // Simple HC algorithm #include +//To compute execution time +#include - +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ // REPRESENTATION typedef moCudaBitVector solution; typedef moCudaBitNeighbor Neighbor; @@ -98,10 +101,7 @@ void main_function(int argc, char **argv) * ========================================================= */ solution sol(vecSize); - if(vecSize<64) - for(unsigned i=0;i #include using namespace std; @@ -7,17 +8,15 @@ using namespace std; // The general include for eo #include #include -// Fitness function +// OneMax full eval function #include -// Cuda Fitness function +// OneMax increment eval function #include #include // One Max solution #include // One Max neighbor #include -//To compute execution time -#include // One Max ordered neighborhood #include // The Solution and neighbor comparator @@ -31,7 +30,12 @@ using namespace std; #include // The simple HC algorithm explorer #include +//To compute execution time +#include +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ // REPRESENTATION typedef moCudaBitVector solution; typedef moCudaBitNeighbor Neighbor; @@ -96,9 +100,6 @@ void main_function(int argc, char **argv) * ========================================================= */ solution sol(vecSize); - if(vecSize<64) - for(unsigned i=0;i #include @@ -8,9 +8,9 @@ using namespace std; // The general include for eo #include #include -// Fitness function +// OneMax full eval function #include -// Cuda Fitness function +// OneMax increment eval function #include #include // One Max solution @@ -40,7 +40,9 @@ using namespace std; #include - +//------------------------------------------------------------------------------------ +// Define types of the representation solution, different neighbors and neighborhoods +//------------------------------------------------------------------------------------ // REPRESENTATION typedef moCudaBitVector solution; @@ -67,6 +69,7 @@ void main_function(int argc, char **argv) parser.processParam( seedParam ); unsigned seed = seedParam.value(); + // description of genotype eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); parser.processParam( vecSizeParam, "Representation" ); @@ -205,14 +208,14 @@ void main_function(int argc, char **argv) eval(sol1); std::cout << "Tabu Search 1:" << std::endl; std::cout << "---------------------" << std::endl; - std::cout << "initial: " << sol1.fitness()<< std::endl; + std::cout << "initial: " << sol1<< std::endl; moCudaTimer timer1; timer1.start(); localSearch1(sol1); timer1.stop(); + std::cout << "final: " << sol1 << std::endl< #include using namespace std; @@ -9,12 +8,12 @@ using namespace std; // The general include for eo #include #include -// Fitness function +// OneMax full eval function #include -// Cuda Fitness function -#include +// OneMax increment eval function #include // One Max solution +#include #include //To compute execution time #include @@ -39,9 +38,9 @@ using namespace std; #include #include -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------------------ // Define types of the representation solution, different neighbors and neighborhoods -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------------------ // REPRESENTATION typedef moCudaBitVector solution; @@ -50,181 +49,130 @@ typedef moCudaRndWithReplNeighborhood Neighborhood; void main_function(int argc, char **argv) { - /* ========================================================= -* -* Parameters -* -* ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ -// First define a parser from the command-line arguments -eoParser parser(argc, argv); + // 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 + // 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(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); -// description of genotype -eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); -parser.processParam( vecSizeParam, "Representation" ); -unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.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" ); + // 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 -} + // 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 - * - * ========================================================= */ + /* ========================================================= + * + * 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); + //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 - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ -//solution sol(size); -solution sol(vecSize); + solution sol(vecSize); -for(unsigned int i=0;i eval; -EvalOneMax eval; - -/* ========================================================= - * - * Evaluation of a solution neighbor's - * - * ========================================================= */ + /* ========================================================= + * + * Evaluation of a solution neighbor's + * + * ========================================================= */ OneMaxIncrEval incr_eval; moCudaVectorEval > cueval(vecSize,incr_eval); -/* ========================================================= - * - * Comparator of solutions and neighbors - * - * ========================================================= */ - // moNeighborComparator comparator; - moSolNeighborComparator solComparator; - -/* ========================================================= - * - * a solution neighborhood - * - * ========================================================= */ + /* ========================================================= + * + * a solution neighborhood + * + * ========================================================= */ Neighborhood neighborhood(vecSize,cueval); -/* ========================================================= - * - * the cooling schedule of the process - * - * ========================================================= */ + + /* ========================================================= + * + * the cooling schedule of the process + * + * ========================================================= */ -// initial temp, factor of decrease, number of steps without decrease, final temp. + // initial temp, factor of decrease, number of steps without decrease, final temp. moSimpleCoolingSchedule coolingSchedule(500, 0.9, 1000, 0.01); -/* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - moSA localSearch1(neighborhood, eval, cueval,coolingSchedule); + moSA SA(neighborhood, eval, cueval,coolingSchedule); -/* ========================================================= - * - * execute the local search from random solution - * - * ========================================================= */ + /* ========================================================= + * + * execute the local search from random solution + * + * ========================================================= */ -//init(solution); -eval(sol); + //init(solution); + eval(sol); -std::cout << "#########################################" << std::endl; -std::cout << "initial solution1: " << sol.fitness() << std::endl; + std::cout << "#########################################" << std::endl; + std::cout << "initial : " << sol << std::endl; + SA(sol); + std::cout << "final : " << sol << std::endl; + std::cout << "#########################################" << std::endl; -localSearch1(sol); - -std::cout << "final solution1: " << sol.fitness() << std::endl; -std::cout << "#########################################" << std::endl; - - -/* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ - -// moSolNeighborComparator solComparator; - -/* ========================================================= - * - * Example of Checkpointing - * - * ========================================================= */ - - /*moTrueContinuator continuator;//always continue - moCheckpoint checkpoint(continuator); - moFitnessStat fitStat; - checkpoint.add(fitStat); - eoFileMonitor monitor("fitness.out", ""); - moCounterMonitorSaver countMon(100, monitor); - checkpoint.add(countMon); - monitor.add(fitStat); - - moSA localSearch2(neighborhood, eval, cueval, coolingSchedule, solComparator, checkpoint); - - - eval(sol1); - for(int i=0;i