Merge branch 'islandmodel'
This commit is contained in:
commit
953b4377e9
77 changed files with 4960 additions and 408 deletions
|
|
@ -44,6 +44,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-Wunknown-pragmas -O2" CACHE STRING "" FORCE)
|
|||
if(SMP)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -pthread" CACHE STRING "" FORCE)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -pthread" CACHE STRING "" FORCE)
|
||||
add_definitions(-D_GLIBCXX_USE_NANOSLEEP)
|
||||
endif(SMP)
|
||||
|
||||
######################################################################################
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ if(PROFILING)
|
|||
COMMAND lcov -r output.info '*/tutorial*' -o output.info
|
||||
COMMAND lcov -r output.info '/usr*' -o output.info
|
||||
COMMAND lcov -r output.info '*/test*' -o output.info
|
||||
COMMAND lcov -r output.info '*/eo*' -o output.info
|
||||
COMMAND lcov -r output.info '*/mo*' -o output.info
|
||||
COMMAND lcov -r output.info '*/moeo*' -o output.info
|
||||
COMMAND lcov -r output.info '*/problems*' -o output.info
|
||||
COMMAND genhtml output.info -o coverage/ --highlight --legend
|
||||
)
|
||||
else(LCOV)
|
||||
|
|
|
|||
62
eo/src/eoInvertedContinue.h
Normal file
62
eo/src/eoInvertedContinue.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
<eoInvertedContinue.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||
|
||||
Alexandre Quemy
|
||||
|
||||
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 _eoInvertedContinue_h
|
||||
#define _eoInvertedContinue_h
|
||||
|
||||
#include <eoContinue.h>
|
||||
|
||||
/**
|
||||
* Return the opposite of the wrapped continuator
|
||||
*
|
||||
* @ingroup Continuators
|
||||
*/
|
||||
template< class EOT>
|
||||
class eoInvertedContinue: public eoContinue<EOT>
|
||||
{
|
||||
public:
|
||||
/// Ctor
|
||||
eoInvertedContinue(eoContinue<EOT>& _cont)
|
||||
: cont(_cont) {};
|
||||
|
||||
/** Returns the opposite of the wrapped continuator
|
||||
*/
|
||||
virtual bool operator() ( const eoPop<EOT>& _pop )
|
||||
{
|
||||
return !cont(_pop);
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "eoInvertedContinue"; }
|
||||
|
||||
private:
|
||||
eoContinue<EOT> &eval;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -11,7 +11,7 @@ if(DOXYGEN_FOUND)
|
|||
# Creating the custom target
|
||||
if(UNIX AND NOT ${CMAKE_VERBOSE_MAKEFILE})
|
||||
add_custom_target(doc-smp
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${SMP_DOC_CONFIG_FILE} 2> /dev/null > /dev/null
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${SMP_DOC_CONFIG_FILE}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
else(UNIX AND NOT ${CMAKE_VERBOSE_MAKEFILE})
|
||||
add_custom_target(doc-smp
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
ParadisEO-SMP for Symmetric MultiProcessing or Shared Memory Parallelism is a module for multicores computations on several algorithms proposed by ParadiseEO. By simply wrapping the algorithms, it allows you to refer only to the API of your algorithm instead of learning a new one.
|
||||
|
||||
Different parallelism models are avaiable such as the Master / Slaves model or the Island Model.
|
||||
Different parallelism models are available such as the Master / Slaves Model or the Island Model.
|
||||
|
||||
@section tutorials Tutorials
|
||||
|
||||
|
|
|
|||
|
|
@ -1296,7 +1296,7 @@ SKIP_FUNCTION_MACROS = YES
|
|||
# If a tag file is not located in the directory in which doxygen
|
||||
# is run, you must also specify the path to the tagfile here.
|
||||
|
||||
TAGFILES = @SMP_BIN_DIR@/doc/eo.doxytag=http://eodev.sourceforge.net/smp/doc/html
|
||||
TAGFILES = @SMP_BIN_DIR@/doc/smp.doxytag=http://paradiseo.gforge.inria.fr/addon/smp/doc/index.html
|
||||
|
||||
# When a file name is specified after GENERATE_TAGFILE, doxygen will create
|
||||
# a tag file that is based on the input files it reads.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
### 0) Include directories
|
||||
######################################################################################
|
||||
|
||||
include_directories(${EO_SRC_DIR}/src)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
######################################################################################
|
||||
|
|
@ -16,9 +17,22 @@ set(LIBRARY_OUTPUT_PATH ${SMP_LIB_OUTPUT_PATH})
|
|||
######################################################################################
|
||||
|
||||
set (SMP_FILE
|
||||
thread.cpp
|
||||
MWModel.h
|
||||
scheduler.h)
|
||||
scheduler.h
|
||||
island.h
|
||||
topology/abstractTopology.h
|
||||
topology/topology.h
|
||||
topology/topologyBuilder.h
|
||||
topology/complete.cpp
|
||||
topology/star.cpp
|
||||
topology/ring.cpp
|
||||
topology/hypercubic.cpp
|
||||
topology/mesh.cpp
|
||||
topology/customBooleanTopology.cpp
|
||||
topology/customStochasticTopology.cpp
|
||||
notifier.cpp
|
||||
islandModelWrapper.h
|
||||
)
|
||||
|
||||
add_library(smp STATIC ${SMP_FILE})
|
||||
|
||||
|
|
@ -28,15 +42,16 @@ install(TARGETS smp ARCHIVE DESTINATION ${LIB} COMPONENT libraries)
|
|||
### 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)
|
||||
|
||||
######################################################################################
|
||||
### 4) Install directories
|
||||
######################################################################################
|
||||
|
||||
install(DIRECTORY MWAlgo
|
||||
install(DIRECTORY MWAlgo topology
|
||||
DESTINATION include${INSTALL_SUB_DIR}/smp
|
||||
COMPONENT headers
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
PATTERN "*.cpp"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -32,12 +32,14 @@ template<class... Args>
|
|||
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel(unsigned workersNb, Args&... args) :
|
||||
EOAlgo<EOT>(args...),
|
||||
scheduler(workersNb)
|
||||
{ assert(workersNb > 0); }
|
||||
{
|
||||
assert(workersNb > 0);
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class Policy>
|
||||
template<class... Args>
|
||||
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel(Args&... args) :
|
||||
MWModel(Thread::hardware_concurrency(), args...)
|
||||
MWModel(std::thread::hardware_concurrency(), args...)
|
||||
{}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class Policy>
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef MWMODEL_H_
|
||||
#define MWMODEL_H_
|
||||
#ifndef SMP_MWMODEL_H_
|
||||
#define SMP_MWMODEL_H_
|
||||
|
||||
#include <cassert>
|
||||
#include <thread>
|
||||
|
||||
#include <scheduler.h>
|
||||
#include <algoDispatching.h>
|
||||
#include <policiesDispatching.h>
|
||||
|
||||
|
||||
#include <eo>
|
||||
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ namespace smp
|
|||
|
||||
/** MWModel: Master / Worker Model for multicore computation
|
||||
|
||||
The MW Model wraps any algorithm in order to apply it on several populations.
|
||||
The MW Model wraps any algorithm in order to dispatch load between threads.
|
||||
|
||||
@see smp::Worker, smp::Thread
|
||||
*/
|
||||
|
|
@ -99,7 +99,7 @@ protected:
|
|||
void operator()(eoPop<EOT>& pop, const eoEasyEA_tag&);
|
||||
|
||||
/**
|
||||
* Specifid algorithm for EasyPSO
|
||||
* Specific algorithm for EasyPSO
|
||||
*/
|
||||
void operator()(eoPop<EOT>& pop, const eoEasyPSO_tag&);
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ protected:
|
|||
*/
|
||||
void operator()(eoPop<EOT>& pop,const error_tag&);
|
||||
|
||||
std::vector<Thread*> workers;
|
||||
std::vector<std::thread*> workers;
|
||||
Scheduler<EOT,Policy> scheduler;
|
||||
};
|
||||
|
||||
|
|
|
|||
74
smp/src/PPExpander.h
Normal file
74
smp/src/PPExpander.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
<PPExpander.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 SMP_PPE_H_
|
||||
#define SMP_PPE_H_
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/** 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 T, class... Arg>
|
||||
class Loop<T,Arg...>
|
||||
{
|
||||
template<class U>
|
||||
U& findValueImpl(T&, Arg&... arg, std::false_type)
|
||||
{
|
||||
return Loop<Arg...>().template findValue<U>(arg...);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
U& findValueImpl(T& t, Arg&... arg, std::true_type)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
public:
|
||||
template<class U>
|
||||
U& findValue(T& t, Arg&... arg)
|
||||
{
|
||||
typedef typename std::is_base_of<U,T>::type tag;
|
||||
return findValueImpl<U>(t,arg...,tag());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
98
smp/src/abstractIsland.h
Normal file
98
smp/src/abstractIsland.h
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
<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 SMP_ABSTRACT_ISLAND_H_
|
||||
#define SMP_ABSTRACT_ISLAND_H_
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <migPolicy.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
// Forward declaration
|
||||
template<class bEOT>
|
||||
class IslandModel;
|
||||
|
||||
/** AbstractIsland: An abstract island.
|
||||
|
||||
The abstract island is used to manipulate island pointers wihout the knowledge of the algorithm.
|
||||
The template is the base type for individuals.
|
||||
|
||||
@see smp::Island smp::IslandModel
|
||||
*/
|
||||
|
||||
template<class bEOT>
|
||||
class AIsland
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void operator()() = 0;
|
||||
|
||||
/**
|
||||
* Set the Island Model.
|
||||
* @param _model The model which manipulate the island.
|
||||
*/
|
||||
virtual void setModel(IslandModel<bEOT>* _model) = 0;
|
||||
|
||||
/**
|
||||
* Check if there is population to receive or to emigrate.
|
||||
*/
|
||||
virtual void check(void) = 0;
|
||||
|
||||
/**
|
||||
* Update the island by adding population to send in the imigrants list.
|
||||
* @param _data Population to integrate.
|
||||
*/
|
||||
virtual void update(eoPop<bEOT> _data) = 0;
|
||||
|
||||
/**
|
||||
* Check if the algorithm is stopped.
|
||||
* @return true if stopped.
|
||||
*/
|
||||
virtual bool isStopped(void) const = 0;
|
||||
|
||||
/**
|
||||
* Receive population by integrate individuals.
|
||||
*/
|
||||
virtual void receive(void) = 0;
|
||||
|
||||
protected:
|
||||
std::mutex m;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -27,8 +27,8 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef ALGO_D_H_
|
||||
#define ALGO_D_H_
|
||||
#ifndef SMP_ALGO_DISPATCHING_H_
|
||||
#define SMP_ALGO_DISPATCHING_H_
|
||||
|
||||
#include <eo>
|
||||
|
||||
|
|
@ -37,7 +37,9 @@ namespace paradiseo
|
|||
namespace smp
|
||||
{
|
||||
/** Algo Dispatching
|
||||
* The Algo Dispatching enable to choose the algorithm to call at compile time by tag-dispatching method
|
||||
|
||||
The Algo Dispatching enables to choose the algorithm to call at compile time by tag-dispatching method
|
||||
|
||||
**/
|
||||
|
||||
// Main algorithms tags
|
||||
|
|
|
|||
79
smp/src/bimap.cpp
Normal file
79
smp/src/bimap.cpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
<bimap.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 A, class B>
|
||||
void paradiseo::smp::Bimap<A,B>::add(A& a, B& b)
|
||||
{
|
||||
rightAssociation[a] = b;
|
||||
leftAssociation[b] = a;
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
std::map<A,B> paradiseo::smp::Bimap<A,B>::getRight() const
|
||||
{
|
||||
return rightAssociation;
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
std::map<B,A> paradiseo::smp::Bimap<A,B>::getLeft() const
|
||||
{
|
||||
return leftAssociation;
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
void paradiseo::smp::Bimap<A,B>::removeFromRight(const A& a)
|
||||
{
|
||||
for(auto& it : leftAssociation)
|
||||
if(it->second == a)
|
||||
leftAssociation.erase(it);
|
||||
|
||||
rightAssociation.erase(a);
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
void paradiseo::smp::Bimap<A,B>::removeFromLeft(const B& b)
|
||||
{
|
||||
for(auto& it : rightAssociation)
|
||||
if(it->second == b)
|
||||
rightAssociation.erase(it);
|
||||
|
||||
leftAssociation.erase(b);
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
unsigned paradiseo::smp::Bimap<A,B>::size() const
|
||||
{
|
||||
return leftAssociation.size();
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
bool paradiseo::smp::Bimap<A,B>::empty() const
|
||||
{
|
||||
return leftAssociation.empty();
|
||||
}
|
||||
105
smp/src/bimap.h
Normal file
105
smp/src/bimap.h
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
<bimap.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 SMP_BIMAP_MODEL_H_
|
||||
#define SMP_BIMAP_MODEL_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
/** Bimap
|
||||
|
||||
Bidirectional map in order to create a bijection between islands and vertices.
|
||||
A and B objects are stocked in two std::map, then if you would like to avoid instances duplications,
|
||||
template A and B with pointers.
|
||||
|
||||
**/
|
||||
|
||||
template<class A, class B>
|
||||
class Bimap
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Add a relation
|
||||
* @param A right key
|
||||
* @param B left key
|
||||
*/
|
||||
void add(A& a, B& b);
|
||||
|
||||
/**
|
||||
* Return a map which represents the right association.
|
||||
* @return rightAssociation
|
||||
*/
|
||||
std::map<A,B> getRight() const;
|
||||
|
||||
/**
|
||||
* Return a map which represents the left association.
|
||||
* @return leftAssociation
|
||||
*/
|
||||
std::map<B,A> getLeft() const;
|
||||
|
||||
/**
|
||||
* Remove an association from a right key.
|
||||
* @param Right key of the association to be removed.
|
||||
*/
|
||||
void removeFromRight(const A& a);
|
||||
|
||||
/**
|
||||
* Remove an association from a left key.
|
||||
* @param Left key of the association to be removed.
|
||||
*/
|
||||
void removeFromLeft(const B& b);
|
||||
|
||||
/**
|
||||
* Return the number of associations.
|
||||
* @return Size of bimap
|
||||
*/
|
||||
unsigned size() const;
|
||||
|
||||
/**
|
||||
* Check if the bimap is empty
|
||||
* @return true if the bimap is empty
|
||||
*/
|
||||
bool empty() const;
|
||||
|
||||
protected:
|
||||
std::map<A,B> rightAssociation;
|
||||
std::map<B,A> leftAssociation;
|
||||
};
|
||||
|
||||
#include <bimap.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
63
smp/src/contDispatching.h
Normal file
63
smp/src/contDispatching.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
<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 SMP_CONT_DISPATCHING_H_
|
||||
#define SMP_CONT_DISPATCHING_H_
|
||||
|
||||
/** Continuator Dispatching
|
||||
|
||||
The Continuator Dispatching enables to wrap continuators in the Island constructor for a better user interface and, moreover, avoiding side effect.
|
||||
|
||||
**/
|
||||
|
||||
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
|
||||
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, class bEOT>
|
||||
paradiseo::smp::ContWrapper<EOT, bEOT>::ContWrapper(eoContinue<EOT>& _cont, AIsland<bEOT>* island) :
|
||||
ck(_cont),
|
||||
islandNotifier(island, &AIsland<bEOT>::check)
|
||||
{
|
||||
ck.add(islandNotifier);
|
||||
}
|
||||
72
smp/src/contWrapper.h
Normal file
72
smp/src/contWrapper.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
<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 SMP_CONT_WRAPPER_H_
|
||||
#define SMP_CONT_WRAPPER_H_
|
||||
|
||||
#include <utils/eoCheckPoint.h>
|
||||
#include <eoContinue.h>
|
||||
#include <migPolicy.h>
|
||||
#include <islandNotifier.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
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.
|
||||
By using the wrapper, we do not have to modify original continuators inside the IslandModel and then,
|
||||
it avoids some side effects.
|
||||
|
||||
*/
|
||||
template<class EOT, class bEOT>
|
||||
class ContWrapper
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param _cont Original continuators
|
||||
* @param _island Pointer on the island used by the notifier
|
||||
*/
|
||||
ContWrapper(eoContinue<EOT>& _cont, AIsland<bEOT>* _island);
|
||||
|
||||
protected:
|
||||
eoCheckPoint<EOT> ck;
|
||||
IslandNotifier<bEOT> islandNotifier;
|
||||
};
|
||||
|
||||
#include <contWrapper.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
<thread.cpp>
|
||||
<intPolicy.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||
|
||||
Alexandre Quemy
|
||||
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,
|
||||
|
|
@ -27,47 +27,28 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <thread.h>
|
||||
#ifndef SMP_INT_POLICY_H_
|
||||
#define SMP_INT_POLICY_H_
|
||||
|
||||
#include <eoReplacement.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
Thread::Thread(Thread&& other)
|
||||
{
|
||||
t = std::move(other.t);
|
||||
}
|
||||
/** IntPolicy: Integration policy for island.
|
||||
|
||||
Thread& Thread::operator=(Thread&& other)
|
||||
{
|
||||
t = std::move(other.t);
|
||||
return *this;
|
||||
}
|
||||
The island model will check its policy to know how to integrate populations sent by other islands.
|
||||
|
||||
const std::thread::id paradiseo::smp::Thread::getId() const
|
||||
{
|
||||
return t.get_id();
|
||||
}
|
||||
@see smp::Island, smp::MigPolicy
|
||||
*/
|
||||
|
||||
bool paradiseo::smp::Thread::joinable() const
|
||||
{
|
||||
return t.joinable();
|
||||
}
|
||||
|
||||
void paradiseo::smp::Thread::join()
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
|
||||
int paradiseo::smp::Thread::hardware_concurrency()
|
||||
{
|
||||
return std::thread::hardware_concurrency();
|
||||
}
|
||||
template <class EOT>
|
||||
using IntPolicy = eoReplacement<EOT>;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
158
smp/src/island.cpp
Normal file
158
smp/src/island.cpp
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
<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
|
||||
*/
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
template<class... Args>
|
||||
paradiseo::smp::Island<EOAlgo,EOT,bEOT>::Island(std::function<EOT(bEOT&)> _convertFromBase, std::function<bEOT(EOT&)> _convertToBase, eoPop<EOT>& _pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args) :
|
||||
// The PPExpander looks for the continuator in the parameters pack.
|
||||
// The private inheritance of ContWrapper wraps the continuator and add islandNotifier.
|
||||
ContWrapper<EOT, bEOT>(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)...)),
|
||||
// With the PPE we look for the eval function in order to evaluate EOT to integrate
|
||||
eval(Loop<Args...>().template findValue<eoEvalFunc<EOT>>(args...)),
|
||||
pop(_pop),
|
||||
intPolicy(_intPolicy),
|
||||
migPolicy(_migPolicy),
|
||||
stopped(false),
|
||||
model(nullptr),
|
||||
convertFromBase(_convertFromBase),
|
||||
convertToBase(_convertToBase)
|
||||
{
|
||||
// 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>");
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
template<class... Args>
|
||||
paradiseo::smp::Island<EOAlgo,EOT,bEOT>::Island(eoPop<EOT>& _pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args) :
|
||||
Island(
|
||||
// Default conversion functions for homogeneous islands
|
||||
[](bEOT& i) -> EOT { return std::forward<EOT>(i); },
|
||||
[](EOT& i) -> bEOT { return std::forward<bEOT>(i); },
|
||||
_pop, _intPolicy, _migPolicy, args...)
|
||||
{ }
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::operator()()
|
||||
{
|
||||
stopped = false;
|
||||
algo(pop);
|
||||
stopped = true;
|
||||
// Let's wait the end of communications with the island model
|
||||
for(auto& message : sentMessages)
|
||||
message.join();
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::setModel(IslandModel<bEOT>* _model)
|
||||
{
|
||||
model = _model;
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
eoPop<EOT>& paradiseo::smp::Island<EOAlgo,EOT,bEOT>::getPop() const
|
||||
{
|
||||
return pop;
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::check()
|
||||
{
|
||||
// Sending
|
||||
for(PolicyElement<EOT>& elem : migPolicy)
|
||||
if(!elem(pop))
|
||||
send(elem.getSelect());
|
||||
|
||||
// Receiving
|
||||
receive();
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
bool paradiseo::smp::Island<EOAlgo,EOT,bEOT>::isStopped(void) const
|
||||
{
|
||||
return (bool)stopped;
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::send(eoSelect<EOT>& _select)
|
||||
{
|
||||
// Allow island to work alone
|
||||
if(model != nullptr)
|
||||
{
|
||||
eoPop<EOT> migPop;
|
||||
_select(pop, migPop);
|
||||
|
||||
// Convert pop to base pop
|
||||
eoPop<bEOT> baseMigPop;
|
||||
for(auto& indi : migPop)
|
||||
baseMigPop.push_back(std::move(convertToBase(indi)));
|
||||
|
||||
//std::cout << "On envoie de l'île : " << migPop << std::endl;
|
||||
|
||||
// Delete delivered messages
|
||||
for(auto it = sentMessages.begin(); it != sentMessages.end(); it++)
|
||||
if(!it->joinable())
|
||||
sentMessages.erase(it);
|
||||
|
||||
sentMessages.push_back(std::thread(&IslandModel<bEOT>::update, model, std::move(baseMigPop), this));
|
||||
}
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::receive(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
while (!listImigrants.empty())
|
||||
{
|
||||
//std::cout << "On reçoit dans l'île : " << listImigrants.size() << std::endl;
|
||||
eoPop<bEOT> base_offspring = std::move(listImigrants.front());
|
||||
|
||||
// Convert objects from base to our objects type
|
||||
eoPop<EOT> offspring;
|
||||
for(auto& indi : base_offspring)
|
||||
offspring.push_back(std::move(convertFromBase(indi)));
|
||||
|
||||
// Evaluate objects to integrate
|
||||
for(auto& indi : offspring)
|
||||
eval(indi);
|
||||
|
||||
intPolicy(pop, offspring);
|
||||
listImigrants.pop();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::update(eoPop<bEOT> _data)
|
||||
{
|
||||
//std::cout << "On update dans l'île" << std::endl;
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
listImigrants.push(_data);
|
||||
}
|
||||
157
smp/src/island.h
Normal file
157
smp/src/island.h
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
<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 SMP_ISLAND_H_
|
||||
#define SMP_ISLAND_H_
|
||||
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <atomic>
|
||||
#include <type_traits>
|
||||
|
||||
#include <eoEvalFunc.h>
|
||||
#include <eoSelect.h>
|
||||
#include <eoAlgo.h>
|
||||
#include <eoPop.h>
|
||||
|
||||
#include <abstractIsland.h>
|
||||
#include <islandModel.h>
|
||||
#include <migPolicy.h>
|
||||
#include <intPolicy.h>
|
||||
#include <PPExpander.h>
|
||||
#include <contWrapper.h>
|
||||
#include <contDispatching.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
/** Island: Concrete island that wraps an algorithm
|
||||
|
||||
The island wraps an algorithm and provide mecanisms for emigration and integration of populations.
|
||||
An island also have a base type which represents the type of individuals of the Island Model.
|
||||
|
||||
@see smp::AbstractIsland, smp::MigPolicy
|
||||
*/
|
||||
|
||||
template<template <class> class EOAlgo, class EOT, class bEOT = EOT>
|
||||
class Island : private ContWrapper<EOT, bEOT>, public AIsland<bEOT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param _convertFromBase Function to convert EOT from base EOT
|
||||
* @param _convertToBase Function to convert base EOT to EOT
|
||||
* @param _pop Population of the island
|
||||
* @param _intPolicy Integration policy
|
||||
* @param _migPolicy Migration policy
|
||||
* @param args Parameters to construct the algorithm.
|
||||
*/
|
||||
template<class... Args>
|
||||
Island(std::function<EOT(bEOT&)> _convertFromBase, std::function<bEOT(EOT&)> _convertToBase, eoPop<EOT>& pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args);
|
||||
/**
|
||||
* Constructor
|
||||
* @param _pop Population of the island
|
||||
* @param _intPolicy Integration policy
|
||||
* @param _migPolicy Migration policy
|
||||
* @param args Parameters to construct the algorithm.
|
||||
*/
|
||||
template<class... Args>
|
||||
Island(eoPop<EOT>& pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args);
|
||||
|
||||
/**
|
||||
* Start the island.
|
||||
*/
|
||||
void operator()(void);
|
||||
|
||||
/**
|
||||
* Set model
|
||||
* @param _model Pointer to the Island Model corresponding
|
||||
*/
|
||||
virtual void setModel(IslandModel<bEOT>* _model);
|
||||
|
||||
/**
|
||||
* Return a reference to the island population.
|
||||
* @return Reference to the island population
|
||||
*/
|
||||
eoPop<EOT>& getPop() const;
|
||||
|
||||
/**
|
||||
* Check if there is population to receive or to migrate
|
||||
*/
|
||||
virtual void check(void);
|
||||
|
||||
/**
|
||||
* Update the list of imigrants.
|
||||
* @param _data Elements to integrate in the main population.
|
||||
*/
|
||||
void update(eoPop<bEOT> _data);
|
||||
|
||||
/**
|
||||
* Check if the algorithm is stopped.
|
||||
* @return true if stopped
|
||||
*/
|
||||
virtual bool isStopped(void) const;
|
||||
|
||||
/**
|
||||
* Check if there is population to receive
|
||||
*/
|
||||
virtual void receive(void);
|
||||
|
||||
AIsland<bEOT> clone() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Send population to mediator
|
||||
* @param _select Method to select EOT to send
|
||||
*/
|
||||
virtual void send(eoSelect<EOT>& _select);
|
||||
|
||||
EOAlgo<EOT> algo;
|
||||
eoEvalFunc<EOT>& eval;
|
||||
eoPop<EOT>& pop;
|
||||
std::queue<eoPop<bEOT>> listImigrants;
|
||||
IntPolicy<EOT>& intPolicy;
|
||||
MigPolicy<EOT>& migPolicy;
|
||||
std::atomic<bool> stopped;
|
||||
std::vector<std::thread> sentMessages;
|
||||
IslandModel<bEOT>* model;
|
||||
std::function<EOT(bEOT&)> convertFromBase;
|
||||
std::function<bEOT(EOT&)> convertToBase;
|
||||
};
|
||||
|
||||
#include <island.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
192
smp/src/islandModel.cpp
Normal file
192
smp/src/islandModel.cpp
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
<islandModel.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 <functional>
|
||||
#include <algorithm>
|
||||
|
||||
template<class EOT>
|
||||
paradiseo::smp::IslandModel<EOT>::IslandModel(AbstractTopology& _topo) :
|
||||
topo(_topo),
|
||||
running(false)
|
||||
{ }
|
||||
|
||||
template<class EOT>
|
||||
void paradiseo::smp::IslandModel<EOT>::add(AIsland<EOT>& _island)
|
||||
{
|
||||
islands.push_back(std::pair<AIsland<EOT>*, bool>(&_island, false));
|
||||
islands.back().first->setModel(this);
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
void paradiseo::smp::IslandModel<EOT>::operator()()
|
||||
{
|
||||
running = true;
|
||||
|
||||
// INIT PART
|
||||
// Create topology, table and initialize islands
|
||||
initModel();
|
||||
|
||||
std::vector<std::thread> threads(islands.size());
|
||||
|
||||
// Launching threads
|
||||
unsigned i = 0;
|
||||
for(auto it : islands)
|
||||
{
|
||||
threads[i] = std::thread(&AIsland<EOT>::operator(), it.first);
|
||||
i++;
|
||||
}
|
||||
|
||||
// Lambda function in order to know the number of working islands
|
||||
std::function<int()> workingIslands = [this]() -> int
|
||||
{
|
||||
return (int)std::count_if(std::begin(islands), std::end(islands),
|
||||
[](std::pair<AIsland<EOT>*, bool>& i) -> bool
|
||||
{ return i.second; } );
|
||||
};
|
||||
|
||||
// SCHEDULING PART
|
||||
while(workingIslands() > 0)
|
||||
{
|
||||
// Count working islands
|
||||
for(auto& it : islands)
|
||||
{
|
||||
// If an island is stopped we need to isolate its node in the topology
|
||||
if(it.second && it.first->isStopped())
|
||||
{
|
||||
it.second = false;
|
||||
topo.isolateNode(table.getLeft()[it.first]);
|
||||
}
|
||||
}
|
||||
// Check sending
|
||||
send();
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(10));
|
||||
}
|
||||
|
||||
// ENDING PART
|
||||
// Wait the end of algorithms
|
||||
for(auto& thread : threads)
|
||||
thread.join();
|
||||
|
||||
|
||||
// Wait the end of messages sending
|
||||
for(auto& message : sentMessages)
|
||||
message.join();
|
||||
|
||||
// Force last integration
|
||||
i = 0;
|
||||
for(auto it : islands)
|
||||
{
|
||||
threads[i] = std::thread(&AIsland<EOT>::receive, it.first);
|
||||
i++;
|
||||
}
|
||||
|
||||
// Wait the end of the last integration
|
||||
for(auto& thread : threads)
|
||||
thread.join();
|
||||
|
||||
running = false;
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
void paradiseo::smp::IslandModel<EOT>::update(eoPop<EOT> _data, AIsland<EOT>* _island)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
listEmigrants.push(std::pair<eoPop<EOT>,AIsland<EOT>*>(_data, _island));
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
void paradiseo::smp::IslandModel<EOT>::setTopology(AbstractTopology& _topo)
|
||||
{
|
||||
// If we change topo, we need to protect it
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
topo = _topo;
|
||||
// If we change when the algorithm is running, we need to recontruct the topo
|
||||
if(running)
|
||||
{
|
||||
topo.construct(islands.size());
|
||||
// If we change the topology during the algorithm, we need to isolate stopped islands
|
||||
for(auto it : islands)
|
||||
if(!it.second)
|
||||
topo.isolateNode(table.getLeft()[it.first]);
|
||||
}
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
void paradiseo::smp::IslandModel<EOT>::send(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
if (!listEmigrants.empty())
|
||||
{
|
||||
// Get the neighbors
|
||||
unsigned idFrom = table.getLeft()[listEmigrants.front().second];
|
||||
std::vector<unsigned> neighbors = topo.getIdNeighbors(idFrom);
|
||||
|
||||
// Send elements to neighbors
|
||||
eoPop<EOT> migPop = std::move(listEmigrants.front().first);
|
||||
for (unsigned idTo : neighbors)
|
||||
sentMessages.push_back(std::thread(&AIsland<EOT>::update, table.getRight()[idTo], std::move(migPop)));
|
||||
|
||||
listEmigrants.pop();
|
||||
}
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
bool paradiseo::smp::IslandModel<EOT>::isRunning() const
|
||||
{
|
||||
return (bool)running;
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
void paradiseo::smp::IslandModel<EOT>::initModel(void)
|
||||
{
|
||||
// Preparing islands
|
||||
for(auto& it : islands)
|
||||
it.second = true; // Indicate islands are active
|
||||
|
||||
// Construct topology according to the number of islands
|
||||
topo.construct(islands.size());
|
||||
|
||||
// Create table
|
||||
table = createTable();
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
Bimap<unsigned, AIsland<EOT>*> paradiseo::smp::IslandModel<EOT>::createTable()
|
||||
{
|
||||
Bimap<unsigned, AIsland<EOT>*> table;
|
||||
unsigned islandId = 0;
|
||||
for(auto it : islands)
|
||||
{
|
||||
table.add(islandId, it.first);
|
||||
islandId++;
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
113
smp/src/islandModel.h
Normal file
113
smp/src/islandModel.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
<islandModel.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 SMP_ISLAND_MODEL_H_
|
||||
#define SMP_ISLAND_MODEL_H_
|
||||
|
||||
#include <queue>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <thread>
|
||||
|
||||
#include <bimap.h>
|
||||
#include <abstractIsland.h>
|
||||
#include <topology/topology.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/** IslandModel
|
||||
|
||||
The IslandModel object is an island container that provides mecanisms in order to manage island communications according to a topology.
|
||||
|
||||
@see smp::Island, smp::MigPolicy
|
||||
*/
|
||||
|
||||
template<class EOT>
|
||||
class IslandModel
|
||||
{
|
||||
public:
|
||||
IslandModel(AbstractTopology& _topo);
|
||||
|
||||
/**
|
||||
* Add an island to the model.
|
||||
* @param _island Island to add.
|
||||
*/
|
||||
void add(AIsland<EOT>& _island);
|
||||
|
||||
/**
|
||||
* Launch the island model by starting islands on their population.
|
||||
*/
|
||||
void operator()();
|
||||
|
||||
/**
|
||||
* Update the island model by adding population to send in the emigrants list.
|
||||
*/
|
||||
void update(eoPop<EOT> _data, AIsland<EOT>* _island);
|
||||
|
||||
/**
|
||||
* Change topology
|
||||
* @param _topo New topology.
|
||||
*/
|
||||
void setTopology(AbstractTopology& _topo);
|
||||
|
||||
bool isRunning() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Send population to islands
|
||||
*/
|
||||
void send(void);
|
||||
|
||||
/**
|
||||
* Initialize islands, topology and table before starting the model
|
||||
*/
|
||||
void initModel(void);
|
||||
|
||||
Bimap<unsigned, AIsland<EOT>*> createTable();
|
||||
|
||||
std::queue<std::pair<eoPop<EOT>,AIsland<EOT>*>> listEmigrants;
|
||||
Bimap<unsigned, AIsland<EOT>*> table;
|
||||
std::vector<std::pair<AIsland<EOT>*, bool>> islands;
|
||||
AbstractTopology& topo;
|
||||
std::vector<std::thread> sentMessages;
|
||||
std::mutex m;
|
||||
std::atomic<bool> running;
|
||||
};
|
||||
|
||||
#include <islandModel.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
90
smp/src/islandModelWrapper.h
Normal file
90
smp/src/islandModelWrapper.h
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
<islandModelWrapper.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 SMP_HOMOGENEOUS_ISLAND_MODEL_H_
|
||||
#define SMP_HOMOGENEOUS_ISLAND_MODEL_H_
|
||||
|
||||
#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
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/** 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++)
|
||||
{
|
||||
pops[i] = eoPop<EOT>(_popSize, _chromInit);
|
||||
islands[i] = new Island<EOAlgo, EOT>(pops[i], args...);
|
||||
model.add(*islands[i]);
|
||||
}
|
||||
|
||||
// Start the model
|
||||
model();
|
||||
|
||||
// Delete islands
|
||||
for(auto& island : islands)
|
||||
delete island;
|
||||
|
||||
return pops;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
74
smp/src/islandNotifier.h
Normal file
74
smp/src/islandNotifier.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
<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 SMP_ISLAND_NOTIFIER_H_
|
||||
#define SMP_ISLAND_NOTIFIER_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/** 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 checks if we have to execute the binded task.
|
||||
At the moment, the task is performed each generation.
|
||||
|
||||
*/
|
||||
template <class EOT>
|
||||
class IslandNotifier : public eoUpdater
|
||||
{
|
||||
public :
|
||||
/**
|
||||
* Constructor
|
||||
* @param _observer Island which will perform the task
|
||||
* @param _task Task to perform each generation
|
||||
*/
|
||||
IslandNotifier(AIsland<EOT>* _observer, std::function<void(AIsland<EOT>*)> _task);
|
||||
|
||||
/**
|
||||
* Notify the island by performing the binded task
|
||||
*/
|
||||
virtual void operator()();
|
||||
|
||||
protected :
|
||||
AIsland<EOT>* observer;
|
||||
std::function<void(AIsland<EOT>*)> task;
|
||||
};
|
||||
|
||||
#include <islandNotifier.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
50
smp/src/migPolicy.h
Normal file
50
smp/src/migPolicy.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
<migPolicy.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 SMP_MIG_POLICY_H_
|
||||
#define SMP_MIG_POLICY_H_
|
||||
|
||||
#include <vector>
|
||||
#include <policyElement.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
/** MigPolicy: Migration policy is a vector of PolicyElement.
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
using MigPolicy = std::vector<PolicyElement<EOT>>;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
40
smp/src/notifier.cpp
Normal file
40
smp/src/notifier.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
<notifier.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 <notifier.h>
|
||||
|
||||
paradiseo::smp::Notifier::Notifier(std::function<void(void)> _task) :
|
||||
task(_task)
|
||||
{}
|
||||
|
||||
void paradiseo::smp::Notifier::operator()()
|
||||
{
|
||||
task();
|
||||
}
|
||||
|
||||
68
smp/src/notifier.h
Normal file
68
smp/src/notifier.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
<notifier.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 SMP_NOTIFIER_H_
|
||||
#define SMP_NOTIFIER_H_
|
||||
|
||||
#include <utils/eoUpdater.h>
|
||||
#include <functional>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
Notifier: The notifier will perform the binded task each generation.
|
||||
|
||||
*/
|
||||
class Notifier : public eoUpdater
|
||||
{
|
||||
public :
|
||||
/**
|
||||
* Constructor
|
||||
* @param _task task to perform each generation
|
||||
*/
|
||||
Notifier(std::function<void(void)> _task);
|
||||
|
||||
/**
|
||||
* Performing the binded task
|
||||
*/
|
||||
virtual void operator()();
|
||||
|
||||
protected :
|
||||
std::function<void(void)> task;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -27,17 +27,17 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef POLICIES_D_H_
|
||||
#define POLICIES_D_H_
|
||||
|
||||
#include <eo>
|
||||
#ifndef SMP_POLICIES_DISPATCHING_H_
|
||||
#define SMP_POLICIES_DISPATCHING_H_
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
/** Policies Dispatching
|
||||
* The Policies Dispatching enable to choose the policy to call at compile time by tag-dispatching method
|
||||
|
||||
The Policies Dispatching enables to choose the policy to call at compile time by tag-dispatching method
|
||||
|
||||
**/
|
||||
|
||||
struct LinearPolicy {};
|
||||
|
|
|
|||
59
smp/src/policyElement.cpp
Normal file
59
smp/src/policyElement.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
<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 <thread>
|
||||
#include <eo>
|
||||
|
||||
template <class EOT>
|
||||
paradiseo::smp::PolicyElement<EOT>::PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criterion) :
|
||||
selection(_selection),
|
||||
criterion(_criterion)
|
||||
{ }
|
||||
|
||||
template <class EOT>
|
||||
bool paradiseo::smp::PolicyElement<EOT>::operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
|
||||
// END DEBUG
|
||||
|
||||
return criterion(_pop);
|
||||
}
|
||||
|
||||
template <class EOT>
|
||||
void paradiseo::smp::PolicyElement<EOT>::addCriterion(eoContinue<EOT>& _criterion)
|
||||
{
|
||||
criterion.add(_criterion);
|
||||
}
|
||||
|
||||
template <class EOT>
|
||||
eoSelect<EOT>& paradiseo::smp::PolicyElement<EOT>::getSelect()
|
||||
{
|
||||
return selection;
|
||||
}
|
||||
|
||||
88
smp/src/policyElement.h
Normal file
88
smp/src/policyElement.h
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
<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 SMP_POLICY_ELEMENT_H_
|
||||
#define SMP_POLICY_ELEMENT_H_
|
||||
|
||||
#include <eoContinue.h>
|
||||
#include <eoSelect.h>
|
||||
#include <eoPop.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
/** PolicyElement: PolicyElement is an element of a migration policy.
|
||||
|
||||
The policy element is a pair made of a selection method and a criterion to apply the selection.
|
||||
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
class PolicyElement : public eoContinue<EOT>
|
||||
{
|
||||
public :
|
||||
/**
|
||||
* Constructor
|
||||
* @param _selection How to select elements for migration
|
||||
* @param _criterion When notifying the island
|
||||
*/
|
||||
PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criterion);
|
||||
|
||||
/**
|
||||
* Check is the criterion is reach
|
||||
* @param _pop Population which is checked by the criteria.
|
||||
* @return false if the criterion is reached.
|
||||
*/
|
||||
bool operator()(const eoPop<EOT>& _pop);
|
||||
|
||||
/**
|
||||
* Add criteria for the same selection method.
|
||||
* @param _criterion New criterion.
|
||||
*/
|
||||
void addCriterion(eoContinue<EOT>& _criterion);
|
||||
|
||||
/**
|
||||
* Access to the selection method.
|
||||
* @return Reference to the selection method.
|
||||
*/
|
||||
eoSelect<EOT>& getSelect();
|
||||
|
||||
protected :
|
||||
eoSelect<EOT>& selection;
|
||||
eoContinue<EOT>& criterion;
|
||||
};
|
||||
|
||||
#include <policyElement.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -27,8 +27,6 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
template<class EOT, class Policy>
|
||||
paradiseo::smp::Scheduler<EOT,Policy>::Scheduler(unsigned workersNb) :
|
||||
workers(workersNb),
|
||||
|
|
@ -75,7 +73,7 @@ void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, e
|
|||
|
||||
// Starting threads
|
||||
for(unsigned i = 0; i < workers.size(); i++)
|
||||
workers[i].start(&Scheduler<EOT,Policy>::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i]));
|
||||
workers[i] = std::thread(&Scheduler<EOT,Policy>::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i]));
|
||||
|
||||
// Wait the end of tasks
|
||||
for(unsigned i = 0; i < workers.size(); i++)
|
||||
|
|
@ -90,7 +88,7 @@ void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, e
|
|||
for(unsigned i = 0; i < workers.size(); i++)
|
||||
{
|
||||
planning[i] = 2;
|
||||
workers[i].start(&Scheduler<EOT,Policy>::applyProgressivePolicy, this, std::ref(func), std::ref(popPackages[i]), i);
|
||||
workers[i] = std::thread(&Scheduler<EOT,Policy>::applyProgressivePolicy, this, std::ref(func), std::ref(popPackages[i]), i);
|
||||
}
|
||||
|
||||
unsigned counter = 0;
|
||||
|
|
@ -114,9 +112,8 @@ void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, e
|
|||
planning[i] *= 2;
|
||||
}
|
||||
}
|
||||
/* A nanosleep can increase performances by 10% but
|
||||
as it is not supported by Fedora atm, I deactivate it. */
|
||||
//std::this_thread::sleep_for(std::chrono::nanoseconds(10));
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(10));
|
||||
}
|
||||
|
||||
done = true;
|
||||
|
|
|
|||
|
|
@ -27,15 +27,14 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef SCHEDULER_H_
|
||||
#define SCHEDULER_H_
|
||||
#ifndef SMP_SCHEDULER_H_
|
||||
#define SMP_SCHEDULER_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
#include <thread.h>
|
||||
#include <policiesDispatching.h>
|
||||
|
||||
#include <eoEvalFunc.h>
|
||||
|
|
@ -46,9 +45,12 @@ namespace paradiseo
|
|||
{
|
||||
namespace smp
|
||||
{
|
||||
/**
|
||||
A scheduler class
|
||||
/** Scheduler : Dispatch load between workers according to a policy.
|
||||
|
||||
Dispatch load between the specified number of workers according to a policy.
|
||||
|
||||
*/
|
||||
|
||||
template<class EOT, class Policy = LinearPolicy>
|
||||
class Scheduler
|
||||
{
|
||||
|
|
@ -103,7 +105,7 @@ protected:
|
|||
*/
|
||||
std::vector<std::vector<EOT*>> subGroups(eoPop<EOT>& pop);
|
||||
|
||||
std::vector<Thread> workers;
|
||||
std::vector<std::thread> workers;
|
||||
std::vector<std::vector<EOT*>> popPackages;
|
||||
|
||||
std::atomic<bool> done;
|
||||
|
|
|
|||
|
|
@ -30,8 +30,27 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#ifndef SMP_H
|
||||
#define SMP_H
|
||||
|
||||
#include <thread.h>
|
||||
#include <MWModel.h>
|
||||
#include <scheduler.h>
|
||||
#include <islandModel.h>
|
||||
#include <islandModelWrapper.h>
|
||||
#include <island.h>
|
||||
#include <abstractIsland.h>
|
||||
#include <migPolicy.h>
|
||||
#include <intPolicy.h>
|
||||
#include <policyElement.h>
|
||||
#include <islandNotifier.h>
|
||||
#include <notifier.h>
|
||||
|
||||
// Topologies
|
||||
#include <topology/topology.h>
|
||||
#include <topology/complete.h>
|
||||
#include <topology/ring.h>
|
||||
#include <topology/star.h>
|
||||
#include <topology/hypercubic.h>
|
||||
#include <topology/mesh.cpp>
|
||||
#include <topology/customBooleanTopology.h>
|
||||
#include <topology/customBooleanTopology.h>
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
112
smp/src/thread.h
112
smp/src/thread.h
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
<thread.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||
|
||||
Alexandre Quemy
|
||||
|
||||
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 THREAD_H_
|
||||
#define THREAD_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
/**
|
||||
A thread class which encapsulate the std::thread behaviour for more flexibility
|
||||
@see smp::Worker, smp::MWModel
|
||||
*/
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
Thread() = default;
|
||||
|
||||
/**
|
||||
* Constructor that will immediatly start the thread
|
||||
* @param f represente any callable object such as function or class method
|
||||
* @param args... reference object and parameters for f
|
||||
*/
|
||||
template< class Callable, class... Args >
|
||||
explicit Thread(Callable&& f, Args&&... args) : t(std::thread(std::forward<Callable>(f), std::forward<Args>(args)...)) {}
|
||||
|
||||
Thread(Thread&& other);
|
||||
|
||||
Thread(const Thread&) = delete;
|
||||
Thread& operator=(const Thread&) = delete;
|
||||
|
||||
virtual ~Thread() = default;
|
||||
|
||||
Thread& operator=(Thread&& other);
|
||||
|
||||
/**
|
||||
* Start the thread according to parameters
|
||||
* If the thread is running, it will wait until the end of its task
|
||||
* @param f represente any callable object such as function or class method
|
||||
* @param args... reference object and parameters for f
|
||||
*/
|
||||
template<class Callable,class... Args>
|
||||
void start(Callable&& f,Args&&... args);
|
||||
|
||||
/**
|
||||
* Get the id of the thread
|
||||
* @return id of the thread
|
||||
*/
|
||||
const std::thread::id getId() const;
|
||||
|
||||
/**
|
||||
* Get the state of the thread
|
||||
* @return true if the thread is running, false otherwise
|
||||
*/
|
||||
bool joinable() const;
|
||||
|
||||
/**
|
||||
* Wait until the end of the task
|
||||
*/
|
||||
void join();
|
||||
|
||||
static int hardware_concurrency();
|
||||
|
||||
protected:
|
||||
std::thread t;
|
||||
};
|
||||
|
||||
template<class Callable,class... Args>
|
||||
void paradiseo::smp::Thread::start(Callable&& f,Args&&... args)
|
||||
{
|
||||
t = std::thread(std::forward<Callable>(f), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /*THREAD_H_*/
|
||||
74
smp/src/topology/abstractTopology.h
Normal file
74
smp/src/topology/abstractTopology.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
<abstractTopology.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 ABSTRACT_TOPO_H_
|
||||
#define ABSTRACT_TOPO_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/** AbstractTopology: The Abstract Topology defines what is necessary to any topology.
|
||||
In order to know a topology, we just need to know how to construct it and what are the neighbors of each node, regardless of the type of topology (boolean or stochastic).
|
||||
|
||||
@see smp::topology::Topology, smp::topology::TopologyBuilder
|
||||
|
||||
*/
|
||||
|
||||
class AbstractTopology
|
||||
{
|
||||
public :
|
||||
|
||||
/**
|
||||
* Return a vector containing the index of nearby nodes according to the topology
|
||||
* @param idNode index of the node of which you want the neighbors.
|
||||
*/
|
||||
virtual std::vector<unsigned> getIdNeighbors(unsigned idIsland) const = 0;
|
||||
|
||||
/**
|
||||
* Construct or re-construct a topology with the given number of nodes.
|
||||
* @param nbNode number of nodes for the topology
|
||||
*/
|
||||
virtual void construct(unsigned nbNode) = 0;
|
||||
|
||||
/**
|
||||
*Changes the topology : removes any connection from/to the given node.
|
||||
*@param idNode index of the node to be isolated
|
||||
*/
|
||||
virtual void isolateNode(unsigned idNode) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
49
smp/src/topology/complete.cpp
Normal file
49
smp/src/topology/complete.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
<complete.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 <topology/complete.h>
|
||||
#include <vector>
|
||||
|
||||
void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||
{
|
||||
if(nbNode != matrix.size())
|
||||
{
|
||||
matrix.clear();
|
||||
|
||||
matrix.resize(nbNode);
|
||||
for(auto& line : matrix)
|
||||
line.resize(nbNode);
|
||||
|
||||
std::vector<bool> line;
|
||||
line.assign(nbNode,true);
|
||||
matrix.assign(nbNode, line);
|
||||
for(unsigned i = 0; i < nbNode; i++)
|
||||
matrix[i][i]=false;
|
||||
}
|
||||
}
|
||||
56
smp/src/topology/complete.h
Normal file
56
smp/src/topology/complete.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
<completeTopologyBuilder.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 COMPLETE_H_
|
||||
#define COMPLETE_H_
|
||||
|
||||
#include <vector>
|
||||
#include <topology/topologyBuilder.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/**
|
||||
*Complete: Inherit from TopologyBuilder. Represents a builder for a complete topology : each node has every other node for neighor.
|
||||
*/
|
||||
class Complete: public TopologyBuilder
|
||||
{
|
||||
public :
|
||||
/**
|
||||
*Fills the given matrix for a complete topology with the specified number of nodes.
|
||||
*/
|
||||
void operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
120
smp/src/topology/customBooleanTopology.cpp
Normal file
120
smp/src/topology/customBooleanTopology.cpp
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
<customBooleanTopology.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 <topology/customBooleanTopology.h>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
paradiseo::smp::CustomBooleanTopology::CustomBooleanTopology(std::string filename)
|
||||
{
|
||||
std::ifstream f(filename);
|
||||
|
||||
if(f)
|
||||
{
|
||||
int temp;
|
||||
unsigned size;
|
||||
bool isNeighbor, isFirst = true;
|
||||
std::string line;
|
||||
std::vector<bool> lineVector;
|
||||
|
||||
while(getline(f, line))
|
||||
{
|
||||
lineVector.clear();
|
||||
|
||||
//line contains a line of text from the file
|
||||
std::istringstream tokenizer(line);
|
||||
std::string token;
|
||||
|
||||
while(tokenizer >> temp >> std::skipws)
|
||||
{
|
||||
//white spaces are skipped, and the integer is converted to boolean, to be stored
|
||||
isNeighbor = (bool) temp;
|
||||
lineVector.push_back(isNeighbor);
|
||||
}
|
||||
|
||||
//if this is the first line, we must initiate the variable size
|
||||
if(isFirst)
|
||||
{
|
||||
size = lineVector.size();
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
//for each vector non empty, if the size is not equal to the others, error
|
||||
if(lineVector.size() != size && !lineVector.empty())
|
||||
throw std::runtime_error("Mistake in the topology, line " + std::to_string(_matrix.size()+1) );
|
||||
|
||||
if(!lineVector.empty())
|
||||
_matrix.push_back(lineVector);
|
||||
}
|
||||
|
||||
//for each vector, verify if the size is equal to the size of the final matrix
|
||||
for(auto& line : _matrix)
|
||||
if(line.size() != _matrix.size())
|
||||
throw std::runtime_error("Mistake in the topology, matrix is not squared" );
|
||||
|
||||
f.close () ;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Error occured while reading the topology file " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<unsigned> paradiseo::smp::CustomBooleanTopology::getIdNeighbors(unsigned idNode) const
|
||||
{
|
||||
std::vector<unsigned> neighbors;
|
||||
for(unsigned j = 0; j < _matrix.size();j++)
|
||||
if(_matrix[idNode][j])
|
||||
neighbors.push_back(j);
|
||||
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
void paradiseo::smp::CustomBooleanTopology::construct(unsigned nbNode)
|
||||
{
|
||||
assert(nbNode == _matrix.size());
|
||||
}
|
||||
|
||||
void paradiseo::smp::CustomBooleanTopology::isolateNode(unsigned idNode)
|
||||
{
|
||||
for(unsigned i = 0; i < _matrix.size(); i++)
|
||||
{
|
||||
//Line of idNode to false : no connection FROM this node
|
||||
_matrix[idNode][i] = false;
|
||||
|
||||
//Column of idNode to false : no connection TO this node
|
||||
_matrix[i][idNode] = false;
|
||||
}
|
||||
}
|
||||
77
smp/src/topology/customBooleanTopology.h
Normal file
77
smp/src/topology/customBooleanTopology.h
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
<customBooleanTopology.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 CUST_BOOL_TOPO_H_
|
||||
#define CUST_BOOL_TOPO_H_
|
||||
|
||||
#include <vector>
|
||||
#include <topology/abstractTopology.h>
|
||||
#include <string>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
class CustomBooleanTopology : public AbstractTopology
|
||||
{
|
||||
public :
|
||||
/**
|
||||
*Constructor for a custom topology from a file
|
||||
*@param filename Name of the file, must be in the same directory as the executable
|
||||
*/
|
||||
CustomBooleanTopology(std::string filename);
|
||||
|
||||
/**
|
||||
* Inherited from AbstractTopology
|
||||
* @see smp::topology::AbstractTopology::getIdNeighbors
|
||||
*/
|
||||
std::vector<unsigned> getIdNeighbors(unsigned idNode) const;
|
||||
|
||||
/**
|
||||
* Inherited from AbstractTopology : a custom topology cannot be reconstructed in a different way, so the method throws an error if nbNode doesn't match with the actual number of nodes.
|
||||
* @param nbNode number of nodes for the topology
|
||||
*/
|
||||
void construct(unsigned nbNode);
|
||||
|
||||
/**
|
||||
*Inherited from AbstractTopology : changes the topology : removes any connection from/to the given node.
|
||||
*@param idNode index of the node to be isolated
|
||||
*/
|
||||
void isolateNode(unsigned idNode);
|
||||
|
||||
private :
|
||||
std::vector<std::vector<bool>> _matrix;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
128
smp/src/topology/customStochasticTopology.cpp
Normal file
128
smp/src/topology/customStochasticTopology.cpp
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
<customStochasticTopology.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 <topology/customStochasticTopology.h>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
paradiseo::smp::CustomStochasticTopology::CustomStochasticTopology(std::string filename)
|
||||
{
|
||||
std::ifstream f(filename);
|
||||
if(f)
|
||||
{
|
||||
double temp;
|
||||
unsigned size;
|
||||
double isNeighbor, isFirst = true;
|
||||
std::string line;
|
||||
std::vector<double> lineVector;
|
||||
|
||||
while(getline(f, line))
|
||||
{
|
||||
lineVector.clear();
|
||||
|
||||
// Line contains a line of text from the file
|
||||
std::istringstream tokenizer(line);
|
||||
std::string token;
|
||||
|
||||
while(tokenizer>> temp >> std::skipws)
|
||||
{
|
||||
// White spaces are skipped, and the integer is converted to boolean, to be stored
|
||||
if(temp<0)
|
||||
isNeighbor = 0;
|
||||
else if(temp>1)
|
||||
isNeighbor = 1;
|
||||
else
|
||||
isNeighbor = (double) temp;
|
||||
lineVector.push_back(isNeighbor);
|
||||
}
|
||||
|
||||
// If this is the first line, we must initiate the variable size
|
||||
if(isFirst)
|
||||
{
|
||||
size = lineVector.size();
|
||||
isFirst=false;
|
||||
}
|
||||
|
||||
// For each vector non empty, if the size is not equal to the others, error
|
||||
if(lineVector.size() != size && !lineVector.empty())
|
||||
throw std::runtime_error("Mistake in the topology, line "+ std::to_string(_matrix.size()+1) );
|
||||
|
||||
if(!lineVector.empty())
|
||||
_matrix.push_back(lineVector);
|
||||
}
|
||||
|
||||
// For each vector, verify if the size is equal to the size of the final matrix
|
||||
for(auto& line : _matrix)
|
||||
if(line.size() != _matrix.size())
|
||||
throw std::runtime_error("Mistake in the topology, matrix is not square" );
|
||||
|
||||
f.close () ;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Error occured while reading the topology file " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<unsigned> paradiseo::smp::CustomStochasticTopology::getIdNeighbors(unsigned idNode) const
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_real_distribution<> dis(0,1);
|
||||
|
||||
std::vector<unsigned> neighbors;
|
||||
for(unsigned j = 0; j < _matrix.size(); j++)
|
||||
if(_matrix[idNode][j] > dis(gen))
|
||||
neighbors.push_back(j);
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
void paradiseo::smp::CustomStochasticTopology::construct(unsigned nbNode)
|
||||
{
|
||||
assert(nbNode == _matrix.size());
|
||||
}
|
||||
|
||||
void paradiseo::smp::CustomStochasticTopology::isolateNode(unsigned idNode)
|
||||
{
|
||||
for(unsigned i = 0; i < _matrix.size(); i++)
|
||||
{
|
||||
//Line of idNode to false : no connection FROM this node
|
||||
_matrix[idNode][i]=0;
|
||||
|
||||
//Column of idNode to false : no connection TO this node
|
||||
_matrix[i][idNode]=0;
|
||||
}
|
||||
}
|
||||
78
smp/src/topology/customStochasticTopology.h
Normal file
78
smp/src/topology/customStochasticTopology.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
<customStochasticTopology.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 CUST_STOCH_TOPO_H_
|
||||
#define CUST_STOCH_TOPO_H_
|
||||
|
||||
#include <vector>
|
||||
#include <topology/abstractTopology.h>
|
||||
#include <string>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
class CustomStochasticTopology : public AbstractTopology
|
||||
{
|
||||
public :
|
||||
|
||||
/**
|
||||
*Constructor for a custom topology from a file
|
||||
*@param filename Name of the file, must be in the same directory as the executable
|
||||
*/
|
||||
CustomStochasticTopology(std::string filename);
|
||||
|
||||
/**
|
||||
* Inherited from AbstractTopology
|
||||
* @see smp::topology::AbstractTopology::getIdNeighbors
|
||||
*/
|
||||
std::vector<unsigned> getIdNeighbors(unsigned idNode) const;
|
||||
|
||||
/**
|
||||
* Inherited from AbstractTopology : a custom topology cannot be reconstructed in a different way, so the method throws an error if nbNode doesn't match with the actual number of nodes.
|
||||
* @param nbNode number of nodes for the topology
|
||||
*/
|
||||
void construct(unsigned nbNode);
|
||||
|
||||
/**
|
||||
*Inherited from AbstractTopology : changes the topology : removes any connection from/to the given node.
|
||||
*@param idNode index of the node to be isolated
|
||||
*/
|
||||
void isolateNode(unsigned idNode);
|
||||
|
||||
private :
|
||||
std::vector<std::vector<double>> _matrix;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
65
smp/src/topology/hypercubic.cpp
Normal file
65
smp/src/topology/hypercubic.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
<hypercubic.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 <topology/hypercubic.h>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
|
||||
void paradiseo::smp::Hypercubic::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||
{
|
||||
if(nbNode != matrix.size())
|
||||
{
|
||||
// Check if the number of node is coherent with an hypercube
|
||||
assert((nbNode & (nbNode-1)) == 0);
|
||||
|
||||
unsigned power = 0, i, j;
|
||||
while((nbNode & 1 << power) == 0)
|
||||
power++;
|
||||
|
||||
matrix.clear();
|
||||
matrix.resize(nbNode);
|
||||
|
||||
for(auto& line : matrix)
|
||||
line.resize(nbNode);
|
||||
|
||||
// Construction
|
||||
matrix[0][0] = false;
|
||||
for(unsigned dim = 1; dim <= power; dim ++)
|
||||
{
|
||||
unsigned stepNbNode = 1 << (dim-1); //represents the number of nodes for the current step.
|
||||
for(i = 0; i < stepNbNode; i++)
|
||||
for(j = 0; j < stepNbNode; j++)
|
||||
{
|
||||
matrix[i+stepNbNode][j+stepNbNode]=matrix[i][j]; //Diagonal part
|
||||
matrix[i][j+stepNbNode]= matrix[i+stepNbNode][j] = (i == j); //Identity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
58
smp/src/topology/hypercubic.h
Normal file
58
smp/src/topology/hypercubic.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
<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 HYPERCUBIC_H_
|
||||
#define HYPERCUBIC_H_
|
||||
|
||||
#include <vector>
|
||||
#include <topology/topologyBuilder.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/**
|
||||
*Hypercubic: Inherit from TopologyBuilder. Represents a builder for an hypercubic topology.
|
||||
*The number of nodes must be a power of 2, and will be the degree of the hpercube. If it is not the case, the topology will not be built.
|
||||
*/
|
||||
class Hypercubic: public TopologyBuilder
|
||||
{
|
||||
public :
|
||||
/**
|
||||
*Fills the given matrix for a hypercubic topology with the specified number of nodes.
|
||||
*/
|
||||
void operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
90
smp/src/topology/mesh.cpp
Normal file
90
smp/src/topology/mesh.cpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
<mesh.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 <vector>
|
||||
#include <cmath>
|
||||
#include <topology/mesh.h>
|
||||
|
||||
void paradiseo::smp::Mesh::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||
{
|
||||
unsigned i = 0, j, height, width;
|
||||
std::vector<unsigned> listFact = paradiseo::smp::Mesh::factorization(nbNode);
|
||||
|
||||
// Compute width and height
|
||||
// Find the ratio height/width of the grid that matches best the variable _ratio
|
||||
while (i < listFact.size() - 1 && (double)listFact[i]*listFact[i] / nbNode < _ratio)
|
||||
i++;
|
||||
|
||||
// ListFact[i] contains first factor which produces a ratio above the variable _ratio,
|
||||
// or the last element if there is no ratio that can go over the variable _ratio.
|
||||
double r1 = (double)listFact[i] * listFact[i] / nbNode;
|
||||
double r2 = (double)listFact[i-1] * listFact[i-1] / nbNode;
|
||||
|
||||
// Which ratio (r1,r2) matches _ratio best?
|
||||
if (std::abs(r2 - _ratio) <= _ratio - r1)
|
||||
height = listFact[i-1];
|
||||
else
|
||||
height = listFact[i];
|
||||
|
||||
width = nbNode/height;
|
||||
|
||||
// Building matrix
|
||||
matrix.clear();
|
||||
|
||||
matrix.resize(nbNode);
|
||||
for(auto& line : matrix)
|
||||
line.resize(nbNode);
|
||||
|
||||
for(i = 0; i < matrix.size(); i++)
|
||||
{
|
||||
matrix[i][i]=false;
|
||||
for (j = i+1; j < matrix.size(); j++)
|
||||
{
|
||||
matrix[j][i] = matrix[i][j] = ((j-i == 1) && (j % width != 0)) || (j-i == width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void paradiseo::smp::Mesh::setRatio(double r)
|
||||
{
|
||||
_ratio = r;
|
||||
}
|
||||
|
||||
std::vector<unsigned> paradiseo::smp::Mesh::factorization(unsigned n) const
|
||||
{
|
||||
unsigned i;
|
||||
double max = std::sqrt(n+1);
|
||||
std::vector<unsigned> listFact;
|
||||
for(i=1; i < max; i++)
|
||||
{
|
||||
if((n/i)*i == n)
|
||||
listFact.push_back(i);
|
||||
}
|
||||
return listFact;
|
||||
}
|
||||
70
smp/src/topology/mesh.h
Normal file
70
smp/src/topology/mesh.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
<mesh.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 MESH_H_
|
||||
#define MESH_H_
|
||||
|
||||
#include <vector>
|
||||
#include <topology/topologyBuilder.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/**
|
||||
*Mesh: Inherit from TopologyBuilder. Represents a builder for a mesh topology : nodes are organised over a rectangular grid, and each node is connected to : 2 nodes (corner), 3 nodes (edge) or 4 nodes (center). The default mesh has a ratio near 1 (square), but the user can change the ratio between 0 and 1 (line to square)
|
||||
*/
|
||||
class Mesh : public TopologyBuilder
|
||||
{
|
||||
public :
|
||||
/**
|
||||
*Fills the given matrix for a mesh topology with the specified number of nodes.
|
||||
*/
|
||||
void operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const;
|
||||
|
||||
/**
|
||||
*Setter for the variable _ratio
|
||||
*/
|
||||
void setRatio(double r);
|
||||
|
||||
private :
|
||||
/**
|
||||
*Ratio of the grid, between 0 and 1 (default). The change will not be done before next construction of the topology.
|
||||
*/
|
||||
double _ratio=1;
|
||||
|
||||
std::vector<unsigned> factorization(unsigned n) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
50
smp/src/topology/ring.cpp
Normal file
50
smp/src/topology/ring.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
<ring.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 <vector>
|
||||
#include <topology/ring.h>
|
||||
|
||||
void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||
{
|
||||
if(nbNode != matrix.size())
|
||||
{
|
||||
matrix.clear();
|
||||
|
||||
matrix.resize(nbNode);
|
||||
for(auto& line : matrix)
|
||||
line.resize(nbNode);
|
||||
|
||||
std::vector<bool> line;
|
||||
line.assign(nbNode, false);
|
||||
matrix.assign(nbNode, line);
|
||||
|
||||
for(unsigned i=0; i < nbNode; i++)
|
||||
matrix[i][(i+1)%nbNode]=true;
|
||||
}
|
||||
}
|
||||
57
smp/src/topology/ring.h
Normal file
57
smp/src/topology/ring.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
<ring.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 RING_H_
|
||||
#define RING_H_
|
||||
|
||||
#include <vector>
|
||||
#include <topology/topologyBuilder.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/**
|
||||
*Ring: Inherit from TopologyBuilder. Represents a builder for a ring topology : each node has the next node for neighor. The last node is connected to the first.
|
||||
*/
|
||||
class Ring : public TopologyBuilder
|
||||
{
|
||||
public :
|
||||
/**
|
||||
*Fills the given matrix for a ring topology with the specified number of nodes.
|
||||
*/
|
||||
void operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
52
smp/src/topology/star.cpp
Normal file
52
smp/src/topology/star.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
<star.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 <vector>
|
||||
#include <topology/star.h>
|
||||
|
||||
void paradiseo::smp::Star::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||
{
|
||||
matrix.clear();
|
||||
|
||||
matrix.resize(nbNode);
|
||||
for(auto& line : matrix)
|
||||
line.resize(nbNode);
|
||||
|
||||
std::vector<bool> line (nbNode,false);
|
||||
|
||||
line[_center]=true;
|
||||
matrix.assign(nbNode,line);
|
||||
|
||||
matrix[_center][_center]=false;
|
||||
}
|
||||
|
||||
void paradiseo::smp::Star::setCenter(unsigned c)
|
||||
{
|
||||
_center=c;
|
||||
}
|
||||
68
smp/src/topology/star.h
Normal file
68
smp/src/topology/star.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
<star.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 STAR_H_
|
||||
#define STAR_H_
|
||||
|
||||
#include <vector>
|
||||
#include <topology/topologyBuilder.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/**
|
||||
*Star: Inherit from TopologyBuilder. Represents a builder for a star topology : each node excepted the center has every other node for neighor. The center node doesn't have any neighbor. The center is the first node by default.
|
||||
*/
|
||||
class Star : public TopologyBuilder
|
||||
{
|
||||
public :
|
||||
/**
|
||||
*Fills the given matrix for a star topology with the specified number of nodes.
|
||||
*/
|
||||
void operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const;
|
||||
|
||||
/**
|
||||
*Setter for the variable _center
|
||||
*/
|
||||
void setCenter(unsigned c);
|
||||
|
||||
private :
|
||||
/**
|
||||
*Index of the node which is the center. The change will not be done before next construction of the topology.
|
||||
*/
|
||||
unsigned _center=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
66
smp/src/topology/topology.cpp
Normal file
66
smp/src/topology/topology.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
<topology.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 TopologyType>
|
||||
std::vector<unsigned> paradiseo::smp::Topology<TopologyType>::getIdNeighbors(unsigned idNode) const
|
||||
{
|
||||
std::vector<unsigned> neighbors;
|
||||
for(unsigned j=0; j<_matrix.size();j++)
|
||||
if(_matrix[idNode][j]) neighbors.push_back(j);
|
||||
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
template <class TopologyType>
|
||||
void paradiseo::smp::Topology<TopologyType>::construct(unsigned nbNode)
|
||||
{
|
||||
_builder(nbNode, _matrix);
|
||||
}
|
||||
|
||||
|
||||
template <class TopologyType>
|
||||
void paradiseo::smp::Topology<TopologyType>::isolateNode(unsigned idNode)
|
||||
{
|
||||
for(unsigned i = 0; i < _matrix.size(); i++)
|
||||
{
|
||||
//Line of idNode to false : no connection FROM this node
|
||||
_matrix[idNode][i] = false;
|
||||
|
||||
//Column of idNode to false : no connection TO this node
|
||||
_matrix[i][idNode] = false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class TopologyType>
|
||||
TopologyType & paradiseo::smp::Topology<TopologyType>::getBuilder()
|
||||
{
|
||||
TopologyType &b=_builder;
|
||||
return b;
|
||||
}
|
||||
|
||||
94
smp/src/topology/topology.h
Normal file
94
smp/src/topology/topology.h
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
<topology.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 TOPOLOGY_H_
|
||||
#define TOPOLOGY_H_
|
||||
|
||||
#include <vector>
|
||||
#include <topology/abstractTopology.h>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/**
|
||||
Topology : Inherit from AbstractTopology and must be templated with the type of Topology (e.g : Ring, Star...)
|
||||
It represents the boolean topology, and cannot be used for Stochastic topology.
|
||||
|
||||
@see smp::topology::AbstractTopology
|
||||
*/
|
||||
|
||||
template<class TopologyType>
|
||||
class Topology : public AbstractTopology
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
Topology() = default;
|
||||
|
||||
/**
|
||||
* Inherited from AbstractTopology
|
||||
* @see smp::topology::AbstractTopology::getIdNeighbors
|
||||
*/
|
||||
std::vector<unsigned> getIdNeighbors(unsigned idNode) const;
|
||||
|
||||
/**
|
||||
* Inherited from AbstractTopology : construct or re-construct a topology with the given number of nodes
|
||||
* @param nbNode number of nodes for the topology
|
||||
*/
|
||||
void construct(unsigned nbNode);
|
||||
|
||||
/**
|
||||
*Inherited from AbstractTopology : changes the topology : removes any connection from/to the given node.
|
||||
*@param idNode index of the node to be isolated
|
||||
*/
|
||||
void isolateNode(unsigned idNode);
|
||||
|
||||
/**
|
||||
*Getter for the variable _builder by reference
|
||||
*/
|
||||
TopologyType & getBuilder();
|
||||
|
||||
private :
|
||||
|
||||
TopologyType _builder;
|
||||
std::vector<std::vector<bool>> _matrix;
|
||||
};
|
||||
|
||||
#include<topology/topology.cpp>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
58
smp/src/topology/topologyBuilder.h
Normal file
58
smp/src/topology/topologyBuilder.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
<abstractNode.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 TOPO_BUILDER_H_
|
||||
#define TOPO_BUILDER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace paradiseo
|
||||
{
|
||||
namespace smp
|
||||
{
|
||||
|
||||
/** TopologyBuilder: abstract class to build any boolean topology with a particular structure.
|
||||
*/
|
||||
|
||||
class TopologyBuilder
|
||||
{
|
||||
public :
|
||||
|
||||
/**
|
||||
*Build th topology with the given number of nodes in the matrix.
|
||||
*@see smp::topology::Ring, smp::topology::Star, smp::topology::Complete
|
||||
**/
|
||||
virtual void operator()(unsigned _nbNode, std::vector<std::vector<bool>>& _matrix) const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -11,11 +11,16 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
|||
######################################################################################
|
||||
|
||||
set (TEST_LIST
|
||||
t-smpThread
|
||||
t-smpScheduler
|
||||
t-smpMW_eoEasyEA
|
||||
t-smpMW_eoEasyPSO
|
||||
t-smpMW_eoSyncEasyPSO
|
||||
t-smpIsland
|
||||
t-smpTopo
|
||||
t-smpMI_Homogeneous
|
||||
t-smpMI_Heterogeneous
|
||||
t-smpMI_Wrapper
|
||||
t-smpCustomTopo
|
||||
)
|
||||
|
||||
######################################################################################
|
||||
|
|
@ -35,3 +40,15 @@ execute_process(
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/t-data.dat
|
||||
${CMAKE_CURRENT_BINARY_DIR}/t-data.dat)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/t-data.dat DESTINATION share${INSTALL_SUB_DIR}/smp/test COMPONENT tests)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data-topo-bool
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data-topo-bool)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data-topo-bool DESTINATION share${INSTALL_SUB_DIR}/smp/test COMPONENT tests)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data-topo-stoch
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data-topo-stoch)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data-topo-stoch DESTINATION share${INSTALL_SUB_DIR}/smp/test COMPONENT tests)
|
||||
|
|
|
|||
4
smp/test/data-topo-bool
Normal file
4
smp/test/data-topo-bool
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
0 1 0 0
|
||||
1 0 1 1
|
||||
0 1 0 1
|
||||
1 0 1 0
|
||||
3
smp/test/data-topo-stoch
Normal file
3
smp/test/data-topo-stoch
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.25 .5 .75
|
||||
.2 .1 .05
|
||||
.9 .2 .03
|
||||
117
smp/test/t-smpCustomTopo.cpp
Normal file
117
smp/test/t-smpCustomTopo.cpp
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#include <topology/customBooleanTopology.h>
|
||||
#include <topology/customStochasticTopology.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::vector<unsigned> value;
|
||||
|
||||
//TEST OF CUSTOM BOOLEAN TOPOLOGY
|
||||
CustomBooleanTopology topo_bool("data-topo-bool");
|
||||
std::vector<unsigned> neighbors = topo_bool.getIdNeighbors(0);
|
||||
|
||||
value.clear();
|
||||
value.push_back(1);
|
||||
assert(neighbors == value);
|
||||
///////////////////////////////////////////////////////
|
||||
neighbors = topo_bool.getIdNeighbors(1);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
value.push_back(2);
|
||||
value.push_back(3);
|
||||
assert(neighbors == value);
|
||||
//////////////////////////////////////////////////////
|
||||
neighbors = topo_bool.getIdNeighbors(2);
|
||||
|
||||
value.clear();
|
||||
value.push_back(1);
|
||||
value.push_back(3);
|
||||
assert(neighbors == value);
|
||||
//////////////////////////////////////////////////////
|
||||
neighbors = topo_bool.getIdNeighbors(3);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
value.push_back(2);
|
||||
assert(neighbors == value);
|
||||
|
||||
|
||||
//TEST OF CUSTOM STOCHASTIC TOPOLOGY
|
||||
CustomStochasticTopology topo_stoch("data-topo-stoch");
|
||||
std::vector<std::vector<double>> matrix;
|
||||
matrix.resize(3);
|
||||
for(auto& line : matrix)
|
||||
line.resize(3);
|
||||
|
||||
//Computation of the mean probability
|
||||
int it_nb = 1000;
|
||||
for(int i = 0 ; i < it_nb ; i++)
|
||||
{
|
||||
for(int j = 0; j < 3; j++)
|
||||
{
|
||||
neighbors = topo_stoch.getIdNeighbors(j);
|
||||
for(auto& node : neighbors)
|
||||
{
|
||||
matrix[j][node]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(auto& line : matrix)
|
||||
{
|
||||
for(auto& edge : line)
|
||||
edge = edge/it_nb;
|
||||
}
|
||||
|
||||
//Reading the actual matrix
|
||||
std::ifstream f("data-topo-stoch");
|
||||
std::vector<std::vector<double>> _matrix;
|
||||
if (f)
|
||||
{
|
||||
double temp;
|
||||
double isNeighbor;
|
||||
std::string line;
|
||||
std::vector<double> lineVector;
|
||||
|
||||
while(getline(f, line))
|
||||
{
|
||||
lineVector.clear();
|
||||
|
||||
//line contains a line of text from the file
|
||||
std::istringstream tokenizer(line);
|
||||
std::string token;
|
||||
|
||||
while(tokenizer >> temp >> std::skipws)
|
||||
{
|
||||
//white spaces are skipped, and the integer is converted to boolean, to be stored
|
||||
|
||||
if(temp<0)
|
||||
isNeighbor = 0;
|
||||
else if(temp>1)
|
||||
isNeighbor = 1;
|
||||
else
|
||||
isNeighbor = (double) temp;
|
||||
lineVector.push_back(isNeighbor);
|
||||
}
|
||||
|
||||
if(!lineVector.empty())
|
||||
_matrix.push_back(lineVector);
|
||||
}
|
||||
|
||||
f.close () ;
|
||||
}
|
||||
|
||||
//Comparison to the actual matrix : _matrix
|
||||
for(unsigned i = 0; i < matrix.size(); i++)
|
||||
for(unsigned j = 0; j < matrix.size(); j++)
|
||||
assert(std::abs(_matrix[i][j] - matrix[i][j]) < .05);
|
||||
}
|
||||
97
smp/test/t-smpIsland.cpp
Normal file
97
smp/test/t-smpIsland.cpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <smp.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 = 100;
|
||||
} 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
|
||||
eoGenContinue<Indi> genCont_2(param.maxGen); // generation continuation
|
||||
|
||||
// Define population
|
||||
eoPop<Indi> pop(param.popSize, chromInit);
|
||||
|
||||
try
|
||||
{
|
||||
// Island 1
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria(5);
|
||||
eoDetTournamentSelect<Indi> selectOne(2);
|
||||
eoSelectNumber<Indi> who(selectOne, 1);
|
||||
|
||||
MigPolicy<Indi> migPolicy;
|
||||
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy;
|
||||
|
||||
eoPop<Indi> pop(param.popSize, chromInit);
|
||||
Island<eoEasyEA,Indi> test(pop, intPolicy, migPolicy, genCont, plainEval, select, transform, replace);
|
||||
|
||||
// Island 2
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria_2(5);
|
||||
eoDetTournamentSelect<Indi> selectOne_2(2);
|
||||
eoSelectNumber<Indi> who_2(selectOne_2, 1);
|
||||
|
||||
MigPolicy<Indi> migPolicy_2;
|
||||
migPolicy_2.push_back(PolicyElement<Indi>(who_2, criteria_2));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy_2;
|
||||
|
||||
eoPop<Indi> pop2(param.popSize, chromInit);
|
||||
Island<eoEasyEA,Indi> test2(pop2, intPolicy_2, migPolicy_2, genCont_2, plainEval, select, transform, replace);
|
||||
|
||||
test();
|
||||
test2();
|
||||
|
||||
cout << test.getPop() << endl;
|
||||
cout << test2.getPop() << endl;
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
182
smp/test/t-smpMI_Heterogeneous.cpp
Normal file
182
smp/test/t-smpMI_Heterogeneous.cpp
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
#include <smp>
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
#include "smpTestClass.h"
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
using namespace std;
|
||||
|
||||
typedef eoBit<double> Indi2; // A bitstring with fitness double
|
||||
|
||||
// Conversion functions
|
||||
Indi2 fromBase(Indi& i, unsigned size)
|
||||
{
|
||||
(void)i;
|
||||
// Dummy conversion. We just create a new Indi2
|
||||
Indi2 v;
|
||||
for (unsigned ivar=0; ivar<size; ivar++)
|
||||
{
|
||||
bool r = rng.flip(); // new value, random in {0,1}
|
||||
v.push_back(r); // append that random value to v
|
||||
}
|
||||
std::cout << "Convert from base : " << v << std::endl;
|
||||
return v;
|
||||
}
|
||||
|
||||
Indi toBase(Indi2& i)
|
||||
{
|
||||
(void)i;
|
||||
// Dummy conversion. We just create a new Indi
|
||||
Indi v;
|
||||
std::cout << "Convert to base : " << v << std::endl;
|
||||
return v;
|
||||
}
|
||||
|
||||
// Eval function for the PSO
|
||||
// A simple fitness function that computes the number of ones of a bitstring
|
||||
// @param _Indi2 A biststring Indi2vidual
|
||||
|
||||
double binary_value(const Indi2 & _Indi2)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _Indi2.size(); i++)
|
||||
sum += _Indi2[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// PSO PART
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// PSO general parameters
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
const unsigned int VEC_SIZE = 16; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 10; // Size of population
|
||||
const unsigned int MAX_GEN = 10; // Maximum number of generation before STOP
|
||||
const float CROSS_RATE = 0.8; // Crossover rate
|
||||
const double P_MUT_PER_BIT = 0.01; // probability of bit-flip mutation
|
||||
const float MUT_RATE = 1.0; // mutation rate
|
||||
|
||||
rng.reseed(SEED);
|
||||
|
||||
eoEvalFuncPtr<Indi2> eval(binary_value);
|
||||
|
||||
// PSO population initialization
|
||||
eoPop<Indi2> pop;
|
||||
|
||||
for(unsigned int igeno=0; igeno<POP_SIZE; igeno++)
|
||||
{
|
||||
Indi2 v; // void Indi2vidual, to be filled
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
|
||||
{
|
||||
bool r = rng.flip(); // new value, random in {0,1}
|
||||
v.push_back(r); // append that random value to v
|
||||
}
|
||||
eval(v); // evaluate it
|
||||
pop.push_back(v); // and put it in the population
|
||||
}
|
||||
|
||||
// ISLAND 1 : PSO
|
||||
// // Algorithm part
|
||||
eoDetTournamentSelect<Indi2> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
eo1PtBitXover<Indi2> xover;
|
||||
eoBitMutation<Indi2> mutation(P_MUT_PER_BIT);
|
||||
eoGenContinue<Indi2> continuator(MAX_GEN);
|
||||
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi2> criteria(1);
|
||||
eoDetTournamentSelect<Indi2> selectOne(2);
|
||||
eoSelectNumber<Indi2> who(selectOne, 1);
|
||||
|
||||
MigPolicy<Indi2> migPolicy;
|
||||
migPolicy.push_back(PolicyElement<Indi2>(who, criteria));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi2> intPolicy;
|
||||
|
||||
// We bind conversion functions
|
||||
auto frombase = std::bind(fromBase, std::placeholders::_1, VEC_SIZE);
|
||||
auto tobase = std::bind(toBase, std::placeholders::_1);
|
||||
|
||||
Island<eoSGA,Indi2, Indi> gga(frombase, tobase, pop, intPolicy, migPolicy, select, xover, CROSS_RATE, mutation, MUT_RATE, eval, continuator);
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// EasyEA PART
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// EA general parameters
|
||||
typedef struct {
|
||||
unsigned popSize = 10;
|
||||
unsigned tSize = 2;
|
||||
double pCross = 0.8;
|
||||
double pMut = 0.7;
|
||||
unsigned maxGen = 10;
|
||||
} Param;
|
||||
|
||||
Param param;
|
||||
loadInstances("t-data.dat", n, bkv, a, b);
|
||||
|
||||
// Evaluation function
|
||||
IndiEvalFunc plainEval;
|
||||
|
||||
// Init a solution
|
||||
IndiInit chromInit;
|
||||
|
||||
// Define selection
|
||||
eoDetTournamentSelect<Indi> selectOne2(param.tSize);
|
||||
eoSelectPerc<Indi> select2(selectOne2);// 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
|
||||
eoPop<Indi> pop2(param.popSize, chromInit);
|
||||
|
||||
// ISLAND 2 : EasyEA
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria2(1);
|
||||
eoDetTournamentSelect<Indi> selectOne3(5);
|
||||
eoSelectNumber<Indi> who2(selectOne3, 2);
|
||||
|
||||
MigPolicy<Indi> migPolicy2;
|
||||
migPolicy2.push_back(PolicyElement<Indi>(who2, criteria2));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy2;
|
||||
|
||||
Island<eoEasyEA,Indi> test(pop2, intPolicy2, migPolicy2, genCont, plainEval, select2, transform, replace);
|
||||
|
||||
// MODEL CREATION
|
||||
Topology<Complete> topo;
|
||||
IslandModel<Indi> model(topo);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
model.add(test);
|
||||
model.add(gga);
|
||||
|
||||
model();
|
||||
|
||||
cout << test.getPop() << endl;
|
||||
cout << gga.getPop() << endl;
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
117
smp/test/t-smpMI_Homogeneous.cpp
Normal file
117
smp/test/t-smpMI_Homogeneous.cpp
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#include <smp>
|
||||
#include <eo>
|
||||
|
||||
#include "smpTestClass.h"
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
using namespace std;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Defining parameters
|
||||
typedef struct {
|
||||
unsigned popSize = 1000;
|
||||
unsigned tSize = 2;
|
||||
double pCross = 0.8;
|
||||
double pMut = 0.7;
|
||||
unsigned maxGen = 1000;
|
||||
} Param;
|
||||
|
||||
Param param;
|
||||
|
||||
// Fixing the seed
|
||||
rng.reseed(42);
|
||||
|
||||
// Load instance
|
||||
loadInstances("t-data.dat", n, bkv, a, b);
|
||||
|
||||
//Common part to all islands
|
||||
IndiEvalFunc plainEval;
|
||||
IndiInit chromInit;
|
||||
eoDetTournamentSelect<Indi> selectOne(param.tSize);
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
IndiXover Xover; // CROSSOVER
|
||||
IndiSwapMutation mutationSwap; // MUTATION
|
||||
eoSGATransform<Indi> transform(Xover, param.pCross, mutationSwap, param.pMut);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
// MODEL
|
||||
// Topologies
|
||||
Topology<Complete> topo;
|
||||
IslandModel<Indi> model(topo);
|
||||
|
||||
// ISLAND 1
|
||||
// // Algorithm part
|
||||
eoGenContinue<Indi> genCont(param.maxGen+100);
|
||||
eoPop<Indi> pop(param.popSize, chromInit);
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria(5);
|
||||
eoDetTournamentSelect<Indi> selectOne1(20);
|
||||
eoSelectNumber<Indi> who(selectOne1, 3);
|
||||
|
||||
MigPolicy<Indi> migPolicy;
|
||||
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy;
|
||||
|
||||
Island<eoEasyEA,Indi> test(pop, intPolicy, migPolicy, genCont, plainEval, select, transform, replace);
|
||||
|
||||
// ISLAND 1
|
||||
// // Algorithm part
|
||||
eoGenContinue<Indi> genCont_2(param.maxGen); // generation continuation
|
||||
eoPop<Indi> pop2(30, chromInit);
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria_2(5);
|
||||
eoDetTournamentSelect<Indi> selectOne_2(25);
|
||||
eoSelectNumber<Indi> who_2(selectOne_2, 5);
|
||||
|
||||
MigPolicy<Indi> migPolicy_2;
|
||||
migPolicy_2.push_back(PolicyElement<Indi>(who_2, criteria_2));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy_2;
|
||||
|
||||
Island<eoEasyEA,Indi> test2(pop2, intPolicy_2, migPolicy_2, genCont_2, plainEval, select, transform, replace);
|
||||
|
||||
// Island 3
|
||||
// // Algorithm part
|
||||
eoGenContinue<Indi> genCont_3(param.maxGen);
|
||||
eoPop<Indi> pop3(30, chromInit);
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria_3(10);
|
||||
eoDetTournamentSelect<Indi> selectOne_3(15);
|
||||
eoSelectNumber<Indi> who_3(selectOne_3, 1);
|
||||
|
||||
MigPolicy<Indi> migPolicy_3;
|
||||
migPolicy.push_back(PolicyElement<Indi>(who_3, criteria_3));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy_3;
|
||||
|
||||
Island<eoEasyEA,Indi> test3(pop3, intPolicy_3, migPolicy_3, genCont_3, plainEval, select, transform, replace);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
model.add(test);
|
||||
model.add(test2);
|
||||
model.add(test3);
|
||||
|
||||
model();
|
||||
|
||||
cout << test.getPop() << endl;
|
||||
cout << test2.getPop() << endl;
|
||||
cout << test3.getPop() << endl;
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
78
smp/test/t-smpMI_Wrapper.cpp
Normal file
78
smp/test/t-smpMI_Wrapper.cpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#include <smp>
|
||||
#include <eo>
|
||||
|
||||
#include "smpTestClass.h"
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
using namespace std;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Defining parameters
|
||||
typedef struct {
|
||||
unsigned popSize = 1000;
|
||||
unsigned tSize = 2;
|
||||
double pCross = 0.8;
|
||||
double pMut = 0.7;
|
||||
unsigned maxGen = 1000;
|
||||
} Param;
|
||||
|
||||
Param param;
|
||||
|
||||
// Fixing the seed
|
||||
rng.reseed(42);
|
||||
|
||||
// Load instance
|
||||
loadInstances("t-data.dat", n, bkv, a, b);
|
||||
|
||||
//Common part to all islands
|
||||
IndiEvalFunc plainEval;
|
||||
IndiInit chromInit;
|
||||
eoDetTournamentSelect<Indi> selectOne(param.tSize);
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
IndiXover Xover; // CROSSOVER
|
||||
IndiSwapMutation mutationSwap; // MUTATION
|
||||
eoSGATransform<Indi> transform(Xover, param.pCross, mutationSwap, param.pMut);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
// MODEL
|
||||
// Topologies
|
||||
Topology<Complete> topo;
|
||||
|
||||
// ISLAND 1
|
||||
// // Algorithm part
|
||||
eoGenContinue<Indi> genCont(param.maxGen+100);
|
||||
eoPop<Indi> pop(param.popSize, chromInit);
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria(5);
|
||||
eoDetTournamentSelect<Indi> selectOne1(20);
|
||||
eoSelectNumber<Indi> who(selectOne1, 3);
|
||||
|
||||
MigPolicy<Indi> migPolicy;
|
||||
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
std::vector<eoPop<Indi>> pops = IslandModelWrapper<eoEasyEA,Indi>(50, topo, 100, chromInit, intPolicy, migPolicy, genCont, plainEval, select, transform, replace);
|
||||
|
||||
for(auto& pop : pops)
|
||||
{
|
||||
for(auto& indi : pop)
|
||||
plainEval(indi);
|
||||
pop.sort();
|
||||
std::cout << pop << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
#include <smp>
|
||||
|
||||
#include "smpTestClass.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace paradiseo::smp;
|
||||
|
||||
void f(std::atomic<int> &x)
|
||||
{
|
||||
for(int i = 0; i < 100; i++) {
|
||||
cout << x << endl;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
void g(std::atomic<int> &x)
|
||||
{
|
||||
for(int i = 0; i < 100; i++)
|
||||
x--;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
std::cout << "Foo" << std::endl;
|
||||
//std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//---------------------------------------------------
|
||||
std::atomic<int> nb(0);
|
||||
|
||||
Thread t1(&f,std::ref(nb));
|
||||
Thread t2(&g,std::ref(nb));
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
|
||||
assert(nb == 0); // Test atomic_barrier
|
||||
|
||||
//--------------------------------------------------
|
||||
try
|
||||
{
|
||||
t1.start(foo);
|
||||
|
||||
t1.join();
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
191
smp/test/t-smpTopo.cpp
Normal file
191
smp/test/t-smpTopo.cpp
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
#include <smp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
std::vector<unsigned> value;
|
||||
|
||||
//Test of Complete Topology
|
||||
n=5;
|
||||
Topology<Complete> topo_comp;
|
||||
topo_comp.construct(n);
|
||||
|
||||
|
||||
std::vector<unsigned> neighbors = topo_comp.getIdNeighbors(1);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
value.push_back(2);
|
||||
value.push_back(3);
|
||||
value.push_back(4);
|
||||
assert(neighbors == value);
|
||||
|
||||
neighbors=topo_comp.getIdNeighbors(2);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
value.push_back(1);
|
||||
value.push_back(3);
|
||||
value.push_back(4);
|
||||
assert(neighbors == value);
|
||||
|
||||
//Isolate an node
|
||||
topo_comp.isolateNode(2);
|
||||
neighbors=topo_comp.getIdNeighbors(2);
|
||||
|
||||
assert(neighbors.empty());
|
||||
|
||||
neighbors=topo_comp.getIdNeighbors(3);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
value.push_back(1);
|
||||
value.push_back(4);
|
||||
assert(neighbors == value);
|
||||
|
||||
//Re-construct Topology with different number of nodes
|
||||
n=3;
|
||||
topo_comp.construct(n);
|
||||
neighbors=topo_comp.getIdNeighbors(2);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
value.push_back(1);
|
||||
assert(neighbors == value);
|
||||
|
||||
n=8;
|
||||
topo_comp.construct(n);
|
||||
neighbors = topo_comp.getIdNeighbors(3);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
value.push_back(1);
|
||||
value.push_back(2);
|
||||
value.push_back(4);
|
||||
value.push_back(5);
|
||||
value.push_back(6);
|
||||
value.push_back(7);
|
||||
assert(neighbors == value);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//Test of Star Topology
|
||||
n=4;
|
||||
Topology<Star> topo_star;
|
||||
topo_star.construct(n);
|
||||
|
||||
neighbors=topo_star.getIdNeighbors(0);
|
||||
|
||||
value.clear();
|
||||
assert(neighbors == value);
|
||||
//---------------------------------------
|
||||
neighbors=topo_star.getIdNeighbors(2);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
assert(neighbors == value);
|
||||
//---------------------------------------
|
||||
topo_star.getBuilder().setCenter(2);
|
||||
topo_star.construct(n);
|
||||
|
||||
neighbors=topo_star.getIdNeighbors(0);
|
||||
|
||||
value.clear();
|
||||
value.push_back(2);
|
||||
assert(neighbors == value);
|
||||
//---------------------------------------
|
||||
neighbors=topo_star.getIdNeighbors(2);
|
||||
value.clear();
|
||||
assert(neighbors == value);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//Test of Ring Topology
|
||||
n=8;
|
||||
Topology<Ring> topo_ring;
|
||||
topo_ring.construct(n);
|
||||
|
||||
neighbors=topo_ring.getIdNeighbors(4);
|
||||
|
||||
value.clear();
|
||||
value.push_back(5);
|
||||
assert(neighbors == value);
|
||||
//---------------------------------------
|
||||
neighbors=topo_ring.getIdNeighbors(7);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
assert(neighbors == value);
|
||||
//---------------------------------------
|
||||
neighbors=topo_ring.getIdNeighbors(0);
|
||||
|
||||
value.clear();
|
||||
value.push_back(1);
|
||||
assert(neighbors == value);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//Test of Hypercubic Topology
|
||||
n=2;
|
||||
Topology<Hypercubic> topo_hyper;
|
||||
topo_hyper.construct(n);
|
||||
|
||||
neighbors=topo_hyper.getIdNeighbors(0);
|
||||
|
||||
value.clear();
|
||||
value.push_back(1);
|
||||
assert(neighbors == value);
|
||||
//------------------------------------
|
||||
n=4;
|
||||
topo_hyper.construct(n);
|
||||
|
||||
neighbors=topo_hyper.getIdNeighbors(1);
|
||||
|
||||
value.clear();
|
||||
value.push_back(0);
|
||||
value.push_back(3);
|
||||
assert(neighbors == value);
|
||||
//-------------------------------------
|
||||
n=8;
|
||||
topo_hyper.construct(n);
|
||||
|
||||
neighbors=topo_hyper.getIdNeighbors(5);
|
||||
|
||||
value.clear();
|
||||
value.push_back(1);
|
||||
value.push_back(4);
|
||||
value.push_back(7);
|
||||
assert(neighbors == value);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//Test of Mesh Topology
|
||||
n=9;
|
||||
Topology<Mesh> topo_mesh;
|
||||
topo_mesh.construct(n);
|
||||
neighbors=topo_mesh.getIdNeighbors(0);
|
||||
|
||||
value.clear();
|
||||
value.push_back(1);
|
||||
value.push_back(3);
|
||||
assert(neighbors == value);
|
||||
//-------------------------------------
|
||||
topo_mesh.getBuilder().setRatio(0.4);
|
||||
topo_mesh.construct(n);
|
||||
neighbors=topo_mesh.getIdNeighbors(5);
|
||||
|
||||
value.clear();
|
||||
value.push_back(6);
|
||||
//assert(neighbors == value);
|
||||
//--------------------------------------
|
||||
n=8;
|
||||
topo_mesh.construct(n);
|
||||
neighbors=topo_mesh.getIdNeighbors(0);
|
||||
|
||||
value.clear();
|
||||
value.push_back(1);
|
||||
value.push_back(4);
|
||||
assert(neighbors == value);
|
||||
}
|
||||
272
smp/tutorial/BaseLesson.h
Normal file
272
smp/tutorial/BaseLesson.h
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
#ifndef _BASELESSON_H
|
||||
#define _BASELESSON_H
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n = 10;
|
||||
int** a;
|
||||
int** b;
|
||||
|
||||
int bkv; //best known value
|
||||
|
||||
struct parameters
|
||||
{
|
||||
unsigned seed ;
|
||||
int popSize;
|
||||
int tSize;
|
||||
string inst;
|
||||
string loadName;
|
||||
string schema;
|
||||
double pCross;
|
||||
double pMut;
|
||||
int minGen;
|
||||
int maxGen;
|
||||
};
|
||||
|
||||
class Indi : public EO<eoMinimizingFitness> {
|
||||
|
||||
public:
|
||||
|
||||
int* solution;
|
||||
int evalNb = 0;
|
||||
|
||||
Indi () {
|
||||
solution = new int[n];
|
||||
create();
|
||||
}
|
||||
|
||||
Indi (const Indi & _problem){ // copy constructor
|
||||
solution = new int[n];
|
||||
for (int i = 0; i < n ; i++){
|
||||
solution[i] = _problem.solution[i];
|
||||
}
|
||||
if (!_problem.invalid()) // if the solution has already been evaluated
|
||||
fitness(_problem.fitness()); // copy the fitness
|
||||
}
|
||||
|
||||
~Indi(){ // destructor
|
||||
delete[] solution;
|
||||
}
|
||||
|
||||
void operator= (const Indi & _problem){ // copy assignment operator
|
||||
for (int i = 0; i < n ; i++){
|
||||
solution[i] = _problem.solution[i];
|
||||
}
|
||||
fitness(_problem.fitness()); // copy the fitness
|
||||
}
|
||||
|
||||
int& operator[] (unsigned i)
|
||||
{
|
||||
return solution[i];
|
||||
}
|
||||
|
||||
|
||||
void create(){ // create and initialize a solution
|
||||
int random, temp;
|
||||
for (int i=0; i< n; i++)
|
||||
solution[i]=i;
|
||||
|
||||
// we want a random permutation so we shuffle
|
||||
for (int i = 0; i < n; i++){
|
||||
random = rand()%(n-i) + i;
|
||||
temp = solution[i];
|
||||
solution[i] = solution[random];
|
||||
solution[random] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
int evaluate() { // evaluate the solution
|
||||
int cost=0;
|
||||
for (int i=0; i<n; i++)
|
||||
for (int j=0; j<n; j++)
|
||||
cost += a[i][j] * b[solution[i]][solution[j]];
|
||||
evalNb++;
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
//std::cout << "Evaluation " << evalNb << std::endl;
|
||||
|
||||
return cost;
|
||||
}
|
||||
|
||||
|
||||
void printSolution() {
|
||||
for (int i = 0; i < n ; i++)
|
||||
std::cout << solution[i] << " " ;
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
class IndiInit : public eoInit<Indi>
|
||||
{
|
||||
public:
|
||||
|
||||
void operator()(Indi & _problem)
|
||||
{
|
||||
_problem.create();
|
||||
}
|
||||
};
|
||||
|
||||
class IndiEvalFunc : public eoEvalFunc<Indi>
|
||||
{
|
||||
public:
|
||||
|
||||
void operator()(Indi & _problem)
|
||||
{
|
||||
_problem.fitness(_problem.evaluate());
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class IndiXover : public eoQuadOp<Indi> {
|
||||
public:
|
||||
|
||||
/* The two parameters in input are the parents.
|
||||
The first parameter is also the output ie the child
|
||||
*/
|
||||
bool operator()(Indi & _problem1, Indi & _problem2)
|
||||
{
|
||||
int i;
|
||||
int random, temp;
|
||||
std::vector<int> unassigned_positions(n);
|
||||
std::vector<int> remaining_items(n);
|
||||
int j = 0;
|
||||
|
||||
/* 1) find the items assigned in different positions for the 2 parents */
|
||||
for (i = 0 ; i < n ; i++){
|
||||
if (_problem1.solution[i] != _problem2.solution[i]){
|
||||
unassigned_positions[j] = i;
|
||||
remaining_items[j] = _problem1.solution[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
/* 2) shuffle the remaining items to ensure that remaining items
|
||||
will be assigned at random positions */
|
||||
for (i = 0; i < j; i++){
|
||||
random = rand()%(j-i) + i;
|
||||
temp = remaining_items[i];
|
||||
remaining_items[i] = remaining_items[random];
|
||||
remaining_items[random] = temp;
|
||||
}
|
||||
|
||||
/* 3) copy the shuffled remaining items at unassigned positions */
|
||||
for (i = 0; i < j ; i++)
|
||||
_problem1.solution[unassigned_positions[i]] = remaining_items[i];
|
||||
|
||||
// crossover in our case is always possible
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class IndiSwapMutation: public eoMonOp<Indi> {
|
||||
public:
|
||||
|
||||
bool operator()(Indi& _problem) {
|
||||
int i,j;
|
||||
int temp;
|
||||
|
||||
// generate two different indices
|
||||
i=rand()%n;
|
||||
do
|
||||
j = rand()%n;
|
||||
while (i == j);
|
||||
|
||||
// swap
|
||||
temp = _problem.solution[i];
|
||||
_problem.solution[i] = _problem.solution[j];
|
||||
_problem.solution[j] = temp;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void parseFile(eoParser & parser, parameters & param)
|
||||
{
|
||||
|
||||
// For each parameter, you can in on single line
|
||||
// define the parameter, read it through the parser, and assign it
|
||||
|
||||
param.seed = parser.createParam(unsigned(time(0)), "seed", "Random number seed", 'S').value(); // will be in default section General
|
||||
|
||||
// init and stop
|
||||
param.loadName = parser.createParam(string(""), "Load","A save file to restart from",'L', "Persistence" ).value();
|
||||
|
||||
param.inst = parser.createParam(string(""), "inst","a dat file to read instances from",'i', "Persistence" ).value();
|
||||
|
||||
param.schema = parser.createParam(string(""), "schema","an xml file mapping process",'s', "Persistence" ).value();
|
||||
|
||||
param.popSize = parser.createParam(unsigned(10), "popSize", "Population size",'P', "Evolution engine" ).value();
|
||||
|
||||
param.tSize = parser.createParam(unsigned(2), "tSize", "Tournament size",'T', "Evolution Engine" ).value();
|
||||
|
||||
param.minGen = parser.createParam(unsigned(100), "minGen", "Minimum number of iterations",'g', "Stopping criterion" ).value();
|
||||
|
||||
param.maxGen = parser.createParam(unsigned(300), "maxGen", "Maximum number of iterations",'G', "Stopping criterion" ).value();
|
||||
|
||||
param.pCross = parser.createParam(double(0.6), "pCross", "Probability of Crossover", 'C', "Genetic Operators" ).value();
|
||||
|
||||
param.pMut = parser.createParam(double(0.1), "pMut", "Probability of Mutation", 'M', "Genetic Operators" ).value();
|
||||
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
string statusName = parser.createParam(str_status, "status","Status file",'S', "Persistence" ).value();
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusName != "")
|
||||
{
|
||||
ofstream os(statusName.c_str());
|
||||
os << parser; // and you can use that file as parameter file
|
||||
}
|
||||
}
|
||||
|
||||
void loadInstances(const char* filename, int& n, int& bkv, int** & a, int** & b)
|
||||
{
|
||||
|
||||
ifstream data_file;
|
||||
int i, j;
|
||||
data_file.open(filename);
|
||||
if (! data_file.is_open())
|
||||
{
|
||||
cout << "\n Error while reading the file " << filename << ". Please check if it exists !" << endl;
|
||||
exit (1);
|
||||
}
|
||||
data_file >> n;
|
||||
data_file >> bkv; // best known value
|
||||
// ****************** dynamic memory allocation ****************** /
|
||||
a = new int* [n];
|
||||
b = new int* [n];
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
a[i] = new int[n];
|
||||
b[i] = new int[n];
|
||||
}
|
||||
|
||||
// ************** read flows and distanceMatrixs matrices ************** /
|
||||
for (i = 0; i < n; i++)
|
||||
for (j = 0; j < n; j++)
|
||||
data_file >> a[i][j];
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
for (j = 0; j < n; j++)
|
||||
data_file >> b[i][j];
|
||||
|
||||
data_file.close();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -3,3 +3,18 @@
|
|||
######################################################################################
|
||||
|
||||
add_subdirectory(Lesson1)
|
||||
add_subdirectory(Lesson2)
|
||||
add_subdirectory(Lesson3)
|
||||
add_subdirectory(Lesson4)
|
||||
|
||||
######################################################################################
|
||||
### 0) Install BaseFile for all lessons and data
|
||||
######################################################################################
|
||||
|
||||
install(FILES BaseLesson.h DESTINATION include${INSTALL_SUB_DIR}/smp/tutorial COMPONENT tutorial)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lessonData.dat
|
||||
${CMAKE_CURRENT_BINARY_DIR}/lessonData.dat)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lessonData.dat DESTINATION share${INSTALL_SUB_DIR}/smp/tutorial COMPONENT tutorial)
|
||||
|
|
|
|||
|
|
@ -1,22 +1,15 @@
|
|||
/*
|
||||
<QAP.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
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 use,
|
||||
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".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
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,
|
||||
|
|
@ -34,7 +27,6 @@
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QAP_H
|
||||
#define QAP_H
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,15 @@
|
|||
/*
|
||||
<QAPGA.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
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 use,
|
||||
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".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -1,22 +1,15 @@
|
|||
/*
|
||||
<main.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
<lesson1_eoEasyEA.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
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 use,
|
||||
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".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -1,22 +1,15 @@
|
|||
/*
|
||||
<parserStruct.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
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 use,
|
||||
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".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -1,22 +1,15 @@
|
|||
/*
|
||||
<utils.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
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 use,
|
||||
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".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
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,
|
||||
|
|
@ -33,6 +26,7 @@
|
|||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef _UTILS_H
|
||||
#define _UTILS_H
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
23
smp/tutorial/Lesson2/CMakeLists.txt
Normal file
23
smp/tutorial/Lesson2/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Lesson 2
|
||||
|
||||
######################################################################################
|
||||
### 0) Define files
|
||||
######################################################################################
|
||||
|
||||
set(files
|
||||
lesson2_homogeneous
|
||||
)
|
||||
|
||||
######################################################################################
|
||||
### 1) Create the lesson
|
||||
######################################################################################
|
||||
|
||||
add_lesson(smp Lesson2 "${files}")
|
||||
|
||||
######################################################################################
|
||||
### 2) Include dependencies
|
||||
######################################################################################
|
||||
|
||||
include_directories(${EO_SRC_DIR}/src
|
||||
${SMP_SRC_DIR}/src
|
||||
${PROBLEMS_SRC_DIR})
|
||||
153
smp/tutorial/Lesson2/lesson2_homogeneous.cpp
Normal file
153
smp/tutorial/Lesson2/lesson2_homogeneous.cpp
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
<lesson2_homogeneous.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
|
||||
*/
|
||||
|
||||
/*///////////////////////////////////////////////////////////////////
|
||||
// SMP Tutorial 2 : Homogeneous Model
|
||||
// This file shows how to create an homogeneous
|
||||
// island model with 3 islands, a complete topology
|
||||
// and different parameters for each island.
|
||||
/*///////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <smp>
|
||||
#include <eo>
|
||||
|
||||
#include "../BaseLesson.h"
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
using namespace std;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Defining parameters
|
||||
typedef struct {
|
||||
unsigned popSize = 1000;
|
||||
unsigned tSize = 2;
|
||||
double pCross = 0.8;
|
||||
double pMut = 0.7;
|
||||
unsigned maxGen = 1000;
|
||||
} Param;
|
||||
|
||||
Param param;
|
||||
|
||||
// Fixing the seed
|
||||
rng.reseed(42);
|
||||
|
||||
// Load instance
|
||||
loadInstances("../lessonData.dat", n, bkv, a, b);
|
||||
|
||||
//Common part to all islands
|
||||
IndiEvalFunc plainEval;
|
||||
IndiInit chromInit;
|
||||
eoDetTournamentSelect<Indi> selectOne(param.tSize);
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
IndiXover Xover; // CROSSOVER
|
||||
IndiSwapMutation mutationSwap; // MUTATION
|
||||
eoSGATransform<Indi> transform(Xover, param.pCross, mutationSwap, param.pMut);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
// MODEL
|
||||
// Topologies
|
||||
Topology<Complete> topo;
|
||||
IslandModel<Indi> model(topo);
|
||||
|
||||
// ISLAND 1
|
||||
// // Algorithm part
|
||||
eoGenContinue<Indi> genCont(param.maxGen+100);
|
||||
eoPop<Indi> pop(param.popSize, chromInit);
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria(5);
|
||||
eoDetTournamentSelect<Indi> selectOne1(20);
|
||||
eoSelectNumber<Indi> who(selectOne1, 3);
|
||||
|
||||
MigPolicy<Indi> migPolicy;
|
||||
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy;
|
||||
|
||||
Island<eoEasyEA,Indi> test(pop, intPolicy, migPolicy, genCont, plainEval, select, transform, replace);
|
||||
|
||||
// ISLAND 1
|
||||
// // Algorithm part
|
||||
eoGenContinue<Indi> genCont_2(param.maxGen); // generation continuation
|
||||
eoPop<Indi> pop2(30, chromInit);
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria_2(5);
|
||||
eoDetTournamentSelect<Indi> selectOne_2(25);
|
||||
eoSelectNumber<Indi> who_2(selectOne_2, 5);
|
||||
|
||||
MigPolicy<Indi> migPolicy_2;
|
||||
migPolicy_2.push_back(PolicyElement<Indi>(who_2, criteria_2));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy_2;
|
||||
|
||||
Island<eoEasyEA,Indi> test2(pop2, intPolicy_2, migPolicy_2, genCont_2, plainEval, select, transform, replace);
|
||||
|
||||
// Island 3
|
||||
// // Algorithm part
|
||||
eoGenContinue<Indi> genCont_3(param.maxGen);
|
||||
eoPop<Indi> pop3(30, chromInit);
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria_3(10);
|
||||
eoDetTournamentSelect<Indi> selectOne_3(15);
|
||||
eoSelectNumber<Indi> who_3(selectOne_3, 1);
|
||||
|
||||
MigPolicy<Indi> migPolicy_3;
|
||||
migPolicy.push_back(PolicyElement<Indi>(who_3, criteria_3));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy_3;
|
||||
|
||||
Island<eoEasyEA,Indi> test3(pop3, intPolicy_3, migPolicy_3, genCont_3, plainEval, select, transform, replace);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
model.add(test);
|
||||
model.add(test2);
|
||||
model.add(test3);
|
||||
|
||||
model();
|
||||
|
||||
cout << test.getPop() << endl;
|
||||
cout << test2.getPop() << endl;
|
||||
cout << test3.getPop() << endl;
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
smp/tutorial/Lesson3/CMakeLists.txt
Normal file
23
smp/tutorial/Lesson3/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Lesson 3
|
||||
|
||||
######################################################################################
|
||||
### 0) Define files
|
||||
######################################################################################
|
||||
|
||||
set(files
|
||||
lesson3_heterogeneous
|
||||
)
|
||||
|
||||
######################################################################################
|
||||
### 1) Create the lesson
|
||||
######################################################################################
|
||||
|
||||
add_lesson(smp Lesson3 "${files}")
|
||||
|
||||
######################################################################################
|
||||
### 2) Include dependencies
|
||||
######################################################################################
|
||||
|
||||
include_directories(${EO_SRC_DIR}/src
|
||||
${SMP_SRC_DIR}/src
|
||||
${PROBLEMS_SRC_DIR})
|
||||
226
smp/tutorial/Lesson3/lesson3_heterogeneous.cpp
Normal file
226
smp/tutorial/Lesson3/lesson3_heterogeneous.cpp
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
/*
|
||||
<lesson3_heterogeneous.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
|
||||
*/
|
||||
|
||||
/*///////////////////////////////////////////////////////////////////
|
||||
// SMP Tutorial 3 : Heterogeneous Model
|
||||
// This file shows how to create an heterogeneous
|
||||
// island model with 2 islands : an eoEasyEA island and a PSO.
|
||||
// The file can be broken down into 3 parts :
|
||||
// The PSO part, with algorithm parameters and PSO Island creatation.
|
||||
// Then, the eoEasyEA part.
|
||||
// And finally, the model creation.
|
||||
// On top of that, you conversion functions are defined at the
|
||||
// begining of this file.
|
||||
/*///////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <smp>
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
#include "../BaseLesson.h"
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
using namespace std;
|
||||
|
||||
typedef eoBit<double> Indi2; // A bitstring with fitness double
|
||||
|
||||
// Conversion functions
|
||||
Indi2 fromBase(Indi& i, unsigned size)
|
||||
{
|
||||
(void)i;
|
||||
// Dummy conversion. We just create a new Indi2
|
||||
Indi2 v;
|
||||
for (unsigned ivar=0; ivar<size; ivar++)
|
||||
{
|
||||
bool r = rng.flip(); // new value, random in {0,1}
|
||||
v.push_back(r); // append that random value to v
|
||||
}
|
||||
std::cout << "Convert from base : " << v << std::endl;
|
||||
return v;
|
||||
}
|
||||
|
||||
Indi toBase(Indi2& i)
|
||||
{
|
||||
(void)i;
|
||||
// Dummy conversion. We just create a new Indi
|
||||
Indi v;
|
||||
std::cout << "Convert to base : " << v << std::endl;
|
||||
return v;
|
||||
}
|
||||
|
||||
// Eval function for the PSO
|
||||
// A simple fitness function that computes the number of ones of a bitstring
|
||||
// @param _Indi2 A biststring Indi2vidual
|
||||
|
||||
double binary_value(const Indi2 & _Indi2)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _Indi2.size(); i++)
|
||||
sum += _Indi2[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// PSO PART
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// PSO general parameters
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
const unsigned int VEC_SIZE = 16; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 10; // Size of population
|
||||
const unsigned int MAX_GEN = 10; // Maximum number of generation before STOP
|
||||
const float CROSS_RATE = 0.8; // Crossover rate
|
||||
const double P_MUT_PER_BIT = 0.01; // probability of bit-flip mutation
|
||||
const float MUT_RATE = 1.0; // mutation rate
|
||||
|
||||
rng.reseed(SEED);
|
||||
|
||||
eoEvalFuncPtr<Indi2> eval(binary_value);
|
||||
|
||||
// PSO population initialization
|
||||
eoPop<Indi2> pop;
|
||||
|
||||
for(unsigned int igeno=0; igeno<POP_SIZE; igeno++)
|
||||
{
|
||||
Indi2 v; // void Indi2vidual, to be filled
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
|
||||
{
|
||||
bool r = rng.flip(); // new value, random in {0,1}
|
||||
v.push_back(r); // append that random value to v
|
||||
}
|
||||
eval(v); // evaluate it
|
||||
pop.push_back(v); // and put it in the population
|
||||
}
|
||||
|
||||
// ISLAND 1 : PSO
|
||||
// // Algorithm part
|
||||
eoDetTournamentSelect<Indi2> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
eo1PtBitXover<Indi2> xover;
|
||||
eoBitMutation<Indi2> mutation(P_MUT_PER_BIT);
|
||||
eoGenContinue<Indi2> continuator(MAX_GEN);
|
||||
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi2> criteria(1);
|
||||
eoDetTournamentSelect<Indi2> selectOne(2);
|
||||
eoSelectNumber<Indi2> who(selectOne, 1);
|
||||
|
||||
MigPolicy<Indi2> migPolicy;
|
||||
migPolicy.push_back(PolicyElement<Indi2>(who, criteria));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi2> intPolicy;
|
||||
|
||||
// We bind conversion functions
|
||||
auto frombase = std::bind(fromBase, std::placeholders::_1, VEC_SIZE);
|
||||
auto tobase = std::bind(toBase, std::placeholders::_1);
|
||||
|
||||
Island<eoSGA,Indi2, Indi> gga(frombase, tobase, pop, intPolicy, migPolicy, select, xover, CROSS_RATE, mutation, MUT_RATE, eval, continuator);
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// EasyEA PART
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// EA general parameters
|
||||
typedef struct {
|
||||
unsigned popSize = 10;
|
||||
unsigned tSize = 2;
|
||||
double pCross = 0.8;
|
||||
double pMut = 0.7;
|
||||
unsigned maxGen = 10;
|
||||
} Param;
|
||||
|
||||
Param param;
|
||||
loadInstances("../lessonData.dat", n, bkv, a, b);
|
||||
|
||||
// Evaluation function
|
||||
IndiEvalFunc plainEval;
|
||||
|
||||
// Init a solution
|
||||
IndiInit chromInit;
|
||||
|
||||
// Define selection
|
||||
eoDetTournamentSelect<Indi> selectOne2(param.tSize);
|
||||
eoSelectPerc<Indi> select2(selectOne2);// 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
|
||||
eoPop<Indi> pop2(param.popSize, chromInit);
|
||||
|
||||
// ISLAND 2 : EasyEA
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria2(1);
|
||||
eoDetTournamentSelect<Indi> selectOne3(5);
|
||||
eoSelectNumber<Indi> who2(selectOne3, 2);
|
||||
|
||||
MigPolicy<Indi> migPolicy2;
|
||||
migPolicy2.push_back(PolicyElement<Indi>(who2, criteria2));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy2;
|
||||
|
||||
Island<eoEasyEA,Indi> test(pop2, intPolicy2, migPolicy2, genCont, plainEval, select2, transform, replace);
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
// MODEL CREATION
|
||||
Topology<Complete> topo;
|
||||
IslandModel<Indi> model(topo);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
model.add(test);
|
||||
model.add(gga);
|
||||
|
||||
model();
|
||||
|
||||
cout << test.getPop() << endl;
|
||||
cout << gga.getPop() << endl;
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
smp/tutorial/Lesson4/CMakeLists.txt
Normal file
23
smp/tutorial/Lesson4/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Lesson 4
|
||||
|
||||
######################################################################################
|
||||
### 0) Define files
|
||||
######################################################################################
|
||||
|
||||
set(files
|
||||
lesson4_topology
|
||||
)
|
||||
|
||||
######################################################################################
|
||||
### 1) Create the lesson
|
||||
######################################################################################
|
||||
|
||||
add_lesson(smp Lesson4 "${files}")
|
||||
|
||||
######################################################################################
|
||||
### 2) Include dependencies
|
||||
######################################################################################
|
||||
|
||||
include_directories(${EO_SRC_DIR}/src
|
||||
${SMP_SRC_DIR}/src
|
||||
${PROBLEMS_SRC_DIR})
|
||||
139
smp/tutorial/Lesson4/lesson4_topology.cpp
Normal file
139
smp/tutorial/Lesson4/lesson4_topology.cpp
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
<lesson4_topology.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
|
||||
*/
|
||||
|
||||
/*///////////////////////////////////////////////////////////////////
|
||||
// SMP Tutorial 4 : Advanced Island Model Mecanisms
|
||||
// This file shows how to create events called by islands.
|
||||
// In our case, we would like to change the topology after 10 seconds
|
||||
// of computation.
|
||||
/*///////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <smp>
|
||||
#include <eo>
|
||||
#include <chrono>
|
||||
|
||||
#include "../BaseLesson.h"
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
Simple function to change topology of a given model, once, after 10 seconds.
|
||||
*/
|
||||
void changeTopo(IslandModel<Indi>* _model, AbstractTopology& _topo)
|
||||
{
|
||||
static auto start = std::chrono::system_clock::now();
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto elapsed = now - start;
|
||||
static bool first = false;
|
||||
if(std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count() > 10000 && !first)
|
||||
{
|
||||
std::cout << "Changing topology !" << std::endl;
|
||||
_model->setTopology(_topo);
|
||||
first = true;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Defining parameters
|
||||
typedef struct {
|
||||
unsigned popSize = 1000;
|
||||
unsigned tSize = 2;
|
||||
double pCross = 0.8;
|
||||
double pMut = 0.7;
|
||||
unsigned maxGen = 1000;
|
||||
} Param;
|
||||
|
||||
Param param;
|
||||
|
||||
// Load instance
|
||||
loadInstances("../lessonData.dat", n, bkv, a, b);
|
||||
|
||||
//Common part to all islands
|
||||
IndiEvalFunc plainEval;
|
||||
IndiInit chromInit;
|
||||
eoDetTournamentSelect<Indi> selectOne(param.tSize);
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
IndiXover Xover; // CROSSOVER
|
||||
IndiSwapMutation mutationSwap; // MUTATION
|
||||
eoSGATransform<Indi> transform(Xover, param.pCross, mutationSwap, param.pMut);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
// MODEL
|
||||
// Topologies
|
||||
Topology<Complete> topo;
|
||||
IslandModel<Indi> model(topo);
|
||||
|
||||
// ISLAND 1
|
||||
// // Algorithm part
|
||||
eoGenContinue<Indi> genCont(param.maxGen+100);
|
||||
eoPop<Indi> pop(param.popSize, chromInit);
|
||||
// // Emigration policy
|
||||
// // // Element 1
|
||||
eoPeriodicContinue<Indi> criteria(5);
|
||||
eoDetTournamentSelect<Indi> selectOne1(20);
|
||||
eoSelectNumber<Indi> who(selectOne1, 3);
|
||||
|
||||
Topology<Ring> topo2;
|
||||
|
||||
/*
|
||||
We need to bind our function in a std::function object.
|
||||
Then, we create a Notifier that we add to our island thanks
|
||||
to an eoCheckPoint.
|
||||
*/
|
||||
auto task = std::bind(changeTopo, &model, topo2);
|
||||
Notifier topoChanger(task);
|
||||
eoCheckPoint<Indi> ck(genCont);
|
||||
ck.add(topoChanger);
|
||||
|
||||
MigPolicy<Indi> migPolicy;
|
||||
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
|
||||
|
||||
// // Integration policy
|
||||
eoPlusReplacement<Indi> intPolicy;
|
||||
|
||||
Island<eoEasyEA,Indi> test(pop, intPolicy, migPolicy, ck, plainEval, select, transform, replace);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
model.add(test);
|
||||
|
||||
// The topology will change after 10 seconds of computation
|
||||
model();
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
27
smp/tutorial/lessonData.dat
Normal file
27
smp/tutorial/lessonData.dat
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
12 224416
|
||||
|
||||
0 27 85 2 1 15 11 35 11 20 21 61
|
||||
27 0 80 58 21 76 72 44 85 94 90 51
|
||||
85 80 0 3 48 29 90 66 41 15 83 96
|
||||
2 58 3 0 74 45 65 40 54 83 14 71
|
||||
1 21 48 74 0 77 36 53 37 26 87 76
|
||||
15 76 29 45 77 0 91 13 29 11 77 32
|
||||
11 72 90 65 36 91 0 87 67 94 79 2
|
||||
35 44 66 40 53 13 87 0 10 99 56 70
|
||||
11 85 41 54 37 29 67 10 0 99 60 4
|
||||
20 94 15 83 26 11 94 99 99 0 56 2
|
||||
21 90 83 14 87 77 79 56 60 56 0 60
|
||||
61 51 96 71 76 32 2 70 4 2 60 0
|
||||
|
||||
0 21 95 82 56 41 6 25 10 4 63 6
|
||||
21 0 44 40 75 79 0 89 35 9 1 85
|
||||
95 44 0 84 12 0 26 91 11 35 82 26
|
||||
82 40 84 0 69 56 86 45 91 59 18 76
|
||||
56 75 12 69 0 39 18 57 36 61 36 21
|
||||
41 79 0 56 39 0 71 11 29 82 82 6
|
||||
6 0 26 86 18 71 0 71 8 77 74 30
|
||||
25 89 91 45 57 11 71 0 89 76 76 40
|
||||
10 35 11 91 36 29 8 89 0 93 56 1
|
||||
4 9 35 59 61 82 77 76 93 0 50 4
|
||||
63 1 82 18 36 82 74 76 56 50 0 36
|
||||
6 85 26 76 21 6 30 40 1 4 36 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue