Island mecanism : migration element and policy, island
This commit is contained in:
parent
2cd7f1f423
commit
1a23b618fc
9 changed files with 218 additions and 34 deletions
|
|
@ -30,6 +30,9 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#ifndef PPE_H_
|
#ifndef PPE_H_
|
||||||
#define 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;
|
template<class... Arg> class Loop;
|
||||||
|
|
||||||
57
smp/src/contDispatching.h
Normal file
57
smp/src/contDispatching.h
Normal 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
63
smp/src/contWrapper.h
Normal 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
|
||||||
|
|
@ -32,11 +32,12 @@ 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, eoReplacement<EOT>& _intPolicy, Policy<EOT>& _migPolicy, Args&... args) :
|
||||||
|
ContWrapper<EOT>(Loop<Args...>().template findValue<eoContinue<EOT>>(args...),_migPolicy),
|
||||||
pop(_popSize, _chromInit),
|
pop(_popSize, _chromInit),
|
||||||
algo(EOAlgo<EOT>(args...)),
|
algo(EOAlgo<EOT>(wrap_pp<eoContinue<EOT>>(this->ck,args)...)),
|
||||||
intPolicy(_intPolicy)
|
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>
|
template<template <class> class EOAlgo, class EOT>
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,10 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <policy.h>
|
#include <migPolicy.h>
|
||||||
|
#include <PPExpander.h>
|
||||||
|
#include <contWrapper.h>
|
||||||
|
#include <contDispatching.h>
|
||||||
|
|
||||||
namespace paradiseo
|
namespace paradiseo
|
||||||
{
|
{
|
||||||
|
|
@ -43,7 +46,7 @@ namespace smp
|
||||||
{
|
{
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT>
|
template<template <class> class EOAlgo, class EOT>
|
||||||
class Island
|
class Island : private ContWrapper<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
|
|
|
||||||
|
|
@ -27,47 +27,28 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef POLICY_H_
|
#ifndef MIG_POLICY_H_
|
||||||
#define POLICY_H_
|
#define MIG_POLICY_H_
|
||||||
|
|
||||||
#include <eo>
|
#include <eo>
|
||||||
|
|
||||||
|
#include <migPolicyElement.h>
|
||||||
|
|
||||||
namespace paradiseo
|
namespace paradiseo
|
||||||
{
|
{
|
||||||
namespace smp
|
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>
|
template <class EOT>
|
||||||
class Policy : public eoContinue<EOT>, public std::vector<PolicyElement<EOT>>
|
class Policy : public eoContinue<EOT>, public std::vector<PolicyElement<EOT>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool operator()(const eoPop<EOT>& _pop)
|
bool operator()(const eoPop<EOT>& _pop)
|
||||||
{
|
{
|
||||||
|
std::cout << "On regarde la politique de migration" << std::endl;
|
||||||
for(PolicyElement<EOT>& elem : *this)
|
for(PolicyElement<EOT>& elem : *this)
|
||||||
{
|
{
|
||||||
|
std::cout << ".";
|
||||||
if(!elem(_pop))
|
if(!elem(_pop))
|
||||||
std::cout << "On lance l'emmigration" << std::endl;
|
std::cout << "On lance l'emmigration" << std::endl;
|
||||||
}
|
}
|
||||||
76
smp/src/migPolicyElement.h
Normal file
76
smp/src/migPolicyElement.h
Normal 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
|
||||||
|
|
@ -34,7 +34,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <MWModel.h>
|
#include <MWModel.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <island.h>
|
#include <island.h>
|
||||||
#include <policy.h>
|
#include <migPolicy.h>
|
||||||
#include <PPE.h>
|
#include <migPolicyElement.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ int main(void)
|
||||||
unsigned tSize = 2;
|
unsigned tSize = 2;
|
||||||
double pCross = 0.8;
|
double pCross = 0.8;
|
||||||
double pMut = 0.7;
|
double pMut = 0.7;
|
||||||
unsigned maxGen = 1000;
|
unsigned maxGen = 100;
|
||||||
} Param;
|
} Param;
|
||||||
|
|
||||||
Param param;
|
Param param;
|
||||||
|
|
@ -50,9 +50,9 @@ int main(void)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Emigration policy
|
// Emigration policy
|
||||||
eoGenContinue<Indi> criteria(1); // We mig each gen
|
eoPeriodicContinue<Indi> criteria(25); // We mig each gen
|
||||||
Policy<Indi> pol;
|
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);
|
Island<eoEasyEA,Indi> test(param.popSize, chromInit, replace, pol, genCont, plainEval, select, transform, replace);
|
||||||
test();
|
test();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue