Work's start on Generic COSEARCH
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1609 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
d34328e5f6
commit
50850230ea
2 changed files with 706 additions and 0 deletions
318
contribution/branches/MOLS/COSEARCH/fspEA.cpp
Executable file
318
contribution/branches/MOLS/COSEARCH/fspEA.cpp
Executable file
|
|
@ -0,0 +1,318 @@
|
|||
//eo
|
||||
#include <eo>
|
||||
#include <eoSwapMutation.h>
|
||||
|
||||
//general
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <unistd.h>
|
||||
|
||||
// moeo
|
||||
#include <moeo>
|
||||
#include <do/make_continue_moeo.h>
|
||||
#include <do/make_checkpoint_moeo.h>
|
||||
|
||||
// fsp
|
||||
#include <fsp>
|
||||
|
||||
//peo
|
||||
#include <peo>
|
||||
#include <peoAsyncDataTransfer.h>
|
||||
#include <peoSyncDataTransfer.h>
|
||||
#include <core/star_topo.h>
|
||||
#include <peoParallelAlgorithmWrapper.h>
|
||||
#include <core/eoVector_mesg.h>
|
||||
|
||||
//DMLS
|
||||
|
||||
|
||||
#include <moeoTransfer.h>
|
||||
|
||||
void make_help(eoParser & _parser);
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try{
|
||||
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
eoState state; // to keep all things allocated
|
||||
|
||||
/*** number of objectives ***/
|
||||
fspObjectiveVectorTraits::nObj = 2;
|
||||
|
||||
/*** parameters ***/
|
||||
eoValueParam<uint32_t>& _seedParam = parser.createParam(uint32_t(0), "seed", "Random number seed", 'S');
|
||||
std::string _file = parser.createParam(std::string(), "file", "", '\0', "Representation", true).value();
|
||||
double _crossRate = parser.createParam((double) 0.05, "crossRate", "Rate for 2-PT crossover", 0, "Variation Operators").value();
|
||||
double _mutRate = parser.createParam((double) 1.0, "mutRate", "Rate for shift mutation", 0, "Variation Operators").value();
|
||||
unsigned int _popSize = parser.createParam((unsigned int)(100), "popSize", "Population Size", 'P', "Evolution Engine").value();
|
||||
std::string _strategy = parser.createParam(std::string(), "explorer", "OneOne - OneAll - AllOne - AllAll - OneFirst - AllFirst - OneND - AllND", '\0', "Evolution Engine", true).value();
|
||||
unsigned int _nbKick = parser.createParam((unsigned int)(10), "nbKick", "Number of kick", 'K', "Evolution Engine").value();
|
||||
|
||||
// seed
|
||||
if (_seedParam.value() == 0)
|
||||
_seedParam.value() = time(0);
|
||||
rng.reseed(_seedParam.value());
|
||||
|
||||
/*** the representation-dependent things ***/
|
||||
|
||||
// load data
|
||||
fspData data(_file);
|
||||
// size
|
||||
unsigned int size = data.getN(); // nb jobs
|
||||
// init
|
||||
fspInit init(size, 0);
|
||||
// eval
|
||||
fspEval simpleEval(data.getM(), data.getN(), data.getP(), data.getD());
|
||||
eoEvalFuncCounter<FSP> eval(simpleEval);
|
||||
// cross
|
||||
fspCross cross;
|
||||
// mut
|
||||
fspMut mut;
|
||||
// op
|
||||
eoSGAGenOp<FSP> op(cross, _crossRate, mut, _mutRate);
|
||||
|
||||
/*** the representation-independent things ***/
|
||||
|
||||
// move init
|
||||
fspMoveInit moveInit;
|
||||
// move next
|
||||
fspMoveNext moveNext;
|
||||
// move incr eval
|
||||
fspMoveIncrEval moveIncrEval(data.getM(), data.getN(), data.getP(), data.getD());
|
||||
|
||||
|
||||
bool multiply=true;
|
||||
moeoPopNeighborhoodExplorer<fspMove> * explorer;
|
||||
moeoUnvisitedSelect<FSP> * selector;
|
||||
if (_strategy == std::string("OneOne"))
|
||||
{
|
||||
selector = new moeoNumberUnvisitedSelect<FSP> (1);
|
||||
explorer = new moeoSimpleSubNeighborhoodExplorer<fspMove> (moveInit, moveNext, moveIncrEval, 1);
|
||||
}
|
||||
else if (_strategy == std::string("OneAll"))
|
||||
{
|
||||
selector = new moeoNumberUnvisitedSelect<FSP> (1);
|
||||
explorer = new moeoExhaustiveNeighborhoodExplorer<fspMove> (moveInit, moveNext, moveIncrEval);
|
||||
}
|
||||
else if (_strategy == std::string("AllOne"))
|
||||
{
|
||||
selector = new moeoExhaustiveUnvisitedSelect<FSP>;
|
||||
explorer = new moeoSimpleSubNeighborhoodExplorer<fspMove> (moveInit, moveNext, moveIncrEval, 1);
|
||||
multiply=false;
|
||||
}
|
||||
else if (_strategy == std::string("AllAll"))
|
||||
{
|
||||
selector = new moeoExhaustiveUnvisitedSelect<FSP>;
|
||||
explorer = new moeoExhaustiveNeighborhoodExplorer<fspMove> (moveInit, moveNext, moveIncrEval);
|
||||
}
|
||||
else if (_strategy == std::string("OneFirst"))
|
||||
{
|
||||
selector = new moeoNumberUnvisitedSelect<FSP> (1);
|
||||
explorer = new moeoFirstImprovingNeighborhoodExplorer<fspMove> (moveInit, moveNext, moveIncrEval);
|
||||
}
|
||||
else if (_strategy == std::string("AllFirst"))
|
||||
{
|
||||
selector = new moeoExhaustiveUnvisitedSelect<FSP>;
|
||||
explorer = new moeoFirstImprovingNeighborhoodExplorer<fspMove> (moveInit, moveNext, moveIncrEval);
|
||||
}
|
||||
else if (_strategy == std::string("OneND"))
|
||||
{
|
||||
selector = new moeoNumberUnvisitedSelect<FSP> (1);
|
||||
explorer = new moeoNoDesimprovingNeighborhoodExplorer<fspMove> (moveInit, moveNext, moveIncrEval);
|
||||
}
|
||||
else if (_strategy == std::string("AllND"))
|
||||
{
|
||||
selector = new moeoExhaustiveUnvisitedSelect<FSP>;
|
||||
explorer = new moeoNoDesimprovingNeighborhoodExplorer<fspMove> (moveInit, moveNext, moveIncrEval);
|
||||
multiply=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string stmp = std::string("Invalid explorer strategy: ") + _strategy;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
state.storeFunctor(selector);
|
||||
state.storeFunctor(explorer);
|
||||
|
||||
//peo :: init (argc, argv);
|
||||
|
||||
eoPop<FSP> popIBEA;
|
||||
eoPop<FSP> popLS;
|
||||
eoPop<FSP> popCentral;
|
||||
eoPop<FSP> popCentral2;
|
||||
popCentral.resize(0);
|
||||
popCentral2.resize(0);
|
||||
// initialization of the population
|
||||
popIBEA.append(_popSize, init);
|
||||
popLS.append(1, init);
|
||||
// definition of an unbounded archive
|
||||
moeoNewBoundedArchive<FSP> archCentral(100);
|
||||
moeoNewBoundedArchive<FSP> archCentral2(100);
|
||||
moeoNewBoundedArchive<FSP> archLS(100);
|
||||
moeoUnboundedArchive<FSP> archIBEA;
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<FSP> & stop = do_make_continue_moeo(parser, state, eval);
|
||||
|
||||
eoGenContinue<FSP> stop1(5000000);
|
||||
eoGenContinue<FSP> stop2(5000000);
|
||||
eoGenContinue<FSP> stop3(5000000);
|
||||
|
||||
// checkpointing
|
||||
eoCheckPoint<FSP> & checkpoint1 = do_make_checkpoint_moeo(parser, state, eval, stop1, popIBEA, archIBEA);
|
||||
eoCheckPoint<FSP> & checkpoint2 = do_make_checkpoint_moeo(parser, state, eval, stop2, popLS, archLS);
|
||||
eoCheckPoint<FSP> & checkpoint3 = do_make_checkpoint_moeo(parser, state, eval, stop3, popCentral, archCentral);
|
||||
|
||||
moeoArchiveObjectiveVectorSavingUpdater < FSP > * save_updater1 = new moeoArchiveObjectiveVectorSavingUpdater < FSP > (archIBEA, "archIBEA");
|
||||
state.storeFunctor(save_updater1);
|
||||
checkpoint1.add(*save_updater1);
|
||||
|
||||
moeoArchiveObjectiveVectorSavingUpdater < FSP > * save_updater2 = new moeoArchiveObjectiveVectorSavingUpdater < FSP > (archLS, "archLS");
|
||||
state.storeFunctor(save_updater2);
|
||||
checkpoint2.add(*save_updater2);
|
||||
|
||||
moeoArchiveObjectiveVectorSavingUpdater < FSP > * save_updater3 = new moeoArchiveObjectiveVectorSavingUpdater < FSP > (archCentral, "archCentral");
|
||||
state.storeFunctor(save_updater3);
|
||||
checkpoint3.add(*save_updater3);
|
||||
|
||||
// metric
|
||||
moeoAdditiveEpsilonBinaryMetric<fspObjectiveVector> metric;
|
||||
// algorithms
|
||||
moeoIBEA<FSP> algo1 (checkpoint1, eval, op, metric);
|
||||
//moeoSEEA<FSP> algo1 (checkpoint1, eval, op, arch1);
|
||||
moeoUnifiedDominanceBasedLS <fspMove> algo2(checkpoint2, eval, archLS, *explorer, *selector);
|
||||
|
||||
//moeoUnifiedDominanceBasedLS <tspMove> algo3(checkpoint3, eval, arch3, *explorer, *selector);
|
||||
//moeoSEEA<FSP> algo3 (checkpoint3, eval, op, arch3);
|
||||
//moeoSEEA<FSP> algo4 (checkpoint4, eval, op, arch4);
|
||||
//moeoIBEA<FSP> algo3 (checkpoint3, eval, op, metric);
|
||||
//moeoNSGAII<FSP> algo3 (checkpoint3, eval, op);
|
||||
|
||||
//PEO:initialisation
|
||||
|
||||
|
||||
|
||||
//Topolgy
|
||||
RingTopology ring1, ring2;
|
||||
StarTopology star;
|
||||
|
||||
|
||||
|
||||
|
||||
eoSwapMutation <FSP> swap;
|
||||
|
||||
|
||||
|
||||
CentralAggregation<FSP> test;
|
||||
IBEAAggregation<FSP> test2;
|
||||
LSAggregation<FSP> test3(swap, eval, _nbKick);
|
||||
ArchToArchAggregation<FSP> test4;
|
||||
|
||||
apply<FSP>(eval, popIBEA);
|
||||
popIBEA.sort();
|
||||
apply<FSP>(eval, popLS);
|
||||
popLS.sort();
|
||||
|
||||
|
||||
|
||||
/* peoSyncDataTransfer transfer1(archCentral, ring1, test);
|
||||
centralArchive<FSP> centre1(archCentral, popCentral, transfer1, checkpoint3);
|
||||
|
||||
|
||||
peoSyncDataTransfer transfer2(archCentral, ring2, test);
|
||||
centralArchive<FSP> centre2(archCentral, popCentral, transfer2, checkpoint3);
|
||||
|
||||
|
||||
|
||||
|
||||
peoSyncDataTransfer transfer3(popIBEA, ring1, test2);
|
||||
eoGenContinue <FSP> cont2(500);
|
||||
|
||||
gestionTransfer<FSP> gest2(cont2, transfer3, archIBEA);
|
||||
//centralArchive centre1(arch1, pop1, transfer1);
|
||||
checkpoint1.add(gest2);
|
||||
|
||||
|
||||
|
||||
|
||||
peoSyncDataTransfer transfer4(archLS, ring2, test3);
|
||||
eoAmeliorationContinue <FSP> cont(archLS, 1, false);
|
||||
//eoGenContinue <FSP> cont(10000);
|
||||
gestionTransfer2<FSP> gest(cont, transfer4, archLS);
|
||||
checkpoint2.add(gest);*/
|
||||
|
||||
|
||||
// std::vector<peoSyncDataTransfer> vect;
|
||||
|
||||
|
||||
// initDebugging();
|
||||
//setDebugMode(true);
|
||||
|
||||
testPEO<FSP> hop(argc, argv, algo1, algo2, popIBEA, popLS, archCentral, test, test, test2, test3, checkpoint1, checkpoint2, checkpoint3);
|
||||
|
||||
|
||||
hop();
|
||||
|
||||
|
||||
|
||||
// Start the parallel EA
|
||||
/*eoPop<FSP> dummyPop;
|
||||
dummyPop.resize(0);
|
||||
|
||||
eoPop<FSP> dummyPop2;
|
||||
dummyPop2.resize(0);*/
|
||||
|
||||
//Wrapp algorithms
|
||||
|
||||
/* peoParallelAlgorithmWrapper parallelEA_1(centre1, dummyPop);
|
||||
transfer1.setOwner( parallelEA_1 );
|
||||
|
||||
|
||||
peoParallelAlgorithmWrapper parallelEA_2(algo1, popIBEA);
|
||||
transfer3.setOwner( parallelEA_2 );
|
||||
|
||||
|
||||
peoParallelAlgorithmWrapper parallelEA_3(centre2, dummyPop2);
|
||||
transfer2.setOwner( parallelEA_3 );
|
||||
|
||||
|
||||
peoParallelAlgorithmWrapper parallelEA_4(algo2, popLS);
|
||||
transfer4.setOwner( parallelEA_4 );*/
|
||||
|
||||
|
||||
/* if (getNodeRank()==1)
|
||||
{
|
||||
|
||||
cout << "Initial Population IBEA\n" << popIBEA << endl;
|
||||
}
|
||||
|
||||
if (getNodeRank()==2)
|
||||
{
|
||||
|
||||
cout << "Initial Population LS\n" << popLS << endl;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//run
|
||||
//peo :: run( );
|
||||
//peo :: finalize( );
|
||||
//endDebugging();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch (exception& e){
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
388
contribution/branches/MOLS/COSEARCH/moeoTransfer.h
Normal file
388
contribution/branches/MOLS/COSEARCH/moeoTransfer.h
Normal file
|
|
@ -0,0 +1,388 @@
|
|||
//eo
|
||||
#include <eo>
|
||||
|
||||
// moeo
|
||||
#include <moeo>
|
||||
|
||||
//general
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
//peo
|
||||
#include <peo>
|
||||
#include <peoAsyncDataTransfer.h>
|
||||
#include <peoSyncDataTransfer.h>
|
||||
|
||||
#include <dmls.h>
|
||||
|
||||
|
||||
template <class A1, class A2, class R>
|
||||
class generalAggregation: public eoBF<A1, A2, R>{};
|
||||
|
||||
template <class EOT, class A, class R>
|
||||
class AbstractEntityToPopAggregation: public generalAggregation<eoPop<EOT>&, A, R>{};
|
||||
|
||||
template <class EOT, class A, class R>
|
||||
class AbstractEntityToArchiveAggregation: public generalAggregation<moeoArchive<EOT>&, A, R>{};
|
||||
|
||||
template <class EOT>
|
||||
class PopToPopAggregation: public AbstractEntityToPopAggregation<EOT, eoPop<EOT>&, void>{};
|
||||
|
||||
template <class EOT>
|
||||
class ArchiveToPopAggregation: public AbstractEntityToPopAggregation<EOT, moeoArchive<EOT>&, void>{};
|
||||
|
||||
template <class EOT>
|
||||
class PopToArchiveAggregation: public AbstractEntityToArchiveAggregation<EOT, eoPop<EOT>&, void>{};
|
||||
|
||||
template <class EOT>
|
||||
class ArchiveToArchiveAggregation: public AbstractEntityToArchiveAggregation<EOT, moeoArchive<EOT>&, void>{};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
template <class EOT>
|
||||
class gestionTransfer: public eoUpdater{
|
||||
|
||||
public:
|
||||
gestionTransfer(eoGenContinue < EOT > & _continuator,
|
||||
peoDataTransfer & _asyncDataTransfer,
|
||||
moeoArchive<EOT>& _archive):continuator(_continuator), asyncDataTransfer(_asyncDataTransfer), archive(_archive){}
|
||||
|
||||
void operator()(){
|
||||
if(!continuator(archive)){
|
||||
asyncDataTransfer();
|
||||
continuator.totalGenerations(continuator.totalGenerations());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
eoGenContinue < EOT > & continuator;
|
||||
peoDataTransfer& asyncDataTransfer;
|
||||
moeoArchive<EOT>& archive;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
template <class EOT>
|
||||
class gestionTransfer2: public eoUpdater{
|
||||
|
||||
public:
|
||||
gestionTransfer2(eoContinue < EOT > & _continuator,
|
||||
peoSyncDataTransfer & _asyncDataTransfer,
|
||||
moeoArchive<EOT>& _archive):continuator(_continuator), asyncDataTransfer(_asyncDataTransfer), archive(_archive){}
|
||||
|
||||
void operator()(){
|
||||
if(!continuator(archive)){
|
||||
asyncDataTransfer();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
eoContinue < EOT > & continuator;
|
||||
peoSyncDataTransfer& asyncDataTransfer;
|
||||
moeoArchive<EOT>& archive;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
/*template <class EOT>
|
||||
class IBEAAggregationRnd: public ArchiveToPopAggregation<EOT>{
|
||||
|
||||
public:
|
||||
void operator()(eoPop< EOT >& _pop, moeoArchive< EOT >& _archive) {
|
||||
UF_random_generator<unsigned int> rndGen;
|
||||
std::vector<unsigned int> tab;
|
||||
unsigned int resizeValue;
|
||||
unsigned int popCorrectSize= _pop.size();
|
||||
|
||||
if (_pop.size() - _archive.size()>0){
|
||||
resizeValue=_pop.size() - _archive.size();
|
||||
_pop.shuffle();
|
||||
}
|
||||
else
|
||||
resizeValue=0;
|
||||
|
||||
for(unsigned int i=0; i<_archive.size(); i++)
|
||||
tab.push_back(i);
|
||||
std::random_shuffle(tab.begin(), tab.end(), rndGen);
|
||||
|
||||
_pop.resize(resizeValue);
|
||||
|
||||
for (unsigned int i=0; i<(popCorrectSize-resizeValue); i++)
|
||||
{
|
||||
_pop.push_back(_archive[tab[i]]);
|
||||
}
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
_pop[i].fitness(0.0);
|
||||
_pop[i].diversity(0.0);
|
||||
}
|
||||
}
|
||||
};*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
template <class EOT>
|
||||
class IBEAAggregation: public ArchiveToPopAggregation<EOT>{
|
||||
public:
|
||||
void operator()(eoPop< EOT >& _pop, moeoArchive< EOT >& _archive) {
|
||||
unsigned int popSize= _pop.size();
|
||||
_pop.reserve(popSize + _archive.size());
|
||||
for (unsigned int i=0; i<_archive.size(); i++)
|
||||
{
|
||||
_pop.push_back(_archive[i]);
|
||||
_pop[i+popSize].fitness(0.0);
|
||||
//_pop[i].diversity(0.0);
|
||||
}
|
||||
diversityAssignment(_pop);
|
||||
std::sort(_pop.begin(), _pop.end(), cmp);
|
||||
_pop.resize(popSize);
|
||||
}
|
||||
|
||||
private:
|
||||
moeoCrowdingDiversityAssignment<EOT> diversityAssignment;
|
||||
moeoDiversityThenFitnessComparator<EOT> cmp;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
/*template <class EOT>
|
||||
class IBEAAggregationQuiMarchePas{
|
||||
public:
|
||||
void operator()(eoPop< EOT >& _pop, moeoArchive< EOT >& _archive) {
|
||||
UF_random_generator<unsigned int> rndGen;
|
||||
std::vector<unsigned int> tab;
|
||||
unsigned int resizeValue;
|
||||
unsigned int popCorrectSize= _pop.size();
|
||||
|
||||
|
||||
if (_pop.size() <= _archive.size())
|
||||
_pop.resize(0);
|
||||
|
||||
for (unsigned int i=0; i<_archive.size(); i++)
|
||||
{
|
||||
_pop.push_back(_archive[i]);
|
||||
_pop[i].fitness(0.0);
|
||||
_pop[i].diversity(0.0);
|
||||
}
|
||||
|
||||
}
|
||||
};*/
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
template <class EOT>
|
||||
class LSAggregation: public ArchiveToArchiveAggregation<EOT>{
|
||||
public:
|
||||
|
||||
LSAggregation(eoMonOp <EOT> & _op, eoEvalFunc<EOT>& _eval, unsigned int _nbKick): ArchiveToArchiveAggregation<EOT>(),op(_op), eval(_eval), nbKick(_nbKick){}
|
||||
|
||||
void operator()(moeoArchive< EOT >& _archive1, moeoArchive <EOT >& _archive2) {
|
||||
unsigned int archSize=_archive2.size();
|
||||
if(archSize>0){
|
||||
_archive1.resize(0);
|
||||
_archive1.push_back(_archive2[rng.random(archSize)]);
|
||||
// std::cout << "kick : " << nbKick << std::endl;
|
||||
//si la solution n'a pas encore été visité
|
||||
if(_archive1[0].flag()==1){
|
||||
std::cout << "kick pour du vrai" << std::endl;
|
||||
//on la kick
|
||||
for(unsigned int i=0; i<nbKick; i++){
|
||||
//std::cout << _archive1[0] << std::endl;
|
||||
op(_archive1[0]);
|
||||
}
|
||||
eval(_archive1[0]);
|
||||
_archive1[0].flag(0);
|
||||
}
|
||||
for (unsigned int i=0; i<_archive1.size(); i++)
|
||||
{
|
||||
|
||||
_archive1[i].fitness(0.0);
|
||||
_archive1[i].diversity(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
eoMonOp<EOT> & op;
|
||||
eoEvalFunc<EOT> & eval;
|
||||
unsigned int nbKick;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//Aggregation pour archiver une pop
|
||||
template <class EOT>
|
||||
class CentralAggregation: public PopToArchiveAggregation<EOT>{
|
||||
public:
|
||||
void operator()(moeoArchive< EOT >& _archive, eoPop< EOT >& _pop) {
|
||||
_archive(_pop);
|
||||
}
|
||||
};
|
||||
|
||||
//aggregation pour archiver une archive
|
||||
template <class EOT>
|
||||
class ArchToArchAggregation{
|
||||
public:
|
||||
void operator()(moeoArchive< EOT >& _archive1, moeoArchive< EOT >& _archive2) {
|
||||
_archive1(_archive2);
|
||||
}
|
||||
};
|
||||
|
||||
template <class EOT>
|
||||
class gestArchive{
|
||||
|
||||
public:
|
||||
gestArchive(moeoArchive <EOT>& _archive,
|
||||
eoPop <EOT>& _pop,
|
||||
peoSyncDataTransfer & _syncDataTransfer,
|
||||
eoContinue <EOT>& _cont):
|
||||
archive(_archive), pop(_pop), syncDataTransfer(_syncDataTransfer), cont(_cont){}
|
||||
|
||||
void operator()(eoPop <EOT>& population) {
|
||||
while(true){
|
||||
// pop.resize(0);
|
||||
//for(unsigned int i=0; i<archive.size(); i++)
|
||||
// pop.push_back(archive[i]);
|
||||
syncDataTransfer();//appel pour faire l'echange
|
||||
// archive(pop);
|
||||
// pop.resize(0);
|
||||
// for(unsigned int i=0; i<archive.size(); i++)
|
||||
// pop.push_back(archive[i]);
|
||||
cont(archive);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
moeoArchive <EOT>& archive;
|
||||
eoPop <EOT>& pop;
|
||||
peoSyncDataTransfer& syncDataTransfer;
|
||||
eoContinue <EOT>& cont;
|
||||
};
|
||||
|
||||
|
||||
template <class EOT>
|
||||
class testPEO{
|
||||
|
||||
public:
|
||||
testPEO(int _argc,
|
||||
char** _argv,
|
||||
moeoPopAlgo<EOT> & _algo1,
|
||||
moeoPopAlgo<EOT> & _algo2,
|
||||
eoPop<EOT> & _pop1,
|
||||
eoPop<EOT> & _pop2,
|
||||
moeoNewBoundedArchive<EOT> & _centralArchive,
|
||||
AbstractEntityToArchiveAggregation<EOT, eoPop<EOT> &, void>& _algo1ToArchive,
|
||||
AbstractEntityToArchiveAggregation<EOT, eoPop<EOT> &, void>& _algo2ToArchive,
|
||||
generalAggregation <eoPop<EOT> &, moeoArchive<EOT> &, void>& _archiveToAlgo1,
|
||||
generalAggregation <moeoArchive<EOT> &, moeoArchive<EOT> &, void>& _archiveToAlgo2,
|
||||
eoCheckPoint<EOT> & _checkAlgo1,
|
||||
eoCheckPoint<EOT> & _checkAlgo2,
|
||||
eoCheckPoint<EOT> & _checkArchive):
|
||||
argc(_argc),
|
||||
argv(_argv),
|
||||
algo1(_algo1),
|
||||
algo2(_algo2),
|
||||
pop1(_pop1),
|
||||
pop2(_pop2),
|
||||
centralArchive(_centralArchive),
|
||||
algo1ToArchive(_algo1ToArchive),
|
||||
algo2ToArchive(_algo2ToArchive),
|
||||
archiveToAlgo1(_archiveToAlgo1),
|
||||
archiveToAlgo2(_archiveToAlgo2),
|
||||
checkAlgo1(_checkAlgo1),
|
||||
checkAlgo2(_checkAlgo2),
|
||||
checkArchive(_checkArchive){}
|
||||
|
||||
void operator()(){
|
||||
|
||||
//PEO Initialization
|
||||
peo :: init (argc, argv);
|
||||
|
||||
//Two RingTopolgy
|
||||
RingTopology ring1, ring2;
|
||||
|
||||
|
||||
//DataTransfer for the fisrt ring
|
||||
peoSyncDataTransfer transfer1(centralArchive, ring1, algo1ToArchive);
|
||||
peoSyncDataTransfer transfer2(pop1, ring1, archiveToAlgo1);
|
||||
|
||||
//DataTransfer for the second ring
|
||||
peoSyncDataTransfer transfer3(centralArchive, ring2, algo2ToArchive);
|
||||
peoSyncDataTransfer transfer4(pop2, ring2, archiveToAlgo2);
|
||||
|
||||
//Transfer Algo1 -> archiveCentral (Ring1)
|
||||
gestArchive<EOT> toCenter1(centralArchive, pop1, transfer1, checkArchive);
|
||||
|
||||
//Transfer archiveCentral -> Algo1 (Ring1)
|
||||
eoGenContinue <EOT> genContinuator1(100);
|
||||
gestionTransfer<EOT> exitCenter1(genContinuator1, transfer2, centralArchive);
|
||||
checkAlgo1.add(exitCenter1);
|
||||
|
||||
//Transfer Algo2 -> archiveCentral (Ring2)
|
||||
gestArchive<EOT> toCenter2(centralArchive, pop2, transfer3, checkArchive);
|
||||
|
||||
//Transfer archiveCentral -> Algo2 (Ring2)
|
||||
eoGenContinue <EOT> genContinuator2(200);
|
||||
gestionTransfer<EOT> exitCenter2(genContinuator2, transfer4, centralArchive);
|
||||
checkAlgo2.add(exitCenter2);
|
||||
|
||||
//dummyPop
|
||||
eoPop<EOT> dummyPop;
|
||||
|
||||
//Wrapping of algotithm
|
||||
peoParallelAlgorithmWrapper parallelEA_1(toCenter1, dummyPop);
|
||||
transfer1.setOwner( parallelEA_1 );
|
||||
|
||||
|
||||
peoParallelAlgorithmWrapper parallelEA_2(algo1, pop1);
|
||||
transfer2.setOwner( parallelEA_2 );
|
||||
|
||||
|
||||
peoParallelAlgorithmWrapper parallelEA_3(toCenter2, dummyPop);
|
||||
transfer3.setOwner( parallelEA_3 );
|
||||
|
||||
|
||||
peoParallelAlgorithmWrapper parallelEA_4(algo2, pop2);
|
||||
transfer4.setOwner( parallelEA_4 );
|
||||
|
||||
|
||||
//run
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
endDebugging();
|
||||
}
|
||||
|
||||
private:
|
||||
int argc;
|
||||
char** argv;
|
||||
moeoPopAlgo<EOT> & algo1;
|
||||
moeoPopAlgo<EOT> & algo2;
|
||||
eoPop<EOT> & pop1;
|
||||
eoPop<EOT> & pop2;
|
||||
moeoNewBoundedArchive <EOT> & centralArchive;
|
||||
AbstractEntityToArchiveAggregation<EOT, eoPop<EOT> &, void> & algo1ToArchive;
|
||||
AbstractEntityToArchiveAggregation<EOT, eoPop<EOT> &, void> & algo2ToArchive;
|
||||
generalAggregation <eoPop<EOT> &, moeoArchive<EOT> &, void> & archiveToAlgo1;
|
||||
generalAggregation <moeoArchive<EOT> &, moeoArchive<EOT> &, void> & archiveToAlgo2;
|
||||
eoCheckPoint<EOT> & checkAlgo1;
|
||||
eoCheckPoint<EOT> & checkAlgo2;
|
||||
eoCheckPoint<EOT> & checkArchive;
|
||||
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue