From 743d94aea0b1f8e7a1a0bb24f5d4d0e3c0367f2d Mon Sep 17 00:00:00 2001 From: canape Date: Wed, 30 Jan 2008 13:49:55 +0000 Subject: [PATCH] Test peo modified git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@911 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-peo/test/CMakeLists.txt | 19 ++++- trunk/paradiseo-peo/test/t-EAAsyncIsland.cpp | 8 ++ .../paradiseo-peo/test/t-EAAsyncIslandLib.cpp | 77 +++++++++++++++++ trunk/paradiseo-peo/test/t-EASyncIsland.cpp | 8 ++ .../paradiseo-peo/test/t-EASyncIslandLib.cpp | 81 ++++++++++++++++++ trunk/paradiseo-peo/test/t-MultiStart.cpp | 42 ++------- trunk/paradiseo-peo/test/t-MultiStartLib.cpp | 40 +++++++++ trunk/paradiseo-peo/test/t-PSOGlobalBest.cpp | 8 ++ .../paradiseo-peo/test/t-PSOGlobalBestLib.cpp | 85 +++++++++++++++++++ trunk/paradiseo-peo/test/t-PSOSelect.cpp | 34 ++++++++ .../paradiseo-peo/test/t-PSOWorstPosition.cpp | 8 ++ .../test/t-PSOWorstPositionLib.cpp | 85 +++++++++++++++++++ trunk/paradiseo-peo/test/t-ParallelEval.cpp | 42 +-------- .../paradiseo-peo/test/t-ParallelEvalLib.cpp | 42 +++++++++ .../test/t-ParallelTransform.cpp | 55 +----------- .../test/t-ParallelTransformLib.cpp | 55 ++++++++++++ trunk/paradiseo-peo/test/t-peo.cpp | 10 --- 17 files changed, 559 insertions(+), 140 deletions(-) create mode 100644 trunk/paradiseo-peo/test/t-EAAsyncIsland.cpp create mode 100644 trunk/paradiseo-peo/test/t-EAAsyncIslandLib.cpp create mode 100644 trunk/paradiseo-peo/test/t-EASyncIsland.cpp create mode 100644 trunk/paradiseo-peo/test/t-EASyncIslandLib.cpp create mode 100644 trunk/paradiseo-peo/test/t-MultiStartLib.cpp create mode 100644 trunk/paradiseo-peo/test/t-PSOGlobalBest.cpp create mode 100644 trunk/paradiseo-peo/test/t-PSOGlobalBestLib.cpp create mode 100644 trunk/paradiseo-peo/test/t-PSOSelect.cpp create mode 100644 trunk/paradiseo-peo/test/t-PSOWorstPosition.cpp create mode 100644 trunk/paradiseo-peo/test/t-PSOWorstPositionLib.cpp create mode 100644 trunk/paradiseo-peo/test/t-ParallelEvalLib.cpp create mode 100644 trunk/paradiseo-peo/test/t-ParallelTransformLib.cpp delete mode 100644 trunk/paradiseo-peo/test/t-peo.cpp diff --git a/trunk/paradiseo-peo/test/CMakeLists.txt b/trunk/paradiseo-peo/test/CMakeLists.txt index aff4a4147..1d34b86ae 100644 --- a/trunk/paradiseo-peo/test/CMakeLists.txt +++ b/trunk/paradiseo-peo/test/CMakeLists.txt @@ -59,12 +59,23 @@ ENDIF(WIN32 AND NOT CYGWIN) ### 3) Define your targets and link the librairies ###################################################################################### -SET (TEST_LIST t-peo - ) - -SET (TEST_LIBRARY t-ParallelEval +SET (TEST_LIST t-ParallelEval t-ParallelTransform t-MultiStart + t-PSOSelect + t-EAAsyncIsland + t-EASyncIsland + t-PSOGlobalBest + t-PSOWorstPosition + ) + +SET (TEST_LIBRARY t-ParallelEvalLib + t-ParallelTransformLib + t-MultiStartLib + t-EAAsyncIslandLib + t-EASyncIslandLib + t-PSOGlobalBestLib + t-PSOWorstPositionLib ) diff --git a/trunk/paradiseo-peo/test/t-EAAsyncIsland.cpp b/trunk/paradiseo-peo/test/t-EAAsyncIsland.cpp new file mode 100644 index 000000000..715849ccf --- /dev/null +++ b/trunk/paradiseo-peo/test/t-EAAsyncIsland.cpp @@ -0,0 +1,8 @@ +#include + +int main (int __argc, char *__argv[]) +{ + system("mpdboot"); + system("mpiexec -n 4 ./t-EAAsyncIslandLib @param "); + system("mpdallexit"); +} diff --git a/trunk/paradiseo-peo/test/t-EAAsyncIslandLib.cpp b/trunk/paradiseo-peo/test/t-EAAsyncIslandLib.cpp new file mode 100644 index 000000000..1bcbefe40 --- /dev/null +++ b/trunk/paradiseo-peo/test/t-EAAsyncIslandLib.cpp @@ -0,0 +1,77 @@ +//Test : Asynchronous island with EA +#include +#include +typedef eoReal Indi; + +double f (const Indi & _indi) +{ + double sum=_indi[0]+_indi[1]; + return (-sum); +} +int main (int __argc, char *__argv[]) +{ + peo :: init( __argc, __argv ); + if (getNodeRank()==1) + std::cout<<"\n\nTest : Asynchronous island with EA\n\n"; + rng.reseed (10); + RingTopology topology; + eoGenContinue < Indi > genContPara (10); + eoCombinedContinue continuatorPara (genContPara); + eoCheckPoint checkpoint(continuatorPara); + peoEvalFunc mainEval( f ); + peoPopEval eval(mainEval); + eoUniformGenerator < double >uGen (-2., 2.); + eoInitFixedLength < Indi > random (2, uGen); + eoRankingSelect selectionStrategy; + eoSelectNumber select(selectionStrategy,10); + eoSegmentCrossover crossover; + eoUniformMutation mutation(0.01); + peoTransform transform(crossover,0.8,mutation,0.3); + peoPop < Indi > pop; + pop.append (10, random); + eoPlusReplacement replace; + eoRandomSelect mig_select_one; + eoSelector > mig_select (mig_select_one,2,pop); + eoReplace > mig_replace (replace,pop); + peoSyncIslandMig > mig(2,mig_select,mig_replace,topology,pop,pop); + checkpoint.add(mig); + eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace ); + peoWrapper parallelEA( eaAlg, pop); + eval.setOwner(parallelEA); + transform.setOwner(parallelEA); + mig.setOwner(parallelEA); + eoGenContinue < Indi > genContPara2 (10); + eoCombinedContinue continuatorPara2 (genContPara2); + eoCheckPoint checkpoint2(continuatorPara2); + peoEvalFunc mainEval2( f ); + peoPopEval eval2(mainEval2); + eoUniformGenerator < double >uGen2 (-2., 2.); + eoInitFixedLength < Indi > random2 (2, uGen2); + eoRankingSelect selectionStrategy2; + eoSelectNumber select2(selectionStrategy2,10); + eoSegmentCrossover crossover2; + eoUniformMutation mutation2(0.01); + peoTransform transform2(crossover2,0.8,mutation2,0.3); + peoPop < Indi > pop2; + pop2.append (10, random2); + eoPlusReplacement replace2; + eoRandomSelect mig_select_one2; + eoSelector > mig_select2 (mig_select_one2,2,pop2); + eoReplace > mig_replace2 (replace2,pop2); + peoSyncIslandMig > mig2(2,mig_select2,mig_replace2,topology,pop2,pop2); + checkpoint2.add(mig2); + eoEasyEA< Indi > eaAlg2( checkpoint2, eval2, select2, transform2, replace2 ); + peoWrapper parallelEA2( eaAlg2, pop2); + eval2.setOwner(parallelEA2); + transform2.setOwner(parallelEA2); + mig2.setOwner(parallelEA2); + peo :: run(); + peo :: finalize(); + if (getNodeRank()==1) + { + pop.sort(); + pop2.sort(); + std::cout << "Final population 1 :\n" << pop << std::endl; + std::cout << "Final population 2 :\n" << pop2 << std::endl; + } +} diff --git a/trunk/paradiseo-peo/test/t-EASyncIsland.cpp b/trunk/paradiseo-peo/test/t-EASyncIsland.cpp new file mode 100644 index 000000000..7971a5014 --- /dev/null +++ b/trunk/paradiseo-peo/test/t-EASyncIsland.cpp @@ -0,0 +1,8 @@ +#include + +int main (int __argc, char *__argv[]) +{ + system("mpdboot"); + system("mpiexec -n 4 ./t-EASyncIslandLib @param "); + system("mpdallexit"); +} diff --git a/trunk/paradiseo-peo/test/t-EASyncIslandLib.cpp b/trunk/paradiseo-peo/test/t-EASyncIslandLib.cpp new file mode 100644 index 000000000..a7b1b8c83 --- /dev/null +++ b/trunk/paradiseo-peo/test/t-EASyncIslandLib.cpp @@ -0,0 +1,81 @@ +//Test : Synchronous island with EA +#include +#include +typedef eoReal Indi; + +double f (const Indi & _indi) +{ + double sum=_indi[0]+_indi[1]; + return (-sum); +} +int main (int __argc, char *__argv[]) +{ + peo :: init( __argc, __argv ); + if (getNodeRank()==1) + std::cout<<"\n\nTest : Synchronous island with EA\n\n"; + rng.reseed (10); + RingTopology topology; + eoGenContinue < Indi > genContPara (10); + eoCombinedContinue continuatorPara (genContPara); + eoCheckPoint checkpoint(continuatorPara); + peoEvalFunc mainEval( f ); + peoPopEval eval(mainEval); + eoUniformGenerator < double >uGen (-2., 2.); + eoInitFixedLength < Indi > random (2, uGen); + eoRankingSelect selectionStrategy; + eoSelectNumber select(selectionStrategy,10); + eoSegmentCrossover crossover; + eoUniformMutation mutation(0.01); + peoTransform transform(crossover,0.8,mutation,0.3); + peoPop < Indi > pop; + pop.append (10, random); + eoPlusReplacement replace; + eoRandomSelect mig_select_one; + eoSelector > mig_select (mig_select_one,2,pop); + eoReplace > mig_replace (replace,pop); + eoPeriodicContinue< Indi > mig_cont( 2 ); + eoContinuator cont(mig_cont, pop); + peoAsyncIslandMig > mig(cont,mig_select,mig_replace,topology,pop,pop); + checkpoint.add(mig); + eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace ); + peoWrapper parallelEA( eaAlg, pop); + eval.setOwner(parallelEA); + transform.setOwner(parallelEA); + mig.setOwner(parallelEA); + eoGenContinue < Indi > genContPara2 (10); + eoCombinedContinue continuatorPara2 (genContPara2); + eoCheckPoint checkpoint2(continuatorPara2); + peoEvalFunc mainEval2( f ); + peoPopEval eval2(mainEval2); + eoUniformGenerator < double >uGen2 (-2., 2.); + eoInitFixedLength < Indi > random2 (2, uGen2); + eoRankingSelect selectionStrategy2; + eoSelectNumber select2(selectionStrategy2,10); + eoSegmentCrossover crossover2; + eoUniformMutation mutation2(0.01); + peoTransform transform2(crossover2,0.8,mutation2,0.3); + peoPop < Indi > pop2; + pop2.append (10, random2); + eoPlusReplacement replace2; + eoRandomSelect mig_select_one2; + eoSelector > mig_select2 (mig_select_one2,2,pop2); + eoReplace > mig_replace2 (replace2,pop2); + eoPeriodicContinue< Indi > mig_cont2( 2 ); + eoContinuator cont2(mig_cont2, pop2); + peoAsyncIslandMig > mig2(cont2,mig_select2,mig_replace2,topology,pop2,pop2); + checkpoint2.add(mig2); + eoEasyEA< Indi > eaAlg2( checkpoint2, eval2, select2, transform2, replace2 ); + peoWrapper parallelEA2( eaAlg2, pop2); + eval2.setOwner(parallelEA2); + transform2.setOwner(parallelEA2); + mig2.setOwner(parallelEA2); + peo :: run(); + peo :: finalize(); + if (getNodeRank()==1) + { + pop.sort(); + pop2.sort(); + std::cout << "Final population 1 :\n" << pop << std::endl; + std::cout << "Final population 2 :\n" << pop2 << std::endl; + } +} diff --git a/trunk/paradiseo-peo/test/t-MultiStart.cpp b/trunk/paradiseo-peo/test/t-MultiStart.cpp index 96183bae0..ce8599318 100644 --- a/trunk/paradiseo-peo/test/t-MultiStart.cpp +++ b/trunk/paradiseo-peo/test/t-MultiStart.cpp @@ -1,40 +1,8 @@ -// Test : multistart +#include -#include - -struct Algorithm +int main (int __argc, char *__argv[]) { - void operator()(double & _d) - { - _d = _d * _d; - } -}; - -int main (int __argc, char * * __argv) -{ - - peo :: init (__argc, __argv); - if (getNodeRank()==1) - std::cout<<"\n\nTest : multistart\n\n"; - std::vector < double > v; - if (getNodeRank()==1) - std::cout<<"\n\nBefore :"; - for(unsigned i = 0; i< 10; i++) - { - v.push_back(i); - if (getNodeRank()==1) - std::cout<<"\n"< initParallel (algo); - peoWrapper parallelAlgo (initParallel, v); - initParallel.setOwner(parallelAlgo); - peo :: run( ); - peo :: finalize( ); - if (getNodeRank()==1) - { - std::cout<<"\n\nAfter :\n"; - for(unsigned i = 0; i< 10; i++) - std::cout< + +struct Algorithm +{ + void operator()(double & _d) + { + _d = _d * _d; + } +}; + +int main (int __argc, char * * __argv) +{ + + peo :: init (__argc, __argv); + if (getNodeRank()==1) + std::cout<<"\n\nTest : multistart\n\n"; + std::vector < double > v; + if (getNodeRank()==1) + std::cout<<"\n\nBefore :"; + for(unsigned i = 0; i< 10; i++) + { + v.push_back(i); + if (getNodeRank()==1) + std::cout<<"\n"< initParallel (algo); + peoWrapper parallelAlgo (initParallel, v); + initParallel.setOwner(parallelAlgo); + peo :: run( ); + peo :: finalize( ); + if (getNodeRank()==1) + { + std::cout<<"\n\nAfter :\n"; + for(unsigned i = 0; i< 10; i++) + std::cout< + +int main (int __argc, char *__argv[]) +{ + system("mpdboot"); + system("mpiexec -n 4 ./t-PSOGlobalBestLib @param "); + system("mpdallexit"); +} diff --git a/trunk/paradiseo-peo/test/t-PSOGlobalBestLib.cpp b/trunk/paradiseo-peo/test/t-PSOGlobalBestLib.cpp new file mode 100644 index 000000000..949445c6f --- /dev/null +++ b/trunk/paradiseo-peo/test/t-PSOGlobalBestLib.cpp @@ -0,0 +1,85 @@ +// Test : PSO Global Best +#include +typedef eoRealParticle < double >Indi; +double f (const Indi & _indi) +{ + double sum=_indi[0]+_indi[1]; + return (sum); +} +int main (int __argc, char *__argv[]) +{ + peo :: init( __argc, __argv ); + if (getNodeRank()==1) + std::cout<<"\n\nTest : PSO Global Best\n\n"; + rng.reseed (10); + RingTopology topologyMig; + eoGenContinue < Indi > genContPara (10); + eoCombinedContinue continuatorPara (genContPara); + eoCheckPoint checkpoint(continuatorPara); + peoEvalFunc plainEval(f); + peoPopEval< Indi > eval(plainEval); + eoUniformGenerator < double >uGen (0, 1.); + eoInitFixedLength < Indi > random (2, uGen); + eoUniformGenerator < double >sGen (-1., 1.); + eoVelocityInitFixedLength < Indi > veloRandom (2, sGen); + eoFirstIsBestInit < Indi > localInit; + eoRealVectorBounds bndsFlight(2,0,1.); + eoStandardFlight < Indi > flight(bndsFlight); + peoPop < Indi > pop; + pop.append (10, random); + eoLinearTopology topology(2); + eoRealVectorBounds bnds(2,-1.,1.); + eoStandardVelocity < Indi > velocity (topology,1,0.5,2.,bnds); + eoInitializer init(eval,veloRandom,localInit,topology,pop); + eoPeriodicContinue< Indi > mig_cont( 2 ); + peoPSOSelect mig_selec(topology); + peoGlobalBestVelocity mig_replac (2.,velocity); + eoContinuator cont(mig_cont, pop); + eoSelector > mig_select (mig_selec,1,pop); + eoReplace > mig_replace (mig_replac,pop); + eoGenContinue < Indi > genContPara2 (10); + eoCombinedContinue continuatorPara2 (genContPara2); + eoCheckPoint checkpoint2(continuatorPara2); + peoEvalFunc plainEval2(f); + peoPopEval< Indi > eval2(plainEval2); + eoUniformGenerator < double >uGen2 (0, 1.); + eoInitFixedLength < Indi > random2 (2, uGen2); + eoUniformGenerator < double >sGen2 (-1., 1.); + eoVelocityInitFixedLength < Indi > veloRandom2 (2, sGen2); + eoFirstIsBestInit < Indi > localInit2; + eoRealVectorBounds bndsFlight2(2,0,1.); + eoStandardFlight < Indi > flight2(bndsFlight2); + peoPop < Indi > pop2; + pop2.append (10, random2); + eoLinearTopology topology2(2); + eoRealVectorBounds bnds2(2,-1.,1.); + eoStandardVelocity < Indi > velocity2 (topology2,1,0.5,2.,bnds2); + eoInitializer init2(eval2,veloRandom2,localInit2,topology2,pop2); + eoPeriodicContinue< Indi > mig_cont2( 2 ); + peoPSOSelect mig_selec2(topology2); + peoGlobalBestVelocity mig_replac2 (2.,velocity2); + eoContinuator cont2(mig_cont2,pop2); + eoSelector > mig_select2 (mig_selec2,1,pop2); + eoReplace > mig_replace2 (mig_replac2,pop2); + peoAsyncIslandMig< Indi, peoPop > mig(cont,mig_select, mig_replace, topologyMig, pop, pop); + checkpoint.add( mig ); + peoAsyncIslandMig< Indi, peoPop > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2); + checkpoint2.add( mig2 ); + eoSyncEasyPSO psa(init,checkpoint,eval, velocity, flight); + peoWrapper parallelPSO( psa, pop); + eval.setOwner(parallelPSO); + mig.setOwner(parallelPSO); + eoSyncEasyPSO 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; + } +} diff --git a/trunk/paradiseo-peo/test/t-PSOSelect.cpp b/trunk/paradiseo-peo/test/t-PSOSelect.cpp new file mode 100644 index 000000000..f5628fd6c --- /dev/null +++ b/trunk/paradiseo-peo/test/t-PSOSelect.cpp @@ -0,0 +1,34 @@ +//Test : PSO select +#include +typedef eoRealParticle < double >Indi; +double f (const Indi & _indi) +{ + double sum=_indi[0]+_indi[1]; + return (-sum); +} + +int main (int __argc, char *__argv[]) +{ + std::cout<<"\n\nTest : PSO select\n\n"; + rng.reseed (10); + peoEvalFunc plainEval(f); + eoEvalFuncCounter < Indi > firstEval(plainEval); + eoPopLoopEval < Indi > eval(firstEval); + eoUniformGenerator < double >uGen (1, 2); + eoInitFixedLength < Indi > random (2, uGen); + eoUniformGenerator < double >sGen (-1, 1); + eoVelocityInitFixedLength < Indi > veloRandom (2, sGen); + eoFirstIsBestInit < Indi > localInit; + eoRealVectorBounds bndsFlight(2,1,2); + eoStandardFlight < Indi > flight(bndsFlight); + eoLinearTopology topology(6); + eoRealVectorBounds bnds(2,-1,1); + eoStandardVelocity < Indi > velocity (topology,1,0.5,2.,bnds); + eoPop < Indi > empty_pop,pop(20, random); + eoInitializer init(eval,veloRandom,localInit,topology,pop); + init(); + eval (empty_pop,pop); + peoPSOSelect mig_selec(topology); + pop.sort(); + std::cout<<"\nBest : "< + +int main (int __argc, char *__argv[]) +{ + system("mpdboot"); + system("mpiexec -n 4 ./t-PSOWorstPositionLib @param "); + system("mpdallexit"); +} diff --git a/trunk/paradiseo-peo/test/t-PSOWorstPositionLib.cpp b/trunk/paradiseo-peo/test/t-PSOWorstPositionLib.cpp new file mode 100644 index 000000000..ea784d726 --- /dev/null +++ b/trunk/paradiseo-peo/test/t-PSOWorstPositionLib.cpp @@ -0,0 +1,85 @@ +// Test : PSO Worst Position +#include +typedef eoRealParticle < double >Indi; +double f (const Indi & _indi) +{ + double sum=_indi[0]+_indi[1]; + return (sum); +} +int main (int __argc, char *__argv[]) +{ + peo :: init( __argc, __argv ); + if (getNodeRank()==1) + std::cout<<"\n\nTest : PSO Worst Position\n\n"; + rng.reseed (10); + RingTopology topologyMig; + eoGenContinue < Indi > genContPara (10); + eoCombinedContinue continuatorPara (genContPara); + eoCheckPoint checkpoint(continuatorPara); + peoEvalFunc plainEval(f); + peoPopEval< Indi > eval(plainEval); + eoUniformGenerator < double >uGen (0, 1.); + eoInitFixedLength < Indi > random (2, uGen); + eoUniformGenerator < double >sGen (-1., 1.); + eoVelocityInitFixedLength < Indi > veloRandom (2, sGen); + eoFirstIsBestInit < Indi > localInit; + eoRealVectorBounds bndsFlight(2,0,1.); + eoStandardFlight < Indi > flight(bndsFlight); + peoPop < Indi > pop; + pop.append (10, random); + eoLinearTopology topology(2); + eoRealVectorBounds bnds(2,-1.,1.); + eoStandardVelocity < Indi > velocity (topology,1,0.5,2.,bnds); + eoInitializer init(eval,veloRandom,localInit,topology,pop); + eoPeriodicContinue< Indi > mig_cont( 2 ); + peoPSOSelect mig_selec(topology); + peoWorstPositionReplacement mig_replac; + eoContinuator cont(mig_cont, pop); + eoSelector > mig_select (mig_selec,1,pop); + eoReplace > mig_replace (mig_replac,pop); + eoGenContinue < Indi > genContPara2 (10); + eoCombinedContinue continuatorPara2 (genContPara2); + eoCheckPoint checkpoint2(continuatorPara2); + peoEvalFunc plainEval2(f); + peoPopEval< Indi > eval2(plainEval2); + eoUniformGenerator < double >uGen2 (0, 1.); + eoInitFixedLength < Indi > random2 (2, uGen2); + eoUniformGenerator < double >sGen2 (-1., 1.); + eoVelocityInitFixedLength < Indi > veloRandom2 (2, sGen2); + eoFirstIsBestInit < Indi > localInit2; + eoRealVectorBounds bndsFlight2(2,0,1.); + eoStandardFlight < Indi > flight2(bndsFlight2); + peoPop < Indi > pop2; + pop2.append (10, random2); + eoLinearTopology topology2(2); + eoRealVectorBounds bnds2(2,-1.,1.); + eoStandardVelocity < Indi > velocity2 (topology2,1,0.5,2.,bnds2); + eoInitializer init2(eval2,veloRandom2,localInit2,topology2,pop2); + eoPeriodicContinue< Indi > mig_cont2( 2 ); + peoPSOSelect mig_selec2(topology2); + peoWorstPositionReplacement mig_replac2; + eoContinuator cont2(mig_cont2,pop2); + eoSelector > mig_select2 (mig_selec2,1,pop2); + eoReplace > mig_replace2 (mig_replac2,pop2); + peoAsyncIslandMig< Indi, peoPop > mig(cont,mig_select, mig_replace, topologyMig, pop, pop); + checkpoint.add( mig ); + peoAsyncIslandMig< Indi, peoPop > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2); + checkpoint2.add( mig2 ); + eoSyncEasyPSO psa(init,checkpoint,eval, velocity, flight); + peoWrapper parallelPSO( psa, pop); + eval.setOwner(parallelPSO); + mig.setOwner(parallelPSO); + eoSyncEasyPSO 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; + } +} diff --git a/trunk/paradiseo-peo/test/t-ParallelEval.cpp b/trunk/paradiseo-peo/test/t-ParallelEval.cpp index 0d3054cd5..57f791c60 100644 --- a/trunk/paradiseo-peo/test/t-ParallelEval.cpp +++ b/trunk/paradiseo-peo/test/t-ParallelEval.cpp @@ -1,42 +1,8 @@ -// Test : parallel evaluation -#include -#include -typedef eoReal Indi; -double f (const Indi & _indi) -{ - double sum=_indi[0]+_indi[1]; - return (-sum); -} -struct Algorithm -{ - Algorithm( peoPopEval < Indi > & _eval): eval( _eval ){} - void operator()(eoPop < Indi > & _pop) - { - eoPop < Indi > empty_pop; - eval(empty_pop, _pop); - } - peoPopEval < Indi > & eval; -}; +#include int main (int __argc, char *__argv[]) { - peo :: init( __argc, __argv ); - if (getNodeRank()==1) - std::cout<<"\n\nTest : parallel evaluation\n\n"; - rng.reseed (10); - peoEvalFunc plainEval(f); - peoPopEval< Indi > eval(plainEval); - eoUniformGenerator < double >uGen (0, 1); - eoInitFixedLength < Indi > random (2, uGen); - eoPop < Indi > pop(20, random); - Algorithm algo ( eval ); - peoWrapper parallelAlgo( algo, pop); - eval.setOwner(parallelAlgo); - peo :: run(); - peo :: finalize(); - if (getNodeRank()==1) - { - pop.sort(); - std::cout< +#include +typedef eoReal Indi; +double f (const Indi & _indi) +{ + double sum=_indi[0]+_indi[1]; + return (-sum); +} +struct Algorithm +{ + Algorithm( peoPopEval < Indi > & _eval): eval( _eval ){} + void operator()(eoPop < Indi > & _pop) + { + eoPop < Indi > empty_pop; + eval(empty_pop, _pop); + } + peoPopEval < Indi > & eval; +}; + +int main (int __argc, char *__argv[]) +{ + peo :: init( __argc, __argv ); + if (getNodeRank()==1) + std::cout<<"\n\nTest : parallel evaluation\n\n"; + rng.reseed (10); + peoEvalFunc plainEval(f); + peoPopEval< Indi > eval(plainEval); + eoUniformGenerator < double >uGen (0, 1); + eoInitFixedLength < Indi > random (2, uGen); + eoPop < Indi > pop(20, random); + Algorithm algo ( eval ); + peoWrapper parallelAlgo( algo, pop); + eval.setOwner(parallelAlgo); + peo :: run(); + peo :: finalize(); + if (getNodeRank()==1) + { + pop.sort(); + std::cout< -#include -typedef eoReal Indi; -double f (const Indi & _indi) -{ - double sum=_indi[0]+_indi[1]; - return (-sum); -} -struct Algorithm -{ - Algorithm( eoEvalFunc < Indi > & _eval, eoSelect < Indi > & _select, peoTransform < Indi > & _transform): - loopEval(_eval), - eval(loopEval), - selectTransform( _select, _transform), - breed(selectTransform) {} - - void operator()(eoPop < Indi > & _pop) - { - eoPop < Indi > offspring, empty_pop; - eval(empty_pop, _pop); - eval(empty_pop, offspring); - std::cout<<"\n\nBefore :\n"< loopEval; - eoPopEvalFunc < Indi > & eval; - eoSelectTransform < Indi > selectTransform; - eoBreed < Indi > & breed; -}; +#include int main (int __argc, char *__argv[]) { - peo :: init( __argc, __argv ); - if (getNodeRank()==1) - std::cout<<"\n\nTest : parallel transform\n\n"; - rng.reseed (10); - eoEvalFuncPtr < Indi > plainEval(f); - eoEvalFuncCounter < Indi > eval(plainEval); - eoUniformGenerator < double >uGen (0, 1); - eoInitFixedLength < Indi > random (2, uGen); - eoPop < Indi > empty_pop,pop(6, random); - eoRankingSelect < Indi > selectionStrategy; - eoSelectNumber < Indi > select(selectionStrategy,6); - eoSegmentCrossover < Indi > crossover; - eoUniformMutation < Indi > mutation(0.01); - peoTransform transform(crossover,0.8,mutation,0.3); - Algorithm algo ( eval, select, transform ); - peoWrapper parallelAlgo( algo, pop); - transform.setOwner(parallelAlgo); - peo :: run(); - peo :: finalize(); + system("mpdboot"); + system("mpiexec -n 4 ./t-ParallelTransformLib @param "); + system("mpdallexit"); } diff --git a/trunk/paradiseo-peo/test/t-ParallelTransformLib.cpp b/trunk/paradiseo-peo/test/t-ParallelTransformLib.cpp new file mode 100644 index 000000000..14c5b9247 --- /dev/null +++ b/trunk/paradiseo-peo/test/t-ParallelTransformLib.cpp @@ -0,0 +1,55 @@ +// Test : parallel transform +#include +#include +typedef eoReal Indi; +double f (const Indi & _indi) +{ + double sum=_indi[0]+_indi[1]; + return (-sum); +} +struct Algorithm +{ + Algorithm( eoEvalFunc < Indi > & _eval, eoSelect < Indi > & _select, peoTransform < Indi > & _transform): + loopEval(_eval), + eval(loopEval), + selectTransform( _select, _transform), + breed(selectTransform) {} + + void operator()(eoPop < Indi > & _pop) + { + eoPop < Indi > offspring, empty_pop; + eval(empty_pop, _pop); + eval(empty_pop, offspring); + std::cout<<"\n\nBefore :\n"< loopEval; + eoPopEvalFunc < Indi > & eval; + eoSelectTransform < Indi > selectTransform; + eoBreed < Indi > & breed; +}; + +int main (int __argc, char *__argv[]) +{ + peo :: init( __argc, __argv ); + if (getNodeRank()==1) + std::cout<<"\n\nTest : parallel transform\n\n"; + rng.reseed (10); + eoEvalFuncPtr < Indi > plainEval(f); + eoEvalFuncCounter < Indi > eval(plainEval); + eoUniformGenerator < double >uGen (0, 1); + eoInitFixedLength < Indi > random (2, uGen); + eoPop < Indi > empty_pop,pop(6, random); + eoRankingSelect < Indi > selectionStrategy; + eoSelectNumber < Indi > select(selectionStrategy,6); + eoSegmentCrossover < Indi > crossover; + eoUniformMutation < Indi > mutation(0.01); + peoTransform transform(crossover,0.8,mutation,0.3); + Algorithm algo ( eval, select, transform ); + peoWrapper parallelAlgo( algo, pop); + transform.setOwner(parallelAlgo); + peo :: run(); + peo :: finalize(); +} diff --git a/trunk/paradiseo-peo/test/t-peo.cpp b/trunk/paradiseo-peo/test/t-peo.cpp deleted file mode 100644 index 0de8f1643..000000000 --- a/trunk/paradiseo-peo/test/t-peo.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int main (int __argc, char *__argv[]) -{ - system("mpdboot"); - system("mpiexec -n 4 ./t-ParallelEval @param "); - system("mpiexec -n 4 ./t-ParallelTransform @param "); - system("mpiexec -n 4 ./t-MultiStart @param "); - system("mpdallexit"); -}