Add island
This commit is contained in:
parent
188fed8910
commit
4ec6e3f606
5 changed files with 160 additions and 1 deletions
|
|
@ -18,7 +18,8 @@ set(LIBRARY_OUTPUT_PATH ${SMP_LIB_OUTPUT_PATH})
|
|||
set (SMP_FILE
|
||||
thread.cpp
|
||||
MWModel.h
|
||||
scheduler.h)
|
||||
scheduler.h
|
||||
island.h)
|
||||
|
||||
add_library(smp STATIC ${SMP_FILE})
|
||||
|
||||
|
|
|
|||
39
smp/src/island.cpp
Normal file
39
smp/src/island.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
<island.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 <type_traits>
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
template<class... Args>
|
||||
paradiseo::smp::Island<EOAlgo,EOT>::Island(Args&... args) :
|
||||
algo(EOAlgo<EOT>(args...))
|
||||
{
|
||||
static_assert(std::is_base_of<eoAlgo<EOT>,EOAlgo<EOT>>::value, "Algorithm must inherits from eoAlgo<EOT>");
|
||||
}
|
||||
|
||||
58
smp/src/island.h
Normal file
58
smp/src/island.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
<island.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_H_
|
||||
#define ISLAND_H_
|
||||
|
||||
#include <eo>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
template<template <class> class EOAlgo, class EOT>
|
||||
class Island
|
||||
{
|
||||
public:
|
||||
template<class... Args>
|
||||
Island(Args&... args);
|
||||
|
||||
protected:
|
||||
eoPop<EOT> pop;
|
||||
EOAlgo<EOT> algo;
|
||||
};
|
||||
|
||||
#include <island.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -16,6 +16,7 @@ set (TEST_LIST
|
|||
t-smpMW_eoEasyEA
|
||||
t-smpMW_eoEasyPSO
|
||||
t-smpMW_eoSyncEasyPSO
|
||||
t-smpIsland
|
||||
)
|
||||
|
||||
######################################################################################
|
||||
|
|
|
|||
60
smp/test/t-smpIsland.cpp
Normal file
60
smp/test/t-smpIsland.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include <island.h>
|
||||
#include <eo>
|
||||
|
||||
#include "smpTestClass.h"
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
using namespace std;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
typedef struct {
|
||||
unsigned popSize = 10;
|
||||
unsigned tSize = 2;
|
||||
double pCross = 0.8;
|
||||
double pMut = 0.7;
|
||||
unsigned maxGen = 1000;
|
||||
} Param;
|
||||
|
||||
Param param;
|
||||
|
||||
rng.reseed(42);
|
||||
|
||||
loadInstances("t-data.dat", n, bkv, a, b);
|
||||
|
||||
// Evaluation function
|
||||
IndiEvalFunc plainEval;
|
||||
|
||||
// Init a solution
|
||||
IndiInit chromInit;
|
||||
|
||||
// Define selection
|
||||
eoDetTournamentSelect<Indi> selectOne(param.tSize);
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
|
||||
// Define operators for crossover and mutation
|
||||
IndiXover Xover; // CROSSOVER
|
||||
IndiSwapMutation mutationSwap; // MUTATION
|
||||
|
||||
// Encapsule in a tranform operator
|
||||
eoSGATransform<Indi> transform(Xover, param.pCross, mutationSwap, param.pMut);
|
||||
|
||||
// Define replace operator
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
eoGenContinue<Indi> genCont(param.maxGen); // generation continuation
|
||||
|
||||
// Define population
|
||||
eoPop<Indi> pop(param.popSize, chromInit);
|
||||
|
||||
try
|
||||
{
|
||||
Island<eoEasyEA,Indi> test(genCont, plainEval, select, transform, replace);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue