Lesson Wrapper
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@832 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
4116f0a7ac
commit
1531fbd49c
10 changed files with 611 additions and 1 deletions
|
|
@ -11,6 +11,6 @@ SET(TSP_BINARY_DIR ${ParadisEO-PEO_BINARY_DIR}/tutorial/examples/tsp)
|
||||||
### 2) Where must cmake go now ?
|
### 2) Where must cmake go now ?
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
SUBDIRS(examples Lesson1 Lesson2 Lesson3 Lesson4 Lesson5 Lesson6)
|
SUBDIRS(examples Lesson1 Lesson2 Lesson3 Lesson4 Lesson5 Lesson6 Wrapper)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
|
||||||
92
trunk/paradiseo-peo/tutorial/Wrapper/CMakeLists.txt
Normal file
92
trunk/paradiseo-peo/tutorial/Wrapper/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 0) Set the compiler and define targets to easily run the lessons
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
SET (CMAKE_CXX_COMPILER mpicxx)
|
||||||
|
|
||||||
|
ADD_CUSTOM_TARGET(install DEPENDS ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Wrapper/param ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Wrapper/schema.xml)
|
||||||
|
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
TARGET install
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
ARGS -E copy_if_different
|
||||||
|
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Wrapper/param
|
||||||
|
${ParadisEO-PEO_BINARY_DIR}/tutorial/Wrapper)
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
TARGET install
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
ARGS -E copy_if_different
|
||||||
|
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Wrapper/schema.xml
|
||||||
|
${ParadisEO-PEO_BINARY_DIR}/tutorial/Wrapper)
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 1) Include the sources
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src ${MO_SRC_DIR}/src ${ParadisEO-PEO_SOURCE_DIR}/src ${TSP_SRC_DIR})
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 2) Specify where CMake can find the libraries (mandatory: before 3) )
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
IF(NOT WIN32 OR CYGWIN)
|
||||||
|
LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-PEO_BINARY_DIR}/lib ${TSP_BINARY_DIR}/lib)
|
||||||
|
ENDIF(NOT WIN32 OR CYGWIN)
|
||||||
|
|
||||||
|
# especially for Visual Studio
|
||||||
|
IF(WIN32 AND NOT CYGWIN)
|
||||||
|
LINK_DIRECTORIES(${EO_BIN_DIR}\\lib\\${CMAKE_BUILD_TYPE} ${ParadisEO-PEO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE} ${TSP_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||||
|
ENDIF(WIN32 AND NOT CYGWIN)
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 3) Define your target(s): just an executable here
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(example1 main1.cpp)
|
||||||
|
ADD_DEPENDENCIES(example1 peo rmc_mpi)
|
||||||
|
ADD_EXECUTABLE(example2 main2.cpp)
|
||||||
|
ADD_DEPENDENCIES(example2 peo rmc_mpi)
|
||||||
|
ADD_EXECUTABLE(example3 main3.cpp)
|
||||||
|
ADD_DEPENDENCIES(example3 peo rmc_mpi)
|
||||||
|
ADD_EXECUTABLE(example4 main4.cpp)
|
||||||
|
ADD_DEPENDENCIES(example4 peo rmc_mpi)
|
||||||
|
ADD_EXECUTABLE(example5 main5.cpp)
|
||||||
|
ADD_DEPENDENCIES(example5 tsp peo rmc_mpi)
|
||||||
|
ADD_EXECUTABLE(example6 main6.cpp)
|
||||||
|
ADD_DEPENDENCIES(example6 tsp peo rmc_mpi)
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 4) Optionnal: define your target(s)'s version: no effect for windows
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 5) Link the librairies
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
TARGET_LINK_LIBRARIES(example1 ${XML2_LIBS} peo rmc_mpi eo eoutils)
|
||||||
|
TARGET_LINK_LIBRARIES(example2 ${XML2_LIBS} peo rmc_mpi eo eoutils)
|
||||||
|
TARGET_LINK_LIBRARIES(example3 ${XML2_LIBS} peo rmc_mpi eo eoutils)
|
||||||
|
TARGET_LINK_LIBRARIES(example4 ${XML2_LIBS} peo rmc_mpi eo eoutils)
|
||||||
|
TARGET_LINK_LIBRARIES(example5 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
|
||||||
|
TARGET_LINK_LIBRARIES(example6 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
91
trunk/paradiseo-peo/tutorial/Wrapper/main1.cpp
Normal file
91
trunk/paradiseo-peo/tutorial/Wrapper/main1.cpp
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
#include <peo>
|
||||||
|
#include <es.h>
|
||||||
|
typedef eoReal<double> Indi;
|
||||||
|
|
||||||
|
double f (const Indi & _indi)
|
||||||
|
{
|
||||||
|
double sum;
|
||||||
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
|
sum=100*pow(sum,2);
|
||||||
|
sum+=pow((1-_indi[0]),2);
|
||||||
|
return (-sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int __argc, char** __argv )
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
peo :: init( __argc, __argv );
|
||||||
|
|
||||||
|
// Parameters
|
||||||
|
const unsigned int VEC_SIZE = 2;
|
||||||
|
const unsigned int POP_SIZE = 20;
|
||||||
|
const unsigned int MAX_GEN = 300;
|
||||||
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
|
const float CROSS_RATE = 0.8;
|
||||||
|
const double EPSILON = 0.01;
|
||||||
|
const float MUT_RATE = 0.3;
|
||||||
|
rng.reseed (time(0));
|
||||||
|
|
||||||
|
|
||||||
|
// Algorithm
|
||||||
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
|
eoEvalFuncPtr< Indi > mainEval( f );
|
||||||
|
eoEvalFuncCounter< Indi > eval(mainEval);
|
||||||
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
eoRankingSelect<Indi> selectionStrategy;
|
||||||
|
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||||
|
eoSegmentCrossover<Indi> crossover;
|
||||||
|
eoUniformMutation<Indi> mutation(EPSILON);
|
||||||
|
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
|
peoSeqTransform<Indi> eaTransform(transform);
|
||||||
|
eoPlusReplacement<Indi> replace;
|
||||||
|
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
|
||||||
|
|
||||||
|
// Population
|
||||||
|
eoPop < Indi > pop;
|
||||||
|
pop.append (POP_SIZE, random);
|
||||||
|
|
||||||
|
// Wrapper
|
||||||
|
peoParallelAlgorithmWrapper parallelEA( eaAlg, pop);
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
// Algorithm
|
||||||
|
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||||
|
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||||
|
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||||
|
eoEvalFuncPtr< Indi > mainEval2( f );
|
||||||
|
eoEvalFuncCounter< Indi > eval2(mainEval2);
|
||||||
|
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||||
|
eoRankingSelect<Indi> selectionStrategy2;
|
||||||
|
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||||
|
eoSegmentCrossover<Indi> crossover2;
|
||||||
|
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||||
|
eoSGATransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||||
|
peoSeqTransform<Indi> eaTransform2(transform2);
|
||||||
|
eoPlusReplacement<Indi> replace2;
|
||||||
|
eoEasyEA< Indi > eaAlg2( checkpoint2, eval2, select2, transform2, replace2 );
|
||||||
|
|
||||||
|
// Population
|
||||||
|
eoPop < Indi > pop2;
|
||||||
|
pop2.append (POP_SIZE, random2);
|
||||||
|
|
||||||
|
|
||||||
|
// Wrapper
|
||||||
|
peo :: init( __argc, __argv );
|
||||||
|
peoParallelAlgorithmWrapper parallelEA2( eaAlg2, pop2);
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
||||||
|
}
|
||||||
66
trunk/paradiseo-peo/tutorial/Wrapper/main2.cpp
Normal file
66
trunk/paradiseo-peo/tutorial/Wrapper/main2.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
#include <peo>
|
||||||
|
#include <es.h>
|
||||||
|
typedef eoReal<double> Indi;
|
||||||
|
|
||||||
|
double f (const Indi & _indi)
|
||||||
|
{
|
||||||
|
double sum;
|
||||||
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
|
sum=100*pow(sum,2);
|
||||||
|
sum+=pow((1-_indi[0]),2);
|
||||||
|
return (-sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int __argc, char** __argv )
|
||||||
|
{
|
||||||
|
peo :: init( __argc, __argv );
|
||||||
|
|
||||||
|
// Parameters
|
||||||
|
const unsigned int VEC_SIZE = 2;
|
||||||
|
const unsigned int POP_SIZE = 20;
|
||||||
|
const unsigned int MAX_GEN = 300;
|
||||||
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
|
const float CROSS_RATE = 0.8;
|
||||||
|
const double EPSILON = 0.01;
|
||||||
|
const float MUT_RATE = 0.5;
|
||||||
|
rng.reseed (time(0));
|
||||||
|
|
||||||
|
// Algorithm
|
||||||
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
|
|
||||||
|
//eoEvalFuncPtr< Indi > mainEval( f );
|
||||||
|
//eoEvalFuncCounter< Indi > eval(mainEval);
|
||||||
|
peoEvalFunc<Indi> mainEval( f );
|
||||||
|
peoParaPopEval <Indi> eval(mainEval);
|
||||||
|
|
||||||
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
eoRankingSelect<Indi> selectionStrategy;
|
||||||
|
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||||
|
eoSegmentCrossover<Indi> crossover;
|
||||||
|
eoUniformMutation<Indi> mutation(EPSILON);
|
||||||
|
|
||||||
|
//eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
|
//peoSeqTransform<Indi> eaTransform(transform);
|
||||||
|
peoParaSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
|
|
||||||
|
eoPlusReplacement<Indi> replace;
|
||||||
|
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
|
||||||
|
|
||||||
|
// Population*/
|
||||||
|
eoPop < Indi > pop;
|
||||||
|
pop.append (POP_SIZE, random);
|
||||||
|
peoParallelAlgorithmWrapper parallelEA( eaAlg, pop);
|
||||||
|
eval.setOwner(parallelEA);
|
||||||
|
transform.setOwner(parallelEA);
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
|
}
|
||||||
60
trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp
Normal file
60
trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
#include <peo>
|
||||||
|
#include <es.h>
|
||||||
|
|
||||||
|
typedef eoRealParticle < double >Indi;
|
||||||
|
|
||||||
|
double f (const Indi & _indi)
|
||||||
|
{
|
||||||
|
double sum;
|
||||||
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
|
sum=100*pow(sum,2);
|
||||||
|
sum+=pow((1-_indi[0]),2);
|
||||||
|
return (-sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int __argc, char** __argv )
|
||||||
|
{
|
||||||
|
|
||||||
|
peo :: init( __argc, __argv );
|
||||||
|
const unsigned int VEC_SIZE = 2;
|
||||||
|
const unsigned int POP_SIZE = 20;
|
||||||
|
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||||
|
const unsigned int MAX_GEN = 300;
|
||||||
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
|
const double INIT_VELOCITY_MIN = -1.;
|
||||||
|
const double INIT_VELOCITY_MAX = 1.;
|
||||||
|
const double C1 = 0.5;
|
||||||
|
const double C2 = 2.;
|
||||||
|
rng.reseed (time(0));
|
||||||
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
|
|
||||||
|
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
||||||
|
peoParaPopEval< Indi > eval(plainEval);
|
||||||
|
|
||||||
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
|
eoPop < Indi > pop;
|
||||||
|
pop.append (POP_SIZE, random);
|
||||||
|
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||||
|
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
|
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||||
|
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
|
||||||
|
|
||||||
|
// Parallel algorithm
|
||||||
|
|
||||||
|
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
|
||||||
|
peoParallelAlgorithmWrapper parallelPSO( psa, pop);
|
||||||
|
eval.setOwner(parallelPSO);
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
|
}
|
||||||
119
trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp
Normal file
119
trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
#include <peo>
|
||||||
|
#include <es.h>
|
||||||
|
|
||||||
|
typedef eoRealParticle < double >Indi;
|
||||||
|
|
||||||
|
double f (const Indi & _indi)
|
||||||
|
{
|
||||||
|
double sum;
|
||||||
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
|
sum=100*pow(sum,2);
|
||||||
|
sum+=pow((1-_indi[0]),2);
|
||||||
|
return (-sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int __argc, char** __argv )
|
||||||
|
{
|
||||||
|
|
||||||
|
peo :: init( __argc, __argv );
|
||||||
|
const unsigned int VEC_SIZE = 2;
|
||||||
|
const unsigned int POP_SIZE = 20;
|
||||||
|
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||||
|
const unsigned int MAX_GEN = 100;
|
||||||
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
|
const double INIT_VELOCITY_MIN = -1.;
|
||||||
|
const double INIT_VELOCITY_MAX = 1.;
|
||||||
|
const unsigned int MIG_FREQ = 10;
|
||||||
|
const double C1 = 0.5;
|
||||||
|
const double C2 = 2.;
|
||||||
|
rng.reseed (time(0));
|
||||||
|
|
||||||
|
// Island model
|
||||||
|
|
||||||
|
RingTopology topologyMig;
|
||||||
|
|
||||||
|
// First
|
||||||
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
|
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
||||||
|
peoParaPopEval< Indi > eval(plainEval);
|
||||||
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
|
eoPop < Indi > pop;
|
||||||
|
pop.append (POP_SIZE, random);
|
||||||
|
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||||
|
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
|
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||||
|
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
|
||||||
|
|
||||||
|
// Island model
|
||||||
|
|
||||||
|
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||||
|
peoPSOSelect<Indi> mig_selec(topology);
|
||||||
|
eoSelectNumber< Indi > mig_select(mig_selec);
|
||||||
|
peoPSOReplacement<Indi> mig_replace;
|
||||||
|
|
||||||
|
|
||||||
|
// Second
|
||||||
|
|
||||||
|
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||||
|
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||||
|
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||||
|
peoEvalFunc<Indi, double, const Indi& > plainEval2(f);
|
||||||
|
peoParaPopEval< Indi > eval2(plainEval2);
|
||||||
|
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||||
|
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
||||||
|
eoFirstIsBestInit < Indi > localInit2;
|
||||||
|
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
|
eoStandardFlight < Indi > flight2(bndsFlight2);
|
||||||
|
eoPop < Indi > pop2;
|
||||||
|
pop2.append (POP_SIZE, random2);
|
||||||
|
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
||||||
|
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
|
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
||||||
|
eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2);
|
||||||
|
|
||||||
|
// Island model
|
||||||
|
|
||||||
|
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||||
|
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||||
|
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
||||||
|
peoPSOReplacement<Indi> mig_replace2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Island model
|
||||||
|
|
||||||
|
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop);
|
||||||
|
checkpoint.add( mig );
|
||||||
|
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop2);
|
||||||
|
checkpoint2.add( mig2 );
|
||||||
|
|
||||||
|
|
||||||
|
// Parallel algorithm
|
||||||
|
|
||||||
|
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
|
||||||
|
peoParallelAlgorithmWrapper parallelPSO( psa, pop);
|
||||||
|
eval.setOwner(parallelPSO);
|
||||||
|
mig.setOwner(parallelPSO);
|
||||||
|
eoSyncEasyPSO <Indi> psa2(init2,checkpoint2,eval2, velocity2, flight2);
|
||||||
|
peoParallelAlgorithmWrapper parallelPSO2( psa2, pop2);
|
||||||
|
eval2.setOwner(parallelPSO2);
|
||||||
|
mig2.setOwner(parallelPSO2);
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
{
|
||||||
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
|
std::cout << "Final population :\n" << pop2 << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
77
trunk/paradiseo-peo/tutorial/Wrapper/main5.cpp
Normal file
77
trunk/paradiseo-peo/tutorial/Wrapper/main5.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
#include "param.h"
|
||||||
|
#include "route_init.h"
|
||||||
|
#include "route_eval.h"
|
||||||
|
#include "order_xover.h"
|
||||||
|
#include "edge_xover.h"
|
||||||
|
#include "partial_mapped_xover.h"
|
||||||
|
#include "city_swap.h"
|
||||||
|
#include "part_route_eval.h"
|
||||||
|
#include "merge_route_eval.h"
|
||||||
|
#include "two_opt_init.h"
|
||||||
|
#include "two_opt_next.h"
|
||||||
|
#include "two_opt_incr_eval.h"
|
||||||
|
|
||||||
|
#include <peo>
|
||||||
|
|
||||||
|
#define POP_SIZE 10
|
||||||
|
#define NUM_GEN 100
|
||||||
|
#define CROSS_RATE 1.0
|
||||||
|
#define MUT_RATE 0.01
|
||||||
|
|
||||||
|
|
||||||
|
int main (int __argc, char * * __argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
peo :: init (__argc, __argv);
|
||||||
|
loadParameters (__argc, __argv);
|
||||||
|
RouteInit route_init;
|
||||||
|
RouteEval full_eval;
|
||||||
|
OrderXover order_cross;
|
||||||
|
PartialMappedXover pm_cross;
|
||||||
|
EdgeXover edge_cross;
|
||||||
|
CitySwap city_swap_mut;
|
||||||
|
|
||||||
|
// Initialization of the local search
|
||||||
|
TwoOptInit pmx_two_opt_init;
|
||||||
|
TwoOptNext pmx_two_opt_next;
|
||||||
|
TwoOptIncrEval pmx_two_opt_incr_eval;
|
||||||
|
moBestImprSelect <TwoOpt> pmx_two_opt_move_select;
|
||||||
|
moHC <TwoOpt> hc (pmx_two_opt_init, pmx_two_opt_next, pmx_two_opt_incr_eval, pmx_two_opt_move_select, full_eval);
|
||||||
|
|
||||||
|
// EA
|
||||||
|
eoPop <Route> pop (POP_SIZE, route_init);
|
||||||
|
eoGenContinue <Route> cont (NUM_GEN);
|
||||||
|
eoCheckPoint <Route> checkpoint (cont);
|
||||||
|
peoSeqPopEval <Route> eval (full_eval);
|
||||||
|
eoStochTournamentSelect <Route> select_one;
|
||||||
|
eoSelectNumber <Route> select (select_one, POP_SIZE);
|
||||||
|
eoSGATransform <Route> transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
|
||||||
|
peoSeqTransform <Route> para_transform (transform);
|
||||||
|
eoEPReplacement <Route> replace (2);
|
||||||
|
eoEasyEA< Route > eaAlg( checkpoint, eval, select, para_transform, replace );
|
||||||
|
peoParallelAlgorithmWrapper parallelEA( eaAlg, pop);
|
||||||
|
peo :: run ();
|
||||||
|
peo :: finalize ();
|
||||||
|
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
{
|
||||||
|
std :: cout << "\nResult before the local search\n";
|
||||||
|
for(unsigned i=0;i<pop.size();i++)
|
||||||
|
std::cout<<"\n"<<pop[i].fitness();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local search
|
||||||
|
peo :: init (__argc, __argv);
|
||||||
|
peoSynchronousMultiStart <Route> initParallelHC (hc);
|
||||||
|
peoParallelAlgorithmWrapper parallelHC (initParallelHC, pop);
|
||||||
|
initParallelHC.setOwner(parallelHC);
|
||||||
|
peo :: run( );
|
||||||
|
peo :: finalize( );
|
||||||
|
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
{
|
||||||
|
std :: cout << "\nResult after the local search\n";
|
||||||
|
for(unsigned i=0;i<pop.size();i++)
|
||||||
|
std::cout<<"\n"<<pop[i].fitness();
|
||||||
|
}
|
||||||
|
}
|
||||||
77
trunk/paradiseo-peo/tutorial/Wrapper/main6.cpp
Normal file
77
trunk/paradiseo-peo/tutorial/Wrapper/main6.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
#include "param.h"
|
||||||
|
#include "route_init.h"
|
||||||
|
#include "route_eval.h"
|
||||||
|
#include "order_xover.h"
|
||||||
|
#include "edge_xover.h"
|
||||||
|
#include "partial_mapped_xover.h"
|
||||||
|
#include "city_swap.h"
|
||||||
|
#include "part_route_eval.h"
|
||||||
|
#include "merge_route_eval.h"
|
||||||
|
#include "two_opt_init.h"
|
||||||
|
#include "two_opt_next.h"
|
||||||
|
#include "two_opt_incr_eval.h"
|
||||||
|
|
||||||
|
#include <peo>
|
||||||
|
|
||||||
|
#define POP_SIZE 10
|
||||||
|
#define NUM_GEN 200
|
||||||
|
#define CROSS_RATE 1.0
|
||||||
|
#define MUT_RATE 0.1
|
||||||
|
|
||||||
|
|
||||||
|
int main (int __argc, char * * __argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
peo :: init (__argc, __argv);
|
||||||
|
loadParameters (__argc, __argv);
|
||||||
|
RouteInit route_init;
|
||||||
|
RouteEval full_eval;
|
||||||
|
OrderXover order_cross;
|
||||||
|
PartialMappedXover pm_cross;
|
||||||
|
EdgeXover edge_cross;
|
||||||
|
CitySwap city_swap_mut;
|
||||||
|
|
||||||
|
// Local search
|
||||||
|
TwoOptInit pmx_two_opt_init;
|
||||||
|
TwoOptNext pmx_two_opt_next;
|
||||||
|
TwoOptIncrEval pmx_two_opt_incr_eval;
|
||||||
|
moBestImprSelect <TwoOpt> pmx_two_opt_move_select;
|
||||||
|
moHC <TwoOpt> hc (pmx_two_opt_init, pmx_two_opt_next, pmx_two_opt_incr_eval, pmx_two_opt_move_select, full_eval);
|
||||||
|
eoPop <Route> pop (POP_SIZE, route_init);
|
||||||
|
peoSynchronousMultiStart <Route> initParallelHC (hc);
|
||||||
|
peoParallelAlgorithmWrapper parallelHC (initParallelHC, pop);
|
||||||
|
initParallelHC.setOwner(parallelHC);
|
||||||
|
peo :: run( );
|
||||||
|
peo :: finalize( );
|
||||||
|
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
{
|
||||||
|
std :: cout << "\nResult before the EA\n";
|
||||||
|
for(unsigned i=0;i<pop.size();i++)
|
||||||
|
std::cout<<"\n"<<pop[i].fitness();
|
||||||
|
std :: cout << "\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// EA
|
||||||
|
peo :: init (__argc, __argv);
|
||||||
|
eoGenContinue <Route> cont (NUM_GEN);
|
||||||
|
eoCheckPoint <Route> checkpoint (cont);
|
||||||
|
peoSeqPopEval <Route> eval (full_eval);
|
||||||
|
eoStochTournamentSelect <Route> select_one;
|
||||||
|
eoSelectNumber <Route> select (select_one, POP_SIZE);
|
||||||
|
eoSGATransform <Route> transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
|
||||||
|
peoSeqTransform <Route> para_transform (transform);
|
||||||
|
eoEPReplacement <Route> replace (2);
|
||||||
|
eoEasyEA< Route > eaAlg( checkpoint, eval, select, para_transform, replace );
|
||||||
|
peoParallelAlgorithmWrapper parallelEA( eaAlg, pop);
|
||||||
|
peo :: run ();
|
||||||
|
peo :: finalize ();
|
||||||
|
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
{
|
||||||
|
std :: cout << "\nResult after the EA\n";
|
||||||
|
for(unsigned i=0;i<pop.size();i++)
|
||||||
|
std::cout<<"\n"<<pop[i].fitness();
|
||||||
|
std :: cout << "\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
12
trunk/paradiseo-peo/tutorial/Wrapper/param
Normal file
12
trunk/paradiseo-peo/tutorial/Wrapper/param
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
## miscallenous parameters
|
||||||
|
|
||||||
|
--debug=false
|
||||||
|
|
||||||
|
## deployment schema
|
||||||
|
|
||||||
|
--schema=schema.xml
|
||||||
|
|
||||||
|
## parameters
|
||||||
|
|
||||||
|
--inst=../examples/tsp/benchs/eil101.tsp
|
||||||
|
|
||||||
16
trunk/paradiseo-peo/tutorial/Wrapper/schema.xml
Normal file
16
trunk/paradiseo-peo/tutorial/Wrapper/schema.xml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<schema>
|
||||||
|
<group scheduler="0">
|
||||||
|
<node name="0" num_workers="0">
|
||||||
|
</node>
|
||||||
|
<node name="1" num_workers="0">
|
||||||
|
<runner>1</runner>
|
||||||
|
<runner>2</runner>
|
||||||
|
</node>
|
||||||
|
<node name="2" num_workers="1">
|
||||||
|
</node>
|
||||||
|
<node name="3" num_workers="1">
|
||||||
|
</node>
|
||||||
|
</group>
|
||||||
|
</schema>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue