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
|
|
@ -18,7 +18,7 @@ enable_language(CXX)
|
|||
|
||||
## Test the presence of a compiler
|
||||
if("${CMAKE_CXX_COMPILER}" STREQUAL "" OR "${CMAKE_C_COMPILER}" STREQUAL "")
|
||||
message(FATAL_ERROR "No compiler found !")
|
||||
message(FATAL_ERROR "No compiler found!")
|
||||
endif()
|
||||
|
||||
## Versioning
|
||||
|
|
@ -35,6 +35,7 @@ SET(GLOBAL_VERSION "${VERSION}")
|
|||
######################################################################################
|
||||
|
||||
## Optional
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/module" CACHE INTERNAL "Cmake module" FORCE)
|
||||
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
|
||||
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()
|
||||
set(PARADISEO_LIBRARIES_TO_FIND ${Paradiseo_FIND_COMPONENTS})
|
||||
endif()
|
||||
|
|
@ -64,10 +64,6 @@ find_path(EO_INCLUDE_DIR eo
|
|||
PATH_SUFFIXES include${INSTALL_SUB_DIR}/eo eo/src
|
||||
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
|
||||
PATH_SUFFIXES include${INSTALL_SUB_DIR}/mo mo/src
|
||||
PATHS ${PARADISEO_SRC_PATHS})
|
||||
|
|
@ -85,7 +81,12 @@ foreach(COMP ${PARADISEO_LIBRARIES_TO_FIND})
|
|||
PATHS ${PARADISEO_SRC_PATHS})
|
||||
elseif(${COMP} STREQUAL "peo")
|
||||
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
|
||||
PATHS ${PARADISEO_SRC_PATHS})
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -1,33 +1,25 @@
|
|||
|
||||
IF(EDO_USE_LIB STREQUAL "uBLAS")
|
||||
FIND_PACKAGE(Boost )
|
||||
IF( Boost_FOUND )
|
||||
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )
|
||||
ADD_DEFINITIONS( -DWITH_BOOST )
|
||||
ELSE()
|
||||
MESSAGE( "ERROR: You asked for Boost::uBLAS but it has not been found." )
|
||||
SET(IS_FATAL 1)
|
||||
ENDIF()
|
||||
ELSEIF( EDO_USE_LIB STREQUAL "Eigen3" )
|
||||
# FIXME FindEigen3.cmake does not work
|
||||
#find_package(Eigen3)
|
||||
#include_directories(EIGEN3_INCLUDE_DIR)
|
||||
SET( EIGEN3_FOUND 1)
|
||||
SET( EIGEN3_INCLUDE_DIR "/usr/include/eigen3/" )
|
||||
if(EDO_USE_LIB STREQUAL "uBLAS")
|
||||
find_package(Boost)
|
||||
if(Boost_FOUND)
|
||||
include_directories( ${Boost_INCLUDE_DIRS} )
|
||||
add_definitions( -DWITH_BOOST )
|
||||
else()
|
||||
message(FATAL_ERROR "\n\nERROR: You asked for Boost::uBLAS but it has not been found.\n" )
|
||||
endif()
|
||||
elseif(EDO_USE_LIB STREQUAL "Eigen3")
|
||||
find_package(Eigen3)
|
||||
if(EIGEN3_FOUND)
|
||||
include_directories(EIGEN3_INCLUDE_DIR)
|
||||
add_definitions( -DWITH_EIGEN )
|
||||
else()
|
||||
message(FATAL_ERROR "\n\nERROR: You asked for Eigen3 but it has not been found.\n" )
|
||||
endif()
|
||||
|
||||
IF( EIGEN3_FOUND )
|
||||
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()
|
||||
else()
|
||||
# FIXME ideally, we would have a minimal implementation with STL vectors…
|
||||
MESSAGE( "You must set EDO_USE_LIB to either 'uBLAS' or 'Eigen3'." )
|
||||
SET(IS_FATAL 1)
|
||||
ENDIF()
|
||||
message(FATAL_ERROR "\n\nYou must set EDO_USE_LIB to either 'uBLAS' or 'Eigen3'.\n" )
|
||||
endif()
|
||||
|
||||
|
||||
######################################################################################
|
||||
|
|
@ -37,14 +29,14 @@ ENDIF()
|
|||
add_subdirectory(doc)
|
||||
add_subdirectory(src)
|
||||
|
||||
if(ENABLE_CMAKE_TESTING)
|
||||
if(ENABLE_CMAKE_TESTING AND EIGEN3_FOUND) # see edoNormalAdaptive
|
||||
add_subdirectory(test)
|
||||
endif(ENABLE_CMAKE_TESTING)
|
||||
endif()
|
||||
|
||||
if(ENABLE_CMAKE_EXAMPLE)
|
||||
if(${CMAKE_VERBOSE_MAKEFILE})
|
||||
message("EDO examples:")
|
||||
endif(${CMAKE_VERBOSE_MAKEFILE})
|
||||
add_subdirectory(application)
|
||||
endif(ENABLE_CMAKE_EXAMPLE)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,18 @@
|
|||
### 1) Where do we go now ?!?
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common
|
||||
)
|
||||
|
||||
ADD_SUBDIRECTORY(common) # Rosenbrock and Sphere
|
||||
#ADD_SUBDIRECTORY(eda_sa)
|
||||
ADD_SUBDIRECTORY(eda)
|
||||
ADD_SUBDIRECTORY(cmaes)
|
||||
include_directories(${EIGEN3_INCLUDE_DIR})
|
||||
|
||||
add_subdirectory(common) # Rosenbrock and Sphere
|
||||
#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})
|
||||
|
||||
include_directories(${EO_SRC_DIR}/src)
|
||||
include_directories(${EDO_SRC_DIR}/src)
|
||||
link_directories(${EO_BIN_DIR}/${LIB})
|
||||
include_directories(${EDO_SRC_DIR}/src)
|
||||
link_directories(${EDO_BIN_DIR}/${LIB})
|
||||
|
||||
set(RESOURCES
|
||||
|
|
|
|||
|
|
@ -23,17 +23,13 @@
|
|||
### 3) Define your targets and link the librairies
|
||||
######################################################################################
|
||||
|
||||
find_package(Boost 1.33.0)
|
||||
|
||||
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(${EO_SRC_DIR}/src)
|
||||
include_directories(${EDO_SRC_DIR}/src)
|
||||
|
||||
include_directories(${EIGEN3_INCLUDE_DIR})
|
||||
|
||||
set(SOURCES
|
||||
#t-cholesky
|
||||
t-variance
|
||||
|
|
@ -42,14 +38,14 @@ set(SOURCES
|
|||
t-bounderno
|
||||
t-uniform
|
||||
t-continue
|
||||
t-dispatcher-round
|
||||
# t-dispatcher-round
|
||||
t-repairer-modulo
|
||||
)
|
||||
|
||||
foreach(current ${SOURCES})
|
||||
add_executable(${current} ${current}.cpp)
|
||||
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)
|
||||
endforeach()
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,6 @@
|
|||
#include <eoEvalCounterThrowException.h>
|
||||
#include <eoEvalTimeThrowException.h>
|
||||
#include <eoEvalUserTimeThrowException.h>
|
||||
#include <eoEvalKeepBest.h>
|
||||
|
||||
// Continuators - all include eoContinue.h
|
||||
#include <eoCombinedContinue.h>
|
||||
|
|
@ -103,7 +102,6 @@
|
|||
#include <eoSharingSelect.h>
|
||||
// Embedding truncation selection
|
||||
#include <eoTruncatedSelectOne.h>
|
||||
#include <eoRankMuSelect.h>
|
||||
|
||||
// the batch selection - from an eoSelectOne
|
||||
#include <eoSelectPerc.h>
|
||||
|
|
@ -115,6 +113,7 @@
|
|||
// DetSelect can also be obtained as eoSequentialSelect, an eoSelectOne
|
||||
// (using setup and an index)
|
||||
#include <eoDetSelect.h>
|
||||
#include <eoRankMuSelect.h>
|
||||
|
||||
// Breeders
|
||||
#include <eoGeneralBreeder.h> // applies one eoGenOp, stop on offspring count
|
||||
|
|
@ -143,9 +142,6 @@
|
|||
#include <utils/eoRealVectorBounds.h> // includes eoRealBounds.h
|
||||
#include <utils/eoIntBounds.h> // no eoIntVectorBounds
|
||||
|
||||
// Serialization stuff
|
||||
#include <serial/eoSerial.h>
|
||||
|
||||
// aliens
|
||||
#include <other/external_eo>
|
||||
#include <eoCounter.h>
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@
|
|||
#include <eoMergeReduce.h>
|
||||
#include <eoReplacement.h>
|
||||
|
||||
|
||||
|
||||
template <class EOT> class eoIslandsEasyEA ;
|
||||
|
||||
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.
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,
|
||||
eoPopEvalFunc <EOT> & _pop_eval,
|
||||
|
|
@ -244,44 +219,45 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
|||
/// Apply a few generation of evolution to the population.
|
||||
virtual void operator()(eoPop<EOT>& _pop)
|
||||
{
|
||||
if (isFirstCall)
|
||||
{
|
||||
size_t total_capacity = _pop.capacity() + offspring.capacity();
|
||||
_pop.reserve(total_capacity);
|
||||
offspring.reserve(total_capacity);
|
||||
isFirstCall = false;
|
||||
}
|
||||
|
||||
if (isFirstCall)
|
||||
eoPop<EOT> empty_pop;
|
||||
|
||||
popEval(empty_pop, _pop); // A first eval of pop.
|
||||
|
||||
do
|
||||
{
|
||||
size_t total_capacity = _pop.capacity() + offspring.capacity();
|
||||
_pop.reserve(total_capacity);
|
||||
offspring.reserve(total_capacity);
|
||||
isFirstCall = false;
|
||||
}
|
||||
|
||||
eoPop<EOT> empty_pop;
|
||||
|
||||
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);
|
||||
popEval(_pop, offspring); // eval of parents + offspring if necessary
|
||||
|
||||
popEval(_pop, offspring); // eval of parents + offspring if necessary
|
||||
replace(_pop, offspring); // after replace, the new pop. is in _pop
|
||||
|
||||
replace(_pop, offspring); // after replace, the new pop. is in _pop
|
||||
if (pSize > _pop.size())
|
||||
throw std::runtime_error("Population shrinking!");
|
||||
else if (pSize < _pop.size())
|
||||
throw std::runtime_error("Population growing!");
|
||||
|
||||
if (pSize > _pop.size())
|
||||
throw std::runtime_error("Population shrinking!");
|
||||
else if (pSize < _pop.size())
|
||||
throw std::runtime_error("Population growing!");
|
||||
}
|
||||
catch (std::exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::string s = e.what();
|
||||
s.append( " in eoEasyEA");
|
||||
throw std::runtime_error( s );
|
||||
std::string s = e.what();
|
||||
s.append( " in eoEasyEA");
|
||||
throw std::runtime_error( s );
|
||||
}
|
||||
}
|
||||
while ( continuator( _pop ) );
|
||||
while ( continuator( _pop ) );
|
||||
}
|
||||
|
||||
protected :
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public :
|
|||
throw eoEvalFuncCounterBounderException(_threshold);
|
||||
}
|
||||
|
||||
func(eo);
|
||||
this->func(eo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public:
|
|||
nbStep(_nbStep) {
|
||||
isAccept = false;
|
||||
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) {
|
||||
isAccept = false;
|
||||
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
|
||||
* @param _monOp an eoMonOp (pertubation operator)
|
||||
* @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
|
||||
|
|
@ -57,16 +58,22 @@ public:
|
|||
* @return value of monOp
|
||||
*/
|
||||
bool operator()(EOT& _solution) {
|
||||
bool res = monOp(_solution);
|
||||
_solution.invalidate();
|
||||
fullEval(_solution);
|
||||
return res;
|
||||
bool res = false;
|
||||
|
||||
for(unsigned int i = 0; i < nbPerturbation; i++)
|
||||
res = res || monOp(_solution);
|
||||
|
||||
_solution.invalidate();
|
||||
fullEval(_solution);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
/** monOp */
|
||||
eoMonOp<EOT>& monOp;
|
||||
eoEvalFunc<EOT>& fullEval;
|
||||
/** monOp */
|
||||
eoMonOp<EOT>& monOp;
|
||||
eoEvalFunc<EOT>& fullEval;
|
||||
unsigned int nbPerturbation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,36 +1,36 @@
|
|||
/*
|
||||
<moBitFlipNeighborhood.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
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,
|
||||
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
|
||||
*/
|
||||
<moBitFlipNeighborhood.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
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,
|
||||
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 _moBitFlipNeighborhood_h
|
||||
#define _moBitFlipNeighborhood_h
|
||||
|
|
@ -51,111 +51,119 @@ template< class Neighbor >
|
|||
class moBitFlipNeighborhood : public moNeighborhood<Neighbor>
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Define type of a solution corresponding to Neighbor
|
||||
*/
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param _rate bit flip rate (per bit)
|
||||
* @param _length bit string length
|
||||
* @param _sampleSize number of neighbor to sample in the neighborhood, if 0 all the neighborhood is sampled
|
||||
*/
|
||||
moBitFlipNeighborhood(double _rate, unsigned _length, unsigned _sampleSize): moNeighborhood<Neighbor>(), rate(_rate), length(_length), sampleSize(_sampleSize) {
|
||||
nNeighbors = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if it exist a neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @return true if the neighborhood was not empty (bit string larger than 0)
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& _solution) {
|
||||
return _solution.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* one random neighbor
|
||||
*
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void randomNeighbor(EOT & _solution, Neighbor & _neighbor) {
|
||||
// number of flipped bits
|
||||
_neighbor.nBits = 0;
|
||||
|
||||
for(unsigned int i = 0; i < _solution.size(); i++) {
|
||||
if (rng.flip(rate)) {
|
||||
if (_neighbor.nBits < _neighbor.bits.size())
|
||||
_neighbor.bits[_neighbor.nBits] = i;
|
||||
else
|
||||
_neighbor.bits.push_back(i);
|
||||
_neighbor.nBits++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define type of a solution corresponding to Neighbor
|
||||
*/
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param _rate bit flip rate (per bit)
|
||||
* @param _length bit string length
|
||||
* @param _sampleSize number of neighbor to sample in the neighborhood, if 0 all the neighborhood is sampled
|
||||
*/
|
||||
moBitFlipNeighborhood(double _rate, unsigned _length, unsigned _sampleSize): moNeighborhood<Neighbor>(), rate(_rate), length(_length), sampleSize(_sampleSize) {
|
||||
nNeighbors = 0;
|
||||
}
|
||||
|
||||
// reduce the size if necessary
|
||||
if (_neighbor.nBits < _neighbor.bits.size())
|
||||
_neighbor.bits.resize(_neighbor.nBits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of the neighborhood:
|
||||
* one random neighbor
|
||||
*
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||
randomNeighbor(_solution, _neighbor);
|
||||
|
||||
nNeighbors = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the next neighbor
|
||||
* apply several bit flips on the solution
|
||||
* @param _solution the solution to explore (population of solutions)
|
||||
* @param _neighbor the next neighbor which in order of distance
|
||||
*/
|
||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||
randomNeighbor(_solution, _neighbor);
|
||||
|
||||
nNeighbors++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if all neighbors are explored or not,if false, there is no neighbor left to explore
|
||||
* @param _solution the solution to explore
|
||||
* @return true if there is again a neighbor to explore: population size larger or equals than 1
|
||||
*/
|
||||
virtual bool cont(EOT & _solution) {
|
||||
return nNeighbors < sampleSize ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class Name
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moBitFlipNeighborhood";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if it exist a neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @return true if the neighborhood was not empty (bit string larger than 0)
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& _solution) {
|
||||
return _solution.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* one random neighbor
|
||||
*
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void randomNeighbor(EOT & _solution, Neighbor & _neighbor) {
|
||||
// number of flipped bits
|
||||
_neighbor.nBits = 0;
|
||||
|
||||
for(unsigned int i = 0; i < _solution.size(); i++) {
|
||||
if (rng.flip(rate)) {
|
||||
if (_neighbor.nBits < _neighbor.bits.size())
|
||||
_neighbor.bits[_neighbor.nBits] = i;
|
||||
else
|
||||
_neighbor.bits.push_back(i);
|
||||
_neighbor.nBits++;
|
||||
}
|
||||
}
|
||||
|
||||
// reduce the size if necessary
|
||||
if (_neighbor.nBits < _neighbor.bits.size())
|
||||
_neighbor.bits.resize(_neighbor.nBits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of the neighborhood:
|
||||
* one random neighbor
|
||||
*
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||
randomNeighbor(_solution, _neighbor);
|
||||
|
||||
nNeighbors = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the next neighbor
|
||||
* apply several bit flips on the solution
|
||||
* @param _solution the solution to explore (population of solutions)
|
||||
* @param _neighbor the next neighbor which in order of distance
|
||||
*/
|
||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||
randomNeighbor(_solution, _neighbor);
|
||||
|
||||
nNeighbors++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if all neighbors are explored or not,if false, there is no neighbor left to explore
|
||||
* @param _solution the solution to explore
|
||||
* @return true if there is again a neighbor to explore: population size larger or equals than 1
|
||||
*/
|
||||
virtual bool cont(EOT & _solution) {
|
||||
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 as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moBitFlipNeighborhood";
|
||||
}
|
||||
|
||||
protected:
|
||||
// bit flip rate
|
||||
double rate;
|
||||
|
||||
// length of the bit string
|
||||
unsigned int length;
|
||||
|
||||
// maximum number of visited neighbor i.e. number of neighbor to sample in the neighborhood
|
||||
unsigned int sampleSize;
|
||||
|
||||
// number of visited neighbors
|
||||
unsigned nNeighbors;
|
||||
// bit flip rate
|
||||
double rate;
|
||||
|
||||
// length of the bit string
|
||||
unsigned int length;
|
||||
|
||||
// maximum number of visited neighbor i.e. number of neighbor to sample in the neighborhood
|
||||
unsigned int sampleSize;
|
||||
|
||||
// number of visited neighbors
|
||||
unsigned nNeighbors;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -61,10 +61,10 @@ public:
|
|||
int d;
|
||||
int k;
|
||||
|
||||
unsigned i, j;
|
||||
|
||||
_neighbor.getIndices(n, i, j);
|
||||
unsigned i = _neighbor.first();
|
||||
unsigned j = _neighbor.second();
|
||||
|
||||
// _neighbor.getIndices(n, i, j);
|
||||
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]]);
|
||||
|
||||
|
|
|
|||
|
|
@ -107,6 +107,22 @@ public:
|
|||
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:
|
||||
std::pair<unsigned int, unsigned int> indices;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,114 +1,186 @@
|
|||
/*
|
||||
<moShiftNeighbor.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
<moShiftNeighbor.h>
|
||||
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
|
||||
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".
|
||||
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.
|
||||
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
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef _moShiftNeighbor_h
|
||||
#define _moShiftNeighbor_h
|
||||
|
||||
#include <neighborhood/moBackableNeighbor.h>
|
||||
#include <neighborhood/moIndexNeighbor.h>
|
||||
|
||||
/**
|
||||
* Indexed Shift Neighbor
|
||||
* Other name : insertion operator
|
||||
*/
|
||||
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:
|
||||
|
||||
using moIndexNeighbor<EOT, Fitness>::key;
|
||||
using moBackableNeighbor<EOT, Fitness>::fitness;
|
||||
using moIndexNeighbor<EOT, Fitness>::key;
|
||||
using moIndexNeighbor<EOT, Fitness>::index;
|
||||
|
||||
/**
|
||||
* Apply move on a solution regarding a key
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
insertion(_solution, indices.first, indices.second);
|
||||
|
||||
/**
|
||||
* Apply move on a solution regarding a key
|
||||
* @param _sol the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _sol) {
|
||||
unsigned int tmp ;
|
||||
size=_sol.size();
|
||||
translate(key+1);
|
||||
// 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();
|
||||
}
|
||||
_solution.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* fix two indexes regarding a key
|
||||
* @param _key the key allowing to compute the two indexes for the shift
|
||||
*/
|
||||
void translate(unsigned int _key) {
|
||||
int step;
|
||||
int val = _key;
|
||||
int tmpSize = size * (size-1) / 2;
|
||||
// moves from left to right
|
||||
if (val <= tmpSize) {
|
||||
step = size - 1;
|
||||
first = 0;
|
||||
while ((val - step) > 0) {
|
||||
val = val - step;
|
||||
step--;
|
||||
first++;
|
||||
}
|
||||
second = first + val + 1;
|
||||
}
|
||||
// moves from right to left (equivalent moves are avoided)
|
||||
else { /* val > tmpSize */
|
||||
val = val - tmpSize;
|
||||
step = size - 2;
|
||||
second = 0;
|
||||
while ((val - step) > 0) {
|
||||
val = val - step;
|
||||
step--;
|
||||
second++;
|
||||
}
|
||||
first = second + val + 1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* apply the correct insertion to restore the solution (use by moFullEvalByModif)
|
||||
* @param _solution the solution to move back
|
||||
*/
|
||||
virtual void moveBack(EOT& _solution) {
|
||||
if (indices.first < indices.second)
|
||||
insertion(_solution, indices.second - 1, indices.first);
|
||||
else
|
||||
insertion(_solution, indices.second, indices.first + 1);
|
||||
}
|
||||
|
||||
void print() {
|
||||
std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl;
|
||||
/**
|
||||
* 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;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter to fix the two indexes to swap
|
||||
* @param _solution solution from which the neighborhood is visited
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void set(EOT & _solution, unsigned int _first, unsigned int _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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
std::cout << key << ": [" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int first;
|
||||
unsigned int second;
|
||||
unsigned int size;
|
||||
std::pair<unsigned int, unsigned int> indices;
|
||||
|
||||
/**
|
||||
* 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-moStatistics
|
||||
t-moIndexedVectorTabuList
|
||||
t-moRndIndexedVectorTabuList
|
||||
# t-moRndIndexedVectorTabuList
|
||||
t-moDynSpanCoolingSchedule
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@ class moeoConvertPopToObjectiveVectors : public eoUF < const eoPop < MOEOT >, co
|
|||
*/
|
||||
const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop)
|
||||
{
|
||||
std::vector < ObjectiveVector > result;
|
||||
result.resize(_pop.size());
|
||||
std::vector < ObjectiveVector > result(0);
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
result.push_back(_pop[i].objectiveVector());
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public:
|
|||
* Update the island by adding population to send in the imigrants list.
|
||||
* @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.
|
||||
|
|
@ -82,6 +82,11 @@ public:
|
|||
*/
|
||||
virtual bool isStopped(void) const = 0;
|
||||
|
||||
/**
|
||||
* Set the stopped indicator on false
|
||||
*/
|
||||
virtual void setRunning(void) = 0;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
void paradiseo::smp::Bimap<A,B>::removeFromRight(const A& a)
|
||||
{
|
||||
for(auto& it : leftAssociation)
|
||||
if(it->second == a)
|
||||
leftAssociation.erase(it);
|
||||
leftAssociation.erase(remove(leftAssociation.begin(), leftAssociation.end(),
|
||||
[&](std::pair<B,A>& i) -> bool { return i->second == a; }),
|
||||
leftAssociation.end());
|
||||
|
||||
rightAssociation.erase(a);
|
||||
}
|
||||
|
|
@ -59,9 +59,9 @@ void paradiseo::smp::Bimap<A,B>::removeFromRight(const A& 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);
|
||||
rightAssociation.erase(remove(rightAssociation.begin(), rightAssociation.end(),
|
||||
[&](std::pair<A,B>& i) -> bool { return i->second == b; }),
|
||||
rightAssociation.end());
|
||||
|
||||
leftAssociation.erase(b);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,10 @@ void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::operator()()
|
|||
stopped = true;
|
||||
// Let's wait the end of communications with the island model
|
||||
for(auto& message : sentMessages)
|
||||
message.join();
|
||||
message.wait();
|
||||
|
||||
// Clear the sentMessages container
|
||||
sentMessages.clear();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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>
|
||||
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::send(eoSelect<EOT>& _select)
|
||||
{
|
||||
|
|
@ -113,15 +122,15 @@ void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::send(eoSelect<EOT>& _select)
|
|||
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));
|
||||
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());
|
||||
|
||||
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>
|
||||
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::lock_guard<std::mutex> lock(this->m);
|
||||
listImigrants.push(_data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#include <vector>
|
||||
#include <utility>
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
#include <eoEvalFunc.h>
|
||||
#include <eoSelect.h>
|
||||
|
|
@ -112,13 +114,18 @@ public:
|
|||
* Update the list of imigrants.
|
||||
* @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.
|
||||
* @return true if stopped
|
||||
*/
|
||||
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
|
||||
|
|
@ -142,7 +149,7 @@ protected:
|
|||
IntPolicy<EOT>& intPolicy;
|
||||
MigPolicy<EOT>& migPolicy;
|
||||
std::atomic<bool> stopped;
|
||||
std::vector<std::thread> sentMessages;
|
||||
std::vector<std::shared_future<bool>> sentMessages;
|
||||
IslandModel<bEOT>* model;
|
||||
std::function<EOT(bEOT&)> convertFromBase;
|
||||
std::function<bEOT(EOT&)> convertToBase;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ void paradiseo::smp::IslandModel<EOT>::operator()()
|
|||
unsigned i = 0;
|
||||
for(auto it : islands)
|
||||
{
|
||||
it.first->setRunning();
|
||||
threads[i] = std::thread(&AIsland<EOT>::operator(), it.first);
|
||||
i++;
|
||||
}
|
||||
|
|
@ -97,7 +98,10 @@ void paradiseo::smp::IslandModel<EOT>::operator()()
|
|||
|
||||
// Wait the end of messages sending
|
||||
for(auto& message : sentMessages)
|
||||
message.join();
|
||||
message.wait();
|
||||
|
||||
// Clear the sentMessages container
|
||||
sentMessages.clear();
|
||||
|
||||
// Force last integration
|
||||
i = 0;
|
||||
|
|
@ -115,10 +119,12 @@ void paradiseo::smp::IslandModel<EOT>::operator()()
|
|||
}
|
||||
|
||||
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);
|
||||
listEmigrants.push(std::pair<eoPop<EOT>,AIsland<EOT>*>(_data, _island));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
|
|
@ -150,11 +156,17 @@ void paradiseo::smp::IslandModel<EOT>::send(void)
|
|||
|
||||
// Send elements to neighbors
|
||||
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)
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<class EOT>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#include <queue>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <future>
|
||||
#include <thread>
|
||||
|
||||
#include <bimap.h>
|
||||
|
|
@ -71,7 +72,7 @@ public:
|
|||
/**
|
||||
* 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
|
||||
|
|
@ -99,7 +100,7 @@ protected:
|
|||
Bimap<unsigned, AIsland<EOT>*> table;
|
||||
std::vector<std::pair<AIsland<EOT>*, bool>> islands;
|
||||
AbstractTopology& topo;
|
||||
std::vector<std::thread> sentMessages;
|
||||
std::vector<std::shared_future<bool>> sentMessages;
|
||||
std::mutex m;
|
||||
std::atomic<bool> running;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,18 +32,15 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
|
||||
void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||
{
|
||||
if(nbNode != matrix.size())
|
||||
{
|
||||
matrix.clear();
|
||||
matrix.clear();
|
||||
|
||||
matrix.resize(nbNode);
|
||||
for(auto& line : matrix)
|
||||
line.resize(nbNode);
|
||||
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;
|
||||
}
|
||||
std::vector<bool> line;
|
||||
line.assign(nbNode,true);
|
||||
matrix.assign(nbNode, line);
|
||||
for(unsigned i = 0; i < nbNode; i++)
|
||||
matrix[i][i]=false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,32 +34,29 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
|
||||
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);
|
||||
// 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++;
|
||||
unsigned power = 0, i, j;
|
||||
while((nbNode & 1 << power) == 0)
|
||||
power++;
|
||||
|
||||
matrix.clear();
|
||||
matrix.resize(nbNode);
|
||||
matrix.clear();
|
||||
matrix.resize(nbNode);
|
||||
|
||||
for(auto& line : matrix)
|
||||
line.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
|
||||
}
|
||||
}
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,19 +32,16 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
|
||||
void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||
{
|
||||
if(nbNode != matrix.size())
|
||||
{
|
||||
matrix.clear();
|
||||
matrix.clear();
|
||||
|
||||
matrix.resize(nbNode);
|
||||
for(auto& line : matrix)
|
||||
line.resize(nbNode);
|
||||
matrix.resize(nbNode);
|
||||
for(auto& line : matrix)
|
||||
line.resize(nbNode);
|
||||
|
||||
std::vector<bool> line;
|
||||
line.assign(nbNode, false);
|
||||
matrix.assign(nbNode, line);
|
||||
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;
|
||||
}
|
||||
for(unsigned i=0; i < nbNode; i++)
|
||||
matrix[i][(i+1)%nbNode]=true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue