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:
canape 2008-02-04 15:34:40 +00:00
commit e7b97ea34f
10 changed files with 728 additions and 0 deletions

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

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

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

View 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

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