From aca68a1559f7b7bb7e642ad85dd0277b5f094db6 Mon Sep 17 00:00:00 2001 From: boufaras Date: Tue, 23 Nov 2010 13:42:34 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2003 331e1502-861f-0410-8da2-ba01fb791d7f --- .../tutoriel/Kswap-OneMax/testKswapHC.cu | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/ParadisEO-GPU/tutoriel/Kswap-OneMax/testKswapHC.cu b/ParadisEO-GPU/tutoriel/Kswap-OneMax/testKswapHC.cu index 42a4c3a05..4303f0bd9 100644 --- a/ParadisEO-GPU/tutoriel/Kswap-OneMax/testKswapHC.cu +++ b/ParadisEO-GPU/tutoriel/Kswap-OneMax/testKswapHC.cu @@ -1,5 +1,5 @@ //Init the number of threads per block -#define BLOCK_SIZE 128 +#define BLOCK_SIZE 512 #include #include using namespace std; @@ -32,6 +32,34 @@ using namespace std; // The simple HC algorithm explorer #include +/** + * @return the factorial of an unsigned integer + * @param i an integer + */ + +unsigned long int factorial1(unsigned int i) { + if (i == 0) + return 1; + else + return i * factorial1(i - 1); +} + +/** + * @return the neighborhood Size from the solution size and number of swap + * @param _size the solution size + * @param _Kswap the number of swap + */ + +unsigned long int sizeMapping1( unsigned int _size, unsigned int _Kswap) { + + unsigned long int _sizeMapping = _size; + for (unsigned int i = _Kswap; i > 0; i--) { + _sizeMapping *= (_size - i); + } + _sizeMapping /= factorial1(_Kswap + 1); + return _sizeMapping; +} + // REPRESENTATION typedef moCudaBitVector solution; typedef moBitFlippingNeighbor Neighbor; @@ -117,7 +145,7 @@ void main_function(int argc, char **argv) * Evaluation of a solution neighbor's * * ========================================================= */ - unsigned int sizeMap=sizeMapping(vecSize,KSwap); + unsigned long int sizeMap=sizeMapping1(vecSize,KSwap); std::cout<<"sizeMap : "< incr_eval; moCudaKswapEval > cueval(sizeMap,incr_eval); @@ -186,32 +214,7 @@ void main_function(int argc, char **argv) timer.deleteTimer(); std::cout << "final: " << sol.fitness() << std::endl; - /* ========================================================= - * - * Execute the Simple Hill climbing from random sollution - * - * ========================================================= */ - /*solution sol1(vecSize); - if(vecSize<64) - for(unsigned i=0;i