/* Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012 Alexandre Quemy, Thibault Lasnier - INSA Rouen This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software. You can ue, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms. ParadisEO WebSite : http://paradiseo.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr */ /*/////////////////////////////////////////////////////////////////// // SMP Tutorial 3 : Heterogeneous Model // This file shows how to create an heterogeneous // island model with 2 islands : an eoEasyEA island and a PSO. // The file can be broken down into 3 parts : // The PSO part, with algorithm parameters and PSO Island creatation. // Then, the eoEasyEA part. // And finally, the model creation. // On top of that, you conversion functions are defined at the // begining of this file. /*/////////////////////////////////////////////////////////////////// #include #include #include #include "../BaseLesson.h" using namespace paradiseo::smp; using namespace std; typedef eoBit Indi2; // A bitstring with fitness double // Conversion functions Indi2 fromBase(Indi& i, unsigned size) { (void)i; // Dummy conversion. We just create a new Indi2 Indi2 v; for (unsigned ivar=0; ivar eval(binary_value); // PSO population initialization eoPop pop; for(unsigned int igeno=0; igeno select(T_SIZE); // T_SIZE in [2,POP_SIZE] eo1PtBitXover xover; eoBitMutation mutation(P_MUT_PER_BIT); eoGenContinue continuator(MAX_GEN); // // Emigration policy // // // Element 1 eoPeriodicContinue criteria(1); eoDetTournamentSelect selectOne(2); eoSelectNumber who(selectOne, 1); MigPolicy migPolicy; migPolicy.push_back(PolicyElement(who, criteria)); // // Integration policy eoPlusReplacement intPolicy; // We bind conversion functions auto frombase = std::bind(fromBase, std::placeholders::_1, VEC_SIZE); auto tobase = std::bind(toBase, std::placeholders::_1); Island gga(frombase, tobase, pop, intPolicy, migPolicy, select, xover, CROSS_RATE, mutation, MUT_RATE, eval, continuator); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // EasyEA PART ////////////////////////////////////////////////////////////////// // EA general parameters typedef struct { unsigned popSize = 10; unsigned tSize = 2; double pCross = 0.8; double pMut = 0.7; unsigned maxGen = 10; } Param; Param param; loadInstances("../lessonData.dat", n, bkv, a, b); // Evaluation function IndiEvalFunc plainEval; // Init a solution IndiInit chromInit; // Define selection eoDetTournamentSelect selectOne2(param.tSize); eoSelectPerc select2(selectOne2);// by default rate==1 // Define operators for crossover and mutation IndiXover Xover; // CROSSOVER IndiSwapMutation mutationSwap; // MUTATION // Encapsule in a tranform operator eoSGATransform transform(Xover, param.pCross, mutationSwap, param.pMut); // Define replace operator eoPlusReplacement replace; eoGenContinue genCont(param.maxGen); // generation continuation eoPop pop2(param.popSize, chromInit); // ISLAND 2 : EasyEA // // Emigration policy // // // Element 1 eoPeriodicContinue criteria2(1); eoDetTournamentSelect selectOne3(5); eoSelectNumber who2(selectOne3, 2); MigPolicy migPolicy2; migPolicy2.push_back(PolicyElement(who2, criteria2)); // // Integration policy eoPlusReplacement intPolicy2; Island test(pop2, intPolicy2, migPolicy2, genCont, plainEval, select2, transform, replace); ////////////////////////////////////////////////////////////////// // MODEL CREATION Topology topo; IslandModel model(topo); try { model.add(test); model.add(gga); model(); cout << test.getPop() << endl; cout << gga.getPop() << endl; } catch(exception& e) { cout << "Exception: " << e.what() << '\n'; } return 0; }