git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2093 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
boufaras 2011-01-28 16:38:00 +00:00
commit 47fac5086e

View file

@ -11,6 +11,7 @@ __device__ int * dev_b;
// The general include for eo // The general include for eo
#include <eo> #include <eo>
#include <ga.h> #include <ga.h>
#include <eval/moCudakernelEval.h>
// Fitness function // Fitness function
#include <problems/eval/QAPEval.h> #include <problems/eval/QAPEval.h>
// Cuda Fitness function // Cuda Fitness function
@ -24,27 +25,22 @@ __device__ int * dev_b;
#include <neighborhood/moKswapNeighbor.h> #include <neighborhood/moKswapNeighbor.h>
//To compute execution time //To compute execution time
#include <performance/moCudaTimer.h> #include <performance/moCudaTimer.h>
// QAP ordered neighborhood //Kswap neighborhood
#include <neighborhood/moCudaKswapNeighborhood.h> #include <neighborhood/moCudaKswapNeighborhood.h>
// The Solution and neighbor comparator // The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h> #include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h> #include <comparator/moSolNeighborComparator.h>
// The Iter continuator // The Iter continuator
#include <continuator/moIterContinuator.h> #include <continuator/moIterContinuator.h>
// Local search algorithm // The Tabou Search algorithm
#include <algo/moLocalSearch.h>
// The Tabou Search algorithm explorer
#include <explorer/moTSexplorer.h>
//Algorithm and its components
#include <algo/moTS.h> #include <algo/moTS.h>
//Tabu list //Tabu list
#include <memory/moNeighborVectorTabuList.h> #include <memory/moIndexedVectorTabuList.h>
//Memories //Memories
#include <memory/moDummyIntensification.h> #include <memory/moDummyIntensification.h>
#include <memory/moDummyDiversification.h> #include <memory/moDummyDiversification.h>
#include <memory/moBestImprAspiration.h> #include <memory/moBestImprAspiration.h>
//#include <time.h> #include <time.h>
typedef moCudaIntVector<eoMinimizingFitness> solution; typedef moCudaIntVector<eoMinimizingFitness> solution;
typedef moKswapNeighbor<solution> Neighbor; typedef moKswapNeighbor<solution> Neighbor;
@ -54,97 +50,99 @@ typedef moCudaKswapNeighborhood<Neighbor> Neighborhood;
int main(int argc, char **argv) int main(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
// seed // seed
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();
// Swap number // Swap number
eoValueParam<unsigned int> KSwapParam(1, "KSwap", "swap number", 'N'); eoValueParam<unsigned int> KSwapParam(1, "KSwap", "swap number", 'N');
parser.processParam(KSwapParam, "KSwap" ); parser.processParam(KSwapParam, "KSwap" );
unsigned KSwap = KSwapParam.value(); unsigned KSwap = KSwapParam.value();
// Iteration number // Iteration number
eoValueParam<unsigned int> nbIterationParam(1, "nbIteration", "TS Iteration number", 'I'); eoValueParam<unsigned int> nbIterationParam(1, "nbIteration", "TS Iteration number", 'I');
parser.processParam( nbIterationParam, "TS Iteration number" ); parser.processParam( nbIterationParam, "TS Iteration number" );
unsigned nbIteration = nbIterationParam.value(); unsigned nbIteration = nbIterationParam.value();
// size tabu list // size tabu list
eoValueParam<unsigned int> sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T'); eoValueParam<unsigned int> sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T');
parser.processParam( sizeTabuListParam, "Search Parameters" ); parser.processParam( sizeTabuListParam, "Search Parameters" );
unsigned sizeTabuList = sizeTabuListParam.value(); unsigned sizeTabuList = sizeTabuListParam.value();
// duration tabu list // duration tabu list
eoValueParam<unsigned int> durationParam(7, "duration", "duration of the tabu list", 'D'); eoValueParam<unsigned int> durationParam(7, "duration", "duration of the tabu list", 'D');
parser.processParam( durationParam, "Search Parameters" ); parser.processParam( durationParam, "Search Parameters" );
unsigned duration = durationParam.value(); unsigned duration = durationParam.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 aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); // rng.reseed(seed);
//srand(time(NULL)); srand(seed);
/* ========================================================= /* =========================================================
* *
* Initilisation of QAP data * Initilisation of QAP data
* *
* ========================================================= */ * ========================================================= */
QAPData<int> _data(argv[1]); QAPData<int> _data(argv[1]);
unsigned vecSize=_data.sizeData; unsigned vecSize=_data.sizeData;
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
solution sol(vecSize); solution sol(vecSize);
_data.cudaObject.memCopyGlobalVariable(dev_a,_data.a_d); _data.cudaObject.memCopyGlobalVariable(dev_a,_data.a_d);
_data.cudaObject.memCopyGlobalVariable(dev_b,_data.b_d); _data.cudaObject.memCopyGlobalVariable(dev_b,_data.b_d);
/* ========================================================= /*=========================================================
* *
* Evaluation of a solution neighbor's * Evaluation of a solution neighbor's
* *
* ========================================================= */ * ========================================================= */
QAPEval<solution> eval(_data);
unsigned long int sizeMap=sizeMapping(vecSize,KSwap); QAPEval<solution> eval(_data);
// std::cout<<"sizeMap : "<<sizeMap<<std::endl; unsigned long int sizeMap=sizeMapping(vecSize,1);
QAPIncrEval<Neighbor> incr_eval; QAPIncrEval<Neighbor> incr_eval;
moCudaKswapEval<Neighbor,QAPIncrEval<Neighbor> > cueval(sizeMap,incr_eval); moCudaKswapEval<Neighbor,QAPIncrEval<Neighbor> > cueval(sizeMap,incr_eval);
/* ========================================================= /* =========================================================
* *
@ -152,8 +150,8 @@ int main(int argc, char **argv)
* *
* ========================================================= */ * ========================================================= */
moNeighborComparator<Neighbor> comparator; moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator; moSolNeighborComparator<Neighbor> solComparator;
/* ========================================================= /* =========================================================
* *
@ -161,27 +159,26 @@ int main(int argc, char **argv)
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize,KSwap,cueval); Neighborhood neighborhood(vecSize,1,cueval);
/* ========================================================= /* =========================================================
* *
* continuator * continuator
* *
* ========================================================= */ * ========================================================= */
moIterContinuator <Neighbor> continuator(nbIteration); moIterContinuator <Neighbor> continuator(nbIteration);
/* ========================================================= /* =========================================================
* *
* tabu list * tabu list
* *
* ========================================================= */ * ========================================================= */
//moNeighborVectorTabuList<shiftNeighbor> tl(sizeTabuList,0); sizeTabuList=(vecSize*(vecSize-1))/2;
sizeTabuList=(vecSize*(vecSize-1))/2; duration=sizeTabuList/8;
duration=sizeTabuList/8; // tabu list
// tabu list moIndexedVectorTabuList<Neighbor> tl(sizeTabuList,duration);
moNeighborVectorTabuList<Neighbor> tl(sizeTabuList,duration);
/* ========================================================= /* =========================================================
* *
@ -189,27 +186,18 @@ int main(int argc, char **argv)
* *
* ========================================================= */ * ========================================================= */
moDummyIntensification<Neighbor> inten; moDummyIntensification<Neighbor> inten;
moDummyDiversification<Neighbor> div; moDummyDiversification<Neighbor> div;
moBestImprAspiration<Neighbor> asp; moBestImprAspiration<Neighbor> asp;
/* ========================================================= /* =========================================================
* *
* An explorer of solution neighborhood's * The Tabu search algorithm
* *
* ========================================================= */ * ========================================================= */
moTSexplorer<Neighbor> explorer(neighborhood, cueval, comparator, solComparator, tl, inten, div, asp); moTS<Neighbor> tabuSearch(neighborhood, eval, cueval, comparator, solComparator, continuator, tl, inten, div, asp);
/* =========================================================
*
* the local search algorithm
*
* ========================================================= */
moLocalSearch<Neighbor> localSearch1(explorer, continuator, eval);
/* ========================================================= /* =========================================================
* *
* Execute the local search from random sollution * Execute the local search from random sollution
@ -221,9 +209,10 @@ int main(int argc, char **argv)
std::cout << "initial: " << sol<< std::endl; std::cout << "initial: " << sol<< std::endl;
// Create timer for timing CUDA calculation // Create timer for timing CUDA calculation
cudaFuncSetCacheConfig(kernelPermutation<solution,eoMinimizingFitness, Neighbor , QAPIncrEval<Neighbor> >, cudaFuncCachePreferL1);
moCudaTimer timer; moCudaTimer timer;
timer.start(); timer.start();
localSearch1(sol); tabuSearch(sol);
std::cout << "final: " << sol << std::endl; std::cout << "final: " << sol << std::endl;
timer.stop(); timer.stop();
printf("CUDA execution time = %f ms\n",timer.getTime()); printf("CUDA execution time = %f ms\n",timer.getTime());