Add homogeneous test. Pop is not created by the island anymore and has to me given to the island.

This commit is contained in:
quemy 2012-11-29 22:21:29 +01:00
commit c90fdc579f
5 changed files with 147 additions and 16 deletions

View file

@ -27,12 +27,9 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr
*/ */
#include <type_traits>
template<template <class> class EOAlgo, class EOT> template<template <class> class EOAlgo, class EOT>
template<class... Args> template<class... Args>
paradiseo::smp::Island<EOAlgo,EOT>::Island(unsigned _popSize, eoInit<EOT>& _chromInit, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args) : paradiseo::smp::Island<EOAlgo,EOT>::Island(eoPop<EOT>& _pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args) :
// The PPExpander looks for the continuator in the parameters pack. // The PPExpander looks for the continuator in the parameters pack.
// The private inheritance of ContWrapper wraps the continuator and add islandNotifier. // The private inheritance of ContWrapper wraps the continuator and add islandNotifier.
ContWrapper<EOT>(Loop<Args...>().template findValue<eoContinue<EOT>>(args...), this), ContWrapper<EOT>(Loop<Args...>().template findValue<eoContinue<EOT>>(args...), this),
@ -40,7 +37,7 @@ paradiseo::smp::Island<EOAlgo,EOT>::Island(unsigned _popSize, eoInit<EOT>& _chro
algo(EOAlgo<EOT>(wrap_pp<eoContinue<EOT>>(this->ck,args)...)), algo(EOAlgo<EOT>(wrap_pp<eoContinue<EOT>>(this->ck,args)...)),
// With the PPE we look for the eval function in order to evaluate EOT to integrate // With the PPE we look for the eval function in order to evaluate EOT to integrate
eval(Loop<Args...>().template findValue<eoEvalFunc<EOT>>(args...)), eval(Loop<Args...>().template findValue<eoEvalFunc<EOT>>(args...)),
pop(_popSize, _chromInit), pop(_pop),
intPolicy(_intPolicy), intPolicy(_intPolicy),
migPolicy(_migPolicy), migPolicy(_migPolicy),
stopped(false), stopped(false),

View file

@ -34,8 +34,13 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <atomic> #include <atomic>
#include <type_traits>
#include <eoEvalFunc.h>
#include <eoSelect.h>
#include <eoAlgo.h>
#include <eoPop.h>
#include <eo>
#include <abstractIsland.h> #include <abstractIsland.h>
#include <islandModel.h> #include <islandModel.h>
#include <migPolicy.h> #include <migPolicy.h>
@ -68,7 +73,7 @@ public:
* @param args Parameters to construct the algorithm. * @param args Parameters to construct the algorithm.
*/ */
template<class... Args> template<class... Args>
Island(unsigned _popSize, eoInit<EOT>& _chromInit, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args); Island(eoPop<EOT>& pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args);
/** /**
* Start the island. * Start the island.
@ -118,7 +123,7 @@ protected:
virtual void receive(void); virtual void receive(void);
eoEvalFunc<EOT>& eval; eoEvalFunc<EOT>& eval;
eoPop<EOT> pop; eoPop<EOT>& pop;
EOAlgo<EOT> algo; EOAlgo<EOT> algo;
std::queue<eoPop<EOT>> listImigrants; std::queue<eoPop<EOT>> listImigrants;
IntPolicy<EOT>& intPolicy; IntPolicy<EOT>& intPolicy;

View file

@ -18,6 +18,7 @@ set (TEST_LIST
t-smpMW_eoSyncEasyPSO t-smpMW_eoSyncEasyPSO
t-smpIsland t-smpIsland
t-smpTopo t-smpTopo
t-smpMI_Homogeneous
) )
###################################################################################### ######################################################################################

View file

@ -9,11 +9,11 @@ using namespace std;
int main(void) int main(void)
{ {
typedef struct { typedef struct {
unsigned popSize = 1000; unsigned popSize = 10;
unsigned tSize = 2; unsigned tSize = 2;
double pCross = 0.8; double pCross = 0.8;
double pMut = 0.7; double pMut = 0.7;
unsigned maxGen = 10; unsigned maxGen = 100;
} Param; } Param;
Param param; Param param;
@ -62,8 +62,9 @@ int main(void)
// // Integration policy // // Integration policy
eoPlusReplacement<Indi> intPolicy; eoPlusReplacement<Indi> intPolicy;
Island<eoEasyEA,Indi> test(param.popSize, chromInit, intPolicy, migPolicy, genCont, plainEval, select, transform, replace); eoPop<Indi> pop(param.popSize, chromInit);
Island<eoEasyEA,Indi> test(pop, intPolicy, migPolicy, genCont, plainEval, select, transform, replace);
// Island 2 // Island 2
// // Emigration policy // // Emigration policy
@ -77,8 +78,9 @@ int main(void)
// // Integration policy // // Integration policy
eoPlusReplacement<Indi> intPolicy_2; eoPlusReplacement<Indi> intPolicy_2;
Island<eoEasyEA,Indi> test2(param.popSize, chromInit, intPolicy_2, migPolicy_2, genCont_2, plainEval, select, transform, replace); eoPop<Indi> pop2(param.popSize, chromInit);
Island<eoEasyEA,Indi> test2(pop2, intPolicy_2, migPolicy_2, genCont_2, plainEval, select, transform, replace);
// Topology // Topology
Topology<Complete> topo; Topology<Complete> topo;
@ -87,8 +89,11 @@ int main(void)
model.add(test); model.add(test);
model.add(test2); model.add(test2);
model(); //model();
test();
test2();
cout << test.getPop() << endl; cout << test.getPop() << endl;
cout << test2.getPop() << endl; cout << test2.getPop() << endl;
} }

View file

@ -0,0 +1,123 @@
#include <smp>
#include <eo>
#include "smpTestClass.h"
using namespace paradiseo::smp;
using namespace std;
int main(void)
{
typedef struct {
unsigned popSize = 100;
unsigned tSize = 2;
double pCross = 0.8;
double pMut = 0.7;
unsigned maxGen = 100;
} Param;
Param param;
rng.reseed(42);
loadInstances("t-data.dat", n, bkv, a, b);
// Evaluation function
IndiEvalFunc plainEval;
// Init a solution
IndiInit chromInit;
// Define selection
eoDetTournamentSelect<Indi> selectOne(param.tSize);
eoSelectPerc<Indi> select(selectOne);// by default rate==1
// Define operators for crossover and mutation
IndiXover Xover; // CROSSOVER
IndiSwapMutation mutationSwap; // MUTATION
// Encapsule in a tranform operator
eoSGATransform<Indi> transform(Xover, param.pCross, mutationSwap, param.pMut);
// Define replace operator
eoPlusReplacement<Indi> replace;
eoGenContinue<Indi> genCont(param.maxGen+100); // generation continuation
eoGenContinue<Indi> genCont_2(param.maxGen); // generation continuation
eoGenContinue<Indi> genCont_3(param.maxGen); // generation continuation
// Define population
eoPop<Indi> pop(param.popSize, chromInit);
try
{
// Island 1
// // Emigration policy
// // // Element 1
eoPeriodicContinue<Indi> criteria(5);
eoDetTournamentSelect<Indi> selectOne(20);
eoSelectNumber<Indi> who(selectOne, 3);
MigPolicy<Indi> migPolicy;
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
// // Integration policy
eoPlusReplacement<Indi> intPolicy;
eoPop<Indi> pop(param.popSize, chromInit);
Island<eoEasyEA,Indi> test(pop, intPolicy, migPolicy, genCont, plainEval, select, transform, replace);
// Island 2
// // Emigration policy
// // // Element 1
eoPeriodicContinue<Indi> criteria_2(5);
eoDetTournamentSelect<Indi> selectOne_2(25);
eoSelectNumber<Indi> who_2(selectOne_2, 5);
MigPolicy<Indi> migPolicy_2;
migPolicy_2.push_back(PolicyElement<Indi>(who_2, criteria_2));
// // Integration policy
eoPlusReplacement<Indi> intPolicy_2;
eoPop<Indi> pop2(30, chromInit);
Island<eoEasyEA,Indi> test2(pop2, intPolicy_2, migPolicy_2, genCont_2, plainEval, select, transform, replace);
// Island 3
// // Emigration policy
// // // Element 1
eoPeriodicContinue<Indi> criteria_3(10);
eoDetTournamentSelect<Indi> selectOne_3(15);
eoSelectNumber<Indi> who_3(selectOne_3, 1);
MigPolicy<Indi> migPolicy_3;
migPolicy.push_back(PolicyElement<Indi>(who_3, criteria_3));
// // Integration policy
eoPlusReplacement<Indi> intPolicy_3;
eoPop<Indi> pop3(30, chromInit);
Island<eoEasyEA,Indi> test3(pop3, intPolicy_3, migPolicy_3, genCont_3, plainEval, select, transform, replace);
// Topology
Topology<Complete> topo;
IslandModel<Indi> model(topo);
model.add(test);
model.add(test2);
model.add(test3);
model();
cout << test.getPop() << endl;
cout << test2.getPop() << endl;
cout << test3.getPop() << endl;
}
catch(exception& e)
{
cout << "Exception: " << e.what() << '\n';
}
return 0;
}