Lesson7 and Lesson8 added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@924 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
e7f6d3ca83
commit
e7b97ea34f
10 changed files with 728 additions and 0 deletions
59
trunk/paradiseo-peo/tutorial/Lesson6/make/make_peoMoeoPop.h
Normal file
59
trunk/paradiseo-peo/tutorial/Lesson6/make/make_peoMoeoPop.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
template <class EOT>
|
||||
peoMoeoPop<EOT>& do_make_pop(eoParser & _parser, eoState& _state, eoInit<EOT> & _init)
|
||||
{
|
||||
// random seed
|
||||
eoValueParam<uint32_t>& seedParam = _parser.createParam(uint32_t(0), "seed", "Random number seed", 'S');
|
||||
if (seedParam.value() == 0)
|
||||
seedParam.value() = time(0);
|
||||
eoValueParam<unsigned>& popSize = _parser.createParam(unsigned(20), "popSize", "Population Size", 'P', "Evolution Engine");
|
||||
|
||||
// Either load or initialize
|
||||
// create an empty pop and let the state handle the memory
|
||||
peoMoeoPop<EOT>& pop = _state.takeOwnership(peoMoeoPop<EOT>());
|
||||
|
||||
eoValueParam<std::string>& loadNameParam = _parser.createParam(std::string(""), "Load","A save file to restart from",'L', "Persistence" );
|
||||
eoValueParam<bool> & recomputeFitnessParam = _parser.createParam(false, "recomputeFitness", "Recompute the fitness after re-loading the pop.?", 'r', "Persistence" );
|
||||
|
||||
if (loadNameParam.value() != "") // something to load
|
||||
{
|
||||
// create another state for reading
|
||||
eoState inState; // a state for loading - WITHOUT the parser
|
||||
// register the rng and the pop in the state, so they can be loaded,
|
||||
// and the present run will be the exact continuation of the saved run
|
||||
// eventually with different parameters
|
||||
inState.registerObject(pop);
|
||||
inState.registerObject(rng);
|
||||
inState.load(loadNameParam.value()); // load the pop and the rng
|
||||
// the fitness is read in the file:
|
||||
// do only evaluate the pop if the fitness has changed
|
||||
if (recomputeFitnessParam.value())
|
||||
{
|
||||
for (unsigned i=0; i<pop.size(); i++)
|
||||
pop[i].invalidate();
|
||||
}
|
||||
if (pop.size() < popSize.value())
|
||||
std::cerr << "WARNING, only " << pop.size() << " individuals read in file " << loadNameParam.value() << "\nThe remaining " << popSize.value() - pop.size() << " will be randomly drawn" << std::endl;
|
||||
if (pop.size() > popSize.value())
|
||||
{
|
||||
std::cerr << "WARNING, Load file contained too many individuals. Only the best will be retained" << std::endl;
|
||||
pop.resize(popSize.value());
|
||||
}
|
||||
}
|
||||
else // nothing loaded from a file
|
||||
{
|
||||
rng.reseed(seedParam.value());
|
||||
}
|
||||
|
||||
if (pop.size() < popSize.value()) // missing some guys
|
||||
{
|
||||
// Init pop from the randomizer: need to use the append function
|
||||
pop.append(popSize.value(), _init);
|
||||
}
|
||||
|
||||
// for future stateSave, register the algorithm into the state
|
||||
_state.registerObject(_parser);
|
||||
_state.registerObject(pop);
|
||||
_state.registerObject(rng);
|
||||
|
||||
return pop;
|
||||
}
|
||||
80
trunk/paradiseo-peo/tutorial/Lesson7/CMakeLists.txt
Normal file
80
trunk/paradiseo-peo/tutorial/Lesson7/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
|
||||
######################################################################################
|
||||
### 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/Lesson7/param ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson7/schema.xml)
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET install
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy_if_different
|
||||
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson7/param
|
||||
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson7)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET install
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy_if_different
|
||||
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson7/schema.xml
|
||||
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson7)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src ${MOEO_SRC_DIR}/src ${MO_SRC_DIR}/src ${ParadisEO-PEO_SOURCE_DIR}/src)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-PEO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}\\lib\\${CMAKE_BUILD_TYPE} ${ParadisEO-PEO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your target(s): just an executable here
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(algo main.cpp)
|
||||
ADD_DEPENDENCIES(algo peo rmc_mpi)
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal: define properties
|
||||
######################################################################################
|
||||
|
||||
SET(Lesson7_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(algo PROPERTIES VERSION "${Lesson7_VERSION}")
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(algo ${XML2_LIBS} peo rmc_mpi eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
153
trunk/paradiseo-peo/tutorial/Lesson7/main.cpp
Normal file
153
trunk/paradiseo-peo/tutorial/Lesson7/main.cpp
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
#include <peo>
|
||||
#include <es.h>
|
||||
|
||||
typedef eoReal<double> Indi;
|
||||
|
||||
double f (const Indi & _indi)
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
}
|
||||
|
||||
// Communications between 2 EA and 1 archive
|
||||
|
||||
|
||||
int main (int __argc, char *__argv[])
|
||||
{
|
||||
|
||||
peo :: init( __argc, __argv );
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int MAX_GEN = 100;
|
||||
const double INIT_POSITION_MIN = -2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const float CROSS_RATE = 0.8;
|
||||
const double EPSILON = 0.01;
|
||||
const float MUT_RATE = 0.3;
|
||||
const unsigned int MIG_FREQ = 2;
|
||||
const unsigned int MIG_SIZE = 2;
|
||||
rng.reseed (time(0));
|
||||
|
||||
|
||||
// Archive
|
||||
|
||||
peoEvalFunc<Indi > plainEval(f);
|
||||
eoEvalFuncCounter < Indi > firstEval(plainEval);
|
||||
eoPopLoopEval < Indi > evalArchive(firstEval);
|
||||
eoUniformGenerator < double > uGenArchive (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > randomArchive (VEC_SIZE, uGenArchive);
|
||||
peoPop < Indi > empty_pop,archive;
|
||||
archive.append(POP_SIZE, randomArchive);
|
||||
evalArchive (empty_pop,archive);
|
||||
archive.sort();
|
||||
if (getNodeRank()==1)
|
||||
std::cout << "Archive before :\n" << archive << std::endl;
|
||||
|
||||
|
||||
|
||||
// First algorithm
|
||||
/*****************************************************************************************/
|
||||
|
||||
RingTopology topology;
|
||||
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
peoEvalFunc<Indi> mainEval( f );
|
||||
peoPopEval <Indi> eval(mainEval);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoBestSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
peoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoBestSelect <Indi> mig_select_one;
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select (mig_select_one,MIG_SIZE,pop);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replace (replace,pop);
|
||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||
eoContinuator<Indi> cont(mig_cont, pop);
|
||||
peoAsyncIslandMig< peoPop<Indi>, peoPop<Indi> > mig(cont,mig_select, mig_replace, topology);
|
||||
checkpoint.add(mig);
|
||||
|
||||
|
||||
eoRandomSelect<Indi> mig_select_oneArchive;
|
||||
eoSelector <Indi, peoPop<Indi> > mig_selectArchive (mig_select_oneArchive,MIG_SIZE,archive);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replaceArchive (replace,archive);
|
||||
eoPeriodicContinue< Indi > mig_contArchive( MIG_FREQ );
|
||||
eoContinuator<Indi> contArchive(mig_contArchive, pop);
|
||||
peoAsyncIslandMig< peoPop<Indi>, peoPop<Indi> > migArchive(contArchive,mig_selectArchive, mig_replaceArchive, topology);
|
||||
checkpoint.add(migArchive);
|
||||
|
||||
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
eval.setOwner(parallelEA);
|
||||
transform.setOwner(parallelEA);
|
||||
mig.setOwner(parallelEA);
|
||||
migArchive.setOwner(parallelEA);
|
||||
|
||||
// Second algorithm
|
||||
/*****************************************************************************************/
|
||||
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||
peoEvalFunc<Indi> mainEval2( f );
|
||||
peoPopEval <Indi> eval2(mainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoBestSelect<Indi> selectionStrategy2;
|
||||
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover2;
|
||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||
peoTransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||
peoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
eoPlusReplacement<Indi> replace2;
|
||||
eoBestSelect <Indi> mig_select_one2;
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select2 (mig_select_one2,MIG_SIZE,pop2);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replace2 (replace2,pop2);
|
||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||
eoContinuator<Indi> cont2(mig_cont2, pop2);
|
||||
peoAsyncIslandMig< peoPop<Indi>, peoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topology);
|
||||
checkpoint2.add(mig2);
|
||||
|
||||
|
||||
eoRandomSelect<Indi> mig_select_oneArchive2;
|
||||
eoSelector <Indi, peoPop<Indi> > mig_selectArchive2 (mig_select_oneArchive2,MIG_SIZE,archive);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replaceArchive2 (replace2,archive);
|
||||
eoPeriodicContinue< Indi > mig_contArchive2( MIG_FREQ );
|
||||
eoContinuator<Indi> contArchive2(mig_contArchive2, pop2);
|
||||
peoAsyncIslandMig< peoPop<Indi>, peoPop<Indi> > migArchive2(contArchive2,mig_selectArchive2, mig_replaceArchive2, topology);
|
||||
checkpoint2.add(migArchive2);
|
||||
|
||||
|
||||
|
||||
eoEasyEA< Indi > eaAlg2( checkpoint2, eval2, select2, transform2, replace2 );
|
||||
peoWrapper parallelEA2( eaAlg2, pop2);
|
||||
eval2.setOwner(parallelEA2);
|
||||
transform2.setOwner(parallelEA2);
|
||||
mig2.setOwner(parallelEA2);
|
||||
migArchive2.setOwner(parallelEA2);
|
||||
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
pop2.sort();
|
||||
archive.sort();
|
||||
std::cout << "Final population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
||||
std::cout << "Archive after :\n" << archive << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
trunk/paradiseo-peo/tutorial/Lesson7/param
Normal file
9
trunk/paradiseo-peo/tutorial/Lesson7/param
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
## miscallenous parameters
|
||||
|
||||
--debug=false
|
||||
|
||||
## deployment schema
|
||||
|
||||
--schema=schema.xml
|
||||
|
||||
|
||||
20
trunk/paradiseo-peo/tutorial/Lesson7/schema.xml
Normal file
20
trunk/paradiseo-peo/tutorial/Lesson7/schema.xml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?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>
|
||||
</node>
|
||||
|
||||
<node name="2" num_workers="1">
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
</node>
|
||||
|
||||
</group>
|
||||
</schema>
|
||||
|
||||
75
trunk/paradiseo-peo/tutorial/Lesson8/CMakeLists.txt
Normal file
75
trunk/paradiseo-peo/tutorial/Lesson8/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
|
||||
######################################################################################
|
||||
### 0) Set the compiler and define targets to easily run the lessons
|
||||
######################################################################################
|
||||
|
||||
SET (CMAKE_CXX_COMPILER mpicxx)
|
||||
SET(MAKE_SRC_DIR "${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson8/make" CACHE PATH "Make source directory" FORCE)
|
||||
|
||||
ADD_CUSTOM_TARGET(install DEPENDS ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson8/param ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson8/schema.xml)
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET install
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy_if_different
|
||||
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson8/param
|
||||
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson8)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET install
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy_if_different
|
||||
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson8/schema.xml
|
||||
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson8)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src ${MOEO_SRC_DIR}/src ${FLOWSHOP_SRC_DIR} ${MO_SRC_DIR}/src ${ParadisEO-PEO_SOURCE_DIR}/src ${TSP_SRC_DIR} ${MAKE_SRC_DIR})
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries (mandatory: before 3) )
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${MOEO_BIN_DIR}/lib ${FLOWSHOP_BIN_DIR}/lib ${ParadisEO-PEO_BINARY_DIR}/lib ${TSP_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your target(s): just an executable here
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(example main.cpp)
|
||||
ADD_DEPENDENCIES(example flowshop moeo peo rmc_mpi)
|
||||
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal: define your target(s)'s version: no effect for windows
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(example ${XML2_LIBS} flowshop moeo peo rmc_mpi eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
116
trunk/paradiseo-peo/tutorial/Lesson8/main.cpp
Normal file
116
trunk/paradiseo-peo/tutorial/Lesson8/main.cpp
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#include <peo>
|
||||
#include <moeo>
|
||||
#include "parallelStruct.h"
|
||||
#include <make_library.h>
|
||||
#include <FlowShop.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
peo :: init( argc,argv );
|
||||
const unsigned int MIG_FREQ = 10;
|
||||
const unsigned int MIG_SIZE = 1;
|
||||
rng.reseed (time(0));
|
||||
|
||||
|
||||
// Global archive
|
||||
peoMoeoArchive<FlowShop> globalArch;
|
||||
if (getNodeRank()==1)
|
||||
std::cout << "Archive before :\n" << globalArch << std::endl;
|
||||
|
||||
/***************************************************/
|
||||
/***************** First algorithm *****************/
|
||||
/***************************************************/
|
||||
|
||||
// Topology
|
||||
RingTopology topology;
|
||||
|
||||
// Algorithm
|
||||
eoParser parser(argc, argv);
|
||||
eoState state;
|
||||
peoMoeoPopEval<FlowShop>& eval = do_make_para_eval(parser, state);
|
||||
eoInit<FlowShop>& init = do_make_genotype(parser, state);
|
||||
eoGenOp<FlowShop>& op = do_make_op(parser, state);
|
||||
peoMoeoPop<FlowShop>& pop = do_make_pop(parser, state, init); // peoMoeoPop is defined in parallelStruct.h
|
||||
moeoArchive<FlowShop> arch;
|
||||
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
|
||||
eoCheckPoint < FlowShop> & checkpoint = state.storeFunctor(new eoCheckPoint < FlowShop > (term));
|
||||
|
||||
// Communication between EA and the global archive
|
||||
|
||||
// Selection mode in the EA
|
||||
moeoRandomSelect <FlowShop> mig_select_one;
|
||||
moeoSelector <FlowShop, peoMoeoPop<FlowShop> > mig_select (mig_select_one,MIG_SIZE,pop); // moeoSelector is defined in parallelStruct.h
|
||||
// Mode of replacement in the EA
|
||||
moeoReplace < peoMoeoArchive<FlowShop>, peoMoeoPop<FlowShop> > mig_replace (pop); // moeoReplace is defined in parallelStruct.h
|
||||
// Continuator for the island
|
||||
eoPeriodicContinue< FlowShop> mig_cont( MIG_FREQ );
|
||||
eoContinuator<FlowShop> cont(mig_cont, pop);
|
||||
// Communication : EA ---> global archive
|
||||
peoAsyncIslandMig< peoMoeoPop<FlowShop>, peoMoeoArchive<FlowShop> > mig(cont,mig_select, mig_replace, topology);
|
||||
checkpoint.add(mig);
|
||||
// Selection mode in the global archive
|
||||
moeoSelectorArchive < peoMoeoArchive<FlowShop> > mig_selectArchive (globalArch); // moeoSelectorArchive is defined in parallelStruct.h
|
||||
// Mode of replacement in the global archive
|
||||
moeoReplaceArchive < peoMoeoPop<FlowShop>, peoMoeoArchive<FlowShop> > mig_replaceArchive (globalArch); // moeoReplaceArchive is defined in parallelStruct.h
|
||||
// Continuator for the island
|
||||
eoPeriodicContinue< FlowShop> mig_contArchive( MIG_FREQ );
|
||||
eoContinuator<FlowShop> contArchive(mig_contArchive, pop);
|
||||
// Communication : global archive ---> EA
|
||||
peoAsyncIslandMig< peoMoeoArchive<FlowShop>, peoMoeoPop<FlowShop> > migArchive(contArchive, mig_selectArchive, mig_replaceArchive, topology);
|
||||
checkpoint.add(migArchive);
|
||||
|
||||
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
|
||||
peoWrapper parallelMOEO( algo, pop);
|
||||
eval.setOwner(parallelMOEO);
|
||||
// Migrations
|
||||
mig.setOwner(parallelMOEO);
|
||||
migArchive.setOwner(parallelMOEO);
|
||||
|
||||
/***************************************************/
|
||||
/***************************************************/
|
||||
/***************************************************/
|
||||
|
||||
// The same one
|
||||
|
||||
RingTopology topology2;
|
||||
eoParser parser2(argc, argv);
|
||||
eoState state2;
|
||||
peoMoeoPopEval<FlowShop>& eval2 = do_make_para_eval(parser2, state2);
|
||||
eoInit<FlowShop>& init2 = do_make_genotype(parser2, state2);
|
||||
eoGenOp<FlowShop>& op2 = do_make_op(parser2, state2);
|
||||
peoMoeoPop<FlowShop>& pop2 = do_make_pop(parser2, state2, init2);
|
||||
moeoArchive<FlowShop> arch2;
|
||||
eoContinue<FlowShop>& term2 = do_make_continue_moeo(parser2, state2, eval2);
|
||||
eoCheckPoint < FlowShop> & checkpoint2 = state2.storeFunctor(new eoCheckPoint < FlowShop > (term2));
|
||||
moeoRandomSelect <FlowShop> mig_select_one2;
|
||||
moeoSelector <FlowShop, peoMoeoPop<FlowShop> > mig_select2 (mig_select_one2,MIG_SIZE,pop2);
|
||||
moeoReplace < peoMoeoArchive<FlowShop>, peoMoeoPop<FlowShop> > mig_replace2 (pop2);
|
||||
eoPeriodicContinue< FlowShop> mig_cont2( MIG_FREQ );
|
||||
eoContinuator<FlowShop> cont2(mig_cont2, pop2);
|
||||
peoAsyncIslandMig< peoMoeoPop<FlowShop>, peoMoeoArchive<FlowShop> > mig2(cont2,mig_select2, mig_replace2, topology2);
|
||||
checkpoint2.add(mig2);
|
||||
moeoSelectorArchive < peoMoeoArchive<FlowShop> > mig_selectArchive2 (globalArch);
|
||||
moeoReplaceArchive < peoMoeoPop<FlowShop>, peoMoeoArchive<FlowShop> > mig_replaceArchive2 (globalArch);
|
||||
eoPeriodicContinue< FlowShop> mig_contArchive2( MIG_FREQ );
|
||||
eoContinuator<FlowShop> contArchive2(mig_contArchive2, pop2);
|
||||
peoAsyncIslandMig< peoMoeoArchive<FlowShop>, peoMoeoPop<FlowShop> > migArchive2(contArchive2, mig_selectArchive2, mig_replaceArchive2, topology2);
|
||||
checkpoint2.add(migArchive2);
|
||||
eoAlgo<FlowShop>& algo2 = do_make_ea_moeo(parser2, state2, eval2, checkpoint2, op2, arch2);
|
||||
peoWrapper parallelMOEO2( algo2, pop2);
|
||||
eval2.setOwner(parallelMOEO2);
|
||||
mig2.setOwner(parallelMOEO2);
|
||||
migArchive2.setOwner(parallelMOEO2);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
pop2.sort();
|
||||
std::cout << "Final population :\n" << pop2 << std::endl;
|
||||
globalArch.sort();
|
||||
std::cout << "Archive after :\n" << globalArch << std::endl;
|
||||
}
|
||||
}
|
||||
137
trunk/paradiseo-peo/tutorial/Lesson8/parallelStruct.h
Normal file
137
trunk/paradiseo-peo/tutorial/Lesson8/parallelStruct.h
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
template<class EOT>
|
||||
class peoMoeoPop: public eoPop<EOT>, public peoData
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void pack ()
|
||||
{
|
||||
::pack ((unsigned) this->size ());
|
||||
for (unsigned i = 0; i < this->size (); i ++)
|
||||
::pack ((*this)[i]);
|
||||
}
|
||||
|
||||
virtual void unpack ()
|
||||
{
|
||||
unsigned n;
|
||||
::unpack (n);
|
||||
this->resize (n);
|
||||
for (unsigned i = 0; i < n; i ++)
|
||||
::unpack ((*this)[i]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class MOEOT>
|
||||
class peoMoeoArchive: public moeoArchive < MOEOT >, public peoData
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void pack ()
|
||||
{
|
||||
::pack ((unsigned) this->size ());
|
||||
for (unsigned i = 0; i < this->size (); i ++)
|
||||
::pack ((*this)[i]);
|
||||
}
|
||||
|
||||
|
||||
virtual void unpack ()
|
||||
{
|
||||
unsigned n;
|
||||
::unpack (n);
|
||||
this->resize (n);
|
||||
for (unsigned i = 0; i < n; i ++)
|
||||
::unpack ((*this)[i]);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template < class EOT, class TYPE> class moeoSelector : public selector< TYPE >
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
moeoSelector(moeoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source)
|
||||
{}
|
||||
|
||||
// Example
|
||||
virtual void operator()(TYPE & _dest)
|
||||
{
|
||||
size_t target = static_cast<size_t>(nb_select);
|
||||
_dest.resize(target);
|
||||
for (size_t i = 0; i < _dest.size(); ++i)
|
||||
_dest[i] = selector(source);
|
||||
}
|
||||
|
||||
protected:
|
||||
moeoSelectOne<EOT> & selector ;
|
||||
unsigned nb_select;
|
||||
const TYPE & source;
|
||||
};
|
||||
|
||||
|
||||
template < class TYPESOUR, class TYPEDEST> class moeoReplaceArchive : public replacement< TYPESOUR >
|
||||
{
|
||||
public:
|
||||
|
||||
moeoReplaceArchive(TYPEDEST & _destination): destination(_destination)
|
||||
{}
|
||||
|
||||
// Example
|
||||
virtual void operator()(TYPESOUR & _source)
|
||||
{
|
||||
destination.update (_source);
|
||||
}
|
||||
|
||||
protected:
|
||||
TYPEDEST & destination;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template < class TYPESOUR, class TYPEDEST> class moeoReplace : public replacement< TYPESOUR >
|
||||
{
|
||||
public:
|
||||
|
||||
moeoReplace(TYPEDEST & _destination): destination(_destination)
|
||||
{}
|
||||
|
||||
// Example
|
||||
virtual void operator()(TYPESOUR & _source)
|
||||
{
|
||||
for(unsigned i=0;i<_source.size();i++)
|
||||
{
|
||||
unsigned ind=0;
|
||||
double worst=destination[0].fitness();
|
||||
for (unsigned j=1;j<destination.size();j++)
|
||||
if ( destination[j].fitness()< worst)
|
||||
{
|
||||
ind=j;
|
||||
worst=destination[j].fitness();
|
||||
}
|
||||
destination[ind]=_source[i];
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
TYPEDEST & destination;
|
||||
};
|
||||
|
||||
|
||||
template <class TYPE> class moeoSelectorArchive : public selector< TYPE >
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
moeoSelectorArchive(const TYPE & _source): source(_source)
|
||||
{}
|
||||
|
||||
// Example
|
||||
virtual void operator()(TYPE & _dest)
|
||||
{
|
||||
_dest.update (source);
|
||||
}
|
||||
|
||||
protected:
|
||||
const TYPE & source;
|
||||
};
|
||||
63
trunk/paradiseo-peo/tutorial/Lesson8/param
Normal file
63
trunk/paradiseo-peo/tutorial/Lesson8/param
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
###### General ######
|
||||
--help=0 # -h : Prints this message
|
||||
#--stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
# --seed=1183379758 # -S : Random number seed
|
||||
|
||||
###### Evolution Engine ######
|
||||
--popSize=20 # -P : Population Size
|
||||
--updateArch=1 # Update the archive at each gen.
|
||||
--fitness=FastNonDominatedSorting # -F : Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased
|
||||
--indicator=Epsilon # -i : Binary indicator for IndicatorBased: Epsilon, Hypervolume
|
||||
--rho=1.1 # -r : reference point for the hypervolume indicator
|
||||
--kappa=0.05 # -k : Scaling factor kappa for IndicatorBased
|
||||
--diversity=Crowding # -D : Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding
|
||||
--comparator=FitnessThenDiversity # -C : Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative
|
||||
--selection=DetTour(2) # -S : Selection scheme: DetTour(T), StochTour(t) or Random
|
||||
--replacement=Elitist # -R : Replacement scheme: Elitist, Environmental or Generational
|
||||
--nbOffspring=100% # -O : Number of offspring (percentage or absolute)
|
||||
|
||||
###### Output ######
|
||||
#--resDir=Res # Directory to store DISK outputs
|
||||
#--eraseDir=1 # erase files in dirName if any
|
||||
--printPop=0 # Print sorted pop. every gen.
|
||||
--storeArch=0 # Store the archive's objective vectors at each gen.
|
||||
--contribution=0 # Store the contribution of the archive at each gen.
|
||||
--entropy=0 # Store the entropy of the archive at each gen.
|
||||
|
||||
###### Persistence ######
|
||||
--Load= # -L : A save file to restart from
|
||||
--recomputeFitness=0 # -r : Recompute the fitness after re-loading the pop.?
|
||||
--saveFrequency=0 # Save every F generation (0 = only final state, absent = never)
|
||||
--saveTimeInterval=0 # Save every T seconds (0 or absent = never)
|
||||
#--status=./FlowShopEA.status # Status file
|
||||
|
||||
###### Representation ######
|
||||
--BenchmarkFile=../../../../paradiseo-moeo/tutorial/examples/flowshop/benchs/020_10_01.txt # -B : Benchmark file name REQUIRED
|
||||
|
||||
###### Stopping criterion ######
|
||||
--maxGen=100 # -G : Maximum number of generations (0 = none)
|
||||
--maxEval=0 # -E : Maximum number of evaluations (0 = none)
|
||||
--maxTime=0 # -T : Maximum running time in seconds (0 = none)
|
||||
#--CtrlC=1 # -C : Terminate current generation upon Ctrl C (only available on Unix platforms)
|
||||
|
||||
###### Variation Operators ######
|
||||
--crossRate=1 # Relative rate for the only crossover
|
||||
--shiftMutRate=0.5 # Relative rate for shift mutation
|
||||
--exchangeMutRate=0.5 # Relative rate for exchange mutation
|
||||
--pCross=0.25 # -c : Probability of Crossover
|
||||
--pMut=0.35 # -m : Probability of Mutation
|
||||
|
||||
|
||||
|
||||
## miscallenous parameters
|
||||
|
||||
--debug=false
|
||||
|
||||
## deployment schema
|
||||
|
||||
--schema=schema.xml
|
||||
|
||||
## parameters
|
||||
|
||||
--inst=../examples/tsp/benchs/eil101.tsp
|
||||
|
||||
16
trunk/paradiseo-peo/tutorial/Lesson8/schema.xml
Normal file
16
trunk/paradiseo-peo/tutorial/Lesson8/schema.xml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?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>
|
||||
</node>
|
||||
<node name="2" num_workers="1">
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
</node>
|
||||
</group>
|
||||
</schema>
|
||||
Loading…
Add table
Add a link
Reference in a new issue