Wrap model in order to create homogeneous model easily.
This commit is contained in:
parent
f8d2d1cfa5
commit
6974bc7bbe
10 changed files with 252 additions and 20 deletions
|
|
@ -69,6 +69,24 @@ public:
|
|||
return leftAssociation;
|
||||
}
|
||||
|
||||
void removeFromRight(const A& a)
|
||||
{
|
||||
for(auto& it : leftAssociation)
|
||||
if(it->second == a)
|
||||
leftAssociation.erase(it);
|
||||
|
||||
rightAssociation.erase(a);
|
||||
}
|
||||
|
||||
void removeFromLeft(const B& b)
|
||||
{
|
||||
for(auto& it : rightAssociation)
|
||||
if(it->second == b)
|
||||
rightAssociation.erase(it);
|
||||
|
||||
leftAssociation.erase(b);
|
||||
}
|
||||
|
||||
unsigned size() const
|
||||
{
|
||||
return leftAssociation.size();
|
||||
|
|
|
|||
58
smp/src/homogeneousModel.cpp
Normal file
58
smp/src/homogeneousModel.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
<homogeneousModel.cpp>
|
||||
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
|
||||
*/
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
template<class... IslandInit>
|
||||
paradiseo::smp::HomogeneousIslandModel<EOAlgo, EOT>::HomogeneousIslandModel(unsigned _islandNumber, AbstractTopology& _topo, unsigned _popSize, eoInit<EOT> &_chromInit, IslandInit... args) :
|
||||
model(_topo)
|
||||
{
|
||||
pops.resize(_islandNumber);
|
||||
islands.resize(_islandNumber);
|
||||
for(unsigned i = 0; i < _islandNumber; i++)
|
||||
{
|
||||
pops[i] = eoPop<EOT>(_popSize, _chromInit);
|
||||
islands[i] = new Island<EOAlgo, EOT>(pops[i], args...);
|
||||
model.add(*islands[i]);
|
||||
}
|
||||
|
||||
model();
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
paradiseo::smp::HomogeneousIslandModel<EOAlgo, EOT>::~HomogeneousIslandModel()
|
||||
{
|
||||
for(auto& island : islands)
|
||||
delete island;
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
std::vector<eoPop<EOT>>& paradiseo::smp::HomogeneousIslandModel<EOAlgo, EOT>::getPop()
|
||||
{
|
||||
return pops;
|
||||
}
|
||||
72
smp/src/homogeneousModel.h
Normal file
72
smp/src/homogeneousModel.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
<homogeneousModel.h>
|
||||
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
|
||||
*/
|
||||
|
||||
#ifndef HOMOGENEOUS_ISLAND_MODEL_H_
|
||||
#define HOMOGENEOUS_ISLAND_MODEL_H_
|
||||
|
||||
#include <queue>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include <bimap.h>
|
||||
#include <abstractIsland.h>
|
||||
#include <island.h>
|
||||
#include <topology/topology.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
class HomogeneousIslandModel
|
||||
{
|
||||
public:
|
||||
template<class... IslandInit>
|
||||
HomogeneousIslandModel(unsigned _islandNumber, AbstractTopology& _topo, unsigned _popSize, eoInit<EOT> &_chromInit, IslandInit... args);
|
||||
|
||||
~HomogeneousIslandModel();
|
||||
|
||||
std::vector<eoPop<EOT>>& getPop();
|
||||
|
||||
protected:
|
||||
IslandModel<EOT> model;
|
||||
std::vector<Island<EOAlgo,EOT>*> islands;
|
||||
std::vector<eoPop<EOT>> pops;
|
||||
};
|
||||
|
||||
#include <homogeneousModel.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -77,7 +77,7 @@ void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::setModel(IslandModel<bEOT>* _model
|
|||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
eoPop<EOT>& paradiseo::smp::Island<EOAlgo,EOT,bEOT>::getPop()
|
||||
eoPop<EOT>& paradiseo::smp::Island<EOAlgo,EOT,bEOT>::getPop() const
|
||||
{
|
||||
return pop;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public:
|
|||
* Return a reference to the island population.
|
||||
* @return Reference to the island population
|
||||
*/
|
||||
eoPop<EOT>& getPop();
|
||||
eoPop<EOT>& getPop() const;
|
||||
|
||||
/**
|
||||
* Check if there is population to receive or to migrate
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ template<class EOT>
|
|||
class IslandModel
|
||||
{
|
||||
public:
|
||||
IslandModel(AbstractTopology& topo);
|
||||
IslandModel(AbstractTopology& _topo);
|
||||
|
||||
/**
|
||||
* Add an island to the model.
|
||||
|
|
|
|||
40
smp/src/notifier.cpp
Normal file
40
smp/src/notifier.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
<notifier.cpp>
|
||||
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
|
||||
*/
|
||||
|
||||
#include <notifier.h>
|
||||
|
||||
paradiseo::smp::Notifier::Notifier(std::function<void(void)> _task) :
|
||||
task(_task)
|
||||
{}
|
||||
|
||||
void paradiseo::smp::Notifier::operator()()
|
||||
{
|
||||
task();
|
||||
}
|
||||
|
||||
60
smp/src/notifier.h
Normal file
60
smp/src/notifier.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
<notifier.h>
|
||||
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
|
||||
*/
|
||||
|
||||
#ifndef NOTIFIER_H_
|
||||
#define NOTIFIER_H_
|
||||
|
||||
#include <eo>
|
||||
#include <functional>
|
||||
|
||||
/** Notifier: The notifier will perform the binded task each generation.
|
||||
|
||||
*/
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
class Notifier : public eoUpdater
|
||||
{
|
||||
public :
|
||||
Notifier(std::function<void(void)> _task);
|
||||
|
||||
virtual void operator()();
|
||||
|
||||
protected :
|
||||
std::function<void(void)> task;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -33,6 +33,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#include <MWModel.h>
|
||||
#include <scheduler.h>
|
||||
#include <islandModel.h>
|
||||
#include <homogeneousModel.h>
|
||||
#include <island.h>
|
||||
#include <abstractIsland.h>
|
||||
#include <migPolicy.h>
|
||||
|
|
|
|||
|
|
@ -6,19 +6,6 @@
|
|||
using namespace paradiseo::smp;
|
||||
using namespace std;
|
||||
|
||||
void changeTopo(IslandModel<Indi>& _model, AbstractTopology& _topo)
|
||||
{
|
||||
static bool first = false;
|
||||
// Change topology after 1s of computation
|
||||
std::chrono::milliseconds dura(1000);
|
||||
std::this_thread::sleep_for( dura );
|
||||
if(!first)
|
||||
{
|
||||
_model.setTopology(_topo);
|
||||
first = !first;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Defining parameters
|
||||
|
|
@ -63,10 +50,6 @@ int main(void)
|
|||
eoDetTournamentSelect<Indi> selectOne1(20);
|
||||
eoSelectNumber<Indi> who(selectOne1, 3);
|
||||
|
||||
Topology<Ring> topo2;
|
||||
//std::function<void(void)> task = std::bind(changeTopo, model, topo2);
|
||||
//Notifier topoChanger(task);
|
||||
|
||||
MigPolicy<Indi> migPolicy;
|
||||
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue