git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@620 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
ae34cb14eb
commit
27fd82ba4b
8 changed files with 799 additions and 1 deletions
|
|
@ -30,6 +30,11 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~peoParallelAlgorithmWrapper() {
|
||||||
|
|
||||||
|
delete algorithm;
|
||||||
|
}
|
||||||
|
|
||||||
void run() { algorithm->operator()(); }
|
void run() { algorithm->operator()(); }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
234
trunk/paradiseo-peo/src/peoSynchronousMultiStart.h
Normal file
234
trunk/paradiseo-peo/src/peoSynchronousMultiStart.h
Normal file
|
|
@ -0,0 +1,234 @@
|
||||||
|
#ifndef __peoSynchronousMultiStart_h
|
||||||
|
#define __peoSynchronousMultiStart_h
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "core/service.h"
|
||||||
|
#include "core/messaging.h"
|
||||||
|
|
||||||
|
|
||||||
|
template < typename EntityType > class peoSynchronousMultiStart : public Service {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
template < typename AlgorithmType > peoSynchronousMultiStart( AlgorithmType& externalAlgorithm ) {
|
||||||
|
|
||||||
|
singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm );
|
||||||
|
algorithms.push_back( singularAlgorithm );
|
||||||
|
|
||||||
|
aggregationFunction = new NoAggregationFunction();
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename AlgorithmType, typename AggregationFunctionType > peoSynchronousMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction ) {
|
||||||
|
|
||||||
|
for ( unsigned int index = 0; index < externalAlgorithms; index++ ) {
|
||||||
|
|
||||||
|
algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
aggregationFunction = new Algorithm< AggregationFunctionType >( externalAggregationFunction );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
~peoSynchronousMultiStart() {
|
||||||
|
|
||||||
|
for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ];
|
||||||
|
for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ];
|
||||||
|
|
||||||
|
delete aggregationFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template < typename Type > void operator()( Type& externalData ) {
|
||||||
|
|
||||||
|
for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ ) {
|
||||||
|
|
||||||
|
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
functionIndex = dataIndex = idx = num_term = 0;
|
||||||
|
requestResourceRequest( data.size() * algorithms.size() );
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd ) {
|
||||||
|
|
||||||
|
for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ ) {
|
||||||
|
|
||||||
|
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
functionIndex = dataIndex = idx = num_term = 0;
|
||||||
|
requestResourceRequest( data.size() * algorithms.size() );
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void packData();
|
||||||
|
|
||||||
|
void unpackData();
|
||||||
|
|
||||||
|
void execute();
|
||||||
|
|
||||||
|
void packResult();
|
||||||
|
|
||||||
|
void unpackResult();
|
||||||
|
|
||||||
|
void notifySendingData();
|
||||||
|
|
||||||
|
void notifySendingAllResourceRequests();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
template < typename Type > struct DataType;
|
||||||
|
|
||||||
|
struct AbstractDataType {
|
||||||
|
|
||||||
|
virtual ~AbstractDataType() { }
|
||||||
|
|
||||||
|
template < typename Type > operator Type& () {
|
||||||
|
|
||||||
|
return ( dynamic_cast< DataType< Type >& >( *this ) ).data;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename Type > struct DataType : public AbstractDataType {
|
||||||
|
|
||||||
|
DataType( Type& externalData ) : data( externalData ) { }
|
||||||
|
|
||||||
|
Type& data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AbstractAlgorithm {
|
||||||
|
|
||||||
|
virtual ~AbstractAlgorithm() { }
|
||||||
|
|
||||||
|
virtual void operator()( AbstractDataType& dataTypeInstance ) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm {
|
||||||
|
|
||||||
|
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) { }
|
||||||
|
|
||||||
|
void operator()( AbstractDataType& dataTypeInstance ) { algorithm( dataTypeInstance ); }
|
||||||
|
|
||||||
|
AlgorithmType& algorithm;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct AbstractAggregationAlgorithm {
|
||||||
|
|
||||||
|
virtual ~AbstractAggregationAlgorithm() { }
|
||||||
|
|
||||||
|
virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) {};
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename AggregationAlgorithmType > struct AggregationAlgorithm : public AbstractAggregationAlgorithm {
|
||||||
|
|
||||||
|
AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm ) { }
|
||||||
|
|
||||||
|
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) {
|
||||||
|
|
||||||
|
aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB );
|
||||||
|
}
|
||||||
|
|
||||||
|
AggregationAlgorithmType& aggregationAlgorithm;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NoAggregationFunction : public AbstractAggregationAlgorithm {
|
||||||
|
|
||||||
|
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) {
|
||||||
|
|
||||||
|
static_cast< EntityType& >( dataTypeInstanceA ) = static_cast< EntityType& >( dataTypeInstanceB );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AbstractAlgorithm* singularAlgorithm;
|
||||||
|
|
||||||
|
std::vector< AbstractAlgorithm* > algorithms;
|
||||||
|
AbstractAggregationAlgorithm* aggregationFunction;
|
||||||
|
|
||||||
|
|
||||||
|
EntityType entityTypeInstance;
|
||||||
|
std::vector< AbstractDataType* > data;
|
||||||
|
|
||||||
|
unsigned idx;
|
||||||
|
unsigned num_term;
|
||||||
|
unsigned dataIndex;
|
||||||
|
unsigned functionIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packData() {
|
||||||
|
|
||||||
|
::pack( functionIndex );
|
||||||
|
::pack( idx );
|
||||||
|
::pack( ( EntityType& ) *data[ idx++ ] );
|
||||||
|
|
||||||
|
// done with functionIndex for the entire data set - moving to another
|
||||||
|
// function/algorithm starting all over with the entire data set ( idx is set to 0 )
|
||||||
|
if ( idx == data.size() ) {
|
||||||
|
|
||||||
|
++functionIndex; idx = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackData() {
|
||||||
|
|
||||||
|
::unpack( functionIndex );
|
||||||
|
::unpack( dataIndex );
|
||||||
|
::unpack( entityTypeInstance );
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::execute() {
|
||||||
|
|
||||||
|
// wrapping the unpacked data - the definition of an abstract algorithm imposes
|
||||||
|
// that its internal function operator acts only on abstract data types
|
||||||
|
AbstractDataType* entityWrapper = new DataType< EntityType >( entityTypeInstance );
|
||||||
|
algorithms[ functionIndex ]->operator()( *entityWrapper );
|
||||||
|
|
||||||
|
delete entityWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packResult() {
|
||||||
|
|
||||||
|
::pack( dataIndex );
|
||||||
|
::pack( entityTypeInstance );
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackResult() {
|
||||||
|
|
||||||
|
::unpack( dataIndex );
|
||||||
|
::unpack( entityTypeInstance );
|
||||||
|
|
||||||
|
// wrapping the unpacked data - the definition of an abstract algorithm imposes
|
||||||
|
// that its internal function operator acts only on abstract data types
|
||||||
|
AbstractDataType* entityWrapper = new DataType< EntityType >( entityTypeInstance );
|
||||||
|
aggregationFunction->operator()( *data[ dataIndex ], *entityWrapper );
|
||||||
|
delete entityWrapper;
|
||||||
|
|
||||||
|
num_term++;
|
||||||
|
|
||||||
|
if ( num_term == data.size() * algorithms.size() ) {
|
||||||
|
|
||||||
|
getOwner()->setActive();
|
||||||
|
resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::notifySendingData() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::notifySendingAllResourceRequests() {
|
||||||
|
|
||||||
|
getOwner()->setPassive();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -11,6 +11,6 @@ SET(TSP_BINARY_DIR ${ParadisEO-PEO_BINARY_DIR}/tutorial/examples/tsp)
|
||||||
### 2) Where must cmake go now ?
|
### 2) Where must cmake go now ?
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
SUBDIRS(examples Lesson1 Lesson2 Lesson3 Walkthrough)
|
SUBDIRS(examples Lesson1 Lesson2 Lesson3 LessonParallelAlgorithm Walkthrough)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 0) Set the compiler and define targets to easily run the lessons
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
SET (CMAKE_CXX_COMPILER mpicxx)
|
||||||
|
|
||||||
|
ADD_CUSTOM_TARGET(install DEPENDS ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson1/lesson.param ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson1/schema.xml)
|
||||||
|
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
TARGET install
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
ARGS -E copy_if_different
|
||||||
|
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson1/lesson.param
|
||||||
|
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson1)
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
TARGET install
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
ARGS -E copy_if_different
|
||||||
|
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson1/schema.xml
|
||||||
|
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson1)
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 1) Include the sources
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(${EO_SRC_DIR})
|
||||||
|
INCLUDE_DIRECTORIES(${MO_SRC_DIR})
|
||||||
|
INCLUDE_DIRECTORIES(${PEO_SRC_DIR})
|
||||||
|
INCLUDE_DIRECTORIES(${TSP_SRC_DIR})
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 2) Specify where CMake can find the libraries (mandatory: before 3) )
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
LINK_DIRECTORIES( ${EO_SRC_DIR}
|
||||||
|
${EO_SRC_DIR}/utils
|
||||||
|
${ParadisEO-PEO_BINARY_DIR}/lib
|
||||||
|
${TSP_BINARY_DIR}/lib)
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 3) Define your target(s): just an executable here
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
# no matter what is the OS, hopefully
|
||||||
|
ADD_EXECUTABLE(parallelAlgorithmExample main.cpp)
|
||||||
|
|
||||||
|
ADD_DEPENDENCIES(parallelAlgorithmExample tsp)
|
||||||
|
ADD_DEPENDENCIES(parallelAlgorithmExample peo)
|
||||||
|
ADD_DEPENDENCIES(parallelAlgorithmExample rmc_mpi)
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 4) Optionnal: define your target(s)'s version: no effect for windows
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
SET(LESSON1_VERSION "1.0.beta")
|
||||||
|
SET_TARGET_PROPERTIES(parallelAlgorithmExample PROPERTIES VERSION "${LESSONPARAALG_VERSION}")
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
### 5) Link the librairies
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
TARGET_LINK_LIBRARIES(parallelAlgorithmExample ${XML2_LIBS}) # define in CMakeLists.txt at PEO root dir
|
||||||
|
TARGET_LINK_LIBRARIES(parallelAlgorithmExample tsp)
|
||||||
|
TARGET_LINK_LIBRARIES(parallelAlgorithmExample peo)
|
||||||
|
TARGET_LINK_LIBRARIES(parallelAlgorithmExample rmc_mpi)
|
||||||
|
TARGET_LINK_LIBRARIES(parallelAlgorithmExample eo)
|
||||||
|
TARGET_LINK_LIBRARIES(parallelAlgorithmExample eoutils)
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
## miscallenous parameters
|
||||||
|
|
||||||
|
--debug=false
|
||||||
|
|
||||||
|
## deployment schema
|
||||||
|
|
||||||
|
--schema=schema.xml
|
||||||
|
|
||||||
|
## parameters
|
||||||
|
|
||||||
|
--inst=../examples/tsp/benchs/eil101.tsp
|
||||||
|
|
||||||
337
trunk/paradiseo-peo/tutorial/LessonParallelAlgorithm/main.cpp
Normal file
337
trunk/paradiseo-peo/tutorial/LessonParallelAlgorithm/main.cpp
Normal file
|
|
@ -0,0 +1,337 @@
|
||||||
|
// "main.cpp"
|
||||||
|
|
||||||
|
// (c) OPAC Team, LIFL, January 2006
|
||||||
|
|
||||||
|
/*
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
|
#include <paradiseo>
|
||||||
|
|
||||||
|
#include <peoParallelAlgorithmWrapper.h>
|
||||||
|
#include <peoSynchronousMultiStart.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "route.h"
|
||||||
|
#include "route_init.h"
|
||||||
|
#include "route_eval.h"
|
||||||
|
|
||||||
|
#include "order_xover.h"
|
||||||
|
#include "city_swap.h"
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <mo.h>
|
||||||
|
|
||||||
|
#include <graph.h>
|
||||||
|
#include <route.h>
|
||||||
|
#include <route_eval.h>
|
||||||
|
#include <route_init.h>
|
||||||
|
|
||||||
|
#include <two_opt.h>
|
||||||
|
#include <two_opt_init.h>
|
||||||
|
#include <two_opt_next.h>
|
||||||
|
#include <two_opt_incr_eval.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define RANDOM_POP_SIZE 30
|
||||||
|
#define RANDOM_ITERATIONS 10
|
||||||
|
|
||||||
|
|
||||||
|
#define POP_SIZE 10
|
||||||
|
#define NUM_GEN 100
|
||||||
|
#define CROSS_RATE 1.0
|
||||||
|
#define MUT_RATE 0.01
|
||||||
|
|
||||||
|
#define NUMBER_OF_POPULATIONS 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct RandomExplorationAlgorithm {
|
||||||
|
|
||||||
|
RandomExplorationAlgorithm( peoPopEval< Route >& __popEval, peoSynchronousMultiStart< Route >& extParallelExecution )
|
||||||
|
: popEval( __popEval ), parallelExecution( extParallelExecution ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// the sequential algorithm to be executed in parallel by the wrapper
|
||||||
|
void operator()() {
|
||||||
|
|
||||||
|
RouteInit route_init; // random init object - creates random Route objects
|
||||||
|
RouteEval route_eval;
|
||||||
|
eoPop< Route > population( RANDOM_POP_SIZE, route_init );
|
||||||
|
|
||||||
|
popEval( population );
|
||||||
|
|
||||||
|
|
||||||
|
// executing HCs on the population in parallel
|
||||||
|
parallelExecution( population );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// just to show off :: HCs on a vector of Route objects
|
||||||
|
{
|
||||||
|
Route* rVect = new Route[ 5 ];
|
||||||
|
for ( unsigned int index = 0; index < 5; index++ ) {
|
||||||
|
|
||||||
|
route_init( rVect[ index ] ); route_eval( rVect[ index ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
// applying the HCs on the vector of Route objects
|
||||||
|
parallelExecution( rVect, rVect + 5 );
|
||||||
|
delete[] rVect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Route bestRoute = population.best_element();
|
||||||
|
|
||||||
|
for ( unsigned int index = 0; index < RANDOM_ITERATIONS; index++ ) {
|
||||||
|
|
||||||
|
for ( unsigned int routeIndex = 0; routeIndex < RANDOM_POP_SIZE; routeIndex++ ) {
|
||||||
|
|
||||||
|
route_init( population[ routeIndex ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
popEval( population );
|
||||||
|
|
||||||
|
if ( fabs( population.best_element().fitness() ) < fabs( bestRoute.fitness() ) ) bestRoute = population.best_element();
|
||||||
|
|
||||||
|
std::cout << "Random Iteration #" << index << "... [ " << bestRoute.fitness() << " ]" << std::flush << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
peoPopEval< Route >& popEval;
|
||||||
|
peoSynchronousMultiStart< Route >& parallelExecution;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main( int __argc, char** __argv ) {
|
||||||
|
|
||||||
|
srand( time(NULL) );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// initializing the ParadisEO-PEO environment
|
||||||
|
peo :: init( __argc, __argv );
|
||||||
|
|
||||||
|
|
||||||
|
// processing the command line specified parameters
|
||||||
|
loadParameters( __argc, __argv );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
// #1 An EO evolutionary algorithm to be executed in parallel with other algorithms (no parallel evaluation, no etc.).
|
||||||
|
|
||||||
|
// init, eval operators, EA operators -------------------------------------------------------------------------------------------------------------
|
||||||
|
RouteInit route_init; // random init object - creates random Route objects
|
||||||
|
RouteEval full_eval; // evaluator object - offers a fitness value for a specified Route object
|
||||||
|
|
||||||
|
OrderXover crossover; // crossover operator - creates two offsprings out of two specified parents
|
||||||
|
CitySwap mutation; // mutation operator - randomly mutates one gene for a specified individual
|
||||||
|
// ------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// evolutionary algorithm components --------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
eoPop< Route > population( POP_SIZE, route_init ); // initial population for the algorithm having POP_SIZE individuals
|
||||||
|
|
||||||
|
eoGenContinue< Route > eaCont( NUM_GEN ); // continuation criterion - the algorithm will iterate for NUM_GEN generations
|
||||||
|
eoCheckPoint< Route > eaCheckpointContinue( eaCont ); // checkpoint object - verify at each iteration if the continuation criterion is met
|
||||||
|
|
||||||
|
eoRankingSelect< Route > selectionStrategy; // selection strategy - applied at each iteration for selecting parent individuals
|
||||||
|
eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE ); // selection object - POP_SIZE individuals are selected at each iteration
|
||||||
|
|
||||||
|
// transform operator - includes the crossover and the mutation operators with a specified associated rate
|
||||||
|
eoSGATransform< Route > transform( crossover, CROSS_RATE, mutation, MUT_RATE );
|
||||||
|
|
||||||
|
eoPlusReplacement< Route > eaReplace; // replacement strategy - for replacing the initial population with offspring individuals
|
||||||
|
// ------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// SEQENTIAL ALGORITHM DEFINITION -----------------------------------------------------------------------------------------------------------------
|
||||||
|
eoEasyEA< Route > eaAlg( eaCheckpointContinue, full_eval, eaSelect, transform, eaReplace );
|
||||||
|
// SEQENTIAL ALGORITHM DEFINITION -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
peoParallelAlgorithmWrapper parallelEAAlg( eaAlg, population ); // specifying the embedded algorithm and the algorithm input data
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
// #2 A MO hill climbing to be executed in parallel with other algorithms (no parallel evaluation, no etc.).
|
||||||
|
|
||||||
|
if ( getNodeRank() == 1 ) {
|
||||||
|
|
||||||
|
Graph::load( __argv [ 1 ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
Route route;
|
||||||
|
RouteInit init; init( route );
|
||||||
|
RouteEval full_evalHC; full_evalHC( route );
|
||||||
|
|
||||||
|
if ( getNodeRank() == 1 ) {
|
||||||
|
|
||||||
|
std :: cout << "[From] " << route << std :: endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TwoOptInit two_opt_init;
|
||||||
|
TwoOptNext two_opt_next;
|
||||||
|
TwoOptIncrEval two_opt_incr_eval;
|
||||||
|
|
||||||
|
moBestImprSelect< TwoOpt > two_opt_select;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// SEQENTIAL ALGORITHM DEFINITION -----------------------------------------------------------------------------------------------------------------
|
||||||
|
moHC< TwoOpt > hill_climbing( two_opt_init, two_opt_next, two_opt_incr_eval, two_opt_select, full_evalHC );
|
||||||
|
// SEQENTIAL ALGORITHM DEFINITION -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
peoParallelAlgorithmWrapper parallelHillClimbing( hill_climbing, route ); // specifying the embedded algorithm and the algorithm input data
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
// #3 A user defined algorithm to be executed in parallel with other algorithms - parallel evaluation and synchronous
|
||||||
|
// multi-start of several hill-climbing algorithms (inside the user defined algorithm)!!.
|
||||||
|
|
||||||
|
RouteEval full_evalRandom;
|
||||||
|
peoParaPopEval< Route > randomParaEval( full_evalRandom );
|
||||||
|
|
||||||
|
|
||||||
|
peoSynchronousMultiStart< Route > parallelExecution( hill_climbing );
|
||||||
|
|
||||||
|
RandomExplorationAlgorithm randomExplorationAlgorithm( randomParaEval, parallelExecution );
|
||||||
|
|
||||||
|
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
peoParallelAlgorithmWrapper parallelRandExp( randomExplorationAlgorithm ); // specifying the embedded algorithm - no input data in this case
|
||||||
|
|
||||||
|
randomParaEval.setOwner( parallelRandExp );
|
||||||
|
parallelExecution.setOwner( parallelRandExp );
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
// #4 Synchronous Multi-Start: several hill-climbing algorithms launched in parallel on different initial solutions
|
||||||
|
|
||||||
|
RouteInit ex_hc_route_init; // random init object - creates random Route objects
|
||||||
|
RouteEval ex_hc_full_eval; // evaluator object - offers a fitness value for a specified Route object
|
||||||
|
|
||||||
|
eoPop< Route > ex_hc_population( POP_SIZE, ex_hc_route_init );
|
||||||
|
|
||||||
|
for ( unsigned int index = 0; index < POP_SIZE; index++ ) {
|
||||||
|
|
||||||
|
ex_hc_full_eval( ex_hc_population[ index ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
peoSynchronousMultiStart< Route > ex_hc_parallelExecution( hill_climbing );
|
||||||
|
peoParallelAlgorithmWrapper ex_hc_parallel( ex_hc_parallelExecution, ex_hc_population ); // specifying the embedded algorithm - no input data in this case
|
||||||
|
|
||||||
|
ex_hc_parallelExecution.setOwner( ex_hc_parallel );
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
// #5 Synchronous Multi-Start: Multiple EO evolutionary algorithms to be executed in parallel
|
||||||
|
// (inside different processes, on different populations; no parallel evaluation, no etc.).
|
||||||
|
|
||||||
|
RouteInit ex_route_init; // random init object - creates random Route objects
|
||||||
|
RouteEval ex_full_eval; // evaluator object - offers a fitness value for a specified Route object
|
||||||
|
|
||||||
|
std::vector< eoPop< Route > > ex_population;
|
||||||
|
ex_population.resize( NUMBER_OF_POPULATIONS );
|
||||||
|
|
||||||
|
for ( unsigned int indexPop = 0; indexPop < NUMBER_OF_POPULATIONS; indexPop++ ) {
|
||||||
|
|
||||||
|
ex_population[ indexPop ].resize( POP_SIZE );
|
||||||
|
|
||||||
|
for ( unsigned int index = 0; index < POP_SIZE; index++ ) {
|
||||||
|
|
||||||
|
ex_route_init( ex_population[ indexPop ][ index ] );
|
||||||
|
ex_full_eval( ex_population[ indexPop ][ index ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
peoSynchronousMultiStart< eoPop< Route > > ex_parallelExecution( eaAlg );
|
||||||
|
peoParallelAlgorithmWrapper ex_parallel( ex_parallelExecution, ex_population ); // specifying the embedded algorithm - no input data in this case
|
||||||
|
|
||||||
|
ex_parallelExecution.setOwner( ex_parallel );
|
||||||
|
// SETTING UP THE PARALLEL WRAPPER ----------------------------------------------------------------------------------------------------------------
|
||||||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
peo :: run( );
|
||||||
|
peo :: finalize( );
|
||||||
|
// shutting down the ParadisEO-PEO environment
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// the algorithm is executed in the #1 rank process
|
||||||
|
if ( getNodeRank() == 1 ) {
|
||||||
|
|
||||||
|
std :: cout << "[To] " << route << std :: endl << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
std :: cout << "Synchronous Multi-Start HCs:" << std :: endl ;
|
||||||
|
for ( unsigned int index = 0; index < POP_SIZE; index++ ) {
|
||||||
|
|
||||||
|
std::cout << ex_hc_population[ index ] << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
std :: cout << "Synchronous Multi-Start EAs:" << std :: endl ;
|
||||||
|
for ( unsigned int index = 0; index < NUMBER_OF_POPULATIONS; index++ ) {
|
||||||
|
|
||||||
|
std::cout << ex_population[ index ] << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl << std::flush;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<schema>
|
||||||
|
<group scheduler="0">
|
||||||
|
<node name="0" num_workers="0">
|
||||||
|
</node>
|
||||||
|
<node name="1" num_workers="0">
|
||||||
|
<runner>1</runner>
|
||||||
|
<runner>2</runner>
|
||||||
|
<runner>3</runner>
|
||||||
|
<runner>4</runner>
|
||||||
|
<runner>5</runner>
|
||||||
|
</node>
|
||||||
|
<node name="2" num_workers="1">
|
||||||
|
</node>
|
||||||
|
<node name="3" num_workers="1">
|
||||||
|
</node>
|
||||||
|
</group>
|
||||||
|
</schema>
|
||||||
102
trunk/paradiseo-peo/tutorial/examples/tsp/benchs/eil101.tsp.hc
Normal file
102
trunk/paradiseo-peo/tutorial/examples/tsp/benchs/eil101.tsp.hc
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
101
|
||||||
|
41 49
|
||||||
|
35 17
|
||||||
|
55 45
|
||||||
|
55 20
|
||||||
|
15 30
|
||||||
|
25 30
|
||||||
|
20 50
|
||||||
|
10 43
|
||||||
|
55 60
|
||||||
|
30 60
|
||||||
|
20 65
|
||||||
|
50 35
|
||||||
|
30 25
|
||||||
|
15 10
|
||||||
|
30 5
|
||||||
|
10 20
|
||||||
|
5 30
|
||||||
|
20 40
|
||||||
|
15 60
|
||||||
|
45 65
|
||||||
|
45 20
|
||||||
|
45 10
|
||||||
|
55 5
|
||||||
|
65 35
|
||||||
|
65 20
|
||||||
|
45 30
|
||||||
|
35 40
|
||||||
|
41 37
|
||||||
|
64 42
|
||||||
|
40 60
|
||||||
|
31 52
|
||||||
|
35 69
|
||||||
|
53 52
|
||||||
|
65 55
|
||||||
|
63 65
|
||||||
|
2 60
|
||||||
|
20 20
|
||||||
|
5 5
|
||||||
|
60 12
|
||||||
|
40 25
|
||||||
|
42 7
|
||||||
|
24 12
|
||||||
|
23 3
|
||||||
|
11 14
|
||||||
|
6 38
|
||||||
|
2 48
|
||||||
|
8 56
|
||||||
|
13 52
|
||||||
|
6 68
|
||||||
|
47 47
|
||||||
|
49 58
|
||||||
|
27 43
|
||||||
|
37 31
|
||||||
|
57 29
|
||||||
|
63 23
|
||||||
|
53 12
|
||||||
|
32 12
|
||||||
|
36 26
|
||||||
|
21 24
|
||||||
|
17 34
|
||||||
|
12 24
|
||||||
|
24 58
|
||||||
|
27 69
|
||||||
|
15 77
|
||||||
|
62 77
|
||||||
|
49 73
|
||||||
|
67 5
|
||||||
|
56 39
|
||||||
|
37 47
|
||||||
|
37 56
|
||||||
|
57 68
|
||||||
|
47 16
|
||||||
|
44 17
|
||||||
|
46 13
|
||||||
|
49 11
|
||||||
|
49 42
|
||||||
|
53 43
|
||||||
|
61 52
|
||||||
|
57 48
|
||||||
|
56 37
|
||||||
|
55 54
|
||||||
|
15 47
|
||||||
|
14 37
|
||||||
|
11 31
|
||||||
|
16 22
|
||||||
|
4 18
|
||||||
|
28 18
|
||||||
|
26 52
|
||||||
|
26 35
|
||||||
|
31 67
|
||||||
|
15 19
|
||||||
|
22 22
|
||||||
|
18 24
|
||||||
|
26 27
|
||||||
|
25 24
|
||||||
|
22 27
|
||||||
|
25 21
|
||||||
|
19 21
|
||||||
|
20 26
|
||||||
|
18 18
|
||||||
|
35 35
|
||||||
Loading…
Add table
Add a link
Reference in a new issue