Add islandNotifier to allow the mig and int policy to be checked in the island. The islandNotifier is added to the algorithm continuator and will make the island perform a binded task. In the case of island, the task is to check policies.
This commit is contained in:
parent
477dbe49a9
commit
cf561b537a
14 changed files with 498 additions and 93 deletions
71
smp/src/abstractIsland.h
Normal file
71
smp/src/abstractIsland.h
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
<abstractIsland.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 ABS_ISLAND_H_
|
||||||
|
#define ABS_ISLAND_H_
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
|
#include <migPolicy.h>
|
||||||
|
|
||||||
|
namespace paradiseo
|
||||||
|
{
|
||||||
|
namespace smp
|
||||||
|
{
|
||||||
|
|
||||||
|
/** AbstractIsland: An abstract island.
|
||||||
|
|
||||||
|
@see smp::Island
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class EOT>
|
||||||
|
class AIsland
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Send population to mediator
|
||||||
|
* @param _select Method to select EOT to send
|
||||||
|
*/
|
||||||
|
virtual void send(eoSelect<EOT>& _select) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there is population to receive
|
||||||
|
*/
|
||||||
|
virtual void receive(void) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there is population to receive or to emigrate
|
||||||
|
*/
|
||||||
|
virtual void check(void) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
36
smp/src/contWrapper.cpp
Normal file
36
smp/src/contWrapper.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
<contWrapper.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<class EOT>
|
||||||
|
paradiseo::smp::ContWrapper<EOT>::ContWrapper(eoContinue<EOT>& _cont, AIsland<EOT>* island) :
|
||||||
|
ck(_cont),
|
||||||
|
islandNotifier(island, &AIsland<EOT>::check)
|
||||||
|
{
|
||||||
|
ck.add(islandNotifier);
|
||||||
|
}
|
||||||
|
|
@ -36,26 +36,36 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <migPolicy.h>
|
#include <migPolicy.h>
|
||||||
|
#include <islandNotifier.h>
|
||||||
|
|
||||||
namespace paradiseo
|
namespace paradiseo
|
||||||
{
|
{
|
||||||
namespace smp
|
namespace smp
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** ContWrapper: Utility class to wrap the algorithm continuators with island notifier.
|
||||||
|
|
||||||
|
Utility class to wrap the algorithm continuators with island notifier during the island construction.
|
||||||
|
|
||||||
|
*/
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
class ContWrapper
|
class ContWrapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ContWrapper(eoContinue<EOT>& _cont, Policy<EOT>& _policy) :
|
/**
|
||||||
ck(_cont)
|
* Constructor
|
||||||
{
|
* @param _cont Original continuators
|
||||||
ck.add(_policy);
|
* @param _policy Policy to wrap with continuators
|
||||||
}
|
*/
|
||||||
|
ContWrapper(eoContinue<EOT>& _cont, AIsland<EOT>* island);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
eoCheckPoint<EOT> ck;
|
eoCheckPoint<EOT> ck;
|
||||||
|
IslandNotifier<EOT> islandNotifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <contWrapper.cpp>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
smp/src/intPolicy.cpp
Normal file
35
smp/src/intPolicy.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
<intPolicy.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 <class EOT>
|
||||||
|
paradiseo::smp::IntPolicy<EOT>::IntPolicy(eoEvalFunc<EOT>& _eval, eoReplacement<EOT>& _replace) :
|
||||||
|
eval(_eval),
|
||||||
|
replace(_replace)
|
||||||
|
{}
|
||||||
|
|
||||||
68
smp/src/intPolicy.h
Normal file
68
smp/src/intPolicy.h
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
<intPolicy.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 INT_POLICY_H_
|
||||||
|
#define INT_POLICY_H_
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
|
|
||||||
|
namespace paradiseo
|
||||||
|
{
|
||||||
|
namespace smp
|
||||||
|
{
|
||||||
|
|
||||||
|
/** IntPolicy: Integration policy for island.
|
||||||
|
|
||||||
|
The island model will check its policy to know how to integrate population sent by other islands.
|
||||||
|
|
||||||
|
@see smp::Island, smp::MigPolicy
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
class IntPolicy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param _eval Method to evaluate the population to integrate.
|
||||||
|
* @param _replace Method to replace elements in the island.
|
||||||
|
*/
|
||||||
|
IntPolicy(eoEvalFunc<EOT>& _eval, eoReplacement<EOT>& _replace);
|
||||||
|
|
||||||
|
eoEvalFunc<EOT>& eval;
|
||||||
|
eoReplacement<EOT>& replace;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include<intPolicy.cpp>
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -31,14 +31,18 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
|
||||||
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, eoReplacement<EOT>& _intPolicy, Policy<EOT>& _migPolicy, Args&... args) :
|
paradiseo::smp::Island<EOAlgo,EOT>::Island(unsigned _popSize, eoInit<EOT>& _chromInit, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args) :
|
||||||
ContWrapper<EOT>(Loop<Args...>().template findValue<eoContinue<EOT>>(args...),_migPolicy),
|
// The PPExpander looks for the continuator in the parameters pack.
|
||||||
pop(_popSize, _chromInit),
|
// The private inheritance of ContWrapper wraps the continuator and add islandNotifier.
|
||||||
|
ContWrapper<EOT>(Loop<Args...>().template findValue<eoContinue<EOT>>(args...), this),
|
||||||
|
// We inject the wrapped continuator by tag dispatching method during the algorithm construction.
|
||||||
algo(EOAlgo<EOT>(wrap_pp<eoContinue<EOT>>(this->ck,args)...)),
|
algo(EOAlgo<EOT>(wrap_pp<eoContinue<EOT>>(this->ck,args)...)),
|
||||||
intPolicy(_intPolicy)
|
pop(_popSize, _chromInit),
|
||||||
|
intPolicy(_intPolicy),
|
||||||
|
migPolicy(_migPolicy)
|
||||||
{
|
{
|
||||||
|
// 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>");
|
static_assert(std::is_base_of<eoAlgo<EOT>,EOAlgo<EOT>>::value, "Algorithm must inherit from eoAlgo<EOT>");
|
||||||
_migPolicy.addObserver(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT>
|
template<template <class> class EOAlgo, class EOT>
|
||||||
|
|
@ -59,6 +63,21 @@ eoPop<EOT>& paradiseo::smp::Island<EOAlgo,EOT>::getPop()
|
||||||
return pop;
|
return pop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<template <class> class EOAlgo, class EOT>
|
||||||
|
void paradiseo::smp::Island<EOAlgo,EOT>::check()
|
||||||
|
{
|
||||||
|
std::cout << "On check" << std::endl;
|
||||||
|
for(PolicyElement<EOT>& elem : migPolicy)
|
||||||
|
{
|
||||||
|
if(!elem(pop))
|
||||||
|
{
|
||||||
|
std::cout << "On lance l'emmigration" << std::endl;
|
||||||
|
send(elem.getSelect());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
receive();
|
||||||
|
}
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT>
|
template<template <class> class EOAlgo, class EOT>
|
||||||
void paradiseo::smp::Island<EOAlgo,EOT>::send(eoSelect<EOT>& _select)
|
void paradiseo::smp::Island<EOAlgo,EOT>::send(eoSelect<EOT>& _select)
|
||||||
{
|
{
|
||||||
|
|
@ -73,8 +92,11 @@ void paradiseo::smp::Island<EOAlgo,EOT>::receive(void)
|
||||||
{
|
{
|
||||||
while (!listImigrants.empty())
|
while (!listImigrants.empty())
|
||||||
{
|
{
|
||||||
intPolicy(pop, *(listImigrants.front()));
|
eoPop<EOT> offspring = *(listImigrants.front());
|
||||||
listImigrants.pop();
|
for(auto indi : offspring)
|
||||||
}
|
|
||||||
|
|
||||||
|
intPolicy.replace(pop, offspring);
|
||||||
|
listImigrants.pop();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <abstractIsland.h>
|
#include <abstractIsland.h>
|
||||||
#include <migPolicy.h>
|
#include <migPolicy.h>
|
||||||
|
#include <intPolicy.h>
|
||||||
#include <PPExpander.h>
|
#include <PPExpander.h>
|
||||||
#include <contWrapper.h>
|
#include <contWrapper.h>
|
||||||
#include <contDispatching.h>
|
#include <contDispatching.h>
|
||||||
|
|
@ -50,25 +51,57 @@ template<template <class> class EOAlgo, class EOT>
|
||||||
class Island : private ContWrapper<EOT>, public AIsland<EOT>
|
class Island : private ContWrapper<EOT>, public AIsland<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param _popSize Size of the algorithm population.
|
||||||
|
* @param _chromInit Population initializer.
|
||||||
|
* @param _intPolicy Integration policy
|
||||||
|
* @param _migPolicy Migration policy
|
||||||
|
* @param args Parameters to construct the algorithm of the island.
|
||||||
|
*/
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
Island(unsigned _popSize, eoInit<EOT>& _chromInit, eoReplacement<EOT>& _intPolicy, Policy<EOT>& _migPolicy, Args&... args);
|
Island(unsigned _popSize, eoInit<EOT>& _chromInit, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the island.
|
||||||
|
*/
|
||||||
void operator()();
|
void operator()();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the list of imigrants.
|
||||||
|
* @param _data Elements to integrate in the main population.
|
||||||
|
*/
|
||||||
void update(eoPop<EOT>& _data);
|
void update(eoPop<EOT>& _data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a reference to the island population.
|
||||||
|
* @return Reference to the island population
|
||||||
|
*/
|
||||||
eoPop<EOT>& getPop();
|
eoPop<EOT>& getPop();
|
||||||
|
|
||||||
//friend void Policy<EOT>::notifyIsland(eoSelect<EOT>& _select) const;
|
/**
|
||||||
|
* Check if there is population to receive or to migrate
|
||||||
|
*/
|
||||||
|
virtual void check(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void send(eoSelect<EOT>& _select);
|
|
||||||
void receive(void);
|
/**
|
||||||
|
* Send population to mediator
|
||||||
|
* @param _select Method to select EOT to send
|
||||||
|
*/
|
||||||
|
virtual void send(eoSelect<EOT>& _select);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there is population to receive
|
||||||
|
*/
|
||||||
|
virtual void receive(void);
|
||||||
|
|
||||||
eoPop<EOT> pop;
|
eoPop<EOT> pop;
|
||||||
EOAlgo<EOT> algo;
|
EOAlgo<EOT> algo;
|
||||||
std::queue<eoPop<EOT>*> listImigrants;
|
std::queue<eoPop<EOT>*> listImigrants;
|
||||||
eoReplacement<EOT>& intPolicy;
|
IntPolicy<EOT>& intPolicy;
|
||||||
|
MigPolicy<EOT>& migPolicy;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <island.cpp>
|
#include <island.cpp>
|
||||||
|
|
|
||||||
41
smp/src/islandNotifier.cpp
Normal file
41
smp/src/islandNotifier.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
<islandNotifier.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 <class EOT>
|
||||||
|
paradiseo::smp::IslandNotifier<EOT>::IslandNotifier(AIsland<EOT>* _observer, std::function<void(AIsland<EOT>*)> _task) :
|
||||||
|
observer(_observer),
|
||||||
|
task(_task)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
void paradiseo::smp::IslandNotifier<EOT>::operator()()
|
||||||
|
{
|
||||||
|
task(observer);
|
||||||
|
}
|
||||||
|
|
||||||
68
smp/src/islandNotifier.h
Normal file
68
smp/src/islandNotifier.h
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
<islandNotifier.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 ISLAND_NOTIFIER_H_
|
||||||
|
#define ISLAND_NOTIFIER_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
/** IslandNotifier: The notifier will perform the binded task each generation.
|
||||||
|
|
||||||
|
The island notifier makes the binded task executed by the island which observes.
|
||||||
|
We can imagine that a continuator check is we have to execute the binded task.
|
||||||
|
At the moment the task is perfermed each generation.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace paradiseo
|
||||||
|
{
|
||||||
|
namespace smp
|
||||||
|
{
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
class IslandNotifier : public eoUpdater
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
IslandNotifier(AIsland<EOT>* _observer, std::function<void(AIsland<EOT>*)> _task);
|
||||||
|
|
||||||
|
virtual void operator()();
|
||||||
|
|
||||||
|
protected :
|
||||||
|
AIsland<EOT>* observer;
|
||||||
|
std::function<void(AIsland<EOT>*)> task;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include <islandNotifier.cpp>
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -30,61 +30,18 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#ifndef MIG_POLICY_H_
|
#ifndef MIG_POLICY_H_
|
||||||
#define MIG_POLICY_H_
|
#define MIG_POLICY_H_
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <migPolicyElement.h>
|
#include <policyElement.h>
|
||||||
#include <island.h>
|
|
||||||
#include <abstractIsland.h>
|
|
||||||
|
|
||||||
namespace paradiseo
|
namespace paradiseo
|
||||||
{
|
{
|
||||||
namespace smp
|
namespace smp
|
||||||
{
|
{
|
||||||
// Forward declaration
|
/** MigPolicy: Migration policy
|
||||||
template <class EOT>
|
*/
|
||||||
class AIsland;
|
|
||||||
|
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class Policy : public eoContinue<EOT>, public std::vector<PolicyElement<EOT>>
|
using MigPolicy = std::vector<PolicyElement<EOT>>;
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool operator()(const eoPop<EOT>& _pop)
|
|
||||||
{
|
|
||||||
std::cout << "On regarde la politique de migration" << std::endl;
|
|
||||||
for(PolicyElement<EOT>& elem : *this)
|
|
||||||
{
|
|
||||||
std::cout << ".";
|
|
||||||
if(!elem(_pop))
|
|
||||||
{
|
|
||||||
std::cout << "On lance l'emmigration" << std::endl;
|
|
||||||
notifyIsland(elem.getSelect());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true; // Always return true because it never stops the algorithm
|
|
||||||
}
|
|
||||||
|
|
||||||
void addObserver(AIsland<EOT>* _observer)
|
|
||||||
{
|
|
||||||
observers.insert(_observer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObserver(AIsland<EOT>* _observer)
|
|
||||||
{
|
|
||||||
observers.erase(_observer);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
void notifyIsland(eoSelect<EOT>& _select) const
|
|
||||||
{
|
|
||||||
std::cout << "On notifie les iles" << std::endl;
|
|
||||||
for (AIsland<EOT>* it : observers)
|
|
||||||
it->send(_select);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<AIsland<EOT>*> observers;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
61
smp/src/policyElement.cpp
Normal file
61
smp/src/policyElement.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
<policyElement.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 <eo>
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
paradiseo::smp::PolicyElement<EOT>::PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criteria) :
|
||||||
|
selection(_selection),
|
||||||
|
criteria(_criteria)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
bool paradiseo::smp::PolicyElement<EOT>::operator()(const eoPop<EOT>& _pop)
|
||||||
|
{
|
||||||
|
// DEBUG
|
||||||
|
static int i = 0;
|
||||||
|
std::cout << i << std::endl;
|
||||||
|
i++;
|
||||||
|
// END DEBUG
|
||||||
|
|
||||||
|
return criteria(_pop);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
void paradiseo::smp::PolicyElement<EOT>::addCriteria(eoContinue<EOT>& _criteria)
|
||||||
|
{
|
||||||
|
criteria.add(_criteria);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
eoSelect<EOT>& paradiseo::smp::PolicyElement<EOT>::getSelect()
|
||||||
|
{
|
||||||
|
return selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -41,39 +41,39 @@ template <class EOT>
|
||||||
class PolicyElement : public eoContinue<EOT>
|
class PolicyElement : public eoContinue<EOT>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criteria) :
|
/**
|
||||||
selection(_selection),
|
* Constructor
|
||||||
criteria(_criteria)
|
* @param _selection How to select elements for migration
|
||||||
{
|
* @param _criteria When notifying the island
|
||||||
|
*/
|
||||||
|
PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criteria);
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Check is the criteria is reach
|
||||||
|
* @param _pop Population which is checked by the criteria.
|
||||||
|
* @return false if the criteria is reached.
|
||||||
|
*/
|
||||||
|
bool operator()(const eoPop<EOT>& _pop);
|
||||||
|
|
||||||
bool operator()(const eoPop<EOT>& _pop)
|
/**
|
||||||
{
|
* Add criteria for the same selection method.
|
||||||
// DEBUG
|
* @param _criteria New criteria.
|
||||||
static int i = 0;
|
*/
|
||||||
std::cout << i << std::endl;
|
void addCriteria(eoContinue<EOT>& _criteria);
|
||||||
i++;
|
|
||||||
// END DEBUG
|
|
||||||
|
|
||||||
return criteria(_pop);
|
/**
|
||||||
}
|
* Access to the selection method.
|
||||||
|
* @return Reference to the selection method.
|
||||||
void addCriteria(eoContinue<EOT>& _criteria)
|
*/
|
||||||
{
|
eoSelect<EOT>& getSelect();
|
||||||
criteria.add(_criteria);
|
|
||||||
}
|
|
||||||
|
|
||||||
eoSelect<EOT>& getSelect()
|
|
||||||
{
|
|
||||||
return selection;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
eoSelect<EOT>& selection;
|
eoSelect<EOT>& selection;
|
||||||
eoContinue<EOT>& criteria;
|
eoContinue<EOT>& criteria;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <policyElement.cpp>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +35,8 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <island.h>
|
#include <island.h>
|
||||||
#include <migPolicy.h>
|
#include <migPolicy.h>
|
||||||
#include <migPolicyElement.h>
|
#include <intPolicy.h>
|
||||||
|
#include <policyElement.h>
|
||||||
|
#include <islandNotifier.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,11 @@ int main(void)
|
||||||
eoPeriodicContinue<Indi> criteria(25); // We mig each gen
|
eoPeriodicContinue<Indi> criteria(25); // We mig each gen
|
||||||
eoDetTournamentSelect<Indi> selectOne(2);
|
eoDetTournamentSelect<Indi> selectOne(2);
|
||||||
eoSelectNumber<Indi> who(selectOne, 5);
|
eoSelectNumber<Indi> who(selectOne, 5);
|
||||||
Policy<Indi> pol;
|
MigPolicy<Indi> migPolicy;
|
||||||
pol.push_back(PolicyElement<Indi>(who, criteria));
|
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
|
||||||
|
IntPolicy<Indi> intPolicy(plainEval,replace);
|
||||||
|
|
||||||
Island<eoEasyEA,Indi> test(param.popSize, chromInit, replace, pol, genCont, plainEval, select, transform, replace);
|
Island<eoEasyEA,Indi> test(param.popSize, chromInit, intPolicy, migPolicy, genCont, plainEval, select, transform, replace);
|
||||||
|
|
||||||
test();
|
test();
|
||||||
cout << test.getPop() << endl;
|
cout << test.getPop() << endl;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue