Mecanism to isolate stopped island in topology
This commit is contained in:
parent
56a72c2ff1
commit
cf93d6aeb4
5 changed files with 32 additions and 37 deletions
|
|
@ -57,13 +57,6 @@ public:
|
|||
{
|
||||
rightAssociation[a] = b;
|
||||
leftAssociation[b] = a;
|
||||
|
||||
std::cout << "DUMP" << std::endl;
|
||||
for(auto i : rightAssociation)
|
||||
std::cout << i.first << "------" << i.second << std::endl;
|
||||
for(auto i : leftAssociation)
|
||||
std::cout << i.first << "------" << i.second << std::endl;
|
||||
std::cout << "END DUMP" << std::endl;
|
||||
}
|
||||
|
||||
std::map<A,B> getRight() const
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ paradiseo::smp::Island<EOAlgo,EOT>::Island(unsigned _popSize, eoInit<EOT>& _chro
|
|||
pop(_popSize, _chromInit),
|
||||
intPolicy(_intPolicy),
|
||||
migPolicy(_migPolicy),
|
||||
stopped(false)
|
||||
stopped(false),
|
||||
model(nullptr)
|
||||
{
|
||||
// Check in compile time the inheritance thanks to type_trait.
|
||||
static_assert(std::is_base_of<eoAlgo<EOT>,EOAlgo<EOT>>::value, "Algorithm must inherit from eoAlgo<EOT>");
|
||||
|
|
@ -58,6 +59,7 @@ void paradiseo::smp::Island<EOAlgo,EOT>::operator()()
|
|||
for(auto& message : sentMessages)
|
||||
message.join();
|
||||
stopped = true;
|
||||
//std::cout << "Fin de l'île " << this << std::endl;
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
|
|
@ -96,39 +98,37 @@ bool paradiseo::smp::Island<EOAlgo,EOT>::isStopped(void) const
|
|||
template<template <class> class EOAlgo, class EOT>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT>::send(eoSelect<EOT>& _select)
|
||||
{
|
||||
//std::cout << "Ile lance la migration" << std::endl;
|
||||
eoPop<EOT> migPop;
|
||||
_select(pop, migPop);
|
||||
//std::cout << " La population migrante est :" << std::endl << migPop << std::endl;
|
||||
|
||||
// Delete delivered messages
|
||||
for(auto it = sentMessages.begin(); it != sentMessages.end(); it++)
|
||||
if(!it->joinable())
|
||||
sentMessages.erase(it);
|
||||
|
||||
sentMessages.push_back(std::thread(&IslandModel<EOT>::update, model, migPop, this));
|
||||
|
||||
if(model != nullptr)
|
||||
{
|
||||
//std::cout << "Ile lance la migration" << std::endl;
|
||||
eoPop<EOT> migPop;
|
||||
_select(pop, migPop);
|
||||
//std::cout << " La population migrante est :" << std::endl << migPop << std::endl;
|
||||
|
||||
// Delete delivered messages
|
||||
for(auto it = sentMessages.begin(); it != sentMessages.end(); it++)
|
||||
if(!it->joinable())
|
||||
sentMessages.erase(it);
|
||||
|
||||
sentMessages.push_back(std::thread(&IslandModel<EOT>::update, model, migPop, this));
|
||||
}
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT>::receive(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
if(!listImigrants.empty()) {
|
||||
std::cout << "______________________________________________" << std::endl;
|
||||
std::cout << "Ile : " << this << std::endl;
|
||||
std::cout << "Pop avant : " << std::endl << pop << std::endl;
|
||||
while (!listImigrants.empty())
|
||||
{
|
||||
|
||||
eoPop<EOT> offspring = listImigrants.front();
|
||||
|
||||
// Evaluate objects to integrate
|
||||
std::cout << "Evaluation des individus : " << std::endl;
|
||||
//std::cout << "Evaluation des individus : " << std::endl;
|
||||
for(auto& indi : offspring)
|
||||
{
|
||||
eval(indi);
|
||||
std::cout << indi << std::endl;
|
||||
//std::cout << indi << std::endl;
|
||||
}
|
||||
//std::cout << "Ile " << this << " recoit : " << std::endl;
|
||||
//std::cout << offspring << std::endl;
|
||||
|
|
@ -137,9 +137,6 @@ void paradiseo::smp::Island<EOAlgo,EOT>::receive(void)
|
|||
listImigrants.pop();
|
||||
|
||||
}
|
||||
std::cout << "Pop après : " << std::endl << pop << std::endl;
|
||||
std::cout << "______________________________________________" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
|
|
|
|||
|
|
@ -117,7 +117,6 @@ protected:
|
|||
*/
|
||||
virtual void receive(void);
|
||||
|
||||
IslandModel<EOT>* model;
|
||||
eoEvalFunc<EOT>& eval;
|
||||
eoPop<EOT> pop;
|
||||
EOAlgo<EOT> algo;
|
||||
|
|
@ -126,7 +125,7 @@ protected:
|
|||
MigPolicy<EOT>& migPolicy;
|
||||
std::atomic<bool> stopped;
|
||||
std::vector<std::thread> sentMessages;
|
||||
|
||||
IslandModel<EOT>* model;
|
||||
};
|
||||
|
||||
#include <island.cpp>
|
||||
|
|
|
|||
|
|
@ -64,9 +64,14 @@ void paradiseo::smp::IslandModel<EOT>::operator()()
|
|||
// Count working islands
|
||||
workingThread = islands.size();
|
||||
for(auto& it : islands)
|
||||
{
|
||||
// If an island is stopped we need to isolate its node in the topology
|
||||
if(it->isStopped())
|
||||
{
|
||||
workingThread--;
|
||||
|
||||
topo.isolateNode(table.getLeft()[it]);
|
||||
}
|
||||
}
|
||||
// Check reception
|
||||
send();
|
||||
|
||||
|
|
@ -95,14 +100,14 @@ void paradiseo::smp::IslandModel<EOT>::send(void)
|
|||
std::lock_guard<std::mutex> lock(m);
|
||||
while (!listEmigrants.empty())
|
||||
{
|
||||
std::cout << "Le mediateur va envoyer de " << listEmigrants.front().second << " qui est " << table.getLeft()[listEmigrants.front().second] << std::endl;
|
||||
//std::cout << "Le mediateur va envoyer de " << listEmigrants.front().second << " qui est " << table.getLeft()[listEmigrants.front().second] << std::endl;
|
||||
|
||||
unsigned id = table.getLeft()[listEmigrants.front().second];
|
||||
std::vector<unsigned> neighbors = topo.getIdNeighbors(id);
|
||||
eoPop<EOT> migPop = listEmigrants.front().first;
|
||||
for (unsigned neighbor : neighbors)
|
||||
{
|
||||
std::cout << "On envoie à " << neighbor << std::endl;
|
||||
//std::cout << "On envoie à " << neighbor << std::endl;
|
||||
sentMessages.push_back(std::thread(&AIsland<EOT>::update, table.getRight()[neighbor], migPop));
|
||||
}
|
||||
listEmigrants.pop();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue