Island mecanism : migration element and policy, island

This commit is contained in:
quemy 2012-11-08 23:57:02 +01:00
commit 1a23b618fc
9 changed files with 218 additions and 34 deletions

View file

@ -30,6 +30,9 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#ifndef PPE_H_
#define PPE_H_
/** Parameter Pack Expansion: Utility file to expand parameter pack
/* Utility file to expand parameter pack with the recursive method
**/
template<class... Arg> class Loop;

57
smp/src/contDispatching.h Normal file
View file

@ -0,0 +1,57 @@
/*
<contDispatching.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 CONT_D_H_
#define CONT_D_H_
/** Continuator Dispatching
* The Continuator Dispatching enable to wrap continuator in Island constructor for a better user interface
**/
template<class T, class U>
U& wrap_pp_impl(T&, U& u, std::false_type)
{ return u; }
template<class T, class U>
T& wrap_pp_impl(T& t, U&, std::true_type)
{ return t; }
template<class T, class U>
struct result_of_wrap_pp :
std::conditional<std::is_base_of<T,U>::value,T&,U&>
{};
template<class T, class U>
typename result_of_wrap_pp<T,U>::type wrap_pp(T& t, U& u)
{
typedef typename std::is_base_of<T,U>::type tag;
return wrap_pp_impl(t,u,tag());
}
#endif

63
smp/src/contWrapper.h Normal file
View file

@ -0,0 +1,63 @@
/*
<contWrapper.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 CONTWRAPPER_H_
#define CONTWRAPPER_H_
#include <queue>
#include <vector>
#include <utility>
#include <eo>
#include <migPolicy.h>
namespace paradiseo
{
namespace smp
{
template<class EOT>
class ContWrapper
{
public:
ContWrapper(eoContinue<EOT>& _cont, Policy<EOT>& _policy) :
ck(_cont)
{
ck.add(_policy);
}
protected:
eoCheckPoint<EOT> ck;
};
}
}
#endif

View file

@ -32,11 +32,12 @@ Contact: paradiseo-help@lists.gforge.inria.fr
template<template <class> class EOAlgo, class EOT>
template<class... Args>
paradiseo::smp::Island<EOAlgo,EOT>::Island(unsigned _popSize, eoInit<EOT>& _chromInit, eoReplacement<EOT>& _intPolicy, Policy<EOT>& _migPolicy, Args&... args) :
ContWrapper<EOT>(Loop<Args...>().template findValue<eoContinue<EOT>>(args...),_migPolicy),
pop(_popSize, _chromInit),
algo(EOAlgo<EOT>(args...)),
algo(EOAlgo<EOT>(wrap_pp<eoContinue<EOT>>(this->ck,args)...)),
intPolicy(_intPolicy)
{
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>");
}
template<template <class> class EOAlgo, class EOT>

View file

@ -35,7 +35,10 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <utility>
#include <eo>
#include <policy.h>
#include <migPolicy.h>
#include <PPExpander.h>
#include <contWrapper.h>
#include <contDispatching.h>
namespace paradiseo
{
@ -43,7 +46,7 @@ namespace smp
{
template<template <class> class EOAlgo, class EOT>
class Island
class Island : private ContWrapper<EOT>
{
public:
template<class... Args>

View file

@ -27,47 +27,28 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef POLICY_H_
#define POLICY_H_
#ifndef MIG_POLICY_H_
#define MIG_POLICY_H_
#include <eo>
#include <migPolicyElement.h>
namespace paradiseo
{
namespace smp
{
template <class EOT>
class PolicyElement : public eoContinue<EOT>
{
public :
PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criteria) :
selection(_selection),
criteria(_criteria)
{
}
bool operator()(const eoPop<EOT>& _pop)
{
std::cout << "Policy Element" << std::endl;
return false;
}
protected :
eoSelect<EOT>& selection;
eoContinue<EOT>& criteria;
};
template <class EOT>
class Policy : public eoContinue<EOT>, public 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;
}

View file

@ -0,0 +1,76 @@
/*
<policyElement.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 POLICY_ELEM_H_
#define POLICY_ELEM_H_
#include <eo>
namespace paradiseo
{
namespace smp
{
template <class EOT>
class PolicyElement : public eoContinue<EOT>
{
public :
PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criteria) :
selection(_selection),
criteria(_criteria)
{
}
bool operator()(const eoPop<EOT>& _pop)
{
// DEBUG
static int i = 0;
std::cout << i << std::endl;
i++;
// END DEBUG
return criteria(_pop);
}
void addCriteria(eoContinue<EOT>& _criteria)
{
criteria.add(_criteria);
}
protected :
eoSelect<EOT>& selection;
eoContinue<EOT>& criteria;
};
}
}
#endif

View file

@ -34,7 +34,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <MWModel.h>
#include <scheduler.h>
#include <island.h>
#include <policy.h>
#include <PPE.h>
#include <migPolicy.h>
#include <migPolicyElement.h>
#endif

View file

@ -13,7 +13,7 @@ int main(void)
unsigned tSize = 2;
double pCross = 0.8;
double pMut = 0.7;
unsigned maxGen = 1000;
unsigned maxGen = 100;
} Param;
Param param;
@ -50,9 +50,9 @@ int main(void)
try
{
// Emigration policy
eoGenContinue<Indi> criteria(1); // We mig each gen
eoPeriodicContinue<Indi> criteria(25); // We mig each gen
Policy<Indi> pol;
pol.push_back(PolicyElement<Indi>(select, genCont));
pol.push_back(PolicyElement<Indi>(select, criteria));
Island<eoEasyEA,Indi> test(param.popSize, chromInit, replace, pol, genCont, plainEval, select, transform, replace);
test();