t-PSOGlobalBest.cpp

00001 /*
00002 * <t-PSOGlobalBest.cpp>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
00004 * (C) OPAC Team, LIFL, 2002-2008
00005 *
00006 * Clive Canape
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * peoData to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 
00037 
00038 // Test : PSO Global Best
00039 #include <peo>
00040 typedef eoRealParticle < double >Indi;
00041 double f (const Indi & _indi)
00042 {
00043   double sum=_indi[0]+_indi[1];
00044   return (sum);
00045 }
00046 int main (int __argc, char *__argv[])
00047 {
00048   peo :: init( __argc, __argv );
00049   if (getNodeRank()==1)
00050     std::cout<<"\n\nTest : PSO Global Best\n\n";
00051   rng.reseed (10);
00052   RingTopology topologyMig;
00053   eoGenContinue < Indi > genContPara (10);
00054   eoCombinedContinue <Indi> continuatorPara (genContPara);
00055   eoCheckPoint<Indi> checkpoint(continuatorPara);
00056   peoEvalFunc<Indi, double, const Indi& > plainEval(f);
00057   peoPopEval< Indi > eval(plainEval);
00058   eoUniformGenerator < double >uGen (0, 1.);
00059   eoInitFixedLength < Indi > random (2, uGen);
00060   eoUniformGenerator < double >sGen (-1., 1.);
00061   eoVelocityInitFixedLength < Indi > veloRandom (2, sGen);
00062   eoFirstIsBestInit < Indi > localInit;
00063   eoRealVectorBounds bndsFlight(2,0,1.);
00064   eoStandardFlight < Indi > flight(bndsFlight);
00065   eoPop < Indi > pop;
00066   pop.append (10, random);
00067   eoLinearTopology<Indi> topology(2);
00068   eoRealVectorBounds bnds(2,-1.,1.);
00069   eoStandardVelocity < Indi > velocity (topology,1,0.5,2.,bnds);
00070   eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
00071   eoPeriodicContinue< Indi > mig_cont( 2 );
00072   peoPSOSelect<Indi> mig_selec(topology);
00073   peoGlobalBestVelocity<Indi> mig_replac (2.,velocity);
00074   eoContinuator<Indi> cont(mig_cont, pop);
00075   eoSelector <Indi, eoPop<Indi> > mig_select (mig_selec,1,pop);
00076   eoReplace <Indi, eoPop<Indi> > mig_replace (mig_replac,pop);
00077   eoGenContinue < Indi > genContPara2 (10);
00078   eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
00079   eoCheckPoint<Indi> checkpoint2(continuatorPara2);
00080   peoEvalFunc<Indi, double, const Indi& > plainEval2(f);
00081   peoPopEval< Indi > eval2(plainEval2);
00082   eoUniformGenerator < double >uGen2 (0, 1.);
00083   eoInitFixedLength < Indi > random2 (2, uGen2);
00084   eoUniformGenerator < double >sGen2 (-1., 1.);
00085   eoVelocityInitFixedLength < Indi > veloRandom2 (2, sGen2);
00086   eoFirstIsBestInit < Indi > localInit2;
00087   eoRealVectorBounds bndsFlight2(2,0,1.);
00088   eoStandardFlight < Indi > flight2(bndsFlight2);
00089   eoPop < Indi > pop2;
00090   pop2.append (10, random2);
00091   eoLinearTopology<Indi> topology2(2);
00092   eoRealVectorBounds bnds2(2,-1.,1.);
00093   eoStandardVelocity < Indi > velocity2 (topology2,1,0.5,2.,bnds2);
00094   eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2);
00095   eoPeriodicContinue< Indi > mig_cont2( 2 );
00096   peoPSOSelect<Indi> mig_selec2(topology2);
00097   peoGlobalBestVelocity<Indi> mig_replac2 (2.,velocity2);
00098   eoContinuator<Indi> cont2(mig_cont2,pop2);
00099   eoSelector <Indi, eoPop<Indi> > mig_select2 (mig_selec2,1,pop2);
00100   eoReplace <Indi, eoPop<Indi> > mig_replace2 (mig_replac2,pop2);
00101   peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig);
00102   checkpoint.add( mig );
00103   peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig);
00104   checkpoint2.add( mig2 );
00105   eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
00106   peoWrapper parallelPSO( psa, pop);
00107   eval.setOwner(parallelPSO);
00108   mig.setOwner(parallelPSO);
00109   eoSyncEasyPSO <Indi> psa2(init2,checkpoint2,eval2, velocity2, flight2);
00110   peoWrapper parallelPSO2( psa2, pop2);
00111   eval2.setOwner(parallelPSO2);
00112   mig2.setOwner(parallelPSO2);
00113   peo :: run();
00114   peo :: finalize();
00115   if (getNodeRank()==1)
00116     {
00117       pop.sort();
00118       pop2.sort();
00119       std::cout << "Final population :\n" << pop << std::endl;
00120       std::cout << "Final population :\n" << pop2        << std::endl;
00121     }
00122 }

Generated on Thu Mar 13 15:55:03 2008 for ParadisEO-PEO-ParallelanddistributedEvolvingObjects by  doxygen 1.4.7