t-EAAsyncIsland.cpp

00001 /*
00002 * <t-EAAsyncIsland.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 //Test : Asynchronous island with EA
00038 #include <peo>
00039 #include <es.h>
00040 typedef eoReal<double> Indi;
00041 
00042 double f (const Indi & _indi)
00043 {
00044   double sum=_indi[0]+_indi[1];
00045   return (-sum);
00046 }
00047 int main (int __argc, char *__argv[])
00048 {
00049   peo :: init( __argc, __argv );
00050   if (getNodeRank()==1)
00051     std::cout<<"\n\nTest : Asynchronous island with EA\n\n";
00052   rng.reseed (10);
00053   RingTopology topology;
00054   eoGenContinue < Indi > genContPara (10);
00055   eoCombinedContinue <Indi> continuatorPara (genContPara);
00056   eoCheckPoint<Indi> checkpoint(continuatorPara);
00057   peoEvalFunc<Indi> mainEval( f );
00058   peoPopEval <Indi> eval(mainEval);
00059   eoUniformGenerator < double >uGen (-2., 2.);
00060   eoInitFixedLength < Indi > random (2, uGen);
00061   eoRankingSelect<Indi> selectionStrategy;
00062   eoSelectNumber<Indi> select(selectionStrategy,10);
00063   eoSegmentCrossover<Indi> crossover;
00064   eoUniformMutation<Indi>  mutation(0.01);
00065   peoTransform<Indi> transform(crossover,0.8,mutation,0.3);
00066   /*p*/
00067   eoPop < Indi > pop;
00068   pop.append (10, random);
00069   eoPlusReplacement<Indi> replace;
00070   eoRandomSelect<Indi> mig_select_one;
00071   eoSelector <Indi, eoPop<Indi> > mig_select (mig_select_one,2,pop);
00072   eoReplace <Indi, eoPop<Indi> > mig_replace (replace,pop);
00073   eoPeriodicContinue< Indi > mig_cont( 2 );
00074   eoContinuator<Indi> cont(mig_cont, pop);
00075   peoAsyncIslandMig<eoPop<Indi>, eoPop<Indi> > mig(cont,mig_select,mig_replace,topology);
00076   checkpoint.add(mig);
00077   eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
00078   peoWrapper parallelEA( eaAlg, pop);
00079   eval.setOwner(parallelEA);
00080   transform.setOwner(parallelEA);
00081   mig.setOwner(parallelEA);
00082   eoGenContinue < Indi > genContPara2 (10);
00083   eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
00084   eoCheckPoint<Indi> checkpoint2(continuatorPara2);
00085   peoEvalFunc<Indi> mainEval2( f );
00086   peoPopEval <Indi> eval2(mainEval2);
00087   eoUniformGenerator < double >uGen2 (-2., 2.);
00088   eoInitFixedLength < Indi > random2 (2, uGen2);
00089   eoRankingSelect<Indi> selectionStrategy2;
00090   eoSelectNumber<Indi> select2(selectionStrategy2,10);
00091   eoSegmentCrossover<Indi> crossover2;
00092   eoUniformMutation<Indi>  mutation2(0.01);
00093   peoTransform<Indi> transform2(crossover2,0.8,mutation2,0.3);
00094   /*p*/
00095   eoPop < Indi > pop2;
00096   pop2.append (10, random2);
00097   eoPlusReplacement<Indi> replace2;
00098   eoRandomSelect<Indi> mig_select_one2;
00099   eoSelector <Indi, eoPop<Indi> > mig_select2 (mig_select_one2,2,pop2);
00100   eoReplace <Indi, eoPop<Indi> > mig_replace2 (replace2,pop2);
00101   eoPeriodicContinue< Indi > mig_cont2( 2 );
00102   eoContinuator<Indi> cont2(mig_cont2, pop2);
00103   peoAsyncIslandMig<eoPop<Indi>, eoPop<Indi> > mig2(cont2,mig_select2,mig_replace2,topology);
00104   checkpoint2.add(mig2);
00105   eoEasyEA< Indi > eaAlg2( checkpoint2, eval2, select2, transform2, replace2 );
00106   peoWrapper parallelEA2( eaAlg2, pop2);
00107   eval2.setOwner(parallelEA2);
00108   transform2.setOwner(parallelEA2);
00109   mig2.setOwner(parallelEA2);
00110   peo :: run();
00111   peo :: finalize();
00112   if (getNodeRank()==1)
00113     {
00114       pop.sort();
00115       pop2.sort();
00116       std::cout << "Final population 1 :\n" << pop << std::endl;
00117       std::cout << "Final population 2 :\n" << pop2 << std::endl;
00118     }
00119 }

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