git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2117 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
48c715572c
commit
1343b27d98
6 changed files with 183 additions and 246 deletions
|
|
@ -9,21 +9,22 @@
|
||||||
### 1) Include the sources
|
### 1) Include the sources
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(
|
INCLUDE_DIRECTORIES(
|
||||||
# include CUDA source directory
|
|
||||||
${CUDA_SRC_DIR}
|
# include CUDA source directory
|
||||||
|
${CUDA_SRC_DIR}
|
||||||
# include NVIDIA source directory
|
# include NVIDIA source directory
|
||||||
${NVIDIA_SRC_DIR}
|
${NVIDIA_SRC_DIR}
|
||||||
# include EO source directory
|
# include EO source directory
|
||||||
${PARADISEO_EO_SRC_DIR}/src
|
${PARADISEO_EO_SRC_DIR}/src
|
||||||
# include MO source directory
|
# include MO source directory
|
||||||
${PARADISEO_MO_SRC_DIR}/src
|
${PARADISEO_MO_SRC_DIR}/src
|
||||||
# include problems directory
|
# include problems directory
|
||||||
${PARADISEO_PROBLEMS_SRC_DIR}
|
${PARADISEO_PROBLEMS_SRC_DIR}
|
||||||
# include GPU directory
|
# include GPU directory
|
||||||
${PARADISEO_GPU_SRC_DIR}
|
${PARADISEO_GPU_SRC_DIR}
|
||||||
# include your source directory
|
# include your source directory
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../src
|
${CMAKE_CURRENT_SOURCE_DIR}/../src
|
||||||
)
|
)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
@ -46,10 +47,10 @@ CUDA_ADD_EXECUTABLE(CutestSimpleHC testSimpleHC.cu)
|
||||||
CUDA_ADD_EXECUTABLE(CutestSimpleTS testSimpleTS.cu)
|
CUDA_ADD_EXECUTABLE(CutestSimpleTS testSimpleTS.cu)
|
||||||
CUDA_ADD_EXECUTABLE(CutestSimulatedAnnealing testSimulatedAnnealing.cu)
|
CUDA_ADD_EXECUTABLE(CutestSimulatedAnnealing testSimulatedAnnealing.cu)
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(CutestFirstImpr eoutils ga eo libcutil.a)
|
TARGET_LINK_LIBRARIES(CutestFirstImpr eoutils ga eo ${cutil})
|
||||||
TARGET_LINK_LIBRARIES(CutestNeutralHC eoutils ga eo libcutil.a)
|
TARGET_LINK_LIBRARIES(CutestNeutralHC eoutils ga eo ${cutil})
|
||||||
TARGET_LINK_LIBRARIES(CutestSimpleHC eoutils ga eo libcutil.a)
|
TARGET_LINK_LIBRARIES(CutestSimpleHC eoutils ga eo ${cutil})
|
||||||
TARGET_LINK_LIBRARIES(CutestSimpleTS eoutils ga eo libcutil.a)
|
TARGET_LINK_LIBRARIES(CutestSimpleTS eoutils ga eo ${cutil})
|
||||||
TARGET_LINK_LIBRARIES(CutestSimulatedAnnealing eoutils ga eo libcutil.a)
|
TARGET_LINK_LIBRARIES(CutestSimulatedAnnealing eoutils ga eo ${cutil})
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//Init the number of threads per block
|
//Init the number of threads per block
|
||||||
#define BLOCK_SIZE 128
|
#define BLOCK_SIZE 256
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -8,15 +8,13 @@ using namespace std;
|
||||||
// The general include for eo
|
// The general include for eo
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <ga.h>
|
#include <ga.h>
|
||||||
// Fitness function
|
// OneMax full eval function
|
||||||
#include <problems/eval/EvalOneMax.h>
|
#include <problems/eval/EvalOneMax.h>
|
||||||
// Cuda Fitness function
|
// OneMax increment eval function
|
||||||
#include <eval/moCudaVectorEval.h>
|
#include <eval/moCudaVectorEval.h>
|
||||||
#include <problems/eval/OneMaxIncrEval.h>
|
#include <problems/eval/OneMaxIncrEval.h>
|
||||||
// One Max solution
|
// One Max solution
|
||||||
#include <cudaType/moCudaBitVector.h>
|
#include <cudaType/moCudaBitVector.h>
|
||||||
//To compute execution time
|
|
||||||
#include <performance/moCudaTimer.h>
|
|
||||||
// One Max neighbor
|
// One Max neighbor
|
||||||
#include <neighborhood/moCudaBitNeighbor.h>
|
#include <neighborhood/moCudaBitNeighbor.h>
|
||||||
// One Max ordered neighborhood
|
// One Max ordered neighborhood
|
||||||
|
|
@ -32,7 +30,12 @@ using namespace std;
|
||||||
#include <algo/moFirstImprHC.h>
|
#include <algo/moFirstImprHC.h>
|
||||||
// The First Improvment algorithm explorer
|
// The First Improvment algorithm explorer
|
||||||
#include <explorer/moFirstImprHCexplorer.h>
|
#include <explorer/moFirstImprHCexplorer.h>
|
||||||
|
//To compute execution time
|
||||||
|
#include <performance/moCudaTimer.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Define types of the representation solution, different neighbors and neighborhoods
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
// REPRESENTATION
|
// REPRESENTATION
|
||||||
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
||||||
typedef moCudaBitNeighbor <solution,eoMaximizingFitness> Neighbor;
|
typedef moCudaBitNeighbor <solution,eoMaximizingFitness> Neighbor;
|
||||||
|
|
@ -85,10 +88,8 @@ void main_function(int argc, char **argv)
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
//reproducible random seed: if you don't change SEED above,
|
//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);
|
rng.reseed(seed);
|
||||||
int seed1=time(0);
|
|
||||||
srand(seed1);
|
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
|
|
@ -97,9 +98,6 @@ void main_function(int argc, char **argv)
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
solution sol(vecSize);
|
solution sol(vecSize);
|
||||||
if(vecSize<64)
|
|
||||||
for(unsigned i=0;i<vecSize;i++) cout<<sol[i]<<" ";
|
|
||||||
cout<<endl;
|
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
|
|
@ -172,14 +170,14 @@ void main_function(int argc, char **argv)
|
||||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||||
eval(sol);
|
eval(sol);
|
||||||
|
|
||||||
std::cout << "initial: " << sol.fitness()<< std::endl;
|
std::cout << "initial: " << sol<< std::endl;
|
||||||
moCudaTimer timer;
|
moCudaTimer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
localSearch(sol);
|
localSearch(sol);
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
std::cout << "final: " << sol << std::endl;
|
||||||
printf("CUDA execution time = %f ms\n",timer.getTime());
|
printf("CUDA execution time = %f ms\n",timer.getTime());
|
||||||
timer.deleteTimer();
|
timer.deleteTimer();
|
||||||
std::cout << "final: " << sol.fitness() << std::endl;
|
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
|
|
@ -188,24 +186,18 @@ void main_function(int argc, char **argv)
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
solution sol1(vecSize);
|
solution sol1(vecSize);
|
||||||
if(vecSize<64)
|
|
||||||
for(unsigned i=0;i<vecSize;i++) cout<<sol1[i]<<" ";
|
|
||||||
cout<<endl;
|
|
||||||
cout<<endl;
|
|
||||||
|
|
||||||
eval(sol1);
|
eval(sol1);
|
||||||
|
std::cout<< std::endl;
|
||||||
std::cout << "initial: " << sol1.fitness()<< std::endl;
|
std::cout << "initial: " << sol1<< std::endl;
|
||||||
|
|
||||||
moCudaTimer timer1;
|
moCudaTimer timer1;
|
||||||
timer1.start();
|
timer1.start();
|
||||||
firstImprHC(sol1);
|
firstImprHC(sol1);
|
||||||
timer1.stop();
|
timer1.stop();
|
||||||
|
std::cout << "final: " << sol1 << std::endl;
|
||||||
printf("CUDA execution time = %f ms\n",timer1.getTime());
|
printf("CUDA execution time = %f ms\n",timer1.getTime());
|
||||||
timer1.deleteTimer();
|
timer1.deleteTimer();
|
||||||
|
|
||||||
std::cout << "final: " << sol1.fitness() << std::endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A main that catches the exceptions
|
// A main that catches the exceptions
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
//Init the number of threads per block
|
//Init the number of threads per block
|
||||||
#define BLOCK_SIZE 128
|
#define BLOCK_SIZE 256
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -7,15 +8,13 @@ using namespace std;
|
||||||
// The general include for eo
|
// The general include for eo
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <ga.h>
|
#include <ga.h>
|
||||||
// Fitness function
|
// OneMax full eval function
|
||||||
#include <problems/eval/EvalOneMax.h>
|
#include <problems/eval/EvalOneMax.h>
|
||||||
// Cuda Fitness function
|
// OneMax increment eval function
|
||||||
#include <eval/moCudaVectorEval.h>
|
#include <eval/moCudaVectorEval.h>
|
||||||
#include <problems/eval/OneMaxIncrEval.h>
|
#include <problems/eval/OneMaxIncrEval.h>
|
||||||
// One Max solution
|
// One Max solution
|
||||||
#include <cudaType/moCudaBitVector.h>
|
#include <cudaType/moCudaBitVector.h>
|
||||||
//To compute execution time
|
|
||||||
#include <performance/moCudaTimer.h>
|
|
||||||
// One Max neighbor
|
// One Max neighbor
|
||||||
#include <neighborhood/moCudaBitNeighbor.h>
|
#include <neighborhood/moCudaBitNeighbor.h>
|
||||||
// One Max ordered neighborhood
|
// One Max ordered neighborhood
|
||||||
|
|
@ -27,8 +26,12 @@ using namespace std;
|
||||||
#include <continuator/moTrueContinuator.h>
|
#include <continuator/moTrueContinuator.h>
|
||||||
// Simple HC algorithm
|
// Simple HC algorithm
|
||||||
#include <algo/moNeutralHC.h>
|
#include <algo/moNeutralHC.h>
|
||||||
|
//To compute execution time
|
||||||
|
#include <performance/moCudaTimer.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Define types of the representation solution, different neighbors and neighborhoods
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
// REPRESENTATION
|
// REPRESENTATION
|
||||||
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
||||||
typedef moCudaBitNeighbor <solution,eoMaximizingFitness> Neighbor;
|
typedef moCudaBitNeighbor <solution,eoMaximizingFitness> Neighbor;
|
||||||
|
|
@ -98,10 +101,7 @@ void main_function(int argc, char **argv)
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
solution sol(vecSize);
|
solution sol(vecSize);
|
||||||
if(vecSize<64)
|
|
||||||
for(unsigned i=0;i<vecSize;i++) cout<<sol[i]<<" ";
|
|
||||||
cout<<endl;
|
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* Eval fitness function
|
* Eval fitness function
|
||||||
|
|
@ -155,14 +155,14 @@ void main_function(int argc, char **argv)
|
||||||
|
|
||||||
eval(sol);
|
eval(sol);
|
||||||
|
|
||||||
std::cout << "initial: " << sol.fitness()<< std::endl;
|
std::cout << "initial: " << sol<< std::endl;
|
||||||
moCudaTimer timer;
|
moCudaTimer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
neutralHC(sol);
|
neutralHC(sol);
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
std::cout << "final: " << sol << std::endl;
|
||||||
printf("CUDA execution time = %f ms\n",timer.getTime());
|
printf("CUDA execution time = %f ms\n",timer.getTime());
|
||||||
timer.deleteTimer();
|
timer.deleteTimer();
|
||||||
std::cout << "final: " << sol.fitness() << std::endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
//Init the number of threads per block
|
//Init the number of threads per block
|
||||||
#define BLOCK_SIZE 128
|
#define BLOCK_SIZE 256
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -7,17 +8,15 @@ using namespace std;
|
||||||
// The general include for eo
|
// The general include for eo
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <ga.h>
|
#include <ga.h>
|
||||||
// Fitness function
|
// OneMax full eval function
|
||||||
#include <problems/eval/EvalOneMax.h>
|
#include <problems/eval/EvalOneMax.h>
|
||||||
// Cuda Fitness function
|
// OneMax increment eval function
|
||||||
#include <eval/moCudaVectorEval.h>
|
#include <eval/moCudaVectorEval.h>
|
||||||
#include <problems/eval/OneMaxIncrEval.h>
|
#include <problems/eval/OneMaxIncrEval.h>
|
||||||
// One Max solution
|
// One Max solution
|
||||||
#include <cudaType/moCudaBitVector.h>
|
#include <cudaType/moCudaBitVector.h>
|
||||||
// One Max neighbor
|
// One Max neighbor
|
||||||
#include <neighborhood/moCudaBitNeighbor.h>
|
#include <neighborhood/moCudaBitNeighbor.h>
|
||||||
//To compute execution time
|
|
||||||
#include <performance/moCudaTimer.h>
|
|
||||||
// One Max ordered neighborhood
|
// One Max ordered neighborhood
|
||||||
#include <neighborhood/moCudaOrderNeighborhood.h>
|
#include <neighborhood/moCudaOrderNeighborhood.h>
|
||||||
// The Solution and neighbor comparator
|
// The Solution and neighbor comparator
|
||||||
|
|
@ -31,7 +30,12 @@ using namespace std;
|
||||||
#include <algo/moSimpleHC.h>
|
#include <algo/moSimpleHC.h>
|
||||||
// The simple HC algorithm explorer
|
// The simple HC algorithm explorer
|
||||||
#include <explorer/moSimpleHCexplorer.h>
|
#include <explorer/moSimpleHCexplorer.h>
|
||||||
|
//To compute execution time
|
||||||
|
#include <performance/moCudaTimer.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Define types of the representation solution, different neighbors and neighborhoods
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
// REPRESENTATION
|
// REPRESENTATION
|
||||||
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
||||||
typedef moCudaBitNeighbor <solution> Neighbor;
|
typedef moCudaBitNeighbor <solution> Neighbor;
|
||||||
|
|
@ -96,9 +100,6 @@ void main_function(int argc, char **argv)
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
solution sol(vecSize);
|
solution sol(vecSize);
|
||||||
if(vecSize<64)
|
|
||||||
for(unsigned i=0;i<vecSize;i++) cout<<sol[i]<<" ";
|
|
||||||
cout<<endl;
|
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
|
|
@ -171,7 +172,7 @@ void main_function(int argc, char **argv)
|
||||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||||
eval(sol);
|
eval(sol);
|
||||||
|
|
||||||
std::cout << "initial: " << sol.fitness()<< std::endl;
|
std::cout << "initial: " << sol<< std::endl;
|
||||||
// Create timer for timing CUDA calculation
|
// Create timer for timing CUDA calculation
|
||||||
moCudaTimer timer;
|
moCudaTimer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
@ -179,34 +180,25 @@ void main_function(int argc, char **argv)
|
||||||
timer.stop();
|
timer.stop();
|
||||||
printf("CUDA execution time = %f ms\n",timer.getTime());
|
printf("CUDA execution time = %f ms\n",timer.getTime());
|
||||||
timer.deleteTimer();
|
timer.deleteTimer();
|
||||||
std::cout << "final: " << sol.fitness() << std::endl;
|
std::cout << "final: " << sol << std::endl;
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* Execute the Simple Hill climbing from random sollution
|
* Execute the Simple Hill climbing from random sollution
|
||||||
*
|
*
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
cout<<endl;
|
||||||
solution sol1(vecSize);
|
solution sol1(vecSize);
|
||||||
if(vecSize<64)
|
|
||||||
for(unsigned i=0;i<vecSize;i++) cout<<sol1[i]<<" ";
|
|
||||||
cout<<endl;
|
|
||||||
cout<<endl;
|
|
||||||
|
|
||||||
|
|
||||||
eval(sol1);
|
eval(sol1);
|
||||||
|
std::cout << "initial: " << sol1<< std::endl;
|
||||||
std::cout << "initial: " << sol1.fitness()<< std::endl;
|
|
||||||
// Create timer for timing CUDA calculation
|
// Create timer for timing CUDA calculation
|
||||||
moCudaTimer timer1;
|
moCudaTimer timer1;
|
||||||
timer1.start();
|
timer1.start();
|
||||||
simpleHC(sol1);
|
simpleHC(sol1);
|
||||||
timer1.stop();
|
timer1.stop();
|
||||||
|
std::cout << "final: " << sol1 << std::endl;
|
||||||
printf("CUDA execution time = %f ms\n",timer1.getTime());
|
printf("CUDA execution time = %f ms\n",timer1.getTime());
|
||||||
timer1.deleteTimer();
|
timer1.deleteTimer();
|
||||||
std::cout << "final: " << sol1.fitness() << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A main that catches the exceptions
|
// A main that catches the exceptions
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//Init the number of threads per block
|
//Init the number of threads per block
|
||||||
#define BLOCK_SIZE 128
|
#define BLOCK_SIZE 256
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -8,9 +8,9 @@ using namespace std;
|
||||||
// The general include for eo
|
// The general include for eo
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <ga.h>
|
#include <ga.h>
|
||||||
// Fitness function
|
// OneMax full eval function
|
||||||
#include <problems/eval/EvalOneMax.h>
|
#include <problems/eval/EvalOneMax.h>
|
||||||
// Cuda Fitness function
|
// OneMax increment eval function
|
||||||
#include <eval/moCudaVectorEval.h>
|
#include <eval/moCudaVectorEval.h>
|
||||||
#include <problems/eval/OneMaxIncrEval.h>
|
#include <problems/eval/OneMaxIncrEval.h>
|
||||||
// One Max solution
|
// One Max solution
|
||||||
|
|
@ -40,7 +40,9 @@ using namespace std;
|
||||||
#include <memory/moBestImprAspiration.h>
|
#include <memory/moBestImprAspiration.h>
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Define types of the representation solution, different neighbors and neighborhoods
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
// REPRESENTATION
|
// REPRESENTATION
|
||||||
|
|
||||||
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
||||||
|
|
@ -67,6 +69,7 @@ void main_function(int argc, char **argv)
|
||||||
parser.processParam( seedParam );
|
parser.processParam( seedParam );
|
||||||
unsigned seed = seedParam.value();
|
unsigned seed = seedParam.value();
|
||||||
|
|
||||||
|
|
||||||
// description of genotype
|
// description of genotype
|
||||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
||||||
parser.processParam( vecSizeParam, "Representation" );
|
parser.processParam( vecSizeParam, "Representation" );
|
||||||
|
|
@ -205,14 +208,14 @@ void main_function(int argc, char **argv)
|
||||||
eval(sol1);
|
eval(sol1);
|
||||||
std::cout << "Tabu Search 1:" << std::endl;
|
std::cout << "Tabu Search 1:" << std::endl;
|
||||||
std::cout << "---------------------" << std::endl;
|
std::cout << "---------------------" << std::endl;
|
||||||
std::cout << "initial: " << sol1.fitness()<< std::endl;
|
std::cout << "initial: " << sol1<< std::endl;
|
||||||
moCudaTimer timer1;
|
moCudaTimer timer1;
|
||||||
timer1.start();
|
timer1.start();
|
||||||
localSearch1(sol1);
|
localSearch1(sol1);
|
||||||
timer1.stop();
|
timer1.stop();
|
||||||
|
std::cout << "final: " << sol1 << std::endl<<std::endl;
|
||||||
printf("CUDA execution time = %f ms\n",timer1.getTime());
|
printf("CUDA execution time = %f ms\n",timer1.getTime());
|
||||||
timer1.deleteTimer();
|
timer1.deleteTimer();
|
||||||
std::cout << "final: " << sol1.fitness() << std::endl<<std::endl;
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* Execute the TS Basic Constructor
|
* Execute the TS Basic Constructor
|
||||||
|
|
@ -222,14 +225,15 @@ void main_function(int argc, char **argv)
|
||||||
eval(sol2);
|
eval(sol2);
|
||||||
std::cout << "Tabu Search 2:" << std::endl;
|
std::cout << "Tabu Search 2:" << std::endl;
|
||||||
std::cout << "---------------------" << std::endl;
|
std::cout << "---------------------" << std::endl;
|
||||||
std::cout << "initial: " << sol2.fitness()<< std::endl;
|
std::cout << "initial: " << sol2<< std::endl;
|
||||||
moCudaTimer timer2;
|
moCudaTimer timer2;
|
||||||
timer2.start();
|
timer2.start();
|
||||||
localSearch2(sol2);
|
localSearch2(sol2);
|
||||||
timer2.stop();
|
timer2.stop();
|
||||||
|
std::cout << "final: " << sol2 << std::endl<< std::endl;
|
||||||
printf("CUDA execution time = %f ms\n",timer2.getTime());
|
printf("CUDA execution time = %f ms\n",timer2.getTime());
|
||||||
timer2.deleteTimer();
|
timer2.deleteTimer();
|
||||||
std::cout << "final: " << sol2.fitness() << std::endl<< std::endl;
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* Execute the TS Simple Constructor
|
* Execute the TS Simple Constructor
|
||||||
|
|
@ -239,14 +243,15 @@ void main_function(int argc, char **argv)
|
||||||
eval(sol3);
|
eval(sol3);
|
||||||
std::cout << "Tabu Search 3:" << std::endl;
|
std::cout << "Tabu Search 3:" << std::endl;
|
||||||
std::cout << "---------------------" << std::endl;
|
std::cout << "---------------------" << std::endl;
|
||||||
std::cout << "initial: " << sol3.fitness()<< std::endl;
|
std::cout << "initial: " << sol3<< std::endl;
|
||||||
moCudaTimer timer3;
|
moCudaTimer timer3;
|
||||||
timer3.start();
|
timer3.start();
|
||||||
localSearch3(sol3);
|
localSearch3(sol3);
|
||||||
timer3.stop();
|
timer3.stop();
|
||||||
|
std::cout << "final: " << sol3<< std::endl<< std::endl;
|
||||||
printf("CUDA execution time = %f ms\n",timer3.getTime());
|
printf("CUDA execution time = %f ms\n",timer3.getTime());
|
||||||
timer3.deleteTimer();
|
timer3.deleteTimer();
|
||||||
std::cout << "final: " << sol3.fitness() << std::endl<< std::endl;
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* Execute the TS General Constructor
|
* Execute the TS General Constructor
|
||||||
|
|
@ -256,15 +261,14 @@ void main_function(int argc, char **argv)
|
||||||
eval(sol4);
|
eval(sol4);
|
||||||
std::cout << "Tabu Search 4:" << std::endl;
|
std::cout << "Tabu Search 4:" << std::endl;
|
||||||
std::cout << "---------------------" << std::endl;
|
std::cout << "---------------------" << std::endl;
|
||||||
std::cout << "initial: " << sol4.fitness()<< std::endl;
|
std::cout << "initial: " << sol4<< std::endl;
|
||||||
moCudaTimer timer4;
|
moCudaTimer timer4;
|
||||||
timer4.start();
|
timer4.start();
|
||||||
localSearch4(sol4);
|
localSearch4(sol4);
|
||||||
timer4.stop();
|
timer4.stop();
|
||||||
|
std::cout << "final: " << sol4 << std::endl<< std::endl;
|
||||||
printf("CUDA execution time = %f ms\n",timer4.getTime());
|
printf("CUDA execution time = %f ms\n",timer4.getTime());
|
||||||
timer4.deleteTimer();
|
timer4.deleteTimer();
|
||||||
std::cout << "final: " << sol4.fitness() << std::endl<< std::endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A main that catches the exceptions
|
// A main that catches the exceptions
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
///Init the number of threads per block
|
//Init the number of threads per block
|
||||||
#define BLOCK_SIZE 128
|
#define BLOCK_SIZE 256
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -9,12 +8,12 @@ using namespace std;
|
||||||
// The general include for eo
|
// The general include for eo
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <ga.h>
|
#include <ga.h>
|
||||||
// Fitness function
|
// OneMax full eval function
|
||||||
#include <problems/eval/EvalOneMax.h>
|
#include <problems/eval/EvalOneMax.h>
|
||||||
// Cuda Fitness function
|
// OneMax increment eval function
|
||||||
#include <eval/moCudaVectorEval.h>
|
|
||||||
#include <problems/eval/OneMaxIncrEval.h>
|
#include <problems/eval/OneMaxIncrEval.h>
|
||||||
// One Max solution
|
// One Max solution
|
||||||
|
#include <eval/moCudaVectorEval.h>
|
||||||
#include <cudaType/moCudaBitVector.h>
|
#include <cudaType/moCudaBitVector.h>
|
||||||
//To compute execution time
|
//To compute execution time
|
||||||
#include <performance/moCudaTimer.h>
|
#include <performance/moCudaTimer.h>
|
||||||
|
|
@ -39,9 +38,9 @@ using namespace std;
|
||||||
#include <utils/eoFileMonitor.h>
|
#include <utils/eoFileMonitor.h>
|
||||||
#include <continuator/moCounterMonitorSaver.h>
|
#include <continuator/moCounterMonitorSaver.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Define types of the representation solution, different neighbors and neighborhoods
|
// Define types of the representation solution, different neighbors and neighborhoods
|
||||||
//-----------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// REPRESENTATION
|
// REPRESENTATION
|
||||||
|
|
||||||
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
typedef moCudaBitVector<eoMaximizingFitness> solution;
|
||||||
|
|
@ -50,181 +49,130 @@ typedef moCudaRndWithReplNeighborhood<Neighbor> Neighborhood;
|
||||||
|
|
||||||
void main_function(int argc, char **argv)
|
void main_function(int argc, char **argv)
|
||||||
{
|
{
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* Parameters
|
* Parameters
|
||||||
*
|
*
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
// First define a parser from the command-line arguments
|
// First define a parser from the command-line arguments
|
||||||
eoParser parser(argc, argv);
|
eoParser parser(argc, argv);
|
||||||
|
|
||||||
// For each parameter, define Parameter, read it through the parser,
|
// For each parameter, define Parameter, read it through the parser,
|
||||||
// and assign the value to the variable
|
// and assign the value to the variable
|
||||||
|
|
||||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||||
parser.processParam( seedParam );
|
parser.processParam( seedParam );
|
||||||
unsigned seed = seedParam.value();
|
unsigned seed = seedParam.value();
|
||||||
|
|
||||||
// description of genotype
|
// description of genotype
|
||||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
||||||
parser.processParam( vecSizeParam, "Representation" );
|
parser.processParam( vecSizeParam, "Representation" );
|
||||||
unsigned vecSize = vecSizeParam.value();
|
unsigned vecSize = vecSizeParam.value();
|
||||||
|
|
||||||
// the name of the "status" file where all actual parameter values will be saved
|
// the name of the "status" file where all actual parameter values will be saved
|
||||||
string str_status = parser.ProgramName() + ".status"; // default value
|
string str_status = parser.ProgramName() + ".status"; // default value
|
||||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||||
parser.processParam( statusParam, "Persistence" );
|
parser.processParam( statusParam, "Persistence" );
|
||||||
|
|
||||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||||
// i.e. in case you need parameters somewhere else, postpone these
|
// i.e. in case you need parameters somewhere else, postpone these
|
||||||
if (parser.userNeedsHelp()) {
|
if (parser.userNeedsHelp()) {
|
||||||
parser.printHelp(cout);
|
parser.printHelp(cout);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (statusParam.value() != "") {
|
if (statusParam.value() != "") {
|
||||||
ofstream os(statusParam.value().c_str());
|
ofstream os(statusParam.value().c_str());
|
||||||
os << parser;// and you can use that file as parameter file
|
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,
|
//reproducible random seed: if you don't change SEED above,
|
||||||
// you'll always get the same result, NOT a random run
|
// you'll always get the same result, NOT a random run
|
||||||
rng.reseed(seed);
|
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<vecSize;i++) cout<<sol[i]<<" ";
|
/* =========================================================
|
||||||
cout<<endl;
|
*
|
||||||
|
* Eval fitness function
|
||||||
|
*
|
||||||
|
* ========================================================= */
|
||||||
|
|
||||||
/* =========================================================
|
EvalOneMax<solution> eval;
|
||||||
*
|
|
||||||
* Eval fitness function
|
|
||||||
*
|
|
||||||
* ========================================================= */
|
|
||||||
|
|
||||||
EvalOneMax<solution> eval;
|
/* =========================================================
|
||||||
|
*
|
||||||
/* =========================================================
|
* Evaluation of a solution neighbor's
|
||||||
*
|
*
|
||||||
* Evaluation of a solution neighbor's
|
* ========================================================= */
|
||||||
*
|
|
||||||
* ========================================================= */
|
|
||||||
|
|
||||||
OneMaxIncrEval<Neighbor> incr_eval;
|
OneMaxIncrEval<Neighbor> incr_eval;
|
||||||
moCudaVectorEval<Neighbor,OneMaxIncrEval<Neighbor> > cueval(vecSize,incr_eval);
|
moCudaVectorEval<Neighbor,OneMaxIncrEval<Neighbor> > cueval(vecSize,incr_eval);
|
||||||
/* =========================================================
|
|
||||||
*
|
|
||||||
* Comparator of solutions and neighbors
|
|
||||||
*
|
|
||||||
* ========================================================= */
|
|
||||||
|
|
||||||
// moNeighborComparator<Neighbor> comparator;
|
/* =========================================================
|
||||||
moSolNeighborComparator<Neighbor> solComparator;
|
*
|
||||||
|
* a solution neighborhood
|
||||||
/* =========================================================
|
*
|
||||||
*
|
* ========================================================= */
|
||||||
* a solution neighborhood
|
|
||||||
*
|
|
||||||
* ========================================================= */
|
|
||||||
|
|
||||||
Neighborhood neighborhood(vecSize,cueval);
|
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<solution> coolingSchedule(500, 0.9, 1000, 0.01);
|
moSimpleCoolingSchedule<solution> coolingSchedule(500, 0.9, 1000, 0.01);
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* the local search algorithm
|
* the local search algorithm
|
||||||
*
|
*
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
moSA<Neighbor> localSearch1(neighborhood, eval, cueval,coolingSchedule);
|
moSA<Neighbor> SA(neighborhood, eval, cueval,coolingSchedule);
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* execute the local search from random solution
|
* execute the local search from random solution
|
||||||
*
|
*
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
//init(solution);
|
//init(solution);
|
||||||
eval(sol);
|
eval(sol);
|
||||||
|
|
||||||
std::cout << "#########################################" << std::endl;
|
std::cout << "#########################################" << std::endl;
|
||||||
std::cout << "initial solution1: " << sol.fitness() << 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<Neighbor> solComparator;
|
|
||||||
|
|
||||||
/* =========================================================
|
|
||||||
*
|
|
||||||
* Example of Checkpointing
|
|
||||||
*
|
|
||||||
* ========================================================= */
|
|
||||||
|
|
||||||
/*moTrueContinuator<Neighbor> continuator;//always continue
|
|
||||||
moCheckpoint<Neighbor> checkpoint(continuator);
|
|
||||||
moFitnessStat<solution> fitStat;
|
|
||||||
checkpoint.add(fitStat);
|
|
||||||
eoFileMonitor monitor("fitness.out", "");
|
|
||||||
moCounterMonitorSaver countMon(100, monitor);
|
|
||||||
checkpoint.add(countMon);
|
|
||||||
monitor.add(fitStat);
|
|
||||||
|
|
||||||
moSA<Neighbor> localSearch2(neighborhood, eval, cueval, coolingSchedule, solComparator, checkpoint);
|
|
||||||
|
|
||||||
|
|
||||||
eval(sol1);
|
|
||||||
for(int i=0;i<vecSize;i++) cout<<sol1[i]<<" ";
|
|
||||||
cout<<endl;
|
|
||||||
|
|
||||||
std::cout << "#########################################" << std::endl;
|
|
||||||
std::cout << "initial solution2: " << sol1.fitness() << std::endl ;
|
|
||||||
|
|
||||||
localSearch2(sol);
|
|
||||||
|
|
||||||
std::cout << "final solution2: " << sol1.fitness() << std::endl ;
|
|
||||||
std::cout << "#########################################" << std::endl;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A main that catc hes the exceptions
|
// A main that catc hes the exceptions
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
main_function(argc, argv);
|
main_function(argc, argv);
|
||||||
}
|
}
|
||||||
catch (exception& e) {
|
catch (exception& e) {
|
||||||
cout << "Exception: " << e.what() << '\n';
|
cout << "Exception: " << e.what() << '\n';
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue