//Init the number of threads per block #define BLOCK_SIZE 128 #include #include using namespace std; // The general include for eo #include #include // Fitness function #include // Cuda Fitness function #include #include // One Max solution #include //To compute execution time #include // One Max neighbor #include // One Max 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 // REPRESENTATION typedef moCudaBitVector solution; typedef moCudaBitNeighbor Neighbor; typedef moCudaOrderNeighborhood 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(); // description of genotype eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); parser.processParam( vecSizeParam, "Representation" ); unsigned vecSize = vecSizeParam.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; moCudaVectorEval > cueval(vecSize,incr_eval); /* ========================================================= * * Comparator of solutions and neighbors * * ========================================================= */ moNeighborComparator comparator; moSolNeighborComparator solComparator; /* ========================================================= * * a solution neighborhood * * ========================================================= */ Neighborhood neighborhood(vecSize,cueval); /* ========================================================= * * continuator * * ========================================================= */ moTimeContinuator continuator(timeLimit); /* ========================================================= * * tabu list * * ========================================================= */ //moNeighborVectorTabuList tl(sizeTabuList,0); // tabu list moNeighborVectorTabuList tl(sizeTabuList,0); /* ========================================================= * * Memories * * ========================================================= */ moDummyIntensification inten; moDummyDiversification div; moBestImprAspiration asp; /* ========================================================= * * An explorer of solution neighborhood's * * ========================================================= */ moTSexplorer explorer(neighborhood, cueval, comparator, solComparator, tl, inten, div, asp); /* ========================================================= * * the local search algorithm * * ========================================================= */ moLocalSearch localSearch1(explorer, continuator, eval); //Basic Constructor moTS localSearch2(neighborhood,eval, cueval, 2, 7); //Simple Constructor moTS localSearch3(neighborhood, eval, cueval, 5, tl); //General Constructor moTS localSearch4(neighborhood, eval, cueval, comparator, solComparator, continuator, tl, inten, div, asp); /* ========================================================= * * Execute the local search(TS) from random sollution * * ========================================================= */ //Initilisation of the solution solution sol1(vecSize); eval(sol1); std::cout << "Tabu Search 1:" << std::endl; std::cout << "---------------------" << std::endl; std::cout << "initial: " << sol1.fitness()<< std::endl; moCudaTimer timer1; timer1.start(); localSearch1(sol1); timer1.stop(); printf("CUDA execution time = %f ms\n",timer1.getTime()); timer1.deleteTimer(); std::cout << "final: " << sol1.fitness() << std::endl<