Merge branch 'master' of git+ssh://localhost:8481/gitroot/paradiseo/paradiseo
This commit is contained in:
commit
6cd61e2e2c
28 changed files with 560 additions and 425 deletions
|
|
@ -35,6 +35,7 @@ SET(GLOBAL_VERSION "${VERSION}")
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
## Optional
|
## Optional
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/module" CACHE INTERNAL "Cmake module" FORCE)
|
||||||
include(FindDoxygen OPTIONAL)
|
include(FindDoxygen OPTIONAL)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
|
||||||
39
cmake/module/FindEigen3.cmake
Normal file
39
cmake/module/FindEigen3.cmake
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
macro(_eigen3_check_version)
|
||||||
|
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
|
||||||
|
|
||||||
|
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
|
||||||
|
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
|
||||||
|
set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
|
||||||
|
set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
|
||||||
|
set(EIGEN3_VERSION_OK TRUE)
|
||||||
|
endmacro(_eigen3_check_version)
|
||||||
|
|
||||||
|
if (EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
_eigen3_check_version( )
|
||||||
|
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
|
||||||
|
|
||||||
|
else (EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
|
||||||
|
PATHS
|
||||||
|
${PROJECT_SOURCE_DIR}/External
|
||||||
|
${CMAKE_INSTALL_PREFIX}/include
|
||||||
|
${KDE4_INCLUDE_DIR}
|
||||||
|
PATH_SUFFIXES eigen3 eigen
|
||||||
|
)
|
||||||
|
|
||||||
|
if(EIGEN3_INCLUDE_DIR)
|
||||||
|
_eigen3_check_version( )
|
||||||
|
endif(EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
|
||||||
|
|
||||||
|
mark_as_advanced(EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
endif(EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ endif()
|
||||||
|
|
||||||
# enabled components
|
# enabled components
|
||||||
if ("${Paradiseo_FIND_COMPONENTS}" STREQUAL "")
|
if ("${Paradiseo_FIND_COMPONENTS}" STREQUAL "")
|
||||||
set(PARADISEO_LIBRARIES_TO_FIND eo eoutils edoutils cma es flowshop ga moeo)
|
set(PARADISEO_LIBRARIES_TO_FIND eo eoutils cma es flowshop ga moeo)
|
||||||
else()
|
else()
|
||||||
set(PARADISEO_LIBRARIES_TO_FIND ${Paradiseo_FIND_COMPONENTS})
|
set(PARADISEO_LIBRARIES_TO_FIND ${Paradiseo_FIND_COMPONENTS})
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -64,10 +64,6 @@ find_path(EO_INCLUDE_DIR eo
|
||||||
PATH_SUFFIXES include${INSTALL_SUB_DIR}/eo eo/src
|
PATH_SUFFIXES include${INSTALL_SUB_DIR}/eo eo/src
|
||||||
PATHS ${PARADISEO_SRC_PATHS})
|
PATHS ${PARADISEO_SRC_PATHS})
|
||||||
|
|
||||||
find_path(EDO_INCLUDE_DIR edo
|
|
||||||
PATH_SUFFIXES include${INSTALL_SUB_DIR}/edo edo/src
|
|
||||||
PATHS ${PARADISEO_SRC_PATHS})
|
|
||||||
|
|
||||||
find_path(MO_INCLUDE_DIR mo
|
find_path(MO_INCLUDE_DIR mo
|
||||||
PATH_SUFFIXES include${INSTALL_SUB_DIR}/mo mo/src
|
PATH_SUFFIXES include${INSTALL_SUB_DIR}/mo mo/src
|
||||||
PATHS ${PARADISEO_SRC_PATHS})
|
PATHS ${PARADISEO_SRC_PATHS})
|
||||||
|
|
@ -85,7 +81,12 @@ foreach(COMP ${PARADISEO_LIBRARIES_TO_FIND})
|
||||||
PATHS ${PARADISEO_SRC_PATHS})
|
PATHS ${PARADISEO_SRC_PATHS})
|
||||||
elseif(${COMP} STREQUAL "peo")
|
elseif(${COMP} STREQUAL "peo")
|
||||||
set(PEO_FOUND true)
|
set(PEO_FOUND true)
|
||||||
find_path(PEO_INCLUDE_DIR peo
|
find_path(EDO_INCLUDE_DIR edo
|
||||||
|
PATH_SUFFIXES include${INSTALL_SUB_DIR}/edo edo/src
|
||||||
|
PATHS ${PARADISEO_SRC_PATHS})
|
||||||
|
elseif(${COMP} STREQUAL "edo")
|
||||||
|
set(EDO_FOUND true)
|
||||||
|
find_path(EDO_INCLUDE_DIR peo
|
||||||
PATH_SUFFIXES include${INSTALL_SUB_DIR}/peo peo/src
|
PATH_SUFFIXES include${INSTALL_SUB_DIR}/peo peo/src
|
||||||
PATHS ${PARADISEO_SRC_PATHS})
|
PATHS ${PARADISEO_SRC_PATHS})
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,25 @@
|
||||||
|
|
||||||
IF(EDO_USE_LIB STREQUAL "uBLAS")
|
if(EDO_USE_LIB STREQUAL "uBLAS")
|
||||||
FIND_PACKAGE(Boost )
|
find_package(Boost)
|
||||||
IF( Boost_FOUND )
|
if(Boost_FOUND)
|
||||||
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )
|
include_directories( ${Boost_INCLUDE_DIRS} )
|
||||||
ADD_DEFINITIONS( -DWITH_BOOST )
|
add_definitions( -DWITH_BOOST )
|
||||||
ELSE()
|
else()
|
||||||
MESSAGE( "ERROR: You asked for Boost::uBLAS but it has not been found." )
|
message(FATAL_ERROR "\n\nERROR: You asked for Boost::uBLAS but it has not been found.\n" )
|
||||||
SET(IS_FATAL 1)
|
endif()
|
||||||
ENDIF()
|
elseif(EDO_USE_LIB STREQUAL "Eigen3")
|
||||||
ELSEIF( EDO_USE_LIB STREQUAL "Eigen3" )
|
find_package(Eigen3)
|
||||||
# FIXME FindEigen3.cmake does not work
|
if(EIGEN3_FOUND)
|
||||||
#find_package(Eigen3)
|
include_directories(EIGEN3_INCLUDE_DIR)
|
||||||
#include_directories(EIGEN3_INCLUDE_DIR)
|
add_definitions( -DWITH_EIGEN )
|
||||||
SET( EIGEN3_FOUND 1)
|
else()
|
||||||
SET( EIGEN3_INCLUDE_DIR "/usr/include/eigen3/" )
|
message(FATAL_ERROR "\n\nERROR: You asked for Eigen3 but it has not been found.\n" )
|
||||||
|
endif()
|
||||||
|
|
||||||
IF( EIGEN3_FOUND )
|
else()
|
||||||
INCLUDE_DIRECTORIES( ${EIGEN3_INCLUDE_DIR} )
|
|
||||||
ADD_DEFINITIONS( -DWITH_EIGEN )
|
|
||||||
ELSE()
|
|
||||||
MESSAGE( "ERROR: You asked for Eigen3 but it has not been found." )
|
|
||||||
SET(IS_FATAL 1)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
ELSE()
|
|
||||||
# FIXME ideally, we would have a minimal implementation with STL vectors…
|
# FIXME ideally, we would have a minimal implementation with STL vectors…
|
||||||
MESSAGE( "You must set EDO_USE_LIB to either 'uBLAS' or 'Eigen3'." )
|
message(FATAL_ERROR "\n\nYou must set EDO_USE_LIB to either 'uBLAS' or 'Eigen3'.\n" )
|
||||||
SET(IS_FATAL 1)
|
endif()
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
@ -37,14 +29,14 @@ ENDIF()
|
||||||
add_subdirectory(doc)
|
add_subdirectory(doc)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
if(ENABLE_CMAKE_TESTING)
|
if(ENABLE_CMAKE_TESTING AND EIGEN3_FOUND) # see edoNormalAdaptive
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif(ENABLE_CMAKE_TESTING)
|
endif()
|
||||||
|
|
||||||
if(ENABLE_CMAKE_EXAMPLE)
|
if(ENABLE_CMAKE_EXAMPLE)
|
||||||
if(${CMAKE_VERBOSE_MAKEFILE})
|
if(${CMAKE_VERBOSE_MAKEFILE})
|
||||||
message("EDO examples:")
|
message("EDO examples:")
|
||||||
endif(${CMAKE_VERBOSE_MAKEFILE})
|
endif(${CMAKE_VERBOSE_MAKEFILE})
|
||||||
add_subdirectory(application)
|
add_subdirectory(application)
|
||||||
endif(ENABLE_CMAKE_EXAMPLE)
|
endif()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,18 @@
|
||||||
### 1) Where do we go now ?!?
|
### 1) Where do we go now ?!?
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(
|
include_directories(
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/common
|
${CMAKE_CURRENT_SOURCE_DIR}/common
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(common) # Rosenbrock and Sphere
|
include_directories(${EIGEN3_INCLUDE_DIR})
|
||||||
#ADD_SUBDIRECTORY(eda_sa)
|
|
||||||
ADD_SUBDIRECTORY(eda)
|
add_subdirectory(common) # Rosenbrock and Sphere
|
||||||
ADD_SUBDIRECTORY(cmaes)
|
#add_subdirectory(eda_sa)
|
||||||
|
|
||||||
|
if(EIGEN3_FOUND) # see edoNormalAdaptive
|
||||||
|
add_subdirectory(eda)
|
||||||
|
add_subdirectory(cmaes)
|
||||||
|
endif()
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ include_directories(${Boost_INCLUDE_DIRS})
|
||||||
link_directories(${Boost_LIBRARY_DIRS})
|
link_directories(${Boost_LIBRARY_DIRS})
|
||||||
|
|
||||||
include_directories(${EO_SRC_DIR}/src)
|
include_directories(${EO_SRC_DIR}/src)
|
||||||
include_directories(${EDO_SRC_DIR}/src)
|
|
||||||
link_directories(${EO_BIN_DIR}/${LIB})
|
link_directories(${EO_BIN_DIR}/${LIB})
|
||||||
|
include_directories(${EDO_SRC_DIR}/src)
|
||||||
link_directories(${EDO_BIN_DIR}/${LIB})
|
link_directories(${EDO_BIN_DIR}/${LIB})
|
||||||
|
|
||||||
set(RESOURCES
|
set(RESOURCES
|
||||||
|
|
|
||||||
|
|
@ -23,17 +23,13 @@
|
||||||
### 3) Define your targets and link the librairies
|
### 3) Define your targets and link the librairies
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
find_package(Boost 1.33.0)
|
|
||||||
|
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
|
||||||
link_directories(${Boost_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/application/common)
|
include_directories(${CMAKE_SOURCE_DIR}/application/common)
|
||||||
include_directories(${EO_SRC_DIR}/src)
|
include_directories(${EO_SRC_DIR}/src)
|
||||||
include_directories(${EDO_SRC_DIR}/src)
|
include_directories(${EDO_SRC_DIR}/src)
|
||||||
|
|
||||||
|
include_directories(${EIGEN3_INCLUDE_DIR})
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
#t-cholesky
|
#t-cholesky
|
||||||
t-variance
|
t-variance
|
||||||
|
|
@ -42,14 +38,14 @@ set(SOURCES
|
||||||
t-bounderno
|
t-bounderno
|
||||||
t-uniform
|
t-uniform
|
||||||
t-continue
|
t-continue
|
||||||
t-dispatcher-round
|
# t-dispatcher-round
|
||||||
t-repairer-modulo
|
t-repairer-modulo
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach(current ${SOURCES})
|
foreach(current ${SOURCES})
|
||||||
add_executable(${current} ${current}.cpp)
|
add_executable(${current} ${current}.cpp)
|
||||||
add_test(${current} ${current})
|
add_test(${current} ${current})
|
||||||
target_link_libraries(${current} eo eoutils edoutils ${Boost_LIBRARIES})
|
target_link_libraries(${current} eo eoutils edoutils)
|
||||||
install(TARGETS ${current} RUNTIME DESTINATION share/edo/test COMPONENT test)
|
install(TARGETS ${current} RUNTIME DESTINATION share/edo/test COMPONENT test)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,6 @@
|
||||||
#include <eoEvalCounterThrowException.h>
|
#include <eoEvalCounterThrowException.h>
|
||||||
#include <eoEvalTimeThrowException.h>
|
#include <eoEvalTimeThrowException.h>
|
||||||
#include <eoEvalUserTimeThrowException.h>
|
#include <eoEvalUserTimeThrowException.h>
|
||||||
#include <eoEvalKeepBest.h>
|
|
||||||
|
|
||||||
// Continuators - all include eoContinue.h
|
// Continuators - all include eoContinue.h
|
||||||
#include <eoCombinedContinue.h>
|
#include <eoCombinedContinue.h>
|
||||||
|
|
@ -103,7 +102,6 @@
|
||||||
#include <eoSharingSelect.h>
|
#include <eoSharingSelect.h>
|
||||||
// Embedding truncation selection
|
// Embedding truncation selection
|
||||||
#include <eoTruncatedSelectOne.h>
|
#include <eoTruncatedSelectOne.h>
|
||||||
#include <eoRankMuSelect.h>
|
|
||||||
|
|
||||||
// the batch selection - from an eoSelectOne
|
// the batch selection - from an eoSelectOne
|
||||||
#include <eoSelectPerc.h>
|
#include <eoSelectPerc.h>
|
||||||
|
|
@ -115,6 +113,7 @@
|
||||||
// DetSelect can also be obtained as eoSequentialSelect, an eoSelectOne
|
// DetSelect can also be obtained as eoSequentialSelect, an eoSelectOne
|
||||||
// (using setup and an index)
|
// (using setup and an index)
|
||||||
#include <eoDetSelect.h>
|
#include <eoDetSelect.h>
|
||||||
|
#include <eoRankMuSelect.h>
|
||||||
|
|
||||||
// Breeders
|
// Breeders
|
||||||
#include <eoGeneralBreeder.h> // applies one eoGenOp, stop on offspring count
|
#include <eoGeneralBreeder.h> // applies one eoGenOp, stop on offspring count
|
||||||
|
|
@ -143,9 +142,6 @@
|
||||||
#include <utils/eoRealVectorBounds.h> // includes eoRealBounds.h
|
#include <utils/eoRealVectorBounds.h> // includes eoRealBounds.h
|
||||||
#include <utils/eoIntBounds.h> // no eoIntVectorBounds
|
#include <utils/eoIntBounds.h> // no eoIntVectorBounds
|
||||||
|
|
||||||
// Serialization stuff
|
|
||||||
#include <serial/eoSerial.h>
|
|
||||||
|
|
||||||
// aliens
|
// aliens
|
||||||
#include <other/external_eo>
|
#include <other/external_eo>
|
||||||
#include <eoCounter.h>
|
#include <eoCounter.h>
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@
|
||||||
#include <eoMergeReduce.h>
|
#include <eoMergeReduce.h>
|
||||||
#include <eoReplacement.h>
|
#include <eoReplacement.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <class EOT> class eoIslandsEasyEA ;
|
template <class EOT> class eoIslandsEasyEA ;
|
||||||
|
|
||||||
template <class EOT> class eoDistEvalEasyEA ;
|
template <class EOT> class eoDistEvalEasyEA ;
|
||||||
|
|
@ -100,33 +102,6 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
offspring.reserve(_offspringSize); // This line avoids an incremental resize of offsprings.
|
offspring.reserve(_offspringSize); // This line avoids an incremental resize of offsprings.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Ctor allowing to specify which pop eval function we're going to use.
|
|
||||||
*
|
|
||||||
* Ctor taking a breed and merge, an overload of ctor to define an offspring size, and
|
|
||||||
* the pop eval function used. This allows to precise if we would like to use the
|
|
||||||
* parallel evaluation, for instance.
|
|
||||||
*/
|
|
||||||
eoEasyEA(
|
|
||||||
eoContinue<EOT>& _continuator,
|
|
||||||
eoEvalFunc<EOT>& _eval,
|
|
||||||
eoPopEvalFunc<EOT>& _pop_eval,
|
|
||||||
eoBreed<EOT>& _breed,
|
|
||||||
eoReplacement<EOT>& _replace,
|
|
||||||
unsigned _offspringSize
|
|
||||||
) : continuator(_continuator),
|
|
||||||
eval (_eval),
|
|
||||||
loopEval(_eval),
|
|
||||||
popEval(_pop_eval),
|
|
||||||
selectTransform(dummySelect, dummyTransform),
|
|
||||||
breed(_breed),
|
|
||||||
mergeReduce(dummyMerge, dummyReduce),
|
|
||||||
replace(_replace),
|
|
||||||
isFirstCall(true)
|
|
||||||
{
|
|
||||||
offspring.reserve(_offspringSize); // This line avoids an incremental resize of offsprings.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
eoEasyEA(eoContinue <EOT> & _continuator,
|
eoEasyEA(eoContinue <EOT> & _continuator,
|
||||||
eoPopEvalFunc <EOT> & _pop_eval,
|
eoPopEvalFunc <EOT> & _pop_eval,
|
||||||
|
|
@ -244,7 +219,6 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
/// Apply a few generation of evolution to the population.
|
/// Apply a few generation of evolution to the population.
|
||||||
virtual void operator()(eoPop<EOT>& _pop)
|
virtual void operator()(eoPop<EOT>& _pop)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (isFirstCall)
|
if (isFirstCall)
|
||||||
{
|
{
|
||||||
size_t total_capacity = _pop.capacity() + offspring.capacity();
|
size_t total_capacity = _pop.capacity() + offspring.capacity();
|
||||||
|
|
@ -255,12 +229,13 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
|
|
||||||
eoPop<EOT> empty_pop;
|
eoPop<EOT> empty_pop;
|
||||||
|
|
||||||
|
popEval(empty_pop, _pop); // A first eval of pop.
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
unsigned pSize = _pop.size();
|
unsigned pSize = _pop.size();
|
||||||
|
|
||||||
offspring.clear(); // new offspring
|
offspring.clear(); // new offspring
|
||||||
|
|
||||||
breed(_pop, offspring);
|
breed(_pop, offspring);
|
||||||
|
|
@ -273,6 +248,7 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
throw std::runtime_error("Population shrinking!");
|
throw std::runtime_error("Population shrinking!");
|
||||||
else if (pSize < _pop.size())
|
else if (pSize < _pop.size())
|
||||||
throw std::runtime_error("Population growing!");
|
throw std::runtime_error("Population growing!");
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public :
|
||||||
throw eoEvalFuncCounterBounderException(_threshold);
|
throw eoEvalFuncCounterBounderException(_threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
func(eo);
|
this->func(eo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public:
|
||||||
nbStep(_nbStep) {
|
nbStep(_nbStep) {
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
if (!neighborhood.isRandom()) {
|
if (!neighborhood.isRandom()) {
|
||||||
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random (" << neighborhood.className() << ")" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ public:
|
||||||
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval) {
|
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval) {
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
if (!neighborhood.isRandom()) {
|
if (!neighborhood.isRandom()) {
|
||||||
std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random (" << neighborhood.className() << ")" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,9 @@ public:
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _monOp an eoMonOp (pertubation operator)
|
* @param _monOp an eoMonOp (pertubation operator)
|
||||||
* @param _fullEval a full evaluation function
|
* @param _fullEval a full evaluation function
|
||||||
|
* @param _nbPerturbation number of operator executions for perturbation
|
||||||
*/
|
*/
|
||||||
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval) {}
|
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval, unsigned int _nbPerturbation = 1):monOp(_monOp), fullEval(_fullEval), nbPerturbation(_nbPerturbation) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply monOp on the solution
|
* Apply monOp on the solution
|
||||||
|
|
@ -57,9 +58,14 @@ public:
|
||||||
* @return value of monOp
|
* @return value of monOp
|
||||||
*/
|
*/
|
||||||
bool operator()(EOT& _solution) {
|
bool operator()(EOT& _solution) {
|
||||||
bool res = monOp(_solution);
|
bool res = false;
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < nbPerturbation; i++)
|
||||||
|
res = res || monOp(_solution);
|
||||||
|
|
||||||
_solution.invalidate();
|
_solution.invalidate();
|
||||||
fullEval(_solution);
|
fullEval(_solution);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,6 +73,7 @@ private:
|
||||||
/** monOp */
|
/** monOp */
|
||||||
eoMonOp<EOT>& monOp;
|
eoMonOp<EOT>& monOp;
|
||||||
eoEvalFunc<EOT>& fullEval;
|
eoEvalFunc<EOT>& fullEval;
|
||||||
|
unsigned int nbPerturbation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,14 @@ public:
|
||||||
return nNeighbors < sampleSize ;
|
return nNeighbors < sampleSize ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The neighborhood is random here
|
||||||
|
* @return true, since the neighborhood is random
|
||||||
|
*/
|
||||||
|
bool isRandom() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the class Name
|
* Return the class Name
|
||||||
* @return the class name as a std::string
|
* @return the class name as a std::string
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,10 @@ public:
|
||||||
int d;
|
int d;
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
unsigned i, j;
|
unsigned i = _neighbor.first();
|
||||||
|
unsigned j = _neighbor.second();
|
||||||
_neighbor.getIndices(n, i, j);
|
|
||||||
|
|
||||||
|
// _neighbor.getIndices(n, i, j);
|
||||||
d = (A[i][i]-A[j][j])*(B[_solution[j]][_solution[j]]-B[_solution[i]][_solution[i]]) +
|
d = (A[i][i]-A[j][j])*(B[_solution[j]][_solution[j]]-B[_solution[i]][_solution[i]]) +
|
||||||
(A[i][j]-A[j][i])*(B[_solution[j]][_solution[i]]-B[_solution[i]][_solution[j]]);
|
(A[i][j]-A[j][i])*(B[_solution[j]][_solution[i]]-B[_solution[i]][_solution[j]]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,22 @@ public:
|
||||||
index( _first + n * (n - 1) / 2 );
|
index( _first + n * (n - 1) / 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter of the firt location
|
||||||
|
* @return first indice
|
||||||
|
*/
|
||||||
|
unsigned int first() {
|
||||||
|
return indices.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter of the second location
|
||||||
|
* @return second indice
|
||||||
|
*/
|
||||||
|
unsigned int second() {
|
||||||
|
return indices.second;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::pair<unsigned int, unsigned int> indices;
|
std::pair<unsigned int, unsigned int> indices;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<moShiftNeighbor.h>
|
<moShiftNeighbor.h>
|
||||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau
|
||||||
|
|
||||||
This software is governed by the CeCILL license under French law and
|
This software is governed by the CeCILL license under French law and
|
||||||
abiding by the rules of distribution of free software. You can ue,
|
abiding by the rules of distribution of free software. You can ue,
|
||||||
|
|
@ -30,85 +30,157 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#ifndef _moShiftNeighbor_h
|
#ifndef _moShiftNeighbor_h
|
||||||
#define _moShiftNeighbor_h
|
#define _moShiftNeighbor_h
|
||||||
|
|
||||||
|
#include <neighborhood/moBackableNeighbor.h>
|
||||||
#include <neighborhood/moIndexNeighbor.h>
|
#include <neighborhood/moIndexNeighbor.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indexed Shift Neighbor
|
* Indexed Shift Neighbor
|
||||||
|
* Other name : insertion operator
|
||||||
*/
|
*/
|
||||||
template <class EOT, class Fitness=typename EOT::Fitness>
|
template <class EOT, class Fitness=typename EOT::Fitness>
|
||||||
class moShiftNeighbor: public moIndexNeighbor<EOT, Fitness>
|
class moShiftNeighbor: public moBackableNeighbor<EOT, Fitness>, public moIndexNeighbor<EOT, Fitness>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using moBackableNeighbor<EOT, Fitness>::fitness;
|
||||||
using moIndexNeighbor<EOT, Fitness>::key;
|
using moIndexNeighbor<EOT, Fitness>::key;
|
||||||
|
using moIndexNeighbor<EOT, Fitness>::index;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply move on a solution regarding a key
|
* Apply move on a solution regarding a key
|
||||||
* @param _sol the solution to move
|
* @param _solution the solution to move
|
||||||
*/
|
*/
|
||||||
virtual void move(EOT & _sol) {
|
virtual void move(EOT & _solution) {
|
||||||
unsigned int tmp ;
|
insertion(_solution, indices.first, indices.second);
|
||||||
size=_sol.size();
|
|
||||||
translate(key+1);
|
_solution.invalidate();
|
||||||
// keep the first component to change
|
|
||||||
tmp = _sol[first];
|
|
||||||
// shift
|
|
||||||
if (first < second) {
|
|
||||||
for (unsigned int i=first; i<second-1; i++)
|
|
||||||
_sol[i] = _sol[i+1];
|
|
||||||
// shift the first component
|
|
||||||
_sol[second-1] = tmp;
|
|
||||||
}
|
|
||||||
else { /* first > second*/
|
|
||||||
for (unsigned int i=first; i>second; i--)
|
|
||||||
_sol[i] = _sol[i-1];
|
|
||||||
// shift the first component
|
|
||||||
_sol[second] = tmp;
|
|
||||||
}
|
|
||||||
_sol.invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fix two indexes regarding a key
|
* apply the correct insertion to restore the solution (use by moFullEvalByModif)
|
||||||
* @param _key the key allowing to compute the two indexes for the shift
|
* @param _solution the solution to move back
|
||||||
*/
|
*/
|
||||||
void translate(unsigned int _key) {
|
virtual void moveBack(EOT& _solution) {
|
||||||
int step;
|
if (indices.first < indices.second)
|
||||||
int val = _key;
|
insertion(_solution, indices.second - 1, indices.first);
|
||||||
int tmpSize = size * (size-1) / 2;
|
else
|
||||||
// moves from left to right
|
insertion(_solution, indices.second, indices.first + 1);
|
||||||
if (val <= tmpSize) {
|
|
||||||
step = size - 1;
|
|
||||||
first = 0;
|
|
||||||
while ((val - step) > 0) {
|
|
||||||
val = val - step;
|
|
||||||
step--;
|
|
||||||
first++;
|
|
||||||
}
|
}
|
||||||
second = first + val + 1;
|
|
||||||
|
/**
|
||||||
|
* Setter
|
||||||
|
* The "parameters" of the neighbor is a function of key and the current solution
|
||||||
|
* for example, for variable length solution
|
||||||
|
*
|
||||||
|
* @param _solution solution from which the neighborhood is visited
|
||||||
|
* @param _key index of the IndexNeighbor
|
||||||
|
*/
|
||||||
|
virtual void index(EOT & _solution, unsigned int _key) {
|
||||||
|
index( _key );
|
||||||
|
|
||||||
|
indices.first = _key % _solution.size() ;
|
||||||
|
indices.second = _key / _solution.size() ;
|
||||||
|
|
||||||
|
if (indices.first <= indices.second)
|
||||||
|
indices.second += 2;
|
||||||
|
|
||||||
|
// =============== To kill :
|
||||||
|
// int step;
|
||||||
|
// int val = _key;
|
||||||
|
// int tmpSize = _solution.size() * (_solution.size() - 1) / 2;
|
||||||
|
|
||||||
|
// // moves from left to right
|
||||||
|
// if (val <= tmpSize) {
|
||||||
|
// step = _solution.size() - 1;
|
||||||
|
// indices.first = 0;
|
||||||
|
// while ((val - step) > 0) {
|
||||||
|
// val = val - step;
|
||||||
|
// step--;
|
||||||
|
// indices.first++;
|
||||||
|
// }
|
||||||
|
// indices.second = indices.first + val + 1;
|
||||||
|
// }
|
||||||
|
// // moves from right to left (equivalent moves are avoided)
|
||||||
|
// else { /* val > tmpSize */
|
||||||
|
// val = val - tmpSize;
|
||||||
|
// step = _solution.size() - 2;
|
||||||
|
// indices.second = 0;
|
||||||
|
// while ((val - step) > 0) {
|
||||||
|
// val = val - step;
|
||||||
|
// step--;
|
||||||
|
// indices.second++;
|
||||||
|
// }
|
||||||
|
// indices.first = indices.second + val + 1;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
// moves from right to left (equivalent moves are avoided)
|
|
||||||
else { /* val > tmpSize */
|
/**
|
||||||
val = val - tmpSize;
|
* Setter to fix the two indexes to swap
|
||||||
step = size - 2;
|
* @param _solution solution from which the neighborhood is visited
|
||||||
second = 0;
|
* @param _first first index
|
||||||
while ((val - step) > 0) {
|
* @param _second second index
|
||||||
val = val - step;
|
*/
|
||||||
step--;
|
void set(EOT & _solution, unsigned int _first, unsigned int _second) {
|
||||||
second++;
|
indices.first = _first;
|
||||||
|
indices.second = _second;
|
||||||
|
|
||||||
|
// set the index
|
||||||
|
if (_first < _second) {
|
||||||
|
index( (_second - 2) * _solution.size() + _first );
|
||||||
|
} else {
|
||||||
|
index( _second * _solution.size() + _first );
|
||||||
}
|
}
|
||||||
first = second + val + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter of the firt location
|
||||||
|
* @return first indice
|
||||||
|
*/
|
||||||
|
unsigned int first() {
|
||||||
|
return indices.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter of the second location
|
||||||
|
* @return second indice
|
||||||
|
*/
|
||||||
|
unsigned int second() {
|
||||||
|
return indices.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print() {
|
void print() {
|
||||||
std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl;
|
std::cout << key << ": [" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int first;
|
std::pair<unsigned int, unsigned int> indices;
|
||||||
unsigned int second;
|
|
||||||
unsigned int size;
|
/**
|
||||||
|
* Apply insertion move on a solution regarding a key
|
||||||
|
* @param _sol the solution to move
|
||||||
|
* @param _first first position
|
||||||
|
* @param _second second position
|
||||||
|
*/
|
||||||
|
void insertion(EOT & _sol, unsigned int _first, unsigned int _second) {
|
||||||
|
unsigned int tmp ;
|
||||||
|
|
||||||
|
// keep the first component to change
|
||||||
|
tmp = _sol[_first];
|
||||||
|
// shift
|
||||||
|
if (_first < _second) {
|
||||||
|
for (unsigned int i = _first; i < _second - 1; i++)
|
||||||
|
_sol[i] = _sol[i+1];
|
||||||
|
// shift the first component
|
||||||
|
_sol[_second-1] = tmp;
|
||||||
|
}
|
||||||
|
else { /* first > second*/
|
||||||
|
for (unsigned int i = _first; i > _second; i--)
|
||||||
|
_sol[i] = _sol[i-1];
|
||||||
|
// shift the first component
|
||||||
|
_sol[_second] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ set (TEST_LIST
|
||||||
t-moNeutralWalkSampling
|
t-moNeutralWalkSampling
|
||||||
t-moStatistics
|
t-moStatistics
|
||||||
t-moIndexedVectorTabuList
|
t-moIndexedVectorTabuList
|
||||||
t-moRndIndexedVectorTabuList
|
# t-moRndIndexedVectorTabuList
|
||||||
t-moDynSpanCoolingSchedule
|
t-moDynSpanCoolingSchedule
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,7 @@ class moeoConvertPopToObjectiveVectors : public eoUF < const eoPop < MOEOT >, co
|
||||||
*/
|
*/
|
||||||
const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop)
|
const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop)
|
||||||
{
|
{
|
||||||
std::vector < ObjectiveVector > result;
|
std::vector < ObjectiveVector > result(0);
|
||||||
result.resize(_pop.size());
|
|
||||||
for (unsigned int i=0; i<_pop.size(); i++)
|
for (unsigned int i=0; i<_pop.size(); i++)
|
||||||
{
|
{
|
||||||
result.push_back(_pop[i].objectiveVector());
|
result.push_back(_pop[i].objectiveVector());
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ public:
|
||||||
* Update the island by adding population to send in the imigrants list.
|
* Update the island by adding population to send in the imigrants list.
|
||||||
* @param _data Population to integrate.
|
* @param _data Population to integrate.
|
||||||
*/
|
*/
|
||||||
virtual void update(eoPop<bEOT> _data) = 0;
|
virtual bool update(eoPop<bEOT> _data) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the algorithm is stopped.
|
* Check if the algorithm is stopped.
|
||||||
|
|
@ -82,6 +82,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool isStopped(void) const = 0;
|
virtual bool isStopped(void) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the stopped indicator on false
|
||||||
|
*/
|
||||||
|
virtual void setRunning(void) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receive population by integrate individuals.
|
* Receive population by integrate individuals.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ std::map<B,A> paradiseo::smp::Bimap<A,B>::getLeft() const
|
||||||
template<class A, class B>
|
template<class A, class B>
|
||||||
void paradiseo::smp::Bimap<A,B>::removeFromRight(const A& a)
|
void paradiseo::smp::Bimap<A,B>::removeFromRight(const A& a)
|
||||||
{
|
{
|
||||||
for(auto& it : leftAssociation)
|
leftAssociation.erase(remove(leftAssociation.begin(), leftAssociation.end(),
|
||||||
if(it->second == a)
|
[&](std::pair<B,A>& i) -> bool { return i->second == a; }),
|
||||||
leftAssociation.erase(it);
|
leftAssociation.end());
|
||||||
|
|
||||||
rightAssociation.erase(a);
|
rightAssociation.erase(a);
|
||||||
}
|
}
|
||||||
|
|
@ -59,9 +59,9 @@ void paradiseo::smp::Bimap<A,B>::removeFromRight(const A& a)
|
||||||
template<class A, class B>
|
template<class A, class B>
|
||||||
void paradiseo::smp::Bimap<A,B>::removeFromLeft(const B& b)
|
void paradiseo::smp::Bimap<A,B>::removeFromLeft(const B& b)
|
||||||
{
|
{
|
||||||
for(auto& it : rightAssociation)
|
rightAssociation.erase(remove(rightAssociation.begin(), rightAssociation.end(),
|
||||||
if(it->second == b)
|
[&](std::pair<A,B>& i) -> bool { return i->second == b; }),
|
||||||
rightAssociation.erase(it);
|
rightAssociation.end());
|
||||||
|
|
||||||
leftAssociation.erase(b);
|
leftAssociation.erase(b);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,10 @@ void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::operator()()
|
||||||
stopped = true;
|
stopped = true;
|
||||||
// Let's wait the end of communications with the island model
|
// Let's wait the end of communications with the island model
|
||||||
for(auto& message : sentMessages)
|
for(auto& message : sentMessages)
|
||||||
message.join();
|
message.wait();
|
||||||
|
|
||||||
|
// Clear the sentMessages container
|
||||||
|
sentMessages.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||||
|
|
@ -100,6 +103,12 @@ bool paradiseo::smp::Island<EOAlgo,EOT,bEOT>::isStopped(void) const
|
||||||
return (bool)stopped;
|
return (bool)stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||||
|
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::setRunning(void)
|
||||||
|
{
|
||||||
|
stopped = false;
|
||||||
|
}
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::send(eoSelect<EOT>& _select)
|
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::send(eoSelect<EOT>& _select)
|
||||||
{
|
{
|
||||||
|
|
@ -114,14 +123,14 @@ void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::send(eoSelect<EOT>& _select)
|
||||||
for(auto& indi : migPop)
|
for(auto& indi : migPop)
|
||||||
baseMigPop.push_back(std::move(convertToBase(indi)));
|
baseMigPop.push_back(std::move(convertToBase(indi)));
|
||||||
|
|
||||||
//std::cout << "On envoie de l'île : " << migPop << std::endl;
|
|
||||||
|
|
||||||
// Delete delivered messages
|
// Delete delivered messages
|
||||||
for(auto it = sentMessages.begin(); it != sentMessages.end(); it++)
|
sentMessages.erase(std::remove_if(sentMessages.begin(), sentMessages.end(),
|
||||||
if(!it->joinable())
|
[&](std::shared_future<bool>& i) -> bool
|
||||||
sentMessages.erase(it);
|
{ return i.wait_for(std::chrono::nanoseconds(0)) == std::future_status::ready; }
|
||||||
|
),
|
||||||
|
sentMessages.end());
|
||||||
|
|
||||||
sentMessages.push_back(std::thread(&IslandModel<bEOT>::update, model, std::move(baseMigPop), this));
|
sentMessages.push_back(std::async(std::launch::async, &IslandModel<bEOT>::update, model, std::move(baseMigPop), this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,9 +159,11 @@ void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::receive(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT, class bEOT>
|
template<template <class> class EOAlgo, class EOT, class bEOT>
|
||||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::update(eoPop<bEOT> _data)
|
bool paradiseo::smp::Island<EOAlgo,EOT,bEOT>::update(eoPop<bEOT> _data)
|
||||||
{
|
{
|
||||||
//std::cout << "On update dans l'île" << std::endl;
|
//std::cout << "On update dans l'île" << std::endl;
|
||||||
std::lock_guard<std::mutex> lock(this->m);
|
std::lock_guard<std::mutex> lock(this->m);
|
||||||
listImigrants.push(_data);
|
listImigrants.push(_data);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,9 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <future>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
#include <eoSelect.h>
|
#include <eoSelect.h>
|
||||||
|
|
@ -112,7 +114,7 @@ public:
|
||||||
* Update the list of imigrants.
|
* Update the list of imigrants.
|
||||||
* @param _data Elements to integrate in the main population.
|
* @param _data Elements to integrate in the main population.
|
||||||
*/
|
*/
|
||||||
void update(eoPop<bEOT> _data);
|
bool update(eoPop<bEOT> _data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the algorithm is stopped.
|
* Check if the algorithm is stopped.
|
||||||
|
|
@ -120,6 +122,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool isStopped(void) const;
|
virtual bool isStopped(void) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the stopped indicator on false
|
||||||
|
*/
|
||||||
|
virtual void setRunning(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there is population to receive
|
* Check if there is population to receive
|
||||||
*/
|
*/
|
||||||
|
|
@ -142,7 +149,7 @@ protected:
|
||||||
IntPolicy<EOT>& intPolicy;
|
IntPolicy<EOT>& intPolicy;
|
||||||
MigPolicy<EOT>& migPolicy;
|
MigPolicy<EOT>& migPolicy;
|
||||||
std::atomic<bool> stopped;
|
std::atomic<bool> stopped;
|
||||||
std::vector<std::thread> sentMessages;
|
std::vector<std::shared_future<bool>> sentMessages;
|
||||||
IslandModel<bEOT>* model;
|
IslandModel<bEOT>* model;
|
||||||
std::function<EOT(bEOT&)> convertFromBase;
|
std::function<EOT(bEOT&)> convertFromBase;
|
||||||
std::function<bEOT(EOT&)> convertToBase;
|
std::function<bEOT(EOT&)> convertToBase;
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ void paradiseo::smp::IslandModel<EOT>::operator()()
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for(auto it : islands)
|
for(auto it : islands)
|
||||||
{
|
{
|
||||||
|
it.first->setRunning();
|
||||||
threads[i] = std::thread(&AIsland<EOT>::operator(), it.first);
|
threads[i] = std::thread(&AIsland<EOT>::operator(), it.first);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +98,10 @@ void paradiseo::smp::IslandModel<EOT>::operator()()
|
||||||
|
|
||||||
// Wait the end of messages sending
|
// Wait the end of messages sending
|
||||||
for(auto& message : sentMessages)
|
for(auto& message : sentMessages)
|
||||||
message.join();
|
message.wait();
|
||||||
|
|
||||||
|
// Clear the sentMessages container
|
||||||
|
sentMessages.clear();
|
||||||
|
|
||||||
// Force last integration
|
// Force last integration
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
@ -115,10 +119,12 @@ void paradiseo::smp::IslandModel<EOT>::operator()()
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
void paradiseo::smp::IslandModel<EOT>::update(eoPop<EOT> _data, AIsland<EOT>* _island)
|
bool paradiseo::smp::IslandModel<EOT>::update(eoPop<EOT> _data, AIsland<EOT>* _island)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m);
|
std::lock_guard<std::mutex> lock(m);
|
||||||
listEmigrants.push(std::pair<eoPop<EOT>,AIsland<EOT>*>(_data, _island));
|
listEmigrants.push(std::pair<eoPop<EOT>,AIsland<EOT>*>(_data, _island));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
|
|
@ -150,11 +156,17 @@ void paradiseo::smp::IslandModel<EOT>::send(void)
|
||||||
|
|
||||||
// Send elements to neighbors
|
// Send elements to neighbors
|
||||||
eoPop<EOT> migPop = std::move(listEmigrants.front().first);
|
eoPop<EOT> migPop = std::move(listEmigrants.front().first);
|
||||||
|
sentMessages.erase(std::remove_if(sentMessages.begin(), sentMessages.end(),
|
||||||
|
[&](std::shared_future<bool>& i) -> bool
|
||||||
|
{ return i.wait_for(std::chrono::nanoseconds(0)) == std::future_status::ready; }
|
||||||
|
),
|
||||||
|
sentMessages.end());
|
||||||
for (unsigned idTo : neighbors)
|
for (unsigned idTo : neighbors)
|
||||||
sentMessages.push_back(std::thread(&AIsland<EOT>::update, table.getRight()[idTo], std::move(migPop)));
|
sentMessages.push_back(std::async(std::launch::async, &AIsland<EOT>::update, table.getRight()[idTo], std::move(migPop)));
|
||||||
|
|
||||||
listEmigrants.pop();
|
listEmigrants.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <future>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <bimap.h>
|
#include <bimap.h>
|
||||||
|
|
@ -71,7 +72,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Update the island model by adding population to send in the emigrants list.
|
* Update the island model by adding population to send in the emigrants list.
|
||||||
*/
|
*/
|
||||||
void update(eoPop<EOT> _data, AIsland<EOT>* _island);
|
bool update(eoPop<EOT> _data, AIsland<EOT>* _island);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change topology
|
* Change topology
|
||||||
|
|
@ -99,7 +100,7 @@ protected:
|
||||||
Bimap<unsigned, AIsland<EOT>*> table;
|
Bimap<unsigned, AIsland<EOT>*> table;
|
||||||
std::vector<std::pair<AIsland<EOT>*, bool>> islands;
|
std::vector<std::pair<AIsland<EOT>*, bool>> islands;
|
||||||
AbstractTopology& topo;
|
AbstractTopology& topo;
|
||||||
std::vector<std::thread> sentMessages;
|
std::vector<std::shared_future<bool>> sentMessages;
|
||||||
std::mutex m;
|
std::mutex m;
|
||||||
std::atomic<bool> running;
|
std::atomic<bool> running;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||||
{
|
|
||||||
if(nbNode != matrix.size())
|
|
||||||
{
|
{
|
||||||
matrix.clear();
|
matrix.clear();
|
||||||
|
|
||||||
|
|
@ -46,4 +44,3 @@ void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector<std::vect
|
||||||
for(unsigned i = 0; i < nbNode; i++)
|
for(unsigned i = 0; i < nbNode; i++)
|
||||||
matrix[i][i]=false;
|
matrix[i][i]=false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void paradiseo::smp::Hypercubic::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
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
|
// Check if the number of node is coherent with an hypercube
|
||||||
assert((nbNode & (nbNode-1)) == 0);
|
assert((nbNode & (nbNode-1)) == 0);
|
||||||
|
|
@ -62,4 +60,3 @@ void paradiseo::smp::Hypercubic::operator()(unsigned nbNode, std::vector<std::ve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <topology/ring.h>
|
#include <topology/ring.h>
|
||||||
|
|
||||||
void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||||
{
|
|
||||||
if(nbNode != matrix.size())
|
|
||||||
{
|
{
|
||||||
matrix.clear();
|
matrix.clear();
|
||||||
|
|
||||||
|
|
@ -47,4 +45,3 @@ void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector<std::vector<b
|
||||||
for(unsigned i=0; i < nbNode; i++)
|
for(unsigned i=0; i < nbNode; i++)
|
||||||
matrix[i][(i+1)%nbNode]=true;
|
matrix[i][(i+1)%nbNode]=true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue