t-EASyncIsland.cpp

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

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