Rename package

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2443 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
boufaras 2011-09-29 14:19:33 +00:00
commit 9c03bd2ecc
26 changed files with 3769 additions and 0 deletions

View file

@ -0,0 +1,6 @@
ADD_SUBDIRECTORY(OneMax)
ADD_SUBDIRECTORY(Kswap-OneMax)
ADD_SUBDIRECTORY(PPP_GPU)
ADD_SUBDIRECTORY(QAP_GPU)
ADD_SUBDIRECTORY(QAP_CPU)

View file

@ -0,0 +1,50 @@
###############################################################################
##
## CMakeLists file for OneMax Example/application
##
###############################################################################
######################################################################################
### 1) Include the sources
######################################################################################
INCLUDE_DIRECTORIES(
# include CUDA source directory
${CUDA_SRC_DIR}
# include EO source directory
${PARADISEO_EO_SRC_DIR}/src
# include MO source directory
${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
)
######################################################################################
######################################################################################
### 2) Specify where CMake can find the libraries
######################################################################################
LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${CUDA_LIB_DIR} )
######################################################################################
######################################################################################
### 3) Define your targets and link the librairies
######################################################################################
CUDA_ADD_EXECUTABLE(GPUtestKswapHCByModif testKswapHCByModif.cu)
CUDA_ADD_EXECUTABLE(GPUtestKswapHCByCpy testKswapHCByCpy.cu)
TARGET_LINK_LIBRARIES(GPUtestKswapHCByModif eoutils ga eo)
TARGET_LINK_LIBRARIES(GPUtestKswapHCByCpy eoutils ga eo)
######################################################################################

View file

@ -0,0 +1,50 @@
/*
<moGPUConfig.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moGPUConfig_H
#define __moGPUConfig_H
#define BLOCK_SIZE 8
#ifndef NB_POS
#define NB_POS 2
#endif
#ifndef SIZE
#define SIZE 60
#endif
#endif

View file

@ -0,0 +1,210 @@
/*
<testKswapHCByCpy.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
// The general include for eo
#include <eo>
#include <ga.h>
// OneMax full eval function
#include <problems/eval/EvalOneMax.h>
// OneMax incremental eval function
#include <eval/moGPUMappingEvalByCpy.h>
#include <problems/eval/OneMaxIncrEval.h>
// One Max solution
#include <GPUType/moGPUBitVector.h>
// One Max neighbor
#include <neighborhood/moGPUXBitFlippingNeighbor.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//Utils to compute size Mapping of x-change position
#include <neighborhood/moNeighborhoodSizeUtils.h>
// Use an ordered neighborhood without mapping, with local copy of solution
#include <neighborhood/moGPUXChangeNeighborhoodByCpy.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The continuator
#include <continuator/moTrueContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
// The simple HC algorithm explorer
#include <explorer/moSimpleHCexplorer.h>
// REPRESENTATION
typedef moGPUBitVector<eoMaximizingFitness> solution;
typedef moGPUXBitFlippingNeighbor<eoMaximizingFitness> Neighbor;
typedef moGPUXChangeNeighborhoodByCpy<Neighbor> 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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(SIZE);
/* =========================================================
*
* Eval fitness function
*
* ========================================================= */
EvalOneMax<solution> eval;
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
unsigned long int sizeMap=sizeMapping(SIZE,NB_POS);
OneMaxIncrEval<Neighbor> incr_eval;
moGPUMappingEvalByCpy<Neighbor,OneMaxIncrEval<Neighbor> > cueval(sizeMap,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(sizeMap,NB_POS,cueval);
/* =========================================================
*
* An explorer of solution neighborhood's
*
* ========================================================= */
moSimpleHCexplorer<Neighbor> explorer(neighborhood, cueval,
comparator, solComparator);
/* =========================================================
*
* The local search algorithm
*
* ========================================================= */
//True continuator <=> Always continue
moTrueContinuator<Neighbor> continuator;
moLocalSearch<Neighbor> localSearch(explorer,continuator, eval);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
// Create timer for timing CUDA calculation
moGPUTimer timer;
timer.start();
localSearch(sol);
timer.stop();
std::cout << "final: " << sol<< std::endl;
printf("Execution time = %f ms\n",timer.getTime());
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try{
main_function(argc, argv);
}
catch(exception& e){
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -0,0 +1,220 @@
/*
<testKswapHC.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
// The general include for eo
#include <eo>
#include <ga.h>
// OneMax full eval function
#include <problems/eval/EvalOneMax.h>
// OneMax incremental eval function
#include <eval/moGPUMappingEvalByModif.h>
#include <problems/eval/OneMaxIncrEval.h>
// One Max solution
#include <GPUType/moGPUBitVector.h>
// One Max neighbor
#include <neighborhood/moGPUXBitFlippingNeighbor.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//Utils to compute size Mapping of x-change position
#include <neighborhood/moNeighborhoodSizeUtils.h>
// One Max ordered neighborhood
#include <neighborhood/moGPUXChangeNeighborhoodByModif.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The continuator
#include <continuator/moTrueContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
// The simple HC algorithm explorer
#include <explorer/moSimpleHCexplorer.h>
// REPRESENTATION
typedef moGPUBitVector<eoMaximizingFitness> solution;
typedef moGPUXBitFlippingNeighbor<eoMaximizingFitness> Neighbor;
typedef moGPUXChangeNeighborhoodByModif<Neighbor> 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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// description of genotype
/*eoValueParam<unsigned int> vecSizeParam(100, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value();*/
//Number of position to change
/* eoValueParam<unsigned int> nbPosParam(1, "nbPos", "X Change", 'N');
parser.processParam( nbPosParam, "Exchange" );
unsigned nbPos = nbPosParam.value();*/
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(SIZE);
/* =========================================================
*
* Eval fitness function
*
* ========================================================= */
EvalOneMax<solution> eval;
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
unsigned long int sizeMap=sizeMapping(SIZE,NB_POS);
OneMaxIncrEval<Neighbor> incr_eval;
moGPUMappingEvalByModif<Neighbor,OneMaxIncrEval<Neighbor> > cueval(sizeMap,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(sizeMap,NB_POS,cueval);
/* =========================================================
*
* An explorer of solution neighborhood's
*
* ========================================================= */
moSimpleHCexplorer<Neighbor> explorer(neighborhood, cueval,
comparator, solComparator);
/* =========================================================
*
* The local search algorithm
*
* ========================================================= */
//True continuator <=> Always continue
moTrueContinuator<Neighbor> continuator;
moLocalSearch<Neighbor> localSearch(explorer,continuator, eval);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
// Create timer for timing CUDA calculation
moGPUTimer timer;
timer.start();
localSearch(sol);
timer.stop();
std::cout << "final: " << sol<< std::endl;
printf("Execution time = %f ms\n",timer.getTime());
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try{
main_function(argc, argv);
}
catch(exception& e){
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -0,0 +1,56 @@
###############################################################################
##
## CMakeLists file for OneMax Example/application
##
###############################################################################
######################################################################################
### 1) Include the sources
######################################################################################
INCLUDE_DIRECTORIES(
# include CUDA source directory
${CUDA_SRC_DIR}
# include EO source directory
${PARADISEO_EO_SRC_DIR}/src
# include MO source directory
${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
)
######################################################################################
######################################################################################
### 2) Specify where CMake can find the libraries
######################################################################################
LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${CUDA_LIB_DIR} )
######################################################################################
######################################################################################
### 3) Define your targets and link the librairies
######################################################################################
CUDA_ADD_EXECUTABLE(GPUtestFirstImpr testFirstImpr.cu)
CUDA_ADD_EXECUTABLE(GPUtestNeutralHC testNeutralHC.cu)
CUDA_ADD_EXECUTABLE(GPUtestSimpleHC testSimpleHC.cu)
CUDA_ADD_EXECUTABLE(GPUtestSimpleHCByCpy testSimpleHCByCpy.cu)
CUDA_ADD_EXECUTABLE(GPUtestSimpleTS testSimpleTS.cu)
CUDA_ADD_EXECUTABLE(GPUtestSimulatedAnnealing testSimulatedAnnealing.cu)
TARGET_LINK_LIBRARIES(GPUtestFirstImpr eoutils ga eo)
TARGET_LINK_LIBRARIES(GPUtestNeutralHC eoutils ga eo)
TARGET_LINK_LIBRARIES(GPUtestSimpleHC eoutils ga eo)
TARGET_LINK_LIBRARIES(GPUtestSimpleHCByCpy eoutils ga eo)
TARGET_LINK_LIBRARIES(GPUtestSimpleTS eoutils ga eo)
TARGET_LINK_LIBRARIES(GPUtestSimulatedAnnealing eoutils ga eo)
######################################################################################

View file

@ -0,0 +1,50 @@
/*
<moGPUConfig.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moGPUConfig_H
#define __moGPUConfig_H
#define BLOCK_SIZE 8
#ifndef NB_POS
#define NB_POS 1
#endif
#ifndef SIZE
#define SIZE 60
#endif
#endif

View file

@ -0,0 +1,241 @@
/*
<testFirstImpr.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
// The general include for eo
#include <eo>
#include <ga.h>
// OneMax full eval function
#include <problems/eval/EvalOneMax.h>
//Parallel evaluation of neighborhood on GPU
#include <eval/moGPUEvalByModif.h>
// OneMax increment evaluation function
#include <problems/eval/OneMaxIncrEval.h>
// One Max solution
#include <GPUType/moGPUBitVector.h>
// Bit neighbor
#include <neighborhood/moGPUBitNeighbor.h>
// Ordered neighborhood
#include <neighborhood/moGPUOrderNeighborhoodByModif.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The continuator
#include <continuator/moTrueContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
// First improvment algorithm
#include <algo/moFirstImprHC.h>
// The First Improvment algorithm explorer
#include <explorer/moFirstImprHCexplorer.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//------------------------------------------------------------------------------------
// Define types of the representation solution, different neighbors and neighborhoods
//------------------------------------------------------------------------------------
typedef moGPUBitVector<eoMaximizingFitness> solution;
typedef moGPUBitNeighbor <eoMaximizingFitness> Neighbor;
typedef moGPUOrderNeighborhoodByModif<Neighbor> 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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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 always get the same result, NOT a random run
rng.reseed(seed);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(SIZE);
/* =========================================================
*
* Eval fitness function
*
* ========================================================= */
EvalOneMax<solution> eval;
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
OneMaxIncrEval<Neighbor> incr_eval;
moGPUEvalByModif<Neighbor,OneMaxIncrEval<Neighbor> > gpuEval(SIZE,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(SIZE,gpuEval);
/* =========================================================
*
* An explorer of solution neighborhood's
*
* ========================================================= */
moFirstImprHCexplorer<Neighbor> explorer(neighborhood, gpuEval, comparator, solComparator);
/* =========================================================
*
* The local search algorithm
*
* ========================================================= */
// True continuator <=> Always continue
moTrueContinuator<Neighbor> continuator;
moLocalSearch<Neighbor> localSearch(explorer,continuator, eval);
/* =========================================================
*
* The First improvment algorithm
*
* ========================================================= */
moFirstImprHC<Neighbor> firstImprHC(neighborhood,eval,gpuEval);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
moGPUTimer timer;
timer.start();
localSearch(sol);
timer.stop();
std::cout << "final: " << sol << std::endl;
printf("Execution time = %.2lf s\n",timer.getTime());
/* =========================================================
*
* Execute the first improvment from random sollution
*
* ========================================================= */
solution sol1(SIZE);
eval(sol1);
std::cout<< std::endl;
std::cout << "initial: " << sol1<< std::endl;
moGPUTimer timer1;
timer1.start();
firstImprHC(sol1);
timer1.stop();
std::cout << "final: " << sol1 << std::endl;
printf("Execution time = %.2lf s\n",timer1.getTime());
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try{
main_function(argc, argv);
}
catch(exception& e){
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -0,0 +1,208 @@
/*
<testNeutralHC.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
// The general include for eo
#include <eo>
#include <ga.h>
// OneMax full eval function
#include <problems/eval/EvalOneMax.h>
//Parallel evaluation of neighborhood on GPU
#include <eval/moGPUEvalByModif.h>
// OneMax increment evaluation function
#include <problems/eval/OneMaxIncrEval.h>
// One Max solution
#include <GPUType/moGPUBitVector.h>
// Bit neighbor
#include <neighborhood/moGPUBitNeighbor.h>
// Ordered neighborhood
#include <neighborhood/moGPUOrderNeighborhoodByModif.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The continuator
#include <continuator/moTrueContinuator.h>
// Neutral HC algorithm
#include <algo/moNeutralHC.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//------------------------------------------------------------------------------------
// Define types of the representation solution, different neighbors and neighborhoods
//------------------------------------------------------------------------------------
typedef moGPUBitVector<eoMaximizingFitness> solution;
typedef moGPUBitNeighbor <eoMaximizingFitness> Neighbor;
typedef moGPUOrderNeighborhoodByModif<Neighbor> 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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
//nbStep maximum step to do
eoValueParam<unsigned int> nbStepParam(10, "nbStep", "maximum number of step", 'n');
parser.processParam( nbStepParam, "numberStep" );
unsigned nbStep = nbStepParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(SIZE);
/* =========================================================
*
* Eval fitness function
*
* ========================================================= */
EvalOneMax<solution> eval;
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
OneMaxIncrEval<Neighbor> incr_eval;
moGPUEvalByModif<Neighbor,OneMaxIncrEval<Neighbor> > gpuEval(SIZE,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(SIZE,gpuEval);
/* =========================================================
*
* The neutral Hill Climbing algorithm
*
* ========================================================= */
//True continuator <=> Always continue
moTrueContinuator<Neighbor> continuator;
moNeutralHC<Neighbor> neutralHC(neighborhood,eval,gpuEval,nbStep,continuator);
/* =========================================================
*
* Execute the neutral Hill climbing from random sollution
*
* ========================================================= */
eval(sol);
std::cout << "initial: " << sol<< std::endl;
moGPUTimer timer;
timer.start();
neutralHC(sol);
timer.stop();
std::cout << "final: " << sol << std::endl;
printf("Execution time = %.2lf s\n",timer.getTime());
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try{
main_function(argc, argv);
}
catch(exception& e){
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -0,0 +1,243 @@
/*
<testSimpleHC.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
// The general include for eo
#include <eo>
#include <ga.h>
// OneMax full eval function
#include <problems/eval/EvalOneMax.h>
//Parallel evaluation of neighborhood on GPU
#include <eval/moGPUEvalByModif.h>
// OneMax increment evaluation function
#include <problems/eval/OneMaxIncrEval.h>
// One Max solution
#include <GPUType/moGPUBitVector.h>
// Bit neighbor
#include <neighborhood/moGPUBitNeighbor.h>
// Ordered neighborhood
#include <neighborhood/moGPUOrderNeighborhoodByModif.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The continuator
#include <continuator/moTrueContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
// Simple HC algorithm
#include <algo/moSimpleHC.h>
// The simple HC algorithm explorer
#include <explorer/moSimpleHCexplorer.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//------------------------------------------------------------------------------------
// Define types of the representation solution, different neighbors and neighborhoods
//------------------------------------------------------------------------------------
typedef moGPUBitVector<eoMaximizingFitness> solution;
typedef moGPUBitNeighbor <eoMaximizingFitness> Neighbor;
typedef moGPUOrderNeighborhoodByModif<Neighbor> 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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(SIZE);
/* =========================================================
*
* Eval fitness function
*
* ========================================================= */
EvalOneMax<solution> eval;
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
OneMaxIncrEval<Neighbor> incr_eval;
moGPUEvalByModif<Neighbor,OneMaxIncrEval<Neighbor> > cueval(SIZE,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(SIZE,cueval);
/* =========================================================
*
* An explorer of solution neighborhood's
*
* ========================================================= */
moSimpleHCexplorer<Neighbor> explorer(neighborhood, cueval,
comparator, solComparator);
/* =========================================================
*
* The local search algorithm
*
* ========================================================= */
//True continuator <=> Always continue
moTrueContinuator<Neighbor> continuator;
moLocalSearch<Neighbor> localSearch(explorer,continuator, eval);
/* =========================================================
*
* The simple Hill Climbing algorithm
*
* ========================================================= */
moSimpleHC<Neighbor> simpleHC(neighborhood,eval,cueval);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
// Create timer for timing CUDA calculation
moGPUTimer timer;
timer.start();
localSearch(sol);
timer.stop();
std::cout << "final: " << sol << std::endl;
printf("Execution time = %0.2lf s\n",timer.getTime());
/* =========================================================
*
* Execute the Simple Hill climbing from random sollution
*
* ========================================================= */
cout<<endl;
solution sol1(SIZE);
eval(sol1);
std::cout << "initial: " << sol1<< std::endl;
// Create timer for timing CUDA calculation
moGPUTimer timer1;
timer1.start();
simpleHC(sol1);
timer1.stop();
std::cout << "final: " << sol1 << std::endl;
printf("Execution time = %0.2lf s\n",timer1.getTime());
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try{
main_function(argc, argv);
}
catch(exception& e){
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -0,0 +1,244 @@
/*
<testSimpleHCByCpy.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
// The general include for eo
#include <eo>
#include <ga.h>
// One Max full eval function
#include <problems/eval/EvalOneMax.h>
//Parallel evaluation of neighborhood on GPU
#include <eval/moGPUEvalByCpy.h>
// One Max increment evaluation function
#include <problems/eval/OneMaxIncrEval.h>
// One Max solution
#include <GPUType/moGPUBitVector.h>
// Bit neighbor
#include <neighborhood/moGPUBitNeighbor.h>
// Ordered neighborhood
#include <neighborhood/moGPUOrderNeighborhoodByCpy.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The continuator
#include <continuator/moTrueContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
// Simple HC algorithm
#include <algo/moSimpleHC.h>
// The simple HC algorithm explorer
#include <explorer/moSimpleHCexplorer.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//------------------------------------------------------------------------------------
// Define types of the representation solution, different neighbors and neighborhoods
//------------------------------------------------------------------------------------
typedef moGPUBitVector<eoMaximizingFitness> solution;
typedef moGPUBitNeighbor<eoMaximizingFitness> Neighbor;
typedef moGPUOrderNeighborhoodByCpy<Neighbor> 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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
srand(seed);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(SIZE);
/* =========================================================
*
* Eval fitness function
*
* ========================================================= */
EvalOneMax<solution> eval;
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
OneMaxIncrEval<Neighbor> incr_eval;
moGPUEvalByCpy<Neighbor,OneMaxIncrEval<Neighbor> > gpuEval(SIZE,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(SIZE,gpuEval);
/* =========================================================
*
* An explorer of solution neighborhood's
*
* ========================================================= */
moSimpleHCexplorer<Neighbor> explorer(neighborhood, gpuEval,
comparator, solComparator);
/* =========================================================
*
* The local search algorithm
*
* ========================================================= */
//True continuator <=> Always continue
moTrueContinuator<Neighbor> continuator;
moLocalSearch<Neighbor> localSearch(explorer,continuator, eval);
/* =========================================================
*
* The simple Hill Climbing algorithm
*
* ========================================================= */
moSimpleHC<Neighbor> simpleHC(neighborhood,eval,gpuEval);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
// Create timer for timing GPU calculation
moGPUTimer timer;
timer.start();
//Run the local search with Simple Hill climbing explorer
localSearch(sol);
timer.stop();
std::cout << "final: " << sol << std::endl;
printf("Execution time = %0.2lf s\n",timer.getTime());
/* =========================================================
*
* Execute the Simple Hill climbing from random sollution
*
* ========================================================= */
cout<<endl;
solution sol1(SIZE);
eval(sol1);
std::cout << "initial: " << sol1<< std::endl;
moGPUTimer timer1;
timer1.start();
// Run Simple Hill Climbing
simpleHC(sol1);
timer1.stop();
std::cout << "final: " << sol1 << std::endl;
printf("Execution time = %0.2lf s\n",timer1.getTime());
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try{
main_function(argc, argv);
}
catch(exception& e){
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -0,0 +1,313 @@
/*
<testSimpleTS.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
// The general include for eo
#include <eo>
#include <ga.h>
// OneMax full eval function
#include <problems/eval/EvalOneMax.h>
//Parallel evaluation of neighborhood on GPU
#include <eval/moGPUEvalByModif.h>
// OneMax increment evaluation function
#include <problems/eval/OneMaxIncrEval.h>
// One Max solution
#include <GPUType/moGPUBitVector.h>
// Bit neighbor
#include <neighborhood/moGPUBitNeighbor.h>
// Ordered neighborhood
#include <neighborhood/moGPUOrderNeighborhoodByModif.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The time continuator
#include <continuator/moTimeContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
// The Tabou Search algorithm explorer
#include <explorer/moTSexplorer.h>
//Algorithm and its components
#include <algo/moTS.h>
//Tabu list
#include <memory/moNeighborVectorTabuList.h>
//Memories
#include <memory/moDummyIntensification.h>
#include <memory/moDummyDiversification.h>
#include <memory/moBestImprAspiration.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//------------------------------------------------------------------------------------
// Define types of the representation solution, different neighbors and neighborhoods
//------------------------------------------------------------------------------------
typedef moGPUBitVector<eoMaximizingFitness> solution;
typedef moGPUBitNeighbor <eoMaximizingFitness> Neighbor;
typedef moGPUOrderNeighborhoodByModif<Neighbor> 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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// size tabu list
eoValueParam<unsigned int> sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T');
parser.processParam( sizeTabuListParam, "Search Parameters" );
unsigned sizeTabuList = sizeTabuListParam.value();
// time Limit
eoValueParam<unsigned int> 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<string> 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<solution> eval;
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
OneMaxIncrEval<Neighbor> incr_eval;
moGPUEvalByModif<Neighbor,OneMaxIncrEval<Neighbor> > gpuEval(SIZE,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(SIZE,gpuEval);
/* =========================================================
*
* continuator
*
* ========================================================= */
moTimeContinuator <Neighbor> continuator(timeLimit);
/* =========================================================
*
* tabu list
*
* ========================================================= */
moNeighborVectorTabuList<Neighbor> tl(sizeTabuList,0);
/* =========================================================
*
* Memories
*
* ========================================================= */
moDummyIntensification<Neighbor> inten;
moDummyDiversification<Neighbor> div;
moBestImprAspiration<Neighbor> asp;
/* =========================================================
*
* An explorer of solution neighborhood's
*
* ========================================================= */
moTSexplorer<Neighbor> explorer(neighborhood, gpuEval, comparator, solComparator, tl, inten, div, asp);
/* =========================================================
*
* the local search algorithm
*
* ========================================================= */
moLocalSearch<Neighbor> localSearch1(explorer, continuator, eval);
//Basic Constructor
moTS<Neighbor> localSearch2(neighborhood,eval, gpuEval, 2, 7);
//Simple Constructor
moTS<Neighbor> localSearch3(neighborhood, eval, gpuEval, 5, tl);
//General Constructor
moTS<Neighbor> localSearch4(neighborhood, eval, gpuEval, comparator, solComparator, continuator, tl, inten, div, asp);
/* =========================================================
*
* Execute the local search(TS) from random sollution
*
* ========================================================= */
//Initilisation of the solution
solution sol1(SIZE);
eval(sol1);
std::cout << "\nTabu Search 1:" << std::endl;
std::cout << "---------------------" << std::endl;
std::cout << "initial: " << sol1<< std::endl;
moGPUTimer timer1;
timer1.start();
localSearch1(sol1);
timer1.stop();
std::cout << "final: " << sol1 <<std::endl;
printf("Execution time = %.2lf s\n",timer1.getTime());
/* =========================================================
*
* Execute the TS Basic Constructor
*
* ========================================================= */
solution sol2(SIZE);
eval(sol2);
std::cout << "\nTabu Search 2:" << std::endl;
std::cout << "---------------------" << std::endl;
std::cout << "initial: " << sol2<< std::endl;
moGPUTimer timer2;
timer2.start();
localSearch2(sol2);
timer2.stop();
std::cout << "final: " << sol2 << std::endl;
printf("Execution time = %.2lf s\n",timer2.getTime());
/* =========================================================
*
* Execute the TS Simple Constructor
*
* ========================================================= */
solution sol3(SIZE);
eval(sol3);
std::cout << "\nTabu Search 3:" << std::endl;
std::cout << "---------------------" << std::endl;
std::cout << "initial: " << sol3<< std::endl;
moGPUTimer timer3;
timer3.start();
localSearch3(sol3);
timer3.stop();
std::cout << "final: " << sol3<< std::endl;
printf("Execution time = %.2lf s\n",timer3.getTime());
/* =========================================================
*
* Execute the TS General Constructor
*
* ========================================================= */
solution sol4(SIZE);
eval(sol4);
std::cout << "\nTabu Search 4:" << std::endl;
std::cout << "---------------------" << std::endl;
std::cout << "initial: " << sol4<< std::endl;
moGPUTimer timer4;
timer4.start();
localSearch4(sol4);
timer4.stop();
std::cout << "final: " << sol4 << std::endl;
printf("Execution time = %.2lf s\n",timer4.getTime());
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try{
main_function(argc, argv);
}
catch(exception& e){
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -0,0 +1,206 @@
/*
<testSimulatedAnnealing.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
//Init the number of threads per block
#include <iostream>
#include <stdlib.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
// The general include for eo
#include <eo>
#include <ga.h>
// OneMax full eval function
#include <problems/eval/EvalOneMax.h>
//Parallel evaluation of neighborhood on GPU
#include <eval/moGPUEvalByModif.h>
// OneMax increment eval function
#include <problems/eval/OneMaxIncrEval.h>
// One Max solution
#include <GPUType/moGPUBitVector.h>
// Bit neighbor
#include <neighborhood/moGPUBitNeighbor.h>
// Random with replacement neighborhood
#include <neighborhood/moGPURndWithReplNeighborhoodByModif.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//Algorithm and its components
#include <coolingSchedule/moCoolingSchedule.h>
#include <algo/moSA.h>
// The simulated annealing algorithm explorer
#include <explorer/moSAexplorer.h>
//continuators
#include <continuator/moTrueContinuator.h>
#include <continuator/moCheckpoint.h>
#include <continuator/moFitnessStat.h>
#include <utils/eoFileMonitor.h>
#include <continuator/moCounterMonitorSaver.h>
//------------------------------------------------------------------------------------
// Define types of the representation solution, different neighbors and neighborhoods
//------------------------------------------------------------------------------------
typedef moGPUBitVector<eoMaximizingFitness> solution;
typedef moGPUBitNeighbor <eoMaximizingFitness> Neighbor;
typedef moGPURndWithReplNeighborhoodByModif<Neighbor> 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
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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 always get the same result, NOT a random run
rng.reseed(seed);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(SIZE);
/* =========================================================
*
* Eval fitness function
*
* ========================================================= */
EvalOneMax<solution> eval;
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
OneMaxIncrEval<Neighbor> incr_eval;
moGPUEvalByModif<Neighbor,OneMaxIncrEval<Neighbor> > gpuEval(SIZE,incr_eval);
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(SIZE,gpuEval);
/* =========================================================
*
* the cooling schedule of the process
*
* ========================================================= */
// initial temp, factor of decrease, number of steps without decrease, final temp.
moSimpleCoolingSchedule<solution> coolingSchedule(500, 0.9, 1000, 0.01);
/* =========================================================
*
* the local search algorithm
*
* ========================================================= */
moSA<Neighbor> SA(neighborhood, eval, gpuEval,coolingSchedule);
/* =========================================================
*
* execute the local search from random solution
*
* ========================================================= */
//init(solution);
eval(sol);
std::cout << "initial : " << sol << std::endl;
moGPUTimer timer;
timer.start();
SA(sol);
timer.stop();
std::cout << "final : " << sol << std::endl;
printf("Execution time = %.2lf s\n",timer.getTime());
}
// A main that catc hes the exceptions
int main(int argc, char **argv)
{
try {
main_function(argc, argv);
}
catch (exception& e) {
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -0,0 +1,47 @@
##############################################################################
##
## CMakeLists file for OneMax Example/application
##
###############################################################################
######################################################################################
### 1) Include the sources
######################################################################################
INCLUDE_DIRECTORIES(
# include CUDA source directory
${CUDA_SRC_DIR}
# include EO source directory
${PARADISEO_EO_SRC_DIR}/src
# include MO source directory
${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
)
######################################################################################
######################################################################################
### 2) Specify where CMake can find the libraries
######################################################################################
LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${CUDA_LIB_DIR} )
######################################################################################
######################################################################################
### 3) Define your targets and link the librairies
######################################################################################
CUDA_ADD_EXECUTABLE(GPUtestSimpleTS_PPP testSimpleTS_PPP.cu)
TARGET_LINK_LIBRARIES(GPUtestSimpleTS_PPP eoutils ga eo)

View file

@ -0,0 +1,56 @@
/*
<moGPUConfig.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moGPUConfig_H
#define __moGPUConfig_H
#define BLOCK_SIZE 8
#ifndef NB_POS
#define NB_POS 2
#endif
#ifndef SIZE
#define SIZE 73
#define Nd 73
#define Md 73
#define ca 30
#define cb 1
#endif
#endif

View file

@ -0,0 +1,252 @@
/*
<testSimpleTS_PPP.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include "moGPUConfig.h"
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
__device__ int * dev_a;
__device__ int * dev_h;
// The general include for eo
#include <eo>
#include <ga.h>
// Fitness function
#include <problems/eval/PPPEval.h>
// GPU Fitness function
#include <eval/moGPUMappingEvalByModif.h>
#include <problems/eval/PPPIncrEval.h>
//Specific data to PPP problem
#include <problems/data/PPPData.h>
// PPP solution
#include <problems/types/PPPSolution.h>
// PPP neighbor
#include <problems/neighborhood/PPPNeighbor.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//Utils to compute size Mapping of x-change position
#include <neighborhood/moNeighborhoodSizeUtils.h>
//x-Change neighborhood
#include <neighborhood/moGPUXChangeNeighborhoodByModif.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The Iter continuator
#include <continuator/moIterContinuator.h>
// The Tabou Search algorithm
#include <algo/moTS.h>
//Tabu list
#include <memory/moIndexedVectorTabuList.h>
//Memories
#include <memory/moDummyIntensification.h>
#include <memory/moDummyDiversification.h>
#include <memory/moBestImprAspiration.h>
typedef PPPSolution<eoMinimizingFitness> solution;
typedef PPPNeighbor<solution> Neighbor;
typedef moGPUXChangeNeighborhoodByModif<Neighbor> Neighborhood;
int main(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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// Iteration number
eoValueParam<unsigned int> nbIterationParam(1, "nbIteration", "TS Iteration number", 'I');
parser.processParam( nbIterationParam, "TS Iteration number" );
unsigned nbIteration = nbIterationParam.value();
// size tabu list
eoValueParam<unsigned int> sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T');
parser.processParam( sizeTabuListParam, "Search Parameters" );
unsigned sizeTabuList = sizeTabuListParam.value();
// duration tabu list
eoValueParam<unsigned int> durationParam(7, "duration", "duration of the tabu list", 'D');
parser.processParam( durationParam, "Search Parameters" );
unsigned duration = durationParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of QAP data
*
* ========================================================= */
PPPData<int> _data;
_data.load();
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(Nd);
_data.GPUObject.memCopyGlobalVariable(dev_a,_data.a_d);
_data.GPUObject.memCopyGlobalVariable(dev_h,_data.H_d);
/*=========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
PPPEval<solution> eval(_data);
unsigned long int sizeMap=sizeMapping(Nd,NB_POS);
PPPIncrEval<Neighbor> incr_eval;
moGPUMappingEvalByModif<Neighbor,PPPIncrEval<Neighbor> > cueval(sizeMap,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(sizeMap,NB_POS,cueval);
/* =========================================================
*
* continuator
*
* ========================================================= */
moIterContinuator <Neighbor> continuator(nbIteration);
/* =========================================================
*
* tabu list
*
* ========================================================= */
sizeTabuList=sizeMap;
duration=sizeTabuList/8;
// tabu list
moIndexedVectorTabuList<Neighbor> tl(sizeTabuList,duration);
/* =========================================================
*
* Memories
*
* ========================================================= */
moDummyIntensification<Neighbor> inten;
moDummyDiversification<Neighbor> div;
moBestImprAspiration<Neighbor> asp;
/* =========================================================
*
* The Tabu search algorithm
*
* ========================================================= */
moTS<Neighbor> tabuSearch(neighborhood, eval, cueval, comparator, solComparator, continuator, tl, inten, div, asp);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
moGPUTimer timer;
timer.start();
tabuSearch(sol);
std::cout << "final: " << sol << std::endl;
timer.stop();
printf("Execution time = %.2lf s\n",timer.getTime());
_data.GPUObject.free(dev_a);
_data.GPUObject.free(dev_h);
return 0;
}

View file

@ -0,0 +1,39 @@
######################################################################################
### 1) Include the sources
######################################################################################
INCLUDE_DIRECTORIES(
# include CUDA source directory
${CUDA_SRC_DIR}
# include EO source directory
${PARADISEO_EO_SRC_DIR}/src
# include MO source directory
${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
)
######################################################################################
######################################################################################
### 2) Specify where CMake can find the libraries
######################################################################################
LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${CUDA_LIB_DIR} )
######################################################################################
######################################################################################
### 3) Define your targets and link the librairies
######################################################################################
CUDA_ADD_EXECUTABLE(CutestSimpleTS_CPU testSimpleTS_CPU.cu)
CUDA_ADD_EXECUTABLE(CutestSimpleHC_CPU testSimpleHC_CPU.cu)
TARGET_LINK_LIBRARIES(CutestSimpleTS_CPU eoutils ga eo)
TARGET_LINK_LIBRARIES(CutestSimpleHC_CPU eoutils ga eo)

View file

@ -0,0 +1,217 @@
/*
<testSimpleHC_CPU.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
//Specific data problem
unsigned * a;
unsigned * b;
unsigned n;
// The general include for eo
#include <eo>
#include <ga.h>
// Fitness function
#include <QapEval.h>
// Cuda Fitness function
#include <QapIncrEval.h>
// QAP solution
#include <eoInt.h>
#include <eoInit.h>
//QAP neighbor
#include <problems/permutation/moIndexedSwapNeighbor.h>
//QAP neighborhood
#include <neighborhood/moOrderNeighborhood.h>
//QAP data
#include <Problem.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The Iter continuator
#include <continuator/moTrueContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
// The Tabou Search algorithm explorer
#include <explorer/moSimpleHCexplorer.h>
//To compute execution time
#include <performance/moGPUTimer.h>
typedef eoInt<eoMinimizingFitness> solution;
typedef moIndexedSwapNeighbor<solution> Neighbor;
typedef moOrderNeighborhood<Neighbor> Neighborhood;
int main(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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of QAP data
*
* ========================================================= */
load(argv[1]);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
eoInitPermutation<solution> init(n);
solution sol;
init(sol);
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
QapEval<solution> eval;
QapIncrEval<Neighbor> incr_eval;
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood((n*(n-1))/2);
/* =========================================================
*
* continuator
*
* ========================================================= */
moTrueContinuator <Neighbor> continuator;
/* =========================================================
*
* An explorer of solution neighborhood's
*
* ========================================================= */
moSimpleHCexplorer<Neighbor> explorer(neighborhood, incr_eval, comparator, solComparator);
/* =========================================================
*
* the local search algorithm
*
* ========================================================= */
moLocalSearch<Neighbor> localSearch(explorer, continuator, eval);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
// Create timer for timing CUDA calculation
moGPUTimer timer;
timer.start();
localSearch(sol);
timer.stop();
std::cout << "final: " << sol << std::endl;
printf("CUDA execution time = %f ms\n",timer.getTime());
timer.deleteTimer();
delete[] a;
delete[] b;
return 0;
}

View file

@ -0,0 +1,251 @@
/*
<testSimpleTS_CPU.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
//Specific data problem
unsigned * a;
unsigned * b;
unsigned n;
// The general include for eo
#include <eo>
#include <ga.h>
// Fitness function
#include <QapEval.h>
// Cuda Fitness function
#include <QapIncrEval.h>
// QAP solution
#include <eoInt.h>
#include <eoInit.h>
//QAP neighbor
#include <problems/permutation/moIndexedSwapNeighbor.h>
//QAP neighborhood
#include <neighborhood/moOrderNeighborhood.h>
//QAP data
#include <Problem.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The Iter continuator
#include <continuator/moIterContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
//Algorithm and its components
#include <algo/moTS.h>
//Tabu list
#include <memory/moIndexedVectorTabuList.h>
//Memories
#include <memory/moDummyIntensification.h>
#include <memory/moDummyDiversification.h>
#include <memory/moBestImprAspiration.h>
//To compute execution time
#include <performance/moGPUTimer.h>
typedef eoInt<eoMinimizingFitness> solution;
typedef moIndexedSwapNeighbor<solution> Neighbor;
typedef moOrderNeighborhood<Neighbor> Neighborhood;
int main(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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// Iteration number
eoValueParam<unsigned int> nbIterationParam(1, "nbIteration", "TS Iteration number", 'I');
parser.processParam( nbIterationParam, "TS Iteration number" );
unsigned nbIteration = nbIterationParam.value();
// size tabu list
eoValueParam<unsigned int> sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T');
parser.processParam( sizeTabuListParam, "Search Parameters" );
unsigned sizeTabuList = sizeTabuListParam.value();
// duration tabu list
eoValueParam<unsigned int> durationParam(7, "duration", "duration of the tabu list", 'D');
parser.processParam( durationParam, "Search Parameters" );
unsigned duration = durationParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of QAP data
*
* ========================================================= */
load(argv[1]);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
eoInitPermutation<solution> init(n);
solution sol;
init(sol);
/*=========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
QapEval<solution> eval;
QapIncrEval<Neighbor> incr_eval;
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(n*(n-1)/2);
/* =========================================================
*
* continuator
*
* ========================================================= */
moIterContinuator <Neighbor> continuator(nbIteration);
/*=========================================================
*
* Tabu list
*
* ========================================================= */
sizeTabuList=(n*(n-1))/2;
duration=sizeTabuList/8;
// tabu list
moIndexedVectorTabuList<Neighbor> tl(sizeTabuList,duration);
/* =========================================================
*
* Memories
*
* ========================================================= */
moDummyIntensification<Neighbor> inten;
moDummyDiversification<Neighbor> div;
moBestImprAspiration<Neighbor> asp;
/* =========================================================
*
* the Tabu search algorithm
*
* ========================================================= */
//General Constructor
moTS<Neighbor> tabuSearch(neighborhood, eval, incr_eval, comparator, solComparator, continuator, tl, inten, div, asp);
/* =========================================================
*
* Execute the Tabu search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
// Create timer for timing CUDA calculation
moGPUTimer timer;
timer.start();
tabuSearch(sol);
timer.stop();
std::cout << "final: " << sol << std::endl;
printf("CUDA execution time = %f ms\n",timer.getTime());
timer.deleteTimer();
delete[] a;
delete[] b;
return 0;
}

View file

@ -0,0 +1,62 @@
/*
<Problem.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __Problem
#define __Problem
/**
* Function to load a QAP data from a specific file
* @param _fileName the name of file containing specific QAP data
*/
void load(char * _fileName) {
fstream file(_fileName, ios::in);
if (!file) {
string str = "QAPData: Could not open file [" + (string)_fileName + "].";
throw runtime_error(str);
}
unsigned i, j;
file >> n;
a = new unsigned[n * n];
b = new unsigned[n * n];
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
file >> a[i * n + j];
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
file >> b[i * n + j];
}
#endif

View file

@ -0,0 +1,75 @@
/*
<QapEval.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __QapEval
#define __QapEval
/**
* Full Evaluation of QAP
*/
template <class EOT>
class QapEval : public eoEvalFunc<EOT>
{
public:
/**
* Constructor
*/
QapEval(){}
/**
* Destructor
*/
~QapEval(){}
/**
* Functor for full evaluation of the solution
* @param _sol the solution to evaluate
*/
void operator() (EOT & _sol) {
int cost=0;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
cost += a[i*n+j] * b[_sol[i]*n+_sol[j]];
_sol.fitness(cost);
}
};
#endif

View file

@ -0,0 +1,100 @@
/*
<QapIncrEval.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __QapIncrEval
#define __QapIncrEval
#include <eval/moEval.h>
/**
* Incremental Evaluation of QAP
*/
template <class Neighbor>
class QapIncrEval : public moEval<Neighbor>{
public:
typedef typename moEval<Neighbor>::EOT EOT;
typedef typename moEval<Neighbor>::Fitness Fitness;
/**
* Constructor
*/
QapIncrEval(){}
/**
* Destructor
*/
~QapIncrEval(){}
/**
* Functor for incremental evaluation of the solution
* @param _sol the solution
* @param _neighbor the neighbor of solution to evaluate
*/
void operator() (EOT & _sol, Neighbor & _neighbor){
unsigned int cost=0;
unsigned i,j;
_neighbor.getIndices(n,i,j);
cost = _sol.fitness() +compute_delta(_sol,i,j);
_neighbor.fitness(cost);
}
/**
* Specific to the QAP incremental evaluation (part of algorithmic)
* @param _sol the solution to evaluate
* @param i the first position of swap
* @param j the second position of swap
*/
unsigned int compute_delta(EOT & _sol,unsigned i,unsigned j)
{
int d;
int k;
d = (a[i*n+i]-a[j*n+j])*(b[_sol[j]*n+_sol[j]]-b[_sol[i]*n+_sol[i]]) +
(a[i*n+j]-a[j*n+i])*(b[_sol[j]*n+_sol[i]]-b[_sol[i]*n+_sol[j]]);
for (k = 0; k < n; k = k + 1)
if (k!=i && k!=j)
d = d + (a[k*n+i]-a[k*n+j])*(b[_sol[k]*n+_sol[j]]-b[_sol[k]*n+_sol[i]]) +
(a[i*n+k]-a[j*n+k])*(b[_sol[j]*n+_sol[k]]-b[_sol[i]*n+_sol[k]]);
return(d);
}
};
#endif

View file

@ -0,0 +1,50 @@
##############################################################################
##
## CMakeLists file for OneMax Example/application
##
###############################################################################
######################################################################################
### 1) Include the sources
######################################################################################
INCLUDE_DIRECTORIES(
# include CUDA source directory
${CUDA_SRC_DIR}
# include NVIDIA source directory
${NVIDIA_SRC_DIR}
# include EO source directory
${PARADISEO_EO_SRC_DIR}/src
# include MO source directory
${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
)
######################################################################################
######################################################################################
### 2) Specify where CMake can find the libraries
######################################################################################
LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib ${NVIDIA_LIB_DIR} ${CUDA_LIB_DIR} )
######################################################################################
######################################################################################
### 3) Define your targets and link the librairies
######################################################################################
CUDA_ADD_EXECUTABLE(GPU_testSimpleHC testSimpleHC.cu)
CUDA_ADD_EXECUTABLE(GPU_testSimpleTS testSimpleTS.cu)
TARGET_LINK_LIBRARIES(GPU_testSimpleHC eoutils ga eo ${cutil})
TARGET_LINK_LIBRARIES(GPU_testSimpleTS eoutils ga eo ${cutil})

View file

@ -0,0 +1,48 @@
/*
<moGPUConfig.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that ou accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moGPUConfig_H
#define __moGPUConfig_H
#define BLOCK_SIZE 8
#ifndef NB_POS
#define NB_POS 2
#endif
#ifndef SIZE
#define SIZE 100
#endif
#endif

View file

@ -0,0 +1,228 @@
/*
<testSimpleHC.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
__device__ int * dev_a;
__device__ int * dev_b;
// The general include for eo
#include <eo>
#include <ga.h>
// Fitness function
#include <problems/eval/QAPEval.h>
// Cuda Fitness function
#include <eval/moGPUMappingEvalByCpy.h>
#include <problems/eval/QAPIncrEval.h>
//Specific data to QAP problem
#include <problems/data/QAPData.h>
// QAP solution
#include <GPUType/moGPUPermutationVector.h>
// Swap neighbor
#include <neighborhood/moGPUXSwapNeighbor.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//Utils to compute size Mapping of x-change position
#include <neighborhood/moNeighborhoodSizeUtils.h>
// Use an ordered neighborhood without mapping, with local copy of solution
#include <neighborhood/moGPUXChangeNeighborhoodByCpy.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The continuator
#include <continuator/moTrueContinuator.h>
// Local search algorithm
#include <algo/moLocalSearch.h>
// Simple HC algorithm
#include <algo/moSimpleHC.h>
// The simple HC algorithm explorer
#include <explorer/moSimpleHCexplorer.h>
typedef moGPUPermutationVector<eoMinimizingFitness> solution;
typedef moGPUXSwapNeighbor<eoMinimizingFitness> Neighbor;
typedef moGPUXChangeNeighborhoodByCpy<Neighbor> Neighborhood;
int main(int argc, char **argv)
{
/* =========================================================
*
* Parameters
*
* ========================================================= */
// First define a parser from the command-line arguments
eoParser parser(argc, argv);
if (argc < 2){
printf("Saisissez le nom de fichier dat à manipuler \n");
exit(1);
}
// For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable
// seed
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of QAP data
*
* ========================================================= */
QAPData<int> _data(argv[1]);
/* =========================================================
*
* Initilisation of the solution and specific data
*
* ========================================================= */
solution sol(_data.sizeData);
_data.GPUObject.memCopyGlobalVariable(dev_a,_data.a_d);
_data.GPUObject.memCopyGlobalVariable(dev_b,_data.b_d);
/* =========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
QAPEval<solution> eval(_data);
unsigned long int sizeMap=sizeMapping(_data.sizeData,NB_POS);
QAPIncrEval<Neighbor> incr_eval;
moGPUMappingEvalByCpy<Neighbor,QAPIncrEval<Neighbor> > cueval(sizeMap,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(sizeMap,NB_POS,cueval);
/* =========================================================
*
* An explorer of solution neighborhood's
*
* ========================================================= */
moSimpleHCexplorer<Neighbor> explorer(neighborhood, cueval,
comparator, solComparator);
/* =========================================================
*
* The local search algorithm
*
* ========================================================= */
//True continuator <=> Always continue
moTrueContinuator<Neighbor> continuator;
moLocalSearch<Neighbor> localSearch(explorer,continuator, eval);
/* =========================================================
*
* The simple Hill Climbing algorithm
*
* ========================================================= */
moSimpleHC<Neighbor> simpleHC(neighborhood,eval,cueval);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
// Create timer for timing CUDA calculation
moGPUTimer timer;
timer.start();
localSearch(sol);
std::cout << "final: " << sol << std::endl;
timer.stop();
printf("Execution time = %f ms\n",timer.getTime());
timer.deleteTimer();
_data.GPUObject.free(dev_a);
_data.GPUObject.free(dev_b);
return 0;
}

View file

@ -0,0 +1,247 @@
/*
<testSimpleTS.cu>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Karima Boufaras, Thé Van LUONG
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
__device__ int * dev_a;
__device__ int * dev_b;
// The general include for eo
#include <eo>
#include <ga.h>
// Fitness function
#include <problems/eval/QAPEval.h>
// Cuda Fitness function
#include <eval/moGPUMappingEvalByCpy.h>
#include <problems/eval/QAPIncrEval.h>
//Specific data to QAP problem
#include <problems/data/QAPData.h>
// QAP solution
#include <GPUType/moGPUPermutationVector.h>
// Swap neighbor
#include <neighborhood/moGPUXSwapNeighbor.h>
//To compute execution time
#include <performance/moGPUTimer.h>
//Utils to compute size Mapping of x-change position
#include <neighborhood/moNeighborhoodSizeUtils.h>
// Use an ordered neighborhood without mapping, with local copy of solution
#include <neighborhood/moGPUXChangeNeighborhoodByCpy.h>
// The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
// The Iter continuator
#include <continuator/moIterContinuator.h>
// The Tabou Search algorithm
#include <algo/moTS.h>
//Tabu list
#include <memory/moIndexedVectorTabuList.h>
//Memories
#include <memory/moDummyIntensification.h>
#include <memory/moDummyDiversification.h>
#include <memory/moBestImprAspiration.h>
typedef moGPUPermutationVector<eoMinimizingFitness> solution;
typedef moGPUXSwapNeighbor<eoMinimizingFitness> Neighbor;
typedef moGPUXChangeNeighborhoodByCpy<Neighbor> Neighborhood;
int main(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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam );
unsigned seed = seedParam.value();
// Iteration number
eoValueParam<unsigned int> nbIterationParam(1, "nbIteration", "TS Iteration number", 'I');
parser.processParam( nbIterationParam, "TS Iteration number" );
unsigned nbIteration = nbIterationParam.value();
// duration tabu list
eoValueParam<unsigned int> durationParam(7, "duration", "duration of the tabu list", 'D');
parser.processParam( durationParam, "Search Parameters" );
unsigned duration = durationParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> 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);
/* =========================================================
*
* Initilisation of QAP data
*
* ========================================================= */
QAPData<int> _data(argv[1]);
/* =========================================================
*
* Initilisation of the solution
*
* ========================================================= */
solution sol(_data.sizeData);
_data.GPUObject.memCopyGlobalVariable(dev_a,_data.a_d);
_data.GPUObject.memCopyGlobalVariable(dev_b,_data.b_d);
/*=========================================================
*
* Evaluation of a solution neighbor's
*
* ========================================================= */
QAPEval<solution> eval(_data);
unsigned long int sizeMap=sizeMapping(_data.sizeData,NB_POS);
QAPIncrEval<Neighbor> incr_eval;
moGPUMappingEvalByCpy<Neighbor,QAPIncrEval<Neighbor> > cueval(sizeMap,incr_eval);
/* =========================================================
*
* Comparator of solutions and neighbors
*
* ========================================================= */
moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator;
/* =========================================================
*
* a solution neighborhood
*
* ========================================================= */
Neighborhood neighborhood(sizeMap,NB_POS,cueval);
/* =========================================================
*
* continuator
*
* ========================================================= */
moIterContinuator <Neighbor> continuator(nbIteration);
/* =========================================================
*
* tabu list
*
* ========================================================= */
moIndexedVectorTabuList<Neighbor> tl(sizeMap,(sizeMap/8));
/* =========================================================
*
* Memories
*
* ========================================================= */
moDummyIntensification<Neighbor> inten;
moDummyDiversification<Neighbor> div;
moBestImprAspiration<Neighbor> asp;
/* =========================================================
*
* The Tabu search algorithm
*
* ========================================================= */
moTS<Neighbor> tabuSearch(neighborhood, eval, cueval, comparator, solComparator, continuator, tl, inten, div, asp);
/* =========================================================
*
* Execute the local search from random sollution
*
* ========================================================= */
//Can be eval here, else it will be done at the beginning of the localSearch
eval(sol);
std::cout << "initial: " << sol<< std::endl;
moGPUTimer timer;
timer.start();
tabuSearch(sol);
std::cout << "final: " << sol << std::endl;
timer.stop();
printf("Execution time = %f ms\n",timer.getTime());
timer.deleteTimer();
_data.GPUObject.free(dev_a);
_data.GPUObject.free(dev_b);
return 0;
}