Add function to wrap model in order to create homogeneous model easily
This commit is contained in:
parent
742b634beb
commit
fc2ea957a4
7 changed files with 39 additions and 92 deletions
|
|
@ -29,6 +29,7 @@ set (SMP_FILE
|
||||||
topology/hypercubic.cpp
|
topology/hypercubic.cpp
|
||||||
topology/mesh.cpp
|
topology/mesh.cpp
|
||||||
notifier.cpp
|
notifier.cpp
|
||||||
|
islandModelWrapper.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(smp STATIC ${SMP_FILE})
|
add_library(smp STATIC ${SMP_FILE})
|
||||||
|
|
@ -39,7 +40,7 @@ install(TARGETS smp ARCHIVE DESTINATION ${LIB} COMPONENT libraries)
|
||||||
### 3) Look for headers
|
### 3) Look for headers
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
file(GLOB HDRS smp *.h)
|
file(GLOB HDRS smp *.h *.cpp)
|
||||||
install(FILES ${HDRS} DESTINATION include${INSTALL_SUB_DIR}/smp COMPONENT headers)
|
install(FILES ${HDRS} DESTINATION include${INSTALL_SUB_DIR}/smp COMPONENT headers)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
@ -50,4 +51,5 @@ install(DIRECTORY MWAlgo topology
|
||||||
DESTINATION include${INSTALL_SUB_DIR}/smp
|
DESTINATION include${INSTALL_SUB_DIR}/smp
|
||||||
COMPONENT headers
|
COMPONENT headers
|
||||||
FILES_MATCHING PATTERN "*.h"
|
FILES_MATCHING PATTERN "*.h"
|
||||||
|
PATTERN "*.cpp"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -156,4 +156,3 @@ void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::update(eoPop<bEOT> _data)
|
||||||
std::lock_guard<std::mutex> lock(this->m);
|
std::lock_guard<std::mutex> lock(this->m);
|
||||||
listImigrants.push(_data);
|
listImigrants.push(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,8 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void receive(void);
|
virtual void receive(void);
|
||||||
|
|
||||||
|
AIsland<bEOT> clone() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
<homogeneousModel.cpp>
|
<islandModelWrapper.h>
|
||||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||||
|
|
||||||
Alexandre Quemy, Thibault Lasnier - INSA Rouen
|
Alexandre Quemy, Thibault Lasnier - INSA Rouen
|
||||||
|
|
@ -27,32 +27,64 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT>
|
#ifndef SMP_HOMOGENEOUS_ISLAND_MODEL_H_
|
||||||
template<class... IslandInit>
|
#define SMP_HOMOGENEOUS_ISLAND_MODEL_H_
|
||||||
paradiseo::smp::HomogeneousIslandModel<EOAlgo, EOT>::HomogeneousIslandModel(unsigned _islandNumber, AbstractTopology& _topo, unsigned _popSize, eoInit<EOT> &_chromInit, IslandInit... args) :
|
|
||||||
model(_topo)
|
#include <queue>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <utility>
|
||||||
|
#include <thread>
|
||||||
|
#include <tuple>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <bimap.h>
|
||||||
|
#include <abstractIsland.h>
|
||||||
|
#include <island.h>
|
||||||
|
#include <topology/topology.h>
|
||||||
|
|
||||||
|
namespace paradiseo
|
||||||
{
|
{
|
||||||
pops.resize(_islandNumber);
|
namespace smp
|
||||||
islands.resize(_islandNumber);
|
{
|
||||||
|
|
||||||
|
/** IslandModelWrapper: Wrapper to create homogeneous model easily
|
||||||
|
|
||||||
|
IslandModelWrapper is a function that creates an homogeneous model with the number
|
||||||
|
of specified islands, built with same parameters.
|
||||||
|
|
||||||
|
@see smp::IslandModel
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<template <class> class EOAlgo, class EOT, class... IslandInit>
|
||||||
|
std::vector<eoPop<EOT>> IslandModelWrapper(unsigned _islandNumber, AbstractTopology& _topo, unsigned _popSize, eoInit<EOT> &_chromInit, IslandInit... args)
|
||||||
|
{
|
||||||
|
// Model creation
|
||||||
|
IslandModel<EOT> model(_topo);
|
||||||
|
|
||||||
|
// Island and pop containers
|
||||||
|
std::vector<Island<EOAlgo,EOT>*> islands(_islandNumber);
|
||||||
|
std::vector<eoPop<EOT>> pops(_islandNumber);
|
||||||
|
|
||||||
|
// Generate islands and put them in the model
|
||||||
for(unsigned i = 0; i < _islandNumber; i++)
|
for(unsigned i = 0; i < _islandNumber; i++)
|
||||||
{
|
{
|
||||||
pops[i] = eoPop<EOT>(_popSize, _chromInit);
|
pops[i] = eoPop<EOT>(_popSize, _chromInit);
|
||||||
islands[i] = new Island<EOAlgo, EOT>(pops[i], args...);
|
islands[i] = new Island<EOAlgo, EOT>(pops[i], args...);
|
||||||
model.add(*islands[i]);
|
model.add(*islands[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start the model
|
||||||
model();
|
model();
|
||||||
}
|
|
||||||
|
// Delete islands
|
||||||
template<template <class> class EOAlgo, class EOT>
|
|
||||||
paradiseo::smp::HomogeneousIslandModel<EOAlgo, EOT>::~HomogeneousIslandModel()
|
|
||||||
{
|
|
||||||
for(auto& island : islands)
|
for(auto& island : islands)
|
||||||
delete island;
|
delete island;
|
||||||
}
|
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT>
|
|
||||||
std::vector<eoPop<EOT>>& paradiseo::smp::HomogeneousIslandModel<EOAlgo, EOT>::getPop()
|
|
||||||
{
|
|
||||||
return pops;
|
return pops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -33,7 +33,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <MWModel.h>
|
#include <MWModel.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <islandModel.h>
|
#include <islandModel.h>
|
||||||
#include <homogeneousModel.h>
|
#include <islandModelWrapper.h>
|
||||||
#include <island.h>
|
#include <island.h>
|
||||||
#include <abstractIsland.h>
|
#include <abstractIsland.h>
|
||||||
#include <migPolicy.h>
|
#include <migPolicy.h>
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ set (TEST_LIST
|
||||||
t-smpTopo
|
t-smpTopo
|
||||||
t-smpMI_Homogeneous
|
t-smpMI_Homogeneous
|
||||||
t-smpMI_Heterogeneous
|
t-smpMI_Heterogeneous
|
||||||
|
t-smpMI_Wrapper
|
||||||
)
|
)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue