Merge branch 'master' of git+ssh://localhost:8481/gitroot/paradiseo/paradiseo

This commit is contained in:
Johann Dreo 2013-02-22 14:01:12 +01:00
commit 6cd61e2e2c
28 changed files with 560 additions and 425 deletions

View file

@ -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)
######################################################################################

View 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)

View file

@ -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()

View file

@ -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()

View file

@ -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()
######################################################################################

View file

@ -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

View file

@ -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()

View file

@ -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>

View file

@ -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,7 +219,6 @@ 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();
@ -255,12 +229,13 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
eoPop<EOT> empty_pop;
popEval(empty_pop, _pop); // A first eval of pop.
do
{
try
{
unsigned pSize = _pop.size();
offspring.clear(); // new offspring
breed(_pop, offspring);
@ -273,6 +248,7 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
throw std::runtime_error("Population shrinking!");
else if (pSize < _pop.size())
throw std::runtime_error("Population growing!");
}
catch (std::exception& e)
{

View file

@ -55,7 +55,7 @@ public :
throw eoEvalFuncCounterBounderException(_threshold);
}
func(eo);
this->func(eo);
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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,9 +58,14 @@ public:
* @return value of monOp
*/
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();
fullEval(_solution);
return res;
}
@ -67,6 +73,7 @@ private:
/** monOp */
eoMonOp<EOT>& monOp;
eoEvalFunc<EOT>& fullEval;
unsigned int nbPerturbation;
};
#endif

View file

@ -30,7 +30,7 @@
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
*/
#ifndef _moBitFlipNeighborhood_h
#define _moBitFlipNeighborhood_h
@ -136,6 +136,14 @@ public:
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

View file

@ -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]]);

View file

@ -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;

View file

@ -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 moBackableNeighbor<EOT, Fitness>::fitness;
using moIndexNeighbor<EOT, Fitness>::key;
using moIndexNeighbor<EOT, Fitness>::index;
/**
* 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) {
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();
virtual void move(EOT & _solution) {
insertion(_solution, indices.first, indices.second);
_solution.invalidate();
}
/**
* fix two indexes regarding a key
* @param _key the key allowing to compute the two indexes for the shift
* apply the correct insertion to restore the solution (use by moFullEvalByModif)
* @param _solution the solution to move back
*/
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++;
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);
}
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;
step = size - 2;
second = 0;
while ((val - step) > 0) {
val = val - step;
step--;
second++;
/**
* 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 );
}
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() {
std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl;
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;
}
}
};

View file

@ -93,7 +93,7 @@ set (TEST_LIST
t-moNeutralWalkSampling
t-moStatistics
t-moIndexedVectorTabuList
t-moRndIndexedVectorTabuList
# t-moRndIndexedVectorTabuList
t-moDynSpanCoolingSchedule
)

View file

@ -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());

View file

@ -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.
*/

View file

@ -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);
}

View file

@ -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)
{
@ -114,14 +123,14 @@ void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::send(eoSelect<EOT>& _select)
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.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::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>
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;
}

View file

@ -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,7 +114,7 @@ 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.
@ -120,6 +122,11 @@ public:
*/
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;

View file

@ -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>

View file

@ -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;
};

View file

@ -32,8 +32,6 @@ 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.resize(nbNode);
@ -45,5 +43,4 @@ void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector<std::vect
matrix.assign(nbNode, line);
for(unsigned i = 0; i < nbNode; i++)
matrix[i][i]=false;
}
}

View file

@ -34,8 +34,6 @@ 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);
@ -57,9 +55,8 @@ void paradiseo::smp::Hypercubic::operator()(unsigned nbNode, std::vector<std::ve
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
}
matrix[i+stepNbNode][j+stepNbNode] = matrix[i][j]; //Diagonal part
matrix[i][j+stepNbNode] = matrix[i+stepNbNode][j] = (i == j); //Identity
}
}
}

View file

@ -32,8 +32,6 @@ 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.resize(nbNode);
@ -46,5 +44,4 @@ void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector<std::vector<b
for(unsigned i=0; i < nbNode; i++)
matrix[i][(i+1)%nbNode]=true;
}
}