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