tutorial PEO modified
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@905 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
f0773471de
commit
f4740e571c
10 changed files with 0 additions and 728 deletions
|
|
@ -1,95 +0,0 @@
|
|||
|
||||
######################################################################################
|
||||
### 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 ${MOEO_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 ${MOEO_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)
|
||||
ADD_EXECUTABLE(example7 main7.cpp)
|
||||
ADD_DEPENDENCIES(example7 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)
|
||||
TARGET_LINK_LIBRARIES(example7 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
#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);
|
||||
peoEvalFunc<Indi> mainEval( f );
|
||||
peoPopEval <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);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
|
||||
// Population
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
// Wrapper
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
eval.setOwner(parallelEA);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
#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;
|
||||
const unsigned MIG_FREQ = 10;
|
||||
const unsigned int MIG_SIZE = 5;
|
||||
rng.reseed (time(0));
|
||||
RingTopology topology;
|
||||
|
||||
// Algorithm
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
peoEvalFunc<Indi> mainEval( f );
|
||||
peoPopEval <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);
|
||||
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
peoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoRandomSelect<Indi> mig_select_one;
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select (mig_select_one,MIG_SIZE,pop);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replace (replace,pop);
|
||||
peoSyncIslandMig<Indi, peoPop<Indi> > mig(MIG_FREQ,mig_select,mig_replace,topology,pop,pop);
|
||||
checkpoint.add(mig);
|
||||
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
|
||||
// Algorithm
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||
peoEvalFunc<Indi> mainEval2( f );
|
||||
peoPopEval <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);
|
||||
peoTransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||
peoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
eoPlusReplacement<Indi> replace2;
|
||||
eoRandomSelect<Indi> mig_select_one2;
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select2 (mig_select_one2,MIG_SIZE,pop2);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replace2 (replace2,pop2);
|
||||
peoSyncIslandMig<Indi, peoPop<Indi> > mig2(MIG_FREQ,mig_select2,mig_replace2,topology,pop2,pop2);
|
||||
checkpoint2.add(mig2);
|
||||
eoEasyEA< Indi > eaAlg2( checkpoint2, eval2, select2, transform2, replace2 );
|
||||
|
||||
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
eval.setOwner(parallelEA);
|
||||
transform.setOwner(parallelEA);
|
||||
mig.setOwner(parallelEA);
|
||||
|
||||
peoWrapper parallelEA2( eaAlg2, pop2);
|
||||
eval2.setOwner(parallelEA2);
|
||||
transform2.setOwner(parallelEA2);
|
||||
mig2.setOwner(parallelEA2);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
|
||||
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
#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 weight = 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);
|
||||
peoPopEval< 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,weight,C1,C2,bnds);
|
||||
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
|
||||
|
||||
// Parallel algorithm
|
||||
|
||||
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
|
||||
peoWrapper parallelPSO( psa, pop);
|
||||
eval.setOwner(parallelPSO);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
#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 omega = 1;
|
||||
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);
|
||||
peoPopEval< 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);
|
||||
peoPop < 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,omega,C1,C2,bnds);
|
||||
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
|
||||
|
||||
// Island model
|
||||
|
||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec(topology);
|
||||
peoWorstPositionReplacement<Indi> mig_replac;
|
||||
|
||||
// Specific implementation (peoData.h)
|
||||
|
||||
eoContinuator<Indi> cont(mig_cont, pop);
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select (mig_selec,1,pop);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replace (mig_replac,pop);
|
||||
|
||||
|
||||
// Second
|
||||
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||
peoEvalFunc<Indi, double, const Indi& > plainEval2(f);
|
||||
peoPopEval< 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);
|
||||
peoPop < 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,omega,C1,C2,bnds2);
|
||||
eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2);
|
||||
|
||||
// Island model
|
||||
|
||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||
peoWorstPositionReplacement<Indi> mig_replac2;
|
||||
|
||||
// Specific implementation (peoData.h)
|
||||
|
||||
eoContinuator<Indi> cont2(mig_cont2,pop2);
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select2 (mig_selec2,1,pop2);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replace2 (mig_replac2,pop2);
|
||||
|
||||
|
||||
// Island model
|
||||
|
||||
peoAsyncIslandMig< Indi, peoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig, pop, pop);
|
||||
checkpoint.add( mig );
|
||||
peoAsyncIslandMig< Indi, peoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2);
|
||||
checkpoint2.add( mig2 );
|
||||
|
||||
|
||||
// Parallel algorithm
|
||||
|
||||
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
|
||||
peoWrapper parallelPSO( psa, pop);
|
||||
eval.setOwner(parallelPSO);
|
||||
mig.setOwner(parallelPSO);
|
||||
eoSyncEasyPSO <Indi> psa2(init2,checkpoint2,eval2, velocity2, flight2);
|
||||
peoWrapper parallelPSO2( psa2, pop2);
|
||||
eval2.setOwner(parallelPSO2);
|
||||
mig2.setOwner(parallelPSO2);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
pop2.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
std::cout << "Final population :\n" << pop2 << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
#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);
|
||||
eoEvalFuncCounter< 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);
|
||||
eoEPReplacement <Route> replace (2);
|
||||
eoEasyEA< Route > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
peo :: run ();
|
||||
peo :: finalize ();
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
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);
|
||||
peoMultiStart <Route> initParallelHC (hc);
|
||||
peoWrapper parallelHC (initParallelHC, pop);
|
||||
initParallelHC.setOwner(parallelHC);
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std :: cout << "\nResult after the local search\n";
|
||||
pop.sort();
|
||||
for(unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
#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);
|
||||
peoMultiStart <Route> initParallelHC (hc);
|
||||
peoWrapper parallelHC (initParallelHC, pop);
|
||||
initParallelHC.setOwner(parallelHC);
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std :: cout << "\nResult before the EA\n";
|
||||
pop.sort();
|
||||
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);
|
||||
eoEvalFuncCounter< 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);
|
||||
eoEPReplacement <Route> replace (2);
|
||||
eoEasyEA< Route > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
peo :: run ();
|
||||
peo :: finalize ();
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std :: cout << "\nResult after the EA\n";
|
||||
pop.sort();
|
||||
for(unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
std :: cout << "\n\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
#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);
|
||||
}
|
||||
|
||||
template <class EOT>
|
||||
class eoResizerInit: public eoInit<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename EOT::AtomType AtomType;
|
||||
|
||||
eoResizerInit(unsigned _size)
|
||||
: size(_size){}
|
||||
|
||||
virtual void operator()(EOT& chrom)
|
||||
{
|
||||
chrom.resize(size);
|
||||
chrom.invalidate();
|
||||
}
|
||||
private :
|
||||
unsigned size;
|
||||
};
|
||||
|
||||
|
||||
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 omega = 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);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
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);
|
||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,omega,C1,C2,bnds);
|
||||
|
||||
eoResizerInit<Indi> sizeInit(VEC_SIZE);
|
||||
// need at least a size initialization
|
||||
eoPop < Indi > pop(POP_SIZE,sizeInit);
|
||||
eoInitFixedLength < Indi > randomSeq (VEC_SIZE, uGen);
|
||||
peoMultiStart <Indi> initRandom (randomSeq);
|
||||
peoWrapper random (initRandom,pop);
|
||||
initRandom.setOwner(random);
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
|
||||
// Parallel algorithm
|
||||
|
||||
peo :: init (__argc, __argv);
|
||||
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
||||
peoPopEval< Indi > eval(plainEval);
|
||||
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
|
||||
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
|
||||
peoWrapper parallelPSO( psa, pop);
|
||||
eval.setOwner(parallelPSO);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
## miscallenous parameters
|
||||
|
||||
--debug=false
|
||||
|
||||
## deployment schema
|
||||
|
||||
--schema=schema.xml
|
||||
|
||||
## parameters
|
||||
|
||||
--inst=../examples/tsp/benchs/eil101.tsp
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?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