move paradiseo/eo to deprecated/ before merge with eodev
This commit is contained in:
parent
948da627ea
commit
0c5120f675
717 changed files with 0 additions and 0 deletions
16
deprecated/eo/tutorial/CMakeLists.txt
Normal file
16
deprecated/eo/tutorial/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
######################################################################################
|
||||
### 1) Where must cmake go now ?
|
||||
######################################################################################
|
||||
|
||||
IF(ENABLE_EO_TUTORIAL)
|
||||
|
||||
ADD_SUBDIRECTORY(Lesson1)
|
||||
ADD_SUBDIRECTORY(Lesson2)
|
||||
ADD_SUBDIRECTORY(Lesson3)
|
||||
ADD_SUBDIRECTORY(Lesson4)
|
||||
ADD_SUBDIRECTORY(Lesson5)
|
||||
ADD_SUBDIRECTORY(Lesson6)
|
||||
|
||||
ENDIF()
|
||||
|
||||
######################################################################################
|
||||
64
deprecated/eo/tutorial/Lesson1/CMakeLists.txt
Normal file
64
deprecated/eo/tutorial/Lesson1/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/ga)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/utils)
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets
|
||||
######################################################################################
|
||||
|
||||
# no matter what is the OS, hopefully
|
||||
ADD_EXECUTABLE(FirstBitGA FirstBitGA.cpp)
|
||||
ADD_EXECUTABLE(FirstRealGA FirstRealGA.cpp)
|
||||
ADD_EXECUTABLE(exercise1.3 exercise1.3.cpp)
|
||||
|
||||
ADD_DEPENDENCIES(FirstBitGA ga eo eoutils)
|
||||
ADD_DEPENDENCIES(FirstRealGA ga eo eoutils)
|
||||
ADD_DEPENDENCIES(exercise1.3 ga eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal
|
||||
######################################################################################
|
||||
|
||||
SET(FIRSTBITGA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(FirstBitGA PROPERTIES VERSION "${FIRSTBITGA_VERSION}")
|
||||
|
||||
SET(FIRSTREALGA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(FirstRealGA PROPERTIES VERSION "${FIRSTREALGA_VERSION}")
|
||||
|
||||
SET(EXERCICE13_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(exercise1.3 PROPERTIES VERSION "${EXERCICE13_VERSION}")
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies for the targets
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(FirstBitGA ga eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(FirstRealGA ga eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(exercise1.3 ga eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
### 6) Configure project installation paths
|
||||
######################################################################################
|
||||
|
||||
INSTALL(TARGETS FirstBitGA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson1 COMPONENT examples)
|
||||
INSTALL(TARGETS FirstRealGA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson1 COMPONENT examples)
|
||||
INSTALL(TARGETS exercise1.3 RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson1 COMPONENT examples)
|
||||
|
||||
######################################################################################
|
||||
167
deprecated/eo/tutorial/Lesson1/FirstBitGA.cpp
Normal file
167
deprecated/eo/tutorial/Lesson1/FirstBitGA.cpp
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// FirstBitGA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// An instance of a VERY simple Bitstring Genetic Algorithm
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
// EVAL
|
||||
//-----------------------------------------------------------------------------
|
||||
// a simple fitness function that computes the number of ones of a bitstring
|
||||
// @param _indi A biststring individual
|
||||
|
||||
double binary_value(const Indi & _indi)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _indi.size(); i++)
|
||||
sum += _indi[i];
|
||||
return sum;
|
||||
}
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
// all parameters are hard-coded!
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
const unsigned int VEC_SIZE = 16; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 100; // Size of population
|
||||
const unsigned int MAX_GEN = 400; // Maximum number of generation before STOP
|
||||
const float CROSS_RATE = 0.8; // Crossover rate
|
||||
const double P_MUT_PER_BIT = 0.01; // probability of bit-flip mutation
|
||||
const float MUT_RATE = 1.0; // mutation rate
|
||||
|
||||
// GENERAL
|
||||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
// EVAL
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
eoEvalFuncPtr<Indi> eval( binary_value );
|
||||
|
||||
// INIT
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
|
||||
// declare the population
|
||||
eoPop<Indi> pop;
|
||||
// fill it!
|
||||
for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)
|
||||
{
|
||||
Indi v; // void individual, to be filled
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
|
||||
{
|
||||
bool r = rng.flip(); // new value, random in {0,1}
|
||||
v.push_back(r); // append that random value to v
|
||||
}
|
||||
eval(v); // evaluate it
|
||||
pop.push_back(v); // and put it in the population
|
||||
}
|
||||
|
||||
// OUTPUT
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl;
|
||||
cout << pop;
|
||||
// shuffle - this is a test
|
||||
pop.shuffle();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Shuffled Population" << endl;
|
||||
cout << pop;
|
||||
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
|
||||
// REPLACE
|
||||
// The simple GA evolution engine uses generational replacement
|
||||
// so no replacement procedure is needed
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eo1PtBitXover<Indi> xover;
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBitMutation<Indi> mutation(P_MUT_PER_BIT);
|
||||
|
||||
// STOP
|
||||
// CHECKPOINT
|
||||
//////////////////////////////////////
|
||||
// termination condition
|
||||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> continuator(MAX_GEN);
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
// standard Generational GA requires as parameters
|
||||
// selection, evaluation, crossover and mutation, stopping criterion
|
||||
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
eval, continuator);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
// GENERAL
|
||||
}
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
162
deprecated/eo/tutorial/Lesson1/FirstRealGA.cpp
Normal file
162
deprecated/eo/tutorial/Lesson1/FirstRealGA.cpp
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// FirstRealGA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// An instance of a VERY simple Real-coded Genetic Algorithm
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoReal<double> Indi;
|
||||
|
||||
// EVAL
|
||||
//-----------------------------------------------------------------------------
|
||||
// a simple fitness function that computes the euclidian norm of a real vector
|
||||
// @param _indi A real-valued individual
|
||||
|
||||
double real_value(const Indi & _indi)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _indi.size(); i++)
|
||||
sum += _indi[i]*_indi[i];
|
||||
return (-sum); // maximizing only
|
||||
}
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
// all parameters are hard-coded!
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int VEC_SIZE = 8; // Number of object variables in genotypes
|
||||
const unsigned int POP_SIZE = 20; // Size of population
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP
|
||||
const float CROSS_RATE = 0.8; // Crossover rate
|
||||
const double EPSILON = 0.01; // range for real uniform mutation
|
||||
const float MUT_RATE = 0.5; // mutation rate
|
||||
|
||||
// GENERAL
|
||||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
// EVAL
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
eoEvalFuncPtr<Indi> eval( real_value );
|
||||
|
||||
// INIT
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
|
||||
// declare the population
|
||||
eoPop<Indi> pop;
|
||||
// fill it!
|
||||
for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)
|
||||
{
|
||||
Indi v; // void individual, to be filled
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
|
||||
{
|
||||
double r = 2*rng.uniform() - 1; // new value, random in [-1,1)
|
||||
v.push_back(r); // append that random value to v
|
||||
}
|
||||
eval(v); // evaluate it
|
||||
pop.push_back(v); // and put it in the population
|
||||
}
|
||||
|
||||
// OUTPUT
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl;
|
||||
cout << pop;
|
||||
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
|
||||
// REPLACE
|
||||
// eoSGA uses generational replacement by default
|
||||
// so no replacement procedure has to be given
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// offspring(i) is a linear combination of parent(i)
|
||||
eoSegmentCrossover<Indi> xover;
|
||||
// MUTATION
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
|
||||
// STOP
|
||||
// CHECKPOINT
|
||||
//////////////////////////////////////
|
||||
// termination condition
|
||||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> continuator(MAX_GEN);
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
// standard Generational GA requires
|
||||
// selection, evaluation, crossover and mutation, stopping criterion
|
||||
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
eval, continuator);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
// GENERAL
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
25
deprecated/eo/tutorial/Lesson1/Makefile.simple
Normal file
25
deprecated/eo/tutorial/Lesson1/Makefile.simple
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# if you use this Makefile as a starting point for another application
|
||||
# you might need to modify the following
|
||||
DIR_EO = ../../src
|
||||
|
||||
.SUFFIXES: .cpp
|
||||
|
||||
# Warning: $(CXX) in Linux (RedHat and Mandrake at least) is g++
|
||||
# However, if you are using this Makefile within xemacs,
|
||||
# and have problems with the interpretation of the output (and its colors)
|
||||
# then you should use c++ instead (make CXX=c++ will do)
|
||||
|
||||
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -pg -o $@ $*.cpp $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
.cpp.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c -pg $*.cpp
|
||||
|
||||
firstGA = FirstRealGA FirstBitGA
|
||||
|
||||
ALL = $(firstGA) exercise1.3
|
||||
|
||||
lesson1 : $(firstGA)
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
clean :
|
||||
@/bin/rm $(ALL) *.o *~
|
||||
162
deprecated/eo/tutorial/Lesson1/exercise1.3.cpp
Normal file
162
deprecated/eo/tutorial/Lesson1/exercise1.3.cpp
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// FirstBitGA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// An instance of a VERY simple Bitstring Genetic Algorithm
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// standard includes
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your individuals
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** a simple fitness function that computes the number of ones of a bitstring
|
||||
@param _indi A biststring individual
|
||||
*/
|
||||
|
||||
double binary_value(const Indi & _indi)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _indi.size(); i++)
|
||||
sum += _indi[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int VEC_SIZE = 8; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 20; // Size of population
|
||||
const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP
|
||||
const float CROSS_RATE = 0.8; // Crossover rate
|
||||
const double P_MUT_PER_BIT = 0.01; // probability of bit-flip mutation
|
||||
const float MUT_RATE = 1.0; // mutation rate
|
||||
|
||||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
eoEvalFuncPtr<Indi> eval( binary_value );
|
||||
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
|
||||
// declare the population
|
||||
eoPop<Indi> pop;
|
||||
// fill it!
|
||||
for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)
|
||||
{
|
||||
Indi v; // void individual, to be filled
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
|
||||
{
|
||||
bool r = rng.flip(); // new value, random in {0,1}
|
||||
v.push_back(r); // append that random value to v
|
||||
}
|
||||
eval(v); // evaluate it
|
||||
pop.push_back(v); // and put it in the population
|
||||
}
|
||||
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl;
|
||||
cout << pop;
|
||||
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
|
||||
// solution solution solution: uncomment one of the following,
|
||||
// comment out the eoDetTournament lines
|
||||
|
||||
// The well-known roulette
|
||||
// eoProportionalSelect<Indi> select;
|
||||
|
||||
// could also use stochastic binary tournament selection
|
||||
//
|
||||
// const double RATE = 0.75;
|
||||
// eoStochTournamentSelect<Indi> select(RATE); // RATE in ]0.5,1]
|
||||
// The robust tournament selection
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
eoDetTournamentSelect<Indi> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
|
||||
// and of course the random selection
|
||||
// eoRandomSelect<Indi> select;
|
||||
|
||||
// The simple GA evolution engine uses generational replacement
|
||||
// so no replacement procedure is needed
|
||||
|
||||
//////////////////////////////////////
|
||||
// termination condition
|
||||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> continuator(MAX_GEN);
|
||||
|
||||
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBitMutation<Indi> mutation(P_MUT_PER_BIT);
|
||||
// 1-point mutation for bitstring
|
||||
eo1PtBitXover<Indi> xover;
|
||||
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
// standard Generational GA requires as parameters
|
||||
// selection, evaluation, crossover and mutation, stopping criterion
|
||||
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
eval, continuator);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
60
deprecated/eo/tutorial/Lesson2/CMakeLists.txt
Normal file
60
deprecated/eo/tutorial/Lesson2/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/ga)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/utils)
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets
|
||||
######################################################################################
|
||||
|
||||
# no matter what is the OS, hopefully
|
||||
ADD_EXECUTABLE(FirstBitEA FirstBitEA.cpp)
|
||||
ADD_EXECUTABLE(FirstRealEA FirstRealEA.cpp)
|
||||
ADD_EXECUTABLE(exercise2.3 exercise2.3.cpp)
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal
|
||||
######################################################################################
|
||||
|
||||
SET(FIRSTBITEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(FirstBitEA PROPERTIES VERSION "${FIRSTBITEA_VERSION}")
|
||||
|
||||
SET(FIRSTREALEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(FirstRealEA PROPERTIES VERSION "${FIRSTREALEA_VERSION}")
|
||||
|
||||
SET(EXERCICE23_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(exercise2.3 PROPERTIES VERSION "${EXERCICE23_VERSION}")
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies for the targets
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(FirstBitEA ga eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(FirstRealEA ga eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(exercise2.3 ga eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
### 6) Configure project installation paths
|
||||
######################################################################################
|
||||
|
||||
INSTALL(TARGETS FirstBitEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson2 COMPONENT examples)
|
||||
INSTALL(TARGETS FirstRealEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson2 COMPONENT examples)
|
||||
INSTALL(TARGETS exercise2.3 RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson2 COMPONENT examples)
|
||||
|
||||
######################################################################################
|
||||
193
deprecated/eo/tutorial/Lesson2/FirstBitEA.cpp
Normal file
193
deprecated/eo/tutorial/Lesson2/FirstBitEA.cpp
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// FirstBitEA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
// EVALFUNC
|
||||
//-----------------------------------------------------------------------------
|
||||
// a simple fitness function that computes the number of ones of a bitstring
|
||||
// Now in a separate file, and declared as binary_value(const vector<bool> &)
|
||||
|
||||
#include "binary_value.h"
|
||||
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
const unsigned int VEC_SIZE = 8; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 20; // Size of population
|
||||
|
||||
const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP
|
||||
const unsigned int MIN_GEN = 10; // Minimum number of generation before ...
|
||||
const unsigned int STEADY_GEN = 50; // stop after STEADY_GEN gen. without improvelent
|
||||
|
||||
const double P_CROSS = 0.8; // Crossover probability
|
||||
const double P_MUT = 1.0; // mutation probability
|
||||
|
||||
const double P_MUT_PER_BIT = 0.01; // internal probability for bit-flip mutation
|
||||
// some parameters for chosing among different operators
|
||||
const double onePointRate = 0.5; // rate for 1-pt Xover
|
||||
const double twoPointsRate = 0.5; // rate for 2-pt Xover
|
||||
const double URate = 0.5; // rate for Uniform Xover
|
||||
const double bitFlipRate = 0.5; // rate for bit-flip mutation
|
||||
const double oneBitRate = 0.5; // rate for one-bit mutation
|
||||
|
||||
// GENERAL
|
||||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
// EVAL
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
// you need to give the full description of the function
|
||||
eoEvalFuncPtr<Indi, double, const vector<bool>& > eval( binary_value );
|
||||
|
||||
// INIT
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
|
||||
// based on boolean_generator class (see utils/eoRndGenerators.h)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(VEC_SIZE, uGen);
|
||||
// Initialization of the population
|
||||
eoPop<Indi> pop(POP_SIZE, random);
|
||||
|
||||
// and evaluate it in one loop
|
||||
apply<Indi>(eval, pop); // STL syntax
|
||||
|
||||
// OUTPUT
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl;
|
||||
cout << pop;
|
||||
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> selectOne(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
// is now encapsulated in a eoSelectPerc (entage)
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eo1PtBitXover<Indi> xover1;
|
||||
// uniform crossover for bitstring
|
||||
eoUBitXover<Indi> xoverU;
|
||||
// 2-pots xover
|
||||
eoNPtsBitXover<Indi> xover2(2);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
xover.add(xover2, twoPointsRate, true);
|
||||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);
|
||||
mutation.add(mutationOneBit, oneBitRate, true);
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Indi> transform(xover, P_CROSS, mutation, P_MUT);
|
||||
|
||||
// STOP
|
||||
// CHECKPOINT
|
||||
//////////////////////////////////////
|
||||
// termination conditions: use more than one
|
||||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> genCont(MAX_GEN);
|
||||
// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement
|
||||
eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, STEADY_GEN);
|
||||
// stop when fitness reaches a target (here VEC_SIZE)
|
||||
eoFitContinue<Indi> fitCont(VEC_SIZE);
|
||||
// do stop when one of the above says so
|
||||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// selection, transformation, eval, replacement, and stopping criterion
|
||||
eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
cout << "\n Here we go\n\n";
|
||||
gga(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
// GENERAL
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
192
deprecated/eo/tutorial/Lesson2/FirstRealEA.cpp
Normal file
192
deprecated/eo/tutorial/Lesson2/FirstRealEA.cpp
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// FirstRealEA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Still an instance of a VERY simple Real-coded Genetic Algorithm
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoReal<double> Indi;
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
// EVALFUNC
|
||||
//-----------------------------------------------------------------------------
|
||||
// a simple fitness function that computes the euclidian norm of a real vector
|
||||
// Now in a separate file, and declared as binary_value(const vector<bool> &)
|
||||
|
||||
#include "real_value.h"
|
||||
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
const unsigned int VEC_SIZE = 8; // Number of object variables in genotypes
|
||||
const unsigned int POP_SIZE = 20; // Size of population
|
||||
|
||||
const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP
|
||||
const unsigned int MIN_GEN = 10; // Minimum number of generation before ...
|
||||
const unsigned int STEADY_GEN = 50; // stop after STEADY_GEN gen. without improvelent
|
||||
|
||||
const float P_CROSS = 0.8; // Crossover probability
|
||||
const float P_MUT = 0.5; // mutation probability
|
||||
|
||||
const double EPSILON = 0.01; // range for real uniform mutation
|
||||
double SIGMA = 0.3; // std dev. for normal mutation
|
||||
// some parameters for chosing among different operators
|
||||
const double hypercubeRate = 0.5; // relative weight for hypercube Xover
|
||||
const double segmentRate = 0.5; // relative weight for segment Xover
|
||||
const double uniformMutRate = 0.5; // relative weight for uniform mutation
|
||||
const double detMutRate = 0.5; // relative weight for det-uniform mutation
|
||||
const double normalMutRate = 0.5; // relative weight for normal mutation
|
||||
|
||||
// GENERAL
|
||||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
// EVAL
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
// you need to give the full description of the function
|
||||
eoEvalFuncPtr<Indi, double, const vector<double>& > eval( real_value );
|
||||
|
||||
// INIT
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
// based on a uniform generator
|
||||
eoUniformGenerator<double> uGen(-1.0, 1.0);
|
||||
eoInitFixedLength<Indi> random(VEC_SIZE, uGen);
|
||||
// Initialization of the population
|
||||
eoPop<Indi> pop(POP_SIZE, random);
|
||||
|
||||
// and evaluate it in one loop
|
||||
apply<Indi>(eval, pop); // STL syntax
|
||||
|
||||
// OUTPUT
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl;
|
||||
cout << pop;
|
||||
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> selectOne(T_SIZE);
|
||||
// is now encapsulated in a eoSelectPerc (entage)
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// uniform chooce on segment made by the parents
|
||||
eoSegmentCrossover<Indi> xoverS;
|
||||
// uniform choice in hypercube built by the parents
|
||||
eoHypercubeCrossover<Indi> xoverA;
|
||||
// Combine them with relative weights
|
||||
eoPropCombinedQuadOp<Indi> xover(xoverS, segmentRate);
|
||||
xover.add(xoverA, hypercubeRate, true);
|
||||
|
||||
// MUTATION
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
eoUniformMutation<Indi> mutationU(EPSILON);
|
||||
// k (=1) coordinates of parents are uniformly modified
|
||||
eoDetUniformMutation<Indi> mutationD(EPSILON);
|
||||
// all coordinates of parents are normally modified (stDev SIGMA)
|
||||
eoNormalMutation<Indi> mutationN(SIGMA);
|
||||
// Combine them with relative weights
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationU, uniformMutRate);
|
||||
mutation.add(mutationD, detMutRate);
|
||||
mutation.add(mutationN, normalMutRate, true);
|
||||
|
||||
// STOP
|
||||
// CHECKPOINT
|
||||
//////////////////////////////////////
|
||||
// termination conditions: use more than one
|
||||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> genCont(MAX_GEN);
|
||||
// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement
|
||||
eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, STEADY_GEN);
|
||||
// stop when fitness reaches a target (here VEC_SIZE)
|
||||
eoFitContinue<Indi> fitCont(0);
|
||||
// do stop when one of the above says so
|
||||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Indi> transform(xover, P_CROSS, mutation, P_MUT);
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// selection, transformation, eval, replacement, and stopping criterion
|
||||
eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
cout << "\n Here we go\n\n";
|
||||
gga(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
// GENERAL
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
34
deprecated/eo/tutorial/Lesson2/Makefile.simple
Normal file
34
deprecated/eo/tutorial/Lesson2/Makefile.simple
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
### This Makefile is part of the tutorial of the EO library
|
||||
# Unlike other Makefiles in EO, it is not using the automake/autoconf
|
||||
# so that it stays easy to understant (you are in the tutorial, remember!)
|
||||
# MS, Oct. 2002
|
||||
|
||||
# if you use this Makefile as a starting point for another application
|
||||
# you might need to modify the following
|
||||
DIR_EO = ../../src
|
||||
|
||||
.SUFFIXES: .cpp
|
||||
|
||||
# Warning: $(CXX) in Linux (RedHat and Mandrake at least) is g++
|
||||
# However, if you are using this Makefile within xemacs,
|
||||
# and have problems with the interpretation of the output (and its colors)
|
||||
# then you should use c++ instead (make CXX=c++ will do)
|
||||
|
||||
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -pg -o $@ $*.cpp $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
.cpp.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c -pg $*.cpp
|
||||
|
||||
firstEA = FirstRealEA FirstBitEA
|
||||
|
||||
ALL = $(firstEA) exercise2.3
|
||||
|
||||
lesson2 : $(firstEA)
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
clean :
|
||||
@/bin/rm $(ALL) *.o *~
|
||||
|
||||
FirstRealEA : real_value.h
|
||||
|
||||
FirstBitEA : binary_value.h
|
||||
16
deprecated/eo/tutorial/Lesson2/binary_value.h
Normal file
16
deprecated/eo/tutorial/Lesson2/binary_value.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <eo>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Just a simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
// INIT
|
||||
double binary_value(const std::vector<bool>& _chrom)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _chrom.size(); i++)
|
||||
sum += _chrom[i];
|
||||
return sum;
|
||||
}
|
||||
197
deprecated/eo/tutorial/Lesson2/exercise2.3.cpp
Normal file
197
deprecated/eo/tutorial/Lesson2/exercise2.3.cpp
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// FirstBitEA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your individuals
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
// EVAL
|
||||
//-----------------------------------------------------------------------------
|
||||
// a simple fitness function that computes the number of ones of a bitstring
|
||||
// Now in a separate file, and declared as binary_value(const vector<bool> &)
|
||||
|
||||
#include "binary_value.h"
|
||||
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
using namespace std;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
const unsigned int VEC_SIZE = 20; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 20; // Size of population
|
||||
|
||||
const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP
|
||||
const unsigned int MIN_GEN = 10; // Minimum number of generation before ...
|
||||
const unsigned int STEADY_GEN = 50; // stop after STEADY_GEN gen. without improvelent
|
||||
|
||||
const double P_CROSS = 0.8; // Crossover probability
|
||||
const double P_MUT = 1.0; // mutation probability
|
||||
|
||||
const double P_MUT_PER_BIT = 0.01; // internal probability for bit-flip mutation
|
||||
// some parameters for chosing among different operators
|
||||
const double onePointRate = 0.5; // rate for 1-pt Xover
|
||||
const double twoPointsRate = 0.5; // rate for 2-pt Xover
|
||||
const double URate = 0.5; // rate for Uniform Xover
|
||||
const double bitFlipRate = 0.5; // rate for bit-flip mutation
|
||||
const double oneBitRate = 0.5; // rate for one-bit mutation
|
||||
|
||||
// GENERAL
|
||||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
// EVAL
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
// you need to give the full description of the function
|
||||
eoEvalFuncPtr<Indi, double, const vector<bool>& > eval( binary_value );
|
||||
|
||||
// INIT
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
|
||||
// based on boolean_generator class (see utils/rnd_generator.h)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(VEC_SIZE, uGen);
|
||||
// Initialization of the population
|
||||
eoPop<Indi> pop(POP_SIZE, random);
|
||||
|
||||
// and evaluate it in one loop
|
||||
apply<Indi>(eval, pop); // STL syntax
|
||||
|
||||
// OUTPUT
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl;
|
||||
cout << pop;
|
||||
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> selectOne(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
// solution solution solution solution solution solution solution
|
||||
// modify the nb offspring / rate in the constructor. 2 ways:
|
||||
// second arg treated as integer
|
||||
eoSelectMany<Indi> select(selectOne,2, eo_is_an_integer);
|
||||
// second arg treated as a rate (default behavior)
|
||||
// eoSelectMany<Indi> select(selectOne,0.1);
|
||||
|
||||
// REPLACE
|
||||
// solution solution solution solution solution solution solution
|
||||
// eoCommaReplacement keeps the best among offspring
|
||||
// eoPlusReplacement keeps the best among parents + offspring
|
||||
// eoCommaReplacement<Indi> replace;
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eo1PtBitXover<Indi> xover1;
|
||||
// uniform crossover for bitstring
|
||||
eoUBitXover<Indi> xoverU;
|
||||
// 2-pots xover
|
||||
eoNPtsBitXover<Indi> xover2(2);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
xover.add(xover2, twoPointsRate, true);
|
||||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);
|
||||
mutation.add(mutationOneBit, oneBitRate, true);
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Indi> transform(xover, P_CROSS, mutation, P_MUT);
|
||||
|
||||
// STOP
|
||||
// CHECKPOINT
|
||||
//////////////////////////////////////
|
||||
// termination conditions: use more than one
|
||||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> genCont(MAX_GEN);
|
||||
// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement
|
||||
eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, STEADY_GEN);
|
||||
// stop when fitness reaches a target (here VEC_SIZE)
|
||||
eoFitContinue<Indi> fitCont(VEC_SIZE);
|
||||
// do stop when one of the above says so
|
||||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// selection, transformation, eval, replacement, and stopping criterion
|
||||
eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
// GENERAL
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
17
deprecated/eo/tutorial/Lesson2/real_value.h
Normal file
17
deprecated/eo/tutorial/Lesson2/real_value.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <vector>
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Just a simple function that takes an vector<double> and sets the fitnes
|
||||
to the sphere function. Please use doubles not float!!!
|
||||
@param _ind A floatingpoint vector
|
||||
*/
|
||||
|
||||
// INIT
|
||||
double real_value(const std::vector<double>& _ind)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _ind.size(); i++)
|
||||
{
|
||||
sum += _ind[i] * _ind[i];
|
||||
}
|
||||
return -sum;
|
||||
}
|
||||
64
deprecated/eo/tutorial/Lesson3/CMakeLists.txt
Normal file
64
deprecated/eo/tutorial/Lesson3/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/ga)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/utils)
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets
|
||||
######################################################################################
|
||||
|
||||
# no matter what is the OS, hopefully
|
||||
ADD_EXECUTABLE(SecondBitEA SecondBitEA.cpp)
|
||||
ADD_EXECUTABLE(SecondRealEA SecondRealEA.cpp)
|
||||
ADD_EXECUTABLE(exercise3.1 exercise3.1.cpp)
|
||||
|
||||
ADD_DEPENDENCIES(SecondBitEA ga eoutils eo)
|
||||
ADD_DEPENDENCIES(SecondRealEA ga eoutils eo)
|
||||
ADD_DEPENDENCIES(exercise3.1 ga eoutils eo)
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal
|
||||
######################################################################################
|
||||
|
||||
SET(SECONDBITEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(SecondBitEA PROPERTIES VERSION "${SECONDBITEA_VERSION}")
|
||||
|
||||
SET(SECONDREALEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(SecondRealEA PROPERTIES VERSION "${SECONDREALEA_VERSION}")
|
||||
|
||||
SET(EXERCICE31_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(exercise3.1 PROPERTIES VERSION "${EXERCICE31_VERSION}")
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies for the targets
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(SecondBitEA ga eoutils eo)
|
||||
TARGET_LINK_LIBRARIES(SecondRealEA ga eoutils eo)
|
||||
TARGET_LINK_LIBRARIES(exercise3.1 ga eoutils eo)
|
||||
|
||||
######################################################################################
|
||||
### 6) Configure project installation paths
|
||||
######################################################################################
|
||||
|
||||
INSTALL(TARGETS SecondBitEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson3 COMPONENT examples)
|
||||
INSTALL(TARGETS SecondRealEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson3 COMPONENT examples)
|
||||
INSTALL(TARGETS exercise3.1 RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson3 COMPONENT examples)
|
||||
|
||||
######################################################################################
|
||||
33
deprecated/eo/tutorial/Lesson3/Makefile.simple
Normal file
33
deprecated/eo/tutorial/Lesson3/Makefile.simple
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
### This Makefile is part of the tutorial of the EO library
|
||||
# Unlike other Makefiles in EO, it is not using the automake/autoconf
|
||||
# so that it stays easy to understant (you are in the tutorial, remember!)
|
||||
# MS, Oct. 2002
|
||||
|
||||
# if you use this Makefile as a starting point for another application
|
||||
# you might need to modify the following
|
||||
DIR_EO = ../../src
|
||||
|
||||
.SUFFIXES: .cpp
|
||||
|
||||
# Warning: $(CXX) in Linux (RedHat and Mandrake at least) is g++
|
||||
# However, if you are using this Makefile within xemacs,
|
||||
# and have problems with the interpretation of the output (and its colors)
|
||||
# then you should use c++ instead (make CXX=c++ will do)
|
||||
|
||||
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -pg -o $@ $*.cpp $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
.cpp.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c -pg $*.cpp
|
||||
|
||||
secondEA = SecondBitEA SecondRealEA
|
||||
|
||||
ALL = $(secondEA) exercise3.1
|
||||
|
||||
lesson3 : $(secondEA)
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
SecondBitEA : binary_value.h
|
||||
SecondRealEA : real_value.h
|
||||
|
||||
clean :
|
||||
@/bin/rm $(ALL) *.o *.sav *.xg *.status *~
|
||||
348
deprecated/eo/tutorial/Lesson3/SecondBitEA.cpp
Normal file
348
deprecated/eo/tutorial/Lesson3/SecondBitEA.cpp
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// SecondGA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Same code than FirstBitEA as far as Evolutionary Computation is concerned
|
||||
// but now you learn to enter the parameters in a more flexible way
|
||||
// and to twidle the output to your preferences!
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <fstream>
|
||||
#include <iostream> // cout
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
// EVAL
|
||||
#include "binary_value.h"
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your genotype and fitness types
|
||||
typedef eoBit<double> Indi;
|
||||
|
||||
// the main_function: nothing changed(!), except variable initialization
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
//-----------------------------------------------------------------------------
|
||||
// instead of having all values of useful parameters as constants, read them:
|
||||
// either on the command line (--option=value or -o=value)
|
||||
// or in a parameter file (same syntax, order independent,
|
||||
// # = usual comment character
|
||||
// or in the environment (TODO)
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size",'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// parameters for evolution engine
|
||||
eoValueParam<unsigned int> popSizeParam(10, "popSize", "Population size",'P');
|
||||
parser.processParam( popSizeParam, "Evolution engine" );
|
||||
unsigned popSize = popSizeParam.value();
|
||||
|
||||
eoValueParam<unsigned int> tSizeParam(10, "tSize", "Tournament size",'T');
|
||||
parser.processParam( tSizeParam, "Evolution Engine" );
|
||||
unsigned tSize = tSizeParam.value();
|
||||
|
||||
// init and stop
|
||||
eoValueParam<string> loadNameParam("", "Load","A save file to restart from",'L');
|
||||
parser.processParam( loadNameParam, "Persistence" );
|
||||
string loadName = loadNameParam.value();
|
||||
|
||||
eoValueParam<unsigned int> maxGenParam(100, "maxGen", "Maximum number of generations",'G');
|
||||
parser.processParam( maxGenParam, "Stopping criterion" );
|
||||
unsigned maxGen = maxGenParam.value();
|
||||
|
||||
eoValueParam<unsigned int> minGenParam(100, "minGen", "Minimum number of generations",'g');
|
||||
parser.processParam( minGenParam, "Stopping criterion" );
|
||||
unsigned minGen = minGenParam.value();
|
||||
|
||||
eoValueParam<unsigned int> steadyGenParam(100, "steadyGen", "Number of generations with no improvement",'s');
|
||||
parser.processParam( steadyGenParam, "Stopping criterion" );
|
||||
unsigned steadyGen = steadyGenParam.value();
|
||||
|
||||
// operators probabilities at the algorithm level
|
||||
eoValueParam<double> pCrossParam(0.6, "pCross", "Probability of Crossover", 'C');
|
||||
parser.processParam( pCrossParam, "Genetic Operators" );
|
||||
double pCross = pCrossParam.value();
|
||||
|
||||
eoValueParam<double> pMutParam(0.1, "pMut", "Probability of Mutation", 'M');
|
||||
parser.processParam( pMutParam, "Genetic Operators" );
|
||||
double pMut = pMutParam.value();
|
||||
|
||||
// relative rates for crossovers
|
||||
eoValueParam<double> onePointRateParam(1, "onePointRate", "Relative rate for one point crossover", '1');
|
||||
parser.processParam( onePointRateParam, "Genetic Operators" );
|
||||
double onePointRate = onePointRateParam.value();
|
||||
|
||||
eoValueParam<double> twoPointsRateParam(1, "twoPointRate", "Relative rate for two point crossover", '2');
|
||||
parser.processParam( twoPointsRateParam, "Genetic Operators" );
|
||||
double twoPointsRate = twoPointsRateParam.value();
|
||||
|
||||
eoValueParam<double> uRateParam(2, "uRate", "Relative rate for uniform crossover", 'U');
|
||||
parser.processParam( uRateParam, "Genetic Operators" );
|
||||
double URate = uRateParam.value();
|
||||
|
||||
// relative rates and private parameters for mutations;
|
||||
eoValueParam<double> pMutPerBitParam(0.01, "pMutPerBit", "Probability of flipping 1 bit in bit-flip mutation", 'b');
|
||||
parser.processParam( pMutPerBitParam, "Genetic Operators" );
|
||||
double pMutPerBit = pMutPerBitParam.value();
|
||||
|
||||
eoValueParam<double> bitFlipRateParam(0.01, "bitFlipRate", "Relative rate for bit-flip mutation", 'B');
|
||||
parser.processParam( bitFlipRateParam, "Genetic Operators" );
|
||||
double bitFlipRate = bitFlipRateParam.value();
|
||||
|
||||
eoValueParam<double> oneBitRateParam(0.01, "oneBitRate", "Relative rate for deterministic bit-flip mutation", 'D');
|
||||
parser.processParam( oneBitRateParam, "Genetic Operators" );
|
||||
double oneBitRate = oneBitRateParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status","Status file",'S');
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "")
|
||||
{
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser; // and you can use that file as parameter file
|
||||
}
|
||||
|
||||
// EVAL
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object ...
|
||||
eoEvalFuncPtr<Indi, double, const vector<bool>& > plainEval( binary_value );
|
||||
// ... to an object that counts the nb of actual evaluations
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// INIT
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
// Either load or initialize
|
||||
// create an empty pop
|
||||
eoPop<Indi> pop;
|
||||
// create a 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 conitnuation of the saved run
|
||||
// eventually with different parameters
|
||||
inState.registerObject(rng);
|
||||
inState.registerObject(pop);
|
||||
|
||||
if (loadName != "")
|
||||
{
|
||||
inState.load(loadName); // load the pop and the rng
|
||||
// the fitness is read in the file:
|
||||
// do only evaluate the pop if the fitness has changed
|
||||
}
|
||||
else
|
||||
{
|
||||
rng.reseed(seed);
|
||||
// a Indi random initializer
|
||||
// based on boolean_generator class (see utils/rnd_generator.h)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
// Init pop from the randomizer: need to use the append function
|
||||
pop.append(popSize, random);
|
||||
// and evaluate pop (STL syntax)
|
||||
apply<Indi>(eval, pop);
|
||||
} // end of initializatio of the population
|
||||
|
||||
// OUTPUT
|
||||
// sort pop for pretty printout
|
||||
pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl << pop << endl;
|
||||
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> selectOne(tSize); // tSize in [2,POPSIZE]
|
||||
// is now encapsulated in a eoSelectPerc (stands for Percentage)
|
||||
eoSelectPerc<Indi> select(selectOne);
|
||||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// the same generational replacement at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eo1PtBitXover<Indi> xover1;
|
||||
// uniform crossover for bitstring
|
||||
eoUBitXover<Indi> xoverU;
|
||||
// 2-pots xover
|
||||
eoNPtsBitXover<Indi> xover2(2);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
xover.add(xover2, twoPointsRate, true);
|
||||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBitMutation<Indi> mutationBitFlip(pMutPerBit);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);
|
||||
mutation.add(mutationOneBit, oneBitRate, true);
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Indi> transform(xover, pCross, mutation, pMut);
|
||||
|
||||
// STOP
|
||||
//////////////////////////////////////
|
||||
// termination condition see FirstBitEA.cpp
|
||||
/////////////////////////////////////
|
||||
eoGenContinue<Indi> genCont(maxGen);
|
||||
eoSteadyFitContinue<Indi> steadyCont(minGen, steadyGen);
|
||||
eoFitContinue<Indi> fitCont(vecSize);
|
||||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
|
||||
// CHECKPOINT
|
||||
// but now you want to make many different things every generation
|
||||
// (e.g. statistics, plots, ...).
|
||||
// the class eoCheckPoint is dedicated to just that:
|
||||
|
||||
// Declare a checkpoint (from a continuator: an eoCheckPoint
|
||||
// IS AN eoContinue and will be called in the loop of all algorithms)
|
||||
eoCheckPoint<Indi> checkpoint(continuator);
|
||||
|
||||
// Create a counter parameter
|
||||
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
||||
|
||||
// Create an incrementor (sub-class of eoUpdater). Note that the
|
||||
// parameter's value is passed by reference,
|
||||
// so every time the incrementer is updated (every generation),
|
||||
// the data in generationCounter will change.
|
||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||
|
||||
// Add it to the checkpoint,
|
||||
// so the counter is updated (here, incremented) every generation
|
||||
checkpoint.add(increment);
|
||||
|
||||
// now some statistics on the population:
|
||||
// Best fitness in population
|
||||
eoBestFitnessStat<Indi> bestStat;
|
||||
// Second moment stats: average and stdev
|
||||
eoSecondMomentStats<Indi> SecondStat;
|
||||
|
||||
// Add them to the checkpoint to get them called at the appropriate time
|
||||
checkpoint.add(bestStat);
|
||||
checkpoint.add(SecondStat);
|
||||
|
||||
// The Stdout monitor will print parameters to the screen ...
|
||||
eoStdoutMonitor monitor(false);
|
||||
|
||||
// when called by the checkpoint (i.e. at every generation)
|
||||
checkpoint.add(monitor);
|
||||
|
||||
// the monitor will output a series of parameters: add them
|
||||
monitor.add(generationCounter);
|
||||
monitor.add(eval); // because now eval is an eoEvalFuncCounter!
|
||||
monitor.add(bestStat);
|
||||
monitor.add(SecondStat);
|
||||
|
||||
// A file monitor: will print parameters to ... a File, yes, you got it!
|
||||
eoFileMonitor fileMonitor("stats.xg", " ");
|
||||
|
||||
// the checkpoint mechanism can handle multiple monitors
|
||||
checkpoint.add(fileMonitor);
|
||||
|
||||
// the fileMonitor can monitor parameters, too, but you must tell it!
|
||||
fileMonitor.add(generationCounter);
|
||||
fileMonitor.add(bestStat);
|
||||
fileMonitor.add(SecondStat);
|
||||
|
||||
// Last type of item the eoCheckpoint can handle: state savers:
|
||||
eoState outState;
|
||||
// Register the algorithm into the state (so it has something to save!!)
|
||||
outState.registerObject(parser);
|
||||
outState.registerObject(pop);
|
||||
outState.registerObject(rng);
|
||||
|
||||
// and feed the state to state savers
|
||||
// save state every 100th generation
|
||||
eoCountedStateSaver stateSaver1(20, outState, "generation");
|
||||
// save state every 1 seconds
|
||||
eoTimedStateSaver stateSaver2(1, outState, "time");
|
||||
|
||||
// Don't forget to add the two savers to the checkpoint
|
||||
checkpoint.add(stateSaver1);
|
||||
checkpoint.add(stateSaver2);
|
||||
// and that's it for the (control and) output
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// stopping criterion, eval, selection, transformation, replacement
|
||||
eoEasyEA<Indi> gga(checkpoint, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
// GENERAL
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
329
deprecated/eo/tutorial/Lesson3/SecondRealEA.cpp
Normal file
329
deprecated/eo/tutorial/Lesson3/SecondRealEA.cpp
Normal file
|
|
@ -0,0 +1,329 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// SecondRealEA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Same code than FirstBitEA as far as Evolutionary Computation is concerned
|
||||
// but now you learn to enter the parameters in a more flexible way
|
||||
// (also slightly different than in SecondBitEA.cpp)
|
||||
// and to twidle the output to your preferences (as in SecondBitEA.cpp)
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <fstream>
|
||||
#include <iostream> // cout
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoReal<eoMinimizingFitness> Indi;
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
// EVALFUNC
|
||||
//-----------------------------------------------------------------------------
|
||||
// a simple fitness function that computes the euclidian norm of a real vector
|
||||
// Now in a separate file, and declared as binary_value(const vector<bool> &)
|
||||
|
||||
#include "real_value.h"
|
||||
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
//-----------------------------------------------------------------------------
|
||||
// instead of having all values of useful parameters as constants, read them:
|
||||
// either on the command line (--option=value or -o=value)
|
||||
// or in a parameter file (same syntax, order independent,
|
||||
// # = usual comment character
|
||||
// or in the environment (TODO)
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, you can in on single line
|
||||
// define the parameter, read it through the parser, and assign it
|
||||
|
||||
unsigned seed = parser.createParam(unsigned(time(0)), "seed", "Random number seed", 'S').value(); // will be in default section General
|
||||
|
||||
// description of genotype
|
||||
unsigned vecSize = parser.createParam(unsigned(8), "vecSize", "Genotype size",'V', "Representation" ).value();
|
||||
|
||||
// parameters for evolution engine
|
||||
unsigned popSize = parser.createParam(unsigned(10), "popSize", "Population size",'P', "Evolution engine" ).value();
|
||||
|
||||
unsigned tSize = parser.createParam(unsigned(2), "tSize", "Tournament size",'T', "Evolution Engine" ).value();
|
||||
|
||||
// init and stop
|
||||
string loadName = parser.createParam(string(""), "Load","A save file to restart from",'L', "Persistence" ).value();
|
||||
|
||||
unsigned maxGen = parser.createParam(unsigned(100), "maxGen", "Maximum number of generations",'G', "Stopping criterion" ).value();
|
||||
|
||||
unsigned minGen = parser.createParam(unsigned(100), "minGen", "Minimum number of generations",'g', "Stopping criterion" ).value();
|
||||
|
||||
unsigned steadyGen = parser.createParam(unsigned(100), "steadyGen", "Number of generations with no improvement",'s', "Stopping criterion" ).value();
|
||||
|
||||
// operators probabilities at the algorithm level
|
||||
double pCross = parser.createParam(double(0.6), "pCross", "Probability of Crossover", 'C', "Genetic Operators" ).value();
|
||||
|
||||
double pMut = parser.createParam(double(0.1), "pMut", "Probability of Mutation", 'M', "Genetic Operators" ).value();
|
||||
|
||||
// relative rates for crossovers
|
||||
double hypercubeRate = parser.createParam(double(1), "hypercubeRate", "Relative rate for hypercube crossover", '\0', "Genetic Operators" ).value();
|
||||
|
||||
double segmentRate = parser.createParam(double(1), "segmentRate", "Relative rate for segment crossover", '\0', "Genetic Operators" ).value();
|
||||
|
||||
// internal parameters for the mutations
|
||||
double EPSILON = parser.createParam(double(0.01), "EPSILON", "Width for uniform mutation", '\0', "Genetic Operators" ).value();
|
||||
|
||||
double SIGMA = parser.createParam(double(0.3), "SIGMA", "Sigma for normal mutation", '\0', "Genetic Operators" ).value();
|
||||
|
||||
// relative rates for mutations
|
||||
double uniformMutRate = parser.createParam(double(1), "uniformMutRate", "Relative rate for uniform mutation", '\0', "Genetic Operators" ).value();
|
||||
|
||||
double detMutRate = parser.createParam(double(1), "detMutRate", "Relative rate for det-uniform mutation", '\0', "Genetic Operators" ).value();
|
||||
|
||||
double normalMutRate = parser.createParam(double(1), "normalMutRate", "Relative rate for normal mutation", '\0', "Genetic Operators" ).value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
string statusName = parser.createParam(str_status, "status","Status file",'S', "Persistence" ).value();
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusName != "")
|
||||
{
|
||||
ofstream os(statusName.c_str());
|
||||
os << parser; // and you can use that file as parameter file
|
||||
}
|
||||
|
||||
// EVAL
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
// you need to give the full description of the function
|
||||
eoEvalFuncPtr<Indi, double, const vector<double>& > plainEval( real_value );
|
||||
// ... to an object that counts the nb of actual evaluations
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// INIT
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
// Either load or initialize
|
||||
// create an empty pop
|
||||
eoPop<Indi> pop;
|
||||
// create a 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 conitnuation of the saved run
|
||||
// eventually with different parameters
|
||||
inState.registerObject(rng);
|
||||
inState.registerObject(pop);
|
||||
|
||||
if (loadName != "")
|
||||
{
|
||||
inState.load(loadName); // load the pop and the rng
|
||||
// the fitness is read in the file:
|
||||
// do only evaluate the pop if the fitness has changed
|
||||
}
|
||||
else
|
||||
{
|
||||
rng.reseed(seed);
|
||||
// a Indi random initializer
|
||||
// based on boolean_generator class (see utils/rnd_generator.h)
|
||||
eoUniformGenerator<double> uGen(-1.0, 1.0);
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
// Init pop from the randomizer: need to use the append function
|
||||
pop.append(popSize, random);
|
||||
// and evaluate pop (STL syntax)
|
||||
apply<Indi>(eval, pop);
|
||||
} // end of initializatio of the population
|
||||
|
||||
// OUTPUT
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl;
|
||||
cout << pop;
|
||||
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> selectOne(tSize);
|
||||
// is now encapsulated in a eoSelectPerc (entage)
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// uniform chooce on segment made by the parents
|
||||
eoSegmentCrossover<Indi> xoverS;
|
||||
// uniform choice in hypercube built by the parents
|
||||
eoHypercubeCrossover<Indi> xoverA;
|
||||
// Combine them with relative weights
|
||||
eoPropCombinedQuadOp<Indi> xover(xoverS, segmentRate);
|
||||
xover.add(xoverA, hypercubeRate, true);
|
||||
|
||||
// MUTATION
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
eoUniformMutation<Indi> mutationU(EPSILON);
|
||||
// k (=1) coordinates of parents are uniformly modified
|
||||
eoDetUniformMutation<Indi> mutationD(EPSILON);
|
||||
// all coordinates of parents are normally modified (stDev SIGMA)
|
||||
eoNormalMutation<Indi> mutationN(SIGMA);
|
||||
// Combine them with relative weights
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationU, uniformMutRate);
|
||||
mutation.add(mutationD, detMutRate);
|
||||
mutation.add(mutationN, normalMutRate, true);
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Indi> transform(xover, pCross, mutation, pMut);
|
||||
|
||||
// STOP
|
||||
//////////////////////////////////////
|
||||
// termination condition see FirstBitEA.cpp
|
||||
/////////////////////////////////////
|
||||
eoGenContinue<Indi> genCont(maxGen);
|
||||
eoSteadyFitContinue<Indi> steadyCont(minGen, steadyGen);
|
||||
eoFitContinue<Indi> fitCont(0);
|
||||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
|
||||
// CHECKPOINT
|
||||
// but now you want to make many different things every generation
|
||||
// (e.g. statistics, plots, ...).
|
||||
// the class eoCheckPoint is dedicated to just that:
|
||||
|
||||
// Declare a checkpoint (from a continuator: an eoCheckPoint
|
||||
// IS AN eoContinue and will be called in the loop of all algorithms)
|
||||
eoCheckPoint<Indi> checkpoint(continuator);
|
||||
|
||||
// Create a counter parameter
|
||||
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
||||
|
||||
// Create an incrementor (sub-class of eoUpdater). Note that the
|
||||
// parameter's value is passed by reference,
|
||||
// so every time the incrementer is updated (every generation),
|
||||
// the data in generationCounter will change.
|
||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||
|
||||
// Add it to the checkpoint,
|
||||
// so the counter is updated (here, incremented) every generation
|
||||
checkpoint.add(increment);
|
||||
|
||||
// now some statistics on the population:
|
||||
// Best fitness in population
|
||||
eoBestFitnessStat<Indi> bestStat;
|
||||
// Second moment stats: average and stdev
|
||||
eoSecondMomentStats<Indi> SecondStat;
|
||||
|
||||
// Add them to the checkpoint to get them called at the appropriate time
|
||||
checkpoint.add(bestStat);
|
||||
checkpoint.add(SecondStat);
|
||||
|
||||
// The Stdout monitor will print parameters to the screen ...
|
||||
eoStdoutMonitor monitor(false);
|
||||
|
||||
// when called by the checkpoint (i.e. at every generation)
|
||||
checkpoint.add(monitor);
|
||||
|
||||
// the monitor will output a series of parameters: add them
|
||||
monitor.add(generationCounter);
|
||||
monitor.add(eval); // because now eval is an eoEvalFuncCounter!
|
||||
monitor.add(bestStat);
|
||||
monitor.add(SecondStat);
|
||||
|
||||
// A file monitor: will print parameters to ... a File, yes, you got it!
|
||||
eoFileMonitor fileMonitor("stats.xg", " ");
|
||||
|
||||
// the checkpoint mechanism can handle multiple monitors
|
||||
checkpoint.add(fileMonitor);
|
||||
|
||||
// the fileMonitor can monitor parameters, too, but you must tell it!
|
||||
fileMonitor.add(generationCounter);
|
||||
fileMonitor.add(bestStat);
|
||||
fileMonitor.add(SecondStat);
|
||||
|
||||
// Last type of item the eoCheckpoint can handle: state savers:
|
||||
eoState outState;
|
||||
// Register the algorithm into the state (so it has something to save!!)
|
||||
outState.registerObject(parser);
|
||||
outState.registerObject(pop);
|
||||
outState.registerObject(rng);
|
||||
|
||||
// and feed the state to state savers
|
||||
// save state every 100th generation
|
||||
eoCountedStateSaver stateSaver1(20, outState, "generation");
|
||||
// save state every 1 seconds
|
||||
eoTimedStateSaver stateSaver2(1, outState, "time");
|
||||
|
||||
// Don't forget to add the two savers to the checkpoint
|
||||
checkpoint.add(stateSaver1);
|
||||
checkpoint.add(stateSaver2);
|
||||
// and that's it for the (control and) output
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// stopping criterion, eval, selection, transformation, replacement
|
||||
eoEasyEA<Indi> gga(checkpoint, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
// GENERAL
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
16
deprecated/eo/tutorial/Lesson3/binary_value.h
Normal file
16
deprecated/eo/tutorial/Lesson3/binary_value.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <eo>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Just a simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
// INIT
|
||||
double binary_value(const std::vector<bool>& _chrom)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _chrom.size(); i++)
|
||||
sum += _chrom[i];
|
||||
return sum;
|
||||
}
|
||||
404
deprecated/eo/tutorial/Lesson3/exercise3.1.cpp
Normal file
404
deprecated/eo/tutorial/Lesson3/exercise3.1.cpp
Normal file
|
|
@ -0,0 +1,404 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// SecondBitGA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Same code than FirstBitEA as far as Evolutionary Computation is concerned
|
||||
// but now you learn to enter the parameters in a more flexible way
|
||||
// and to twidle the output to your preferences!
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <fstream>
|
||||
#include <iostream> // cout
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
||||
// EVAL
|
||||
#include "binary_value.h"
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your genotype and fitness types
|
||||
typedef eoBit<eoMinimizingFitness> Indi;
|
||||
|
||||
using namespace std;
|
||||
|
||||
// the main_function: nothing changed(!), except variable initialization
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
//-----------------------------------------------------------------------------
|
||||
// instead of having all values of useful parameters as constants, read them:
|
||||
// either on the command line (--option=value or -o=value)
|
||||
// or in a parameter file (same syntax, order independent,
|
||||
// # = usual comment character
|
||||
// or in the environment (TODO)
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(100, "vecSize", "Genotype size",'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// parameters for evolution engine
|
||||
eoValueParam<unsigned int> popSizeParam(100, "popSize", "Population size",'P');
|
||||
parser.processParam( popSizeParam, "Evolution engine" );
|
||||
unsigned popSize = popSizeParam.value();
|
||||
|
||||
eoValueParam<unsigned int> tSizeParam(10, "tSize", "Tournament size",'T');
|
||||
parser.processParam( tSizeParam, "Evolution Engine" );
|
||||
unsigned tSize = tSizeParam.value();
|
||||
|
||||
// init and stop
|
||||
eoValueParam<string> loadNameParam("", "Load","A save file to restart from",'L');
|
||||
parser.processParam( loadNameParam, "Persistence" );
|
||||
string loadName = loadNameParam.value();
|
||||
|
||||
eoValueParam<unsigned int> maxGenParam(500, "maxGen", "Maximum number of generations",'G');
|
||||
parser.processParam( maxGenParam, "Stopping criterion" );
|
||||
unsigned maxGen = maxGenParam.value();
|
||||
|
||||
eoValueParam<unsigned int> minGenParam(500, "minGen", "Minimum number of generations",'g');
|
||||
parser.processParam( minGenParam, "Stopping criterion" );
|
||||
unsigned minGen = minGenParam.value();
|
||||
|
||||
eoValueParam<unsigned int> steadyGenParam(100, "steadyGen", "Number of generations with no improvement",'s');
|
||||
parser.processParam( steadyGenParam, "Stopping criterion" );
|
||||
unsigned steadyGen = steadyGenParam.value();
|
||||
|
||||
// operators probabilities at the algorithm level
|
||||
eoValueParam<double> pCrossParam(0.6, "pCross", "Probability of Crossover", 'C');
|
||||
parser.processParam( pCrossParam, "Genetic Operators" );
|
||||
double pCross = pCrossParam.value();
|
||||
|
||||
eoValueParam<double> pMutParam(0.1, "pMut", "Probability of Mutation", 'M');
|
||||
parser.processParam( pMutParam, "Genetic Operators" );
|
||||
double pMut = pMutParam.value();
|
||||
|
||||
// relative rates for crossovers
|
||||
eoValueParam<double> onePointRateParam(1, "onePointRate", "Relative rate for one point crossover", '1');
|
||||
parser.processParam( onePointRateParam, "Genetic Operators" );
|
||||
double onePointRate = onePointRateParam.value();
|
||||
|
||||
eoValueParam<double> twoPointsRateParam(1, "twoPointRate", "Relative rate for two point crossover", '2');
|
||||
parser.processParam( twoPointsRateParam, "Genetic Operators" );
|
||||
double twoPointsRate = twoPointsRateParam.value();
|
||||
|
||||
eoValueParam<double> uRateParam(2, "uRate", "Relative rate for uniform crossover", 'U');
|
||||
parser.processParam( uRateParam, "Genetic Operators" );
|
||||
double URate = uRateParam.value();
|
||||
|
||||
// relative rates and private parameters for mutations;
|
||||
eoValueParam<double> pMutPerBitParam(0.01, "pMutPerBit", "Probability of flipping 1 bit in bit-flip mutation", 'b');
|
||||
parser.processParam( pMutPerBitParam, "Genetic Operators" );
|
||||
double pMutPerBit = pMutPerBitParam.value();
|
||||
|
||||
eoValueParam<double> bitFlipRateParam(0.01, "bitFlipRate", "Relative rate for bit-flip mutation", 'B');
|
||||
parser.processParam( bitFlipRateParam, "Genetic Operators" );
|
||||
double bitFlipRate = bitFlipRateParam.value();
|
||||
|
||||
eoValueParam<double> oneBitRateParam(0.01, "oneBitRate", "Relative rate for deterministic bit-flip mutation", 'D');
|
||||
parser.processParam( oneBitRateParam, "Genetic Operators" );
|
||||
double oneBitRate = oneBitRateParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status","Status file",'S');
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "")
|
||||
{
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser; // and you can use that file as parameter file
|
||||
}
|
||||
|
||||
// EVAL
|
||||
/////////////////////////////
|
||||
// Fitness function
|
||||
////////////////////////////
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object ...
|
||||
eoEvalFuncPtr<Indi, double, const vector<bool>& > plainEval( binary_value );
|
||||
// ... to an object that counts the nb of actual evaluations
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// INIT
|
||||
////////////////////////////////
|
||||
// Initilisation of population
|
||||
////////////////////////////////
|
||||
// Either load or initialize
|
||||
// create an empty pop
|
||||
eoPop<Indi> pop;
|
||||
// create a 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 conitnuation of the saved run
|
||||
// eventually with different parameters
|
||||
inState.registerObject(rng);
|
||||
inState.registerObject(pop);
|
||||
|
||||
if (loadName != "")
|
||||
{
|
||||
inState.load(loadName); // load the pop and the rng
|
||||
// the fitness is read in the file:
|
||||
// do only evaluate the pop if the fitness has changed
|
||||
}
|
||||
else
|
||||
{
|
||||
rng.reseed(seed);
|
||||
// a Indi random initializer
|
||||
// based on boolean_generator class (see utils/rnd_generator.h)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
// Init pop from the randomizer: need to use the append function
|
||||
pop.append(popSize, random);
|
||||
// and evaluate pop (STL syntax)
|
||||
apply<Indi>(eval, pop);
|
||||
} // end of initializatio of the population
|
||||
|
||||
// OUTPUT
|
||||
// sort pop for pretty printout
|
||||
// pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl << pop ;
|
||||
cout << "and best is " << pop.best_element() << "\n\n";
|
||||
cout << "and worse is " << pop.worse_element() << "\n\n";
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> selectOne(tSize); // tSize in [2,POPSIZE]
|
||||
// is now encapsulated in a eoSelectPerc (entage)
|
||||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// generational replacement at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
// want to add (weak) elitism? easy!
|
||||
// rename the eoGenerationalReplacement replace_main,
|
||||
// then encapsulate it in the elitist replacement
|
||||
// eoWeakElitistReplacement<Indi> replace(replace_main);
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eo1PtBitXover<Indi> xover1;
|
||||
// uniform crossover for bitstring
|
||||
eoUBitXover<Indi> xoverU;
|
||||
// 2-pots xover
|
||||
eoNPtsBitXover<Indi> xover2(2);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
xover.add(xover2, twoPointsRate, true);
|
||||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBitMutation<Indi> mutationBitFlip(pMutPerBit);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);
|
||||
mutation.add(mutationOneBit, oneBitRate, true);
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Indi> transform(xover, pCross, mutation, pMut);
|
||||
|
||||
// STOP
|
||||
//////////////////////////////////////
|
||||
// termination condition see FirstBitEA.cpp
|
||||
/////////////////////////////////////
|
||||
eoGenContinue<Indi> genCont(maxGen);
|
||||
eoSteadyFitContinue<Indi> steadyCont(minGen, steadyGen);
|
||||
// eoFitContinue<Indi> fitCont(vecSize); // remove if minimizing :-)
|
||||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
// continuator.add(fitCont);
|
||||
// Ctrl C signal handling: don't know if that works in MSC ...
|
||||
#ifndef _MSC_VER
|
||||
eoCtrlCContinue<Indi> ctrlC;
|
||||
continuator.add(ctrlC);
|
||||
#endif
|
||||
|
||||
// CHECKPOINT
|
||||
// but now you want to make many different things every generation
|
||||
// (e.g. statistics, plots, ...).
|
||||
// the class eoCheckPoint is dedicated to just that:
|
||||
|
||||
// Declare a checkpoint (from a continuator: an eoCheckPoint
|
||||
// IS AN eoContinue and will be called in the loop of all algorithms)
|
||||
eoCheckPoint<Indi> checkpoint(continuator);
|
||||
|
||||
// Create a counter parameter
|
||||
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
||||
|
||||
// Create an incrementor (sub-class of eoUpdater). Note that the
|
||||
// parameter's value is passed by reference,
|
||||
// so every time the incrementer is updated (every generation),
|
||||
// the data in generationCounter will change.
|
||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||
|
||||
// Add it to the checkpoint,
|
||||
// so the counter is updated (here, incremented) every generation
|
||||
checkpoint.add(increment);
|
||||
|
||||
// now some statistics on the population:
|
||||
// Best fitness in population
|
||||
eoBestFitnessStat<Indi> bestStat;
|
||||
eoAverageStat<Indi> averageStat;
|
||||
// Second moment stats: average and stdev
|
||||
eoSecondMomentStats<Indi> SecondStat;
|
||||
// the Fitness Distance Correlation
|
||||
// need first an object to compute the distances
|
||||
eoQuadDistance<Indi> dist; // Hamming distance
|
||||
eoFDCStat<Indi> fdcStat(dist);
|
||||
|
||||
// Add them to the checkpoint to get them called at the appropriate time
|
||||
checkpoint.add(bestStat);
|
||||
checkpoint.add(averageStat);
|
||||
checkpoint.add(SecondStat);
|
||||
checkpoint.add(fdcStat);
|
||||
|
||||
// The Stdout monitor will print parameters to the screen ...
|
||||
eoStdoutMonitor monitor(false);
|
||||
|
||||
// when called by the checkpoint (i.e. at every generation)
|
||||
checkpoint.add(monitor);
|
||||
|
||||
// the monitor will output a series of parameters: add them
|
||||
monitor.add(generationCounter);
|
||||
monitor.add(eval); // because now eval is an eoEvalFuncCounter!
|
||||
monitor.add(bestStat);
|
||||
monitor.add(SecondStat);
|
||||
monitor.add(fdcStat);
|
||||
|
||||
// test de eoPopStat and/or eoSortedPopStat.
|
||||
// Dumps the whole pop every 10 gen.
|
||||
// eoSortedPopStat<Indi> popStat(10, "Dump of whole population");
|
||||
// eoPopStat<Indi> popStat(10, "Dump of whole population");
|
||||
// checkpoint.add(popStat);
|
||||
// monitor.add(popStat);
|
||||
|
||||
// A file monitor: will print parameters to ... a File, yes, you got it!
|
||||
eoFileMonitor fileMonitor("stats.xg", " ");
|
||||
|
||||
// the checkpoint mechanism can handle monitors
|
||||
checkpoint.add(fileMonitor);
|
||||
|
||||
// the fileMonitor can monitor parameters, too, but you must tell it!
|
||||
fileMonitor.add(generationCounter);
|
||||
fileMonitor.add(bestStat);
|
||||
fileMonitor.add(SecondStat);
|
||||
|
||||
#ifndef _MSC_VER
|
||||
// and an eoGnuplot1DMonitor will 1-print to a file, and 2- plot on screen
|
||||
eoGnuplot1DMonitor gnuMonitor("best_average.xg",minimizing_fitness<Indi>());
|
||||
// the checkpoint mechanism can handle multiple monitors
|
||||
checkpoint.add(gnuMonitor);
|
||||
// the gnuMonitor can monitor parameters, too, but you must tell it!
|
||||
gnuMonitor.add(eval);
|
||||
gnuMonitor.add(bestStat);
|
||||
gnuMonitor.add(averageStat);
|
||||
|
||||
// send a scaling command to gnuplot
|
||||
gnuMonitor.gnuplotCommand("set yrange [0:500]");
|
||||
|
||||
// a specific plot monitor for FDC
|
||||
// first into a file (it adds everything ti itself
|
||||
eoFDCFileSnapshot<Indi> fdcFileSnapshot(fdcStat);
|
||||
// then to a Gnuplot monitor
|
||||
eoGnuplot1DSnapshot fdcGnuplot(fdcFileSnapshot);
|
||||
// and of coruse add them to the checkPoint
|
||||
checkpoint.add(fdcFileSnapshot);
|
||||
checkpoint.add(fdcGnuplot);
|
||||
|
||||
// want to see how the fitness is spread?
|
||||
eoScalarFitnessStat<Indi> fitStat;
|
||||
checkpoint.add(fitStat);
|
||||
// a gnuplot-based monitor for snapshots: needs a dir name
|
||||
// where to store the files
|
||||
eoGnuplot1DSnapshot fitSnapshot("Fitnesses");
|
||||
// add any stat that is a vector<double> to it
|
||||
fitSnapshot.add(fitStat);
|
||||
// and of course add it to the checkpoint
|
||||
checkpoint.add(fitSnapshot);
|
||||
#endif
|
||||
// Last type of item the eoCheckpoint can handle: state savers:
|
||||
eoState outState;
|
||||
// Register the algorithm into the state (so it has something to save!!)
|
||||
outState.registerObject(rng);
|
||||
outState.registerObject(pop);
|
||||
|
||||
// and feed the state to state savers
|
||||
// save state every 100th generation
|
||||
eoCountedStateSaver stateSaver1(100, outState, "generation");
|
||||
// save state every 1 seconds
|
||||
eoTimedStateSaver stateSaver2(1, outState, "time");
|
||||
|
||||
// Don't forget to add the two savers to the checkpoint
|
||||
checkpoint.add(stateSaver1);
|
||||
checkpoint.add(stateSaver2);
|
||||
// and that's it for the (control and) output
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// selection, transformation, eval, replacement, and stopping criterion
|
||||
eoEasyEA<Indi> gga(checkpoint, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
// GENERAL
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
17
deprecated/eo/tutorial/Lesson3/real_value.h
Normal file
17
deprecated/eo/tutorial/Lesson3/real_value.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <vector>
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Just a simple function that takes an vector<double> and sets the fitnes
|
||||
to the sphere function. Please use doubles not float!!!
|
||||
@param _ind A floatingpoint vector
|
||||
*/
|
||||
|
||||
// INIT
|
||||
double real_value(const std::vector<double>& _ind)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _ind.size(); i++)
|
||||
{
|
||||
sum += _ind[i] * _ind[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
95
deprecated/eo/tutorial/Lesson4/BitEA.cpp
Normal file
95
deprecated/eo/tutorial/Lesson4/BitEA.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <ga/make_ga.h>
|
||||
#include <apply.h>
|
||||
|
||||
// EVAL
|
||||
#include "binary_value.h"
|
||||
|
||||
// GENERAL
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your genotype and fitness types
|
||||
typedef eoBit<double> EOT;
|
||||
|
||||
// PARAMETRES
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
// GENERAL
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
///// FIRST, problem or representation dependent stuff
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
// EVAL
|
||||
// The evaluation fn - encapsulated into an eval counter for output
|
||||
eoEvalFuncPtr<EOT, double> mainEval( binary_value<EOT> );
|
||||
eoEvalFuncCounter<EOT> eval(mainEval);
|
||||
|
||||
// REPRESENTATION
|
||||
// the genotype - through a genotype initializer
|
||||
eoInit<EOT>& init = make_genotype(parser, state, EOT());
|
||||
|
||||
// if you want to do sharing, you'll need a distance.
|
||||
// here Hamming distance
|
||||
eoHammingDistance<EOT> dist;
|
||||
|
||||
// OPERATORS
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
eoGenOp<EOT>& op = make_op(parser, state, init);
|
||||
|
||||
// GENERAL
|
||||
//// Now the representation-independent things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population - and evaluate
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<EOT>& pop = make_pop(parser, state, init);
|
||||
|
||||
// STOP
|
||||
// stopping criteria
|
||||
eoContinue<EOT> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
// GENERATION
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op, &dist);
|
||||
|
||||
///// End of construction of the algorith
|
||||
/////////////////////////////////////////
|
||||
// PARAMETRES
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
// EVAL
|
||||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<EOT>(eval, pop);
|
||||
// STOP
|
||||
// print it out (sort witout modifying)
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
// GENERATION
|
||||
run_ea(ga, pop); // run the ga
|
||||
// STOP
|
||||
// print it out (sort witout modifying)
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
// GENERAL
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
}
|
||||
98
deprecated/eo/tutorial/Lesson4/CMakeLists.txt
Normal file
98
deprecated/eo/tutorial/Lesson4/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
######################################################################################
|
||||
### 0) Copy the ESEA.param and RealEA.param files in the build directory for an easy use.
|
||||
######################################################################################
|
||||
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${EO_SOURCE_DIR}/tutorial/Lesson4/ESEA.param
|
||||
${EO_BINARY_DIR}/tutorial/Lesson4/ESEA.param
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${EO_SOURCE_DIR}/tutorial/Lesson4/RealEA.param
|
||||
${EO_BINARY_DIR}/tutorial/Lesson4/RealEA.param
|
||||
)
|
||||
|
||||
##############
|
||||
# OLD_TARGETS
|
||||
##############
|
||||
#ADD_CUSTOM_TARGET(param DEPENDS ${EO_SOURCE_DIR}/tutorial/Lesson4/ESEA.param)
|
||||
#ADD_CUSTOM_COMMAND(
|
||||
# TARGET param
|
||||
# POST_BUILD
|
||||
# COMMAND ${CMAKE_COMMAND}
|
||||
# ARGS -E copy_if_different
|
||||
# ${EO_SOURCE_DIR}/tutorial/Lesson4/ESEA.param
|
||||
# ${EO_BINARY_DIR}/tutorial/Lesson4)
|
||||
#ADD_CUSTOM_TARGET(param DEPENDS ${EO_SOURCE_DIR}/tutorial/Lesson4/RealEA.param)
|
||||
#ADD_CUSTOM_COMMAND(
|
||||
# TARGET param
|
||||
# POST_BUILD
|
||||
# COMMAND ${CMAKE_COMMAND}
|
||||
# ARGS -E copy_if_different
|
||||
# ${EO_SOURCE_DIR}/tutorial/Lesson4/RealEA.param
|
||||
# ${EO_BINARY_DIR}/tutorial/Lesson4)
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/es)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/utils)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/ga)
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets
|
||||
######################################################################################
|
||||
|
||||
# no matter what is the OS, hopefully
|
||||
ADD_EXECUTABLE(BitEA BitEA.cpp)
|
||||
ADD_EXECUTABLE(RealEA RealEA.cpp)
|
||||
ADD_EXECUTABLE(ESEA ESEA.cpp)
|
||||
|
||||
#ADD_DEPENDENCIES(BitEA es ga eo eoutils)
|
||||
#ADD_DEPENDENCIES(RealEA es ga eo eoutils)
|
||||
#ADD_DEPENDENCIES(ESEA es ga eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal
|
||||
######################################################################################
|
||||
|
||||
SET(BITEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(BitEA PROPERTIES VERSION "${BITEA_VERSION}")
|
||||
|
||||
SET(REALEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(RealEA PROPERTIES VERSION "${REALEA_VERSION}")
|
||||
|
||||
SET(ESEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(ESEA PROPERTIES VERSION "${ESEA_VERSION}")
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies for the targets
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(BitEA es ga eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(RealEA es ga eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(ESEA es ga eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
### 6) Configure project installation paths
|
||||
######################################################################################
|
||||
|
||||
INSTALL(TARGETS BitEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson4 COMPONENT examples)
|
||||
INSTALL(TARGETS RealEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson4 COMPONENT examples)
|
||||
INSTALL(TARGETS ESEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson4 COMPONENT examples)
|
||||
|
||||
######################################################################################
|
||||
137
deprecated/eo/tutorial/Lesson4/ESEA.cpp
Normal file
137
deprecated/eo/tutorial/Lesson4/ESEA.cpp
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
// Program to test several EO-ES features
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <eo>
|
||||
|
||||
// representation specific
|
||||
#include <es/make_es.h>
|
||||
|
||||
#include "real_value.h" // the sphere fitness
|
||||
|
||||
// Now the main
|
||||
///////////////
|
||||
typedef eoMinimizingFitness FitT;
|
||||
|
||||
template <class EOT>
|
||||
void runAlgorithm(EOT, eoParser& _parser, eoState& _state);
|
||||
|
||||
int main_function(int argc, char *argv[])
|
||||
{
|
||||
// Create the command-line parser
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
|
||||
eoValueParam<bool>& simpleParam = parser.createParam(true, "Isotropic", "Isotropic self-adaptive mutation", 'i', "ES mutation");
|
||||
eoValueParam<bool>& stdevsParam = parser.createParam(false, "Stdev", "One self-adaptive stDev per variable", 's', "ES mutation");
|
||||
eoValueParam<bool>& corrParam = parser.createParam(false, "Correl", "Use correlated mutations", 'c', "ES mutation");
|
||||
|
||||
// Run the appropriate algorithm
|
||||
if (simpleParam.value() == false)
|
||||
{
|
||||
cout << "Using eoReal" << endl;
|
||||
runAlgorithm(eoReal<FitT>(), parser, state);
|
||||
}
|
||||
else if (stdevsParam.value() == false)
|
||||
{
|
||||
cout << "Using eoEsSimple" << endl;
|
||||
runAlgorithm(eoEsSimple<FitT>(), parser, state);
|
||||
}
|
||||
else if (corrParam.value() == false)
|
||||
{
|
||||
cout << "Using eoEsStdev" << endl;
|
||||
runAlgorithm(eoEsStdev<FitT>(), parser, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Using eoEsFull" << endl;
|
||||
runAlgorithm(eoEsFull<FitT>(), parser, state);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** The templatized main (sort of)
|
||||
* quite similar to the main of other genotypes
|
||||
* (e.g. t-eoReal and t-eoGA in test dir)
|
||||
*/
|
||||
template <class EOT>
|
||||
void runAlgorithm(EOT, eoParser& _parser, eoState& _state)
|
||||
{
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
||||
///// FIRST, problem or representation dependent stuff
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
// The evaluation fn - encapsulated into an eval counter for output
|
||||
eoEvalFuncPtr<EOT, double, const std::vector<double>&>
|
||||
mainEval( real_value );
|
||||
eoEvalFuncCounter<EOT> eval(mainEval);
|
||||
|
||||
// the genotype - through a genotype initializer
|
||||
eoRealInitBounded<EOT>& init = make_genotype(_parser, _state, EOT());
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
eoGenOp<EOT>& op = make_op(_parser, _state, init);
|
||||
|
||||
//// Now the representation-independent things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population - and evaluate
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<EOT>& pop = make_pop(_parser, _state, init);
|
||||
apply<EOT>(eval, pop);
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<EOT> & term = make_continue(_parser, _state, eval);
|
||||
// output
|
||||
eoCheckPoint<EOT> & checkpoint = make_checkpoint(_parser, _state, eval, term);
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<EOT>& ga = make_algo_scalar(_parser, _state, eval, checkpoint, op);
|
||||
|
||||
///// End of construction of the algorith
|
||||
/////////////////////////////////////////
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(_parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
}
|
||||
61
deprecated/eo/tutorial/Lesson4/ESEA.param
Normal file
61
deprecated/eo/tutorial/Lesson4/ESEA.param
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
###### General ######
|
||||
# --help=0 # -h : Prints this message
|
||||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
# --seed=1104133126 # -S : Random number seed
|
||||
|
||||
###### ES mutation ######
|
||||
# --Isotropic=1 # -i : Isotropic self-adaptive mutation
|
||||
# --Stdev=0 # -s : One self-adaptive stDev per variable
|
||||
# --Correl=0 # -c : Use correlated mutations
|
||||
|
||||
###### Evolution Engine ######
|
||||
--popSize=1 # -P : Population Size
|
||||
--selection=Sequential # -S : Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e) or Sequential(ordered/unordered)
|
||||
--nbOffspring=700% # -O : Nb of offspring (percentage or absolute)
|
||||
--replacement=Comma # -R : Replacement: Comma, Plus or EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)
|
||||
--weakElitism=0 # -w : Old best parent replaces new worst offspring *if necessary*
|
||||
|
||||
###### Genotype Initialization ######
|
||||
# --vecSize=10 # -n : The number of variables
|
||||
# --initBounds=10[-1,1] # -B : Bounds for initialization (MUST be bounded)
|
||||
--sigmaInit=0.3% # -s : Initial value for Sigmas (with a '%' -> scaled by the range of each variable)
|
||||
|
||||
###### Output ######
|
||||
# --useEval=1 # Use nb of eval. as counter (vs nb of gen.)
|
||||
# --useTime=1 # Display time (s) every generation
|
||||
# --printBestStat=1 # Print Best/avg/stdev every gen.
|
||||
# --printPop=0 # Print sorted pop. every gen.
|
||||
|
||||
###### Output - Disk ######
|
||||
# --resDir=Res # Directory to store DISK outputs
|
||||
# --eraseDir=1 # erase files in dirName if any
|
||||
# --fileBestStat=0 # Output bes/avg/std to file
|
||||
|
||||
###### Output - Graphical ######
|
||||
# --plotBestStat=0 # Plot Best/avg Stat
|
||||
# --plotHisto=0 # Plot histogram of fitnesses
|
||||
|
||||
###### 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=t-eoESAll.status # Status file
|
||||
|
||||
###### Stopping criterion ######
|
||||
# --maxGen=100 # -G : Maximum number of generations () = none)
|
||||
# --steadyGen=100 # -s : Number of generations with no improvement
|
||||
# --minGen=0 # -g : Minimum number of generations
|
||||
# --maxEval=0 # -E : Maximum number of evaluations (0 = none)
|
||||
# --targetFitness=0 # -T : Stop when fitness reaches
|
||||
# --CtrlC=0 # -C : Terminate current generation upon Ctrl C
|
||||
|
||||
###### Variation Operators ######
|
||||
# --objectBounds=10[-inf,+inf] # -B : Bounds for variables
|
||||
# --operator=SGA # -o : Description of the operator (SGA only now)
|
||||
# --pCross=1 # -C : Probability of Crossover
|
||||
# --pMut=1 # -M : Probability of Mutation
|
||||
# --crossType=global # -C : Type of ES recombination (global or standard)
|
||||
# --crossObj=discrete # -O : Recombination of object variables (discrete, intermediate or none)
|
||||
# --crossStdev=intermediate # -S : Recombination of mutation strategy parameters (intermediate, discrete or none)
|
||||
# --TauLoc=1 # -l : Local Tau (before normalization)
|
||||
33
deprecated/eo/tutorial/Lesson4/Makefile.simple
Normal file
33
deprecated/eo/tutorial/Lesson4/Makefile.simple
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
### This Makefile is part of the tutorial of the EO library
|
||||
# Unlike other Makefiles in EO, it is not using the automake/autoconf
|
||||
# so that it stays easy to understant (you are in the tutorial, remember!)
|
||||
# MS, Oct. 2002
|
||||
|
||||
# if you use this Makefile as a starting point for another application
|
||||
# you might need to modify the following
|
||||
DIR_EO = ../../src
|
||||
|
||||
.SUFFIXES: .cpp
|
||||
|
||||
# Warning: $(CXX) in Linux (RedHat and Mandrake at least) is g++
|
||||
# However, if you are using this Makefile within xemacs,
|
||||
# and have problems with the interpretation of the output (and its colors)
|
||||
# then you should use c++ instead (make CXX=c++ will do)
|
||||
|
||||
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -o $@ $*.cpp $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
.cpp.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c $*.cpp
|
||||
|
||||
ALL = BitEA RealEA ESEA
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
BitEA : BitEA.o ;
|
||||
$(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.2\" -Wall -g -o $@ $< $(DIR_EO)/ga/libga.a $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
RealEA : RealEA.o ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.2\" -Wall -g -o $@ $< $(DIR_EO)/es/libes.a $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
ESEA : ESEA.o ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.2\" -Wall -g -o $@ $< $(DIR_EO)/es/libes.a $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
clean :
|
||||
@/bin/rm $(ALL) *.o *.sav *.xg *.status *~
|
||||
72
deprecated/eo/tutorial/Lesson4/RealEA.cpp
Normal file
72
deprecated/eo/tutorial/Lesson4/RealEA.cpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <es/make_real.h>
|
||||
#include "real_value.h"
|
||||
#include <apply.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
typedef eoReal<eoMinimizingFitness> EOT;
|
||||
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
///// FIRST, problem or representation dependent stuff
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
// The evaluation fn - encapsulated into an eval counter for output
|
||||
eoEvalFuncPtr<EOT, double, const std::vector<double>&>
|
||||
mainEval( real_value );
|
||||
eoEvalFuncCounter<EOT> eval(mainEval);
|
||||
|
||||
// the genotype - through a genotype initializer
|
||||
eoRealInitBounded<EOT>& init = make_genotype(parser, state, EOT());
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
eoGenOp<EOT>& op = make_op(parser, state, init);
|
||||
|
||||
//// Now the representation-independent things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population - and evaluate
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<EOT>& pop = make_pop(parser, state, init);
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<EOT> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<EOT>& ea = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
|
||||
///// End of construction of the algorith
|
||||
/////////////////////////////////////////
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<EOT>(eval, pop);
|
||||
// print it out
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
run_ea(ea, pop); // run the ea
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
}
|
||||
56
deprecated/eo/tutorial/Lesson4/RealEA.param
Normal file
56
deprecated/eo/tutorial/Lesson4/RealEA.param
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
###### General ######
|
||||
# --help=0 # -h : Prints this message
|
||||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
# --seed=1104133126 # -S : Random number seed
|
||||
|
||||
###### Evolution Engine ######
|
||||
--popSize=10 # -P : Population Size
|
||||
--selection=Sequential # -S : Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e) or Sequential(ordered/unordered)
|
||||
--nbOffspring=700% # -O : Nb of offspring (percentage or absolute)
|
||||
--replacement=Plus # -R : Replacement: Comma, Plus or EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)
|
||||
--weakElitism=0 # -w : Old best parent replaces new worst offspring *if necessary*
|
||||
|
||||
###### Genotype Initialization ######
|
||||
# --vecSize=10 # -n : The number of variables
|
||||
# --initBounds=10[-1,1] # -B : Bounds for initialization (MUST be bounded)
|
||||
--sigmaInit=0.3% # -s : Initial value for Sigmas (with a '%' -> scaled by the range of each variable)
|
||||
|
||||
###### Output ######
|
||||
# --useEval=1 # Use nb of eval. as counter (vs nb of gen.)
|
||||
# --useTime=1 # Display time (s) every generation
|
||||
# --printBestStat=1 # Print Best/avg/stdev every gen.
|
||||
# --printPop=0 # Print sorted pop. every gen.
|
||||
|
||||
###### Output - Disk ######
|
||||
# --resDir=Res # Directory to store DISK outputs
|
||||
# --eraseDir=1 # erase files in dirName if any
|
||||
# --fileBestStat=0 # Output bes/avg/std to file
|
||||
|
||||
###### Output - Graphical ######
|
||||
# --plotBestStat=0 # Plot Best/avg Stat
|
||||
# --plotHisto=0 # Plot histogram of fitnesses
|
||||
|
||||
###### 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=t-eoESAll.status # Status file
|
||||
|
||||
###### Stopping criterion ######
|
||||
# --maxGen=100 # -G : Maximum number of generations () = none)
|
||||
# --steadyGen=100 # -s : Number of generations with no improvement
|
||||
# --minGen=0 # -g : Minimum number of generations
|
||||
# --maxEval=0 # -E : Maximum number of evaluations (0 = none)
|
||||
# --targetFitness=0 # -T : Stop when fitness reaches
|
||||
# --CtrlC=0 # -C : Terminate current generation upon Ctrl C
|
||||
|
||||
###### Variation Operators ######
|
||||
# --objectBounds=10[-inf,+inf] # -B : Bounds for variables
|
||||
# --operator=SGA # -o : Description of the operator (SGA only now)
|
||||
# --pCross=1 # -C : Probability of Crossover
|
||||
# --pMut=1 # -M : Probability of Mutation
|
||||
# --crossType=global # -C : Type of ES recombination (global or standard)
|
||||
# --crossObj=discrete # -O : Recombination of object variables (discrete, intermediate or none)
|
||||
# --crossStdev=intermediate # -S : Recombination of mutation strategy parameters (intermediate, discrete or none)
|
||||
# --TauLoc=1 # -l : Local Tau (before normalization)
|
||||
25
deprecated/eo/tutorial/Lesson4/binary_value.h
Normal file
25
deprecated/eo/tutorial/Lesson4/binary_value.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include <eo>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Just a simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
|
||||
template <class Chrom> double binary_value(const Chrom& _chrom)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _chrom.size(); i++)
|
||||
if (_chrom[i])
|
||||
sum += _chrom[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
struct BinaryValue
|
||||
{
|
||||
template <class Chrom> void operator()(Chrom& _chrom)
|
||||
{
|
||||
_chrom.fitness(binary_value(_chrom));
|
||||
}
|
||||
};
|
||||
16
deprecated/eo/tutorial/Lesson4/real_value.h
Normal file
16
deprecated/eo/tutorial/Lesson4/real_value.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <vector>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/** Just a simple function that takes an eoEsBase<double> and sets the fitnes
|
||||
to sphere
|
||||
@param _ind vector<double>
|
||||
*/
|
||||
|
||||
double real_value(const std::vector<double>& _ind)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _ind.size(); i++)
|
||||
sum += _ind[i] * _ind[i];
|
||||
return sqrt(sum);
|
||||
}
|
||||
56
deprecated/eo/tutorial/Lesson5/CMakeLists.txt
Normal file
56
deprecated/eo/tutorial/Lesson5/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets
|
||||
######################################################################################
|
||||
|
||||
# no matter what is the OS, hopefully
|
||||
ADD_EXECUTABLE(OneMaxEA OneMaxEA.cpp)
|
||||
ADD_EXECUTABLE(OneMaxLibEA OneMaxLibEA.cpp make_OneMax.cpp)
|
||||
|
||||
ADD_DEPENDENCIES(OneMaxEA es ga eo eoutils)
|
||||
ADD_DEPENDENCIES(OneMaxLibEA es ga eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal
|
||||
######################################################################################
|
||||
|
||||
SET(ONEMAXEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(OneMaxEA PROPERTIES VERSION "${ONEMAXEA_VERSION}")
|
||||
|
||||
SET(ONEMAXLIBEA_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(OneMaxLibEA PROPERTIES VERSION "${ONEMAXLIBEA_VERSION}")
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies for the targets
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(OneMaxEA es ga eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(OneMaxLibEA es ga eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
### 6) Configure project installation paths
|
||||
######################################################################################
|
||||
|
||||
INSTALL(TARGETS OneMaxEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson5 COMPONENT examples)
|
||||
INSTALL(TARGETS OneMaxLibEA RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson5 COMPONENT examples)
|
||||
|
||||
######################################################################################
|
||||
56
deprecated/eo/tutorial/Lesson5/Makefile.simple
Normal file
56
deprecated/eo/tutorial/Lesson5/Makefile.simple
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
### This Makefile is part of the tutorial of the EO library
|
||||
# Unlike other Makefiles in EO, it is not using the automake/autoconf
|
||||
# so that it stays easy to understant (you are in the tutorial, remember!)
|
||||
# MS, Oct. 2002
|
||||
|
||||
# if you use this Makefile as a starting point for another application
|
||||
# you might need to modify the following
|
||||
DIR_EO = ../../src
|
||||
|
||||
.SUFFIXES: .cpp
|
||||
|
||||
# Warning: $(CXX) in Linux (RedHat and Mandrake at least) is g++
|
||||
# However, if you are using this Makefile within xemacs,
|
||||
# and have problems with the interpretation of the output (and its colors)
|
||||
# then you should use c++ instead (make CXX=c++ will do)
|
||||
|
||||
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -o $@ $*.cpp $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
.cpp.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c $*.cpp
|
||||
|
||||
# local sources
|
||||
COMMON_SOURCES = eoOneMax.h \
|
||||
eoOneMaxEvalFunc.h \
|
||||
eoOneMaxInit.h \
|
||||
eoOneMaxMutation.h \
|
||||
eoOneMaxQuadCrossover.h \
|
||||
make_genotype_OneMax.h \
|
||||
make_op_OneMax.h
|
||||
|
||||
NO_LIB_SOURCES = OneMaxEA.cpp
|
||||
|
||||
LIB_SOURCES = OneMaxLibEA.cpp make_OneMax.cpp
|
||||
|
||||
|
||||
SOURCES = $(COMMON_SOURCES) OneMaxEA.cpp OneMaxLibEA.cpp make_OneMax.cpp
|
||||
|
||||
LIB_EO = $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
ALL = OneMaxEA OneMaxLibEA
|
||||
|
||||
OneMaxEA : OneMaxEA.o
|
||||
$(CXX) -g -o $@ OneMaxEA.o $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a -lm
|
||||
|
||||
OneMaxLibEA : OneMaxLibEA.o make_OneMax.o
|
||||
$(CXX) -g -o $@ OneMaxLibEA.o make_OneMax.o $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a -lm
|
||||
|
||||
tar : ; tar czvf OneMax.tgz *.h *.cpp Makefile
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
clean : ; /bin/rm *.o $(ALL)
|
||||
|
||||
########## local dependencies
|
||||
OneMaxEA.o : $(COMMON_SOURCES) OneMaxEA.cpp
|
||||
OneMaxLibEA.o : $(COMMON_SOURCES) OneMaxLibEA.cpp
|
||||
make_OneMax.o : make_OneMax.cpp eoOneMax.h
|
||||
188
deprecated/eo/tutorial/Lesson5/OneMaxEA.cpp
Normal file
188
deprecated/eo/tutorial/Lesson5/OneMaxEA.cpp
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
|
||||
This is the template main file.
|
||||
It includes all other files that have been generated by the script create.sh
|
||||
so it is the only file to compile.
|
||||
|
||||
In case you want to build up a separate library for your new Evolving Object,
|
||||
you'll need some work - follow what's done in the src/ga dir, used in the
|
||||
main file BitEA in tutorial/Lesson4 dir.
|
||||
Or you can wait until we do it :-)
|
||||
*/
|
||||
|
||||
// Miscilaneous include and declaration
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// eo general include
|
||||
#include "eo"
|
||||
// the real bounds (not yet in general eo include)
|
||||
#include "utils/eoRealVectorBounds.h"
|
||||
|
||||
// include here whatever specific files for your representation
|
||||
// Basically, this should include at least the following
|
||||
|
||||
/** definition of representation:
|
||||
* class eoOneMax MUST derive from EO<FitT> for some fitness
|
||||
*/
|
||||
#include "eoOneMax.h"
|
||||
|
||||
/** definition of initilizqtion:
|
||||
* class eoOneMaxInit MUST derive from eoInit<eoOneMax>
|
||||
*/
|
||||
#include "eoOneMaxInit.h"
|
||||
|
||||
/** definition of evaluation:
|
||||
* class eoOneMaxEvalFunc MUST derive from eoEvalFunc<eoOneMax>
|
||||
* and should test for validity before doing any computation
|
||||
* see tutorial/Templates/evalFunc.tmpl
|
||||
*/
|
||||
#include "eoOneMaxEvalFunc.h"
|
||||
|
||||
// GENOTYPE eoOneMax ***MUST*** be templatized over the fitness
|
||||
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
// START fitness type: double or eoMaximizingFitness if you are maximizing
|
||||
// eoMinimizingFitness if you are minimizing
|
||||
typedef eoMaximizingFitness MyFitT ; // type of fitness
|
||||
// END fitness type
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
|
||||
// Then define your EO objects using that fitness type
|
||||
typedef eoOneMax<MyFitT> Indi; // ***MUST*** derive from EO
|
||||
|
||||
// create an initializer
|
||||
#include "make_genotype_OneMax.h"
|
||||
eoInit<Indi> & make_genotype(eoParser& _parser, eoState&_state, Indi _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
||||
// and the variation operaotrs
|
||||
#include "make_op_OneMax.h"
|
||||
eoGenOp<Indi>& make_op(eoParser& _parser, eoState& _state, eoInit<Indi>& _init)
|
||||
{
|
||||
return do_make_op(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// Use existing modules to define representation independent routines
|
||||
// These are parser-based definitions of objects
|
||||
|
||||
// how to initialize the population
|
||||
// it IS representation independent if an eoInit is given
|
||||
#include <do/make_pop.h>
|
||||
eoPop<Indi >& make_pop(eoParser& _parser, eoState& _state, eoInit<Indi> & _init)
|
||||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// the stopping criterion
|
||||
#include <do/make_continue.h>
|
||||
eoContinue<Indi>& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)
|
||||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
// outputs (stats, population dumps, ...)
|
||||
#include <do/make_checkpoint.h>
|
||||
eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
// evolution engine (selection and replacement)
|
||||
#include <do/make_algo_scalar.h>
|
||||
eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& _continue, eoGenOp<Indi>& _op)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
// no template for that one
|
||||
#include <do/make_run.h>
|
||||
// the instanciating fitnesses
|
||||
#include <eoScalarFitness.h>
|
||||
void run_ea(eoAlgo<Indi>& _ga, eoPop<Indi>& _pop)
|
||||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
// checks for help demand, and writes the status file
|
||||
// and make_help; in libutils
|
||||
void make_help(eoParser & _parser);
|
||||
|
||||
// now use all of the above, + representation dependent things
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
// The fitness
|
||||
//////////////
|
||||
eoOneMaxEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
|
||||
// turn that object into an evaluation counter
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// the genotype - through a genotype initializer
|
||||
eoInit<Indi>& init = make_genotype(parser, state, Indi());
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
eoGenOp<Indi>& op = make_op(parser, state, init);
|
||||
|
||||
|
||||
//// Now the representation-independent things
|
||||
//
|
||||
// YOU SHOULD NOT NEED TO MODIFY ANYTHING BEYOND THIS POINT
|
||||
// unless you want to add specific statistics to the checkpoint
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<Indi>& pop = make_pop(parser, state, init);
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<Indi> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
|
||||
///// End of construction of the algorithm
|
||||
|
||||
/////////////////////////////////////////
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<Indi>(eval, pop);
|
||||
// if you want to print it out
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
162
deprecated/eo/tutorial/Lesson5/OneMaxLibEA.cpp
Normal file
162
deprecated/eo/tutorial/Lesson5/OneMaxLibEA.cpp
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
|
||||
This is the template main file for compiling after creating a
|
||||
library.
|
||||
See make_OneMax.cpp file.
|
||||
*/
|
||||
|
||||
// Miscilaneous include and declaration
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// eo general include
|
||||
#include "eo"
|
||||
// the real bounds (not yet in general eo include)
|
||||
#include "utils/eoRealVectorBounds.h"
|
||||
|
||||
// include here whatever specific files for your representation
|
||||
// Basically, this should include at least the following
|
||||
|
||||
/** definition of representation:
|
||||
* class eoOneMax MUST derive from EO<FitT> for some fitness
|
||||
*/
|
||||
#include "eoOneMax.h"
|
||||
|
||||
/** definition of initilizqtion:
|
||||
* class eoOneMaxInit MUST derive from eoInit<eoOneMax>
|
||||
*/
|
||||
#include "eoOneMaxInit.h"
|
||||
|
||||
/** definition of evaluation:
|
||||
* class eoOneMaxEvalFunc MUST derive from eoEvalFunc<eoOneMax>
|
||||
* and should test for validity before doing any computation
|
||||
* see tutorial/Templates/evalFunc.tmpl
|
||||
*/
|
||||
#include "eoOneMaxEvalFunc.h"
|
||||
|
||||
// GENOTYPE eoOneMax ***MUST*** be templatized over the fitness
|
||||
|
||||
//
|
||||
// START fitness type: double or eoMaximizingFitness if you are maximizing
|
||||
// eoMinimizingFitness if you are minimizing
|
||||
typedef eoMinimizingFitness MyFitT ; // type of fitness
|
||||
// END fitness type
|
||||
//
|
||||
|
||||
// Then define your EO objects using that fitness type
|
||||
typedef eoOneMax<MyFitT> Indi; // ***MUST*** derive from EO
|
||||
|
||||
// create an initializer - done here and NOT in make_OneMax.cpp
|
||||
// because it is NOT representation independent
|
||||
#include "make_genotype_OneMax.h"
|
||||
eoInit<Indi> & make_genotype(eoParser& _parser, eoState&_state, Indi _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
||||
// same thing for the variation operaotrs
|
||||
#include "make_op_OneMax.h"
|
||||
eoGenOp<Indi>& make_op(eoParser& _parser, eoState& _state, eoInit<Indi>& _init)
|
||||
{
|
||||
return do_make_op(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// The representation independent routines are simply declared here
|
||||
|
||||
// how to initialize the population
|
||||
// it IS representation independent if an eoInit is given
|
||||
eoPop<Indi >& make_pop(eoParser& _parser, eoState& _state, eoInit<Indi> & _init);
|
||||
|
||||
// the stopping criterion
|
||||
eoContinue<Indi>& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval);
|
||||
|
||||
// outputs (stats, population dumps, ...)
|
||||
eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& _continue);
|
||||
|
||||
// evolution engine (selection and replacement)
|
||||
eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& _continue, eoGenOp<Indi>& _op);
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
// no template for that one
|
||||
void run_ea(eoAlgo<Indi>& _ga, eoPop<Indi>& _pop);
|
||||
|
||||
// checks for help demand, and writes the status file
|
||||
// and make_help; in libutils - just a declaration, code in libeoutils.a
|
||||
void make_help(eoParser & _parser);
|
||||
|
||||
// now use all of the above, + representation dependent things
|
||||
// from here on, no difference with eoOneMax.cpp
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
// The fitness
|
||||
//////////////
|
||||
eoOneMaxEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
|
||||
// turn that object into an evaluation counter
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// the genotype - through a genotype initializer
|
||||
eoInit<Indi>& init = make_genotype(parser, state, Indi());
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
eoGenOp<Indi>& op = make_op(parser, state, init);
|
||||
|
||||
|
||||
//// Now the representation-independent things
|
||||
//
|
||||
// YOU SHOULD NOT NEED TO MODIFY ANYTHING BEYOND THIS POINT
|
||||
// unless you want to add specific statistics to the checkpoint
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<Indi>& pop = make_pop(parser, state, init);
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<Indi> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
|
||||
///// End of construction of the algorithm
|
||||
|
||||
/////////////////////////////////////////
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<Indi>(eval, pop);
|
||||
// if you want to print it out
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
110
deprecated/eo/tutorial/Lesson5/eoOneMax.h
Normal file
110
deprecated/eo/tutorial/Lesson5/eoOneMax.h
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
*/
|
||||
|
||||
#ifndef _eoOneMax_h
|
||||
#define _eoOneMax_h
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
|
||||
* Note that you MUST derive your structure from EO<fitT>
|
||||
* but you MAY use some other already prepared class in the hierarchy
|
||||
* like eoVector for instance, if you handle a vector of something....
|
||||
|
||||
* If you create a structure from scratch,
|
||||
* the only thing you need to provide are
|
||||
* a default constructor
|
||||
* IO routines printOn and readFrom
|
||||
*
|
||||
* Note that operator<< and operator>> are defined at EO level
|
||||
* using these routines
|
||||
*/
|
||||
template< class FitT>
|
||||
class eoOneMax: public EO<FitT> {
|
||||
public:
|
||||
/** Ctor: you MUST provide a default ctor.
|
||||
* though such individuals will generally be processed
|
||||
* by some eoInit object
|
||||
*/
|
||||
eoOneMax()
|
||||
{
|
||||
// START Code of default Ctor of an eoOneMax object
|
||||
// END Code of default Ctor of an eoOneMax object
|
||||
}
|
||||
|
||||
virtual ~eoOneMax()
|
||||
{
|
||||
// START Code of Destructor of an eoEASEAGenome object
|
||||
// END Code of Destructor of an eoEASEAGenome object
|
||||
}
|
||||
|
||||
virtual string className() const { return "eoOneMax"; }
|
||||
|
||||
/** printing... */
|
||||
void printOn(ostream& _os) const
|
||||
{
|
||||
// First write the fitness
|
||||
EO<FitT>::printOn(_os);
|
||||
_os << ' ';
|
||||
// START Code of default output
|
||||
|
||||
/** HINTS
|
||||
* in EO we systematically write the sizes of things before the things
|
||||
* so readFrom is easier to code (see below)
|
||||
*/
|
||||
_os << b.size() << ' ' ;
|
||||
for (unsigned i=0; i<b.size(); i++)
|
||||
_os << b[i] << ' ' ;
|
||||
// END Code of default output
|
||||
}
|
||||
|
||||
/** reading...
|
||||
* of course, your readFrom must be able to read what printOn writes!!!
|
||||
*/
|
||||
void readFrom(istream& _is)
|
||||
{
|
||||
// of course you should read the fitness first!
|
||||
EO<FitT>::readFrom(_is);
|
||||
// START Code of input
|
||||
|
||||
/** HINTS
|
||||
* remember the eoOneMax object will come from the default ctor
|
||||
* this is why having the sizes written out is useful
|
||||
*/
|
||||
unsigned s;
|
||||
_is >> s;
|
||||
b.resize(s);
|
||||
for (unsigned i=0; i<s; i++)
|
||||
{
|
||||
bool bTmp;
|
||||
_is >> bTmp;
|
||||
b[i] = bTmp;
|
||||
}
|
||||
// END Code of input
|
||||
}
|
||||
|
||||
// accessing and setting values
|
||||
void setB(vector<bool> & _b)
|
||||
{
|
||||
b=_b;
|
||||
}
|
||||
const vector<bool> & B()
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
private: // put all data here
|
||||
// START Private data of an eoOneMax object
|
||||
std::vector<bool> b;
|
||||
// END Private data of an eoOneMax object
|
||||
};
|
||||
|
||||
#endif
|
||||
68
deprecated/eo/tutorial/Lesson5/eoOneMaxEvalFunc.h
Normal file
68
deprecated/eo/tutorial/Lesson5/eoOneMaxEvalFunc.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for evaluator in EO, a functor that computes the fitness of an EO
|
||||
==========================================================================
|
||||
*/
|
||||
|
||||
#ifndef _eoOneMaxEvalFunc_h
|
||||
#define _eoOneMaxEvalFunc_h
|
||||
|
||||
// include whatever general include you need
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
// include the base definition of eoEvalFunc
|
||||
#include "eoEvalFunc.h"
|
||||
|
||||
/**
|
||||
Always write a comment in this format before class definition
|
||||
if you want the class to be documented by Doxygen
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoOneMaxEvalFunc : public eoEvalFunc<EOT>
|
||||
{
|
||||
public:
|
||||
/// Ctor - no requirement
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoOneMaxEvalFunc()
|
||||
// eoOneMaxEvalFunc( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoOneMaxEvalFunc object
|
||||
// END Code of Ctor of an eoOneMaxEvalFunc object
|
||||
}
|
||||
|
||||
/** Actually compute the fitness
|
||||
*
|
||||
* @param EOT & _eo the EO object to evaluate
|
||||
* it should stay templatized to be usable
|
||||
* with any fitness type
|
||||
*/
|
||||
void operator()(EOT & _eo)
|
||||
{
|
||||
// test for invalid to avoid recomputing fitness of unmodified individuals
|
||||
if (_eo.invalid())
|
||||
{
|
||||
double fit; // to hold fitness value
|
||||
// START Code of computation of fitness of the eoOneMax object
|
||||
const vector<bool> & b = _eo.B();
|
||||
fit = 0;
|
||||
for (unsigned i=0; i<b.size(); i++)
|
||||
fit += (b[i]?0:1);
|
||||
// END Code of computation of fitness of the eoOneMax object
|
||||
_eo.fitness(fit);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoOneMaxEvalFunc object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoOneMaxEvalFunc object
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
62
deprecated/eo/tutorial/Lesson5/eoOneMaxInit.h
Normal file
62
deprecated/eo/tutorial/Lesson5/eoOneMaxInit.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for EO objects initialization in EO
|
||||
============================================
|
||||
*/
|
||||
|
||||
#ifndef _eoOneMaxInit_h
|
||||
#define _eoOneMaxInit_h
|
||||
|
||||
// include the base definition of eoInit
|
||||
#include <eoInit.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* There is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO (e.g. to initialize
|
||||
* atoms of an eoVector you will need an eoInit<AtomType>)
|
||||
*/
|
||||
template <class GenotypeT>
|
||||
class eoOneMaxInit: public eoInit<GenotypeT> {
|
||||
public:
|
||||
/// Ctor - no requirement
|
||||
// START eventually add or modify the anyVariable argument
|
||||
// eoOneMaxInit()
|
||||
eoOneMaxInit( unsigned _vecSize) : vecSize(_vecSize)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoOneMaxInit object
|
||||
// END Code of Ctor of an eoOneMaxInit object
|
||||
}
|
||||
|
||||
|
||||
/** initialize a genotype
|
||||
*
|
||||
* @param _genotype generally a genotype that has been default-constructed
|
||||
* whatever it contains will be lost
|
||||
*/
|
||||
void operator()(GenotypeT & _genotype)
|
||||
{
|
||||
// START Code of random initialization of an eoOneMax object
|
||||
vector<bool> b(vecSize);
|
||||
for (unsigned i=0; i<vecSize; i++)
|
||||
b[i]=rng.flip();
|
||||
_genotype.setB(b);
|
||||
// END Code of random initialization of an eoOneMax object
|
||||
_genotype.invalidate(); // IMPORTANT in case the _genotype is old
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoOneMaxInit object
|
||||
unsigned vecSize; // size of all bitstrings that this eoInit randomize
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoOneMaxInit object
|
||||
};
|
||||
|
||||
#endif
|
||||
68
deprecated/eo/tutorial/Lesson5/eoOneMaxMutation.h
Normal file
68
deprecated/eo/tutorial/Lesson5/eoOneMaxMutation.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is useful in Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for simple mutation operators
|
||||
======================================
|
||||
*/
|
||||
|
||||
#ifndef eoOneMaxMutation_H
|
||||
#define eoOneMaxMutation_H
|
||||
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* THere is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO
|
||||
*/
|
||||
template<class GenotypeT>
|
||||
class eoOneMaxMutation: public eoMonOp<GenotypeT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor - no requirement
|
||||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoOneMaxMutation()
|
||||
// eoOneMaxMutation( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoOneMaxEvalFunc object
|
||||
// END Code of Ctor of an eoOneMaxEvalFunc object
|
||||
}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "eoOneMaxMutation"; }
|
||||
|
||||
/**
|
||||
* modifies the parent
|
||||
* @param _genotype The parent genotype (will be modified)
|
||||
*/
|
||||
bool operator()(GenotypeT & _genotype)
|
||||
{
|
||||
bool isModified(true);
|
||||
// START code for mutation of the _genotype object
|
||||
|
||||
/** Requirement
|
||||
* if (_genotype has been modified)
|
||||
* isModified = true;
|
||||
* else
|
||||
* isModified = false;
|
||||
*/
|
||||
return isModified;
|
||||
// END code for mutation of the _genotype object
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoOneMaxMutation object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoOneMaxMutation object
|
||||
};
|
||||
|
||||
#endif
|
||||
70
deprecated/eo/tutorial/Lesson5/eoOneMaxQuadCrossover.h
Normal file
70
deprecated/eo/tutorial/Lesson5/eoOneMaxQuadCrossover.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for simple quadratic crossover operators
|
||||
=================================================
|
||||
|
||||
Quadratic crossover operators modify the both genotypes
|
||||
*/
|
||||
|
||||
#ifndef eoOneMaxQuadCrossover_H
|
||||
#define eoOneMaxQuadCrossover_H
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* THere is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO
|
||||
*/
|
||||
template<class GenotypeT>
|
||||
class eoOneMaxQuadCrossover: public eoQuadOp<GenotypeT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor - no requirement
|
||||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoOneMaxQuadCrossover()
|
||||
// eoOneMaxQuadCrossover( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoOneMaxEvalFunc object
|
||||
// END Code of Ctor of an eoOneMaxEvalFunc object
|
||||
}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "eoOneMaxQuadCrossover"; }
|
||||
|
||||
/**
|
||||
* eoQuad crossover - modifies both parents
|
||||
* @param _genotype1 The first parent
|
||||
* @param _genotype2 The second parent
|
||||
*/
|
||||
bool operator()(GenotypeT& _genotype1, GenotypeT & _genotype2)
|
||||
{
|
||||
bool oneAtLeastIsModified(true);
|
||||
// START code for crossover of _genotype1 and _genotype2 objects
|
||||
|
||||
/** Requirement
|
||||
* if (at least one genotype has been modified) // no way to distinguish
|
||||
* oneAtLeastIsModified = true;
|
||||
* else
|
||||
* oneAtLeastIsModified = false;
|
||||
*/
|
||||
return oneAtLeastIsModified;
|
||||
// END code for crossover of _genotype1 and _genotype2 objects
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoOneMaxQuadCrossover object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoOneMaxQuadCrossover object
|
||||
};
|
||||
|
||||
#endif
|
||||
128
deprecated/eo/tutorial/Lesson5/make_OneMax.cpp
Normal file
128
deprecated/eo/tutorial/Lesson5/make_OneMax.cpp
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
|
||||
This is the template file that llows separate compilation of
|
||||
everything that is representation independant (evolution engine and
|
||||
general output) for an Evolutionary Algorithm with scalar fitness.
|
||||
|
||||
It includes of course the definition of the genotype (eoOneMax.h) and
|
||||
is written like the make_xxx.cpp files in dirs src/ga (for bitstrings)
|
||||
and src/es (for real vectors).
|
||||
|
||||
*/
|
||||
|
||||
// Miscilaneous include and declaration
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// eo general include
|
||||
#include "eo"
|
||||
// the real bounds (not yet in general eo include)
|
||||
#include "utils/eoRealVectorBounds.h"
|
||||
|
||||
// include here whatever specific files for your representation
|
||||
// Basically, this should include at least the following
|
||||
|
||||
/** definition of representation:
|
||||
* class eoOneMax MUST derive from EO<FitT> for some fitness
|
||||
*/
|
||||
#include "eoOneMax.h"
|
||||
|
||||
// create an initializer: this is NOT representation-independent
|
||||
// and will be done in the main file
|
||||
// However, should you decide to freeze that part, you could use the
|
||||
// following (and remove it from the main file, of course!!!)
|
||||
//------------------------------------------------------------------
|
||||
// #include "make_genotype_OneMax.h"
|
||||
// eoInit<eoOneMax<double>> & make_genotype(eoParser& _parser, eoState&_state, eoOneMax<double> _eo)
|
||||
// {
|
||||
// return do_make_genotype(_parser, _state, _eo);
|
||||
// }
|
||||
|
||||
// eoInit<eoOneMax<eoMinimizingFitness>> & make_genotype(eoParser& _parser, eoState&_state, eoOneMax<eoMinimizingFitness> _eo)
|
||||
// {
|
||||
// return do_make_genotype(_parser, _state, _eo);
|
||||
// }
|
||||
|
||||
// same thing for the variation operaotrs
|
||||
//---------------------------------------
|
||||
// #include "make_op_OneMax.h"
|
||||
// eoGenOp<eoOneMax<double>>& make_op(eoParser& _parser, eoState& _state, eoInit<eoOneMax<double>>& _init)
|
||||
// {
|
||||
// return do_make_op(_parser, _state, _init);
|
||||
// }
|
||||
|
||||
// eoGenOp<eoOneMax<eoMinimizingFitness>>& make_op(eoParser& _parser, eoState& _state, eoInit<eoOneMax<eoMinimizingFitness>>& _init)
|
||||
// {
|
||||
// return do_make_op(_parser, _state, _init);
|
||||
// }
|
||||
|
||||
// The following modules use ***representation independent*** routines
|
||||
|
||||
// how to initialize the population
|
||||
// it IS representation independent if an eoInit is given
|
||||
#include <do/make_pop.h>
|
||||
eoPop<eoOneMax<double> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoOneMax<double> > & _init)
|
||||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
eoPop<eoOneMax<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoOneMax<eoMinimizingFitness> > & _init)
|
||||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// the stopping criterion
|
||||
#include <do/make_continue.h>
|
||||
eoContinue<eoOneMax<double> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoOneMax<double> > & _eval)
|
||||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
eoContinue<eoOneMax<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoOneMax<eoMinimizingFitness> > & _eval)
|
||||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
// outputs (stats, population dumps, ...)
|
||||
#include <do/make_checkpoint.h>
|
||||
eoCheckPoint<eoOneMax<double> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoOneMax<double> >& _eval, eoContinue<eoOneMax<double> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
eoCheckPoint<eoOneMax<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoOneMax<eoMinimizingFitness> >& _eval, eoContinue<eoOneMax<eoMinimizingFitness> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
// evolution engine (selection and replacement)
|
||||
#include <do/make_algo_scalar.h>
|
||||
eoAlgo<eoOneMax<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoOneMax<double> >& _eval, eoContinue<eoOneMax<double> >& _continue, eoGenOp<eoOneMax<double> >& _op)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
eoAlgo<eoOneMax<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoOneMax<eoMinimizingFitness> >& _eval, eoContinue<eoOneMax<eoMinimizingFitness> >& _continue, eoGenOp<eoOneMax<eoMinimizingFitness> >& _op)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
// no template for that one
|
||||
#include <do/make_run.h>
|
||||
void run_ea(eoAlgo<eoOneMax<double> >& _ga, eoPop<eoOneMax<double> >& _pop)
|
||||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
void run_ea(eoAlgo<eoOneMax<eoMinimizingFitness> >& _ga, eoPop<eoOneMax<eoMinimizingFitness> >& _pop)
|
||||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
75
deprecated/eo/tutorial/Lesson5/make_genotype_OneMax.h
Normal file
75
deprecated/eo/tutorial/Lesson5/make_genotype_OneMax.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// make_genotype.h
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _make_genotype_h
|
||||
#define _make_genotype_h
|
||||
|
||||
#include <eoOneMax.h>
|
||||
#include <eoOneMaxInit.h>
|
||||
// also need the parser and param includes
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoState.h>
|
||||
|
||||
|
||||
/*
|
||||
* This fuction does the create an eoInit<eoOneMax>
|
||||
*
|
||||
* It could be here tempatized only on the fitness, as it can be used
|
||||
* to evolve structures with any fitness.
|
||||
* However, for consistency reasons, it was finally chosen, as in
|
||||
* the rest of EO, to templatize by the full EOT, as this eventually
|
||||
* allows to choose the type of genotype at run time (see in es dir)
|
||||
*
|
||||
* It returns an eoInit<EOT> that can later be used to initialize
|
||||
* the population (see make_pop.h).
|
||||
*
|
||||
* It uses a parser (to get user parameters) and a state (to store the memory)
|
||||
* the last argument is to disambiguate the call upon different instanciations.
|
||||
*
|
||||
* WARNING: that last argument will generally be the result of calling
|
||||
* the default ctor of EOT, resulting in most cases in an EOT
|
||||
* that is ***not properly initialized***
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
eoInit<EOT> & do_make_genotype(eoParameterLoader& _parser, eoState& _state, EOT)
|
||||
{
|
||||
// read any useful parameter here from the parser
|
||||
// the param itself will belong to the parser (as far as memory is concerned)
|
||||
|
||||
// paramType & param = _parser.createParam(deafultValue, "Keyword", "Comment to appear in help and status", 'c',"Section of status file").value();
|
||||
|
||||
unsigned vecSize = _parser.createParam(unsigned(8), "VecSize", "Size of the bitstrings", 'v',"Representation").value();
|
||||
|
||||
// Then built the initializer - a pointer, stored in the eoState
|
||||
eoInit<EOT>* init = new eoOneMaxInit<EOT>(vecSize);
|
||||
// store in state
|
||||
_state.storeFunctor(init);
|
||||
// and return a reference
|
||||
return *init;
|
||||
}
|
||||
|
||||
#endif
|
||||
210
deprecated/eo/tutorial/Lesson5/make_op_OneMax.h
Normal file
210
deprecated/eo/tutorial/Lesson5/make_op_OneMax.h
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// make_op_OneMax.h
|
||||
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2001
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _make_op_OneMax_h
|
||||
#define _make_op_OneMax_h
|
||||
|
||||
// the operators
|
||||
#include <eoOp.h>
|
||||
#include <eoGenOp.h>
|
||||
#include <eoCloneOps.h>
|
||||
#include <eoOpContainer.h>
|
||||
// combinations of simple eoOps (eoMonOp and eoQuadOp)
|
||||
#include <eoProportionalCombinedOp.h>
|
||||
|
||||
/** definition of mutation:
|
||||
* class eoOneMaxMonop MUST derive from eoMonOp<eoOneMax>
|
||||
*/
|
||||
#include "eoOneMaxMutation.h"
|
||||
|
||||
/** definition of crossover (either as eoBinOp (2->1) or eoQuadOp (2->2):
|
||||
* class eoOneMaxBinCrossover MUST derive from eoBinOp<eoOneMax>
|
||||
* OR
|
||||
* class eoOneMaxQuadCrossover MUST derive from eoQuadOp<eoOneMax>
|
||||
*/
|
||||
// #include "eoOneMaxBinOp.h"
|
||||
// OR
|
||||
#include "eoOneMaxQuadCrossover.h"
|
||||
|
||||
// also need the parser and state includes
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoState.h>
|
||||
|
||||
|
||||
/////////////////// variation operators ///////////////
|
||||
// canonical (crossover + mutation) only at the moment //
|
||||
|
||||
/*
|
||||
* This function builds the operators that will be applied to the eoOneMax
|
||||
*
|
||||
* It uses a parser (to get user parameters), a state (to store the memory)
|
||||
* the last parameter is an eoInit: if some operator needs some info
|
||||
* about the genotypes, the init has it all (e.g. bounds, ...)
|
||||
* Simply do
|
||||
* EOT myEO;
|
||||
* _init(myEO);
|
||||
* and myEO is then an ACTUAL object
|
||||
*
|
||||
* As usual, the template is the complete EOT even though only the fitness
|
||||
* is actually templatized here: the following only applies to eoOneMax
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EOT>& _init)
|
||||
{
|
||||
// this is a temporary version, while Maarten codes the full tree-structured
|
||||
// general operator input
|
||||
// BTW we must leave that simple version available somehow, as it is the one
|
||||
// that 90% people use!
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Variation operators
|
||||
////////////////////////////
|
||||
// read crossover and mutations, combine each in a proportional Op
|
||||
// and create the eoGenOp that calls crossover at rate pCross
|
||||
// then mutation with rate pMut
|
||||
|
||||
// the crossovers
|
||||
/////////////////
|
||||
|
||||
// here we can have eoQuadOp (2->2) only - no time for the eoBinOp case
|
||||
|
||||
// you can have more than one - combined in a proportional way
|
||||
|
||||
// first, define the crossover objects and read their rates from the parser
|
||||
|
||||
// A first crossover
|
||||
eoQuadOp<Indi> *cross = new eoOneMaxQuadCrossover<Indi> /* (varType _anyVariable) */;
|
||||
// store in the state
|
||||
_state.storeFunctor(cross);
|
||||
|
||||
// read its relative rate in the combination
|
||||
double cross1Rate = _parser.createParam(1.0, "cross1Rate", "Relative rate for crossover 1", '1', "Variation Operators").value();
|
||||
|
||||
// and create the combined operator with this one
|
||||
eoPropCombinedQuadOp<Indi> *propXover =
|
||||
new eoPropCombinedQuadOp<Indi>(*cross, cross1Rate);
|
||||
// and of course stor it in the state
|
||||
_state.storeFunctor(propXover);
|
||||
|
||||
|
||||
// Optional: A second(and third, and ...) crossover
|
||||
// of course you must create the corresponding classes
|
||||
// and all ***MUST*** derive from eoQuadOp<Indi>
|
||||
|
||||
/* Uncomment if necessary - and replicate as many time as you need
|
||||
cross = new eoOneMaxSecondCrossover<Indi>(varType _anyVariable);
|
||||
_state.storeFunctor(cross);
|
||||
double cross2Rate = _parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value();
|
||||
propXover.add(*cross, cross2Rate);
|
||||
*/
|
||||
// if you want some gentle output, the last one shoudl be like
|
||||
// propXover.add(*cross, crossXXXRate, true);
|
||||
|
||||
|
||||
// the mutation: same story
|
||||
////////////////
|
||||
// you can have more than one - combined in a proportional way
|
||||
|
||||
// for each mutation,
|
||||
// - define the mutator object
|
||||
// - read its rate from the parser
|
||||
// - add it to the proportional combination
|
||||
|
||||
// a first mutation
|
||||
eoMonOp<Indi> *mut = new eoOneMaxMutation<Indi>/* (varType _anyVariable) */;
|
||||
_state.storeFunctor(mut);
|
||||
// its relative rate in the combination
|
||||
double mut1Rate = _parser.createParam(1.0, "mut1Rate", "Relative rate for mutation 1", '1', "Variation Operators").value();
|
||||
// and the creation of the combined operator with this one
|
||||
eoPropCombinedMonOp<Indi> *propMutation = new eoPropCombinedMonOp<Indi>(*mut, mut1Rate);
|
||||
_state.storeFunctor(propMutation);
|
||||
|
||||
// Optional: A second(and third, and ...) mutation with their rates
|
||||
// of course you must create the corresponding classes
|
||||
// and all ***MUST*** derive from eoMonOp<Indi>
|
||||
|
||||
/* Uncomment if necessary - and replicate as many time as you need
|
||||
mut = new eoOneMaxSecondMutation<Indi>(varType _anyVariable);
|
||||
_state.storeFunctor(mut);
|
||||
double mut2Rate = _parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
|
||||
propMutation.add(*mut, mut2Rate);
|
||||
*/
|
||||
// if you want some gentle output, the last one shoudl be like
|
||||
// propMutation.add(*mut, mutXXXRate, true);
|
||||
|
||||
// end of crossover and mutation definitions
|
||||
////////////////////////////////////////////
|
||||
|
||||
// END Modify definitions of objects by eventually add parameters
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
|
||||
// from now on, you do not need to modify anything
|
||||
// though you CAN add things to the checkpointing (see tutorial)
|
||||
|
||||
// now build the eoGenOp:
|
||||
// to simulate SGA (crossover with proba pCross + mutation with proba pMut
|
||||
// we must construct
|
||||
// a sequential combination of
|
||||
// with proba 1, a proportional combination of
|
||||
// a QuadCopy and our crossover
|
||||
// with proba pMut, our mutation
|
||||
|
||||
// but of course you're free to use any smart combination you could think of
|
||||
// especially, if you have to use eoBinOp rather than eoQuad Op youùll have
|
||||
// to modify that part
|
||||
|
||||
// First read the individual level parameters
|
||||
eoValueParam<double>& pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
|
||||
throw runtime_error("Invalid pCross");
|
||||
|
||||
eoValueParam<double>& pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
|
||||
throw runtime_error("Invalid pMut");
|
||||
|
||||
|
||||
// the crossover - with probability pCross
|
||||
eoProportionalOp<Indi> * propOp = new eoProportionalOp<Indi> ;
|
||||
_state.storeFunctor(propOp);
|
||||
eoQuadOp<Indi> *ptQuad = new eoQuadCloneOp<Indi>;
|
||||
_state.storeFunctor(ptQuad);
|
||||
propOp->add(*propXover, pCrossParam.value()); // crossover, with proba pcross
|
||||
propOp->add(*ptQuad, 1-pCrossParam.value()); // nothing, with proba 1-pcross
|
||||
|
||||
// now the sequential
|
||||
eoSequentialOp<Indi> *op = new eoSequentialOp<Indi>;
|
||||
_state.storeFunctor(op);
|
||||
op->add(*propOp, 1.0); // always do combined crossover
|
||||
op->add(*propMutation, pMutParam.value()); // then mutation, with proba pmut
|
||||
|
||||
// that's it - return a reference
|
||||
return *op;
|
||||
}
|
||||
#endif
|
||||
182
deprecated/eo/tutorial/Lesson6/BinaryPSO.cpp
Normal file
182
deprecated/eo/tutorial/Lesson6/BinaryPSO.cpp
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// BinaryPSO.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// An instance of a VERY simple Real-coded binary Particle Swarm Optimization Algorithm
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <eo>
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoMinimizingFitness FitT;
|
||||
typedef eoBitParticle < FitT > Particle;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// EVALFUNC
|
||||
//-----------------------------------------------------------------------------
|
||||
// Just a simple function that takes binary value of a chromosome and sets
|
||||
// the fitness
|
||||
double binary_value (const Particle & _particle)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _particle.size(); i++)
|
||||
sum +=_particle[i];
|
||||
return (sum);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
// all parameters are hard-coded!
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
|
||||
const unsigned int MAX_GEN=500;
|
||||
const unsigned int VEC_SIZE = 10;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 3;
|
||||
|
||||
const double VELOCITY_INIT_MIN= -1;
|
||||
const double VELOCITY_INIT_MAX= 1;
|
||||
|
||||
const double VELOCITY_MIN= -1.5;
|
||||
const double VELOCITY_MAX= 1.5;
|
||||
|
||||
const double INERTIA= 1;
|
||||
const double LEARNING_FACTOR1= 1.7;
|
||||
const double LEARNING_FACTOR2= 2.3;
|
||||
|
||||
|
||||
//////////////////////////
|
||||
// RANDOM SEED
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
||||
/// SWARM
|
||||
// population <=> swarm
|
||||
eoPop<Particle> pop;
|
||||
|
||||
/// EVALUATION
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
eoEvalFuncPtr<Particle, double, const Particle& > eval( binary_value );
|
||||
|
||||
|
||||
///////////////
|
||||
/// TOPOLOGY
|
||||
//////////////
|
||||
// ring topology
|
||||
eoRingTopology<Particle> topology(NEIGHBORHOOD_SIZE);
|
||||
|
||||
|
||||
/////////////////////
|
||||
// INITIALIZATION
|
||||
////////////////////
|
||||
// position initialization
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength < Particle > random (VEC_SIZE, uGen);
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
// velocities initialization component
|
||||
eoUniformGenerator < double >sGen (VELOCITY_INIT_MIN, VELOCITY_INIT_MAX);
|
||||
eoVelocityInitFixedLength < Particle > veloRandom (VEC_SIZE, sGen);
|
||||
|
||||
// first best position initialization component
|
||||
eoFirstIsBestInit < Particle > localInit;
|
||||
|
||||
// Create an eoInitialier that:
|
||||
// - performs a first evaluation of the particles
|
||||
// - initializes the velocities
|
||||
// - the first best positions of each particle
|
||||
// - setups the topology
|
||||
eoInitializer <Particle> fullInit(eval,veloRandom,localInit,topology,pop);
|
||||
|
||||
// Full initialization here to be able to print the initial population
|
||||
// Else: give the "init" component in the eoEasyPSO constructor
|
||||
fullInit();
|
||||
|
||||
/////////////
|
||||
// OUTPUT
|
||||
////////////
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
|
||||
// Print (sorted) the initial population (raw printout)
|
||||
cout << "INITIAL POPULATION:" << endl;
|
||||
for (unsigned i = 0; i < pop.size(); ++i)
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
|
||||
|
||||
///////////////
|
||||
/// VELOCITY
|
||||
//////////////
|
||||
// Create the bounds for the velocity not go to far away
|
||||
eoRealVectorBounds bnds(VEC_SIZE,VELOCITY_MIN,VELOCITY_MAX);
|
||||
|
||||
// the velocity itself that needs the topology and a few constants
|
||||
eoStandardVelocity <Particle> velocity (topology,INERTIA,LEARNING_FACTOR1,LEARNING_FACTOR2,bnds);
|
||||
|
||||
|
||||
///////////////
|
||||
/// FLIGHT
|
||||
//////////////
|
||||
// Binary flight based on sigmoid function
|
||||
eoSigBinaryFlight <Particle> flight;
|
||||
|
||||
|
||||
////////////////////////
|
||||
/// STOPPING CRITERIA
|
||||
///////////////////////
|
||||
// the algo will run for MAX_GEN iterations
|
||||
eoGenContinue <Particle> genCont (MAX_GEN);
|
||||
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
// standard PSO requires
|
||||
// stopping criteria, evaluation,velocity, flight
|
||||
|
||||
eoEasyPSO<Particle> pso(genCont, eval, velocity, flight);
|
||||
|
||||
// Apply the algo to the swarm - that's it!
|
||||
pso(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL POPULATION:" << endl;
|
||||
for (unsigned i = 0; i < pop.size(); ++i)
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
51
deprecated/eo/tutorial/Lesson6/CMakeLists.txt
Normal file
51
deprecated/eo/tutorial/Lesson6/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(BinaryPSO BinaryPSO.cpp)
|
||||
ADD_EXECUTABLE(RealPSO RealPSO.cpp)
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal
|
||||
######################################################################################
|
||||
|
||||
SET(BINARYPSO_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(BinaryPSO PROPERTIES VERSION "${BINARYPSO_VERSION}")
|
||||
|
||||
SET(REALPSO_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(RealPSO PROPERTIES VERSION "${REALPSO_VERSION}")
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies for the targets
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(BinaryPSO eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(RealPSO eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
### 6) Configure project installation paths
|
||||
######################################################################################
|
||||
|
||||
INSTALL(TARGETS BinaryPSO RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson6 COMPONENT examples)
|
||||
INSTALL(TARGETS RealPSO RUNTIME DESTINATION local/share${INSTALL_SUB_DIR}/eo/examples/Lesson6 COMPONENT examples)
|
||||
|
||||
######################################################################################
|
||||
31
deprecated/eo/tutorial/Lesson6/Makefile.simple
Normal file
31
deprecated/eo/tutorial/Lesson6/Makefile.simple
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
### This Makefile is part of the tutorial of the EO library
|
||||
# Unlike other Makefiles in EO, it is not using the automake/autoconf
|
||||
# so that it stays easy to understant (you are in the tutorial, remember!)
|
||||
# MS, Oct. 2002
|
||||
|
||||
# if you use this Makefile as a starting point for another application
|
||||
# you might need to modify the following
|
||||
DIR_EO = ../../src
|
||||
|
||||
.SUFFIXES: .cpp
|
||||
|
||||
# Warning: $(CXX) in Linux (RedHat and Mandrake at least) is g++
|
||||
# However, if you are using this Makefile within xemacs,
|
||||
# and have problems with the interpretation of the output (and its colors)
|
||||
# then you should use c++ instead (make CXX=c++ will do)
|
||||
|
||||
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -pg -o $@ $*.cpp
|
||||
#$(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
.cpp.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c -pg $*.cpp
|
||||
|
||||
PSO = BinaryPSO RealPSO
|
||||
|
||||
ALL = $(PSO)
|
||||
|
||||
lesson6 : $(PSO)
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
clean :
|
||||
@/bin/rm $(ALL) *.o *.sav *.xg *.status *~
|
||||
183
deprecated/eo/tutorial/Lesson6/RealPSO.cpp
Normal file
183
deprecated/eo/tutorial/Lesson6/RealPSO.cpp
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// RealPSO.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// An instance of a VERY simple Real-coded Particle Swarm Optimization Algorithm
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <eo>
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoMinimizingFitness FitT;
|
||||
typedef eoRealParticle < FitT > Particle;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// EVALFUNC
|
||||
//-----------------------------------------------------------------------------
|
||||
// a simple fitness function that computes the euclidian norm of a real vector
|
||||
FitT real_value (const Particle & _particle)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _particle.size(); i++)
|
||||
sum += pow(_particle[i],2);
|
||||
return (sqrt(sum));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// PARAMETRES
|
||||
// all parameters are hard-coded!
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
|
||||
const unsigned int MAX_GEN=100;
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||
|
||||
const double POS_INIT_MIN= -2;
|
||||
const double POS_INIT_MAX= 2;
|
||||
|
||||
const double VELOCITY_INIT_MIN= -1;
|
||||
const double VELOCITY_INIT_MAX= 1;
|
||||
|
||||
const double VELOCITY_MIN= -1.5;
|
||||
const double VELOCITY_MAX= 1.5;
|
||||
|
||||
const double INERTIA= 1;
|
||||
const double LEARNING_FACTOR1= 1.7;
|
||||
const double LEARNING_FACTOR2= 2.3;
|
||||
|
||||
//////////////////////////
|
||||
// RANDOM SEED
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
||||
/// SWARM
|
||||
// population <=> swarm
|
||||
eoPop<Particle> pop;
|
||||
|
||||
/// EVALUATION
|
||||
// Evaluation: from a plain C++ fn to an EvalFunc Object
|
||||
eoEvalFuncPtr<Particle, FitT, const Particle& > eval( real_value );
|
||||
|
||||
|
||||
///////////////
|
||||
/// TOPOLOGY
|
||||
//////////////
|
||||
// linear topology
|
||||
eoLinearTopology<Particle> topology(NEIGHBORHOOD_SIZE);
|
||||
|
||||
|
||||
/////////////////////
|
||||
// INITIALIZATION
|
||||
////////////////////
|
||||
// position initialization
|
||||
eoUniformGenerator < double >uGen (POS_INIT_MIN, POS_INIT_MAX);
|
||||
eoInitFixedLength < Particle > random (VEC_SIZE, uGen);
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
// velocities initialization component
|
||||
eoUniformGenerator < double >sGen (VELOCITY_INIT_MIN, VELOCITY_INIT_MAX);
|
||||
eoVelocityInitFixedLength < Particle > veloRandom (VEC_SIZE, sGen);
|
||||
|
||||
// first best position initialization component
|
||||
eoFirstIsBestInit < Particle > localInit;
|
||||
|
||||
// Create an eoInitialier that:
|
||||
// - performs a first evaluation of the particles
|
||||
// - initializes the velocities
|
||||
// - the first best positions of each particle
|
||||
// - setups the topology
|
||||
eoInitializer <Particle> fullInit(eval,veloRandom,localInit,topology,pop);
|
||||
|
||||
// Full initialization here to be able to print the initial population
|
||||
// Else: give the "init" component in the eoEasyPSO constructor
|
||||
fullInit();
|
||||
|
||||
/////////////
|
||||
// OUTPUT
|
||||
////////////
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
|
||||
// Print (sorted) the initial population (raw printout)
|
||||
cout << "INITIAL POPULATION:" << endl;
|
||||
for (unsigned i = 0; i < pop.size(); ++i)
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
|
||||
|
||||
///////////////
|
||||
/// VELOCITY
|
||||
//////////////
|
||||
// Create the bounds for the velocity not go to far away
|
||||
eoRealVectorBounds bnds(VEC_SIZE,VELOCITY_MIN,VELOCITY_MAX);
|
||||
|
||||
// the velocity itself that needs the topology and a few constants
|
||||
eoStandardVelocity <Particle> velocity (topology,INERTIA,LEARNING_FACTOR1,LEARNING_FACTOR2,bnds);
|
||||
|
||||
|
||||
///////////////
|
||||
/// FLIGHT
|
||||
//////////////
|
||||
// flight
|
||||
eoStandardFlight <Particle> flight;
|
||||
|
||||
|
||||
////////////////////////
|
||||
/// STOPPING CRITERIA
|
||||
///////////////////////
|
||||
// the algo will run for MAX_GEN iterations
|
||||
eoGenContinue <Particle> genCont (MAX_GEN);
|
||||
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
// standard PSO requires
|
||||
// stopping criteria, evaluation,velocity, flight
|
||||
|
||||
eoEasyPSO<Particle> pso(genCont, eval, velocity, flight);
|
||||
|
||||
// Apply the algo to the swarm - that's it!
|
||||
pso(pop);
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL POPULATION:" << endl;
|
||||
for (unsigned i = 0; i < pop.size(); ++i)
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
32
deprecated/eo/tutorial/Makefile.simple
Normal file
32
deprecated/eo/tutorial/Makefile.simple
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
SUBDIRS = Lesson1 Lesson2 Lesson3 Lesson4 Lesson5 Lesson6
|
||||
|
||||
all:
|
||||
for i in $(SUBDIRS); do cd $$i && $(MAKE) all; cd ..; done
|
||||
|
||||
lesson1 :
|
||||
cd Lesson1; make
|
||||
|
||||
lesson2 :
|
||||
cd Lesson2; make
|
||||
|
||||
lesson3 :
|
||||
cd Lesson3; make
|
||||
|
||||
lesson4 :
|
||||
cd Lesson4; make
|
||||
|
||||
lesson5 :
|
||||
cd Lesson5; make
|
||||
|
||||
lesson6 :
|
||||
cd Lesson6; make
|
||||
|
||||
#empty dist and distdir to let top-level 'make' do its job
|
||||
dist :
|
||||
|
||||
distdir :
|
||||
|
||||
check :
|
||||
|
||||
clean:
|
||||
for i in $(SUBDIRS); do cd $$i && $(MAKE) clean; cd ..; done
|
||||
12
deprecated/eo/tutorial/README
Normal file
12
deprecated/eo/tutorial/README
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
Eo Tutorial - corresponding to EO version 0.9.1+
|
||||
|
||||
To start the tutorial, read index.html in your favorite browser.
|
||||
|
||||
Many things are missing, including many solutions for the exercises,
|
||||
the introduction to EC and most of the Component-based pages.
|
||||
More important, all examples of this tutorial have only been tested
|
||||
on a Linux computer, and the Makefile will not work with MS-Windows
|
||||
systems. Any help is welcome!
|
||||
|
||||
Be patient ...
|
||||
evoMarc
|
||||
45
deprecated/eo/tutorial/Templates/CMakeLists.txt.src-tmpl
Executable file
45
deprecated/eo/tutorial/Templates/CMakeLists.txt.src-tmpl
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${MyStruct_SOURCE_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/do)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(MyStructEA MyStructEA.cpp)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 4) Link the librairies for the targets
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(MyStructEA eo eoutils ga es)
|
||||
|
||||
######################################################################################
|
||||
40
deprecated/eo/tutorial/Templates/CMakeLists.txt.top-tmpl
Executable file
40
deprecated/eo/tutorial/Templates/CMakeLists.txt.top-tmpl
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
######################################################################################
|
||||
### 1) Main project config
|
||||
######################################################################################
|
||||
|
||||
# set the project name
|
||||
PROJECT(MyStructEA)
|
||||
|
||||
# set a language for the entire project.
|
||||
ENABLE_LANGUAGE(CXX)
|
||||
|
||||
#####################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) We need to know where EO is installed
|
||||
######################################################################################
|
||||
|
||||
IF(NOT EO_SOURCE_DIR)
|
||||
SET( EO_SOURCE_DIR
|
||||
EO_SRC_DIR CACHE STRING
|
||||
"EO source directory"
|
||||
FORCE)
|
||||
ENDIF(NOT EO_SOURCE_DIR)
|
||||
|
||||
IF(NOT EO_BINARY_DIR)
|
||||
SET( EO_BINARY_DIR
|
||||
EO_BIN_DIR CACHE STRING
|
||||
"EO binary directory"
|
||||
FORCE)
|
||||
ENDIF(NOT EO_BINARY_DIR)
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Where must cmake go now ?
|
||||
######################################################################################
|
||||
|
||||
SUBDIRS(src)
|
||||
|
||||
######################################################################################
|
||||
48
deprecated/eo/tutorial/Templates/ChangeLog
Normal file
48
deprecated/eo/tutorial/Templates/ChangeLog
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
2007-02-22 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* mutation.tmpl, quadCrossover.tmpl, stat.tmpl: Initialize
|
||||
formerly uninitialized variables.
|
||||
|
||||
* README.tmpl: Hint to regular Templates/README for details.
|
||||
|
||||
* README: Add documentation for adding new source-files.
|
||||
|
||||
* Makefile.am.src-tmpl (noinst_HEADERS): Add
|
||||
(MyStruct_SOURCES): Move header files from here to the new
|
||||
noinst_HEADERS variable.
|
||||
|
||||
2007-01-16 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* README: Add instructions for bash.
|
||||
|
||||
2007-01-14 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* createEOproject.sh: Set TargetDir to /tmp/<name>. This is a workaround
|
||||
for automake finding the scripts of eo itself if we run it in a embedded
|
||||
subdirectory.
|
||||
(COPYING, INSTALL): create.
|
||||
|
||||
* README: State more explicitly what a "complete installation" means.
|
||||
Give build-instructions for moved directories.
|
||||
|
||||
2006-12-16 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* Makefile.am (EXTRA_DIST): Distribute exactly the necessary files
|
||||
|
||||
* EO.tpl, MyStructEA.cpp, MyStructSEA.cpp, make_MyStruct.cpp: Use
|
||||
correct names for includes.
|
||||
|
||||
* README.manual: This is a copy of the old README.
|
||||
|
||||
* README: Describe the new way and setup of creating a new EO project.
|
||||
|
||||
* createEOproject.sh, Makefile.am.src-tmpl, Makefile.am.top-tmpl:
|
||||
* configure.ac.tmpl: New files to create a standalone EO project from
|
||||
templates.
|
||||
|
||||
|
||||
* Local Variables:
|
||||
* coding: iso-8859-1
|
||||
* mode: flyspell
|
||||
* fill-column: 80
|
||||
* End:
|
||||
938
deprecated/eo/tutorial/Templates/EO.tpl
Normal file
938
deprecated/eo/tutorial/Templates/EO.tpl
Normal file
|
|
@ -0,0 +1,938 @@
|
|||
\TEMPLATE_START// -*- mode: c++; c-indent-level: 2; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
//
|
||||
// (The above line is useful in Emacs-like editors)
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
// EASEA.cpp
|
||||
//
|
||||
// C++ file generated by AESAE-EO v0.7
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
//
|
||||
// Main file for creating a new representation in EO
|
||||
// =================================================
|
||||
//
|
||||
// This main file includes all other files that have been generated by the
|
||||
// script create.sh, so it is the only file to compile.
|
||||
//
|
||||
// In case you want to build up a separate library for your new Evolving Object,
|
||||
// you'll need some work - follow what's done in the src/ga dir, used in the
|
||||
// main file BitEA in tutorial/Lesson4 dir.
|
||||
// Or you can wait until we do it :-)
|
||||
|
||||
// Miscellany includes and declarations
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// eo general include
|
||||
#include "eo"
|
||||
// real bounds (not yet in general eo include)
|
||||
#include "utils/eoRealVectorBounds.h"
|
||||
|
||||
unsigned *pCurrentGeneration;
|
||||
unsigned *pEZ_NB_GEN;
|
||||
double EZ_MUT_PROB, EZ_XOVER_PROB, EZ_REPL_PERC=0.0;
|
||||
int EZ_NB_GEN, EZ_POP_SIZE;
|
||||
unsigned long EZ_NB_EVALUATIONS=0L;
|
||||
|
||||
inline int random(int b1=0, int b2=1){
|
||||
return rng.random(b2-b1)+b1;
|
||||
}
|
||||
inline double random(double b1=0, double b2=1){
|
||||
return rng.uniform(b2-b1)+b1;
|
||||
}
|
||||
inline float random(float b1=0, float b2=1){
|
||||
return rng.uniform(b2-b1)+b1;
|
||||
}
|
||||
|
||||
\ANALYSE_PARAMETERS
|
||||
\INSERT_USER_DECLARATIONS
|
||||
\INSERT_INITIALISATION_FUNCTION
|
||||
|
||||
// include here whatever specific files for your representation
|
||||
// Basically, this should include at least the following
|
||||
|
||||
/** definition of representation:
|
||||
* class EASEAGenome MUST derive from EO<FitT> for some fitness
|
||||
*/
|
||||
#include "EASEAGenome.h"
|
||||
|
||||
// GENOTYPE EASEAGenome ***MUST*** be templatized over the fitness
|
||||
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
// START fitness type: double or eoMaximizingFitness if you are maximizing
|
||||
// eoMinimizingFitness if you are minimizing
|
||||
typedef \MINIMAXI MyFitT ; // type of fitness
|
||||
// END fitness type
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
|
||||
// Then define your EO objects using that fitness type
|
||||
typedef EASEAGenome<MyFitT> Indi; // ***MUST*** derive from EO
|
||||
|
||||
\INSERT_USER_FUNCTIONS
|
||||
|
||||
/** definition of evaluation:
|
||||
* class EASEAEvalFunc MUST derive from eoEvalFunc<EASEAGenome>
|
||||
* and should test for validity before doing any computation
|
||||
* see tutorial/Templates/evalFunc.tmpl
|
||||
*/
|
||||
#include "EASEAEvalFunc.h"
|
||||
|
||||
/** definition of initialization:
|
||||
* class EASEAGenomeInit MUST derive from eoInit<EASEAGenome>
|
||||
*/
|
||||
#include "EASEAInit.h"
|
||||
|
||||
/** include all files defining variation operator classes
|
||||
*/
|
||||
#include "EASEAMutation.h"
|
||||
#include "EASEAQuadCrossover.h"
|
||||
|
||||
// Use existing modules to define representation independent routines
|
||||
// These are parser-based definitions of objects
|
||||
|
||||
// how to initialize the population
|
||||
// it IS representation independent if an eoInit is given
|
||||
#include <make_pop.h>
|
||||
eoPop<Indi >& make_pop(eoParser& _parser, eoState& _state, eoInit<Indi> & _init){
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// the stopping criterion
|
||||
#include "make_continue.h"
|
||||
eoContinue<Indi>& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval){
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
// outputs (stats, population dumps, ...)
|
||||
#include <make_checkpoint.h>
|
||||
eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& _continue) {
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
// evolution engine (selection and replacement)
|
||||
#include <make_algo_easea.h>
|
||||
eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& _continue, eoGenOp<Indi>& _op){
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
// no template for that one
|
||||
#include <make_run.h>
|
||||
// the instanciating fitnesses
|
||||
#include <eoScalarFitness.h>
|
||||
void run_ea(eoAlgo<Indi>& _ga, eoPop<Indi>& _pop){
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
// checks for help demand, and writes the status file
|
||||
// and make_help; in libutils
|
||||
void make_help(eoParser & _parser);
|
||||
|
||||
// now use all of the above, + representation dependent things
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
try {
|
||||
\INSERT_INIT_FCT_CALL
|
||||
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
// The fitness
|
||||
//////////////
|
||||
EASEAEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
|
||||
// turn that object into an evaluation counter
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// a genotype initializer
|
||||
EASEAInit<Indi> init;
|
||||
// or, if you need some parameters, you might as well
|
||||
// - write a constructor of the eoMyStructInit that uses a parser
|
||||
// - call it from here:
|
||||
// eoEASEAInit<Indi> init(parser);
|
||||
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
// here, a simple example with only 1 crossover (2->2, a QuadOp) and
|
||||
// one mutation, is given.
|
||||
// Hints to have choice among multiple crossovers and mutations are given
|
||||
|
||||
// A (first) crossover (possibly use the parser in its Ctor)
|
||||
EASEAQuadCrossover<Indi> cross /* (eoParser parser) */;
|
||||
|
||||
// IF MORE THAN ONE:
|
||||
|
||||
// read its relative rate in the combination
|
||||
// double cross1Rate = parser.createParam(1.0, "cross1Rate", "Relative rate for crossover 1", '1', "Variation Operators").value();
|
||||
|
||||
// create the combined operator with the first one (rename it cross1 !!!)
|
||||
// eoPropCombinedQuadOp<Indi> cross(cross1, cross1Rate);
|
||||
|
||||
// and as many as you want the following way:
|
||||
// 1- write the new class by mimicking eoEASEAQuadCrossover.h
|
||||
// 2- include that file here together with eoEASEAQuadCrossover above
|
||||
// 3- uncomment and duplicate the following lines:
|
||||
//
|
||||
// eoEASEASecondCrossover<Indi> cross2(eoParser parser);
|
||||
// double cross2Rate = parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value();
|
||||
// cross.add(cross2, cross2Rate);
|
||||
|
||||
// NOTE: if you want some gentle output, the last one shoudl be like
|
||||
// cross.add(cross, crossXXXRate, true);
|
||||
|
||||
/////////////// Same thing for MUTATION
|
||||
|
||||
// a (first) mutation (possibly use the parser in its Ctor)
|
||||
EASEAMutation<Indi> mut /* (eoParser parser) */;
|
||||
|
||||
// IF MORE THAN ONE:
|
||||
|
||||
// read its relative rate in the combination
|
||||
// double mut1Rate = parser.createParam(1.0, "mut1Rate", "Relative rate for mutation 1", '1', "Variation Operators").value();
|
||||
|
||||
// create the combined operator with the first one (rename it cross1 !!!)
|
||||
// eoPropCombinedMonOp<Indi> mut(mut1, mut1Rate);
|
||||
|
||||
// and as many as you want the following way:
|
||||
// 1- write the new class by mimicking eoEASEAMutation.h
|
||||
// 2- include that file here together with eoEASEAMutation above
|
||||
// 3- uncomment and duplicate the following lines:
|
||||
//
|
||||
// eoEASEASecondMutation<Indi> mut2(eoParser parser);
|
||||
// double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
|
||||
// mut.add(mut2, mut2Rate);
|
||||
|
||||
// NOTE: if you want some gentle output, the last one shoudl be like
|
||||
// mut.add(mut, mutXXXRate, true);
|
||||
|
||||
// now encapsulate your crossover(s) and mutation(s) into an eoGeneralOp
|
||||
// so you can fully benefit of the existing evolution engines
|
||||
|
||||
// First read the individual level parameters
|
||||
double pCross = parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" ).value();
|
||||
// minimum check
|
||||
if ( (pCross < 0) || (pCross > 1) )
|
||||
throw runtime_error("Invalid pCross");
|
||||
|
||||
double pMut = parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" ).value();
|
||||
// minimum check
|
||||
if ( (pMut < 0) || (pMut > 1) )
|
||||
throw runtime_error("Invalid pMut");
|
||||
|
||||
// now create the generalOp
|
||||
eoSGAGenOp<Indi> op(cross, pCross, mut, pMut);
|
||||
|
||||
|
||||
|
||||
//// Now the representation-independent things
|
||||
//
|
||||
// YOU SHOULD NOT NEED TO MODIFY ANYTHING BEYOND THIS POINT
|
||||
// unless you want to add specific statistics to the checkpoint
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<Indi>& pop = make_pop(parser, state, init);
|
||||
// give popSize to AESAE control
|
||||
EZ_POP_SIZE = pop.size();
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<Indi> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
|
||||
///// End of construction of the algorithm
|
||||
|
||||
/////////////////////////////////////////
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<Indi>(eval, pop);
|
||||
// if you want to print it out
|
||||
// cout << "Initial Population\n";
|
||||
// pop.sortedPrintOn(cout);
|
||||
// cout << endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Best individual in final population\n";
|
||||
cout << pop.best_element() << endl;
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
\START_EO_GENOME_H_TPL// -*- mode: c++; c-indent-level: 2; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
//
|
||||
// (The above line is useful in Emacs-like editors)
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
// EASEAGenome.h
|
||||
//
|
||||
// C++ file generated by AESAE-EO v0.7
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
|
||||
#ifndef _EASEAGenome_h
|
||||
#define _EASEAGenome_h
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
|
||||
* Note that you MUST derive your structure from EO<fitT>
|
||||
* but you MAY use some other already prepared class in the hierarchy
|
||||
* like eoVector for instance, if you handle a vector of something....
|
||||
|
||||
* If you create a structure from scratch,
|
||||
* the only thing you need to provide are
|
||||
* a default constructor
|
||||
* IO routines printOn and readFrom
|
||||
*
|
||||
* Note that operator<< and operator>> are defined at EO level
|
||||
* using these routines
|
||||
*/
|
||||
\ANALYSE_USER_CLASSES
|
||||
\INSERT_USER_CLASSES
|
||||
|
||||
template< class FitT>
|
||||
class EASEAGenome: public EO<FitT> {
|
||||
public:
|
||||
/** Ctor: you MUST provide a default ctor.
|
||||
* though such individuals will generally be processed
|
||||
* by some eoInit object
|
||||
*/
|
||||
EASEAGenome() : EO<FitT>()
|
||||
{
|
||||
// START Code of default Ctor of an EASEAGenome object
|
||||
\GENOME_CTOR
|
||||
// END Code of default Ctor of an EASEAGenome object
|
||||
}
|
||||
|
||||
EASEAGenome(const EASEAGenome & arg) : EO<FitT>()
|
||||
{
|
||||
\GENOME_CTOR
|
||||
copy(arg);
|
||||
}
|
||||
|
||||
virtual ~EASEAGenome()
|
||||
{
|
||||
// START Code of Destructor of an EASEAGenome object
|
||||
\GENOME_DTOR
|
||||
// END Code of Destructor of an EASEAGenome object
|
||||
}
|
||||
|
||||
virtual string className() const { return "EASEAGenome"; }
|
||||
|
||||
EASEAGenome& operator=(const EASEAGenome & arg) {
|
||||
copy(arg);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void copy(const EASEAGenome& genome)
|
||||
{
|
||||
if(&genome != this){
|
||||
\GENOME_DTOR
|
||||
\COPY_CTOR
|
||||
if (genome.invalid()) { // copying an invalid genome
|
||||
fitness(FitT()); // put a valid value (i.e. non NAN)
|
||||
invalidate(); // but INVALIDATE the genome
|
||||
}
|
||||
else
|
||||
fitness(genome.fitness());
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const EASEAGenome & genome) const {
|
||||
\EQUAL
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!=(const EASEAGenome & genome) const {
|
||||
return !(*this==genome);
|
||||
}
|
||||
|
||||
/** printing... */
|
||||
void printOn(ostream& os) const
|
||||
{
|
||||
// First write the fitness
|
||||
EO<FitT>::printOn(os);
|
||||
os << ' ';
|
||||
// START Code of default output
|
||||
|
||||
/** HINTS
|
||||
* in EO we systematically write the sizes of things before the things
|
||||
* so readFrom is easier to code (see below)
|
||||
*/
|
||||
\INSERT_DISPLAY
|
||||
\WRITE
|
||||
// END Code of default output
|
||||
}
|
||||
|
||||
/** reading...
|
||||
* of course, your readFrom must be able to read what printOn writes!!!
|
||||
*/
|
||||
void readFrom(istream& is)
|
||||
{
|
||||
// of course you should read the fitness first!
|
||||
EO<FitT>::readFrom(is);
|
||||
// START Code of input
|
||||
|
||||
/** HINTS
|
||||
* remember the EASEAGenome object will come from the default ctor
|
||||
* this is why having the sizes written out is useful
|
||||
*/
|
||||
\READ
|
||||
// END Code of input
|
||||
}
|
||||
|
||||
//private: // put all data here - no privacy in EASEA
|
||||
// START Private data of an EASEAGenome object
|
||||
\INSERT_GENOME
|
||||
// END Private data of an EASEAGenome object
|
||||
};
|
||||
#endif
|
||||
|
||||
\START_EO_EVAL_TPL// -*- mode: c++; c-indent-level: 2; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
//
|
||||
// (The above line is useful in Emacs-like editors)
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
// EASEAEvalFunc.h
|
||||
//
|
||||
// C++ file generated by AESAE-EO v0.7
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
|
||||
/*
|
||||
Evaluator in EO: a functor that computes the fitness of an EO
|
||||
=============================================================
|
||||
*/
|
||||
|
||||
#ifndef _EASEAEvalFunc_h
|
||||
#define _EASEAEvalFunc_h
|
||||
|
||||
// include whatever general include you need
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
// include the base definition of eoEvalFunc
|
||||
#include "eoEvalFunc.h"
|
||||
|
||||
/**
|
||||
Always write a comment in this format before class definition
|
||||
if you want the class to be documented by Doxygen
|
||||
*/
|
||||
template <class EOT>
|
||||
class EASEAEvalFunc : public eoEvalFunc<EOT>
|
||||
{
|
||||
public:
|
||||
/// Ctor - no requirement
|
||||
// START eventually add or modify the anyVariable argument
|
||||
EASEAEvalFunc()
|
||||
// EASEAEvalFunc( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an EASEAEvalFunc object
|
||||
// END Code of Ctor of an EASEAEvalFunc object
|
||||
}
|
||||
|
||||
/** Actually compute the fitness
|
||||
*
|
||||
* @param EOT & _eo the EO object to evaluate
|
||||
* it should stay templatized to be usable
|
||||
* with any fitness type
|
||||
*/
|
||||
void operator()(EOT & genome)
|
||||
{
|
||||
// test for invalid to avoid recomputing fitness of unmodified individuals
|
||||
if (genome.invalid())
|
||||
{
|
||||
// START Code of computation of fitness of the EASEA object
|
||||
\INSERT_EVALUATOR
|
||||
// END Code of computation of fitness of the EASEA object
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an EASEAEvalFunc object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an EASEAEvalFunc object
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
\START_EO_INITER_TPL// -*- mode: c++; c-indent-level: 2; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
//
|
||||
// (The above line is useful in Emacs-like editors)
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
// EASEAInit.h
|
||||
//
|
||||
// C++ file generated by AESAE-EO v0.7
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
|
||||
/*
|
||||
objects initialization in EO
|
||||
============================
|
||||
*/
|
||||
|
||||
#ifndef _EASEAInit_h
|
||||
#define _EASEAInit_h
|
||||
|
||||
// include the base definition of eoInit
|
||||
#include <eoInit.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* There is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO (e.g. to initialize
|
||||
* atoms of an eoVector you will need an eoInit<AtomType>)
|
||||
*/
|
||||
template <class GenotypeT>
|
||||
class EASEAInit: public eoInit<GenotypeT> {
|
||||
public:
|
||||
/// Ctor - no requirement
|
||||
// START eventually add or modify the anyVariable argument
|
||||
EASEAInit()
|
||||
// EASEAInit( varType & _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an EASEAInit object
|
||||
// END Code of Ctor of an EASEAInit object
|
||||
}
|
||||
|
||||
|
||||
/** initialize a genotype
|
||||
*
|
||||
* @param _genotype generally a genotype that has been default-constructed
|
||||
* whatever it contains will be lost
|
||||
*/
|
||||
void operator()(GenotypeT & _genotype)
|
||||
{
|
||||
// START Code of random initialization of an EASEAGenome object
|
||||
\INSERT_EO_INITIALISER
|
||||
// END Code of random initialization of an EASEAGenome object
|
||||
_genotype.invalidate(); // IMPORTANT in case the _genotype is old
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an EASEAInit object
|
||||
// varType & anyVariable; // for example ...
|
||||
// END Private data of an EASEAInit object
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
\START_EO_MUT_TPL// -*- mode: c++; c-indent-level: 2; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
//
|
||||
// (The above line is useful in Emacs-like editors)
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
// EASEAMutation.h
|
||||
//
|
||||
// C++ file generated by AESAE-EO v0.7
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
|
||||
/*
|
||||
simple mutation operators
|
||||
=========================
|
||||
*/
|
||||
|
||||
#ifndef EASEAMutation_H
|
||||
#define EASEAMutation_H
|
||||
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* THere is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO
|
||||
*/
|
||||
template<class GenotypeT>
|
||||
class EASEAMutation: public eoMonOp<GenotypeT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor - no requirement
|
||||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
EASEAMutation()
|
||||
// EASEAMutation( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an EASEAMutation object
|
||||
// END Code of Ctor of an EASEAMutation object
|
||||
}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "EASEAMutation"; }
|
||||
|
||||
/**
|
||||
* modifies the parent
|
||||
* @param _genotype The parent genotype (will be modified)
|
||||
*/
|
||||
bool operator()(GenotypeT & _genotype)
|
||||
{
|
||||
// START code for mutation of the _genotype object
|
||||
\INSERT_MUTATOR
|
||||
// END code for mutation of the _genotype object
|
||||
|
||||
private:
|
||||
// START Private data of an EASEAMutation object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an EASEAMutation object
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
\START_EO_QUAD_XOVER_TPL// -*- mode: c++; c-indent-level: 2; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
//
|
||||
// (The above line is useful in Emacs-like editors)
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
// EASEAQuadCrossover.h
|
||||
//
|
||||
// C++ file generated by AESAE-EO v0.7
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
|
||||
/*
|
||||
Template for simple quadratic crossover operators
|
||||
=================================================
|
||||
|
||||
Quadratic crossover operators modify both genotypes
|
||||
*/
|
||||
|
||||
#ifndef EASEAQuadCrossover_H
|
||||
#define EASEAQuadCrossover_H
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* THere is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO
|
||||
*/
|
||||
template<class GenotypeT>
|
||||
class EASEAQuadCrossover: public eoQuadOp<GenotypeT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor - no requirement
|
||||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
EASEAQuadCrossover()
|
||||
// EASEAQuadCrossover( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an EASEAQuadCrossover object
|
||||
// END Code of Ctor of an EASEAQuadCrossover object
|
||||
}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "EASEAQuadCrossover"; }
|
||||
|
||||
/**
|
||||
* eoQuad crossover - modifies both genotypes
|
||||
*/
|
||||
bool operator()(GenotypeT& child1, GenotypeT & child2)
|
||||
{
|
||||
GenotypeT parent1(child1);
|
||||
GenotypeT parent2(child2);
|
||||
|
||||
// START code for crossover of child1 and child2 objects
|
||||
\INSERT_CROSSOVER
|
||||
return (parent1!=child1)||(parent2!=child2);
|
||||
// END code for crossover of child1 and child2 objects
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an EASEAQuadCrossover object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an EASEAQuadCrossover object
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
\START_EO_CONTINUE_TPL// -*- mode: c++; c-indent-level: 2; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
//
|
||||
// (The above line is useful in Emacs-like editors)
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
// EASEA_make_continue.h
|
||||
//
|
||||
// C++ file generated by AESAE-EO v0.7
|
||||
//
|
||||
//*************************************
|
||||
//
|
||||
|
||||
#ifndef _make_continue_h
|
||||
#define _make_continue_h
|
||||
|
||||
/*
|
||||
Contains the templatized version of parser-based choice of stopping criterion
|
||||
It can then be instantiated, and compiled on its own for a given EOType
|
||||
(see e.g. in dir ga, ga.cpp)
|
||||
*/
|
||||
|
||||
// Continuators - all include eoContinue.h
|
||||
#include <eoCombinedContinue.h>
|
||||
#include <eoGenContinue.h>
|
||||
#include <eoSteadyFitContinue.h>
|
||||
#include <eoEvalContinue.h>
|
||||
#include <eoFitContinue.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <eoCtrlCContinue.h> // CtrlC handling (using 2 global variables!)
|
||||
#endif
|
||||
|
||||
// also need the parser and param includes
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoState.h>
|
||||
|
||||
|
||||
/////////////////// the stopping criterion ////////////////
|
||||
template <class Indi>
|
||||
eoCombinedContinue<Indi> * make_combinedContinue(eoCombinedContinue<Indi> *_combined, eoContinue<Indi> *_cont)
|
||||
{
|
||||
if (_combined) // already exists
|
||||
_combined->add(*_cont);
|
||||
else
|
||||
_combined = new eoCombinedContinue<Indi>(*_cont);
|
||||
return _combined;
|
||||
}
|
||||
|
||||
template <class Indi>
|
||||
eoContinue<Indi> & do_make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)
|
||||
{
|
||||
//////////// Stopping criterion ///////////////////
|
||||
// the combined continue - to be filled
|
||||
eoCombinedContinue<Indi> *continuator = NULL;
|
||||
|
||||
// for each possible criterion, check if wanted, otherwise do nothing
|
||||
|
||||
// First the eoGenContinue - need a default value so you can run blind
|
||||
// but we also need to be able to avoid it <--> 0
|
||||
eoValueParam<unsigned>& maxGenParam = _parser.createParam(\NB_GEN, "maxGen", "Maximum number of generations () = none)",'G',"Stopping criterion");
|
||||
// and give control to EASEA
|
||||
EZ_NB_GEN = maxGenParam.value();
|
||||
pEZ_NB_GEN = & maxGenParam.value();
|
||||
|
||||
// do not test for positivity in EASEA
|
||||
// if (maxGenParam.value()) // positive: -> define and store
|
||||
// {
|
||||
eoGenContinue<Indi> *genCont = new eoGenContinue<Indi>(maxGenParam.value());
|
||||
_state.storeFunctor(genCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<Indi>(continuator, genCont);
|
||||
// }
|
||||
|
||||
// the steadyGen continue - only if user imput
|
||||
eoValueParam<unsigned>& steadyGenParam = _parser.createParam(unsigned(100), "steadyGen", "Number of generations with no improvement",'s', "Stopping criterion");
|
||||
eoValueParam<unsigned>& minGenParam = _parser.createParam(unsigned(0), "minGen", "Minimum number of generations",'g', "Stopping criterion");
|
||||
if (_parser.isItThere(steadyGenParam))
|
||||
{
|
||||
eoSteadyFitContinue<Indi> *steadyCont = new eoSteadyFitContinue<Indi>
|
||||
(minGenParam.value(), steadyGenParam.value());
|
||||
// store
|
||||
_state.storeFunctor(steadyCont);
|
||||
// add to combinedContinue
|
||||
continuator = make_combinedContinue<Indi>(continuator, steadyCont);
|
||||
}
|
||||
|
||||
// Same thing with Eval - but here default value is 0
|
||||
eoValueParam<unsigned long>& maxEvalParam = _parser.createParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)",'E',"Stopping criterion");
|
||||
|
||||
if (maxEvalParam.value()) // positive: -> define and store
|
||||
{
|
||||
eoEvalContinue<Indi> *evalCont = new eoEvalContinue<Indi>(_eval, maxEvalParam.value());
|
||||
_state.storeFunctor(evalCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<Indi>(continuator, evalCont);
|
||||
}
|
||||
/*
|
||||
// the steadyEval continue - only if user imput
|
||||
eoValueParam<unsigned>& steadyGenParam = _parser.createParam(unsigned(100), "steadyGen", "Number of generations with no improvement",'s', "Stopping criterion");
|
||||
eoValueParam<unsigned>& minGenParam = _parser.createParam(unsigned(0), "minGen", "Minimum number of generations",'g', "Stopping criterion");
|
||||
if (_parser.isItThere(steadyGenParam))
|
||||
{
|
||||
eoSteadyGenContinue<Indi> *steadyCont = new eoSteadyFitContinue<Indi>
|
||||
(minGenParam.value(), steadyGenParam.value());
|
||||
// store
|
||||
_state.storeFunctor(steadyCont);
|
||||
// add to combinedContinue
|
||||
continuator = make_combinedContinue<Indi>(continuator, steadyCont);
|
||||
}
|
||||
*/
|
||||
// the target fitness
|
||||
eoFitContinue<Indi> *fitCont;
|
||||
eoValueParam<double>& targetFitnessParam = _parser.createParam(double(0.0), "targetFitness", "Stop when fitness reaches",'T', "Stopping criterion");
|
||||
if (_parser.isItThere(targetFitnessParam))
|
||||
{
|
||||
fitCont = new eoFitContinue<Indi>
|
||||
(targetFitnessParam.value());
|
||||
// store
|
||||
_state.storeFunctor(fitCont);
|
||||
// add to combinedContinue
|
||||
continuator = make_combinedContinue<Indi>(continuator, fitCont);
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
// the CtrlC interception (Linux only I'm afraid)
|
||||
eoCtrlCContinue<Indi> *ctrlCCont;
|
||||
eoValueParam<bool>& ctrlCParam = _parser.createParam(false, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
|
||||
if (_parser.isItThere(ctrlCParam))
|
||||
{
|
||||
ctrlCCont = new eoCtrlCContinue<Indi>;
|
||||
// store
|
||||
_state.storeFunctor(ctrlCCont);
|
||||
// add to combinedContinue
|
||||
continuator = make_combinedContinue<Indi>(continuator, ctrlCCont);
|
||||
}
|
||||
#endif
|
||||
|
||||
// now check that there is at least one!
|
||||
if (!continuator)
|
||||
throw runtime_error("You MUST provide a stopping criterion");
|
||||
// OK, it's there: store in the eoState
|
||||
_state.storeFunctor(continuator);
|
||||
|
||||
// and return
|
||||
return *continuator;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
\START_EO_PARAM_TPL#*************************************
|
||||
#
|
||||
# EASEA.prm
|
||||
#
|
||||
# Parameter file generated by AESAE-EO v0.7
|
||||
#
|
||||
#*************************************
|
||||
###### General ######
|
||||
# --help=0 # -h : Prints this message
|
||||
# --stopOnUnknownParam=1 # Stop if unknown param entered
|
||||
--seed=0 # -S : Random number seed
|
||||
|
||||
###### Evolution Engine ######
|
||||
--popSize=\POP_SIZE # -P : Population Size
|
||||
--selection=\SELECTOR\SELECT_PRM # -S : Selection: Roulette, Ranking(p,e), DetTour(T), StochTour(t) or Sequential(ordered/unordered)
|
||||
--nbOffspring=\OFF_SIZE # -O : Nb of offspring (percentage or absolute)
|
||||
--replacement=General # Type of replacement: Generational, ESComma, ESPlus, SSGA(T), EP(T)
|
||||
|
||||
###### Evolution Engine / Replacement ######
|
||||
--elite=\ELITE_SIZE # Nb of elite parents (percentage or absolute)
|
||||
--eliteType=\ELITISM # Strong (true) or weak (false) elitism (set elite to 0 for none)
|
||||
--surviveParents=\SURV_PAR_SIZE # Nb of surviving parents (percentage or absolute)
|
||||
--reduceParents=\RED_PAR\RED_PAR_PRM # Parents reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform
|
||||
--surviveOffspring=\SURV_OFF_SIZE # Nb of surviving offspring (percentage or absolute)
|
||||
--reduceOffspring=\RED_OFF\RED_OFF_PRM # Offspring reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform
|
||||
--reduceFinal=\RED_FINAL\RED_FINAL_PRM # Final reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform
|
||||
|
||||
###### Output ######
|
||||
# --useEval=1 # Use nb of eval. as counter (vs nb of gen.)
|
||||
# --useTime=1 # Display time (s) every generation
|
||||
# --printBestStat=1 # Print Best/avg/stdev every gen.
|
||||
# --printPop=0 # Print sorted pop. every gen.
|
||||
|
||||
###### Output - Disk ######
|
||||
# --resDir=Res # Directory to store DISK outputs
|
||||
# --eraseDir=1 # erase files in dirName if any
|
||||
# --fileBestStat=0 # Output bes/avg/std to file
|
||||
|
||||
###### Output - Graphical ######
|
||||
# --plotBestStat=0 # Plot Best/avg Stat
|
||||
# --plotHisto=0 # Plot histogram of fitnesses
|
||||
|
||||
###### 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=OneMaxGenomeEA.status # Status file
|
||||
|
||||
###### Stopping criterion ######
|
||||
# --maxGen=100 # -G : Maximum number of generations () = none)
|
||||
# --steadyGen=100 # -s : Number of generations with no improvement
|
||||
# --minGen=0 # -g : Minimum number of generations
|
||||
# --maxEval=0 # -E : Maximum number of evaluations (0 = none)
|
||||
# --targetFitness=0 # -T : Stop when fitness reaches
|
||||
# --CtrlC=0 # -C : Terminate current generation upon Ctrl C
|
||||
|
||||
###### Variation Operators ######
|
||||
# --cross1Rate=1 # -1 : Relative rate for crossover 1
|
||||
# --mut1Rate=1 # -1 : Relative rate for mutation 1
|
||||
--pCross=\XOVER_PROB # -C : Probability of Crossover
|
||||
--pMut=\MUT_PROB # -M : Probability of Mutation
|
||||
|
||||
\START_EO_MAKEFILE_TPL#*************************************
|
||||
#
|
||||
# EASEA.mak
|
||||
#
|
||||
# Makefile generated by AESAE-EO v0.7
|
||||
#
|
||||
#*************************************
|
||||
|
||||
# sample makefile for building an EA evolving a new genotype
|
||||
|
||||
DIR_EO = \EO_DIR
|
||||
|
||||
.cpp: ; c++ -DPACKAGE=\"eo\" -I. -I$(DIR_EO)/src -Wall -g -o $@ $*.cpp $(DIR_EO)/src/libeo.a $(DIR_EO)/src/utils/libeoutils.a
|
||||
|
||||
.cpp.o: ; c++ -DPACKAGE=\"eo\" -I. -I\EO_DIR/src -Wall -g -c $*.cpp
|
||||
|
||||
LIB_EO = $(DIR_EO)/src/utils/libeoutils.a $(DIR_EO)/src/libeo.a
|
||||
|
||||
SOURCES = EASEA.cpp \
|
||||
EASEAEvalFunc.h \
|
||||
EASEAGenome.h \
|
||||
EASEAInit.h \
|
||||
EASEAMutation.h \
|
||||
EASEAQuadCrossover.h \
|
||||
$(LIB_EO)
|
||||
|
||||
ALL = EASEA
|
||||
|
||||
EASEA : $(SOURCES)
|
||||
c++ -g -I. -I$(DIR_EO)/src -o $@ EASEA.cpp $(LIB_EO) -lm
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
clean : ; /bin/rm *.o $(ALL)
|
||||
|
||||
\TEMPLATE_END
|
||||
16
deprecated/eo/tutorial/Templates/Makefile.am.src-tmpl
Normal file
16
deprecated/eo/tutorial/Templates/Makefile.am.src-tmpl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
bin_PROGRAMS = MyStruct
|
||||
|
||||
noinst_HEADERS = eoMyStruct.h \
|
||||
eoMyStructEvalFunc.h \
|
||||
eoMyStructInit.h \
|
||||
eoMyStructMutation.h \
|
||||
eoMyStructQuadCrossover.h
|
||||
|
||||
MyStruct_SOURCES = MyStructEA.cpp
|
||||
|
||||
|
||||
dnl Local Variables:
|
||||
dnl coding: iso-8859-1
|
||||
dnl mode: makefile-automake
|
||||
dnl fill-column: 80
|
||||
dnl End:
|
||||
8
deprecated/eo/tutorial/Templates/Makefile.am.top-tmpl
Normal file
8
deprecated/eo/tutorial/Templates/Makefile.am.top-tmpl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
SUBDIRS = src
|
||||
|
||||
|
||||
dnl Local Variables:
|
||||
dnl coding: iso-8859-1
|
||||
dnl mode: makefile-automake
|
||||
dnl fill-column: 80
|
||||
dnl End:
|
||||
188
deprecated/eo/tutorial/Templates/MyStructEA.cpp
Normal file
188
deprecated/eo/tutorial/Templates/MyStructEA.cpp
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
|
||||
This is the template main file.
|
||||
It includes all other files that have been generated by the script create.sh
|
||||
so it is the only file to compile.
|
||||
|
||||
In case you want to build up a separate library for your new Evolving Object,
|
||||
you'll need some work - follow what's done in the src/ga dir, used in the
|
||||
main file BitEA in tutorial/Lesson4 dir.
|
||||
Or you can wait until we do it :-)
|
||||
*/
|
||||
|
||||
// Miscilaneous include and declaration
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// eo general include
|
||||
#include "eo"
|
||||
// the real bounds (not yet in general eo include)
|
||||
#include "utils/eoRealVectorBounds.h"
|
||||
|
||||
// include here whatever specific files for your representation
|
||||
// Basically, this should include at least the following
|
||||
|
||||
/** definition of representation:
|
||||
* class eoMyStruct MUST derive from EO<FitT> for some fitness
|
||||
*/
|
||||
#include "eoMyStruct.h"
|
||||
|
||||
/** definition of initilizqtion:
|
||||
* class eoMyStructInit MUST derive from eoInit<eoMyStruct>
|
||||
*/
|
||||
#include "eoMyStructInit.h"
|
||||
|
||||
/** definition of evaluation:
|
||||
* class eoMyStructEvalFunc MUST derive from eoEvalFunc<eoMyStruct>
|
||||
* and should test for validity before doing any computation
|
||||
* see tutorial/Templates/evalFunc.tmpl
|
||||
*/
|
||||
#include "eoMyStructEvalFunc.h"
|
||||
|
||||
// GENOTYPE eoMyStruct ***MUST*** be templatized over the fitness
|
||||
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
// START fitness type: double or eoMaximizingFitness if you are maximizing
|
||||
// eoMinimizingFitness if you are minimizing
|
||||
typedef eoMinimizingFitness MyFitT ; // type of fitness
|
||||
// END fitness type
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
|
||||
// Then define your EO objects using that fitness type
|
||||
typedef eoMyStruct<MyFitT> Indi; // ***MUST*** derive from EO
|
||||
|
||||
// create an initializer
|
||||
#include "make_genotype_MyStruct.h"
|
||||
eoInit<Indi> & make_genotype(eoParser& _parser, eoState&_state, Indi _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
||||
// and the variation operaotrs
|
||||
#include "make_op_MyStruct.h"
|
||||
eoGenOp<Indi>& make_op(eoParser& _parser, eoState& _state, eoInit<Indi>& _init)
|
||||
{
|
||||
return do_make_op(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// Use existing modules to define representation independent routines
|
||||
// These are parser-based definitions of objects
|
||||
|
||||
// how to initialize the population
|
||||
// it IS representation independent if an eoInit is given
|
||||
#include <make_pop.h>
|
||||
eoPop<Indi >& make_pop(eoParser& _parser, eoState& _state, eoInit<Indi> & _init)
|
||||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// the stopping criterion
|
||||
#include <make_continue.h>
|
||||
eoContinue<Indi>& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)
|
||||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
// outputs (stats, population dumps, ...)
|
||||
#include <make_checkpoint.h>
|
||||
eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
// evolution engine (selection and replacement)
|
||||
#include <make_algo_scalar.h>
|
||||
eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& _continue, eoGenOp<Indi>& _op)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
// no template for that one
|
||||
#include <make_run.h>
|
||||
// the instanciating fitnesses
|
||||
#include <eoScalarFitness.h>
|
||||
void run_ea(eoAlgo<Indi>& _ga, eoPop<Indi>& _pop)
|
||||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
// checks for help demand, and writes the status file
|
||||
// and make_help; in libutils
|
||||
void make_help(eoParser & _parser);
|
||||
|
||||
// now use all of the above, + representation dependent things
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
// The fitness
|
||||
//////////////
|
||||
eoMyStructEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
|
||||
// turn that object into an evaluation counter
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// the genotype - through a genotype initializer
|
||||
eoInit<Indi>& init = make_genotype(parser, state, Indi());
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
eoGenOp<Indi>& op = make_op(parser, state, init);
|
||||
|
||||
|
||||
//// Now the representation-independent things
|
||||
//
|
||||
// YOU SHOULD NOT NEED TO MODIFY ANYTHING BEYOND THIS POINT
|
||||
// unless you want to add specific statistics to the checkpoint
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<Indi>& pop = make_pop(parser, state, init);
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<Indi> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
|
||||
///// End of construction of the algorithm
|
||||
|
||||
/////////////////////////////////////////
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<Indi>(eval, pop);
|
||||
// if you want to print it out
|
||||
// cout << "Initial Population\n";
|
||||
// pop.sortedPrintOn(cout);
|
||||
// cout << endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
162
deprecated/eo/tutorial/Templates/MyStructLibEA.cpp
Normal file
162
deprecated/eo/tutorial/Templates/MyStructLibEA.cpp
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
|
||||
This is the template main file for compiling after creating a
|
||||
"library", i.e. putting everything but the fitness in a separate file
|
||||
(make_MyStruct.cpp) and compiling it once and for all.
|
||||
*/
|
||||
|
||||
// Miscilaneous include and declaration
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// eo general include
|
||||
#include "eo"
|
||||
// the real bounds (not yet in general eo include)
|
||||
#include "utils/eoRealVectorBounds.h"
|
||||
|
||||
// include here whatever specific files for your representation
|
||||
// Basically, this should include at least the following
|
||||
|
||||
/** definition of representation:
|
||||
* class eoMyStruct MUST derive from EO<FitT> for some fitness
|
||||
*/
|
||||
#include "eoMyStruct.h"
|
||||
|
||||
/** definition of initilizqtion:
|
||||
* class eoMyStructInit MUST derive from eoInit<eoMyStruct>
|
||||
*/
|
||||
#include "eoMyStructInit.h"
|
||||
|
||||
/** definition of evaluation:
|
||||
* class eoMyStructEvalFunc MUST derive from eoEvalFunc<eoMyStruct>
|
||||
* and should test for validity before doing any computation
|
||||
* see tutorial/Templates/evalFunc.tmpl
|
||||
*/
|
||||
#include "eoMyStructEvalFunc.h"
|
||||
|
||||
// GENOTYPE eoMyStruct ***MUST*** be templatized over the fitness
|
||||
|
||||
//
|
||||
// START fitness type: double or eoMaximizingFitness if you are maximizing
|
||||
// eoMinimizingFitness if you are minimizing
|
||||
typedef eoMinimizingFitness MyFitT ; // type of fitness
|
||||
// END fitness type
|
||||
//
|
||||
|
||||
// Then define your EO objects using that fitness type
|
||||
typedef eoMyStruct<MyFitT> Indi; // ***MUST*** derive from EO
|
||||
|
||||
// create an initializer - done here and NOT in make_MyStruct.cpp
|
||||
// because it is NOT representation independent
|
||||
#include "make_genotype_MyStruct.h"
|
||||
eoInit<Indi> & make_genotype(eoParser& _parser, eoState&_state, Indi _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
||||
// same thing for the variation operaotrs
|
||||
#include "make_op_MyStruct.h"
|
||||
eoGenOp<Indi>& make_op(eoParser& _parser, eoState& _state, eoInit<Indi>& _init)
|
||||
{
|
||||
return do_make_op(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// The representation independent routines are simply declared here
|
||||
|
||||
// how to initialize the population
|
||||
// it IS representation independent if an eoInit is given
|
||||
eoPop<Indi >& make_pop(eoParser& _parser, eoState& _state, eoInit<Indi> & _init);
|
||||
|
||||
// the stopping criterion
|
||||
eoContinue<Indi>& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval);
|
||||
|
||||
// outputs (stats, population dumps, ...)
|
||||
eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& _continue);
|
||||
|
||||
// evolution engine (selection and replacement)
|
||||
eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& _continue, eoGenOp<Indi>& _op);
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
// no template for that one
|
||||
void run_ea(eoAlgo<Indi>& _ga, eoPop<Indi>& _pop);
|
||||
|
||||
// checks for help demand, and writes the status file
|
||||
// and make_help; in libutils - just a declaration, code in libeoutils.a
|
||||
void make_help(eoParser & _parser);
|
||||
|
||||
// now use all of the above, + representation dependent things
|
||||
// from here on, no difference with eoMyStruct.cpp
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
// The fitness
|
||||
//////////////
|
||||
eoMyStructEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
|
||||
// turn that object into an evaluation counter
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// the genotype - through a genotype initializer
|
||||
eoInit<Indi>& init = make_genotype(parser, state, Indi());
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
eoGenOp<Indi>& op = make_op(parser, state, init);
|
||||
|
||||
|
||||
//// Now the representation-independent things
|
||||
//
|
||||
// YOU SHOULD NOT NEED TO MODIFY ANYTHING BEYOND THIS POINT
|
||||
// unless you want to add specific statistics to the checkpoint
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<Indi>& pop = make_pop(parser, state, init);
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<Indi> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
|
||||
///// End of construction of the algorithm
|
||||
|
||||
/////////////////////////////////////////
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<Indi>(eval, pop);
|
||||
// if you want to print it out
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
350
deprecated/eo/tutorial/Templates/MyStructSEA.cpp
Normal file
350
deprecated/eo/tutorial/Templates/MyStructSEA.cpp
Normal file
|
|
@ -0,0 +1,350 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
|
||||
This is the template main file.
|
||||
It includes all other files that have been generated by the script create.sh
|
||||
so it is the only file to compile.
|
||||
|
||||
In case you want to build up a separate library for your new Evolving Object,
|
||||
you'll need some work - follow what's done in the src/ga dir, used in the
|
||||
main file BitEA in tutorial/Lesson4 dir.
|
||||
Or you can wait until we do it :-)
|
||||
*/
|
||||
|
||||
// Miscilaneous include and declaration
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// eo general include
|
||||
#include "eo"
|
||||
// the real bounds (not yet in general eo include)
|
||||
#include "utils/eoRealVectorBounds.h"
|
||||
|
||||
// include here whatever specific files for your representation
|
||||
// Basically, this should include at least the following
|
||||
|
||||
/** definition of representation:
|
||||
* class eoMyStruct MUST derive from EO<FitT> for some fitness
|
||||
*/
|
||||
#include "eoMyStruct.h"
|
||||
|
||||
/** definition of initilizqtion:
|
||||
* class eoMyStructInit MUST derive from eoInit<eoMyStruct>
|
||||
*/
|
||||
#include "eoMyStructInit.h"
|
||||
|
||||
/** definition of evaluation:
|
||||
* class eoMyStructEvalFunc MUST derive from eoEvalFunc<eoMyStruct>
|
||||
* and should test for validity before doing any computation
|
||||
* see tutorial/Templates/evalFunc.tmpl
|
||||
*/
|
||||
#include "eoMyStructEvalFunc.h"
|
||||
|
||||
/** definitions of operators: write as many classes as types of operators
|
||||
* and include them here. In this simple example,
|
||||
* one crossover (2->2) and one mutation (1->1) operators are used
|
||||
*/
|
||||
#include "eoMyStructQuadCrossover.h"
|
||||
#include "eoMyStructMutation.h"
|
||||
|
||||
/* and (possibly) your personal statistics */
|
||||
#include "eoMyStructStat.h"
|
||||
|
||||
// GENOTYPE eoMyStruct ***MUST*** be templatized over the fitness
|
||||
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
// START fitness type: double or eoMaximizingFitness if you are maximizing
|
||||
// eoMinimizingFitness if you are minimizing
|
||||
typedef eoMinimizingFitness MyFitT ; // type of fitness
|
||||
// END fitness type
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
|
||||
// Then define your EO objects using that fitness type
|
||||
typedef eoMyStruct<MyFitT> Indi; // ***MUST*** derive from EO
|
||||
|
||||
|
||||
// Use existing modules to define representation independent routines
|
||||
|
||||
// how to initialize the population
|
||||
// it IS representation independent if an eoInit is given
|
||||
#include <make_pop.h>
|
||||
eoPop<Indi >& make_pop(eoParser& _parser, eoState& _state, eoInit<Indi> & _init)
|
||||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// the stopping criterion
|
||||
#include <make_continue.h>
|
||||
eoContinue<Indi>& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)
|
||||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
// outputs (stats, population dumps, ...)
|
||||
#include <make_checkpoint.h>
|
||||
eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
// evolution engine (selection and replacement)
|
||||
#include <make_algo_scalar.h>
|
||||
eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& _continue, eoGenOp<Indi>& _op, eoDistance<Indi> *_dist = NULL)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
|
||||
}
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
// no template for that one
|
||||
#include <make_run.h>
|
||||
// the instanciating fitnesses
|
||||
#include <eoScalarFitness.h>
|
||||
void run_ea(eoAlgo<Indi>& _ga, eoPop<Indi>& _pop)
|
||||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
// checks for help demand, and writes the status file
|
||||
// and make_help; in libutils
|
||||
void make_help(eoParser & _parser);
|
||||
|
||||
// now use all of the above, + representation dependent things
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
// The fitness
|
||||
//////////////
|
||||
eoMyStructEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
|
||||
// turn that object into an evaluation counter
|
||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||
|
||||
// a genotype initializer
|
||||
eoMyStructInit<Indi> init;
|
||||
// or, if you need some parameters, you might as well
|
||||
// - write a constructor of the eoMyStructInit that uses a parser
|
||||
// - call it from here:
|
||||
// eoMyStructInit<Indi> init(parser);
|
||||
|
||||
// if you want to do sharing, you'll need a distance.
|
||||
// see file utils/eoDistance.h
|
||||
//
|
||||
// IF you representation has an operator[]() double-castable,
|
||||
// then you can use for instance the quadratic distance (L2 norm)
|
||||
// eoQuadDistance<Indi> dist;
|
||||
// or the Hamming distance (L1 norm)
|
||||
// eoHammingDistance<Indi> dist;
|
||||
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
// here, a simple example with only 1 crossover (2->2, a QuadOp) and
|
||||
// one mutation, is given.
|
||||
// Hints to have choice among multiple crossovers and mutations are given
|
||||
|
||||
// A (first) crossover (possibly use the parser in its Ctor)
|
||||
eoMyStructQuadCrossover<Indi> cross /* (eoParser parser) */;
|
||||
|
||||
// IF MORE THAN ONE:
|
||||
|
||||
// read its relative rate in the combination
|
||||
// double cross1Rate = parser.createParam(1.0, "cross1Rate", "Relative rate for crossover 1", '1', "Variation Operators").value();
|
||||
|
||||
// create the combined operator with the first one (rename it cross1 !!!)
|
||||
// eoPropCombinedQuadOp<Indi> cross(cross1, cross1Rate);
|
||||
|
||||
// and as many as you want the following way:
|
||||
// 1- write the new class by mimicking eoMyStructQuadCrossover.h
|
||||
// 2- include that file here together with eoMyStructQuadCrossover above
|
||||
// 3- uncomment and duplicate the following lines:
|
||||
//
|
||||
// eoMyStructSecondCrossover<Indi> cross2(eoParser parser);
|
||||
// double cross2Rate = parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value();
|
||||
// cross.add(cross2, cross2Rate);
|
||||
|
||||
// NOTE: if you want some gentle output, the last one shoudl be like
|
||||
// cross.add(cross, crossXXXRate, true);
|
||||
|
||||
/////////////// Same thing for MUTATION
|
||||
|
||||
// a (first) mutation (possibly use the parser in its Ctor)
|
||||
eoMyStructMutation<Indi> mut /* (parser) */;
|
||||
|
||||
// IF MORE THAN ONE:
|
||||
|
||||
// read its relative rate in the combination
|
||||
// double mut1Rate = parser.createParam(1.0, "mut1Rate", "Relative rate for mutation 1", '1', "Variation Operators").value();
|
||||
|
||||
// create the combined operator with the first one (rename it cross1 !!!)
|
||||
// eoPropCombinedMonOp<Indi> mut(mut1, mut1Rate);
|
||||
|
||||
// and as many as you want the following way:
|
||||
// 1- write the new class by mimicking eoMyStructMutation.h
|
||||
// 2- include that file here together with eoMyStructMutation above
|
||||
// 3- uncomment and duplicate the following lines:
|
||||
//
|
||||
// eoMyStructSecondMutation<Indi> mut2(eoParser parser);
|
||||
// double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
|
||||
// mut.add(mut2, mut2Rate);
|
||||
|
||||
// NOTE: if you want some gentle output, the last one shoudl be like
|
||||
// mut.add(mut, mutXXXRate, true);
|
||||
|
||||
// now encapsulate your crossover(s) and mutation(s) into an eoGeneralOp
|
||||
// so you can fully benefit of the existing evolution engines
|
||||
|
||||
// First read the individual level parameters
|
||||
double pCross = parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" ).value();
|
||||
// minimum check
|
||||
if ( (pCross < 0) || (pCross > 1) )
|
||||
throw runtime_error("Invalid pCross");
|
||||
|
||||
double pMut = parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" ).value();
|
||||
// minimum check
|
||||
if ( (pMut < 0) || (pMut > 1) )
|
||||
throw runtime_error("Invalid pMut");
|
||||
|
||||
// now create the generalOp
|
||||
eoSGAGenOp<Indi> op(cross, pCross, mut, pMut);
|
||||
|
||||
|
||||
//// Now some representation-independent things
|
||||
//
|
||||
// You do not need to modify anything beyond this point
|
||||
// unless you want to add specific statistics to the checkpoint
|
||||
// in which case you should uncomment the corresponding block
|
||||
// and possibly modify the parameters in the stat object creation
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population
|
||||
// yes, this is representation indepedent once you have an eoInit
|
||||
eoPop<Indi>& pop = make_pop(parser, state, init);
|
||||
|
||||
// stopping criteria
|
||||
eoContinue<Indi> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
|
||||
|
||||
// UNCOMMENT the following commented block if you want to add you stats
|
||||
|
||||
// if uncommented, it is assumed that you will want to print some stat.
|
||||
// if not, then the following objects will be created uselessly - but what the heck!
|
||||
|
||||
eoMyStructStat<Indi> myStat; // or maybe myStat(parser);
|
||||
checkpoint.add(myStat);
|
||||
// This one is probably redundant with the one in make_checkpoint, but w.t.h.
|
||||
eoIncrementorParam<unsigned> generationCounter("Gen.");
|
||||
checkpoint.add(generationCounter);
|
||||
// need to get the name of the redDir param (if any)
|
||||
std::string dirName = parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk").value() + "/";
|
||||
|
||||
|
||||
// those need to be pointers because of the if's
|
||||
eoStdoutMonitor *myStdOutMonitor;
|
||||
eoFileMonitor *myFileMonitor;
|
||||
#ifdef HAVE_GNUPLOT
|
||||
eoGnuplot1DMonitor *myGnuMonitor;
|
||||
#endif
|
||||
|
||||
// now check how you want to output the stat:
|
||||
bool printMyStructStat = parser.createParam(false, "coutMyStructStat", "Prints my stat to screen, one line per generation", '\0', "My application").value();
|
||||
bool fileMyStructStat = parser.createParam(false, "fileMyStructStat", "Saves my stat to file (in resDir", '\0', "My application").value();
|
||||
bool plotMyStructStat = parser.createParam(false, "plotMyStructStat", "On-line plots my stat using gnuplot", '\0', "My application").value();
|
||||
|
||||
// should we write it on StdOut ?
|
||||
if (printMyStructStat)
|
||||
{
|
||||
myStdOutMonitor = new eoStdoutMonitor(false);
|
||||
// don't forget to store the memory in the state
|
||||
state.storeFunctor(myStdOutMonitor);
|
||||
// and of course to add the monitor to the checkpoint
|
||||
checkpoint.add(*myStdOutMonitor);
|
||||
// and the different fields to the monitor
|
||||
myStdOutMonitor->add(generationCounter);
|
||||
myStdOutMonitor->add(eval);
|
||||
myStdOutMonitor->add(myStat);
|
||||
}
|
||||
|
||||
// first check the directory (and creates it if not exists already):
|
||||
if (fileMyStructStat || plotMyStructStat)
|
||||
if (! testDirRes(dirName, true) )
|
||||
throw runtime_error("Problem with resDir");
|
||||
|
||||
// should we write it to a file ?
|
||||
if (fileMyStructStat)
|
||||
{
|
||||
// the file name is hard-coded - of course you can read
|
||||
// a string parameter in the parser if you prefer
|
||||
myFileMonitor = new eoFileMonitor(dirName + "myStat.xg");
|
||||
// don't forget to store the memory in the state
|
||||
state.storeFunctor(myFileMonitor);
|
||||
// and of course to add the monitor to the checkpoint
|
||||
checkpoint.add(*myFileMonitor);
|
||||
// and the different fields to the monitor
|
||||
myFileMonitor->add(generationCounter);
|
||||
myFileMonitor->add(eval);
|
||||
myFileMonitor->add(myStat);
|
||||
}
|
||||
|
||||
#ifdef HAVE_GNUPLOT
|
||||
// should we PLOT it on StdOut ? (one dot per generation, incremental plot)
|
||||
if (plotMyStructStat)
|
||||
{
|
||||
myGnuMonitor = new eoGnuplot1DMonitor(dirName+"plot_myStat.xg",minimizing_fitness<Indi>());
|
||||
// NOTE: you cand send commands to gnuplot at any time with the method
|
||||
// myGnuMonitor->gnuplotCommand(string)
|
||||
// par exemple, gnuplotCommand("set logscale y")
|
||||
|
||||
// don't forget to store the memory in the state
|
||||
state.storeFunctor(myGnuMonitor);
|
||||
// and of course to add the monitor to the checkpoint
|
||||
checkpoint.add(*myGnuMonitor);
|
||||
// and the different fields to the monitor (X = eval, Y = myStat)
|
||||
myGnuMonitor->add(eval);
|
||||
myGnuMonitor->add(myStat);
|
||||
}
|
||||
#endif
|
||||
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
// and the distance if you want to do sharing
|
||||
// eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op, &dist);
|
||||
|
||||
///// End of construction of the algorithm
|
||||
|
||||
/////////////////////////////////////////
|
||||
// to be called AFTER all parameters have been read!!!
|
||||
make_help(parser);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<Indi>(eval, pop);
|
||||
// if you want to print it out
|
||||
// cout << "Initial Population\n";
|
||||
// pop.sortedPrintOn(cout);
|
||||
// cout << endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
34
deprecated/eo/tutorial/Templates/README
Normal file
34
deprecated/eo/tutorial/Templates/README
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
This Templates directory contains template files of an EO project and
|
||||
a script createEOproject.sh to create a complete new EO project.
|
||||
|
||||
The template requires a complete installation of EO, that is, you must
|
||||
have run "make install" in the build-directory.
|
||||
|
||||
In particular, the C++ compiler must also know how to find the EO
|
||||
include files and the linker must find the EO libraries. Most
|
||||
probably, that means that you have to set the variables
|
||||
CPLUS_INCLUDE_PATH and LIBRARY_PATH, i.e. for a standard installation
|
||||
and using tcsh:
|
||||
setenv CPLUS_INCLUDE_PATH /usr/local/include/eo:"$CPLUS_INCLUDE_PATH"
|
||||
setenv LIBRARY_PATH /usr/local/lib:"$LIBRARY_PATH"
|
||||
|
||||
When running bash, use this:
|
||||
export CPLUS_INCLUDE_PATH=/usr/local/include/eo:"$CPLUS_INCLUDE_PATH"
|
||||
export LIBRARY_PATH=/usr/local/lib:"$LIBRARY_PATH"
|
||||
|
||||
|
||||
You can freely move the created project around. However, whenever you
|
||||
change the location of the source- or build-directories, you need to
|
||||
run
|
||||
touch configure.ac && autoreconf
|
||||
in the source-directory and
|
||||
make
|
||||
in the build-directory (which might or might not be the same for you).
|
||||
|
||||
|
||||
When you add additional source files to the project, simply add them
|
||||
to the <myproj>_SOURCES variable in src/Makefile.am. Header files
|
||||
should be added to noinst_HEADERS.
|
||||
|
||||
|
||||
See README.manual for more details.
|
||||
143
deprecated/eo/tutorial/Templates/README.manual
Normal file
143
deprecated/eo/tutorial/Templates/README.manual
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
This is the old template-directory README. Most of this information is
|
||||
still accurate and it contains more details than the new README.
|
||||
However, see there first for the creation of new projects.
|
||||
|
||||
========================================================================
|
||||
|
||||
This directory contains sample files that should make it easy to
|
||||
create an EO algorithm to evolve any type of structure
|
||||
(EO comes with two examples, bitstrings and vector of real variables,
|
||||
so you'll need this as soon as you want to evolve something else).
|
||||
|
||||
At the moment, only algorithms involving a scalar fitness (double)
|
||||
are implemented (see test dir for Pareto optimization of multiple-
|
||||
objective fitness - or be patient :-)
|
||||
|
||||
This file will help you to build the same algorithm than the ones
|
||||
in the Lesson4 of the tutorial, but with YOUR genotype instead of
|
||||
bitstrings or vector<double>. More details in Lesson5 of the tutorial.
|
||||
|
||||
It is assumed in the following that you have read the first part of
|
||||
the tutorial (Lessons 1 to 4).
|
||||
|
||||
Creating the algorithm for your genotype
|
||||
----------------------------------------
|
||||
In what follows, we will suppose that you want to evolve some data
|
||||
structure, and that you have enough programming skills to be able to
|
||||
write C code for its random initilialization, its crossover, its
|
||||
mutation and the computation of its fitness.
|
||||
|
||||
The helper script * create.sh * will create for you the files you need
|
||||
from the samples in tutorial/Templates dir, and all you'll have to do
|
||||
is to include the actual code where indicated in those files (between
|
||||
keywords START and END).
|
||||
|
||||
First, let's choose a name: let's call the new EO class eoAppli.
|
||||
All newly created classes will be named eoAppliXXX (in the file
|
||||
eoAppliXXX)
|
||||
|
||||
1- cd to the tutorial dir
|
||||
|
||||
2- create the directory for your application (let's assume you call it
|
||||
APPLICATION): type in
|
||||
|
||||
mkdir APPLICATION
|
||||
|
||||
3- go to the Templates dir
|
||||
|
||||
cd Templates
|
||||
|
||||
and run the helper script create.sh with the following arguments
|
||||
|
||||
./create.sh Appli ../APPLICATION
|
||||
|
||||
4- cd to the APPLICATION dir (cd ../APPLICATION).
|
||||
You should see there the following files:
|
||||
AppliEA.cpp the main file, includes all other, to be compiled
|
||||
Makefile with default target eoAppliEA
|
||||
eoAppli.h class eoAppli<FitT>, FitT = template fitness
|
||||
eoAppliEvalFunc.h class for the computation of fotness
|
||||
eoAppliInit.h class for genotype initlialization
|
||||
eoAppliMutation.h class for mutation
|
||||
eoAppliQuadCrossover.h class for (quadratic) crossover
|
||||
make_genotype_Appli.h helper function that create the initializer
|
||||
make_op_Appli.h helper function that creates the variatin operators
|
||||
|
||||
Note: You can go directly to step 6 and 7: you'll get a lot of
|
||||
warnings, but will be able to run an EA that does nothing!
|
||||
|
||||
5- Edit those files to suit your needs. The minimal addition you'll need
|
||||
to make are
|
||||
in eoAppli.h define your genotype
|
||||
in eoAppliInit.h define the initialization of one genotype
|
||||
in eoAppliMutation.h define the mutation of one genotype
|
||||
in eoAppliQuadCrossover.h define the crossover of 2 genotypes
|
||||
|
||||
HINT: look for keywords START and END and modify code in between.
|
||||
|
||||
6- Compile eoAppliEA.cpp. If your APPLICATION dir is in the tutorial
|
||||
dir, you don't need to modify Makefile. Just type in
|
||||
|
||||
% make
|
||||
|
||||
7- Run the resulting program:
|
||||
|
||||
% eoAppliEA
|
||||
|
||||
The default output is one line per generation with the generation
|
||||
number, the number of evaluations performed, the best and average
|
||||
fitnesses in the population.
|
||||
The algorithm stops by default after 100 generations.
|
||||
|
||||
8- Customize the parameters: copy eoAppliEA.status into
|
||||
e.g. eoAppliEA.param, edit eoAppliEA.param (uncomment the lines you
|
||||
want to become active), and run
|
||||
|
||||
% eoAppliEA @eoAppliEA.param
|
||||
|
||||
(see the Lesson 5 of the tutorial for more details now).
|
||||
|
||||
HINTS
|
||||
-----
|
||||
|
||||
1- If some new classes you create require some user parameter, you can
|
||||
either read them in the file where they are created (e.g.
|
||||
make_op_Appli.h for variation operators), or pass the eoParser to the
|
||||
constructor of the class, and read the parameter from the parser.
|
||||
|
||||
2- If you stick to privacy for the data in your EO class, you will
|
||||
probably need to write accessors to those data, as well as some public
|
||||
methods to modify them, as soon as some other methods need them too.
|
||||
|
||||
3- The sample make_op_Appli.h supposes that you ony have one crossover
|
||||
and one mutation operator. However, the code for multiple operators is
|
||||
there: you can have for instance 2 crossover operators, and choose
|
||||
among them according to relative weights (proportional choice) - same
|
||||
for mutation. Look at the operator section in eoAppliEA.cpp In
|
||||
particular, the user parameters cross1Rate and mut1Rate are totally
|
||||
useless for a single operator.
|
||||
|
||||
To add another operator, you have to create another class by mimicking
|
||||
what has been done for the first operator.
|
||||
For instance, let's suppose you want to create another mutation.
|
||||
|
||||
* duplicate the code for eoAppliMutation class
|
||||
* in the second version, change the class name (eoAppliMutation) into
|
||||
another name (let's say eoAppliBetterMutation) - you must change the
|
||||
name in the class declaration, in the constructor and in the
|
||||
className() method.
|
||||
* in the new eoAppliBetterMutation class, change the code for the
|
||||
operator() - and eventually the code for the constructor.
|
||||
* in the make_op_Appli.h file, in the mutation section, uncomment the
|
||||
lines
|
||||
mut = new eoAppliSecondMutation<Indi>(varType _anyVariable);
|
||||
_state.storeFunctor(mut);
|
||||
double mut2Rate = _parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
|
||||
propMutation.add(*mut, mut2Rate);
|
||||
|
||||
and change the name of the class from eoAppliSecondMutation to your
|
||||
name eoAppliBetterMutation (you can also change the keyword from
|
||||
mut2Rate to something more meaningful like BetterMutationRate).
|
||||
You're done!
|
||||
|
||||
In case of problem: Marc.Schoenauer@inria.fr
|
||||
21
deprecated/eo/tutorial/Templates/README.tmpl
Normal file
21
deprecated/eo/tutorial/Templates/README.tmpl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
This is an autogenerated EO project. It was (most probably) generated
|
||||
using the createEOproject.sh script in the
|
||||
<eo-dir>/tutorial/Templates directory.
|
||||
|
||||
The project has a complete build-infrastructure based on
|
||||
automake/autoconf. You can simply run "make" in this directory to have
|
||||
the program compiled. The executable build will be in src/. In case of
|
||||
problem during this step, please read the README file in the
|
||||
...eo-dir/tutorial/Templates directory.
|
||||
|
||||
After creation, the project should compile nicely - but of course the
|
||||
resulting program does noting at all but print a few silly lines.
|
||||
|
||||
Fill in the marked code-snippets in the files in src/ and you have a
|
||||
complete EA project (detailed explanations in EO Tutorial - Lesson 5).
|
||||
|
||||
Enjoy!
|
||||
|
||||
|
||||
For details, for example on moving your project around or adding new
|
||||
files, see <eo-dir>/tutorial/Templates/README.
|
||||
70
deprecated/eo/tutorial/Templates/binCrossover.tmpl
Normal file
70
deprecated/eo/tutorial/Templates/binCrossover.tmpl
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is useful in Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for simple binary crossover operators
|
||||
==============================================
|
||||
|
||||
Binary crossover operators modify the first genotype only,
|
||||
based on the second
|
||||
*/
|
||||
|
||||
#ifndef eoMyStructBinCrossover_H
|
||||
#define eoMyStructBinCrossover_H
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* THere is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO
|
||||
*/
|
||||
template<class GenotypeT>
|
||||
class eoMyStructBinCrossover: public eoBinOp<GenotypeT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor - no requirement
|
||||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoMyStructBinCrossover()
|
||||
// eoMyStructBinCrossover( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoMyStructEvalFunc object
|
||||
// END Code of Ctor of an eoMyStructEvalFunc object
|
||||
}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "eoMyStructBinCrossover"; }
|
||||
|
||||
/**
|
||||
* binCrossover - modifies first genotype only
|
||||
* @param _genotype1 The first genotype
|
||||
* @param _genotype2 The second genotype - const
|
||||
*/
|
||||
bool operator()(GenotypeT & _genotype1, const GenotypeT & _genotype2)
|
||||
{
|
||||
// START code for crossover of _genotype1 and _genotype2 objects
|
||||
|
||||
/** Requirement
|
||||
* if _genotype1 has been modified
|
||||
* return true;
|
||||
* otherwise
|
||||
* return false;
|
||||
*/
|
||||
|
||||
// END code for crossover of _genotype1 and _genotype2 objects
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoMyStructBinCrossover object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoMyStructBinCrossover object
|
||||
};
|
||||
|
||||
#endif
|
||||
39
deprecated/eo/tutorial/Templates/configure.ac.tmpl
Normal file
39
deprecated/eo/tutorial/Templates/configure.ac.tmpl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# EO template autogeneration configure.ac template
|
||||
#
|
||||
# Copyright (C) 2006 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
#
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(MyStruct, 0.1)
|
||||
AC_CONFIG_SRCDIR(src/eoMyStruct.h)
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_HEADERS(config.h)
|
||||
|
||||
dnl Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
AC_ISC_POSIX
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_STDC_HEADERS
|
||||
AC_LANG(C++)
|
||||
AC_CHECK_HEADERS([eo], [], [AC_ERROR(Evolving Objects headers are required)])
|
||||
|
||||
dnl Checks for libraries.
|
||||
AC_LANG(C++)
|
||||
AC_CHECK_LIB([eoutils], [main], [],
|
||||
AC_MSG_ERROR([Evolving Objects utility library is required.]))
|
||||
AC_CHECK_LIB([eo], [main], [],
|
||||
AC_MSG_ERROR([Evolving Objects library is required.]))
|
||||
AC_CHECK_LIB([es], [main], [],
|
||||
AC_MSG_ERROR([EO Evolutionary strategies library is required.]))
|
||||
|
||||
dnl Checks for library functions.
|
||||
|
||||
AC_OUTPUT([Makefile src/Makefile])
|
||||
|
||||
|
||||
dnl Local Variables:
|
||||
dnl coding: iso-8859-1
|
||||
dnl mode: autoconf
|
||||
dnl fill-column: 80
|
||||
dnl End:
|
||||
64
deprecated/eo/tutorial/Templates/continue.tmpl
Normal file
64
deprecated/eo/tutorial/Templates/continue.tmpl
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for continuator in EO, i.e. stopping conditions for EO algorithms
|
||||
==========================================================================
|
||||
*/
|
||||
|
||||
#ifndef _eoMyStructContinue_h
|
||||
#define _eoMyStructContinue_h
|
||||
|
||||
// include the base definition of eoContinue
|
||||
#include <eoContinue.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* ATTENTION, class EOT *must* derive from EO, as operator() will
|
||||
* be called with an eoPop<EOT>
|
||||
*/
|
||||
template< class EOT>
|
||||
class eoMyStructContinue: public eoContinue<EOT> {
|
||||
public:
|
||||
/**
|
||||
* Ctor - no requirement
|
||||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoMyStructContinue()
|
||||
// eoMyStructBinCrossover( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoMyStructEvalFunc object
|
||||
// END Code of Ctor of an eoMyStructEvalFunc object
|
||||
}
|
||||
|
||||
|
||||
/** Returns false when you want to stop
|
||||
*
|
||||
* @param _pop an eoPop
|
||||
*/
|
||||
virtual bool operator() ( const eoPop<EOT>& _pop )
|
||||
{
|
||||
bool stopCondition ; // to store the stopping condition
|
||||
// START Code of computation of stopping condition
|
||||
// stopCondition = blablabla
|
||||
// END Code of computation of stopping condition
|
||||
if (stopCondition) // the algo will stop upon return FALSE
|
||||
{
|
||||
cout << "STOP in eoMyStructContinue \n";
|
||||
return false;
|
||||
}
|
||||
return true; // == do not stop
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoMyStructContinue object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoMyStructContinue object
|
||||
};
|
||||
|
||||
#endif
|
||||
116
deprecated/eo/tutorial/Templates/createEOproject.sh
Executable file
116
deprecated/eo/tutorial/Templates/createEOproject.sh
Executable file
|
|
@ -0,0 +1,116 @@
|
|||
#! /bin/tcsh -f
|
||||
#
|
||||
# Script to create a completely new EO project from templates
|
||||
#
|
||||
# Originally by Marc Schoenauer
|
||||
# Copyright (C) 2006 Jochen Kpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
if ($PWD:t != Templates) then
|
||||
echo "You must start this shell script from the EO Template directory"
|
||||
exit
|
||||
endif
|
||||
|
||||
if ($#argv < 1) then
|
||||
echo "Usage: $0 ApplicationName [TargetDirName]"
|
||||
echo " This will create ../TargetDirName if necessary (default dir name = ApplicationName),"
|
||||
echo " and will also put all the files there that are strictly necessary to compile and run"
|
||||
echo " your application."
|
||||
exit
|
||||
endif
|
||||
|
||||
# we're going to do something
|
||||
echo " "
|
||||
if ($#argv == 1) then
|
||||
set TargetDir = /tmp/$1
|
||||
else
|
||||
set TargetDir = $2
|
||||
endif
|
||||
if ( -d $TargetDir ) then
|
||||
echo "Warning: The target directory does exist already."
|
||||
echo -n "Overwrite (yes/no)? "
|
||||
set REP = $<
|
||||
if ($REP != "yes") then
|
||||
echo "Stopping, nothing done!"
|
||||
exit
|
||||
endif
|
||||
else if ( -e $TargetDir ) then
|
||||
echo "Warning: $TargetDir exist but isn't a directory."
|
||||
echo "Stopping, nothing done!"
|
||||
exit
|
||||
endif
|
||||
mkdir -p $TargetDir/src
|
||||
|
||||
|
||||
# creating files
|
||||
echo "Creating source files for application $1 in $TargetDir/src"
|
||||
sed s/MyStruct/$1/g eoMyStruct.tmpl > $TargetDir/src/eo$1.h
|
||||
sed s/MyStruct/$1/g init.tmpl > $TargetDir/src/eo$1Init.h
|
||||
sed s/MyStruct/$1/g stat.tmpl > $TargetDir/src/eo$1Stat.h
|
||||
sed s/MyStruct/$1/g evalFunc.tmpl > $TargetDir/src/eo$1EvalFunc.h
|
||||
sed s/MyStruct/$1/g mutation.tmpl > $TargetDir/src/eo$1Mutation.h
|
||||
sed s/MyStruct/$1/g quadCrossover.tmpl > $TargetDir/src/eo$1QuadCrossover.h
|
||||
sed s/MyStruct/$1/g MyStructSEA.cpp > $TargetDir/src/$1EA.cpp
|
||||
|
||||
echo "Creating build-support files for application $1 in $TargetDir"
|
||||
sed s/MyStruct/$1/g configure.ac.tmpl > $TargetDir/configure.ac
|
||||
sed s/MyStruct/$1/g Makefile.am.top-tmpl > $TargetDir/Makefile.am
|
||||
sed s/MyStruct/$1/g Makefile.am.src-tmpl > $TargetDir/src/Makefile.am
|
||||
|
||||
|
||||
##### Build a ready-to-use CMake config
|
||||
|
||||
# need paths
|
||||
set eo_src_var = 'EO_SRC_DIR'
|
||||
echo "$PWD" > temp.txt
|
||||
sed -e "s/\//\\\//g" temp.txt > temp2.txt
|
||||
set safe_eo_path = `cat temp2.txt`
|
||||
set safe_eo_path = "$safe_eo_path\/..\/.."
|
||||
|
||||
set eo_bin_var = 'EO_BIN_DIR'
|
||||
set eo_src_path = "$safe_eo_path"
|
||||
set eo_bin_path = "$safe_eo_path\/build"
|
||||
|
||||
sed -e "s/MyStruct/$1/g" -e "s/$eo_src_var/$eo_src_path/g" -e "s/$eo_bin_var/$eo_bin_path/g" CMakeLists.txt.top-tmpl > $TargetDir/CMakeLists.txt
|
||||
sed -e "s/MyStruct/$1/g" CMakeLists.txt.src-tmpl > $TargetDir/src/CMakeLists.txt
|
||||
|
||||
# remove temp dirs
|
||||
rm -f temp.txt temp2.txt
|
||||
|
||||
#####
|
||||
|
||||
|
||||
sed s/MyStruct/$1/g README.tmpl > $TargetDir/README
|
||||
touch $TargetDir/AUTHORS
|
||||
touch $TargetDir/COPYING
|
||||
touch $TargetDir/ChangeLog
|
||||
touch $TargetDir/INSTALL
|
||||
touch $TargetDir/NEWS
|
||||
|
||||
echo "Successfully created project $1 in $TargetDir!"
|
||||
echo "Start building the new project"
|
||||
|
||||
|
||||
### building new project with the Autotools
|
||||
#cd $TargetDir
|
||||
#aclocal || exit
|
||||
#autoheader || exit
|
||||
#automake --add-missing --copy --gnu || exit
|
||||
|
||||
# !!!!! uncompatible option: --force-missing for the latest version of automake
|
||||
|
||||
#autoconf || exit
|
||||
#./configure || exit
|
||||
#make || exit
|
||||
|
||||
# New: building new project using CMake
|
||||
cd $TargetDir
|
||||
#mkdir build
|
||||
#cd build
|
||||
cmake . || exit
|
||||
make || exit
|
||||
|
||||
|
||||
# done
|
||||
echo ""
|
||||
echo "Project $1 successfully build in $TargetDir!"
|
||||
echo "Implement your code and enjoy."
|
||||
117
deprecated/eo/tutorial/Templates/eoMyStruct.tmpl
Normal file
117
deprecated/eo/tutorial/Templates/eoMyStruct.tmpl
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
|
||||
Mandatory:
|
||||
- a default constructor (constructor without any argument)
|
||||
- the I/O functions (readFrom and printOn)
|
||||
|
||||
However, if you are using dynamic memory, there are 2 places
|
||||
to allocate it: the default constructor (if possible?), or, more in
|
||||
the EO spirit, the eoInit object, that you will need to write anyway
|
||||
(template file init.tmpl).
|
||||
|
||||
But remember that a COPY CONSTRUCTOR will be used in many places in EO,
|
||||
so make sure that the default copy constructor works, or, even better,
|
||||
do write your own if in doubt.
|
||||
And of course write the corresponding destructor!
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _eoMyStruct_h
|
||||
#define _eoMyStruct_h
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
|
||||
* Note that you MUST derive your structure from EO<fitT>
|
||||
* but you MAY use some other already prepared class in the hierarchy
|
||||
* like eoVector for instance, if you handle a vector of something....
|
||||
|
||||
* If you create a structure from scratch,
|
||||
* the only thing you need to provide are
|
||||
* a default constructor
|
||||
* IO routines printOn and readFrom
|
||||
*
|
||||
* Note that operator<< and operator>> are defined at EO level
|
||||
* using these routines
|
||||
*/
|
||||
template< class FitT>
|
||||
class eoMyStruct: public EO<FitT> {
|
||||
public:
|
||||
/** Ctor: you MUST provide a default ctor.
|
||||
* though such individuals will generally be processed
|
||||
* by some eoInit object
|
||||
*/
|
||||
eoMyStruct()
|
||||
{
|
||||
// START Code of default Ctor of an eoMyStruct object
|
||||
// END Code of default Ctor of an eoMyStruct object
|
||||
}
|
||||
|
||||
/** Copy Ctor: you MUST provide a copy ctor if the default
|
||||
* one is not what you want
|
||||
* If this is the case, uncomment and fill the following
|
||||
*/
|
||||
/*
|
||||
eoMyStruct(const eoMyStruct &)
|
||||
{
|
||||
// START Code of copy Ctor of an eoMyStruct object
|
||||
// END Code of copy Ctor of an eoMyStruct object
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
virtual ~eoMyStruct()
|
||||
{
|
||||
// START Code of Destructor of an eoEASEAGenome object
|
||||
// END Code of Destructor of an eoEASEAGenome object
|
||||
}
|
||||
|
||||
virtual string className() const { return "eoMyStruct"; }
|
||||
|
||||
/** printing... */
|
||||
void printOn(ostream& os) const
|
||||
{
|
||||
// First write the fitness
|
||||
EO<FitT>::printOn(os);
|
||||
os << ' ';
|
||||
// START Code of default output
|
||||
|
||||
/** HINTS
|
||||
* in EO we systematically write the sizes of things before the things
|
||||
* so readFrom is easier to code (see below)
|
||||
*/
|
||||
|
||||
// END Code of default output
|
||||
}
|
||||
|
||||
/** reading...
|
||||
* of course, your readFrom must be able to read what printOn writes!!!
|
||||
*/
|
||||
void readFrom(istream& is)
|
||||
{
|
||||
// of course you should read the fitness first!
|
||||
EO<FitT>::readFrom(is);
|
||||
// START Code of input
|
||||
|
||||
/** HINTS
|
||||
* remember the eoMyStruct object will come from the default ctor
|
||||
* this is why having the sizes written out is useful
|
||||
*/
|
||||
|
||||
// END Code of input
|
||||
}
|
||||
|
||||
private: // put all data here
|
||||
// START Private data of an eoMyStruct object
|
||||
// END Private data of an eoMyStruct object
|
||||
};
|
||||
|
||||
#endif
|
||||
65
deprecated/eo/tutorial/Templates/evalFunc.tmpl
Normal file
65
deprecated/eo/tutorial/Templates/evalFunc.tmpl
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for evaluator in EO, a functor that computes the fitness of an EO
|
||||
==========================================================================
|
||||
*/
|
||||
|
||||
#ifndef _eoMyStructEvalFunc_h
|
||||
#define _eoMyStructEvalFunc_h
|
||||
|
||||
// include whatever general include you need
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
// include the base definition of eoEvalFunc
|
||||
#include "eoEvalFunc.h"
|
||||
|
||||
/**
|
||||
Always write a comment in this format before class definition
|
||||
if you want the class to be documented by Doxygen
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoMyStructEvalFunc : public eoEvalFunc<EOT>
|
||||
{
|
||||
public:
|
||||
/// Ctor - no requirement
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoMyStructEvalFunc()
|
||||
// eoMyStructEvalFunc( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoMyStructEvalFunc object
|
||||
// END Code of Ctor of an eoMyStructEvalFunc object
|
||||
}
|
||||
|
||||
/** Actually compute the fitness
|
||||
*
|
||||
* @param EOT & _eo the EO object to evaluate
|
||||
* it should stay templatized to be usable
|
||||
* with any fitness type
|
||||
*/
|
||||
void operator()(EOT & _eo)
|
||||
{
|
||||
// test for invalid to avoid recomputing fitness of unmodified individuals
|
||||
if (_eo.invalid())
|
||||
{
|
||||
double fit; // to hold fitness value
|
||||
// START Code of computation of fitness of the eoMyStruct object
|
||||
// fit = blablabla
|
||||
// END Code of computation of fitness of the eoMyStruct object
|
||||
_eo.fitness(fit);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoMyStructEvalFunc object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoMyStructEvalFunc object
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
57
deprecated/eo/tutorial/Templates/init.tmpl
Normal file
57
deprecated/eo/tutorial/Templates/init.tmpl
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for EO objects initialization in EO
|
||||
============================================
|
||||
*/
|
||||
|
||||
#ifndef _eoMyStructInit_h
|
||||
#define _eoMyStructInit_h
|
||||
|
||||
// include the base definition of eoInit
|
||||
#include <eoInit.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* There is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO (e.g. to initialize
|
||||
* atoms of an eoVector you will need an eoInit<AtomType>)
|
||||
*/
|
||||
template <class GenotypeT>
|
||||
class eoMyStructInit: public eoInit<GenotypeT> {
|
||||
public:
|
||||
/// Ctor - no requirement
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoMyStructInit()
|
||||
// eoMyStructInit( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoMyStructInit object
|
||||
// END Code of Ctor of an eoMyStructInit object
|
||||
}
|
||||
|
||||
|
||||
/** initialize a genotype
|
||||
*
|
||||
* @param _genotype generally a genotype that has been default-constructed
|
||||
* whatever it contains will be lost
|
||||
*/
|
||||
void operator()(GenotypeT & _genotype)
|
||||
{
|
||||
// START Code of random initialization of an eoMyStruct object
|
||||
// END Code of random initialization of an eoMyStruct object
|
||||
_genotype.invalidate(); // IMPORTANT in case the _genotype is old
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoMyStructInit object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoMyStructInit object
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for general operators
|
||||
===============================
|
||||
i.e. that takes any number of parents and generates any number of offspring
|
||||
|
||||
a GenOp that creates less offspring than there are parents
|
||||
|
||||
Second version, get parents using an external eoSelectOne
|
||||
*/
|
||||
|
||||
#ifndef eoLessOffspringExternalSelectorGenOp_H
|
||||
#define eoLessOffspringExternalSelectorGenOp_H
|
||||
|
||||
#include <eoGenOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* ATTENTION, class EOT *must* derive from EO, as method invalidate()
|
||||
* must be called if the genotypes of the indis is modified
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoLessOffspringExternalSelectorGenOp: public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
*/
|
||||
eoLessOffspringExternalSelectorGenOp(eoSelectOne<EOT> & _sel, paramType _anyParameter) :
|
||||
sel(_sel), anyParameter(_anyParameter) {}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "eoLessOffspringExternalSelectorGenOp"; }
|
||||
|
||||
/// The TOTAL number of offspring (here = nb of parents modified in place)
|
||||
unsigned max_production(void) { return NbLeftParents; }
|
||||
|
||||
/**
|
||||
* eoShrinkGen operator - modifies some parents in the populator
|
||||
* using extra "parents" selected from an external selector
|
||||
*
|
||||
* @param _pop a POPULATOR (not a simple population)
|
||||
*/
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
{
|
||||
// First, select as many parents as you will have offspring
|
||||
EOT& parent1 = *_plop; // select the first parent
|
||||
++_plop; // advance once for each selected parents
|
||||
...
|
||||
EOT& parentN = *_plop; // say you want N offspring
|
||||
|
||||
// get extra parents - use private selector
|
||||
// _plop.source() is the eoPop<EOT> used by _plop to get parents
|
||||
// WARNING: you are not allowed to modify them (mandatory "const")
|
||||
const EOT& parentN+1 = sel(_plop.source());
|
||||
...
|
||||
const EOT& parentN+K = sel(_plop.source());
|
||||
|
||||
// modify (in place) the "true" parents
|
||||
// (i.e. parent1, ..., parentsN)
|
||||
...
|
||||
|
||||
// invalidate fitnesses of modified parents
|
||||
parent1.invalidate();
|
||||
...
|
||||
parentN.invalidate();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
eoSelectOne<EOT> & sel;
|
||||
paramType anyParameter
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for general operators
|
||||
===============================
|
||||
i.e. that takes any number of parents and generates any number of offspring
|
||||
|
||||
a GenOp that creates less offspring than there are parents
|
||||
|
||||
First version, get parents from populator using the imbedded select() method
|
||||
*/
|
||||
|
||||
#ifndef eoLessOffspringSameSelectorGenOp_H
|
||||
#define eoLessOffspringSameSelectorGenOp_H
|
||||
|
||||
#include <eoGenOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* ATTENTION, class EOT *must* derive from EO, as method invalidate()
|
||||
* must be called if the genotypes of the indis is modified
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoLessOffspringSameSelectorGenOp: public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
*/
|
||||
eoLessOffspringSameSelectorGenOp(paramType _anyParameter) :
|
||||
anyParameter(_anyParameter) {}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "eoLessOffspringSameSelectorGenOp"; }
|
||||
|
||||
/// The TOTAL number of offspring (here = nb of remaining modified parents)
|
||||
unsigned max_production(void) { return NbLeftParents; }
|
||||
|
||||
/**
|
||||
* eoLesOffspringSameSelectorGenOp operator -
|
||||
* gets extra parents from the populator
|
||||
*
|
||||
* @param _pop a POPULATOR (not a simple population)
|
||||
*/
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
{
|
||||
// First, select as many parents as you will have offspring
|
||||
EOT& parent1 = *_plop; // select the first parent
|
||||
++_plop; // advance once for each selected parents
|
||||
...
|
||||
EOT& parentN = *_plop; // say you want N offspring
|
||||
|
||||
// Now select extra parents from the populator
|
||||
EOT& parentN+1 = _plop.select();
|
||||
...
|
||||
EOT& parentN+K = _plop.select();
|
||||
|
||||
// modify the first N parents
|
||||
...
|
||||
|
||||
// oh right, and invalidate their fitnesses
|
||||
parent1.invalidate();
|
||||
...
|
||||
parentN.invalidate();
|
||||
}
|
||||
|
||||
private:
|
||||
paramType anyParameter
|
||||
};
|
||||
|
||||
#endif
|
||||
128
deprecated/eo/tutorial/Templates/make_MyStruct.cpp
Normal file
128
deprecated/eo/tutorial/Templates/make_MyStruct.cpp
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for creating a new representation in EO
|
||||
================================================
|
||||
|
||||
This is the template file that allows separate compilation of
|
||||
everything that is representation independant (evolution engine and
|
||||
general output) for an Evolutionary Algorithm with scalar fitness.
|
||||
|
||||
It includes of course the definition of the genotype (eoMyStruct.h) and
|
||||
is written like the make_xxx.cpp files in dirs src/ga (for bitstrings)
|
||||
and src/es (for real vectors).
|
||||
|
||||
*/
|
||||
|
||||
// Miscilaneous include and declaration
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// eo general include
|
||||
#include "eo"
|
||||
// the real bounds (not yet in general eo include)
|
||||
#include "utils/eoRealVectorBounds.h"
|
||||
|
||||
// include here whatever specific files for your representation
|
||||
// Basically, this should include at least the following
|
||||
|
||||
/** definition of representation:
|
||||
* class eoMyStruct MUST derive from EO<FitT> for some fitness
|
||||
*/
|
||||
#include "eoMyStruct.h"
|
||||
|
||||
// create an initializer: this is NOT representation-independent
|
||||
// and will be done in the main file
|
||||
// However, should you decide to freeze that part, you could use the
|
||||
// following (and remove it from the main file, of course!!!)
|
||||
//------------------------------------------------------------------
|
||||
// #include "make_genotype_MyStruct.h"
|
||||
// eoInit<eoMyStruct<double>> & make_genotype(eoParser& _parser, eoState&_state, eoMyStruct<double> _eo)
|
||||
// {
|
||||
// return do_make_genotype(_parser, _state, _eo);
|
||||
// }
|
||||
|
||||
// eoInit<eoMyStruct<eoMinimizingFitness>> & make_genotype(eoParser& _parser, eoState&_state, eoMyStruct<eoMinimizingFitness> _eo)
|
||||
// {
|
||||
// return do_make_genotype(_parser, _state, _eo);
|
||||
// }
|
||||
|
||||
// same thing for the variation operaotrs
|
||||
//---------------------------------------
|
||||
// #include "make_op_MyStruct.h"
|
||||
// eoGenOp<eoMyStruct<double>>& make_op(eoParser& _parser, eoState& _state, eoInit<eoMyStruct<double>>& _init)
|
||||
// {
|
||||
// return do_make_op(_parser, _state, _init);
|
||||
// }
|
||||
|
||||
// eoGenOp<eoMyStruct<eoMinimizingFitness>>& make_op(eoParser& _parser, eoState& _state, eoInit<eoMyStruct<eoMinimizingFitness>>& _init)
|
||||
// {
|
||||
// return do_make_op(_parser, _state, _init);
|
||||
// }
|
||||
|
||||
// The following modules use ***representation independent*** routines
|
||||
|
||||
// how to initialize the population
|
||||
// it IS representation independent if an eoInit is given
|
||||
#include <make_pop.h>
|
||||
eoPop<eoMyStruct<double> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoMyStruct<double> > & _init)
|
||||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
eoPop<eoMyStruct<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoMyStruct<eoMinimizingFitness> > & _init)
|
||||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
// the stopping criterion
|
||||
#include <make_continue.h>
|
||||
eoContinue<eoMyStruct<double> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoMyStruct<double> > & _eval)
|
||||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
eoContinue<eoMyStruct<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoMyStruct<eoMinimizingFitness> > & _eval)
|
||||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
// outputs (stats, population dumps, ...)
|
||||
#include <make_checkpoint.h>
|
||||
eoCheckPoint<eoMyStruct<double> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoMyStruct<double> >& _eval, eoContinue<eoMyStruct<double> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
eoCheckPoint<eoMyStruct<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoMyStruct<eoMinimizingFitness> >& _eval, eoContinue<eoMyStruct<eoMinimizingFitness> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
// evolution engine (selection and replacement)
|
||||
#include <make_algo_scalar.h>
|
||||
eoAlgo<eoMyStruct<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoMyStruct<double> >& _eval, eoContinue<eoMyStruct<double> >& _continue, eoGenOp<eoMyStruct<double> >& _op)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
eoAlgo<eoMyStruct<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoMyStruct<eoMinimizingFitness> >& _eval, eoContinue<eoMyStruct<eoMinimizingFitness> >& _continue, eoGenOp<eoMyStruct<eoMinimizingFitness> >& _op)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
// no template for that one
|
||||
#include <make_run.h>
|
||||
void run_ea(eoAlgo<eoMyStruct<double> >& _ga, eoPop<eoMyStruct<double> >& _pop)
|
||||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
void run_ea(eoAlgo<eoMyStruct<eoMinimizingFitness> >& _ga, eoPop<eoMyStruct<eoMinimizingFitness> >& _pop)
|
||||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
73
deprecated/eo/tutorial/Templates/make_genotype_MyStruct.h
Normal file
73
deprecated/eo/tutorial/Templates/make_genotype_MyStruct.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// make_genotype.h
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _make_genotype_h
|
||||
#define _make_genotype_h
|
||||
|
||||
#include <eoMyStruct.h>
|
||||
#include <eoMyStructInit.h>
|
||||
// also need the parser and param includes
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoState.h>
|
||||
|
||||
|
||||
/*
|
||||
* This fuction does the create an eoInit<eoMyStruct>
|
||||
*
|
||||
* It could be here tempatized only on the fitness, as it can be used
|
||||
* to evolve structures with any fitness.
|
||||
* However, for consistency reasons, it was finally chosen, as in
|
||||
* the rest of EO, to templatize by the full EOT, as this eventually
|
||||
* allows to choose the type of genotype at run time (see in es dir)
|
||||
*
|
||||
* It returns an eoInit<EOT> that can later be used to initialize
|
||||
* the population (see make_pop.h).
|
||||
*
|
||||
* It uses a parser (to get user parameters) and a state (to store the memory)
|
||||
* the last argument is to disambiguate the call upon different instanciations.
|
||||
*
|
||||
* WARNING: that last argument will generally be the result of calling
|
||||
* the default ctor of EOT, resulting in most cases in an EOT
|
||||
* that is ***not properly initialized***
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
|
||||
{
|
||||
// read any useful parameter here from the parser
|
||||
// the param itself will belong to the parser (as far as memory is concerned)
|
||||
|
||||
// paramType & param = _parser.createParam(deafultValue, "Keyword", "Comment to appear in help and status", 'c',"Section of status file").value();
|
||||
|
||||
// Then built the initializer - a pointer, stored in the eoState
|
||||
eoInit<EOT>* init = new eoMyStructInit<EOT> /* ( param ) */ ;
|
||||
// store in state
|
||||
_state.storeFunctor(init);
|
||||
// and return a reference
|
||||
return *init;
|
||||
}
|
||||
|
||||
#endif
|
||||
210
deprecated/eo/tutorial/Templates/make_op_MyStruct.h
Normal file
210
deprecated/eo/tutorial/Templates/make_op_MyStruct.h
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// make_op_MyStruct.h
|
||||
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2001
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _make_op_MyStruct_h
|
||||
#define _make_op_MyStruct_h
|
||||
|
||||
// the operators
|
||||
#include <eoOp.h>
|
||||
#include <eoGenOp.h>
|
||||
#include <eoCloneOps.h>
|
||||
#include <eoOpContainer.h>
|
||||
// combinations of simple eoOps (eoMonOp and eoQuadOp)
|
||||
#include <eoProportionalCombinedOp.h>
|
||||
|
||||
/** definition of mutation:
|
||||
* class eoMyStructMonop MUST derive from eoMonOp<eoMyStruct>
|
||||
*/
|
||||
#include "eoMyStructMutation.h"
|
||||
|
||||
/** definition of crossover (either as eoBinOp (2->1) or eoQuadOp (2->2):
|
||||
* class eoMyStructBinCrossover MUST derive from eoBinOp<eoMyStruct>
|
||||
* OR
|
||||
* class eoMyStructQuadCrossover MUST derive from eoQuadOp<eoMyStruct>
|
||||
*/
|
||||
// #include "eoMyStructBinOp.h"
|
||||
// OR
|
||||
#include "eoMyStructQuadCrossover.h"
|
||||
|
||||
// also need the parser and state includes
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoState.h>
|
||||
|
||||
|
||||
/////////////////// variation operators ///////////////
|
||||
// canonical (crossover + mutation) only at the moment //
|
||||
|
||||
/*
|
||||
* This function builds the operators that will be applied to the eoMyStruct
|
||||
*
|
||||
* It uses a parser (to get user parameters), a state (to store the memory)
|
||||
* the last parameter is an eoInit: if some operator needs some info
|
||||
* about the genotypes, the init has it all (e.g. bounds, ...)
|
||||
* Simply do
|
||||
* EOT myEO;
|
||||
* _init(myEO);
|
||||
* and myEO is then an ACTUAL object
|
||||
*
|
||||
* As usual, the template is the complete EOT even though only the fitness
|
||||
* is actually templatized here: the following only applies to eoMyStruct
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EOT>& _init)
|
||||
{
|
||||
// this is a temporary version, while Maarten codes the full tree-structured
|
||||
// general operator input
|
||||
// BTW we must leave that simple version available somehow, as it is the one
|
||||
// that 90% people use!
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Variation operators
|
||||
////////////////////////////
|
||||
// read crossover and mutations, combine each in a proportional Op
|
||||
// and create the eoGenOp that calls crossover at rate pCross
|
||||
// then mutation with rate pMut
|
||||
|
||||
// the crossovers
|
||||
/////////////////
|
||||
|
||||
// here we can have eoQuadOp (2->2) only - no time for the eoBinOp case
|
||||
|
||||
// you can have more than one - combined in a proportional way
|
||||
|
||||
// first, define the crossover objects and read their rates from the parser
|
||||
|
||||
// A first crossover
|
||||
eoQuadOp<Indi> *cross = new eoMyStructQuadCrossover<Indi> /* (varType _anyVariable) */;
|
||||
// store in the state
|
||||
_state.storeFunctor(cross);
|
||||
|
||||
// read its relative rate in the combination
|
||||
double cross1Rate = _parser.createParam(1.0, "cross1Rate", "Relative rate for crossover 1", '1', "Variation Operators").value();
|
||||
|
||||
// and create the combined operator with this one
|
||||
eoPropCombinedQuadOp<Indi> *propXover =
|
||||
new eoPropCombinedQuadOp<Indi>(*cross, cross1Rate);
|
||||
// and of course stor it in the state
|
||||
_state.storeFunctor(propXover);
|
||||
|
||||
|
||||
// Optional: A second(and third, and ...) crossover
|
||||
// of course you must create the corresponding classes
|
||||
// and all ***MUST*** derive from eoQuadOp<Indi>
|
||||
|
||||
/* Uncomment if necessary - and replicate as many time as you need
|
||||
cross = new eoMyStructSecondCrossover<Indi>(varType _anyVariable);
|
||||
_state.storeFunctor(cross);
|
||||
double cross2Rate = _parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value();
|
||||
propXover.add(*cross, cross2Rate);
|
||||
*/
|
||||
// if you want some gentle output, the last one shoudl be like
|
||||
// propXover.add(*cross, crossXXXRate, true);
|
||||
|
||||
|
||||
// the mutation: same story
|
||||
////////////////
|
||||
// you can have more than one - combined in a proportional way
|
||||
|
||||
// for each mutation,
|
||||
// - define the mutator object
|
||||
// - read its rate from the parser
|
||||
// - add it to the proportional combination
|
||||
|
||||
// a first mutation
|
||||
eoMonOp<Indi> *mut = new eoMyStructMutation<Indi>/* (varType _anyVariable) */;
|
||||
_state.storeFunctor(mut);
|
||||
// its relative rate in the combination
|
||||
double mut1Rate = _parser.createParam(1.0, "mut1Rate", "Relative rate for mutation 1", '1', "Variation Operators").value();
|
||||
// and the creation of the combined operator with this one
|
||||
eoPropCombinedMonOp<Indi> *propMutation = new eoPropCombinedMonOp<Indi>(*mut, mut1Rate);
|
||||
_state.storeFunctor(propMutation);
|
||||
|
||||
// Optional: A second(and third, and ...) mutation with their rates
|
||||
// of course you must create the corresponding classes
|
||||
// and all ***MUST*** derive from eoMonOp<Indi>
|
||||
|
||||
/* Uncomment if necessary - and replicate as many time as you need
|
||||
mut = new eoMyStructSecondMutation<Indi>(varType _anyVariable);
|
||||
_state.storeFunctor(mut);
|
||||
double mut2Rate = _parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
|
||||
propMutation.add(*mut, mut2Rate);
|
||||
*/
|
||||
// if you want some gentle output, the last one shoudl be like
|
||||
// propMutation.add(*mut, mutXXXRate, true);
|
||||
|
||||
// end of crossover and mutation definitions
|
||||
////////////////////////////////////////////
|
||||
|
||||
// END Modify definitions of objects by eventually add parameters
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
|
||||
// from now on, you do not need to modify anything
|
||||
// though you CAN add things to the checkpointing (see tutorial)
|
||||
|
||||
// now build the eoGenOp:
|
||||
// to simulate SGA (crossover with proba pCross + mutation with proba pMut
|
||||
// we must construct
|
||||
// a sequential combination of
|
||||
// with proba 1, a proportional combination of
|
||||
// a QuadCopy and our crossover
|
||||
// with proba pMut, our mutation
|
||||
|
||||
// but of course you're free to use any smart combination you could think of
|
||||
// especially, if you have to use eoBinOp rather than eoQuad Op youùll have
|
||||
// to modify that part
|
||||
|
||||
// First read the individual level parameters
|
||||
eoValueParam<double>& pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
|
||||
throw runtime_error("Invalid pCross");
|
||||
|
||||
eoValueParam<double>& pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
|
||||
throw runtime_error("Invalid pMut");
|
||||
|
||||
|
||||
// the crossover - with probability pCross
|
||||
eoProportionalOp<Indi> * propOp = new eoProportionalOp<Indi> ;
|
||||
_state.storeFunctor(propOp);
|
||||
eoQuadOp<Indi> *ptQuad = new eoQuadCloneOp<Indi>;
|
||||
_state.storeFunctor(ptQuad);
|
||||
propOp->add(*propXover, pCrossParam.value()); // crossover, with proba pcross
|
||||
propOp->add(*ptQuad, 1-pCrossParam.value()); // nothing, with proba 1-pcross
|
||||
|
||||
// now the sequential
|
||||
eoSequentialOp<Indi> *op = new eoSequentialOp<Indi>;
|
||||
_state.storeFunctor(op);
|
||||
op->add(*propOp, 1.0); // always do combined crossover
|
||||
op->add(*propMutation, pMutParam.value()); // then mutation, with proba pmut
|
||||
|
||||
// that's it - return a reference
|
||||
return *op;
|
||||
}
|
||||
#endif
|
||||
77
deprecated/eo/tutorial/Templates/moreOffspringGenOp.tmpl
Normal file
77
deprecated/eo/tutorial/Templates/moreOffspringGenOp.tmpl
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for general operators
|
||||
===============================
|
||||
i.e. that takes any number of parents and generates any number of offspring
|
||||
|
||||
Here, a GenOp that creates more (or same number of) offspring
|
||||
than there are parents
|
||||
*/
|
||||
|
||||
#ifndef eoMoreOffspringGenOp_H
|
||||
#define eoMoreOffspringGenOp_H
|
||||
|
||||
#include <eoGenOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* ATTENTION, class EOT *must* derive from EO, as method invalidate()
|
||||
* must be called if the genotypes of the indis is modified
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoMoreOffspringGenOp: public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
*/
|
||||
eoMoreOffspringGenOp(paramType _anyParameter) :
|
||||
anyParameter(_anyParameter) {}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "eoMoreOffspringGenOp"; }
|
||||
|
||||
/// The TOTAL number of offspring (including modified parents)
|
||||
unsigned max_production(void) { return NbOffspring; }
|
||||
|
||||
/**
|
||||
* eoMoreOffspringGenOp operator - eventually modifies the parents
|
||||
* BUT does generate more offspring
|
||||
*
|
||||
* @param _pop a POPULATOR (not a simple population)
|
||||
*/
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
{
|
||||
EOT& parent1 = *_plop; // select the first parent
|
||||
++_plop; // advance once for each selected parents
|
||||
...
|
||||
EOT& parentN = *_plop; // select the last parent
|
||||
// don't advance after the last one: _plop always
|
||||
// points to the last that has already been treated
|
||||
|
||||
// apply operator to the parents (modifying them AND generating
|
||||
// new individuals ofs1, ofs2, ..., ofsN
|
||||
++_plop; // advance before each insertion
|
||||
_plop.insert(ofs1);
|
||||
...
|
||||
++_plop; // advance before each insertion
|
||||
_plop.insert(ofsN);
|
||||
|
||||
// oh right, and invalidate fitnesses of modified parents
|
||||
parent1.invalidate();
|
||||
...
|
||||
parentN.invalidate();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
paramType anyParameter
|
||||
};
|
||||
|
||||
#endif
|
||||
68
deprecated/eo/tutorial/Templates/mutation.tmpl
Normal file
68
deprecated/eo/tutorial/Templates/mutation.tmpl
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is useful in Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for simple mutation operators
|
||||
======================================
|
||||
*/
|
||||
|
||||
#ifndef eoMyStructMutation_H
|
||||
#define eoMyStructMutation_H
|
||||
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* THere is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO
|
||||
*/
|
||||
template<class GenotypeT>
|
||||
class eoMyStructMutation: public eoMonOp<GenotypeT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor - no requirement
|
||||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoMyStructMutation()
|
||||
// eoMyStructMutation( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoMyStructEvalFunc object
|
||||
// END Code of Ctor of an eoMyStructEvalFunc object
|
||||
}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "eoMyStructMutation"; }
|
||||
|
||||
/**
|
||||
* modifies the parent
|
||||
* @param _genotype The parent genotype (will be modified)
|
||||
*/
|
||||
bool operator()(GenotypeT & _genotype)
|
||||
{
|
||||
bool isModified(true);
|
||||
// START code for mutation of the _genotype object
|
||||
|
||||
/** Requirement
|
||||
* if (_genotype has been modified)
|
||||
* isModified = true;
|
||||
* else
|
||||
* isModified = false;
|
||||
*/
|
||||
return isModified;
|
||||
// END code for mutation of the _genotype object
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoMyStructMutation object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoMyStructMutation object
|
||||
};
|
||||
|
||||
#endif
|
||||
71
deprecated/eo/tutorial/Templates/quadCrossover.tmpl
Normal file
71
deprecated/eo/tutorial/Templates/quadCrossover.tmpl
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for simple quadratic crossover operators
|
||||
=================================================
|
||||
|
||||
Quadratic crossover operators modify the both genotypes
|
||||
*/
|
||||
|
||||
#ifndef eoMyStructQuadCrossover_H
|
||||
#define eoMyStructQuadCrossover_H
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* THere is NO ASSUMPTION on the class GenoypeT.
|
||||
* In particular, it does not need to derive from EO
|
||||
*/
|
||||
template<class GenotypeT>
|
||||
class eoMyStructQuadCrossover: public eoQuadOp<GenotypeT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor - no requirement
|
||||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoMyStructQuadCrossover()
|
||||
// eoMyStructQuadCrossover( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoMyStructEvalFunc object
|
||||
// END Code of Ctor of an eoMyStructEvalFunc object
|
||||
}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
string className() const { return "eoMyStructQuadCrossover"; }
|
||||
|
||||
/**
|
||||
* eoQuad crossover - _genotype1 and _genotype2 are the (future)
|
||||
* offspring, i.e. _copies_ of the parents, to be modified
|
||||
* @param _genotype1 The first parent
|
||||
* @param _genotype2 The second parent
|
||||
*/
|
||||
bool operator()(GenotypeT& _genotype1, GenotypeT & _genotype2)
|
||||
{
|
||||
bool oneAtLeastIsModified(true);
|
||||
// START code for crossover of _genotype1 and _genotype2 objects
|
||||
|
||||
/** Requirement
|
||||
* if (at least one genotype has been modified) // no way to distinguish
|
||||
* oneAtLeastIsModified = true;
|
||||
* else
|
||||
* oneAtLeastIsModified = false;
|
||||
*/
|
||||
return oneAtLeastIsModified;
|
||||
// END code for crossover of _genotype1 and _genotype2 objects
|
||||
}
|
||||
|
||||
private:
|
||||
// START Private data of an eoMyStructQuadCrossover object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoMyStructQuadCrossover object
|
||||
};
|
||||
|
||||
#endif
|
||||
63
deprecated/eo/tutorial/Templates/stat.tmpl
Normal file
63
deprecated/eo/tutorial/Templates/stat.tmpl
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for computing statistics on eoPop
|
||||
============================================
|
||||
*/
|
||||
|
||||
#ifndef _eoMyStructStat_h
|
||||
#define _eoMyStructStat_h
|
||||
|
||||
// include the base definition of eoInit
|
||||
#include <utils/eoStat.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* ASSUMPTION on the class GenoypeT:
|
||||
* it needs to derive from EO (i.e. has a Fitness).
|
||||
*
|
||||
* It is assumed that you want to compute a double.
|
||||
* In case you want something else, then your stat should derive from
|
||||
* eoStat<GenotypeT, T>
|
||||
* where class T is the class of the computed statistics
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoMyStructStat : public eoStat<EOT, double>
|
||||
{
|
||||
public :
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
// START eventually add or modify the anyVariable argument
|
||||
/** Ctor - you change the default name of course.
|
||||
* @param
|
||||
* _description : inherited from eoValueParam (eoStat is an from eoVapueParam)
|
||||
*/
|
||||
eoMyStructStat(std::string _description = "eoMyStructStat ") :
|
||||
eoStat<EOT, double>(0.0, _description)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoMonReelStat object
|
||||
// END Code of Ctor of an eoMonReelStat object
|
||||
}
|
||||
|
||||
void operator()(const eoPop<EOT>& _pop){
|
||||
double tmpStat(0.);
|
||||
// START Code for computing the statistics - in tmpStat
|
||||
// tmpStat = blablabla
|
||||
// END Code for computing the statistics
|
||||
eoStat<EOT,double>::value() = tmpStat; // store the stat in the eoParam value() field
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "eoMyStructStat"; }
|
||||
private :
|
||||
// START Private data of an eoMyStructStat object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoMyStructStat object
|
||||
};
|
||||
|
||||
#endif
|
||||
261
deprecated/eo/tutorial/html/BitEA.html
Normal file
261
deprecated/eo/tutorial/html/BitEA.html
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="cpp2html Marc Schoenauer">
|
||||
<title>BitEA.cpp</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson4.html">Back to Lesson 4</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">BitEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" >
|
||||
<map NAME="Map">
|
||||
<!-- Init -->
|
||||
<area SHAPE="rect" HREF="#init" COORDS="14,31,135,70">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150">
|
||||
<!-- main loop -->
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150">
|
||||
<area SHAPE="rect" HREF="#output" COORDS="280,45,480,70">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150">
|
||||
<area SHAPE="rect" HREF="#select" COORDS="495,110,615,150">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230">
|
||||
<area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287">
|
||||
<area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310">
|
||||
<area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230">
|
||||
<!-- Center of loop -->
|
||||
<area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260">
|
||||
<!-- 4 bottom lines -->
|
||||
<area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370">
|
||||
<area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423">
|
||||
<area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450">
|
||||
<area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450">
|
||||
<area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378">
|
||||
</map>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
<b>#include <iostream></b><br>
|
||||
<b>#include <ga/make_ga.h></b><br>
|
||||
<b>#include <apply.h></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
<b>#include "binary_value.h"</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b>using namespace std;</b><br>
|
||||
<b>int main(int argc, char* argv[])</b><br>
|
||||
<b>{</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your genotype and fitness types<br>
|
||||
<b> typedef eoBit<double> EOT;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> eoParser parser(argc, argv); </b>// for user-parameter reading<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b> eoState state; </b>// keeps all things allocated<br>
|
||||
<b> </b>///// FIRST, problem or representation dependent stuff<br>
|
||||
<b> </b>//////////////////////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
<b> </b>// The evaluation fn - encapsulated into an eval counter for output <br>
|
||||
<b> eoEvalFuncPtr<EOT, float> mainEval( binary_value<EOT> );</b><br>
|
||||
<b> eoEvalFuncCounter<EOT> eval(mainEval);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b> </b>// the genotype - through a genotype initializer<br>
|
||||
<b> eoInit<EOT>& init = make_genotype(parser, state, EOT());</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// Build the variation operator (any seq/prop construct)<br>
|
||||
<b> eoGenOp<EOT>& op = make_op(parser, state, init);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b> </b>//// Now the representation-independent things<br>
|
||||
<b> </b>//////////////////////////////////////////////<br>
|
||||
<b> </b>// initialize the population - and evaluate<br>
|
||||
<b> </b>// yes, this is representation indepedent once you have an eoInit<br>
|
||||
<b> eoPop<EOT>& pop = make_pop(parser, state, init);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// stopping criteria<br>
|
||||
<b> eoContinue<EOT> & term = make_continue(parser, state, eval);</b><br>
|
||||
<b> </b>// output<br>
|
||||
<b> eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#FF6666">
|
||||
<b> </b>// algorithm (need the operator!)<br>
|
||||
<b> eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);</b><br>
|
||||
<b> </b>///// End of construction of the algorith<br>
|
||||
<b> </b>/////////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// to be called AFTER all parameters have been read!!!<br>
|
||||
<b> make_help(parser);</b><br>
|
||||
<b> </b>//// GO<br>
|
||||
<b> </b>///////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
<b> </b>// evaluate intial population AFTER help and status in case it takes time<br>
|
||||
<b> apply(eval, pop);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// print it out (sort witout modifying) <br>
|
||||
<b> cout << "Initial Population\n";</b><br>
|
||||
<b> pop.sortedPrintOn(cout);</b><br>
|
||||
<b> cout << endl;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#FF6666">
|
||||
<b> run_ea(ga, pop); </b>// run the ga<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// print it out (sort witout modifying) <br>
|
||||
<b> cout << "Final Population\n";</b><br>
|
||||
<b> pop.sortedPrintOn(cout);</b><br>
|
||||
<b> cout << endl;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << e.what() << endl;</b><br>
|
||||
<b> }</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr WIDTH="100%"><a href="eoLesson4.html">Back to Lesson 4</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Wed Mar 6 05:40:27 2002
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
BIN
deprecated/eo/tutorial/html/EA_tutorial.jpg
Normal file
BIN
deprecated/eo/tutorial/html/EA_tutorial.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
369
deprecated/eo/tutorial/html/FirstBitEA.html
Normal file
369
deprecated/eo/tutorial/html/FirstBitEA.html
Normal file
|
|
@ -0,0 +1,369 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="cpp2html Marc Schoenauer">
|
||||
<title>FirstBitEA.cpp</title>
|
||||
<!-- Changed by: Marc Schoenauer, 28-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">FirstBitEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" >
|
||||
<map NAME="Map">
|
||||
<!-- Init -->
|
||||
<area SHAPE="rect" HREF="#init" COORDS="14,31,135,70">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150">
|
||||
<!-- main loop -->
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150">
|
||||
<area SHAPE="rect" HREF="#output" COORDS="280,45,480,70">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150">
|
||||
<area SHAPE="rect" HREF="#select" COORDS="495,110,615,150">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230">
|
||||
<area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287">
|
||||
<area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310">
|
||||
<area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230">
|
||||
<!-- Center of loop -->
|
||||
<area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260">
|
||||
<!-- 4 bottom lines -->
|
||||
<area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370">
|
||||
<area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423">
|
||||
<area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450">
|
||||
<area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450">
|
||||
<area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378">
|
||||
</map>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// FirstBitEA.cpp<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
//*<br>
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm <br>
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops<br>
|
||||
//<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// standard includes<br>
|
||||
<b>#include <stdexcept> </b>// runtime_error <br>
|
||||
<b>#include <iostream> </b>// cout<br>
|
||||
<b>#include <strstream> </b>// ostrstream, istrstream<br>
|
||||
// the general include for eo<br>
|
||||
<b>#include <eo></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b>#include <ga.h></b><br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your individuals<br>
|
||||
<b>typedef eoBit<double> Indi; </b>// A bitstring with fitness double<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="evalfunc"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// a simple fitness function that computes the number of ones of a bitstring<br>
|
||||
// Now in a separate file, and declared as binary_value(const vector<bool> &)<br>
|
||||
<b>#include "binary_value.h"</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>void main_function(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> const unsigned int SEED = 42; </b>// seed for random number generator<br>
|
||||
<b> const unsigned int T_SIZE = 3; </b>// size for tournament selection<br>
|
||||
<b> const unsigned int VEC_SIZE = 8; </b>// Number of bits in genotypes<br>
|
||||
<b> const unsigned int POP_SIZE = 20; </b>// Size of population<br>
|
||||
<b> const unsigned int MAX_GEN = 500; </b>// Maximum number of generation before STOP<br>
|
||||
<b> const float CROSS_RATE = 0.8; </b>// Crossover rate<br>
|
||||
<b> const double P_MUT_PER_BIT = 0.01; </b>// probability of bit-flip mutation<br>
|
||||
<b> const float MUT_RATE = 1.0; </b>// mutation rate<br>
|
||||
<b> </b>// some parameters for chosing among different operators<br>
|
||||
<b> const double onePointRate = 0.5; </b>// rate for 1-pt Xover<br>
|
||||
<b> const double twoPointsRate = 0.5; </b>// rate for 2-pt Xover<br>
|
||||
<b> const double URate = 0.5; </b>// rate for Uniform Xover<br>
|
||||
<b> const double bitFlipRate = 0.5; </b>// rate for bit-flip mutation<br>
|
||||
<b> const double oneBitRate = 0.5; </b>// rate for one-bit mutation<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>// Random seed<br>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>//reproducible random seed: if you don't change SEED above, <br>
|
||||
<b> </b>// you'll aways get the same result, NOT a random run<br>
|
||||
<b> rng.reseed(SEED);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
<b> </b>/////////////////////////////<br>
|
||||
<b> </b>// Fitness function<br>
|
||||
<b> </b>////////////////////////////<br>
|
||||
<b> </b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
|
||||
<b> </b>// you need to give the full description of the function<br>
|
||||
<b> eoEvalFuncPtr<Indi, double, const vector<bool>& > eval( binary_value );</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// Initilisation of population<br>
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// based on eoUniformGenerator class (see utils/eoRndGenerators.h)<br>
|
||||
<b> eoUniformGenerator<bool> uGen;</b><br>
|
||||
<b> eoInitFixedLength<Indi> random(VEC_SIZE, uGen);</b><br>
|
||||
<b> </b>// Initialization of the population<br>
|
||||
<b> eoPop<Indi> pop(POP_SIZE, random);</b><br>
|
||||
<b> </b>// and evaluate it in one line<br>
|
||||
<b> apply<Indi>(eval, pop); </b>// STL syntax<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// sort pop before printing it!<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> </b>// Print (sorted) intial population (raw printout)<br>
|
||||
<b> cout << "Initial Population" << endl;</b><br>
|
||||
<b> cout << pop;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// selection and replacement<br>
|
||||
<b> </b>////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// The robust tournament selection<br>
|
||||
<b> eoDetTournamentSelect<Indi> selectOne(T_SIZE); </b>// T_SIZE in [2,POP_SIZE]<br>
|
||||
<a NAME="select_encapsulate"></a>
|
||||
<b> </b>// is now encapsulated in a eoSelectPerc (entage)<br>
|
||||
<b> eoSelectPerc<Indi> select(selectOne);</b>// by default rate==1<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// And we now have the full slection/replacement - though with <br>
|
||||
<b> </b>// no replacement (== generational replacement) at the moment :-)<br>
|
||||
<b> eoNoReplacement<Indi> replace; </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// The variation operators<br>
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// 1-point crossover for bitstring<br>
|
||||
<b> eo1PtBitXover<Indi> xover1;</b><br>
|
||||
<b> </b>// uniform crossover for bitstring<br>
|
||||
<b> eoUBitXover<Indi> xoverU;</b><br>
|
||||
<b> </b>// 2-pots xover<br>
|
||||
<b> eoNPtsBitXover<Indi> xover2(2);</b><br>
|
||||
<b> </b>// Combine them with relative rates<br>
|
||||
<b> eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);</b><br>
|
||||
<b> xover.add(xoverU, URate);</b><br>
|
||||
<b> xover.add(xover2, twoPointsRate, true);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b><br>
|
||||
<b> </b>// standard bit-flip mutation for bitstring<br>
|
||||
<b> eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);</b><br>
|
||||
<b> </b>// mutate exactly 1 bit per individual<br>
|
||||
<b> eoDetBitFlip<Indi> mutationOneBit; </b><br>
|
||||
<b> </b>// Combine them with relative rates<br>
|
||||
<b> eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);</b><br>
|
||||
<b> mutation.add(mutationOneBit, oneBitRate, true);</b><br>
|
||||
<b> </b><br>
|
||||
<a NAME="transform"></a>
|
||||
<b> </b>// The operators are encapsulated into an eoTRansform object<br>
|
||||
<b> eoSGATransform<Indi> transform(xover, CROSS_RATE, mutation, MUT_RATE);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// termination conditions: use more than one<br>
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// stop after MAX_GEN generations<br>
|
||||
<b> eoGenContinue<Indi> genCont(MAX_GEN);</b><br>
|
||||
<b> </b>// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement<br>
|
||||
<b> eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, STEADY_GEN);</b><br>
|
||||
<b> </b>// stop when fitness reaches a target (here VEC_SIZE)<br>
|
||||
<b> eoFitContinue<Indi> fitCont(0);</b><br>
|
||||
<b> </b>// do stop when one of the above says so<br>
|
||||
<b> eoCombinedContinue<Indi> continuator(genCont);</b><br>
|
||||
<b> continuator.add(steadyCont);</b><br>
|
||||
<b> continuator.add(fitCont);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#FF6666">
|
||||
<b> </b>/////////////////////////////////////////<br>
|
||||
<b> </b>// the algorithm<br>
|
||||
<b> </b>////////////////////////////////////////<br>
|
||||
<b> </b>// Easy EA requires <br>
|
||||
<b> </b>// selection, transformation, eval, replacement, and stopping criterion<br>
|
||||
<b> eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);</b><br>
|
||||
<b> </b>// Apply algo to pop - that's it!<br>
|
||||
<b> gga(pop);</b><br>
|
||||
<b> </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// Print (sorted) intial population<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> cout << "FINAL Population\n" << pop << endl;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b>}</b><br>
|
||||
// A main that catches the exceptions<br>
|
||||
<b>int main(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
<b>#ifdef _MSC_VER</b><br>
|
||||
<b> </b>// rng.reseed(42);<br>
|
||||
<b> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br>
|
||||
<b> flag |= _CRTDBG_LEAK_CHECK_DF;</b><br>
|
||||
<b> _CrtSetDbgFlag(flag);</b><br>
|
||||
// _CrtSetBreakAlloc(100);<br>
|
||||
<b>#endif</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
<b> main_function(argc, argv);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << "Exception: " << e.what() << '\n';</b><br>
|
||||
<b> }</b><br>
|
||||
<b> return 1;</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Sun Nov 19 22:26:27 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
312
deprecated/eo/tutorial/html/FirstBitGA.html
Normal file
312
deprecated/eo/tutorial/html/FirstBitGA.html
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.76 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>FirstBitGA.html</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Code for FirstBitGA</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" ><map NAME="Map"><!-- Init --><area SHAPE="rect" HREF="#init" COORDS="14,31,135,70"><area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150"><!-- main loop --><area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150"><area SHAPE="rect" HREF="#output" COORDS="280,45,480,70"><area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150"><area SHAPE="rect" HREF="#select" COORDS="495,110,615,150"><area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230"><area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287"><area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305"><area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310"><area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310"><area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230"><!-- Center of loop --><area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260"><!-- 4 bottom lines --><area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370"><area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370"><area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397"><area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423"><area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450"><area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450"><area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450"><area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378"></map>
|
||||
<br><a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// FirstBitGA.cpp</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">//*</font></tt>
|
||||
<br><tt><font color="#993300">// An instance of a VERY simple Bitstring
|
||||
Genetic Algorithm</font></tt>
|
||||
<br><tt><font color="#993300">//</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// standard includes</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream>
|
||||
</b>// cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900">#include <ga.h></font></tt></b><br>
|
||||
<tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// define your individuals</font></tt>
|
||||
<br><tt><font color="#999900"><b>typedef eoBit<double> Indi;
|
||||
</b>// A bitstring with fitness double</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#CC0000">// a simple fitness function that computes
|
||||
the number of ones of a bitstring</font></tt>
|
||||
<br><tt><font color="#CC0000">// @param _indi A biststring individual</font></tt>
|
||||
<br><a NAME="evalfunc"></a><b><tt><font color="#CC0000">double binary_value(const
|
||||
Indi & _indi)</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">{</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> double sum = 0;</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> for (unsigned i = 0; i < _indi.size();
|
||||
i++)</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> sum += _indi[i];</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> return sum;</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><b><tt><font color="#993300">void main_function(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// all parameters are hard-coded!</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int SEED = 42;
|
||||
</b>// seed for random number generator</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int T_SIZE = 3;
|
||||
</b>// size for tournament selection</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int VEC_SIZE = 8;
|
||||
</b>// Number of bits in genotypes</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int POP_SIZE = 20;
|
||||
</b>// Size of population</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MAX_GEN = 100;
|
||||
</b>// Maximum number of generation before STOP</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float CROSS_RATE = 0.8;
|
||||
</b>// Crossover rate</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double P_MUT_PER_BIT = 0.01;
|
||||
</b>// probability of bit-flip mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float MUT_RATE = 1.0;
|
||||
</b>// mutation rate</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="random"></a><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// Random seed</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//reproducible random seed:
|
||||
if you don't change SEED above, </font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// you'll aways get the same
|
||||
result, NOT a random run</font></tt>
|
||||
<br><b><tt><font color="#993300"> rng.reseed(SEED);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b>/////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Fitness function</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Evaluation: from a plain
|
||||
C++ fn to an EvalFunc Object</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncPtr<Indi> eval(
|
||||
binary_value );</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Initilisation of population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// declare the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi> pop;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// fill it!</font></tt>
|
||||
<br><b><tt><font color="#993399"> for (unsigned int igeno=0; igeno<POP_SIZE;
|
||||
igeno++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
Indi v;
|
||||
</b>// void individual, to be filled</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
{</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
bool r = rng.flip(); </b>// new value, random in {0,1}</font></tt>
|
||||
<br><tt><font color="#993399"><b>
|
||||
v.push_back(r); </b>//
|
||||
append that random value to v</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
}</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
eval(v);
|
||||
</b>// evaluate it</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
pop.push_back(v);
|
||||
</font></tt></b><tt><font color="#993399">// and put it in the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> }</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// sort pop before printing
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population
|
||||
(raw printout)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> cout << "Initial Population"
|
||||
<< endl;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << pop;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// selection and replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// The robust tournament selection</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoDetTournamentSelect<Indi> select(T_SIZE);
|
||||
</b>// T_SIZE in [2,POP_SIZE]</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// The simple GA evolution engine
|
||||
uses generational replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// so no replacement procedure
|
||||
is needed</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// The variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// 1-point crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eo1PtBitXover<Indi> xover;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<br><tt><font color="#993399"><b> </b>// standard bit-flip mutation
|
||||
for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBitMutation<Indi> mutation(P_MUT_PER_BIT);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// termination condition</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop after MAX_GEN generations</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoGenContinue<Indi> continuator(MAX_GEN);</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#FF6666"><b> </b>/////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// standard Generational GA
|
||||
requires as parameters</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// selection, evaluation, crossover
|
||||
and mutation, stopping criterion</font></tt>
|
||||
<p><b><tt><font color="#FF6666"> eoSGA<Indi> gga(select, xover,
|
||||
CROSS_RATE, mutation, MUT_RATE, </font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
eval, continuator);</font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that's
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="final_output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"
|
||||
<< pop << endl;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="main"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// rng.reseed(42);</font></tt>
|
||||
<br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> flag
|
||||
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b>
|
||||
<br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt>
|
||||
<br><b><tt><font color="#993300">#endif</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
main_function(argc, argv);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception&
|
||||
e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
cout << "Exception: " << e.what() << '\n';</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 1;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
|
||||
19 08:31:26 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
354
deprecated/eo/tutorial/html/FirstRealEA.html
Normal file
354
deprecated/eo/tutorial/html/FirstRealEA.html
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>FirstRealEA.cpp</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">FirstRealEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" ><map NAME="Map"><!-- Init --><area SHAPE="rect" HREF="#init" COORDS="14,31,135,70"><area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150"><!-- main loop --><area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150"><area SHAPE="rect" HREF="#output" COORDS="280,45,480,70"><area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150"><area SHAPE="rect" HREF="#select" COORDS="495,110,615,150"><area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230"><area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287"><area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305"><area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310"><area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310"><area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230"><!-- Center of loop --><area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260"><!-- 4 bottom lines --><area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370"><area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370"><area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397"><area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423"><area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450"><area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450"><area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450"><area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378"></map>
|
||||
<br><a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// FirstRealEA.cpp</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">//*</font></tt>
|
||||
<br><tt><font color="#993300">// Still an instance of a VERY simple Real-coded
|
||||
Genetic Algorithm </font></tt>
|
||||
<br><tt><font color="#993300">// (see FirstBitGA.cpp) but now with
|
||||
Breeder - and Combined Ops</font></tt>
|
||||
<br><tt><font color="#993300">//</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// standard includes</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream>
|
||||
</b>// cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900"><b>#include <es.h></b></font></tt><br>
|
||||
<tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// define your individuals</font></tt>
|
||||
<br><b><tt><font color="#999900">typedef eoReal<double> Indi; </font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="evalfunc"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#CC0000">// a simple fitness function that computes
|
||||
the euclidian norm of a real vector</font></tt>
|
||||
<br><tt><font color="#CC0000">// Now in a separate file, and declared as
|
||||
binary_value(const vector<bool> &)</font></tt>
|
||||
<br><b><tt><font color="#CC0000">#include "real_value.h"</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><b><tt><font color="#993300">void main_function(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> const unsigned int SEED = 42; </b>//
|
||||
seed for random number generator</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int T_SIZE = 3; </b>//
|
||||
size for tournament selection</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int VEC_SIZE = 8;
|
||||
</b>// Number of object variables in genotypes</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int POP_SIZE = 20;
|
||||
</b>// Size of population</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MAX_GEN = 500;
|
||||
</b>// Maximum number of generation before STOP</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MIN_GEN = 10;
|
||||
</b>// Minimum number of generation before ...</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int STEADY_GEN =
|
||||
50; </b>// stop after STEADY_GEN gen. without improvelent</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float P_CROSS = 0.8; </b>//
|
||||
Crossover probability</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float P_MUT = 0.5; </b>//
|
||||
mutation probability</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double EPSILON = 0.01; </b>//
|
||||
range for real uniform mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"> <b>double
|
||||
SIGMA = 0.3; </b> // std dev.
|
||||
for normal mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// some parameters for chosing
|
||||
among different operators</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double hypercubeRate = 0.5;
|
||||
</b>// relative weight for hypercube Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double segmentRate = 0.5;
|
||||
</b>// relative weight for segment Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double uniformMutRate = 0.5;
|
||||
</b>// relative weight for uniform mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double detMutRate = 0.5;
|
||||
</b>// relative weight for det-uniform mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"> <b>const double normalMutRate = 0.5;</b>
|
||||
// relative weight for normal mutation</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// Random seed</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//reproducible random seed:
|
||||
if you don't change SEED above, </font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// you'll aways get the same
|
||||
result, NOT a random run</font></tt>
|
||||
<br><b><tt><font color="#993300"> rng.reseed(SEED);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b>/////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Fitness function</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Evaluation: from a plain
|
||||
C++ fn to an EvalFunc Object</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// you need to give the full
|
||||
description of the function</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncPtr<Indi, double, const
|
||||
vector<double>& > eval( real_value );</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Initilisation of population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// based on a uniform generator</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoInitFixedLength<Indi, uniform_generator<double>
|
||||
></font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
random(VEC_SIZE, uniform_generator<double>(-1.0, 1.0));</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Initialization of
|
||||
the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi> pop(POP_SIZE, random);</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b>// and evaluate it in one loop</font></tt>
|
||||
<br><tt><font color="#993399"><b> apply<Indi>(eval, pop); </b>//
|
||||
STL syntax</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// sort pop before printing
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population
|
||||
(raw printout)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> cout << "Initial Population"
|
||||
<< endl;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << pop;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// selection and replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// The robust tournament selection</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoDetTournamentSelect<Indi> selectOne(T_SIZE);</font></tt></b>
|
||||
<br><a NAME="select_encapsulate"></a><tt><font color="#009900"><b> </b>//
|
||||
is now encapsulated in a eoSelectPerc (entage)</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoSelectPerc<Indi> select(selectOne);</b>//
|
||||
by default rate==1</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// And we now have the full
|
||||
slection/replacement - though with </font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// no replacement (== generational
|
||||
replacement) at the moment :-)</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoNoReplacement<Indi> replace; </font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// The variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// uniform chooce on segment
|
||||
made by the parents</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoSegmentCrossover<Indi> xoverS;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// uniform choice in hypercube
|
||||
built by the parents</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoHypercubeCrossover<Indi> xoverA;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
weights</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> xover(xoverS,
|
||||
segmentRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> xover.add(xoverA, hypercubeRate,
|
||||
true);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<br><tt><font color="#993399"><b> </b>// offspring(i) uniformly chosen
|
||||
in [parent(i)-epsilon, parent(i)+epsilon]</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoUniformMutation<Indi>
|
||||
mutationU(EPSILON); </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// k (=1) coordinates of parents
|
||||
are uniformly modified</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoDetUniformMutation<Indi>
|
||||
mutationD(EPSILON); </font></tt></b>
|
||||
<br><tt><font color="#993399"> // all coordinates of parents are normally
|
||||
modified (stDev SIGMA)</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoNormalMutation<Indi>
|
||||
mutationN(SIGMA); </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
weights</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedMonOp<Indi> mutation(mutationU,
|
||||
uniformMutRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> mutation.add(mutationD, detMutRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> mutation.add(mutationN, normalMutRate,
|
||||
true);</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b>// The operators are encapsulated
|
||||
into an eoTRansform object</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoSGATransform<Indi> transform(xover,
|
||||
P_CROSS, mutation, P_MUT);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// termination conditions: use
|
||||
more than one</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop after MAX_GEN generations</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoGenContinue<Indi> genCont(MAX_GEN);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// do MIN_GEN gen., then stop
|
||||
after STEADY_GEN gen. without improvement</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoSteadyFitContinue<Indi> steadyCont(MIN_GEN,
|
||||
STEADY_GEN);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop when fitness reaches
|
||||
a target (here VEC_SIZE)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoFitContinue<Indi> fitCont(0);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// do stop when one of the above
|
||||
says so</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCombinedContinue<Indi> continuator(genCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(steadyCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(fitCont);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#FF6666"><b> </b>/////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Easy EA requires </font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// selection, transformation,
|
||||
eval, replacement, and stopping criterion</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> eoEasyEA<Indi> gga(continuator,
|
||||
eval, select, transform, replace);</font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that's
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> cout << "\n
|
||||
Here we go\n\n";</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"
|
||||
<< pop << endl;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// rng.reseed(42);</font></tt>
|
||||
<br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> flag
|
||||
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b>
|
||||
<br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt>
|
||||
<br><b><tt><font color="#993300">#endif</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
main_function(argc, argv);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception&
|
||||
e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
cout << "Exception: " << e.what() << '\n';</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 1;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Wed Nov
|
||||
29 07:38:36 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
350
deprecated/eo/tutorial/html/FirstRealGA.html
Normal file
350
deprecated/eo/tutorial/html/FirstRealGA.html
Normal file
|
|
@ -0,0 +1,350 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="cpp2html Marc Schoenauer">
|
||||
<title>FirstRealGA.html</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Code for FirstRealGA</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" >
|
||||
<map NAME="Map">
|
||||
<!-- Init -->
|
||||
<area SHAPE="rect" HREF="#init" COORDS="14,31,135,70">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150">
|
||||
<!-- main loop -->
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150">
|
||||
<area SHAPE="rect" HREF="#output" COORDS="280,45,480,70">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150">
|
||||
<area SHAPE="rect" HREF="#select" COORDS="495,110,615,150">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230">
|
||||
<area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287">
|
||||
<area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310">
|
||||
<area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230">
|
||||
<!-- Center of loop -->
|
||||
<area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260">
|
||||
<!-- 4 bottom lines -->
|
||||
<area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370">
|
||||
<area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423">
|
||||
<area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450">
|
||||
<area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450">
|
||||
<area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378">
|
||||
</map>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// FirstRealGA.cpp<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
//*<br>
|
||||
// An instance of a VERY simple Real-coded Genetic Algorithm<br>
|
||||
//<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// standard includes<br>
|
||||
<b>#include <stdexcept> </b>// runtime_error <br>
|
||||
<b>#include <iostream> </b>// cout<br>
|
||||
<b>#include <strstream> </b>// ostrstream, istrstream<br>
|
||||
// the general include for eo<br>
|
||||
<b>#include <eo></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b>#include <es.h></b><br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your individuals<br>
|
||||
<b> typedef eoReal<double> Indi;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// a simple fitness function that computes the euclidian norm of a real vector<br>
|
||||
// @param _indi A real-valued individual <br>
|
||||
<a name="evalfunc"></a>
|
||||
<b>double real_value(const Indi & _indi)</b><br>
|
||||
<b>{</b><br>
|
||||
<b> double sum = 0;</b><br>
|
||||
<b> for (unsigned i = 0; i < _indi.size(); i++)</b><br>
|
||||
<b> sum += _indi[i]*_indi[i];</b><br>
|
||||
<b> return (-sum); </b>// maximizing only<br>
|
||||
<b>}</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>void main_function(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// all parameters are hard-coded!<br>
|
||||
<b> const unsigned int SEED = 42; </b>// seed for random number generator<br>
|
||||
<b> const unsigned int VEC_SIZE = 8; </b>// Number of object variables in genotypes<br>
|
||||
<b> const unsigned int POP_SIZE = 20; </b>// Size of population<br>
|
||||
<b> const unsigned int T_SIZE = 3; </b>// size for tournament selection<br>
|
||||
<b> const unsigned int MAX_GEN = 500; </b>// Maximum number of generation before STOP<br>
|
||||
<b> const float CROSS_RATE = 0.8; </b>// Crossover rate<br>
|
||||
<b> const double EPSILON = 0.01; </b>// range for real uniform mutation<br>
|
||||
<b> const float MUT_RATE = 0.5; </b>// mutation rate<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<a NAME="random"></a>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>// Random seed<br>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>//reproducible random seed: if you don't change SEED above, <br>
|
||||
<b> </b>// you'll aways get the same result, NOT a random run<br>
|
||||
<b> rng.reseed(SEED);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
<b> </b>/////////////////////////////<br>
|
||||
<b> </b>// Fitness function<br>
|
||||
<b> </b>////////////////////////////<br>
|
||||
<b> </b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
|
||||
<b> eoEvalFuncPtr<Indi> eval( real_value );</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// Initilisation of population<br>
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// declare the population<br>
|
||||
<b> eoPop<Indi> pop;</b><br>
|
||||
<b> </b>// fill it!<br>
|
||||
<b> for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> Indi v; </b>// void individual, to be filled<br>
|
||||
<b> for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> double r = 2*rng.uniform() - 1; </b>// new value, random in [-1,1)<br>
|
||||
<b> v.push_back(r); </b>// append that random value to v<br>
|
||||
<b> }</b><br>
|
||||
<b> eval(v); </b>// evaluate it<br>
|
||||
<b> pop.push_back(v); </b>// and put it in the population<br>
|
||||
<b> }</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// sort pop before printing it!<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> </b>// Print (sorted) intial population (raw printout)<br>
|
||||
<b> cout << "Initial Population" << endl;</b><br>
|
||||
<b> cout << pop;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// selection and replacement<br>
|
||||
<b> </b>////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// The robust tournament selection<br>
|
||||
<b> eoDetTournamentSelect<Indi> select(T_SIZE); </b>// T_SIZE in [2,POP_SIZE]<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// eoSGA uses generational replacement by default<br>
|
||||
<b> </b>// so no replacement procedure has to be given<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// termination condition<br>
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// stop after MAX_GEN generations<br>
|
||||
<b> eoGenContinue<Indi> continuator(MAX_GEN);</b><br>
|
||||
<b> </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// The variation operators<br>
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]<br>
|
||||
<b> eoUniformMutation<Indi> mutation(EPSILON); </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// offspring(i) is a linear combination of parent(i)<br>
|
||||
<b> eoSegmentCrossover<Indi> xover;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#FF6666">
|
||||
<b> </b>/////////////////////////////////////////<br>
|
||||
<b> </b>// the algorithm<br>
|
||||
<b> </b>////////////////////////////////////////<br>
|
||||
<b> </b>// standard Generational GA requires<br>
|
||||
<b> </b>// selection, evaluation, crossover and mutation, stopping criterion<br>
|
||||
<b> </b><br>
|
||||
<b> eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE, </b><br>
|
||||
<b> eval, continuator);</b><br>
|
||||
<b> </b>// Apply algo to pop - that's it!<br>
|
||||
<b> gga(pop);</b><br>
|
||||
<b> </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="final_output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// Print (sorted) intial population<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> cout << "FINAL Population\n" << pop << endl;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="main"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b>}</b><br>
|
||||
// A main that catches the exceptions<br>
|
||||
<b>int main(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
<b>#ifdef _MSC_VER</b><br>
|
||||
<b> </b>// rng.reseed(42);<br>
|
||||
<b> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br>
|
||||
<b> flag |= _CRTDBG_LEAK_CHECK_DF;</b><br>
|
||||
<b> _CrtSetDbgFlag(flag);</b><br>
|
||||
// _CrtSetBreakAlloc(100);<br>
|
||||
<b>#endif</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
<b> main_function(argc, argv);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << "Exception: " << e.what() << '\n';</b><br>
|
||||
<b> }</b><br>
|
||||
<b> return 1;</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Sun Nov 19 08:31:29 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
286
deprecated/eo/tutorial/html/Firstmerge.html
Normal file
286
deprecated/eo/tutorial/html/Firstmerge.html
Normal file
|
|
@ -0,0 +1,286 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>Differences</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson1.html">Back to Lesson 1</a> -
|
||||
<a href="eoTutorial.html">Tutorial
|
||||
main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <a href="../../doc/html/index.html">EO
|
||||
documentation</a>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">FirstBitGA and FirstRealGA: differences</font></h1></center>
|
||||
Below is a comparison of the codes for both algorithms (comments have been
|
||||
removed).
|
||||
<br><b><font color="#FF6600">Warning</font></b>: the <font color="#FF6666">pink
|
||||
background</font> here denotes the differences, not the section of
|
||||
the algorithm, which is only recalled by the color of the text!
|
||||
<br>These differences are limited to
|
||||
<ul>
|
||||
<li>
|
||||
the declaration of <font color="#666600">the type of the genotypes,</font></li>
|
||||
|
||||
<li>
|
||||
the <font color="#990000">fitness function</font> (what did you expect
|
||||
:-),</li>
|
||||
|
||||
<li>
|
||||
the <font color="#CC33CC">initialization</font> (and if you look carefully,
|
||||
you'll find out that only a small part of the initialization is different,
|
||||
as both genotypes are eoFixedLength objects) and of course</li>
|
||||
|
||||
<li>
|
||||
the choice of <font color="#CC33CC">variation operators </font>(including
|
||||
the parameter for the mutation).</li>
|
||||
</ul>
|
||||
|
||||
<table BORDER=0 CELLPADDING=5 COLS=2 WIDTH="100%" BGCOLOR="#C3C2B4" >
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">#include
|
||||
<stdexcept ></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">#include <iostream></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">#include <strstream></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">#include <eo></font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">#include
|
||||
<stdexcept ></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">#include <iostream></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">#include <strstream></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">#include <eo></font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include <es.h><br>
|
||||
typedef eoReal<double> Indi;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include <ga.h><br>
|
||||
typedef eoBit<double> Indi;</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">double
|
||||
real_value(const Indi & _indi)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">{</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> double
|
||||
sum = 0;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> for (unsigned
|
||||
i = 0; i < _indi.size(); i++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">
|
||||
sum += _indi[i]*_indi[i];</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> return
|
||||
(-sum); // maximizing</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">}</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">double
|
||||
binary_value(const Indi & _indi)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">{</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> double
|
||||
sum = 0;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> for (unsigned
|
||||
i = 0; i < _indi.size(); i++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">
|
||||
sum += _indi[i];</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> return
|
||||
(sum);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">}</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">void
|
||||
main_function(int argc, char **argv)</font></font>
|
||||
<br><font face="Courier New,Courier">{</font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int SEED = 42;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int VEC_SIZE = 8;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int POP_SIZE = 20;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int T_SIZE = 3;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int MAX_GEN = 500;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const float
|
||||
CROSS_RATE = 0.8;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const float
|
||||
MUT_RATE = 0.5;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">void
|
||||
main_function(int argc, char **argv)</font></font>
|
||||
<br><font face="Courier New,Courier">{</font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int SEED = 42;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int VEC_SIZE = 8;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int POP_SIZE = 20;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int T_SIZE = 3;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
|
||||
int MAX_GEN = 500;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const float
|
||||
CROSS_RATE = 0.8;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">const float
|
||||
MUT_RATE = 0.5;</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#3366FF">const
|
||||
double EPSILON = 0.01;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#3366FF">const
|
||||
double P_MUT_PER_BIT = 0.01;</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">eoEvalFuncPtr<Indi>
|
||||
eval(real_value);</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">eoEvalFuncPtr<Indi>
|
||||
eval(binary_value);</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">eoPop<Indi>
|
||||
pop;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">for (unsigned
|
||||
int igeno=0; igeno<POP_SIZE; igeno++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC"> {</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
Indi v;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
{</font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">eoPop<Indi>
|
||||
pop;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">for (unsigned
|
||||
int igeno=0; igeno<POP_SIZE; igeno++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC"> {</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
Indi v;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
{</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
double r = 2*rng.uniform() - 1;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
bool r = rng.flip(); </font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
v.push_back(r); //</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
}</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
eval(v);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
pop.push_back(v);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC"> }</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
"Initial Population" << endl;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
pop;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#009900">eoDetTournament<Indi>
|
||||
select(T_SIZE);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">eoGenContinue<Indi>
|
||||
continuator(MAX_GEN);</font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
v.push_back(r); //</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
}</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
eval(v);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
pop.push_back(v);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC"> }</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
"Initial Population" << endl;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
pop;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#009900">eoDetTournament<Indi>
|
||||
select(T_SIZE);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">eoGenContinue<Indi>
|
||||
continuator(MAX_GEN);</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">eoUniformMutation<Indi>
|
||||
mutation(EPSILON);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">eoSegmentCrossover<Indi>
|
||||
xover;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">eoBitMutation<Indi>
|
||||
mutation(P_MUT_PER_BIT);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">eo1PtBitXover<Indi>
|
||||
xover;</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4">
|
||||
<font face="Courier New,Courier"><font color="#FF6666">eoSGA<Indi>
|
||||
gga(select, xover, CROSS_RATE,</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">
|
||||
mutation, MUT_RATE, eval, continuator);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">gga(pop);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
"FINAL Population\n" << pop << endl;</font></font>
|
||||
<br><font face="Courier New,Courier">}</font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">int main(int
|
||||
argc, char **argv)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">{</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">... [technical
|
||||
code removed]</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">}</font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4">
|
||||
<font face="Courier New,Courier"><font color="#FF6666">eoSGA<Indi>
|
||||
gga(select, xover, CROSS_RATE,</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">
|
||||
mutation, MUT_RATE, eval, continuator);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">gga(pop);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
"FINAL Population\n" << pop << endl;</font></font>
|
||||
<br><font face="Courier New,Courier">}</font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">int main(int
|
||||
argc, char **argv)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">{</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">[... technical
|
||||
code removed ]</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">}</font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> -
|
||||
<a href="eoTutorial.html">Tutorial
|
||||
main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <a href="../../doc/html/index.html">EO
|
||||
documentation</a>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Tue Nov 7 07:04:15 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Tue Nov 7 07:49:47 CET 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
77
deprecated/eo/tutorial/html/NoWay.html
Normal file
77
deprecated/eo/tutorial/html/NoWay.html
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>Tutorial: Solutions</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoTutorial.html">Tutorial main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> -<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial:</font></h1></center>
|
||||
|
||||
<center><b><font color="#FF0000"><font size=+2>Solutions of exercises</font></font></b></center>
|
||||
|
||||
<p>No, <b><font color="#33CC00">w</font><font color="#FF9900">e </font><font color="#CC66CC">w</font><font color="#33CCFF">o</font><font color="#FFFF00">n</font><font color="#FF0000">'t</font><font color="#999999">
|
||||
p</font><font color="#999900">r</font><font color="#CC6600">o</font><font color="#993399">v</font><font color="#006600">i</font><font color="#990000">d</font><font color="#867CE9">e
|
||||
</font></b><font color="#000000">any
|
||||
hypertext link directly to the correct code, so</font> you get a chance
|
||||
to find out the solution by yourself without immediately going there
|
||||
:-)))
|
||||
<p><b><font color="#000099"><font size=+2>What you should do:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
copy the code of an example onto another name (e.g. <b><tt><font color="#660000">mytest.cpp</font></tt></b>)</li>
|
||||
|
||||
<li>
|
||||
edit and modify <b><tt><font color="#660000">mytest.cpp</font></tt></b>
|
||||
according to the corresponding instructions of the exercise</li>
|
||||
|
||||
<li>
|
||||
compile <b><tt><font color="#660000">mytest.cpp</font></tt></b> by typing
|
||||
<b><tt><font color="#FF6666">make
|
||||
mytest</font></tt></b> at system prompt, and you will hopefully get an
|
||||
executable file named <b><tt><font color="#660000">mytest</font></tt></b>
|
||||
(for Unix systems: if eventually someone tells me how to do that in Windows,
|
||||
apart that you'll probably end up with an executable file named <b><tt><font color="#660000">mytest.exe...</font></tt></b>).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>What you may do later:</font></font></b>
|
||||
<p>All solutions to exercises are in the same<b><font color="#FF6600">
|
||||
sub-dir</font></b> of the Tutorial directory than the example files (i.e.
|
||||
Lesson1 for Lesson1, yes!) and are named <b><tt><font color="#990000">exerciseN.p.cpp</font></tt></b>
|
||||
where N is the lesson number and p the exercise number. Hence you may browse
|
||||
through the code, eventually modifying it, and then simply type, in the
|
||||
corresponding directory,
|
||||
<br><b><tt><font color="#FF6666">... % make exerciseN.p</font></tt></b>
|
||||
<br>which will compile file <b><tt><font color="#660000">exerciseN.p.cpp</font></tt></b>
|
||||
into executable <b><tt><font color="#660000">exerciseN.p</font></tt></b>
|
||||
(for Unix systems: if eventually someone tells me how to do that in Windows,
|
||||
you'll probably end up with an executable file named <b><tt><font color="#660000">exerciseN.p.exe</font></tt></b>).
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>What you may not do:</font></font></b>
|
||||
<center>Complain that it does not work under Windows :-)</center>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoTutorial.html">Tutorial main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> -<b> <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Fri Nov 3 18:49:12 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Fri Nov 3 18:49:12 CET 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
360
deprecated/eo/tutorial/html/OneMaxEA.html
Normal file
360
deprecated/eo/tutorial/html/OneMaxEA.html
Normal file
|
|
@ -0,0 +1,360 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
|
||||
<title>Templates/OneMaxEA.cpp</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson5.html">Back to Lesson 5</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Templates/OneMaxEA.cpp</font></h1></center>
|
||||
The places where you have to put some code are on <b><font color="#FF6666">pink
|
||||
background</font></b>.. Only the the <a href="eoTutorial.html#colors">character
|
||||
colors have the usual meaning</a>.
|
||||
<br><a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">/** -*- mode: c++; c-indent-level:
|
||||
4; c++-member-init-indent: 8; comment-column: 35; -*-</font></tt>
|
||||
<br><tt><font color="#993300">The above line is usefulin Emacs-like editors</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<br><tt><font color="#993300">/*</font></tt>
|
||||
<br><tt><font color="#993300">Template for creating a new representation
|
||||
in EO</font></tt>
|
||||
<br><tt><font color="#993300">================================================</font></tt>
|
||||
<br><tt><font color="#993300">This is the template main file.</font></tt>
|
||||
<br><tt><font color="#993300">It includes all other files that have been
|
||||
generated by the script create.sh</font></tt>
|
||||
<br><tt><font color="#993300">so it is the only file to compile.</font></tt>
|
||||
<br><tt><font color="#993300">In case you want to build up a separate library
|
||||
for your new Evolving Object,</font></tt>
|
||||
<br><tt><font color="#993300">you'll need some work - follow what's done
|
||||
in the src/ga dir, used in the</font></tt>
|
||||
<br><tt><font color="#993300">main file BitEA in tutorial/Lesson4 dir.</font></tt>
|
||||
<br><tt><font color="#993300">Or you can wait until we do it :-)</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<br><tt><font color="#993300">// Miscilaneous include and declaration </font></tt>
|
||||
<br><b><tt><font color="#993300">#include <iostream></font></tt></b>
|
||||
<br><b><tt><font color="#993300">using namespace std;</font></tt></b>
|
||||
<br><tt><font color="#993300">// eo general include</font></tt>
|
||||
<br><b><tt><font color="#993300">#include "eo"</font></tt></b>
|
||||
<br><tt><font color="#993300">// the real bounds (not yet in general eo
|
||||
include)</font></tt>
|
||||
<br><b><tt><font color="#993300">#include "utils/eoRealVectorBounds.h"</font></tt></b>
|
||||
<br><tt><font color="#993300">// include here whatever specific files for
|
||||
your representation</font></tt>
|
||||
<br><tt><font color="#993300">// Basically, this should include at least
|
||||
the following</font></tt>
|
||||
<br><tt><font color="#993300">/** definition of representation: </font></tt>
|
||||
<br><tt><font color="#993300">* class eoOneMax MUST derive from EO<FitT>
|
||||
for some fitness</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900">#include "eoOneMax.h"</font></tt></b>
|
||||
<br><tt><font color="#999900">/** definition of initilizqtion: </font></tt>
|
||||
<br><tt><font color="#999900">* class eoOneMaxInit MUST derive from eoInit<eoOneMax></font></tt>
|
||||
<br><tt><font color="#999900">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">#include "eoOneMaxInit.h"</font></tt></b>
|
||||
<br><tt><font color="#993399">/** definition of evaluation: </font></tt>
|
||||
<br><tt><font color="#993399">* class eoOneMaxEvalFunc MUST derive from
|
||||
eoEvalFunc<eoOneMax></font></tt>
|
||||
<br><tt><font color="#993399">* and should test for validity before doing
|
||||
any computation</font></tt>
|
||||
<br><tt><font color="#993399">* see tutorial/Templates/evalFunc.tmpl</font></tt>
|
||||
<br><tt><font color="#993399">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="fitness"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#CC0000">#include "eoOneMaxEvalFunc.h"</font></tt></b>
|
||||
<br><tt><font color="#CC0000">// GENOTYPE eoOneMax ***MUST***
|
||||
be templatized over the fitness</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000">// START fitness type: double or eoMaximizingFitness
|
||||
if you are maximizing</font></tt>
|
||||
<br><tt><font color="#CC0000">//
|
||||
eoMinimizingFitness if you are minimizing</font></tt>
|
||||
<br><tt><font color="#CC0000"><b>typedef eoMinimizingFitness MyFitT ; </b>//
|
||||
type of fitness </font></tt>
|
||||
<br><tt><font color="#CC0000">// END fitness type</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">// Then define your EO objects using that
|
||||
fitness type</font></tt>
|
||||
<br><tt><font color="#999900"><b>typedef eoOneMax<MyFitT> Indi; </b>
|
||||
// ***MUST*** derive from EO </font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399">// create an initializer</font></tt>
|
||||
<br><b><tt><font color="#993399">#include "make_genotype_OneMax.h"</font></tt></b>
|
||||
<br><b><tt><font color="#993399">eoInit<Indi> & make_genotype(eoParser&
|
||||
_parser, eoState&_state, Indi _eo)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> return do_make_genotype(_parser,
|
||||
_state, _eo);</font></tt></b>
|
||||
<br><b><tt><font color="#993399">} </font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399">// and the variation operaotrs</font></tt>
|
||||
<br><b><tt><font color="#993399">#include "make_op_OneMax.h"</font></tt></b>
|
||||
<br><b><tt><font color="#993399">eoGenOp<Indi>& make_op(eoParser&
|
||||
_parser, eoState& _state, eoInit<Indi>& _init)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> return do_make_op(_parser, _state,
|
||||
_init);</font></tt></b>
|
||||
<br><b><tt><font color="#993399">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399">// Use existing modules to define representation
|
||||
independent routines</font></tt>
|
||||
<br><tt><font color="#993399">// These are parser-based definitions of
|
||||
objects</font></tt>
|
||||
<br><tt><font color="#993399">// how to initialize the population </font></tt>
|
||||
<br><tt><font color="#993399">// it IS representation independent if an
|
||||
eoInit is given</font></tt>
|
||||
<br><b><tt><font color="#993399">#include <do/make_pop.h></font></tt></b>
|
||||
<br><b><tt><font color="#993399">eoPop<Indi >& make_pop(eoParser&
|
||||
_parser, eoState& _state, eoInit<Indi> & _init)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> return do_make_pop(_parser, _state,
|
||||
_init);</font></tt></b>
|
||||
<br><b><tt><font color="#993399">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF">// the stopping criterion</font></tt>
|
||||
<br><b><tt><font color="#3366FF">#include <do/make_continue.h></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">eoContinue<Indi>& make_continue(eoParser&
|
||||
_parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">{</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> return do_make_continue(_parser,
|
||||
_state, _eval);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stat"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF">// outputs (stats, population dumps, ...)</font></tt>
|
||||
<br><b><tt><font color="#3366FF">#include <do/make_checkpoint.h></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">eoCheckPoint<Indi>& make_checkpoint(eoParser&
|
||||
_parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>&
|
||||
_continue) </font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">{</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> return do_make_checkpoint(_parser,
|
||||
_state, _eval, _continue);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900">// evolution engine (selection and replacement)</font></tt>
|
||||
<br><b><tt><font color="#009900">#include <do/make_algo_scalar.h></font></tt></b>
|
||||
<br><b><tt><font color="#009900">eoAlgo<Indi>& make_algo_scalar(eoParser&
|
||||
_parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>&
|
||||
_continue, eoGenOp<Indi>& _op)</font></tt></b>
|
||||
<br><b><tt><font color="#009900">{</font></tt></b>
|
||||
<br><b><tt><font color="#009900"> return do_make_algo_scalar(_parser,
|
||||
_state, _eval, _continue, _op);</font></tt></b>
|
||||
<br><b><tt><font color="#009900">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300">// simple call to the algo. stays there for
|
||||
consistency reasons </font></tt>
|
||||
<br><tt><font color="#993300">// no template for that one</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <do/make_run.h></font></tt></b>
|
||||
<br><tt><font color="#993300">// the instanciating fitnesses</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eoScalarFitness.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">void run_ea(eoAlgo<Indi>& _ga,
|
||||
eoPop<Indi>& _pop)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> do_run(_ga, _pop);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// checks for help demand, and writes the
|
||||
status file</font></tt>
|
||||
<br><tt><font color="#993300">// and make_help; in libutils</font></tt>
|
||||
<br><b><tt><font color="#993300">void make_help(eoParser & _parser);</font></tt></b>
|
||||
<br><tt><font color="#993300">// now use all of the above, + representation
|
||||
dependent things</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char* argv[])</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> eoParser parser(argc, argv); </b>
|
||||
// for user-parameter reading</font></tt>
|
||||
<br><tt><font color="#993300"><b> eoState state; </b>
|
||||
// keeps all things allocated</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b> //
|
||||
The fitness</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b> //////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> eoOneMaxEvalFunc<Indi>
|
||||
plainEval</b> /* (varType _anyVariable) */;<b>;</b></font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b> // turn that object
|
||||
into an evaluation counter</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncCounter<Indi>
|
||||
eval(plainEval);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900"><b> </b> // the genotype - through a
|
||||
genotype initializer</font></tt>
|
||||
<br><b><tt><font color="#999900"> eoInit<Indi>& init = make_genotype(parser,
|
||||
state, Indi());</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b> // Build the variation operator
|
||||
(any seq/prop construct)</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoGenOp<Indi>& op = make_op(parser,
|
||||
state, init);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> //// Now the representation-independent
|
||||
things </font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // YOU SHOULD NOT NEED TO MODIFY
|
||||
ANYTHING BEYOND THIS POINT</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // unless you want to add specific
|
||||
statistics to the checkpoint</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //////////////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b> // initialize the population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // yes, this is representation
|
||||
indepedent once you have an eoInit</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi>& pop
|
||||
= make_pop(parser, state, init);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b> // stopping criteria</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoContinue<Indi> & term =
|
||||
make_continue(parser, state, eval);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b> // output</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCheckPoint<Indi> & checkpoint
|
||||
= make_checkpoint(parser, state, eval, term);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300"><b> </b> // algorithm (need the operator!)</font></tt>
|
||||
<br><b><tt><font color="#993300"> eoAlgo<Indi>& ga = make_algo_scalar(parser,
|
||||
state, eval, checkpoint, op);</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b> ///// End of construction of
|
||||
the algorithm</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b> /////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b> // to be called AFTER all parameters
|
||||
have been read!!!</font></tt>
|
||||
<br><b><tt><font color="#993300"> make_help(parser);</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b> //// GO</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b> ///////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b> // evaluate intial population
|
||||
AFTER help and status in case it takes time</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> apply<Indi>(eval, pop);</font></tt></b>
|
||||
<br><tt><font color="#CC0000"><b> </b> // if you want to print it
|
||||
out</font></tt>
|
||||
<br><tt><font color="#CC0000">// cout << "Initial
|
||||
Population\n";</font></tt>
|
||||
<br><tt><font color="#CC0000">// pop.sortedPrintOn(cout);</font></tt>
|
||||
<br><tt><font color="#CC0000">// cout << endl;</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300"><b> run_ea(ga, pop); </b>// run the
|
||||
ga</font></tt>
|
||||
<br><b><tt><font color="#993300"> cout << "Final Population\n";</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> pop.sortedPrintOn(cout);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> cout << endl;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception& e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> cout <<
|
||||
e.what() << endl;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 0;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson5.html">Back to Lesson 5</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:marc.schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sat May
|
||||
4 07:37:41 2002<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
569
deprecated/eo/tutorial/html/SecondBitEA.html
Normal file
569
deprecated/eo/tutorial/html/SecondBitEA.html
Normal file
|
|
@ -0,0 +1,569 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>SecondBitEA.cpp</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
</a>-
|
||||
<a href="eoProgramming.html">Programming
|
||||
hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">SecondBitEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
<p>For this particular program, as all new lines are concerned with program
|
||||
parameter input and information output, the <font color="#FF6600">font
|
||||
color</font> for program-parameter-related sections will <font color="#FF6600">refer
|
||||
to the section where the parameters are used</font> whereas the background
|
||||
color will remain blue.
|
||||
<p><img SRC="EA_tutorial.jpg" USEMAP="#Map" ><map NAME="Map"><!-- Init --><area SHAPE="rect" HREF="#init" COORDS="14,31,135,70"><area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150"><!-- main loop --><area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150"><area SHAPE="rect" HREF="#output" COORDS="280,45,480,70"><area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150"><area SHAPE="rect" HREF="#select" COORDS="495,110,615,150"><area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230"><area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287"><area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305"><area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310"><area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310"><area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230"><!-- Center of loop --><area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260"><!-- 4 bottom lines --><area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370"><area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370"><area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397"><area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423"><area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450"><area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450"><area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450"><area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378"></map>
|
||||
<br><a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// SecondGA.cpp</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">//*</font></tt>
|
||||
<br><tt><font color="#993300">// Same code than FirstBitEA as far as Evolutionary
|
||||
Computation is concerned</font></tt>
|
||||
<br><tt><font color="#993300">// but now you learn to enter the parameters
|
||||
in a more flexible way</font></tt>
|
||||
<br><tt><font color="#993300">// and to twidle the output to your preferences!</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// standard includes</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream> </b>//
|
||||
cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <fstream></font></tt></b>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="evalfunc"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000">// a simple fitness function that computes
|
||||
the number of ones of a bitstring</font></tt>
|
||||
<br><b><tt><font color="#CC0000">#include "binary_value.h"</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// define your genotype and fitness types</font></tt>
|
||||
<br><b><tt><font color="#999900">typedef eoBit<double> Indi;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300">// the main_function: nothing changed(!),
|
||||
except variable initialization</font></tt>
|
||||
<br><b><tt><font color="#993300">void main_function(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#3366FF">// instead of having all values of useful
|
||||
parameters as constants, read them:</font></tt>
|
||||
<br><tt><font color="#3366FF">// either on the command line (--option=value
|
||||
or -o=value)</font></tt>
|
||||
<br><tt><font color="#3366FF">//
|
||||
or in a parameter file (same syntax, order independent, </font></tt>
|
||||
<br><tt><font color="#3366FF">//
|
||||
# = usual comment character </font></tt>
|
||||
<br><tt><font color="#3366FF">//
|
||||
or in the environment (TODO)</font></tt>
|
||||
<p><tt><font color="#3366FF">// First define a parser from the command-line
|
||||
arguments</font></tt>
|
||||
<br><a NAME="parser_declare"></a><b><tt><font color="#3366FF">eoParser
|
||||
parser(argc, argv);</font></tt></b>
|
||||
<p><tt><font color="#3366FF">// For each parameter, define Parameter, read
|
||||
it through the parser,</font></tt>
|
||||
<br><tt><font color="#3366FF">// and assign the value to the variable</font></tt>
|
||||
<br><a NAME="random"></a>
|
||||
<br><b><tt><font color="#990000">eoValueParam<uint32> seedParam(time(0),
|
||||
"seed", "Random number seed", 'S');</font></tt></b>
|
||||
<br><a NAME="seed_process"></a><b><tt><font color="#990000">parser.processParam(
|
||||
seedParam );</font></tt></b>
|
||||
<br><a NAME="seed_assign"></a><b><tt><font color="#990000">unsigned seed
|
||||
= seedParam.value();</font></tt></b>
|
||||
<p><a NAME="_seed_declare"></a><tt><font color="#999900">// decription
|
||||
of genotype</font></tt>
|
||||
<br><b><tt><font color="#999900">eoValueParam<unsigned int>& vecSizeParam(8,
|
||||
"vecSize", "Genotype size",'V');</font></tt></b>
|
||||
<br><b><tt><font color="#999900">parser.processParam( vecSizeParam, "Representation"
|
||||
);</font></tt></b>
|
||||
<br><b><tt><font color="#999900">unsigned vecSize = vecSizeParam.value();</font></tt></b>
|
||||
<p><tt><font color="#009900">// parameters for evolution engine</font></tt>
|
||||
<br><b><tt><font color="#009900">eoValueParam<unsigned int>& popSizeParam(10,
|
||||
"popSize", "Population size",'P');</font></tt></b>
|
||||
<br><b><tt><font color="#009900">parser.processParam( popSizeParam, "Evolution
|
||||
engine" );</font></tt></b>
|
||||
<br><b><tt><font color="#009900">unsigned popSize = popSizeParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#009900">eoValueParam<unsigned int>& tSizeParam(10,
|
||||
"tSize", "Tournament size",'T');</font></tt></b>
|
||||
<br><b><tt><font color="#009900">parser.processParam( seedParam );</font></tt></b>
|
||||
<br><b><tt><font color="#009900">unsigned tSize = tSizeParam.value();</font></tt></b>
|
||||
<br><a NAME="_load_name"></a>
|
||||
<br><tt><font color="#3366FF"><b> </b>// init and stop</font></tt>
|
||||
<br><b><tt><font color="#3366FF">eoValueParam<string> loadNameParam("",
|
||||
"Load","A save file to restart from",'L');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( loadNameParam, "Persistence"
|
||||
);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">string loadName = loadNameParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#3366FF">eoValueParam<unsigned int> maxGenParam(100,
|
||||
"maxGen", "Maximum number of generations",'G');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( maxGenParam, "Stopping
|
||||
criterion" );</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">unsigned maxGen = maxGenParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#3366FF">eoValueParam<unsigned int> minGenParam(100,
|
||||
"minGen", "Minimum number of generations",'g');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( minGenParam, "Stopping
|
||||
criterion" );</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">unsigned minGen = minGenParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#3366FF">eoValueParam<unsigned int> steadyGenParam(100,
|
||||
"steadyGen", "Number of generations with no improvement",'s');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( steadyGenParam, "Stopping
|
||||
criterion" );</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">unsigned steadyGen = steadyGenParam.value();</font></tt></b>
|
||||
<p><tt><font color="#CC33CC">// operators probabilities at the algorithm
|
||||
level</font></tt>
|
||||
<br><b><tt><font color="#CC33CC">eoValueParam<double> pCrossParam(0.6,
|
||||
"pCross", "Probability of Crossover", 'C'); </font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( pCrossParam, "Genetic
|
||||
Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double pCross = pCrossParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> pMutParam(0.1,
|
||||
"pMut", "Probability of Mutation", 'M');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( pMutParam, "Genetic
|
||||
Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double pMut = pMutParam.value();</font></tt></b>
|
||||
<p><tt><font color="#CC33CC">// relative rates for crossovers</font></tt>
|
||||
<br><b><tt><font color="#CC33CC">eoValueParam<double> onePointRateParam(1,
|
||||
"onePointRate", "Relative rate for one point crossover", '1');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( onePointRateParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double onePointRate = onePointRateParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> twoPointsRateParam(1,
|
||||
"twoPointRate", "Relative rate for two point crossover", '2');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( twoPointsRateParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double twoPointsRate = twoPointsRateParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> uRateParam(2, "uRate",
|
||||
"Relative rate for uniform crossover", 'U');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( uRateParam, "Genetic
|
||||
Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double URate = uRateParam.value();</font></tt></b>
|
||||
<p><tt><font color="#CC33CC">// relative rates and private parameters for
|
||||
mutations;</font></tt>
|
||||
<br><b><tt><font color="#CC33CC">eoValueParam<double> pMutPerBitParam(0.01,
|
||||
"pMutPerBit", "Probability of flipping 1 bit in bit-flip mutation", 'b');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( pMutPerBitParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double pMutPerBit = pMutPerBitParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> bitFlipRateParam(0.01,
|
||||
"bitFlipRate", "Relative rate for bit-flip mutation", 'B');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( bitFlipRateParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double bitFlipRate = bitFlipRateParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> oneBitRateParam(0.01,
|
||||
"oneBitRate", "Relative rate for deterministic bit-flip mutation", 'D');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( oneBitRateParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double oneBitRate = oneBitRateParam.value();</font></tt></b>
|
||||
<p><tt><font color="#3366FF">// the name of the "status" file where all
|
||||
actual parameter values will be saved</font></tt>
|
||||
<br><b><tt><font color="#3366FF">string str_status = parser.ProgramName()
|
||||
+ ".status"; // default value</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">eoValueParam<string> statusParam(str_status.c_str(),
|
||||
"status","Status file",'S');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( statusParam, "Persistence"
|
||||
);</font></tt></b>
|
||||
<p><tt><font color="#3366FF">// do the following AFTER ALL PARAMETERS HAVE
|
||||
BEEN PROCESSED</font></tt>
|
||||
<br><tt><font color="#3366FF">// i.e. in case you need parameters somewhere
|
||||
else, postpone these</font></tt>
|
||||
<br><b><tt><font color="#3366FF">if (parser.userNeedsHelp())</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> {</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> parser.printHelp(cout);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> exit(1);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> }</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">if (statusParam.value() != "")</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> {</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> ofstream
|
||||
os(statusParam.value().c_str());</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> os <<
|
||||
parser; </b>// and you can use that file as parameter file</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> }</font></tt></b></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b>/////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Fitness function</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Evaluation: from a plain
|
||||
C++ fn to an EvalFunc Object ...</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncPtr<Indi, double, const
|
||||
vector<bool>& > plainEval( binary_value );</font></tt></b>
|
||||
<br><a NAME="evalcounter"></a><tt><font color="#CC0000">// ... to an object
|
||||
that counts the nb of actual evaluations</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncCounter<Indi> eval(plainEval);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Initilisation of population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Either load or initialize</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// create an empty pop</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi> pop;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// create a state for reading</font></tt>
|
||||
<br><tt><font color="#993399"><b> eoState inState; </b>// a state
|
||||
for loading - WITHOUT the parser</font></tt>
|
||||
<br><a NAME="register"></a><tt><font color="#993399">// register the rng
|
||||
and the pop in the state, so they can be loaded,</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// and the present run will
|
||||
be the exact conitnuation of the saved run</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// eventually with different
|
||||
parameters</font></tt>
|
||||
<br><b><tt><font color="#993399"> inState.registerObject(rng);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> inState.registerObject(pop);</font></tt></b>
|
||||
<p><a NAME="instate.load"></a><b><tt><font color="#993399">if (load_name
|
||||
!= "")</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b>
|
||||
<br><a NAME="loadstate"></a><tt><font color="#993399"><b>
|
||||
inState.load(load_name); </b>// load the pop and the rng</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
the fitness is read in the file: </font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
do only evaluate the pop if the fitness has changed</font></tt>
|
||||
<br><b><tt><font color="#993399"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> else</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
rng.reseed(seed);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
a Indi random initializer</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
based on eoUniformGenerator class (see utils/eoRndGenerators.h)</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoUniformGenerator<bool>
|
||||
uGen;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> eoInitFixedLength<Indi>
|
||||
random(vecSize, uGen);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
Init pop from the randomizer: need to use the append function</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
pop.append(popSize, random); </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
and evaluate pop (STL syntax) </font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
apply<Indi>(eval, pop);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> } </b>// end
|
||||
of initialization of the population</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// sort pop for pretty printout</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population
|
||||
(raw printout)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> cout << "Initial Population"
|
||||
<< endl << pop << endl;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// selection and replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// The robust tournament selection</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoDetTournamentSelect<Indi> selectOne(tSize);
|
||||
</b>// tSize in [2,POPSIZE]</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// is now encapsulated in a
|
||||
eoSelectPerc (entage)</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoSelectPerc<Indi> select(selectOne);</font></tt></b>
|
||||
<br><tt><font color="#009900"> // or eoSelectPerc<Indi> select(selectOne,
|
||||
rate); </font></tt>
|
||||
<br><tt><font color="#009900"> // but by default rate==1</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// And we now have the full
|
||||
slection/replacement - though with </font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// the same generational replacement
|
||||
at the moment :-)</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoGenerationalReplacement<Indi>
|
||||
replace; </font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// The variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// 1-point crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eo1PtBitXover<Indi> xover1;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// uniform crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoUBitXover<Indi> xoverU;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// 2-pots xover</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoNPtsBitXover<Indi> xover2(2);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
rates</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> xover(xover1,
|
||||
onePointRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> xover.add(xoverU, URate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> xover.add(xover2, twoPointsRate,
|
||||
true);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// standard bit-flip mutation
|
||||
for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBitMutation<Indi> mutationBitFlip(pMutPerBit);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// mutate exactly 1 bit per
|
||||
individual</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoDetBitFlip<Indi> mutationOneBit; </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
rates</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedMonOp<Indi> mutation(mutationBitFlip,
|
||||
bitFlipRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> mutation.add(mutationOneBit, oneBitRate,
|
||||
true);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// The operators are encapsulated
|
||||
into an eoTRansform object</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoSGATransform<Indi> transform(xover,
|
||||
pCross, mutation, pMut);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// termination condition see
|
||||
FirstBitEA.cpp</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoGenContinue<Indi> genCont(maxGen);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoSteadyFitContinue<Indi> steadyCont(minGen,
|
||||
steadyGen);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoFitContinue<Indi> fitCont(vecSize);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoCombinedContinue<Indi> continuator(genCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(steadyCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(fitCont);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// but now you want to make
|
||||
many different things every generation </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// (e.g. statistics, plots,
|
||||
...).</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// the class eoCheckPoint is
|
||||
dedicated to just that:</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Declare a checkpoint (from
|
||||
a continuator: an eoCheckPoint </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// IS AN eoContinue and will
|
||||
be called in the loop of all algorithms)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCheckPoint<Indi> checkpoint(continuator);</font></tt></b>
|
||||
<p><a NAME="param_declare"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Create a counter parameter</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoValueParam<unsigned>
|
||||
generationCounter(0, "Gen.");</font></tt></b>
|
||||
<p><a NAME="param_pass"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Create an incrementor (sub-class of eoUpdater). Note that the </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// parameter's
|
||||
value is passed by reference, </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// so every
|
||||
time the incrementer is updated (every generation),</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// the data
|
||||
in generationCounter will change.</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoIncrementor<unsigned>
|
||||
increment(generationCounter.value());</font></tt></b>
|
||||
<br><a NAME="updater_pass"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Add it to the checkpoint, </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// so the
|
||||
counter is updated (here, incremented) every generation</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(increment);</font></tt></b>
|
||||
<br><a NAME="stat_declare"></a><tt><font color="#3366FF"><b> </b>//
|
||||
now some statistics on the population:</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Best fitness
|
||||
in population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoBestFitnessStat<Indi>
|
||||
bestStat;</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Second
|
||||
moment stats: average and stdev</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoSecondMomentStats<Indi>
|
||||
SecondStat;</font></tt></b>
|
||||
<br><a NAME="stat_pass"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Add them to the checkpoint to get them called at the appropriate time</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(bestStat);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(SecondStat);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// The Stdout
|
||||
monitor will print parameters to the screen ...</font></tt>
|
||||
<br><a NAME="monitor_declare"></a><b><tt><font color="#3366FF">
|
||||
eoStdoutMonitor monitor(false);</font></tt></b>
|
||||
<p><tt><font color="#3366FF"><b> </b>// when called
|
||||
by the checkpoint (i.e. at every generation)</font></tt>
|
||||
<br><a NAME="monitor_pass"></a><b><tt><font color="#3366FF">
|
||||
checkpoint.add(monitor);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// the monitor
|
||||
will output a series of parameters: add them </font></tt>
|
||||
<br><a NAME="monitor_add"></a><b><tt><font color="#3366FF">
|
||||
monitor.add(generationCounter);</font></tt></b><a NAME="eval_monitor"></a>
|
||||
<br><tt><font color="#3366FF"><b> monitor.add(eval);
|
||||
</b>//
|
||||
because now eval is an eoEvalFuncCounter!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> monitor.add(bestStat);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> monitor.add(SecondStat);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// A file
|
||||
monitor: will print parameters to ... a File, yes, you got it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoFileMonitor
|
||||
fileMonitor("stats.xg", " ");</font></tt></b>
|
||||
<p><tt><font color="#3366FF"><b> </b>// the checkpoint
|
||||
mechanism can handle multiple monitors</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(fileMonitor);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// the fileMonitor
|
||||
can monitor parameters, too, but you must tell it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> fileMonitor.add(generationCounter);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> fileMonitor.add(bestStat);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> fileMonitor.add(SecondStat);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Last type
|
||||
of item the eoCheckpoint can handle: state savers:</font></tt>
|
||||
<br><a NAME="outstate_declare"></a><b><tt><font color="#3366FF">
|
||||
eoState outState;</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Register
|
||||
the algorithm into the state</font></tt>
|
||||
<br><a NAME="outstate_register"></a><b><tt><font color="#3366FF">
|
||||
outState.registerObject(parser);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> outState.registerObject(pop);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> outState.registerObject(rng);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// and feed
|
||||
the state to state savers</font></tt>
|
||||
<br><a NAME="statesaver_declare"></a><tt><font color="#3366FF">// save
|
||||
state every 100th generation</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCountedStateSaver
|
||||
stateSaver1(100, outState, "generation"); </font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// save state
|
||||
every 1 seconds </font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoTimedStateSaver
|
||||
stateSaver2(1, outState, "time"); </font></tt></b>
|
||||
<br><a NAME="statesaver_pass"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Don't forget to add the two savers to the checkpoint</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(stateSaver1);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(stateSaver2);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// and that's
|
||||
it for the (control and) output</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#FF6666"><b> </b>/////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Easy EA requires </font></tt>
|
||||
<br><tt><font color="#FF6666"> // stopping criterion, eval, selection,
|
||||
transformation, replacement</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> eoEasyEA<Indi> gga(checkpoint,
|
||||
eval, select, transform, replace);</font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that's
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// Print (sorted) final population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"
|
||||
<< pop << endl;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> flag
|
||||
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b>
|
||||
<br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt>
|
||||
<br><b><tt><font color="#993300">#endif</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
main_function(argc, argv);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception&
|
||||
e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
cout << "Exception: " << e.what() << '\n';</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 1;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
</a>-
|
||||
<a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></b>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
|
||||
26 09:31:04 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
468
deprecated/eo/tutorial/html/SecondRealEA.html
Normal file
468
deprecated/eo/tutorial/html/SecondRealEA.html
Normal file
|
|
@ -0,0 +1,468 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="cpp2html Marc Schoenauer">
|
||||
<title>SecondRealEA</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">SecondRealEA</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" >
|
||||
<map NAME="Map">
|
||||
<!-- Init -->
|
||||
<area SHAPE="rect" HREF="#init" COORDS="14,31,135,70">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150">
|
||||
<!-- main loop -->
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150">
|
||||
<area SHAPE="rect" HREF="#output" COORDS="280,45,480,70">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150">
|
||||
<area SHAPE="rect" HREF="#select" COORDS="495,110,615,150">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230">
|
||||
<area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287">
|
||||
<area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310">
|
||||
<area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230">
|
||||
<!-- Center of loop -->
|
||||
<area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260">
|
||||
<!-- 4 bottom lines -->
|
||||
<area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370">
|
||||
<area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423">
|
||||
<area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450">
|
||||
<area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450">
|
||||
<area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378">
|
||||
</map>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// SecondRealEA.cpp<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
//*<br>
|
||||
// Same code than FirstBitEA as far as Evolutionary Computation is concerned<br>
|
||||
// but now you learn to enter the parameters in a more flexible way<br>
|
||||
// (also slightly different than in SecondBitEA.cpp)<br>
|
||||
// and to twidle the output to your preferences (as in SecondBitEA.cpp)<br>
|
||||
//<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// standard includes<br>
|
||||
<b>#include <stdexcept> </b>// runtime_error <br>
|
||||
<b>#include <iostream> </b>// cout<br>
|
||||
<b>#include <strstream> </b>// ostrstream, istrstream<br>
|
||||
// the general include for eo<br>
|
||||
<b>#include <eo></b><br>
|
||||
<b>#include <es.h></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your individuals<br>
|
||||
<b>typedef eoReal<eoMinimizingFitness> Indi; </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="evalfunc"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// a simple fitness function that computes the euclidian norm of a real vector<br>
|
||||
// Now in a separate file, and declared as binary_value(const vector<bool> &)<br>
|
||||
<b>#include "real_value.h"</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>void main_function(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// instead of having all values of useful parameters as constants, read them:<br>
|
||||
// either on the command line (--option=value or -o=value)<br>
|
||||
// or in a parameter file (same syntax, order independent, <br>
|
||||
// # = usual comment character <br>
|
||||
// or in the environment (TODO)<br>
|
||||
<b> </b>// First define a parser from the command-line arguments<br>
|
||||
<b> eoParser parser(argc, argv);</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// For each parameter, you can in on single line<br>
|
||||
<b> </b>// define the parameter, read it through the parser, and assign it<br>
|
||||
<b> </b><br>
|
||||
<a NAME="random"></a>
|
||||
<b> unsigned seed = parser.createParam(unsigned(time(0)), "seed", "Random number seed", 'S').value(); </b>// will be in default section General<br>
|
||||
<b> </b><br>
|
||||
<b> </b>// description of genotype<br>
|
||||
<b> unsigned vecSize = parser.createParam(unsigned(8), "vecSize", "Genotype size",'V', "Representation" ).value();</b><br>
|
||||
<b> </b>// parameters for evolution engine<br>
|
||||
<b> unsigned popSize = parser.createParam(unsigned(10), "popSize", "Population size",'P', "Evolution engine" ).value();</b><br>
|
||||
<b> unsigned tSize = parser.createParam(unsigned(2), "tSize", "Tournament size",'T', "Evolution Engine" ).value();</b><br>
|
||||
<b> </b>// init and stop<br>
|
||||
<b> string loadName = parser.createParam(string(""), "Load","A save file to restart from",'L', "Persistence" ).value();</b><br>
|
||||
<b> </b><br>
|
||||
<b> unsigned maxGen = parser.createParam(unsigned(100), "maxGen", "Maximum number of generations",'G', "Stopping criterion" ).value();</b><br>
|
||||
<b> unsigned minGen = parser.createParam(unsigned(100), "minGen", "Minimum number of generations",'g', "Stopping criterion" ).value();</b><br>
|
||||
<b> unsigned steadyGen = parser.createParam(unsigned(100), "steadyGen", "Number of generations with no improvement",'s', "Stopping criterion" ).value();</b><br>
|
||||
<b> </b>// operators probabilities at the algorithm level<br>
|
||||
<b> double pCross = parser.createParam(double(0.6), "pCross", "Probability of Crossover", 'C', "Genetic Operators" ).value();</b><br>
|
||||
<b> double pMut = parser.createParam(double(0.1), "pMut", "Probability of Mutation", 'M', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b>// relative rates for crossovers<br>
|
||||
<b> double hypercubeRate = parser.createParam(double(1), "hypercubeRate", "Relative rate for hypercube crossover", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> double segmentRate = parser.createParam(double(1), "segmentRate", "Relative rate for segment crossover", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b>// internal parameters for the mutations<br>
|
||||
<b> double EPSILON = parser.createParam(double(0.01), "EPSILON", "Width for uniform mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b><br>
|
||||
<b> double SIGMA = parser.createParam(double(0.3), "SIGMA", "Sigma for normal mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b>// relative rates for mutations<br>
|
||||
<b> double uniformMutRate = parser.createParam(double(1), "uniformMutRate", "Relative rate for uniform mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> double detMutRate = parser.createParam(double(1), "detMutRate", "Relative rate for det-uniform mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> double normalMutRate = parser.createParam(double(1), "normalMutRate", "Relative rate for normal mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b>// the name of the "status" file where all actual parameter values will be saved <br>
|
||||
<b> string str_status = parser.ProgramName() + ".status"; </b>// default value<br>
|
||||
<b> string statusName = parser.createParam(str_status, "status","Status file",'S', "Persistence" ).value();</b><br>
|
||||
<b> </b>// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED<br>
|
||||
<b> </b>// i.e. in case you need parameters somewhere else, postpone these<br>
|
||||
<b> if (parser.userNeedsHelp())</b><br>
|
||||
<b> {</b><br>
|
||||
<b> parser.printHelp(cout);</b><br>
|
||||
<b> exit(1);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> if (statusName != "")</b><br>
|
||||
<b> {</b><br>
|
||||
<b>ofstream os(statusName.c_str());</b><br>
|
||||
<b>os << parser; </b>// and you can use that file as parameter file<br>
|
||||
<b> }</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
<b> </b>/////////////////////////////<br>
|
||||
<b> </b>// Fitness function<br>
|
||||
<b> </b>////////////////////////////<br>
|
||||
<b> </b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
|
||||
<b> </b>// you need to give the full description of the function<br>
|
||||
<b> eoEvalFuncPtr<Indi, double, const vector<double>& > plainEval( real_value );</b><br>
|
||||
<b> </b>// ... to an object that counts the nb of actual evaluations<br>
|
||||
<b> eoEvalFuncCounter<Indi> eval(plainEval);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// Initilisation of population<br>
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// Either load or initialize<br>
|
||||
<b> </b>// create an empty pop<br>
|
||||
<b> eoPop<Indi> pop;</b><br>
|
||||
<b> </b>// create a state for reading<br>
|
||||
<b> eoState inState; </b>// a state for loading - WITHOUT the parser<br>
|
||||
<b> </b>// register the rng and the pop in the state, so they can be loaded,<br>
|
||||
<b> </b>// and the present run will be the exact conitnuation of the saved run<br>
|
||||
<b> </b>// eventually with different parameters<br>
|
||||
<b> inState.registerObject(rng);</b><br>
|
||||
<b> inState.registerObject(pop);</b><br>
|
||||
<b> </b><br>
|
||||
<b> if (loadName != "")</b><br>
|
||||
<b> {</b><br>
|
||||
<b> inState.load(loadName); </b>// load the pop and the rng<br>
|
||||
<b> </b>// the fitness is read in the file: <br>
|
||||
<b> </b>// do only evaluate the pop if the fitness has changed<br>
|
||||
<b> }</b><br>
|
||||
<b> else</b><br>
|
||||
<b> {</b><br>
|
||||
<b> rng.reseed(seed);</b><br>
|
||||
<b> </b>// a Indi random initializer<br>
|
||||
<b> </b>// based on boolean_generator class (see utils/rnd_generator.h)<br>
|
||||
<b> eoUniformGenerator<double> uGen(-1.0, 1.0);</b><br>
|
||||
<b> eoInitFixedLength<Indi> random(vecSize, uGen);</b><br>
|
||||
<b> </b>// Init pop from the randomizer: need to use the append function<br>
|
||||
<b> pop.append(popSize, random); </b><br>
|
||||
<b> </b>// and evaluate pop (STL syntax) <br>
|
||||
<b> apply<Indi>(eval, pop);</b><br>
|
||||
<b> } </b>// end of initializatio of the population<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// sort pop before printing it!<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> </b>// Print (sorted) intial population (raw printout)<br>
|
||||
<b> cout << "Initial Population" << endl;</b><br>
|
||||
<b> cout << pop;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// selection and replacement<br>
|
||||
<b> </b>////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// The robust tournament selection<br>
|
||||
<b> eoDetTournamentSelect<Indi> selectOne(tSize);</b><br>
|
||||
<b> </b>// is now encapsulated in a eoSelectPerc (entage)<br>
|
||||
<b> eoSelectPerc<Indi> select(selectOne);</b>// by default rate==1<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// And we now have the full slection/replacement - though with <br>
|
||||
<b> </b>// no replacement (== generational replacement) at the moment :-)<br>
|
||||
<b> eoGenerationalReplacement<Indi> replace; </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// The variation operators<br>
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// uniform chooce on segment made by the parents<br>
|
||||
<b> eoSegmentCrossover<Indi> xoverS;</b><br>
|
||||
<b> </b>// uniform choice in hypercube built by the parents<br>
|
||||
<b> eoHypercubeCrossover<Indi> xoverA;</b><br>
|
||||
<b> </b>// Combine them with relative weights<br>
|
||||
<b> eoPropCombinedQuadOp<Indi> xover(xoverS, segmentRate);</b><br>
|
||||
<b> xover.add(xoverA, hypercubeRate, true);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]<br>
|
||||
<b> eoUniformMutation<Indi> mutationU(EPSILON); </b><br>
|
||||
<b> </b>// k (=1) coordinates of parents are uniformly modified<br>
|
||||
<b> eoDetUniformMutation<Indi> mutationD(EPSILON); </b><br>
|
||||
<b> </b>// all coordinates of parents are normally modified (stDev SIGMA)<br>
|
||||
<b> eoNormalMutation<Indi> mutationN(SIGMA); </b><br>
|
||||
<b> </b>// Combine them with relative weights<br>
|
||||
<b> eoPropCombinedMonOp<Indi> mutation(mutationU, uniformMutRate);</b><br>
|
||||
<b> mutation.add(mutationD, detMutRate);</b><br>
|
||||
<b> mutation.add(mutationN, normalMutRate, true);</b><br>
|
||||
<b> </b>// The operators are encapsulated into an eoTRansform object<br>
|
||||
<b> eoSGATransform<Indi> transform(xover, pCross, mutation, pMut);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// termination condition see FirstBitEA.cpp<br>
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> eoGenContinue<Indi> genCont(maxGen);</b><br>
|
||||
<b> eoSteadyFitContinue<Indi> steadyCont(minGen, steadyGen);</b><br>
|
||||
<b> eoFitContinue<Indi> fitCont(0);</b><br>
|
||||
<b> eoCombinedContinue<Indi> continuator(genCont);</b><br>
|
||||
<b> continuator.add(steadyCont);</b><br>
|
||||
<b> continuator.add(fitCont);</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// but now you want to make many different things every generation <br>
|
||||
<b> </b>// (e.g. statistics, plots, ...).<br>
|
||||
<b> </b>// the class eoCheckPoint is dedicated to just that:<br>
|
||||
<b> </b>// Declare a checkpoint (from a continuator: an eoCheckPoint <br>
|
||||
<b> </b>// IS AN eoContinue and will be called in the loop of all algorithms)<br>
|
||||
<b> eoCheckPoint<Indi> checkpoint(continuator);</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// Create a counter parameter<br>
|
||||
<b> eoValueParam<unsigned> generationCounter(0, "Gen.");</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// Create an incrementor (sub-class of eoUpdater). Note that the <br>
|
||||
<b> </b>// parameter's value is passed by reference, <br>
|
||||
<b> </b>// so every time the incrementer is updated (every generation),<br>
|
||||
<b> </b>// the data in generationCounter will change.<br>
|
||||
<b> eoIncrementor<unsigned> increment(generationCounter.value());</b><br>
|
||||
<b> </b>// Add it to the checkpoint, <br>
|
||||
<b> </b>// so the counter is updated (here, incremented) every generation<br>
|
||||
<b> checkpoint.add(increment);</b><br>
|
||||
<b> </b>// now some statistics on the population:<br>
|
||||
<b> </b>// Best fitness in population<br>
|
||||
<b> eoBestFitnessStat<Indi> bestStat;</b><br>
|
||||
<b> </b>// Second moment stats: average and stdev<br>
|
||||
<b> eoSecondMomentStats<Indi> SecondStat;</b><br>
|
||||
<b> </b>// Add them to the checkpoint to get them called at the appropriate time<br>
|
||||
<b> checkpoint.add(bestStat);</b><br>
|
||||
<b> checkpoint.add(SecondStat);</b><br>
|
||||
<b> </b>// The Stdout monitor will print parameters to the screen ...<br>
|
||||
<b> eoStdoutMonitor monitor(false);</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// when called by the checkpoint (i.e. at every generation)<br>
|
||||
<b> checkpoint.add(monitor);</b><br>
|
||||
<b> </b>// the monitor will output a series of parameters: add them <br>
|
||||
<b> monitor.add(generationCounter);</b><br>
|
||||
<b> monitor.add(eval); </b>// because now eval is an eoEvalFuncCounter!<br>
|
||||
<b> monitor.add(bestStat);</b><br>
|
||||
<b> monitor.add(SecondStat);</b><br>
|
||||
<b> </b>// A file monitor: will print parameters to ... a File, yes, you got it!<br>
|
||||
<b> eoFileMonitor fileMonitor("stats.xg", " ");</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// the checkpoint mechanism can handle multiple monitors<br>
|
||||
<b> checkpoint.add(fileMonitor);</b><br>
|
||||
<b> </b>// the fileMonitor can monitor parameters, too, but you must tell it!<br>
|
||||
<b> fileMonitor.add(generationCounter);</b><br>
|
||||
<b> fileMonitor.add(bestStat);</b><br>
|
||||
<b> fileMonitor.add(SecondStat);</b><br>
|
||||
<b> </b>// Last type of item the eoCheckpoint can handle: state savers:<br>
|
||||
<b> eoState outState;</b><br>
|
||||
<b> </b>// Register the algorithm into the state (so it has something to save!!)<br>
|
||||
<b> outState.registerObject(parser);</b><br>
|
||||
<b> outState.registerObject(pop);</b><br>
|
||||
<b> outState.registerObject(rng);</b><br>
|
||||
<b> </b>// and feed the state to state savers<br>
|
||||
<b> </b>// save state every 100th generation<br>
|
||||
<b> eoCountedStateSaver stateSaver1(20, outState, "generation"); </b><br>
|
||||
<b> </b>// save state every 1 seconds <br>
|
||||
<b> eoTimedStateSaver stateSaver2(1, outState, "time"); </b><br>
|
||||
<b> </b>// Don't forget to add the two savers to the checkpoint<br>
|
||||
<b> checkpoint.add(stateSaver1);</b><br>
|
||||
<b> checkpoint.add(stateSaver2);</b><br>
|
||||
<b> </b>// and that's it for the (control and) output<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#FF6666">
|
||||
<b> </b>/////////////////////////////////////////<br>
|
||||
<b> </b>// the algorithm<br>
|
||||
<b> </b>////////////////////////////////////////<br>
|
||||
<b> </b>// Easy EA requires <br>
|
||||
<b> </b>// stopping criterion, eval, selection, transformation, replacement<br>
|
||||
<b> eoEasyEA<Indi> gga(checkpoint, eval, select, transform, replace);</b><br>
|
||||
<b> </b>// Apply algo to pop - that's it!<br>
|
||||
<b> gga(pop);</b><br>
|
||||
<b> </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// Print (sorted) intial population<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> cout << "FINAL Population\n" << pop << endl;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b>}</b><br>
|
||||
// A main that catches the exceptions<br>
|
||||
<b>int main(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
<b> main_function(argc, argv);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << "Exception: " << e.what() << '\n';</b><br>
|
||||
<b> }</b><br>
|
||||
<b> return 1;</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr WIDTH="100%"><a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:marc.schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Sun Apr 28 06:42:44 2002
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
BIN
deprecated/eo/tutorial/html/beige009.jpg
Normal file
BIN
deprecated/eo/tutorial/html/beige009.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
57
deprecated/eo/tutorial/html/binary_value.html
Normal file
57
deprecated/eo/tutorial/html/binary_value.html
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>binary_value.h</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">binary_value.h</font></h1></center>
|
||||
<a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><b><tt><font color="#993300">#include <eo></font></tt></b>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">/** Just a simple function that takes binary
|
||||
value of a chromosome and sets</font></tt>
|
||||
<br><tt><font color="#993300"> the fitnes.</font></tt>
|
||||
<br><tt><font color="#993300"> @param _chrom A
|
||||
binary chromosome </font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">double binary_value(const vector<bool>&
|
||||
_chrom)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> double sum = 0;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> for (unsigned i = 0; i < _chrom.size();
|
||||
i++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> sum += _chrom[i];</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> return sum;</font></tt></b>
|
||||
<br><b><tt><font color="#993399">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Wed Nov
|
||||
29 09:03:09 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
21
deprecated/eo/tutorial/html/debut.html
Normal file
21
deprecated/eo/tutorial/html/debut.html
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>TITRE</title>
|
||||
</head>
|
||||
|
||||
<body text="#000000" background="beige009.jpg" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<!-- -------------- End of header ------------------ -->
|
||||
<!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1><font color="#FF0000">TITRE</font></h1>
|
||||
</center>
|
||||
|
||||
<font face="Courier New,Courier"><font size=+1>
|
||||
<p>
|
||||
77
deprecated/eo/tutorial/html/eoBottomUp.html
Normal file
77
deprecated/eo/tutorial/html/eoBottomUp.html
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.72 [en] (X11; U; Linux 2.2.16 i686) [Netscape]">
|
||||
<title>EO - The Component-Based approach</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#CCCCCC" link="#0000EF" vlink="#51188E" alink="#FF0000">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">EO - Component-Based approach</font></h1></center>
|
||||
|
||||
<p><br>Congratulations - You have chosen the component-based approach!
|
||||
From here you will be allowed to browse into the different components of
|
||||
an Evolutionary Algorithm, and to see how to program your favorite using
|
||||
the EO library.
|
||||
|
||||
<h3>
|
||||
<font color="#000099">Table of Content</font></h3>
|
||||
|
||||
<center>
|
||||
<p><img SRC="EA_tutorial.jpg" USEMAP="#Map" ></center>
|
||||
|
||||
<p>Yes, this is the table of content of this part
|
||||
of the EO tutorial. If you don't already know what this symbolic
|
||||
representation of an EA means, you should try <a
|
||||
href="eoIntroEA.html">here</a>. Otherwise, <font color="#FF6600">click on the figure</font>
|
||||
to go directly to the corresponding section of the tutorial.
|
||||
<br>
|
||||
<map NAME="Map">
|
||||
<area SHAPE="rect" HREF="eoInit.html" COORDS="14,31,135,70">
|
||||
<area SHAPE="rect" HREF="eoEval.html" COORDS="14,110,135,150">
|
||||
|
||||
<area SHAPE="rect" HREF="eoRepresentation.html" COORDS="340,270,465,310">
|
||||
<area SHAPE="rect" HREF="eoIo.html#output" COORDS="280,45,480,70">
|
||||
<area SHAPE="rect" HREF="eoIo.html#stop" COORDS="348,110,430,150">
|
||||
<area SHAPE="rect" HREF="eoEngine.html#selection" COORDS="495,110,615,150">
|
||||
|
||||
<area SHAPE="rect" HREF="eoRepresentation.html" COORDS="495,190,615,230">
|
||||
<area SHAPE="rect" HREF="eoOperators.html#crossover" COORDS="495,265,625,287">
|
||||
<area SHAPE="rect" HREF="eoOperators.html#mutation" COORDS="495,287,625,305">
|
||||
|
||||
<area SHAPE="rect" HREF="eoRepresentation.html" COORDS="170,110,295,150">
|
||||
<area SHAPE="rect" HREF="eoEval.html" COORDS="170,270,295,310">
|
||||
<area SHAPE="rect" HREF="eoEngine.html#replacement" COORDS="170,190,295,230">
|
||||
|
||||
<area SHAPE="rect" HREF="eoGeneration.html" COORDS="310,160,485,260">
|
||||
|
||||
|
||||
<area SHAPE="rect" HREF="eoOperators.html" COORDS="15,350,260,370">
|
||||
<area SHAPE="rect" HREF="eoRepresentation.html" COORDS="270,350,460,370">
|
||||
<area SHAPE="rect" HREF="eoEngine.html" COORDS="15,377,400,397">
|
||||
<area SHAPE="rect" HREF="eoEval.html" COORDS="15,403,230,423">
|
||||
<area SHAPE="rect" HREF="eoCheckPoint.html" COORDS="15,430,221,450">
|
||||
<area SHAPE="rect" HREF="eoCheckpoint.html#stop" COORDS="221,430,345,450">
|
||||
<area SHAPE="rect" HREF="eoCheckpoint.html#stat" COORDS="375,430,445,450">
|
||||
</map>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="eoTutorial.html">Tutorial main page </a>- <a href="eoTopDown.html">Algorithm-Based
|
||||
</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Mon Oct 30 07:28:36 CET 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
150
deprecated/eo/tutorial/html/eoCheckPoint.html
Normal file
150
deprecated/eo/tutorial/html/eoCheckPoint.html
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.73 [en] (X11; I; Linux 2.2.15-4mdk i686) [Netscape]">
|
||||
<title>Variation Operators</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
|
||||
<b><font color="#FF0000">General</font></b>: <a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#FF0000">Local</font></b>: <a href="#introduction">Introduction</a>
|
||||
- <a href="#continuator">Continuators</a> - <a href="#combined_continue">Combined
|
||||
continuators</a> - <a href="#checkpoint">Checkpoints</a> - <a href="#statistic">Statistics</a>
|
||||
- <a href="#monitor">Monitors</a> - <a href="#updater">Updaters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<b><font color="#CC0000">CheckPointing</font></b></h1></center>
|
||||
<a NAME="introduction"></a><b><font color="#000099"><font size=+2>What
|
||||
is Checkpointing about?</font></font></b>
|
||||
<br>Evolutionary Algorithms are almost all timely ticked, the basic time
|
||||
unit being what is called a generation. EO checkpointing mechanism allow
|
||||
you to program things that you want to be done at the end of every generation.
|
||||
This includes deciding to stop, outputing some statistics on the current
|
||||
state of the algorithm, updating some dynamical variables of your
|
||||
algorithm, saving the population to disk, ...
|
||||
<p><b><font color="#FF0000">EO classes described in this page</font></b>:
|
||||
<ul>
|
||||
<li>
|
||||
<b><font color="#FF0000">Base classes</font></b>: eoCheckPoint, <a href="#continuator">eoContinue</a>,
|
||||
eoStat, eoSortedStat, eoMonitor, eoUpdater</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF0000">Derived classes</font></b>: eoCombinedContinue,</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF0000">Related classes</font></b>: eoGnuPlot1DMonitor,
|
||||
eoGnuPlot1DSnapshotMonitor,</li>
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="continuator"></a><b><font color="#000099"><font size=+1>Continuators:</font></font></b>
|
||||
<p>Continuators are functors that compute stopping critera. They receive
|
||||
a population and return a boolean value which is set to false only when
|
||||
some stopping vriterion is met. All algorithms in EO have a loop that goes
|
||||
<b><font color="#993300">do{...}while(continuator(pop)</font></b>which
|
||||
means that the algorithm stops only when the continuator returns <b><font color="#993300">false</font></b>.
|
||||
<p><b><font color="#FF0000">Interface</font></b>: The abstract class
|
||||
for computing stopping conditions is <b><font color="#3366FF">eoContinue</font></b>,
|
||||
and the interface for its operator() is
|
||||
<p>
|
||||
|
||||
<b><tt><font color="#993300"><font size=+1>bool operator()(const eoPop<EOT>&
|
||||
)</font></font></tt></b>
|
||||
<p>which you could have guessed from the <a href="../../doc/html/classeo_continue.html">inheritance
|
||||
diagram</a> for class <b><font color="#3366FF">eoContinue</font></b>, as
|
||||
you see there that <b><font color="#3366FF">eoContinue</font></b> derives
|
||||
from class <b><tt><font color="#993300"><font size=+1>eoUF<const eoPop<EOT>&,
|
||||
bool></font></font></tt></b>.
|
||||
<p><b><font color="#FF0000">Using a continuator</font></b>:
|
||||
<br>You can find an first example of using a continuator in the code for
|
||||
<a href="FirstBitGA.html#stop">FirstBitEA</a>
|
||||
ior more sophisticated continue conditions in <a href="eoLesson2.html#combinedContinue">Lesson2</a>.
|
||||
<br>If you want to find out how it is used inside an algorithm, go and
|
||||
see for instance in eoSGA, the simplest EA within EO.
|
||||
<p><a NAME="writing_continuator"></a><b><font color="#FF0000">Writing a
|
||||
continuator:</font></b>
|
||||
<br>There are only two things to modify in the <a href="../Templates/continue.tmpl">template
|
||||
class definitions</a> provided (apart from the name of the class you are
|
||||
creating!)
|
||||
<ul>
|
||||
<li>
|
||||
The <font color="#FF6600">constructor</font>, where you pass to the object
|
||||
any useful parameter (see the private data at end of class definition).</li>
|
||||
|
||||
<li>
|
||||
The <font color="#FF6600">operator()</font> method, which performs the
|
||||
computation of the actual test using the population plus any other parameter
|
||||
passed at construct time. Don't forget to <b><font color="#FF6600">returnfalse</font></b>
|
||||
when the stopping criterion <b><font color="#FF6600">is met!</font></b></li>
|
||||
</ul>
|
||||
<a NAME="existingContinue"></a><b><font color="#FF0000">Existing continuators:
|
||||
</font></b>Of
|
||||
course you can find out all existing (non-virtual!) subclasses of eoContinue
|
||||
by looking at its <a href="../../doc/html/classeo_continue.html">inheritance
|
||||
diagram</a>. But you might find it more convenient to have them listed
|
||||
here:
|
||||
<ul>
|
||||
<li>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%"><a NAME="combined_continue"></a><b><font color="#000099"><font size=+1>Combining
|
||||
continuators:</font></font></b>
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="checkpoint"></a><b><font color="#000099"><font size=+1>CheckPoints:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using a checkpoint</font></b>: An eoCheckPoint
|
||||
being an eoContinue, its usage is exactly the same. However, an eoCheckPoint
|
||||
will actually do many more things than an eoContinue before returning its
|
||||
boolean result as an eoContinue.
|
||||
<p><a NAME="writing_checkpoint"></a><b><font color="#FF0000">Writing a
|
||||
checkpoint:</font></b>
|
||||
<br>This is something you should never have to do. However, should you
|
||||
feel you have to do it, please do - and send us both the reasons that lead
|
||||
you to that (what is it you couldn't do with existing eoCheckPoint), and
|
||||
the resulting code, of course.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="statistic"></a><b><font color="#000099"><font size=+1>Statistics:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using statistics</font></b>:
|
||||
<p><a NAME="writing_statistic"></a><b><font color="#FF0000">Writing a statitic</font></b>:
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="monitor"></a><b><font color="#000099"><font size=+1>Monitors:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using monitors</font></b>:
|
||||
<p><a NAME="writing_monitor"></a><b><font color="#FF0000">Writing a monitor</font></b>:
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="updater"></a><b><font color="#000099"><font size=+1>Updater:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using updaters</font></b>:
|
||||
<p><a NAME="writing_updater"></a><b><font color="#FF0000">Writing an updater</font></b>:
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">Local</font></b>: <a href="#introduction">Introduction</a>
|
||||
- <a href="#continuator">Continuators</a> - <a href="#combined_continue">Combined
|
||||
continuators</a> - <a href="#checkpoint">Checkpoints</a> - <a href="#statistic">Statistics</a>
|
||||
- <a href="#monitor">Monitors</a> - <a href="#updater">Updaters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">General</font></b>: <a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> -<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Fri Dec. 8 2000 <!-- hhmts end -->
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
778
deprecated/eo/tutorial/html/eoEngine.html
Normal file
778
deprecated/eo/tutorial/html/eoEngine.html
Normal file
|
|
@ -0,0 +1,778 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
|
||||
<title>Genetic Engine</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
|
||||
<b><font color="#CC0000">General: </font></b><a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation
|
||||
<hr WIDTH="100%"></a></font></font><font color="#CC0000">Local: </font></b><a href="#introduction">Introduction</a>
|
||||
- <a href="#selection">Selection</a> - <a href="#replacement">Replacement</a>
|
||||
- <a href="#general">General Replacement</a> - <a href="#popular">Popular
|
||||
evolution engines</a> - <a href="#tournament">Tournaments</a> - <a href="#merge">Merge</a>
|
||||
- <a href="#reduce">Reduce</a> - <a href="#howmany">HowMany</a> - <a href="#SAD">SurviveAndDie</a>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<b><font color="#CC0000">Evolution Engine</font></b></h1></center>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="introduction"></a><b><font color="#000099"><font size=+2>Evolution
|
||||
Engines</font></font></b>
|
||||
<p>The term <b><font color="#FF6600">evolution engine</font></b> denotes
|
||||
the different parts of an Evolutionary Algorithm that simulate the Darwinism:
|
||||
<center>
|
||||
<p><i><font color="#009900">The fittest individuals are more likely to
|
||||
reproduce and survive.</font></i></center>
|
||||
|
||||
<p>Darwinism takes place in two different phases of an EA, though in many
|
||||
<a href="#popular">popular
|
||||
variants</a>, only one phase is activated.
|
||||
<p><a href="#selection">Selection</a> is the Darwinistic choice of parents
|
||||
that will be allowed to <b><font color="#009900">reproduce</font></b><font color="#CC33CC">.</font>
|
||||
<br><a href="#replacement">Replacement</a> takes place after reproduction,
|
||||
and is the Darwinistic choice of those individuals that will <b><font color="#009900">survive</font></b>,
|
||||
i.e. become the parents of the next generation.
|
||||
<p>Both selection and replacement will be discussed in turn, before some
|
||||
helper classes that are used within selection and replacement procedures
|
||||
are presented.
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="selection"></a><b><font color="#000099"><font size=+2>Selection</font></font></b>
|
||||
<p>The very beginning of the generation loop is the selection phase, where
|
||||
some individuals from the population are chosen to become the parents,
|
||||
to be later modified by the variation operators and become the offspring.
|
||||
This is the first step of the <font color="#009900">artificial Darwinism</font>,
|
||||
where the <i><font color="#FF6600">fittest individuals are allowed to reproduce</font></i>.
|
||||
<br>Conceptually, there are two distinct ways to choose the lucky ones:
|
||||
one by one from the very same population (i.e. with replacement), which
|
||||
means that at the extreme the same individual can be chosen every time;
|
||||
or as a whole, in some sort of batch procedure. Of course, repeated selection
|
||||
of one individual results in a batch selection!
|
||||
<p>There are hence two basic EO classes for selection: <font color="#009900">eoSelectOne</font>
|
||||
and <font color="#009900">eoSelect</font>, with different interfaces.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelectOne: </font><font color="#FF0000">The
|
||||
interface</font></b>
|
||||
<p>The abstract class for selection of a single individual from a population
|
||||
is <font color="#009900">eoSelectOne</font>, and the interface for its
|
||||
<tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">const EOT & operator()(const eoPop<EOT>&
|
||||
_parents)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_select_one.html">eoSelectOne</a></font></font></b>.,
|
||||
as you see there that <font color="#009900">eoSelectOne</font> derives
|
||||
from <tt><font color="#993300">class eoUF<const eoPop<EOT>&,
|
||||
const EOT&></font></tt>.
|
||||
<br>This means that it takes <font color="#FF6600">1 population</font>
|
||||
(without the right to modify it - see the <b><tt><font color="#993300">const</font></tt></b>
|
||||
keyword in argument) and returns a const reference to an individual (again,
|
||||
the <b><tt><font color="#993300">const</font></tt></b> keyword ensures
|
||||
that nothing will happen to the individual in the population - remember
|
||||
it returns a reference).
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelectOne: </font><font color="#FF0000">Instances</font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoDetTournamentSelect</font></tt></b> uses
|
||||
the <a href="#detTournament">(deterministic) tournament</a> to choose one
|
||||
individual. Its constructor has one parameter, the tournament size (integer
|
||||
>= 2).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoStochTournamentSelect</font></tt></b> uses
|
||||
the <a href="#stochTournament">binary stochastic tournament</a> to choose
|
||||
one individual. Its constructor has one parameter, the tournament rate
|
||||
(real in [0.5,1]).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoProportionalSelect</font></tt></b>
|
||||
is the original <font color="#FF6600">roulette wheel</font> selection:
|
||||
each parent is selected with a probability proportional to its fitness.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoRandomSelect</font></tt></b> is the <font color="#FF6600">random</font>
|
||||
selection and should give bad results! At the moment, it selects one individual
|
||||
uniformly, but it would be easy to use any probability distribution.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelect: </font><font color="#FF0000">The
|
||||
interface</font></b>
|
||||
<p>The abstract class for batch selection of a whole set of individuals
|
||||
from a population is <font color="#009900">eoSelect</font>, and the interface
|
||||
for its
|
||||
<tt><font color="#993300">operator()</font></tt> is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(const eoPop<EOT>&
|
||||
_source, eoPop<EOT>& _dest)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_select.html">eoSelect</a></font></font></b>.,
|
||||
as you see there that <font color="#009900">eoSelect</font> derives from
|
||||
<tt><font color="#993300">class
|
||||
eoBF<const eoPop<EOT>&, eoPop<EOT>&, void></font></tt>.
|
||||
<br>This means that it takes <font color="#FF6600">2 populations</font>,
|
||||
and fills the second one with individuals from the first one without modifying
|
||||
it (see the <b><tt><font color="#993300">const</font></tt></b> keyword).
|
||||
This raises two questions:
|
||||
<ul>
|
||||
<li>
|
||||
How does it know how many individuals to select?</li>
|
||||
|
||||
<li>
|
||||
How to use repeated selection of one individual (see above the <font color="#009900">eoSelectOne</font>
|
||||
class)?</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelect: </font><font color="#FF0000">HowMany</font></b>
|
||||
<p>There are two ways an can derive the number of individuals it
|
||||
has to select: either it is a fixed number, or it is some percentage of
|
||||
the source population size (any positive real number). In both case, this
|
||||
must be passed to the constructor. In most instances, however, the constructor
|
||||
will accept a real number (double) and a boolean indicating whether this
|
||||
real number should be used as an absolute integer or as a rate, thanks
|
||||
to the <a href="#howmany">eoHowMany</a> class.
|
||||
<p><b><font color="#FF0000">Note</font></b>: an <font color="#009900">eoSelect</font>
|
||||
can select more individuals than there are in the original population.
|
||||
It is the job of the <font color="#009900">replacement</font> to ensure
|
||||
that the population size does not grow along the generations.
|
||||
<p>
|
||||
<hr WIDTH="50%"><b><font color="#000099">eoSelectMany: </font><font color="#FF0000">Encapsulating
|
||||
eoSelectOne</font></b>
|
||||
<p>It is clear that repeated selection of a single individual is a way
|
||||
to do batch selection. This is why it is possible to encapsulate an object
|
||||
of class <font color="#009900">eoSelectOne</font> into an object of class
|
||||
<font color="#009900">eoSelect</font>
|
||||
using the class <font color="#009900">eoSelectMany</font>. Class <font color="#009900">eoSelectMany</font>
|
||||
is derived from class <font color="#009900">eoSelect</font> and takes in
|
||||
its constructor an <font color="#009900">eoSelectOne</font> (plus the number
|
||||
of individuals it should select, according to the <a href="#howmany">eoHowMany</a>
|
||||
paradigm).
|
||||
<p><b><font color="#FF0000">Note</font></b>: some procedures for selecting
|
||||
a single individual require some pre-processing of the whole population
|
||||
that takes place before any selection, and will be repeated identically
|
||||
for every individual. The encapsulation of an into an allows
|
||||
to call such technical processing only once through the use of method setup
|
||||
of class . This method does nothing by default, but is mandatory
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelect: </font><font color="#FF0000">Other
|
||||
instances</font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoDetSelect</font></tt></b> selects individuals
|
||||
<b><font color="#FF6600">deterministically</font></b>,
|
||||
i.e. starting from the best ones down to the worse ones. If the total number
|
||||
to select is less than the size of the source populations, the best individuals
|
||||
are selected once. If more individuals are needed after reaching the bottom
|
||||
of the population, then the selection starts again at top. It the total
|
||||
number required is N times that of the source size, all individuals are
|
||||
selected exactly N times.</li>
|
||||
</ul>
|
||||
No other instances of <font color="#009900">eoSelect</font> that are not
|
||||
encapsualtions of <font color="#009900">eoSelectOne</font> procedures are
|
||||
avaiable as of today (Jan. 4 2001).
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="replacement"></a><b><font color="#000099"><font size=+2>Replacement</font></font></b>
|
||||
<p>The replacement phase takes plac<font color="#000000">e after the birth
|
||||
of all offspring through </font>variation operators. This is the second
|
||||
step of the <font color="#009900">artificial Darwinism</font>, where the
|
||||
<i><font color="#FF6600">fittest
|
||||
individuals are allowed to survive</font></i>.
|
||||
<br>It can also be viewed on the algorithmic side as closing the generation
|
||||
loop, i.e. building the population that will be the initial population
|
||||
of next generation. That population will be <font color="#FF6600">built
|
||||
upon the old parents and the new-born offspring</font>. In all algorithms
|
||||
that come up with EO, the <font color="#FF6600">population size</font>
|
||||
is supposed to be <font color="#FF6600">constant</font> from one generation
|
||||
to the next one - though nothing stops you from writing an algorithm with
|
||||
varying population size.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">Replacement: </font><font color="#FF0000">The
|
||||
interface</font></b>
|
||||
<p>The abstract class for replacement procedures is the functor class
|
||||
<font color="#009900">eoReplacement</font>,
|
||||
and the interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(eoPop<EOT>& _parents,
|
||||
eoPop<EOT>& _offspring)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_replacement.html">eoReplacement</a></font></font></b>.,
|
||||
as you see there that <font color="#009900">eoReplacement</font> derives
|
||||
from <tt><font color="#993300">class eoBF<eoPop<EOT>&, eoPop<EOT>&,
|
||||
void></font></tt>.
|
||||
<br>This means that it takes <font color="#FF6600">2 populations</font>
|
||||
(called, for obvious anthropomorphic reasons, _parents and _offspring :-)
|
||||
and is free to modify both, but the resulting population should be placed
|
||||
in the first argument (usually called_parents) to close the loop and go
|
||||
to next generation.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">Replacement: </font><font color="#FF0000">Instances</font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoGenerationalReplacement </font></tt></b>This
|
||||
is the most straightforward replacement, called <font color="#FF6600">generational
|
||||
replacement</font>: all offspring replace all parents (used in Holland's
|
||||
and Goldberg's traditional GAs). It takes no argument, and supposes
|
||||
that offspring and parents are of the same size (but does not check!).</li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="SSGA"></a><b><tt><font color="#009900">eoMergeReduce</font></tt></b>
|
||||
This is one the basic types of replacement in EO. It has two major steps,
|
||||
<font color="#FF6600">merging</font>
|
||||
both populations of parents and offspring, and <font color="#FF6600">reducing</font>
|
||||
this big population to the right size. It <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_merge_reduce.html">contains
|
||||
two objects</a></font></font> of respective types <b><font color="#009900"><a href="#merge">eoMerge</a></font></b>
|
||||
and <b><font color="#009900"><a href="#reduce">eoReduce</a></font></b>
|
||||
and you can probably guess what each of them actually does :-)</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<p>Available <font color="#FF6600">instances of eoMergeReduce</font> replacement
|
||||
include
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoCommaReplacement</font></tt></b>, one of
|
||||
the two standard strategies in <font color="#000000">Evolution Strategies</font>,
|
||||
<b><font color="#FF6600">selects
|
||||
the best offspring</font></b>. It is an
|
||||
<b><tt><font color="#993300">eoMergeReduce(eoNoElitism,
|
||||
eoTruncate)</font></tt></b>.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoPlusReplacement</font></tt></b>, the other
|
||||
standar<font color="#000000">d Evolution Startegies repla</font>cement,
|
||||
where <b><font color="#FF6600">the best from offspring+parents</font></b>
|
||||
become the next generation. It is an <b><tt><font color="#993300">eoMergeReduce(eoPlus,
|
||||
eoTruncate)</font></tt></b>.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoEPReplacement</font></tt></b>, used in th<font color="#000000">e
|
||||
Evolutionary Programming historical </font>algorithm, does an EP stochastic
|
||||
tournament among parents + offspring. It is an <b><tt><font color="#993300">eoMergeReduce(eoPlus,
|
||||
eoEPReduce)</font></tt></b> and its constructor requires as argument T,
|
||||
the size of the tournament (unsigned int).</li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoReduceMerge</font></tt></b> is another important
|
||||
type of eoReplacement: the parents are first reduced, and then merged with
|
||||
the offspring. Note that the parent population is reduced of the exact
|
||||
number of offspring.</li>
|
||||
|
||||
<br>Though not mandatory, it is implicitely assumed that few offspring
|
||||
have been generated. Hence, all derived replacement procedures of class
|
||||
<b><tt><font color="#009900">eoReduceMerge</font></tt></b>
|
||||
are termed <b><tt><font color="#009900">eoSSGAxxx</font></tt></b>, as they
|
||||
are the ones to use in SteadyState Genetic Algorithm engine. This gives
|
||||
the following <font color="#FF6600">instances of eoReduceMerge</font>:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoSSGAWorseReplacement</font></tt></b>
|
||||
in which the worse parents are killed and replaced by all offsprings (no
|
||||
additional argument needed);</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoSSGADetTournamentReplacement</font></tt></b>
|
||||
in which parents to be killed are chosen by a (reverse) determinitic tournament.
|
||||
Additional parameter (in the constructor) is the tournament size, an <b><tt><font color="#993300">unsigned
|
||||
int</font></tt></b>.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoSSGAStochTournamentReplacement</font></tt></b>
|
||||
in which parents to be killed are chosen by a (reverse) stochastic tournament.
|
||||
Additional parameter (in the constructor) is the tournament rate, a <b><tt><font color="#993300">double</font></tt></b>.</li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<a NAME="SADreplacement"></a><b><tt><font color="#009900">eoSurviveAndDie</font></tt></b>
|
||||
replacement strategies are a generalization of both the above that allows
|
||||
strong elitist and eugenism in both the parent population and the offspring
|
||||
population. The <b><tt><font color="#009900"><a href="#SAD">eoSurviveAndDie</a></font></tt></b>
|
||||
building block takes one population, kills the worse and moves the best
|
||||
to some safe place. The corresponding replacements apply an <b><tt><font color="#009900">eoSurviveAndDie</font></tt></b>
|
||||
to the parents, another one to the offspring, and finally merges the remaining
|
||||
parents and offspring before reducing the resulting population to the right
|
||||
size. Available instances of <b><tt><font color="#009900">eoSurviveAndDieReplacement</font></tt></b>
|
||||
are limited todayto the <b><tt><font color="#009900">eoDeterministicSaDReplacement</font></tt></b>,
|
||||
the that uses a deterministic MergeReduce.</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<p><b><font color="#FF0000">Note</font></b>: The basic use (and initial
|
||||
motivation) for <b><tt><font color="#009900">eoSurviveAndDie</font></tt></b>
|
||||
takes 2 arguments, an eoMergeReduce and a number of surviving parents.
|
||||
It starts by copying the best parents to the new populations, then merges
|
||||
the remaining parents with the offspring before reducing to the number
|
||||
of remaining seats in the new population.</ul>
|
||||
|
||||
<hr WIDTH="50%">
|
||||
<br><a NAME="weakelitism"></a><b><font color="#000099">Replacement: </font><font color="#FF0000">Adding
|
||||
(weak) elitism</font></b>
|
||||
<p>You can add what is called <font color="#FF6600">weak elitism</font>
|
||||
to any replacement by encapsulating it into an <b><tt><font color="#009900">eoWeakElitismReplacement</font></tt></b>
|
||||
object. Weak elitism ensures that the overall <font color="#FF6600">best
|
||||
fitness</font> in the population <font color="#FF6600">will never decrease</font>:
|
||||
if the best fitness in the new population is less than the best fitness
|
||||
of the parent population, then the best parent is added back to the new
|
||||
population, replacing the worse.
|
||||
<p>Within EO, this is very easy to add:
|
||||
<p>First, declare your replacement functor (here, generational, but it
|
||||
can be any replacement object):
|
||||
<br><b><tt><font color="#009900">eoGenerationalReplacement<Indi> genReplace;</font></tt></b>
|
||||
<br>Then wrap the weak elitism around it:
|
||||
<br><b><tt><font color="#009900">eoWeakElitismReplacement<Indi> replace(genReplace);</font></tt></b>
|
||||
<br>and use now replace as your replacement procedure within your algorithm.
|
||||
<p><font color="#FF0000">Note</font>: of course, adding weak elitism to
|
||||
an elitist replacement makes no sense - but will not harm either :-)
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">Replacement: </font><font color="#FF0000">Test
|
||||
file</font></b>
|
||||
<p>The file <b><tt><font color="#993300">t-eoReplacement</font></tt></b>
|
||||
in the <b><font color="#FF6600">test directory</font></b> implements all
|
||||
above replacement procedures within a very simple and easy-to-monitor Dummy
|
||||
EO class.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="general"></a><b><font color="#000099"><font size=+2>General
|
||||
Replacement: eoReduceMergeReduce</font></font></b>
|
||||
<p>In an attempt to unify all the well-known replacements, plus most of
|
||||
the less-known-though-often-used, the <b><tt><font color="#009900">eoReduceMergeReduce</font></tt></b>
|
||||
replacement has been designed, and supersedes all of the above instances.
|
||||
<br>It allows to implement <b><font color="#FF0000">strong elistism</font></b>
|
||||
(i.e. some parents survive, whatever their fitness and that of the offspring),
|
||||
as well as multiple weak elistism (the best parents are put back in the
|
||||
next population if they outperform the best offspring).
|
||||
<p>Basically, an <b><tt><font color="#009900">eoReduceMergeReduce</font></tt></b>
|
||||
starts by eventually preserving the (strong) elite parents, proceeds by
|
||||
reducing both the parent and offspring populations, merges those populations,
|
||||
and eventually reduces the resulting populations (augmented with the elite
|
||||
parents) to the right size. Last, the weak elitism is taken care of if
|
||||
necessary.
|
||||
<br>The following image, taken from the graphical interface of EASEA, somehow
|
||||
demonstrates the different parameters of an <b><tt><font color="#009900">eoReduceMergeReduce.</font></tt></b>
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoReduceMergeReduce: </font><font color="#FF0000">The
|
||||
interface</font></b>
|
||||
<br>Of course the interface is that of eoReplacement. Let's concentrate
|
||||
on the constructor.
|
||||
<p>The constructor takes 6 arguments:
|
||||
<ol>
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany elite</font></tt></b> determines
|
||||
the number of parents to be treated as elite (actual behavior determined
|
||||
by next parameter) using the <a href="#howmany">eoHowMany</a> behavior.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">bool strongElitism</font></tt></b> tells whether
|
||||
the elite above corresponds to strong (true) or false(weak) elitism.</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: the case of no elitism is
|
||||
obtained by setting elite to 0
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany reducedParents </font></tt></b>gives
|
||||
the number of parents remaining after reducing them</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: 0 means that no parent survive
|
||||
(except the possible elite), as in <b><tt><font color="#009900">eoCommaReplacement</font></tt></b>
|
||||
<br>
|
||||
-1 is used inside <b><tt><font color="#009900">eoSSGAReplacement</font></tt></b>s
|
||||
(one parent is killed to make room for the newborn)
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoReduce<EOT> & reduceParents</font></tt></b>
|
||||
indicates how the parents will be reduced (see <a href="#reduce">available
|
||||
instances</a>).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany reducedOffspring </font></tt></b>gives
|
||||
the number of offspring remaining after reducing them</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: 0 is impossible (no evolution!!!)
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoReduce<EOT> & reduceOffspring</font></tt></b>
|
||||
indicates how the offspring will be reduced (see <a href="#reduce">available
|
||||
instances</a>).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoReduce<EOT> & reduceFinal</font></tt></b>
|
||||
indicates how the merged reduced-parents/reduced-offspring will be reduced
|
||||
(see <a href="#reduce">available instances</a>).</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: the number of individuals
|
||||
remaining after that reduction is of course the original size of the population.</ol>
|
||||
All popular evolution engines use some replacement procedure that can be
|
||||
viewed as an instance of an <b><tt><font color="#009900">eoReduceMergeReduce</font></tt></b>.
|
||||
<br>Moreover, a <b><font color="#FF0000">parser-based</font></b> input
|
||||
of a general is proposed in file do/make_checkpoint.h.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="popular"></a><b><font color="#000099"><font size=+2>Popular
|
||||
evolution engines</font></font></b>
|
||||
<p>The most popular evolution engines are listed below, together with the
|
||||
way to use them in EO. If you don't find your particuler algorithm, please
|
||||
send it to us, and we might include it here! In the following, P will denote
|
||||
the number of individuals in the initial population.
|
||||
<ul>
|
||||
<li>
|
||||
<a NAME="GGA"></a><b><font color="#000099">Generational Genetic Algorihtm</font></b><font color="#000000">:
|
||||
popularized by Holland (75) and Goldberg (89), it uses</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
P</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> Proportional
|
||||
(the historical roulette wheel) </font><b><font color="#FF6600">when maximizing
|
||||
a positive scalar fitness</font></b><font color="#000000">, ranking or
|
||||
tournament (stochatic or deterministic) in all cases.</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> Generational.</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> You could
|
||||
use also the </font><b><tt><font color="#009900">eoCommaReplacement</font></tt></b><font color="#000000">,
|
||||
with exactly the same result as there are as many offspring as we need
|
||||
indiviudals in the next population. And using the </font><b><tt><font color="#009900">eoSSGAWorseReplacement</font></tt></b><font color="#000000">
|
||||
would also give the same result, but would be very inefficient!</font>
|
||||
<br><font color="#000000">You can also add <a href="#weakelitism">weak
|
||||
elitism</a> to preserve the best individual.</font>
|
||||
<li>
|
||||
<a NAME="SSGA"></a><b><font color="#000099">Steady-State Genetic Algorithm</font></b><font color="#000000">:
|
||||
widely used in GA/GP community</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
small (historically, 1)</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> tournament
|
||||
(you can use ranking or proportional, but it will be rather inefficient).</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> An
|
||||
eoSSGAxxxReplacement.</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> You can
|
||||
also use the eoPlusReplacement, but you divert from the original SSGA</font>
|
||||
<li>
|
||||
<a NAME="ESPlus"></a><b><font color="#000099">(MU+Lambda)-Evolution Strategy</font></b><font color="#000000">:
|
||||
The elitist ES strategy (Rechenberg 71 and Schwefel 81)</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
Any</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> eoDetSelect
|
||||
(batch deterministic).</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> eoPlusReplacement</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> You could
|
||||
also use eoEPReplacement, to smoothen the selective pressure during replacement,
|
||||
thus getting close to EP evolution engine</font>
|
||||
<li>
|
||||
<a NAME="ESComma"></a><b><font color="#000099">(MU,Lambda)-Evolution Strategy</font></b><font color="#000000">:
|
||||
The non-elitist ES strategy</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
> P</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> eoDetSelect
|
||||
(batch deterministic).</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> eoCommaReplacement</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> You can
|
||||
also add <a href="#weakelitism">weak elitism</a> to preserve the best individual
|
||||
- though you'd probably use the plus strategy if you want (strong) elitism.</font>
|
||||
<li>
|
||||
<a NAME="EP"></a><b><font color="#000099">Evolutionary Programming</font></b><font color="#000000">:
|
||||
The historical method of L. Fogel (65)</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
P</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> eoDetSelect
|
||||
(batch deterministic). Every individual reproduces exactly once.</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> eoEPReplacement,
|
||||
though one historical replacement was the determnistic replacement - i.e.
|
||||
in EO the eoPlusReplacement).</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> Close to
|
||||
an (P+P)-ES</font>
|
||||
<li>
|
||||
<a NAME="General"></a><font color="#FF0000">You name it :-)</font><font color="#000000">:
|
||||
you can of course choose whatever combination you like - respecting a few
|
||||
constraints and common-sense remarks. For instance, eoProportionalSelect
|
||||
should be used only when maximizing a positive fitness, eoCommaReplacement
|
||||
requires more offspring than parents, and, over all, existing EO algorithms
|
||||
wirk with fixed size population - and it is your responsability to use
|
||||
a cmbinatino of selection/replacement that fulfills this requirement (or
|
||||
to create your own eoAlgo that handles varying size populations).</font></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="tournament"></a><b><font color="#000099"><font size=+2>Tournaments</font></font></b>
|
||||
<p>Tournaments are an easy and quick way to <b><font color="#FF6600">select</font></b>
|
||||
individuals within a population based on simple comparisons. Though usually
|
||||
based on fitness comparisons, they can use any comparison operator.
|
||||
<br>In EO, there are two variants of tournaments used to select one single
|
||||
individual, namely <b><tt><font color="#009900">Deterministic Tournament</font></tt></b>
|
||||
and <b><tt><font color="#009900">Stochastic Tournament</font></tt></b>,
|
||||
that are used in selection and in replacement procedures, and a global
|
||||
tournament-based selection of a whole bunch of individuals, the <b><tt><font color="#009900">EP
|
||||
Tournament</font></tt></b>. Though the single-selection tournaments can
|
||||
be repeated to select more than one individual, and the batch tournament
|
||||
selection can be used to select a single individual, both uses are probably
|
||||
a waste of CPU time.
|
||||
<ul>
|
||||
<li>
|
||||
<a NAME="detTournament"></a><b><tt><font color="#009900">Deterministic
|
||||
Tournament</font></tt></b> of size T returns the best of T uniformly chosen
|
||||
individuals in the population. Its size T should be an integer >= 2. It
|
||||
is implemented in the <b><tt><font color="#009900">eoDetTournamentSelect</font></tt></b>
|
||||
class, a sub-class of eoSelectOne, as well as in the <b><tt><font color="#009900">eoDetTournamentTruncate</font></tt></b>
|
||||
class that repeatidly removes from the population the "winner" of the inverse
|
||||
tournament. These objects use the C++ function determinitic_tournament
|
||||
in <a href="../../doc/html/selectors_h-source.html">selectors.h</a>.</li>
|
||||
|
||||
<li>
|
||||
<a NAME="stochTournament"></a><b><tt><font color="#009900">Stochastic Tournament</font></tt></b>
|
||||
of rate R first choses two individuals from the population, and selects
|
||||
the best one with probability R (the worse one with probability 1-R). Real
|
||||
parameter R should be in [0.5,1]. It is implemented in the <b><tt><font color="#009900">eoStochTournamentSelect</font></tt></b>
|
||||
class, a sub-class of eoSelectOne, as well as in the <b><tt><font color="#009900">eoStochTournamentTruncate</font></tt></b>
|
||||
class that repeatidly removes from the population the "winner" of the inverse
|
||||
tournament. These objects use the C++ function determinitic_tournament
|
||||
in <a href="../../doc/html/selectors_h-source.html">selectors.h</a>.</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: A stochastic tournament with
|
||||
rate 1.0 is strictly identical to a deterministic tournament of size 2.
|
||||
<li>
|
||||
<a NAME="EPTournament"></a><b><tt><font color="#009900">EP Tournament</font></tt></b>
|
||||
of size T is a global tournament: it works by assigning a score to all
|
||||
individuals in the population the following way: starting with a score
|
||||
of 0, each individual I is "opposed" T times to a uniformly chosen individual.
|
||||
Everytime I wins, its score in incremented by 1 (and by 0.5 for every draw).
|
||||
The individuals are then selected deterministically based on their scores
|
||||
from that procedure. The <b><tt><font color="#009900">EP Tournament</font></tt></b>
|
||||
is implemented in the <b><tt><font color="#009900">eoEPReduce</font></tt></b>
|
||||
truncation method used in the <b><tt><font color="#009900">eoEPReplacement</font></tt></b>
|
||||
procedure.</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: whereas both the determinitic
|
||||
and the stochastic tournament select one individual, the EP tournament
|
||||
is designed for batch selection. Of course it could be used to select a
|
||||
single individual, but at a rather high computational cost.</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="merge"></a><b><font color="#000099"><font size=+2>Merging
|
||||
populations</font></font></b>
|
||||
<p>In replacement procedures, one frequently needs to merge two populations
|
||||
(computed form old parents and new-born offspring). Classes derived from
|
||||
the abstract class eoMerge are written for that purpose.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoMerge</font></b>: <b><font color="#FF0000">interface</font></b>
|
||||
<br>The abstract class for merging procedures is the functor class
|
||||
<font color="#009900">eoMerge</font>,
|
||||
and the interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(const eoPop<EOT>&
|
||||
_parents, eoPop<EOT>& _offspring)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_merge.html">eoMerge</a></font></font></b>,
|
||||
as you see there that <font color="#009900">eoMerge</font> derives from
|
||||
<br><tt><font color="#993300">class eoBF<const eoPop<EOT>&, eoPop<EOT>&,
|
||||
void></font></tt>.
|
||||
<br>This means that it takes <font color="#FF6600">2 populations</font>
|
||||
and modifies the seond one by adding some individuals from the first one
|
||||
(which is supposed to remain <b><tt><font color="#993300">const</font></tt></b>ant).
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoMerge</font></b>: <b><font color="#FF0000">instances</font></b>
|
||||
<br>Available <font color="#FF6600">instances of eoMerge</font> objects
|
||||
are <b><tt><font color="#009900">eoPlus</font></tt></b>, that simply adds
|
||||
the parents to the offspring, or <b><tt><font color="#009900">eoElitism</font></tt></b>,
|
||||
that adds only some of the (best) parents to the offspring. A special case
|
||||
of eoElistism is <b><tt><font color="#009900">eoNoElitism</font></tt></b>,
|
||||
an eoMerge that does nothing.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="reduce"></a><b><font color="#000099"><font size=+2>Reducing
|
||||
populations</font></font></b>
|
||||
<p>The other useful component of replacement procedures, <font color="#009900">eoReduce</font>,
|
||||
<font color="#FF6600">kills
|
||||
some individuals</font> from a given population.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoReduce</font></b>: <b><font color="#FF0000">interface</font></b>
|
||||
<br>The abstract class for reducing procedures is the functor class
|
||||
<font color="#009900">eoReduce</font>,
|
||||
and the interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(eoPop<EOT>& _parents,
|
||||
unsigned int new_size)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_reduce.html">eoReduce</a></font></font></b>,
|
||||
as you see there that <font color="#009900">eoReduce</font> derives from
|
||||
<br><tt><font color="#993300">class eoBF<eoPop<EOT>&, unsigned
|
||||
int, void></font></tt>.
|
||||
<br>An <font color="#009900">eoReduce</font> shoud take a<font color="#FF6600">
|
||||
population</font> and shrink it to the required size.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoReduce</font></b>: <b><font color="#FF0000">instances</font></b>
|
||||
<br>Available <font color="#FF6600">instances of eoReduce</font> are
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoTruncate</font></tt></b>, deterministically
|
||||
kills the worse individuals, keeping only the required number. It starts
|
||||
by sorting teh populations, and hence does <font color="#FF6600">modify
|
||||
its order</font>.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoLinearTruncate</font></tt></b>, deterministically
|
||||
kills the worse individuals, keeping only the required number. It does
|
||||
so by repeatedly removing the worsr individual. Hence does <font color="#FF6600">not
|
||||
modify its order</font>, but takes longer time than <b><tt><font color="#009900">eoTruncate</font></tt></b>
|
||||
in case of many offspring.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoEPReduce</font></tt></b>, uses the <a href="#EPtournament">EP
|
||||
stochastic tournament</a> to reduce the population. It requires an additinal
|
||||
argument, the tournament size.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoDetTournamentTruncate</font></tt></b> uses
|
||||
inverse deterministic tournament to repeatidly kill one individual until
|
||||
the propoer size is reached. As <b><tt><font color="#009900">eoLinearTruncate</font></tt></b>,
|
||||
it might take some time in the case of many offspring. It requires the
|
||||
size of the tournament (<b><tt><font color="#993300">unsigned int</font></tt></b>)
|
||||
as parameter in the constructor (default is 2).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoStochTournamentruncate</font></tt></b>
|
||||
uses inverse stochastic tournament to repeatidly kill individuals from
|
||||
the population. It requires the rate of the tournament (<b><tt><font color="#993300">double</font></tt></b>)
|
||||
as parameter in the constructor (default is 0.75).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="howmany"></a><b><font color="#000099"><font size=+2>eoHowMany:
|
||||
Choosing a number of individuals</font></font></b>
|
||||
<p>Many classes in selection/replacement procedures will handle a number
|
||||
of individuals that may either be fixed or be related to some argument-population
|
||||
size.
|
||||
<br>Of course, it is possible to write different classes that will only
|
||||
differ by the way they compute the number of individuals they have to treat,
|
||||
as it is done for selectors with the two classes <font color="#009900">eoSelectPerc</font>
|
||||
and <font color="#009900">eoSelectNumber</font> (it could also have been
|
||||
possible to have some pure abstrat class and implement the computation
|
||||
of the number of individuals to treat in some derived classes).
|
||||
<br>However, the class <b><tt><font color="#993300">eoHowMany</font></tt></b>
|
||||
allows one to handle in a single class three different behaviors when given
|
||||
a poopulatio size as argument:
|
||||
<ul>
|
||||
<li>
|
||||
return a given rate of the argument population size</li>
|
||||
|
||||
<li>
|
||||
return an absolute (unsigned) integer, whatever the argument population
|
||||
size</li>
|
||||
|
||||
<li>
|
||||
return the argument population size minus a given number</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoHowMany</font></b>: <b><font color="#FF0000">interface</font></b>
|
||||
<br>The class interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">unsigned int operator()(unsigned int _pop_size)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_how_many.html">eoHowMany</a></font></font></b>,
|
||||
as you see there that <b><tt><font color="#993300">eoHowMany</font></tt></b>
|
||||
derives from
|
||||
<br><tt><font color="#993300">class eoUF<unsigned int, unsigned int></font></tt>.
|
||||
<p>It has 3 possible constructors, that determine its behavior:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany(double _rate, bool _interpret_as_rate
|
||||
= true)</font></tt></b> where <b><tt><font color="#993300">_rate</font></tt></b>
|
||||
is by default the fixed rate of behavior 1 above. However, if the boolean
|
||||
second argument is false, the rate is transformed into a positive integer,
|
||||
and is used for behavior 2 above</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany(int _combien)</font></tt></b>: if
|
||||
<b><tt><font color="#993300">_combien</font></tt></b>
|
||||
is positive, it is the absolute number of behavior 2 above, and if <b><tt><font color="#993300">_combien</font></tt></b>
|
||||
is negative, its absolute value is used to decrease the argument population
|
||||
in behavior 3 above</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany(unsigned int _combien)</font></tt></b>:
|
||||
<b><tt><font color="#993300">_combien</font></tt></b>
|
||||
(positive!) is the absolute number of behavior 2 above. <b><font color="#FF6600">Note</font></b>
|
||||
that this constructor is mandatory to avoid ambiguity, as an unsigned int
|
||||
can be casted to either an int or a double.</li>
|
||||
</ul>
|
||||
It is used in <font color="#009900">eoSelectMany</font> (which supersedes
|
||||
<font color="#009900">eoSelectPerc</font>
|
||||
and <font color="#009900">eoSelectNumber</font>, but they are left there
|
||||
for tutorial reasons!) as well as in many <a href="#reduce">truncation</a>
|
||||
methods, and it is used a lot in the eoGeneralReplacement construct.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="SAD"></a><b><font color="#000099"><font size=+2>Survive and
|
||||
Die</font></font></b>
|
||||
<br>This class is highly politically incorrect: it implements strong elitism
|
||||
and eugenism :-)
|
||||
<br>It starts by killing the worse individuals from the source argument,
|
||||
then appends the best ones to the destination argument and removes them
|
||||
from the source argument. It is used in <b><tt><a href="#SADreplacement">eoSurviveAndDieReplacement</a></tt></b>,
|
||||
where the same dest is used successively for the parents and the offspring.
|
||||
<p><b><font color="#000099">eoSurviveAndDie</font></b>: <b><font color="#FF0000">interface</font></b>
|
||||
<br>The class interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(eoPop<EOT>& _source,
|
||||
eoPop<EOT>& _dest)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_survive_and_die.html">eoSurviveAndDie</a></font></font></b>,
|
||||
as you see there that <b><tt><font color="#993300">eoSurviveAndDie</font></tt></b>
|
||||
derives from <tt><font color="#993300">class eoBF<eoPop<EOT>&,
|
||||
eoPop<EOT>&, void></font></tt>.
|
||||
<p>Its constructor takes 3 argumenrts:
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">eoHowMany(double _survive, double _die,
|
||||
bool _interpret_as_rate = true)</font></tt></b></center>
|
||||
|
||||
<p>to indicate how many (or what proportion, according to <b><tt><font color="#993300">_interpret_as_rate</font></tt></b>)
|
||||
of the source should be copied to the dest population, and how many (or
|
||||
what proportion, according to <b><tt><font color="#993300">_interpret_as_rate</font></tt></b>)
|
||||
should be erased from the source.
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#CC0000">Local: </font></b><a href="#introduction">Introduction</a>
|
||||
- <a href="#selection">Selection</a> - <a href="#replacement">Replacement</a>
|
||||
- <a href="#general">General Replacement</a> - <a href="#popular">Popular
|
||||
evolution engines</a> - <a href="#tournament">Tournaments</a> - <a href="#merge">Merge</a>
|
||||
- <a href="#reduce">Reduce</a> - <a href="#howmany">HowMany</a> - <a href="#SAD">SurviveAndDie</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#CC0000">General: </font></b><a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<hr WIDTH="100%">
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Tue. Jan. 9 2001 <!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
34
deprecated/eo/tutorial/html/eoEval.html
Normal file
34
deprecated/eo/tutorial/html/eoEval.html
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Evaluation</title>
|
||||
</head>
|
||||
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
|
||||
<center>
|
||||
<h1><font color="#FF0000">Evaluation</font></h1>
|
||||
</center>
|
||||
|
||||
|
||||
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 17:51:43 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Nov 6 10:54:33 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
19
deprecated/eo/tutorial/html/eoGeneration.html
Normal file
19
deprecated/eo/tutorial/html/eoGeneration.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Generation</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Generation</h1>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 19:29:28 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Oct 30 19:29:29 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
36
deprecated/eo/tutorial/html/eoInit.html
Normal file
36
deprecated/eo/tutorial/html/eoInit.html
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Initialization</title>
|
||||
</head>
|
||||
<body text="#000000" background="beige009.jpg" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<!-- -------------- End of header ------------------ -->
|
||||
<!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<b><font color="#CC0000">Initialization</font></b></h1></center>
|
||||
|
||||
|
||||
|
||||
<!-- Bottom of file: display some links and address -->
|
||||
<!-- ----------------------------------------------- -->
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>- <a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 17:51:29 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Nov 6 11:25:18 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
25
deprecated/eo/tutorial/html/eoIo.html
Normal file
25
deprecated/eo/tutorial/html/eoIo.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Input / Output</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Input / Output</h1>
|
||||
|
||||
<p>
|
||||
<A NAME=stop>
|
||||
<h3>Stopping criteria</h3>
|
||||
|
||||
<p>
|
||||
<A NAME=output>
|
||||
<h3>Displaying statistics</h3>
|
||||
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 19:29:46 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Tue Oct 31 18:32:22 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
440
deprecated/eo/tutorial/html/eoLesson1.html
Normal file
440
deprecated/eo/tutorial/html/eoLesson1.html
Normal file
|
|
@ -0,0 +1,440 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.76 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>Tutorial: Lesson 1</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson2.html">Lesson 2</a> -
|
||||
<a href="eoTutorial.html">Tutorial
|
||||
main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Programming hints</a> -<font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial: Lesson 1</font></h1></center>
|
||||
This lesson will let you
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#run">run</a> your first Evolutionary Algorithm written within
|
||||
EO Library, choosing between evolving <font color="#999900">bitstrings</font>,
|
||||
or evolving <font color="#999900">vectors of real numbers</font>,</li>
|
||||
|
||||
<li>
|
||||
<a href="#browse">browse</a> through the code of these algorithms, or</li>
|
||||
|
||||
<li>
|
||||
follow the <a href="#tour">guided tour</a>.</li>
|
||||
</ul>
|
||||
Later you will be asked to
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#exercise1">write</a> your own <font color="#990000">fitness function</font>,</li>
|
||||
|
||||
<li>
|
||||
<a href="#exercise2">check</a> that EO let you separate the <font color="#999900">representation</font>
|
||||
from the <font color="#009900">evolution engine</font>.</li>
|
||||
|
||||
<li>
|
||||
<a href="#exercise3">use different kinds</a> of <font color="#009900">selection
|
||||
procedures</font> in the framework of a generational GA <font color="#009900">evolution
|
||||
engine</font>,</li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="run"></a><font color="#000099">I want to run
|
||||
an Evolutionary Algorithm
|
||||
<b>now</b></font></h3>
|
||||
You can choose to run a standard <a href="FirstBitGA.html">bitstring Genetic
|
||||
Algorithm</a> (as defined in Goldberg's book) or a standard <a href="FirstRealGA.html">real-valued
|
||||
genetic algorithm</a>, as proposed in Micahlewicz's book.
|
||||
<p>If you have not already done what was recommended in the <a href="eoTutorial.html#install">Tutorial
|
||||
main page</a> , do it <b><font color="#FF6600">NOW</font></b>. Then go
|
||||
to the Lesson1 sub-dir of the tutorial dir, and simply type at the system
|
||||
prompt
|
||||
<p><tt>(myname@myhost) EOdir/Tutorial/Lesson1 % <font color="#FF6666">FirstRealGA</font></tt>
|
||||
<br>or
|
||||
<br><tt>(myname@myhost) EOdir/Tutorial/Lesson1 % <font color="#FF6666">FirstBitGA</font></tt>
|
||||
<p>and something should happen.
|
||||
<h3>
|
||||
<font color="#000099">What is happening?</font></h3>
|
||||
At the moment, the <font color="#FF6600">FirstBitGA</font> maximizes the
|
||||
number of ones in the bitstring (also calls the <font color="#FF6600">OneMaxfunction</font>,
|
||||
whose solution is, as you can guess,
|
||||
<font color="#FF6600">11111111</font>),
|
||||
and the <font color="#FF6600">FirstRealGA</font> is maximizing (the default
|
||||
action for EO is to maximize) the inverse of the sum (i.e. minimizing the
|
||||
sum) of the square of its variables (also called the <font color="#FF6600">sphere
|
||||
function</font>, whose solution is ... <font color="#FF6600">all zeroes</font>).
|
||||
<p>And what you see on the screen when running one of these two programs
|
||||
is, in each case, the initial and final population of an Evolutionary run,
|
||||
one individual per line, its fitness first, then the number of items (bits
|
||||
or real numbers) of the genotype, and the genotype itself. The final population
|
||||
hopefully contains the solution in the discrete case, and is close to it
|
||||
in the continuous case.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="browse"></a><b><font color="#000099"><font size=+1>Browsing
|
||||
the code:</font></font></b>
|
||||
<p>Now you need to take a look at the program codes, either by browsing
|
||||
alone through the sources for <a href="FirstBitGA.html">FirstBitGA</a>
|
||||
and <a href="FirstRealGA.html">FirstRealGA</a>, or by following the guided
|
||||
tour below. You might prefer to go directly to the <a href="#exercise1">exercises</a>.
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="tour"></a><font color="#000099">Guided tour:</font></h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<b><font color="#993300">General includes:</font></b><font color="#000000">Like
|
||||
all C-like code, the file starts with include directives (<a href="FirstBitGA.html#start">Bit</a>
|
||||
- <a href="FirstRealGA.html#start">Real</a>). Apart from standard includes,
|
||||
the specific file to include is </font><b><font color="#FF6600">eo</font></b><font color="#000000">:
|
||||
this is a file that contains the list of the all important representation-independent
|
||||
EO files.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#999900">Representation</font></b><font color="#000000">:
|
||||
you then have to declare the type of individuals you will be handling.
|
||||
All evolution-related objects you will need are templatized w.r.t. the
|
||||
type of individuals.</font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#representation">Bit</a> You first need to include
|
||||
the representation-dependent file <b><tt><font color="#993300"><font size=+1>ga.h</font></font></tt></b>,
|
||||
containing the bitstring representation and operators. More details about
|
||||
<a href="eoRepresentation.html#bitstring">what is available for bitstrings
|
||||
here</a>.<br>
|
||||
You then say that you will be handling <b><font face="Arial,Helvetica"><a href="../../doc/html/classeo_bit.html">Bitstring
|
||||
genotypes</a></font></b>, whose fitness is a double. This makes Indi derive
|
||||
from the <a href="eoProgramming.html#STL">STL class</a> <font color="#993300">vector<bool></font></li>
|
||||
|
||||
<li>
|
||||
<a href="FirstRealGA.html#representation">Real</a> You first need to include
|
||||
the representation-dependent file <b><tt><font color="#993300"><font size=+1>es.h</font></font></tt></b>,
|
||||
containing the bitstring representation and operators. More details about
|
||||
<a href="eoRepresentation.html#real">what is available for real-values
|
||||
here</a>.<br>
|
||||
You then say that you will be handling <b><font face="Arial,Helvetica"><a href="../../doc/html/classeo_real.html">Real-valued
|
||||
genotypes</a></font></b>, whose fitness is a double. This makes Indi derive
|
||||
from the <a href="eoProgramming.html#STL">STL class</a> <font color="#993300">vector<double></font></li>
|
||||
|
||||
<br> </ul>
|
||||
|
||||
<li>
|
||||
<b><font color="#CC0000">Fitness function:</font></b><font color="#000000">
|
||||
the code for the fitness function is included in the file. It must take
|
||||
as argument a reference to an individual (at the moment).</font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#evalfunc">Bit</a> This function simply computes
|
||||
the number of ones of the bitstring (it's called the OneMax function).
|
||||
The optimum is of course the all-ones bitstring.</li>
|
||||
|
||||
<li>
|
||||
<a href="FirstRealGA.html#evalfunc">Real</a> This function simply computes
|
||||
the inverse of the sum of the squares of all variables (also called the
|
||||
sphere function). The optimum is of course the all-zeroes vector.</li>
|
||||
|
||||
<br> </ul>
|
||||
|
||||
<li>
|
||||
<a NAME="parametres"></a><b><font color="#3366FF">Parameters</font></b><font color="#000000">:
|
||||
all parameters of the algorithm are declared here (<a href="FirstBitGA.html#parametres">Bit</a>
|
||||
- <a href="FirstRealGA.html#parametres">Real</a>), and their values and
|
||||
assigned. Of course, this means that you will need to recompile to change
|
||||
these values - see Lesson 3 to get rid of that heavy requirement.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#990000">Random seeding:</font></b><font color="#000000">
|
||||
Random numbers play an important role in Evolutionary Algorithms. See in
|
||||
<a href="eoProgramming.html#random">EO
|
||||
programming hints</a> more details about how this is simulated in EO -
|
||||
but as far as you are concerned now, remember that the </font><font color="#660000">global
|
||||
Random Number Generator</font><font color="#000000"> is called </font><b><tt><font color="#660000"><font size=+1>rng</font></font></tt></b><font color="#000000">
|
||||
and should be used everywhere you need a realization of a random variable
|
||||
of known law. Moreover, this RNG requires a </font><b><tt><font color="#660000"><font size=+1>seed</font></font></tt></b><font color="#000000">,
|
||||
which is set here (<a href="FirstBitGA.html#random">Bit</a> - <a href="FirstRealGA.html#random">Real</a>):
|
||||
every time you run the algorithm with the </font><font color="#FF6600">same
|
||||
seed</font><font color="#000000">, you will get the </font><font color="#FF6600">same
|
||||
result</font><font color="#000000">. Hence, to test the robustness of your
|
||||
algorithm, you should run it with different seeds. This is rather time
|
||||
consuming in the present programs, so we suggest that you wait until Lesson
|
||||
3 to do so.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#CC0000">Fitness function encapsulation: </font></b><font color="#000000">EO
|
||||
is based on the notion of <a href="eoProgramming.html#functors">functors</a>
|
||||
- hence you now need to encapsulate your fitness function into a functor
|
||||
object. This is what is done here (<a href="FirstBitGA.html#eval">Bit</a>
|
||||
- <a href="FirstRealGA.html#eval">Real</a>).</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#CC33CC">Initialization</font></b><font color="#000000">:
|
||||
to initialize the population, first declare an empty object of class </font><b><tt><font color="#990000">eoPop<Indi></font></tt></b><font color="#000000">,
|
||||
which is basically an <a href="eoProgramming.html#STL">STL</a> </font><b><tt><font color="#990000">vector<Indi></font></tt></b><font color="#000000">,
|
||||
then fill it with Indi's.</font> And remember that
|
||||
<b><tt><font color="#990000">v.push_back</font></tt></b>
|
||||
simply appends its argument at the end of <a href="eoProgramming.html#STL">STL</a>
|
||||
vector <b><tt><font color="#993300">v.</font></tt></b></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#init">Bit</a> <b><tt><font color="#990000">rng.flip()</font></tt></b>
|
||||
return a <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_rng.html">random
|
||||
boolean</a></font></font></li>
|
||||
|
||||
<li>
|
||||
<a href="FirstRealGA.html#init">Real</a> <b><tt><font color="#990000">rng.uniform()</font></tt></b>
|
||||
returns a <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_rng.html">real
|
||||
value uniformly drawn in [0,1].</a></font></font></li>
|
||||
|
||||
<br> </ul>
|
||||
|
||||
<li>
|
||||
<b><font color="#3366FF">Output</font></b><font color="#000000">: take
|
||||
a snapshot at the initial population (<a href="FirstBitGA.html#output">Bit</a>
|
||||
- <a href="FirstRealGA.html#output">Real</a>). Sort it first, so the best
|
||||
individuals are first, and display it. Note that an eoPop has a </font><b><tt><font color="#990000"><<</font></tt></b><font color="#000000">
|
||||
method, which means that a simple </font><b><tt><font color="#990000">os
|
||||
<< pop </font></tt></b><font color="#000000">streams the </font><b><tt><font color="#990000">pop</font></tt></b><font color="#000000">
|
||||
onto the ostream </font><b><tt><font color="#990000">os</font></tt></b><font color="#000000">.
|
||||
This is true for </font><font color="#FF6600">all objects of of class </font><font color="#000000"><b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_printable.html">eoPrintable</a></font></font></b>
|
||||
(most EO objects) through the method </font><b><tt><font color="#990000">printOn</font></tt></b><font color="#000000">
|
||||
(which is then called by the </font><b><tt><font color="#990000"><<</font></tt></b><font color="#000000">
|
||||
operator).</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#009900">Evolution engine:</font></b><font color="#000000">
|
||||
The selection/replacement mechanism (<a href="FirstBitGA.html#engine">Bit</a>
|
||||
- <a href="FirstRealGA.html#engine">Real</a>) is a simple generational
|
||||
GA here: a simple selector, and a generational replacement. The <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_det_tournament_select.html">eoDetTournamentSelect</a></font></font></b>
|
||||
has been chosen as a robust selection, and the generational replacement
|
||||
(all parents are replaced by the offspring) is hard-coded in the eoSGA
|
||||
<a href="#algorithm">algorithm</a>.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<font color="#CC33CC"><b>Variation operators</b>:</font><font color="#000000">
|
||||
in the simple algorithm considered here, individuals undergo </font><font color="#CC33CC">crossover</font><font color="#000000">
|
||||
and </font><font color="#CC33CC">mutation</font><font color="#000000">.
|
||||
In EO, these operators are (<a href="eoProgramming.html#functors">functor</a>)
|
||||
objects of class</font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_quad_op.html">eoQuadOp</a></font></font></b>
|
||||
(binary operator that modifies both its arguments) and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>
|
||||
(unary operator). These operators are applied in turn to all selected
|
||||
parents, according to user-defined probabilities. These probabilities
|
||||
are defined with all other <a href="#parametres">parameters</a>, and will
|
||||
be passed to the <b><tt><font color="#FF6666"><font size=+1>eoSGA </font></font></tt></b><a href="#parametres">algorithm</a><font color="#000000">.
|
||||
For more details on these classes, go to the <a href="eoOperators.html#crossover">algorithm-based
|
||||
corresponding pages</a>, or to their respective documentation pages.</font></li>
|
||||
|
||||
<br>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#operators">Bit</a> The crossover <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo1_pt_bit_crossover.html">eo1PtBitXover</a></font></font></b>
|
||||
is the standard <font color="#CC33CC">1-point crossover</font>, and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_bit_mutation.html">eoBitMutation</a></font></font></b>
|
||||
is the standard <font color="#FF6600">bit-flip mutation</font> that randomly
|
||||
flips all bits with a given probability <b><tt>P_MUT_PER_BIT.</tt></b></li>
|
||||
|
||||
<br><b><font color="#FF0000">Warning</font></b>: the <b><tt>P_MUT_PER_BIT</tt></b>
|
||||
probability is an <font color="#FF6600">internal parameter</font> of the
|
||||
<b><tt><font color="#CC33CC"><font size=+1>eoBinMutation</font></font></tt></b>,
|
||||
it is <b><font color="#FF6600">NOT</font></b> the probability of mutation
|
||||
at the individual level. EO corrects what can be viewed as an inconsistency
|
||||
in Holland's original work, further used in Goldberg's book by separating
|
||||
the probability of mutation for each individual (independent of the type
|
||||
of mutation that will be applied) from the probability of flipping each
|
||||
bit, which is specific of the bit-flip mutation. Hence, to run the
|
||||
same algorithm as Goldberg's SGA, the mutation probability (at individual
|
||||
level) is 1, and the probability of flipping each bit is <b><tt>P_MUT_PER_BIT.</tt></b>
|
||||
<li>
|
||||
<a href="FirstRealGA.html#operators">Real</a> The crossover <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_segment_crossover.html">eoSegmentCrossover</a></font></font></b>
|
||||
is the standard <font color="#CC33CC">segment crossover</font> for real-valued
|
||||
vectors, that chooses a point randomly on the segment between both parents
|
||||
(also termed <font color="#CC33CC">BLX-0</font>). <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_uniform_mutation.html">eoUniformMutation</a></font></font></b>
|
||||
is the <font color="#CC33CC">uniform mutation</font> for real-valued vectors
|
||||
that chooses a new value for each variable uniformly on an interval centered
|
||||
on the parent value. The width of the interval is an <font color="#FF6600">internal
|
||||
parameter</font> of the object, here called <b><tt>EPSILON</tt></b>.</li>
|
||||
|
||||
<br> </ul>
|
||||
|
||||
<li>
|
||||
<b><font color="#3366FF">Stopping criterion:</font></b><font color="#000000">
|
||||
Specify a </font><font color="#3366FF">maximum number of generations</font><font color="#000000">
|
||||
to run (<a href="FirstBitGA.html#stop">Bit</a> - <a href="FirstRealGA.html#stop">Real</a>):
|
||||
the simplest of all stopping criteria at the moment, using an object of
|
||||
a sub-class of class </font><b><font face="Arial,Helvetica"><font color="#3366FF"><font size=+1><a href="../../doc/html/classeo_continue.html">eoContinue</a></font></font></font></b><font color="#000000">.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="algorithm"></a><b><font color="#FF6666">The algorithm: </font></b><font color="#000000">the
|
||||
simple algorithm that is used here, called </font><b><tt><font color="#FF6666"><font size=+1>eoSGA
|
||||
</font></font></tt></b><font color="#000000">requires
|
||||
as parameters a </font><font color="#FF6600">selector</font><font color="#000000">,
|
||||
a </font><font color="#FF6600">crossover</font><font color="#000000"> and
|
||||
the associated </font><font color="#FF6600">crossover rate</font><font color="#000000">,
|
||||
a </font><font color="#FF6600">mutation</font><font color="#000000"> and
|
||||
the associated </font><font color="#FF6600">mutation rate,</font><font color="#000000">
|
||||
and a </font><font color="#FF6600">stopping criterion</font><font color="#000000">.
|
||||
Take a look at the corresponding
|
||||
<a href="eoSGA.html#constructor">constructor</a>
|
||||
of the class </font><b><tt><font color="#FF6666"><font size=+1>eoSGA</font></font></tt></b><font color="#000000">:
|
||||
it only initializes its <a href="eoSGA.html#parametres">private data</a>
|
||||
with the parameters. Now look at the <a href="eoSGA.html#generation">operator()</a>
|
||||
method - the one that is called in the code for <a href="FirstBitGA.html#generation">FirstBitGA</a>
|
||||
or <a href="FirstRealGA.html#generation">FirstRealGA</a> - and you'll find
|
||||
out that is is as simple as it sounds.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#3366FF">Output</font></b><font color="#000000">: After
|
||||
running the algorithm, output the sorted final population (<a href="FirstBitGA.html#final_output">Bit</a>
|
||||
- <a href="FirstRealGA.html#final_output">Real</a>) - and look at the best
|
||||
individual: this is the result of the algorithm.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#990000">Main body:</font></b><font color="#000000"> for
|
||||
technical reasons (intercepting the exceptions), we need a main like this
|
||||
one (<a href="FirstBitGA.html#main">Bit</a> - <a href="FirstRealGA.html#main">Real</a>).,
|
||||
and you should not touch it unless you know what you are doing. Simply
|
||||
note that this main calls the function main_function, which we have been
|
||||
discussing up to now!</font></li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="exercise1"></a><font color="#000099">Exercise
|
||||
1: maximize your own function</font></h3>
|
||||
This is very easy - if your search space is that of bitstring or of unbounded
|
||||
real numbers.
|
||||
<ul>
|
||||
<li>
|
||||
Go to the tutorial directory, and <font color="#FF6600">copy</font> the
|
||||
program you want to modify onto <b><tt><font color="#663300">mytest.cpp.</font></tt></b></li>
|
||||
|
||||
<li>
|
||||
<font color="#FF6600">Edit</font> <b><tt><font color="#990000">mytest.cpp</font></tt></b>
|
||||
with any text editor:</li>
|
||||
|
||||
<li>
|
||||
<font color="#FF6600">Modify</font> the fitness function itself (<a href="FirstBitGA.html#evalfunc">binary_value</a>
|
||||
in <font color="#FF6666"><b><tt>FirstBitGA</tt></b><font face="Courier New,Courier">,</font></font><a href="FirstRealGA.html#evalfunc">real_value</a>
|
||||
in <font color="#FF6666"><b><tt>FirstRealGA</tt></b><font face="Courier New,Courier">)</font></font></li>
|
||||
|
||||
<li>
|
||||
<font color="#FF6600">Compile</font> the program by typing <b><tt><font color="#990000">make
|
||||
mytest</font></tt></b> at system prompt</li>
|
||||
|
||||
<li>
|
||||
<font color="#FF6600">Run</font> the new program by entering the command
|
||||
<b><tt><font color="#990000">mytest</font></tt></b>
|
||||
at system prompt.</li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="exercise2"></a><font color="#000099">Exercise
|
||||
2: check the differences between both programs</font></h3>
|
||||
Go and take a look at the code for these programs <font color="#000000">(<a href="FirstBitGA.html">Bit</a>
|
||||
- <a href="FirstRealGA.html">Real</a>)</font>. Use the symbolic representation
|
||||
of an Evolutionary Algorithm (you should understand that figure now, otherwise
|
||||
go <a href="eoIntro.html">there</a> and come back) to understand how each
|
||||
part of the EA is coded. Try to spot the differences between both codes:
|
||||
there are not so many!
|
||||
<br>After you've tried that alone, take a look at the <a href="Firstmerge.html">solution</a>
|
||||
:-)
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="exercise3"></a><font color="#000099">Exercise
|
||||
3: change the selection procedure</font></h3>
|
||||
This is rather straightforward ... if you know what other types of selection
|
||||
are available!
|
||||
<br>At the moment, let's only consider only the following simple ones:
|
||||
<ul>
|
||||
<li>
|
||||
You already know the <font color="#FF6600">tournament selection</font></li>
|
||||
|
||||
<br><font color="#FF0000">Syntax: </font><tt><font color="#009900"><b>eoDetTournamentSelect<Indi>
|
||||
select(T_SIZE); </b>// T_SIZE in [2,POP_SIZE)</font></tt>
|
||||
<li>
|
||||
Try the well-known <font color="#FF6600">roulette wheel</font></li>
|
||||
|
||||
<br> <font color="#FF0000">Syntax: </font> <b><tt><font color="#009900">eoProportionalSelect<Indi>
|
||||
select;</font></tt></b>
|
||||
<li>
|
||||
Or the <font color="#FF6600">stochastic binary tournament</font></li>
|
||||
|
||||
<br><font color="#FF0000">Syntax: </font><b><tt><font color="#009900">eoStochTournamentSelect<Indi>
|
||||
select(RATE); </font></tt></b><tt><font color="#009900">
|
||||
// RATE in ]0.5,1]</font></tt>
|
||||
<li>
|
||||
and of course the <font color="#FF6600">random</font> selection should
|
||||
give bad results!</li>
|
||||
|
||||
<br><font color="#FF0000">Syntax: </font><b><tt><font color="#009900">eoRandomSelect<Indi>
|
||||
select;</font></tt></b></ul>
|
||||
Note that all these classes of eoObjects are derived from the abstract
|
||||
class
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_select_one.html">eoSelectOne.</a></font></font></b>
|
||||
To find out exactly how each procedure selects the individuals, read the
|
||||
corresponding <a href="eoEngine.html#selection">component-based page</a>.
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#000099"><font size=+2>Lessons learned:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
in EO, all actions are performed by <a href="eoProgramming.html#functors">functor
|
||||
objects</a> (this section is the last time in this tutorial that there
|
||||
is a direct link to the <a href="eoProgramming.html">EO Programming hints</a>
|
||||
page - though the link at top and bottom of all pages will remain there).</li>
|
||||
|
||||
<li>
|
||||
in EO, all object you will usually need to manipulate are <a href="eoProgramming.html#templates">templatized</a><b><font color="#FF6600">
|
||||
w.r.t. the type of the individual</font></b> you are handling.</li>
|
||||
|
||||
<li>
|
||||
The type of the individual is itself <a href="eoProgramming.html#templates">templatized</a><b><font color="#FF6600">
|
||||
w.r.t. the type of fitness</font></b> (double by default).</li>
|
||||
|
||||
<li>
|
||||
In EO (actually, in EC!) <font color="#CC33CC">initialization and variation</font>
|
||||
operators are <font color="#999900">representation</font>-dependent, while
|
||||
the <font color="#009900">evolution engine</font> is <font color="#999900">representation</font>-independent
|
||||
(well, like any rule, this one does have some exceptions).</li>
|
||||
|
||||
<li>
|
||||
Changing the <font color="#990000">fitness function</font>, or the <font color="#009900">selection
|
||||
procedure</font> inside the generational GA evolution engine is straightforward.</li>
|
||||
|
||||
<li>
|
||||
remember, all <font color="#FF6600">solutions</font> to exercises are in
|
||||
the same sub-dir of dir Tutorial than the lesson itself (see <a href="NoWay.html">here</a>).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Lesson 2</a> -
|
||||
<a href="eoTutorial.html">Tutorial
|
||||
main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Fri Nov 3 18:49:12 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Fri Nov 3 18:49:12 CET 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
357
deprecated/eo/tutorial/html/eoLesson2.html
Normal file
357
deprecated/eo/tutorial/html/eoLesson2.html
Normal file
|
|
@ -0,0 +1,357 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
|
||||
<title>Tutorial: Lesson 2</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson1.html">Lesson 1</a> -
|
||||
<a href="eoLesson3.html">Lesson
|
||||
3</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Hints</a>
|
||||
-<font size=+1> <b><font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></b></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial Lesson 2: more encapsulations</font></h1></center>
|
||||
In this lesson, the same Evolutionary Algorithm will be rewritten in a
|
||||
much more general context.
|
||||
<br>First, look at the <a href="#changes">changes</a> that have been done
|
||||
to the algorithms. Then benefit from the new features by
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#minimize">minimizing</a> (and not only maximize) the fitness</li>
|
||||
|
||||
<li>
|
||||
<a href="#combined_operators">combining</a> <font color="#CC33CC">several
|
||||
operators</font> of the same type</li>
|
||||
|
||||
<li>
|
||||
<a href="#combinedContinue">combining</a> <font color="#3366FF">several
|
||||
stopping criteria</font></li>
|
||||
|
||||
<li>
|
||||
use <font color="#009900"><a href="#evolution">alternate</a> selection/replacement</font>
|
||||
engines, deviating from the pure generational GA</li>
|
||||
</ul>
|
||||
|
||||
<p><br>Again, two basic algorithms are provided, namely <a href="FirstBitEA.html">FirstBitEA</a>
|
||||
and <a href="FirstRealEA.html">FirstRealEA</a>.
|
||||
<br><font color="#FF6600">To compile and run</font> them, go to the <font color="#FF6600">Lesson2
|
||||
sub-directory</font> of the tutorial dir and simply type <b><tt><font color="#990000"><font size=+1>make</font></font></tt></b>.
|
||||
Both examples should get compiled, and you can then run them by calling
|
||||
their name from the system prompt.
|
||||
<p>Note the slim difference in names, from <font color="#FF6600">GA</font>
|
||||
to <font color="#FF6600">EA</font>: the behavior of these EAs is
|
||||
almost identical to that of their GA counterpart, at least with the default
|
||||
settings that are provided. But their potentialities for easy modifications
|
||||
are much larger, both in terms of <b><font color="#CC33CC">variation operators</font></b>
|
||||
and of <b><font color="#009900">evolution engine</font></b> (i.e. <font color="#009900">selection/replacement</font>
|
||||
mechanism).
|
||||
<hr WIDTH="100%"><a NAME="changes"></a><b><font color="#000099"><font size=+2>Changes</font></font></b>
|
||||
<p>Browse through the code, and discover them one after the other:
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">The</font><font color="#CC0000"> fitness function
|
||||
</font><font color="#000000">now
|
||||
lies in a </font><b><font color="#CC0000">separate file
|
||||
</font></b><font color="#000000">(<a href="FirstBitEA.html#evalfunc">Bit</a>
|
||||
- <a href="FirstRealEA.html#evalfunc">Real</a>). But, more important, its
|
||||
argument is a <a href="binary_value.html">vector<bool></a> or a <a href="real_value.html">vector<double></a>,
|
||||
and not an unknown type. This will allow to use the same file for any EO
|
||||
object that is a sub-class of the corresponding STL vector class.</font></li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">Also,
|
||||
a non-templatized fitness can be </font><b><font color="#FF6600">compiled
|
||||
separately</font></b><font color="#000000"> (not done here) into an object
|
||||
file once and for all (<a href="eoProgramming.html#templates">remember</a>
|
||||
that templates forbid that).</font>
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="minimize"></a><font color="#000000">The </font><font color="#CC0000"><b>encapsulation
|
||||
</b>of
|
||||
the fitness </font><font color="#000000">(<a href="FirstBitEA.html#eval">Bit</a>
|
||||
- <a href="FirstRealEA.html#eval">Real</a>) looks more complicated: you
|
||||
have to declare 3 template arguments: the type of EO object it will be
|
||||
applied to, the return type and the type of argument the function actually
|
||||
requires.</font></li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">In the
|
||||
previous files (<a href="FirstBitGA.html#eval">Bit</a> - <a href="FirstRealGA.html#eval">Real</a>)
|
||||
, the last 2 types were deduced from the first (2nd argument = fitness
|
||||
type of EO object, third = first).</font>
|
||||
<br>
|
||||
<li>
|
||||
<font color="#000000">Both the above modifications makes it very easy to
|
||||
</font><b><font color="#CC0000">minimize</font></b><font color="#000000">
|
||||
rather than maximize a fitness function (see <a href="#Execrise1">Exercise
|
||||
1)</a>.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<font color="#000000">The</font><font color="#CC33CC"> initialization</font><font color="#000000">
|
||||
of the population is now </font><b><font color="#CC33CC">encapsulated</font></b><font color="#000000">into
|
||||
a </font><font color="#CC33CC"><b>separate initializer</b> </font><font color="#000000">(based
|
||||
on a <a href="FirstBitEA.html#init">boolean generator</a> or a <a href="FirstRealEA.html#init">double-number
|
||||
generator</a> -see <a href="../../doc/html/class_random_generator.html">random_generators.h</a>)
|
||||
that is then used in the constructor of the population to build the individuals.
|
||||
You can also use different initializers and call them in turn through the
|
||||
call to <a href="../../doc/html/classeo_pop.html#a2">pop.append()</a> function
|
||||
(see <a href="#exercise2">Exercise 2</a>).</font></li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><font color="#FF0000">Note</font><font color="#CC33CC">: </font></b><font color="#000000">Don't
|
||||
forget to </font><b><font color="#CC0000">evaluate the population</font></b><font color="#000000">:
|
||||
the eoPop has no idea of the eval function, so it has to be done from outside!!!</font>
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="combined_operators"></a><font color="#000000">You can now use
|
||||
</font><font color="#CC33CC"><b>different
|
||||
</b>crossover
|
||||
</font><font color="#000000">and</font><font color="#CC33CC">
|
||||
mutation
|
||||
<b>operators</b></font><font color="#000000">in the same algorithm,
|
||||
choosing among them according to
|
||||
</font><b><font color="#FF6600">relative
|
||||
weights.</font></b><font color="#CC33CC"> </font><font color="#000000">The
|
||||
class </font><font color="#CC33CC"><b>eoPropCombinedxxxOp</b>,
|
||||
</font><font color="#000000">where
|
||||
xxx is either Mon (for mutations, of class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b></font><font color="#CC33CC">)</font><font color="#000000">
|
||||
or Quad (for crossovers, of class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_quad_op.html">eoQuadOp</a></font></font></b>),
|
||||
is derived from the corresponding eoxxxOp class. When applying the eoPropCombinedxxxOp,
|
||||
one of the eoxxxOp it contains is chosen by a <a href="../../doc/html/classeo_rng.html#a12">roulette
|
||||
wheel,</a> according to their respective rates, and is applied to the arguments.
|
||||
For more details on these classes, go to the <a href="eoOperators.html#crossover">algorithm-based
|
||||
corresponding pages</a>, or to their respective documentation pages.</font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000"><a href="FirstBitEA.html#operators">Bit</a></font></li>
|
||||
|
||||
<br><font color="#000000">Three </font><b><font color="#FF6600">crossover
|
||||
operators</font></b><font color="#000000"> are available: the </font><font color="#FF6600">one-point</font><font color="#000000">
|
||||
crossover is still there (class ), but now you also have the </font><font color="#FF6600">N-point</font><font color="#000000">
|
||||
crossover </font><font color="#CC33CC">eoBinNxOver</font><font color="#000000">
|
||||
(the number of points is 2 by default, but as always you can change
|
||||
that in the constructor), and the </font><font color="#FF6600">Uniform</font><font color="#000000">
|
||||
crossover </font><font color="#CC33CC">eoBinUxOver</font><font color="#000000">
|
||||
(where you can eventually twidle the choice from one parent to the other
|
||||
by providing a probability in the constructore - defaulted to 0.5, which
|
||||
amounts to symmetrical choice).</font>
|
||||
<br><font color="#000000">As for </font><b><font color="#FF6600">mutation
|
||||
operators</font></b><font color="#000000">, apart from the </font><font color="#CC33CC">eoBinMutation</font><font color="#000000">
|
||||
(standard bitstring mutation flipping one bit with a given probability)
|
||||
you can also use the </font><font color="#CC33CC">eoDetBitFlip</font><font color="#000000">
|
||||
that always filps the same number of bits (1 by default, but you can change
|
||||
that in the constructor), randomly chosen in the bitstring. Even though
|
||||
the average number of bits flipped is the same if the </font><font color="#CC33CC">eoBinMutation
|
||||
</font><font color="#000000">is
|
||||
used with a rate of 1/N (N is the bitstring length) </font><font color="#FF6600">the
|
||||
behavior of these mutation can be very different</font><font color="#000000">
|
||||
on many problems.</font>
|
||||
<li>
|
||||
<font color="#000000"><a href="FirstRealEA.html#operators">Real</a></font></li>
|
||||
|
||||
<br><font color="#000000">Two </font><b><font color="#FF6600">crossover
|
||||
operators</font></b><font color="#000000"> are available: the </font><font color="#CC33CC">eoSegmentCrossover</font><font color="#000000">
|
||||
chooses one point uniformly on the segment joining the parents, while the
|
||||
</font><font color="#CC33CC">eoHypercubeCrossover</font><font color="#000000">
|
||||
performs a linear combination on each coordinate independently, which amount
|
||||
to choosing the offspring uniformly in the hypercube whose diagonal is
|
||||
the segment joining the parents.</font>
|
||||
<br><font color="#000000">As for </font><b><font color="#FF6600">mutation
|
||||
operators</font></b><font color="#000000">, apart from the </font><font color="#CC33CC">eoBinMutation</font><font color="#000000">
|
||||
(standard bitstring mutation flipping one bit with a given probability)
|
||||
you can also use the </font><font color="#CC33CC">eoDetBitFlip</font><font color="#000000">
|
||||
that always filps the same number of bits (1 by default, but you can change
|
||||
that in the constructor), randomly chosen in the bitstring. And last but
|
||||
not least, the normal mutation eoNormMutation modifies all coordinates
|
||||
with a Gaussian noise, with standard deviation passed in the constructor.</font></ul>
|
||||
<b><font color="#FF0000">Note:</font></b> A third optional argument in
|
||||
method <b><tt><font color="#660000">add</font></tt></b> is a boolean (defaulted
|
||||
to false). When true, the actual rates for all operators are displayed
|
||||
on the screen as percentages: you don't have to input rates that sum up
|
||||
to 1, all rates are scaled anyway.
|
||||
<p><a NAME="transform"></a><b><font color="#FF0000">Note:</font></b> The
|
||||
operators have to be encapsulated into an <b><tt><font color="#CC33CC">eoTransform</font></tt></b>
|
||||
object (<a href="FirstBitEA.html#transform">Bit</a> - <a href="FirstRealEA.html#transform">Real</a>)
|
||||
to be passed to the <b><tt><font color="#FF6666">eoEasyEA </font></tt></b>algorithm.
|
||||
The <b><tt><font color="#CC33CC">eoSGATransform</font></tt></b> is a simple
|
||||
<b><tt><font color="#CC33CC">eoTransform</font></tt></b>
|
||||
that does exactly the same thing than <b><tt><font color="#FF6666">eoSGA</font></tt></b>:
|
||||
each pair from the selected parents undergoes the <font color="#CC33CC">crossover
|
||||
operator with given probability</font>, and all individuals (after crossover
|
||||
eventually) undergo <font color="#CC33CC">mutation with given probability</font>.
|
||||
The arguments to the <b><tt><font color="#CC33CC">eoSGATransform</font></tt></b>
|
||||
are an <b><tt><font color="#CC33CC">eoQuadOp</font></tt></b> with its probability
|
||||
and an <b><tt><font color="#CC33CC">eoMonOp</font></tt></b> with the associated
|
||||
probability.
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="combinedContinue"></a><font color="#000000">You can use </font><b><font color="#3366FF">combinations
|
||||
</font></b><font color="#000000">of
|
||||
several stopping criteria by using an object of the class </font><b><tt><font color="#3366FF">eoCombinedContinue
|
||||
</font></tt></b><font color="#000000">(<a href="FirstBitEA.html#stop">Bit</a>
|
||||
- <a href="FirstRealEA.html#stop">Real</a>). Initialize it with an object
|
||||
of class </font><font color="#3366FF"><b><tt>eoContinue</tt></b>, </font><font color="#000000">and
|
||||
</font><b><tt><font color="#3366FF">add</font></tt></b><font color="#000000">
|
||||
as many of other such objects as you wish. And as an </font><b><tt><font color="#3366FF">eoCombinedContinue
|
||||
</font></tt><font color="#FF6600">is
|
||||
an</font><tt><font color="#3366FF"> eoContinue</font></tt></b><font color="#000000">,
|
||||
simply pass it to the algorithm (<a href="FirstBitEA.html#generation">Bit</a>
|
||||
- <a href="FirstRealEA.html#generation">Real</a>). To find out more, and
|
||||
to get the list and syntax of existing eoContinue subclasses, check out
|
||||
the corresponding <a href="eoCheckPoint.html#existingContinue">component-based
|
||||
page</a>.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="evolution"></a><font color="#000000">The</font><b><font color="#009900">
|
||||
full selection/replacement mechanism </font></b><font color="#000000">is
|
||||
now in place through the </font><font color="#FF6666"><b><tt>eoEasyEA</tt></b>
|
||||
algorithm.</font></li>
|
||||
|
||||
<br>This means that you can use different <font color="#009900">selectors</font>.
|
||||
which was already true in Lesson 1, but also different <font color="#009900">replacement
|
||||
strategies</font> (see <a href="#Exercise3">Exercise 3</a>) whereas <font color="#009900">generational
|
||||
replacement</font> was hard-coded in the algorithm <b><tt><font color="#FF6666">eoSGA</font></tt></b>
|
||||
used in Lesson1.
|
||||
<p>Beware that we have to encapsulate <font color="#000000">(<a href="FirstBitEA.html#select_encapsulate">Bit</a>
|
||||
- <a href="FirstRealEA.html#select_encapsulate">Real</a>) </font>the <font color="#FF6600">eoDetTournament</font>,
|
||||
which is of class <font color="#FF6600">eoSelectOne</font> (i.e. allows
|
||||
to select one individual from a population, its <b><tt><font color="#660000">operator()</font></tt></b>
|
||||
returning a single individual) into an object of the <font color="#FF6600">eoSelectPerc</font>
|
||||
(perc stands for percentage) which allows to select a ... percentage of
|
||||
a population (his <b><tt><font color="#660000">operator()</font></tt></b>
|
||||
returns a population). This was done internally in the <a href="../../doc/html/classeo_s_g_a.html#a0">constructor
|
||||
of eoSGA</a> - see lesson1.</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="Exercise1"></a><b><font size=+2><font color="#000099">Exercise
|
||||
1: </font><font color="#FF0000">minimizing</font></font></b>
|
||||
<br><font color="#000000">Modify the algorithm so that it minimizes the
|
||||
fitness.</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">For the bitstring case, you only have to modify the
|
||||
<a href="FirstBitEA.html#representation">declaration
|
||||
of the representation</a>, using </font><b><tt><font color="#999900">eoMinimizingFitness</font></tt></b><font color="#000000">
|
||||
instead of </font><b><tt><font color="#999900">double</font></tt></b><font color="#000000">.
|
||||
But is that really all? Give it a try, look at the output, and do it right
|
||||
the second time!!!</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">For the real-valued problem, you also need to modify
|
||||
the file <b><tt><a href="real_value.html">real_value.h</a></tt></b> so
|
||||
that it returns the sum of squares instead of its inverse. And again there
|
||||
is something else to modify...</font></li>
|
||||
</ul>
|
||||
<a NAME="exercise2"></a><b><font size=+2><font color="#000099">Exercise
|
||||
2: </font><font color="#FF0000">initialization</font></font></b>
|
||||
<br><font color="#000000">Use different initializers: for instance, on
|
||||
the real-valued sphere function minimization, try to initialize half of
|
||||
the population in [-2,-1] and the other half in [1,2], with and without
|
||||
the segment and hypercube crossovers (and for large values of VEC_SIZE,
|
||||
the size of the vectors). Amazing, isn't it! Explain that result.</font>
|
||||
<p><a NAME="Exercise3"></a><b><font size=+2><font color="#000099">Exercise
|
||||
3: </font><font color="#FF0000">full selection/replacement</font></font></b>
|
||||
<br><font color="#000000">You can now twiddle the number of offspring that
|
||||
will be generated from the parents. But of course you need to adjust the
|
||||
replacement to keep a constant population size.</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">To </font><font color="#FF6600">modify the number
|
||||
of offspring</font><font color="#000000">, use the second argument of the
|
||||
</font>encapsulator<font color="#000000">
|
||||
(<a href="FirstBitEA.html#select_encapsulate">Bit</a> - <a href="FirstRealEA.html#select_encapsulate">Real</a>)
|
||||
of the </font><font color="#009900">selector</font><font color="#000000">
|
||||
of class </font><b><tt><font color="#009900">eoSelectOne</font></tt></b><font color="#000000">
|
||||
into an eoSelectPerc object. For instance, try</font></li>
|
||||
|
||||
<br><b><tt><font color="#009900">
|
||||
eoSelectPerc<Indi> select(selectOne,2.0)</font></tt></b>
|
||||
<br><font color="#000000">to generate twice as many offspring as there
|
||||
are parents.</font>
|
||||
<br><font color="#000000">You can also use the other encapsulator that
|
||||
takes as second argument an absolute number (e.g. if you want to generate
|
||||
2 offspring whatever the population size):</font>
|
||||
<br><b><tt><font color="#009900">
|
||||
eoSelectNumber<Indi> select(selectOne,2)</font></tt></b>
|
||||
<br><font color="#000000">Or you can use the <a href="eoEngine.html#howmany">HowMany</a>
|
||||
paradigm and the </font><b><tt><font color="#009900">eoSelectMany </font></tt></b><font color="#000000">to
|
||||
do either one depending on some command-line input (advanced).</font>
|
||||
<li>
|
||||
<font color="#000000">To </font><font color="#FF6600">keep a constant population
|
||||
size</font><font color="#000000">, you can use either the </font><b><tt><font color="#009900">eoCommaReplacement</font></tt></b><font color="#000000">
|
||||
class, or the </font><b><tt><font color="#009900">eoPlusReplacement</font></tt></b><font color="#000000">.
|
||||
The former selects the best offspring to replace the parents, the latter
|
||||
selects the best among parents+offspring. Of course you cannot use </font><b><tt><font color="#009900">eoCommaReplacement</font></tt></b><font color="#000000">
|
||||
if you have less offspring than parents!</font></li>
|
||||
|
||||
<br>Now if you use <b><tt><font color="#009900">eoSelectRandom</font></tt></b>
|
||||
as selector with a rate of
|
||||
<i>lambda</i>, you end up with exactly the <i>(mu+lambda)</i>
|
||||
or
|
||||
<i>(mu,lambda)</i> strategies from <a href="intro.html#ES">Evolution
|
||||
Strategies</a>.
|
||||
<li>
|
||||
<font color="#FF0000">Question</font><font color="#000000">: what do you
|
||||
get if you select 1 offspring only, and an </font><b><tt><font color="#009900">eoPlusReplacement</font></tt></b><font color="#000000">
|
||||
strategy? Yes, you get almost the replace_worst Steady-State GA, though
|
||||
rather inefficient, as you sort the population at every generation.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#FF0000">Hint</font><font color="#000000">: there are a few
|
||||
Steady-State replacement strategies already there in EO. See the <a href="eoEngine.html#SSGA">Replacement
|
||||
page</a>.</font></li>
|
||||
</ul>
|
||||
<font color="#FF0000">Remember</font><font color="#000000">: all solutions
|
||||
are in the same sub-directory of the Tutorial dir than the examples (i.e.
|
||||
here Lesson2), and are described <a href="NoWay.html">here</a>.</font>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Lessons learned:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
How to write a <font color="#CC0000">fitness function</font> that only
|
||||
needs a genotype, not a full individual. Moreover you can compile it separately.</li>
|
||||
|
||||
<br>How to <font color="#CC33CC">initialize</font> the population using
|
||||
random generators
|
||||
<li>
|
||||
How to use other <font color="#009900">evolution engine</font> than the
|
||||
simple generational GA.</li>
|
||||
|
||||
<li>
|
||||
How to combine different objects of the same kind into a single object
|
||||
that you can use like a simple basic object (<font color="#CC33CC">operators</font>
|
||||
and <font color="#3366FF">stopping criteria</font> here).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson1.html">Lesson 1</a> -
|
||||
<a href="eoLesson3.html">Lesson
|
||||
3</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Hints</a>
|
||||
- <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Fri Nov 3 18:49:12 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Fri Nov 3 18:49:12 CET 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
565
deprecated/eo/tutorial/html/eoLesson3.html
Normal file
565
deprecated/eo/tutorial/html/eoLesson3.html
Normal file
|
|
@ -0,0 +1,565 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
|
||||
<title>Tutorial: Lesson 3</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson2.html">Lesson 2</a> -
|
||||
<a href="eoLesson4.html">Lesson
|
||||
4</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Hints</a>
|
||||
- <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial Lesson 3: input/output</font></h1></center>
|
||||
In this lesson, you will still use the same Evolutionary Algorithm, BUT
|
||||
in a much more <b><font color="#FF6600">user-friendly</font></b> way. You
|
||||
will discover how to
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#parser">input parameters</a> on the command-line or from a text
|
||||
file</li>
|
||||
|
||||
<li>
|
||||
<a href="#state">save</a> the population to disk, together with every part
|
||||
of the algorithm you could think of - so you can decide to <font color="#FF6600">reload</font>
|
||||
everything later to continue the same run, eventually with different parameters.</li>
|
||||
|
||||
<li>
|
||||
<a href="#stats">generate statistics</a> on the populations, and <a href="#monitor">output
|
||||
them</a> to the screen, text or graphic, or to a file (or to any other
|
||||
device you might want to use).</li>
|
||||
</ul>
|
||||
First, but you should now have done it without being told, go into the
|
||||
<font color="#FF6600">Lesson3
|
||||
sub-dir</font> of the tutorial dir and type
|
||||
<b><tt><font color="#990000"><font size=+1>make</font></font></tt></b>.
|
||||
This will compile the <b><tt><font color="#660000"><font size=+1>SecondBitEA</font></font></tt></b>
|
||||
and <b><tt><font color="#660000"><font size=+1>SecondRealEA</font></font></tt></b>
|
||||
programs.
|
||||
<p>You can then either
|
||||
<ul>
|
||||
<li>
|
||||
browse the corresponding code (<a href="SecondBitEA.html">SecondBitEA</a>
|
||||
and <a href="SecondRealEA.html">SecondRealEA</a>),</li>
|
||||
|
||||
<li>
|
||||
look at the <a href="#changes">summary of changes</a>,</li>
|
||||
|
||||
<li>
|
||||
or find out directly explanations about the new features: the <a href="#parser">eoParser</a>,
|
||||
<a href="#state">eoState</a>
|
||||
and <a href="#checkpoint">eoCheckpoint</a> classes.</li>
|
||||
</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="changes"></a><b><font color="#000099"><font size=+2>Changes</font></font></b>
|
||||
<br><font color="#000000">As already said, the behavior of the algorithm
|
||||
will be exactly the same as the previous one as far as optimization is
|
||||
concerned. Only the input (of algorithm parameters) and output (of program
|
||||
results) will be very different.</font>
|
||||
<br><font color="#000000">Hence, the sections corresponding to the <a href="SecondBitEA.html#eval">fitness
|
||||
function</a>, the <a href="SecondBitEA.html#init">initialization</a>, the
|
||||
<a href="SecondBitEA.html#operators">variation
|
||||
operators</a>, the <a href="SecondBitEA.html#engine">evolution engine</a>
|
||||
and the <a href="SecondBitEA.html#generation">algorithm</a> itself are
|
||||
almost identical (apart from variable name changes).</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000"><a href="SecondBitEA.html#eval">Fitness function</a>:
|
||||
there is an </font><font color="#FF6600">additional line</font><font color="#000000">
|
||||
after the encapsulation of our </font><font color="#CC0000">binary_function</font><font color="#000000">
|
||||
into an </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFunc</font></font></tt></b><font color="#000000">
|
||||
object, which again encapsulate the </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFunc</font></font></tt></b><font color="#000000">
|
||||
into an </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFuncCounter</font></font></tt></b><font color="#000000">.
|
||||
As its name says, this object will, in addition to computing the fitness,
|
||||
count the </font><b><font color="#FF6600">actual</font></b><font color="#000000">
|
||||
number of evaluations: the fitness of non-modified individuals is of course
|
||||
not recomputed - and this is taken care of by this object. Moreover, it
|
||||
can be later </font><font color="#FF6600">used for displays</font><font color="#000000">
|
||||
in <a href="#monitor">eoMonitor</a> objects, as done in the <a href="SecondBitEA.html#eval_monitor">checkpoint
|
||||
section</a>.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The <a href="SecondBitEA.html#init">initialization</a>
|
||||
section has been extended to account for the possibility to </font><font color="#CC33CC">re-load
|
||||
a previously saved population</font><font color="#000000">. This is achieved
|
||||
through an <a href="#state">eoState</a> object, if the corresponding program
|
||||
parameter is set.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The
|
||||
<a href="SecondBitEA.html#operators">variation
|
||||
operators</a> and the <a href="SecondBitEA.html#engine">evolution engine</a>
|
||||
sections are similar to the ones in Lesson2</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The <a href="SecondBitEA.html#parametres">parameter
|
||||
section</a> is completely different from the previous one. All variables
|
||||
corresponding to </font><font color="#3366FF">program parameters</font><font color="#000000">
|
||||
are now read at run-time using an object of class <a href="#parser">eoParser</a>.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The <a href="SecondBitEA.html#stop">stopping criterion
|
||||
section</a>, has in fact now become the checkpoint section, as it involves
|
||||
much more than just stopping criteria. See all details in the <a href="#checkpoint">eoCheckpoint
|
||||
paragraph below</a>.</font></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="parser"></a><b><font color="#000099"><font size=+2>eoParser:
|
||||
parameter input</font></font></b>
|
||||
<br><font color="#000000">The first two examples of Lessons 1 and 2 had
|
||||
a very crude way to set parameter values: they were hard-coded, and you
|
||||
had to recompile the whole program to change a single value. We shall now
|
||||
see now to set parameter values in a flexible way (though we're still looking
|
||||
for volunteers to create a Graphical User Interface :-)</font>
|
||||
<br><font color="#000000">Two base classes are used for that purpose:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">The </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
class, </font><font color="#FF6600">templatized by the type of the variable</font><font color="#000000">
|
||||
you want to handle (i.e. i</font><b><tt><font color="#660000">integer,
|
||||
double, yourPrivateClass</font></tt></b><font color="#000000">, ...). In
|
||||
this lesson, we will not go into details: e.g. we will not tell you that
|
||||
the
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_value_param.html">eoValueParam</a></font></font></b>
|
||||
is actually a templatized sub-class of abstract class eoParam (oops, I
|
||||
said it!), nor will we deal with parameters outside their use from an eoParser.
|
||||
See the parameter section of the Component-Based tutorial, or wait until
|
||||
<a href="eoLesson4.html">lesson
|
||||
4</a>).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The </font><b><tt><font color="#3366FF">eoParser</font></tt></b><font color="#000000">
|
||||
class, whose only purpose is the input of parameters. Read <a href="../../doc/html/classeo_parser.html">its
|
||||
description</a> if you are interested.</font></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%"><a NAME="paraminput"></a><b><font color="#000099">eoParser:</font><font color="#FF0000">
|
||||
Modifying parameter values at run-time:</font></b>
|
||||
<br><font color="#000000">Using an eoParser object, the parameter values
|
||||
are read, by order of priority</font>
|
||||
<ol>
|
||||
<li>
|
||||
<font color="#000000">from the command-line</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from a text file</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from the environment (forthcoming, if somebody insists)</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from default values</font></li>
|
||||
</ol>
|
||||
The syntax of parameter reading is a <b><font color="#FF6600">keyword</font></b>-based
|
||||
syntax, now traditional in the Unix world:
|
||||
<ul>
|
||||
<li>
|
||||
in EO, each parameter is designated by <font color="#FF6600">a (long) keyword</font>,
|
||||
and optionally by a <font color="#FF6600">short (1 character) keyword</font>.</li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
the general syntax to modify parameter value at run-time is (either from
|
||||
the command-line or in a text file)</li>
|
||||
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#660000">--longKeyword=value</font></tt></b>
|
||||
or <b><tt><font color="#660000">-cvalue</font></tt></b>
|
||||
if 'c' is the short keyword (though <b><tt><font color="#660000">-c=value</font></tt></b>
|
||||
also works)
|
||||
<br>
|
||||
<li>
|
||||
so, after compiling the executable for Lesson 3 (<b><tt><font color="#FF6666">make
|
||||
lesson3</font></tt></b> at system prompt in Unix), you can try to type
|
||||
in</li>
|
||||
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#FF6666">SecondBitEA</font></tt></b>
|
||||
<br>and see the algorithm run as before (OneMax optimized on 8-bits bitstrings).
|
||||
But you can now type in
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#FF6666">SecondBitEA --vecSize=100</font></tt></b>
|
||||
<br>and see the output of the optimization of OneMax on 100-bit bitstrings.
|
||||
<br>
|
||||
<li>
|
||||
Take a look at all available parameters by typing in</li>
|
||||
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#FF6666">SecondBitEA --help</font></tt></b>
|
||||
<br>or by going into the code: all parameter inputs have been grouped in
|
||||
the
|
||||
<a href="SecondBitEA.html#parametres">read_param</a> function.
|
||||
<br>
|
||||
<li>
|
||||
After running the algorithm, a new file has been created, named <b><tt><font color="#990000">SecondBitEA.status</font></tt></b>:
|
||||
it contains the list of all actual parameters used, and can directly be
|
||||
used as parameter input file: change the file name (e.g. to <b><tt><font color="#660000">SecondBitEA.param</font></tt></b>),
|
||||
edit it, change whichever parameter you want, and type in</li>
|
||||
|
||||
<br>
|
||||
<b><tt><font color="#FF6666">SecondBitEA @SecondBitEA.param</font></tt></b>
|
||||
<br>and you will see all values that you defined into the file taken into
|
||||
account.
|
||||
<br>
|
||||
<li>
|
||||
The <font color="#FF6600">priority</font> remains to the <font color="#FF6600">command-line</font>,
|
||||
so you can still override the values in the parameter file by giving a
|
||||
new value directly on the command-line.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%"><a NAME="parameters"></a><b><font color="#000099">eoParser:</font><font color="#FF0000">
|
||||
Programming parameter input:</font></b>
|
||||
<br>The code of SeconBitEA provides examples of parameters reading. Lets
|
||||
take the example of the <a href="eoProgramming.html#random">random number
|
||||
generator </a><b><tt><font color="#660000">seed</font></tt></b>.
|
||||
Of course, you first need to <a href="SecondBitEA.html#parser_declare">declare
|
||||
an eoParser object</a> (it needs the standard argc and argv in its constructor).
|
||||
<ul>
|
||||
<li>
|
||||
You must first <a href="SecondBitEA.html#random">declare a parameter</a>
|
||||
of type <b><tt><font color="#660000">uint32</font></tt></b> (32-bits integer).
|
||||
The arguments are: default value, long keyword, comment (that will appear
|
||||
in the help message and in the output "status" file if any) and optional
|
||||
character keyword.</li>
|
||||
|
||||
<li>
|
||||
Then you must <a href="SecondBitEA.html#seed_process">pass it to the parser</a>
|
||||
using the processParam method. The optional argument is a section name,
|
||||
that will be used to make the output of the parser look clean and ordered.</li>
|
||||
|
||||
<li>
|
||||
Finally, you need to <a href="SecondBitEA.html#seed_assign">assign the
|
||||
value</a> to the variable <b><tt><font color="#660000">seed</font></tt></b>.
|
||||
Note that the <b><tt><font color="#990000">value()</font></tt></b> method
|
||||
of eoParam returns a reference, so you can eventually modify its value
|
||||
somewhere else later (though of course this is not any useful for variable
|
||||
<b><tt><font color="#660000">seed</font></tt></b>!).</li>
|
||||
</ul>
|
||||
There is however another way to achieve the same result in less lines of
|
||||
code - with a different memory management. This is what is done in the
|
||||
code for eoRealEA. The same parameter for the <a href="eoProgramming.html#random">random
|
||||
number generator </a><b><tt><font color="#660000">seed</font></tt></b>
|
||||
is read, but in <a href="SecondRealEA.html#random">one single line of code</a>.
|
||||
The only difference is that now you cannot access the eoValueParam object
|
||||
itself - but this is not often necessary.
|
||||
<br>Be careful to ensure that the type of the default value in the call
|
||||
to <a href="../../doc/html/classeo_parameter_loader.html#a3">eoParameterLoader::createParam</a>
|
||||
method as this is the only way the compiler can desambiguate the template
|
||||
(remember that eoParameterLoader is <font color="#000000"><a href="../../doc/html/classeo_parser.html">a
|
||||
base class for eoParser</a></font>.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="state"></a><b><font color="#000099"><font size=+2>eoState:
|
||||
saving and loading</font></font></b><font color="#000000">You might have
|
||||
noticed in the </font><b><tt><font color="#660000">read_param</font></tt></b><font color="#000000">
|
||||
described above a </font><font color="#FF6600">new parameter</font><font color="#000000">
|
||||
named </font><b><tt><font color="#660000"><a href="SecondBitEA.html#_load_name">load_name.</a></font></tt></b><font color="#000000">
|
||||
Now if you go to the <a href="SecondBitEA.html#init">init section</a> of
|
||||
the code, you will see an alternative way of </font><font color="#CC33CC">initializing
|
||||
the population</font><font color="#000000">: if load_name is an empty string,
|
||||
then we do as in the preceding example and use an eoInitFixedLength object.
|
||||
However, if a load_name name was entered, the population is read through
|
||||
the </font><b><tt><font color="#660000"><a href="SecondBitEA.html#instate.load">inState.load(load_name)</a></font></tt></b><font color="#000000">
|
||||
instruction. Moreover, the comment says "Loading pop </font><font color="#FF6600">and
|
||||
rng</font><font color="#000000">".</font>
|
||||
<p><font color="#000000">This is made possible using the </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
class. </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
objects maintain references to </font><b><tt><font color="#660000">eoObjects</font></tt></b><font color="#000000">
|
||||
that have both an input method (</font><b><tt><font color="#3366FF">readFrom</font></tt></b><font color="#000000">)
|
||||
and an output method (</font><b><tt><font color="#3366FF">printOn</font></tt></b><font color="#000000">),
|
||||
i.e. that derive from the base class </font><b><font face="Arial,Helvetica"><font color="#660000"><font size=+1><a href="../../doc/html/classeo_persistent.html">eoPersistent</a></font></font></font></b><font color="#000000">.
|
||||
You must first </font><b><tt><font color="#3366FF"><a href="SecondBitEA.html#register">register</a></font></tt></b><font color="#000000">
|
||||
object into a state, and can then save them to a (text) file, and later
|
||||
read them from that file using the </font><b><tt><font color="#3366FF">load</font></tt></b><font color="#000000">
|
||||
method, as done <a href="SecondBitEA.html#loadstate">here</a>.</font>
|
||||
<br><font color="#000000">Of course, you can call the </font><b><tt><font color="#3366FF">save</font></tt></b><font color="#000000">
|
||||
method for an </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
object anywhere in the code. But the <a href="#statesaver">checkpointing</a>
|
||||
mechanism offers you better ways to do that - and it's so easy ....</font>
|
||||
<p>Note that an eoState alos has another use in EO whan it comes to memory
|
||||
management: it can be a repository of pointers that are not allocated within
|
||||
obects - allowing to delete them by simply deleting the eoState (see <a href="eoLesson4.html#memory">Lesson
|
||||
4)</a>.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="checkpoint"></a><b><font color="#000099"><font size=+2>eoCheckpoint:
|
||||
every generation I'd like to ...</font></font></b>
|
||||
<br><font color="#000000">The checkpointing mechanism is a very powerful
|
||||
construct to perform some </font><b><font color="#FF6600">systematic actions</font></b><font color="#000000">
|
||||
every generation - like </font><font color="#FF6600">saving things</font><font color="#000000">
|
||||
(using eoState objects described above), computing </font><font color="#FF6600">statistics</font><font color="#000000">
|
||||
on the population, </font><font color="#FF6600">updating</font><font color="#000000">
|
||||
dynamical parameters or </font><font color="#FF6600">displaying</font><font color="#000000">
|
||||
information.</font>
|
||||
<p><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
objects are </font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
objects that contain </font><font color="#FF6600">pointers to different
|
||||
types</font><font color="#000000"> of objects. When their </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
method is called (i.e. every generation in the examples up to now), they
|
||||
first call the </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
methods of all object they contain, and then return their result as an
|
||||
</font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
object (i.e. should we continue or stop).</font>
|
||||
<br><b><font color="#FF0000">Programming: </font></b><font color="#000000">To
|
||||
do something every generation, you simply need to </font><b><tt><font color="#3366FF">add</font></tt></b><font color="#000000">
|
||||
an object whose </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
does what you want to the eoState that you will use as continuator in the
|
||||
algorithm.</font>
|
||||
<br>
|
||||
<hr WIDTH="50%"><a NAME="stop"></a><b><font color="#000099">eoCheckpoint:
|
||||
</font><font color="#FF0000">Stopping</font></b>
|
||||
<br><font color="#000000">The </font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
part of an </font><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
is a single object, <a href="SecondBitEA.html#checkpoint">passed to the
|
||||
constructor</a>. If you want more that one stopping criterion, use an <a href="SecondBitEA.html#stop">eoCombinedContinue</a>
|
||||
object as described in <a href="eoLesson2.html#combinedContinue">Lesson2</a>.</font>
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><a NAME="stats"></a><b><font color="#000099">eoCheckpoint: </font><font color="#FF0000">Computing
|
||||
statistics</font></b>
|
||||
<br><font color="#000000">Statistics are computed using </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects, i.e. functor objects whose </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
receives as argument a reference to a population as argument, and can hence
|
||||
compute whatever is needed over that population. </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects are </font><font color="#FF6600">templatized</font><font color="#000000">
|
||||
over the type of what they compute (e.g. </font><b><tt><font color="#660000">double</font></tt></b><font color="#000000">,
|
||||
or </font><b><tt><font color="#660000">pair<double></font></tt></b><font color="#000000">,
|
||||
or ...). But looking at the <a href="../../doc/html/classeo_stat.html">inheritance
|
||||
diagram</a> of the </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
class, you find that </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects are also </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
objects. And this allows </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
to be used within </font><b><tt><font color="#3366FF">eoMonitor</font></tt></b><font color="#000000">
|
||||
object, and hence </font><b><font color="#FF6600">displayed</font></b><font color="#000000">
|
||||
to the user!</font>
|
||||
<p><b><font color="#000099">Statistics: </font><font color="#FF0000">Available
|
||||
instances</font></b>
|
||||
<br>Some widely used statistics are already available (and of course you
|
||||
can build you own!).
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoBestFitnessStat</font></tt></b> returns
|
||||
the fitness value of the best individual in the population (of type <b><tt><font color="#660000">FitnessType</font></tt></b>,
|
||||
whatever this is).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoAverageStat</font></tt></b> and <b><tt><font color="#3366FF">eoSecondMomentStat</font></tt></b>
|
||||
respectively return the average (type double, assumes that <b><tt><font color="#660000">FitnessType</font></tt></b>
|
||||
is castable to a double) and a pair made of the average and the standard
|
||||
deviation (type <b><tt><font color="#660000">pair<double></font></tt></b>)
|
||||
of the fitnesses in the populations.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoDiversityStat</font></tt></b> returns the
|
||||
diversity in the population: assuming that there is a distance function
|
||||
defined among individuals, it returns the average inter-individuals distance.
|
||||
See also Exercise 2.</li>
|
||||
</ul>
|
||||
<b><font color="#000099">Statistics: </font><font color="#FF0000">Adding
|
||||
to the checkpoint</font></b>
|
||||
<br>To compute more statistics when your algorithm is running, simply <a href="SecondBitEA.html#stat_declare">declare</a>
|
||||
the corresponding eoStat objects, and <a href="SecondBitEA.html#stat_pass">add</a>
|
||||
them to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b> you
|
||||
use in the algorithm. But it hardly makes any sense if you don't <b><font color="#3366FF">monitor</font></b>
|
||||
those statistics (i.e. either displaying them on the screen, or storing
|
||||
them into a file): see next section!
|
||||
<p><b><font color="#FF0000">Note</font></b>: actually, there are 2 distinct
|
||||
classes that compute and give access to statistics: <b><tt><font color="#3366FF">eoStat</font></tt></b>and
|
||||
<b><tt><font color="#3366FF">eoSortedStat</font></tt></b>.
|
||||
As its name indicate, the latter is used whenever computing the statistics
|
||||
require a sorted population: not only this avoids to sort the population
|
||||
many times, but also it avoids changing the order of the population at
|
||||
all as <b><tt><font color="#3366FF">eoSortedStat</font></tt></b> objects
|
||||
work on a temporary vector of fitnesses . But <font color="#FF6600">as
|
||||
far as their usage is concerned, its makes no difference</font>.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><a NAME="monitor"></a><b><font color="#000099">eoCheckpoint: </font><font color="#FF0000">Monitoring
|
||||
eoParameters</font></b>
|
||||
<br><font color="#000000">The </font><b><tt><font color="#3366FF">eoMonitor</font></tt></b><font color="#000000">
|
||||
objects are used to display or store to a file a set of </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
objects.</font>
|
||||
<p><b><font color="#000099">Monitors</font></b>: <b><font color="#FF0000">Available
|
||||
instances</font></b>
|
||||
<br>A few monitors are available in the EO distribution:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoStdoutMonitor</font></tt></b> displays its
|
||||
parameters in <font color="#FF6600">text format on the screen</font>. The
|
||||
(optional) boolean value in the constructor modifies the output: when true
|
||||
(the default), verbose output is used, with one line per parameter. When
|
||||
false, parsimonious output displays one line for all parameters.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoFileMonitor</font></tt></b> writes its parameters
|
||||
in <font color="#FF6600">text format in a file</font>. A file name is required
|
||||
in the constructor, and an optional separator character can be added (default
|
||||
is ' '). Note that the file is by default overwritten by next call to the
|
||||
same program, unless you pass "true" as third (optional) boolean parameter,
|
||||
which will result in appending to the file if it ever exists.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoGnuplot1DMonitor</font></tt></b> displays
|
||||
its parameters in <font color="#FF6600">graphical format on the screen</font>
|
||||
by calling the <b><tt><font color="#660000">gnuplot</font></tt></b> program,
|
||||
and as of today, only works in the Unix version of EO (as always, volunteers
|
||||
are welcome to port that to MS Windows). It takes an optional filename
|
||||
as input, as communication of data with <b><tt><font color="#660000">gnuplot</font></tt></b>
|
||||
is done through a file. If no filename is provided, the file will be erased
|
||||
at the end of the run, while it is otherwise kept (though it will be overwritten
|
||||
by next call to the same program).</li>
|
||||
</ul>
|
||||
|
||||
<p><br><b><font color="#000099">Monitors</font></b>: <b><font color="#FF0000">Adding
|
||||
to the checkpoint</font></b>
|
||||
<br>To display something while the algorithm is running, you need to <a href="SecondBitEA.html#monitor_declare">declare</a>
|
||||
an <b><tt><font color="#3366FF">eoMonitor</font></tt></b> object, <a href="SecondBitEA.html#monitor_add">add</a>
|
||||
some objects (that must be <b><tt><font color="#3366FF">eoValueParam</font></tt></b>
|
||||
objects) to that monitor, and of course <a href="SecondBitEA.html#monitor_pass">add</a>
|
||||
the monitor to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>
|
||||
you use in the algorithm.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><a NAME="update"></a><b><font color="#000099">eoCheckpoint: Updating
|
||||
things</font></b>
|
||||
<br><font color="#000000">The last type of objects that </font><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
can handle are </font><b><tt><font color="#3366FF">eoUpdater</font></tt></b><font color="#000000">
|
||||
objects. You should simply encapsulate in an </font><b><tt><font color="#3366FF">eoUpdater</font></tt></b><font color="#000000">
|
||||
anything you wish to do which does not fit into one of the above category.
|
||||
Note that their </font><b><tt><font color="#660000">operator() method</font></tt></b><font color="#000000">
|
||||
does not receive any argument.</font>
|
||||
<p><b><font color="#000099">Updater: </font><font color="#FF0000">Available
|
||||
instances</font></b>: A few updaters are available in the EO distribution:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoIncrementor</font></tt></b> A simple updater
|
||||
which maintains a <font color="#FF6600">counter</font> (an <b><tt><font color="#3366FF">eoValueParam</font></tt></b>
|
||||
that needs to be created beforehand, and passed in the constructor). It
|
||||
is incremented every time the <b><tt><font color="#660000">operator()</font></tt></b>
|
||||
method is called (every generation at the moment). You can of course also
|
||||
give an increment in the constructor (1 by default).</li>
|
||||
|
||||
<li>
|
||||
<a NAME="statesaver"></a><b><tt><font color="#3366FF">eoCountedStateSaver</font></tt></b>
|
||||
and <b><tt><font color="#3366FF">eoTimedStateSaver</font></tt></b> can
|
||||
be used to <font color="#FF6600">save</font> some existing <b><tt><font color="#3366FF">eoState</font></tt></b>
|
||||
(see <a href="#state">above</a>) to a file regularly, either based on the
|
||||
generation count (e.g. every 4 generations) or based on the clock (e.g.
|
||||
every 5 seconds).</li>
|
||||
</ul>
|
||||
<b><font color="#000099">Updater: </font><font color="#FF0000">Adding to
|
||||
the checkpoint</font></b>
|
||||
<br>A very simple example of using an <b><tt><font color="#3366FF">eoUpdater</font></tt></b>
|
||||
is given in the code for SecondBitEA: First <a href="SecondBitEA.html#param_declare">declare</a>
|
||||
an <b><tt><font color="#3366FF">eoValueParam</font></tt></b> object, then
|
||||
<a href="SecondBitEA.html#param_pass">use
|
||||
it to construct</a> an <b><tt><font color="#3366FF">eoIncrementor</font></tt></b>
|
||||
that you must <a href="SecondBitEA.html#updater_pass">add</a> to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>
|
||||
in order to activate its update. You can then use the parameter for your
|
||||
purpose, for instance as a first coordinate for a monitor.
|
||||
<br>Note also how to use the statesavers: first <a href="SecondBitEA.html#outstate_declare">declare</a>
|
||||
a state, then <a href="SecondBitEA.html#outstate_register">register</a>
|
||||
whatever you think necessary to that state, then <a href="SecondBitEA.html#statesaver_declare">pass</a>
|
||||
the state to some state-saver - and don't forget to <a href="SecondBitEA.html#statesaver_pass">add</a>
|
||||
the statesavers to the current <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Exercise 1:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">The code of </font><b><tt><font color="#660000"><font size=+1>SecondBitEA</font></font></tt></b><font color="#000000">
|
||||
display things in the current window in text format. Replace the </font><b><tt><font color="#3366FF">eoFileMonitor</font></tt></b><font color="#000000">
|
||||
by an </font><b><tt><font color="#3366FF">eoGnuplot1DMonitor</font></tt></b><font color="#000000">
|
||||
and watch the </font><b><font color="#FF6600">graphical output </font></b><font color="#000000">(</font><font color="#FF6600">Unix</font><font color="#000000">
|
||||
systems with </font><font color="#FF6600">gnuplot</font><font color="#000000">
|
||||
installed only, sorry).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Note that you must also replace the </font><b><tt><font color="#3366FF">eoSecondMomentStat</font></tt></b><font color="#000000">
|
||||
by an </font><b><tt><font color="#3366FF">eoAverageStat</font></tt></b><font color="#000000">,
|
||||
otherwise the standard deviations won't make any sense here.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Please try to understand why the average is always
|
||||
0 before taking a look at the solution (file <a href="NoWay.html">exercise1.cpp</a>).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Then run</font></li>
|
||||
|
||||
<br><b><tt><font color="#660000">
|
||||
exercise1 --vecSize=1000 --maxGen=1000</font></tt></b>
|
||||
<br><font color="#000000">to get a chance to see something happening before
|
||||
the program ends!</font></ul>
|
||||
|
||||
<hr WIDTH="100%"><b><font color="#000099"><font size=+2>Exercise 2:</font></font></b>
|
||||
<br><font color="#000000">Write the </font><b><tt><font color="#3366FF">eoDiversityStat</font></tt></b><font color="#000000">
|
||||
stat computation and test it. Thanks to send us the code!</font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Exercise 3:</font></font></b>
|
||||
<br><font color="#000000">Write the code for an </font><b><tt><font color="#3366FF">eoGnuplotSecondStatMonitor</font></tt></b><font color="#000000">
|
||||
that would display the </font><b><tt><font color="#3366FF">eoSecondMomentStat</font></tt></b><font color="#000000">
|
||||
(i.e. take into account the standard deviations and display them as error-bars.</font>
|
||||
<br><font color="#000000">Again, send us the code afterwards, thanks :-)</font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Lessons learned:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
Value of program parameters can be set <b><font color="#FF6600">at run-time</font></b>
|
||||
using the <b><tt><font color="#3366FF">eoParser</font></tt></b> class.</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF6600">Snapshots</font></b> of the algorithms can easily
|
||||
be <font color="#FF6600">saved</font> (and <font color="#FF6600">restored</font>)
|
||||
thanks to the <b><tt><font color="#3366FF">eoState</font></tt></b> class.</li>
|
||||
|
||||
<li>
|
||||
The <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b> mechanism
|
||||
let you <b><font color="#FF6600">do things every generation</font></b>
|
||||
without modifying existing algorithms, by simply writing the necessary
|
||||
code and encapsulating it into an object that <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>
|
||||
is aware of, that are at the moment the following:</li>
|
||||
|
||||
<li>
|
||||
computing <b><font color="#FF6600">statistics</font></b>, <b><font color="#FF6600">displaying
|
||||
</font></b>parameters
|
||||
(e.g. statistics), <b><font color="#FF6600">saving</font></b> the
|
||||
<b><tt><font color="#3366FF">(eo)State</font></tt></b>
|
||||
of the program.</li>
|
||||
</ul>
|
||||
In next lesson you will find out that many <a href="intro.html#adaptive">adaptive
|
||||
techniques</a> (the state-of-the-art in Evolutionary Computation) can easily
|
||||
be programmed through the <b><tt><font color="#3366FF">eoUpdater</font></tt></b>
|
||||
construct.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Lesson 2</a> -
|
||||
<a href="eoLesson4.html">Lesson
|
||||
4</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Hints</a>
|
||||
-<b> <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Fri Nov 3 18:49:12 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: None of your business!<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
940
deprecated/eo/tutorial/html/eoLesson4.html
Normal file
940
deprecated/eo/tutorial/html/eoLesson4.html
Normal file
|
|
@ -0,0 +1,940 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
|
||||
<title>Tutorial: Lesson 4</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson3.html">Lesson 3</a> -
|
||||
<a href="eoLesson5.html">Lesson
|
||||
5</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Hints</a>
|
||||
- <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#FF0000">User's guide:</font></b> <a href="#userguide">General</a>
|
||||
- <a href="#binary">Bitstring</a> - <a href="#real">Real</a> - <a href="#ES">ES</a>
|
||||
- <b><font color="#FF0000">Programmer's guide:</font></b> <a href="#programmerguide">General</a>
|
||||
- <a href="#memory">Memory management </a>- <a href="#parameter">Parameters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial Lesson 4: ready-to-use fully operational EA</font></h1></center>
|
||||
In this lesson, you will still use the same Evolutionary Algorithm. But
|
||||
this time you will have <b><font color="#FF6600">full control of all components</font></b>
|
||||
from the <b><font color="#FF6600">command-line or a parameter file</font></b>.<br>
|
||||
You can even use the algorithm decribed here <b><font color="#FF6600">without any other knowledge
|
||||
of EO</font></b>, just by writing your fitness function as a plain C++ function. <br><br>
|
||||
|
||||
<b><font color="#000099"><font size=+2>Contents</font></font></b><br>
|
||||
<ul>
|
||||
<li><b><font color="#FF0000">User's guide</font></b>
|
||||
<ul>
|
||||
<li> <a href="#userguide">Representation independent</a>,
|
||||
useful for <b><font color="#FF6600">all</font></b> applications</li>
|
||||
<li> <a href="#binary">BitEA, the binary version</a>, similar
|
||||
to previous lessons</li>
|
||||
<li> <a href="#real">RealEA, the basic real-valued version</a>,
|
||||
not efficient - see by yourself!</li>
|
||||
<li> <a href="#ES">RealEA, the self-adaptive Evolution Strategy</a>, best choice for continuous optimization in EO today (December 2004)</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><b><font color="#FF0000">Programmer's guide</font></b>:
|
||||
the ultimate purpose of this tutorial is to make you able to do
|
||||
your own experiments - and these these will likely fall outside the scope
|
||||
of the two ready-to-use programs above. You wil hence need to learn more about
|
||||
<ul>
|
||||
<li> <a href="#programmerguide">Building libraries</a> (in spite of the
|
||||
<a href="eoProgramming.html#templates">template problem</a>)</li>
|
||||
<li> <a href="#memory">Memory management</a>: it is radically
|
||||
different that in the 3 previous lessons - though relying
|
||||
of course on the same objects. Note that eoPersistent objects and eoParam
|
||||
objects are handled by different mechanisms.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="userguide"></a><b><font color="#000099"><font size=+2>User's
|
||||
guide</font></font></b>
|
||||
<p><font color="#000000">As already said, the behavior of the algorithms
|
||||
will be exactly the same as the previous one as far as optimization is
|
||||
concerned. Only now you will be able to tune every component of the algorithms
|
||||
(except the type of genotype) using run-time parameters.</font>
|
||||
<br><font color="#000000">Also, as in previous lessons, most of the code
|
||||
is representation-independent, i.e. is the same for both the binary genotypes
|
||||
and the real-valued genotypes. This small user's guide reflects that, but
|
||||
you can go directly to the <a href="#binary">binary</a> or the <a href="#real">real</a>
|
||||
parts if you wish.</font>
|
||||
<p><b><font color="#FF0000">Warning</font></b><font color="#000000">: this
|
||||
is a user guide, not a programming guide. In particular, the </font><font color="#FF6600">keywords</font><font color="#000000">
|
||||
of the parameters are </font><b><font color="#FF6600">not</font></b><font color="#000000">
|
||||
the </font><font color="#FF6600">names</font><font color="#000000"> of
|
||||
the underlying classes (though they should be similar in most cases).</font>
|
||||
<p><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">Parameter
|
||||
input</font></font></b><font color="#000000"> The way to input parameters
|
||||
has already be described in <a href="eoLesson3.html#paraminput">Lesson
|
||||
3</a>. To get a list of parameters, type the command with option --help
|
||||
(or -h): with both testBit and testReal this will result in</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">Printing the list of keywords on the standard output</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Creating (or overwriting) a file name testBit.status
|
||||
or testReal.status that contains the list of all recognized parameters
|
||||
and has the format of an input parameter file.</font></li>
|
||||
</ul>
|
||||
<b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">The
|
||||
status file</font></font></b>
|
||||
<br><font color="#000000">This file will always contain the list of the
|
||||
parameters that have been actually used by the last run of the program,
|
||||
however thay have been entered (try </font><b><tt><font color="#FF6666"><font size=+1>testBit
|
||||
-G1</font></font></tt></b><font color="#000000"> and take a look a the
|
||||
status file). The parameters that are commented out (a # character comments
|
||||
out the rest of the line) in the file are those that were not specified
|
||||
by the user.</font>
|
||||
<br><font color="#000000">On the status file, the parameters are organized
|
||||
in sections. Note, however, that this format is not mandatory in the param
|
||||
file, as </font><font color="#FF6600">only the keywords</font><font color="#000000">
|
||||
are processed.</font>
|
||||
<p><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">Representation-independent
|
||||
parameters</font></font></b>
|
||||
<br><font color="#000000">In what follows, the fixed font colored text
|
||||
is directly taken from the status file and is commented between the lines.
|
||||
The presentation follows the status file format - only two sections are
|
||||
representation-dependent (see the corresponding <a href="#binary">binary</a>
|
||||
or <a href="#real">real</a> sections). All other sections are presented
|
||||
now:</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<br><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#993300">######
|
||||
General ######</font></tt></font></b>
|
||||
<br><b><tt><font color="#993300"><font size=+1># --help=0 # -h : Prints
|
||||
this message</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter </font><font color="#000000">of
|
||||
absolutely no interest: tells whether or not help was requested.</font>
|
||||
<p><b><tt><font color="#993300"><font size=+1># --seed=988700289 # -S :
|
||||
Random number seed</font></font></tt></b>
|
||||
<br><font color="#FF0000">Unsigned long parameter:</font><font color="#000000">
|
||||
the seed for the <a href="eoProgramming.html#random">Random Number Generator</a>
|
||||
If the parameter is absent, then time(0) is used, which indicates the number
|
||||
of seconds since Jan. 1 1980, is used ... and stored in the status file,
|
||||
of course, so you can repeat the same run by simply assigning that value
|
||||
again. There is </font><font color="#FF0000">no default value ("true" random
|
||||
seed)</font><font color="#000000">.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#009900">######
|
||||
engine ######</font></tt></font></b>
|
||||
<br><font color="#000000">In this section, one chooses all components of
|
||||
the <a href="eoEngine.html">Evolution Engine</a> (selection, replacemenet
|
||||
and the like).</font>
|
||||
<p><b><tt><font color="#009900"><font size=+1># --popSize=20 # -P : Population
|
||||
Size</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
the size of the population (constant along evolution). And yes, this is
|
||||
a representation independent parameter, as the population is created either
|
||||
from a file or using an eoInit object - and only that object is representation-dependent.</font>
|
||||
<br><b><tt><font color="#009900"><font size=+1># --selection=DetTour(2)
|
||||
# -S : Selection: Roulette, DetTour(T), StochTour(t) or Sequential(ordered/unordered)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Name of <a href="eoEngine.html#selection">selection procedure.</a> Availabable
|
||||
are the </font><b><font color="#FF6600">roulette wheel</font></b><font color="#000000">
|
||||
(name </font><b><tt><font color="#009900"><font size=+1>Roulette</font></font></tt></b><font color="#000000">,
|
||||
fitness scaling coming soon); </font><b><font color="#FF6600">deterministic
|
||||
tournament</font></b><font color="#000000"> (name </font><b><tt><font color="#009900"><font size=+1>DetTour</font></font></tt></b><font color="#000000">
|
||||
with size - integer > 2 - in parentheses right after the name, use double
|
||||
quotes on the command line); </font><b><font color="#FF6600">stochastic
|
||||
tournament</font></b><font color="#000000"> (name </font><b><tt><font color="#009900"><font size=+1>StochTour</font></font></tt></b><font color="#000000">
|
||||
with probability - float in [0.5, 1] - in parentheses); </font><b><font color="#FF6600">sequential</font></b><font color="#000000">
|
||||
(name
|
||||
</font><b><tt><font color="#009900"><font size=+1>Sequential</font></font></tt></b><font color="#000000">,
|
||||
all individuals in turn), either from best to worst (option </font><b><tt><font color="#009900"><font size=+1>ordered</font></font></tt></b><font color="#000000">
|
||||
in parentheses), or in random ordered (option </font><b><tt><font color="#009900"><font size=+1>unordered</font></font></tt></b><font color="#000000">);
|
||||
and finally repeated </font><b><font color="#FF6600">independent uniform
|
||||
choices</font></b><font color="#000000"> (name </font><b><tt><font color="#009900"><font size=+1>Random</font></font></tt></b><font color="#000000">).
|
||||
Default is </font><font color="#FF0000">DetTour(2)</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#009900"><font size=+1># --nbOffspring=100% # -O
|
||||
: Nb of offspring (percentage or absolute)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer or real-valued parameter:</font><font color="#000000">
|
||||
this parameter indicates the </font><b><font color="#FF6600">amount of
|
||||
offspring</font></b><font color="#000000"> that will be generated from
|
||||
the genitors every generation. However, this amount can be specified either
|
||||
</font><font color="#FF6600">relative</font><font color="#000000">
|
||||
to the population size, and it should then end with percent character (%),
|
||||
or as an </font><font color="#FF6600">absolute</font><font color="#000000">
|
||||
integer number (without the percent char).</font>
|
||||
<br><font color="#000000">Indeed, you can either want, say 7 times more
|
||||
offspring than parents (a rather common situation in Evolution Strategies),
|
||||
in which case you give value 700% to </font><b><tt><font color="#009900"><font size=+1>nbOffspring</font></font></tt></b><font color="#000000">
|
||||
parameter; or you might want a single offspring whatever the population
|
||||
size, like in Steady-State evolution engines, in which case you simply
|
||||
enter value 1. </font><font color="#FF0000">Default is 100%</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#009900"><font size=+1># --replacement=Comma # -R
|
||||
: Replacement: Comma, Plus, EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Name of replacement procedure. Availabable are the </font><b><font color="#FF6600">ES
|
||||
plus and comma</font></b><font color="#000000"> deterministic replacement
|
||||
strategies (named respectively </font><b><tt><font color="#009900"><font size=+1>Plus</font></font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#009900"><font size=+1>Comma</font></font></tt></b><font color="#000000">);
|
||||
</font><b><font color="#FF6600">EP
|
||||
stochastic tournament</font></b><font color="#000000"> (name </font><b><tt><font color="#009900"><font size=+1>EPTour</font></font></tt></b><font color="#000000">
|
||||
with tournament size in parentheses); and the </font><b><font color="#FF6600">steady-state
|
||||
</font></b><font color="#000000">replacement
|
||||
procedures, at the moment only based on fitnesses, replacement being either
|
||||
</font><font color="#FF6600">deterministic</font><font color="#000000">
|
||||
(new born replace worst parent, name </font><b><tt><font color="#009900"><font size=+1>SSGAWorst</font></font></tt></b><font color="#000000">),
|
||||
or based on a tournament (name </font><b><tt><font color="#009900"><font size=+1>SSGADet</font></font></tt></b><font color="#000000">
|
||||
for deterministic tournament, size in parentheses, and </font><b><tt><font color="#009900"><font size=+1>SSGAStoch</font></font></tt></b><font color="#000000">
|
||||
for stochastic tournament, probability in parentheses). </font><font color="#FF0000">Default
|
||||
is Comma</font><font color="#000000"> (which btw is also SGA </font><font color="#FF0000">generational
|
||||
replacement</font><font color="#000000"> whenever there are as many offspring
|
||||
as parents).</font>
|
||||
<p><b><tt><font color="#009900"><font size=+1># --weakElitism=0 # -w :
|
||||
Old best parent replaces new worst offspring *if necessary*</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
if true, weak elitism is added to the replacement procedure (i.e. if the
|
||||
best fitness among the offspring is less than the best fitness, the best
|
||||
parent replaces the worst offspring). </font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Output ######</font></tt></font></b>
|
||||
<br><font color="#000000">This first section on Output contains parameters
|
||||
related to screen text output.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --useEval=1 # Use nb of
|
||||
eval. as counter (vs nb of gen.)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
whether or not you want the nb of evluations to be displayed and used as
|
||||
counter in statistics outputs and plots. </font><font color="#FF0000">Default
|
||||
is true</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --printBestStat=1 # Print
|
||||
Best/avg/stdev every gen.</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
toggles screen output of indicated statistics. </font><font color="#FF0000">Default
|
||||
is true</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --printPop=0 # Print sorted
|
||||
pop. every gen.</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
adds a dump of the whole population to the screen every generation. Is
|
||||
likely to generate </font><b><font color="#FF6600">huge</font></b><font color="#000000">
|
||||
output! </font><font color="#FF0000">Default is false.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --printFDC=1 # Print FDC
|
||||
coeff. every gen.</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
adds Fitness Distance Correlation to output every generation. </font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Output - Disk ######</font></tt></font></b>
|
||||
<br><font color="#000000">This second section on Output contains parameters
|
||||
related to DISK output.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --resDir=Res # Directory
|
||||
to store DISK outputs</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter: </font><font color="#000000">All
|
||||
</font><font color="#FF6600">DISK
|
||||
output</font><font color="#000000"> will be stored in a separate directory
|
||||
-this is its name. If the directory does not exist, it is created. Note
|
||||
that </font><font color="#FF6600">all graphical displays</font><font color="#000000">
|
||||
will use that directory for their temporary files. Also </font><font color="#FF6600">all
|
||||
job dump</font><font color="#000000"> (see section </font><b><font color="#3333FF">Persistence</font></b><font color="#000000">
|
||||
below) store their files there too.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --eraseDir=0 # erase files
|
||||
in dirName if any</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
in order not to mix up files from different runs, it is mandatory to ensure
|
||||
that the directory where all files will be stored is empty. However, if
|
||||
this parameter is not set and the directory already exists, an exception
|
||||
is thrown and the program stops. It it is set, </font><b><font color="#FF6600">all
|
||||
files in the result directory are erased</font></b><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --fileBestStat=0 # Output
|
||||
Best/avg/stdev to a file</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
if present, the best, average and standard deviation statistics are stored
|
||||
in file </font><b><tt><font color="#993300"><font size=+1>resDir/best.xg</font></font></tt></b><font color="#000000">.
|
||||
Each line contains the generation number, eventualy the evaluation count
|
||||
(depending on parameter </font><b><tt><font color="#3333FF"><font size=+1>useEval</font></font></tt></b><font color="#000000">
|
||||
then the statistics. </font><font color="#FF0000">Default is false.</font>
|
||||
<br>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Output - Graphical ######</font></tt></font></b>
|
||||
<br><font color="#000000">This last section on Output contains parameters
|
||||
related to graphical output (only available in Unix through gnuplot at
|
||||
the moment).</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --plotBestStat=0 # Plot
|
||||
Best/avg Stat</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
toggles gnuplot output of best and average plots (Linux only at the moment).
|
||||
</font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --plotFDCStat=0 # Plot
|
||||
FDC scatter plot</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
toggles the Fitness Distance Correlation plot (Fitness vs distance to best).
|
||||
</font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --plotHisto=0 # Plot histogram
|
||||
of fitnesses</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
if on, gnuplot is used to plot the sorted population (fitness vs rank).
|
||||
Gives a graphical idea of the diversity. </font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Persistence ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section contains parameters handling job
|
||||
dump and restart mechanism.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --Load= # -L : A save file
|
||||
to restart from</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
if present, the initial population (and the RNG) is read from indicated
|
||||
file. That file </font><b><font color="#FF0000">must</font></b><font color="#000000">
|
||||
come from a previous save (or must be in same format!), i.e. must contain
|
||||
a popualtion, the RNG and all parameters. If no other parameter is modified,
|
||||
using a previously saved population and RNG will give exactly the same
|
||||
results than having run that previous run longer. And a way to be sure
|
||||
to re-use the same parameters is to ... use that very save file as parameter
|
||||
file, as it contains all actual parameters in the right format.</font>
|
||||
<br><font color="#000000">Note that if not enough individuals are read,
|
||||
the remaining are randomly initialized. </font><font color="#FF0000">No
|
||||
default value</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --recomputeFitness=0 #
|
||||
-r : Recompute the fitness after re-loading the pop.?</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
in case some individuals are read from a file, their fitness is read too.
|
||||
If this one is true, it is nevertheless recomputed. </font><font color="#FF0000">Default
|
||||
is false</font><font color="#000000"> i.e. use fitnes that's in the file.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --saveFrequency=0 # Save
|
||||
every F generation (0 = only final state, absent = never)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
interval between two dump to disk of the whole population (+RNG + parameters),
|
||||
in a file named genNN.sav in the </font><b><tt><font color="#993300"><font size=+1>dirRes</font></font></tt></b><font color="#000000">
|
||||
directory, where NN is the generation number. If this prameter is present
|
||||
(even with 0 or negative value), the final population will always be saved,
|
||||
whatever the reason for stopping. Hence the only way to avoid all saves
|
||||
is to omit the parameter (there is </font><font color="#FF0000">no default
|
||||
value</font><font color="#000000">).</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --saveTimeInterval=0 #
|
||||
Save every T seconds (0 or absent = never)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
time interval between two population (+RNG + parameters) dumps to disks.
|
||||
Files are names timeNN.sav. See pervious parameter description for ore
|
||||
details. </font><font color="#FF0000">No default value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --status=t-eoGA.status
|
||||
# Status file</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
name of the status file (that contains all parameters in the input format).
|
||||
There is no way to avoid creating that file except recompiling ... or giving
|
||||
the name /dev/null (Unix). Default value is </font><font color="#FF0000">ProgramName.status</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Stopping criterion ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section allows to decide when the algorithm
|
||||
will stop.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --maxGen=100 # -G : Maximum
|
||||
number of generations (0 = none)</font></font></tt></b>
|
||||
<br><font color="#000000">Integer parameter: maximum number of generations.
|
||||
A value of 0 disables that stopping criterion. </font><font color="#FF0000">Default
|
||||
is 100.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --steadyGen=100 # -s :
|
||||
Number of generations with no improvement</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
stops whenever that number of generations is passed without any improvement
|
||||
of the best fitness in the population, provided the following minimum number
|
||||
of generations has been done. </font><font color="#FF0000">No default value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --minGen=0 # -g : Minimum
|
||||
number of generations</font></font></tt></b>
|
||||
<br><font color="#000000">Integer parameter: the above steadyGen parameter
|
||||
starts its job only after that minimum nuber of generations is passed.
|
||||
</font><font color="#FF0000">No
|
||||
default value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --maxEval=0 # -E : Maximum
|
||||
number of evaluations (0 = none)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
maximum number of generations.
|
||||
</font><font color="#FF0000">No default
|
||||
value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --targetFitness=0 # -T
|
||||
: Stop when fitness reaches</font></font></tt></b>
|
||||
<br><font color="#FF0000">Real-valued parameter:</font><font color="#000000">
|
||||
the algorithm stops whenever the best fitness reaches that target. </font><font color="#FF0000">No
|
||||
default value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --CtrlC=0 # -C : Terminate
|
||||
current generation upon Ctrl C</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
if true, Ctrl C only stops after the current generation as completed (eventually
|
||||
dumping population to a file if some saver is active). This very useful
|
||||
feature is only available in Unix at the moment. </font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<br>
|
||||
<hr ALIGN=LEFT SIZE=5 WIDTH="100%">
|
||||
<p><a NAME="binary"></a><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">Bistring
|
||||
specific parameters</font></font></b>
|
||||
<br>The following describes the specific parameters that are available
|
||||
in program BitEA to evolve genotypes that are <b><font color="#FF6600">bitstrings</font></b>.
|
||||
<br>The two representation-dependent sections are concerned repectively
|
||||
with genotype initilization and variation operators.
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Genotype Initialization ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section should allow input if all necessary
|
||||
parameters for genitype initialization</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --ChromSize=10 # -n : The
|
||||
length of the bitstrings</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
The bitstring initilization only requires the length of the chromosome.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Variation Operators ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section allows to tune the way the variation
|
||||
operators will be applied to the individuals (in the strict limit of SGA
|
||||
model at the moment, see below).</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --operator=SGA # -o : Description
|
||||
of the operator (SGA only now)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Describes the way the operators are applied. At the moment, </font><b><font color="#FF6600">only
|
||||
SGA</font></b><font color="#000000"> is available. SGA </font><b><font color="#FF6600">sequentially</font></b><font color="#000000">
|
||||
applies a (quadratic) crossover operator with probability </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
and a mutation operator with probability </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">.
|
||||
Both these operators can in turn be </font><b><font color="#FF6600">proportional
|
||||
combinations</font></b><font color="#000000"> of simple operators of the
|
||||
same arity.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pCross=0.6 # -C : Probability
|
||||
of Crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The probability that a given couple of selected genitors is applied the
|
||||
crossover operator. In SGA operator model, each couple of selected genitors
|
||||
is applied the crossover operator with that probability (and remains unchanged
|
||||
with probability </font><b><tt><font color="#CC33CC"><font size=+1>1-pCross</font></font></tt></b><font color="#000000">.
|
||||
Whenever a couple undergoes crossover, a choice is made upon available
|
||||
crossover operators </font><b><font color="#FF6600">proportionaly to their
|
||||
relative rates</font></b><font color="#000000"> (see below). </font><font color="#FF0000">Default
|
||||
is 0.6</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pMut=0.1 # -M : Probability
|
||||
of Mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The probability that a given individual (resulting from a crossover or
|
||||
a non-crossover operation, see above) is applied the mutation operator.
|
||||
Whenever an individual undergoes mutation, a choice is made upon available
|
||||
mutation operators </font><b><font color="#FF6600">proportionaly to their
|
||||
relative rates</font></b><font color="#000000"> (see below). </font><font color="#FF0000">Default
|
||||
is 0.1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --onePointRate=1 # -1 :
|
||||
Relative rate for one point crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the 1-point crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to 2-point and uniform below (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). </font><font color="#FF0000">Default is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --twoPointRate=1 # -2 :
|
||||
Relative rate for two point crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the 2-point crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to 1-point above and uniform below (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). </font><font color="#FF0000">Default is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --uRate=2 # -U : Relative
|
||||
rate for uniform crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the 1-point crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to 1- and 2-point above (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). </font><font color="#FF0000">Default is 2</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pMutPerBit=0.01 # -b
|
||||
: Probability of flipping 1 bit in bit-flip mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
When </font><b><tt><font color="#CC33CC"><font size=+1>bit-flip mutation</font></font></tt></b><font color="#000000">
|
||||
is applied, each bit is flipped independently with probability </font><b><tt><font color="#CC33CC"><font size=+1>pMutPerBit</font></font></tt></b><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --bitFlipRate=0.01 # -s
|
||||
: Relative rate for bit-flip mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the bit-flip mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to one-Bit mutation below (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). </font><font color="#FF0000">Default is 0.01</font><font color="#000000">
|
||||
(if all relative rates are equal, the choice is uniform among available
|
||||
operators).</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --oneBitRate=0.01 # -d
|
||||
: Relative rate for deterministic bit-flip mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the one-bit mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to bit-flip mutation below (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). One-bit mutation flips one and only one bit, uniformly chosen in
|
||||
the individual. </font><font color="#FF0000">Default is 0.01</font><font color="#000000">
|
||||
(if all relative rates are equal, the choice is uniform among available
|
||||
operators).</font>
|
||||
<br>
|
||||
<p>
|
||||
<hr ALIGN=LEFT SIZE=5 WIDTH="100%">
|
||||
<p><a NAME="real"></a><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">Real-valued
|
||||
specific parameters</font></font></b>
|
||||
<br>
|
||||
To run your own real-valued application, write your fitness function
|
||||
(see <b><tt><font color="#993300" size=+1>real_value.h</font></font></tt></b>),
|
||||
recompile, and run from the command line <br>
|
||||
<center><b><tt><font color="#993300" size=+1>RealEA @RealEA.param</font></tt></b></center><br>
|
||||
in order to use sensible parameters! (see <a href="eoLesson3.html#paraminput">Lesson 3</a>
|
||||
for details on the parameter file).
|
||||
But remember that <a href="#ES">Self-adaptive ES</a> will work much better!
|
||||
<br><br>
|
||||
The following describes the specific parameters that are available
|
||||
in programs <b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b>
|
||||
and <b><tt><font color="#993300"><font size=+1>ESEA</font></font></tt></b>
|
||||
to evolve genotypes that are <b><font color="#FF6600">vector<double></font></b>.
|
||||
<br><b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b>
|
||||
implements what can be called a "real-coded GA", where everything is identical
|
||||
to the bitstring case above (except initialization and operators that are
|
||||
specific to vector<double> of course) and <b><tt><font color="#993300"><font size=+1>ESEA</font></font></tt></b>
|
||||
implements the full Evolution-Strategy self-adaptive mutation mechanism
|
||||
- together with specific ES crossover operators. The initialization section
|
||||
for both programs are identical, but the operator sections are totally
|
||||
different. See <a href="#ES">next paragraph</a> for a description of ES
|
||||
specific parameters.
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Genotype Initialization ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section should allow input if all necessary
|
||||
parameters for genitype initialization</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --vecSize=10 # -n : The
|
||||
number of variables</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
The initilization requires the length of the vector<double>.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --initBounds=10[-1,1] #
|
||||
-B : Bounds for uniform initialization</font></font></tt></b>
|
||||
<br><font color="#FF0000">Bounds parameter:</font><font color="#000000">
|
||||
Bounds for uniform initialization of the real variables. The syntax for
|
||||
this parameter given in the </font><b><tt><font color="#CC33CC"><font size=+1>objectBounds</font></font></tt></b><font color="#000000">
|
||||
parameter description below. This argument is mandatory, furthermore the
|
||||
given bounds </font><b><font color="#FF6600">must be bounded</font></b><font color="#000000">.
|
||||
</font><font color="#FF0000">The
|
||||
default is [-1,1]</font><font color="#000000"> for all variables.</font>
|
||||
<br>Note that this parameter is independent of the <b><tt><font color="#CC33CC"><font size=+1>objectBounds</font></font></tt></b>
|
||||
parameter below.
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --sigmaInit=0.3 # -s :
|
||||
Initial value for Sigma(s)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The initial value for all standard-deviation mutation strategy parameters.
|
||||
Useless when no self-adaptive mutation mechanism is used.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Variation Operators ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section allows to tune the way the variation
|
||||
operators will be applied to the individuals (in the strict limit of SGA
|
||||
model at the moment, see below).</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --objectBounds=10[-inf,+inf]
|
||||
# -B : Bounds for variables</font></font></tt></b>
|
||||
<br><font color="#FF0000">Bounds parameter:</font><font color="#000000">
|
||||
Bounds for object variables. The syntax for this parameter is a succession
|
||||
of (optionally semi-colon separated) items of the form </font><b><tt><font color="#993300"><font size=+1>N[min,Max]</font></font></tt></b><font color="#000000">where
|
||||
the optional integer </font><b><tt><font color="#993300"><font size=+1>N</font></font></tt></b><font color="#000000">
|
||||
indicates how many variables have the given bounds. </font><b><tt><font color="#993300"><font size=+1>min</font></font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#993300"><font size=+1>Max</font></font></tt></b><font color="#000000">
|
||||
are either floating point numbers, or </font><b><tt><font color="#993300"><font size=+1>-inf</font></font></tt></b><font color="#000000">
|
||||
(resp. </font><b><tt><font color="#993300"><font size=+1>+inf</font></font></tt></b><font color="#000000">)
|
||||
to indicate unbounded direction. If not enough bounds are provided, the
|
||||
remaining variables will have the same bounds as the last bounds given.</font>
|
||||
<br><font color="#000000">This argument is mandatory, and
|
||||
</font><font color="#FF0000">default
|
||||
is [-inf,+inf]</font><font color="#000000">, i.e. unbounded variables.</font>
|
||||
<p><b><font color="#FF0000">Examples</font></b><font color="#000000">:
|
||||
</font><b><tt><font color="#CC33CC"><font size=+1>10[-1,1]</font></font></tt></b><font color="#000000">is
|
||||
equivalent to simply </font><b><tt><font color="#CC33CC"><font size=+1>[-1,1]</font></font></tt></b><font color="#000000">
|
||||
or to the extended </font><b><tt><font color="#CC33CC"><font size=+1>[-1,1][-1,1][-1,1][-1,1][-1,1][-1,1][-1,1][-1,1][-1,1][-1,1]</font></font></tt></b><font color="#000000">.</font>
|
||||
<br><font color="#000000">And </font><b><tt><font color="#CC33CC"><font size=+1>[-1,1];2[0,1];[-inf,10]</font></font></tt></b>results
|
||||
in the first variable staying in [-1,1], the second and the third in [0,1]
|
||||
and all remaining variables below 10.
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --operator=SGA # -o : Description
|
||||
of the operator (SGA only now)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Describes the way the operators are applied. At the moment, </font><b><font color="#FF6600">only
|
||||
SGA</font></b><font color="#000000"> is available. SGA </font><b><font color="#FF6600">sequentially</font></b><font color="#000000">
|
||||
applies a (quadratic) crossover operator with probability </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
and a mutation operator with probability </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">.
|
||||
Both these operators can in turn be </font><b><font color="#FF6600">proportional
|
||||
combinations</font></b><font color="#000000"> of simple operators of the
|
||||
same arity.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pCross=0.6 # -C : Probability
|
||||
of Crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The probability that a given couple of selected genitors is applied the
|
||||
crossover operator. In SGA operator model, each couple of selected genitors
|
||||
is applied the crossover operator with that probability (and remains unchanged
|
||||
with probability </font><b><tt><font color="#CC33CC"><font size=+1>1-pCross</font></font></tt></b><font color="#000000">.
|
||||
Whenever a couple undergoes crossover, a choice is made upon available
|
||||
crossover operators </font><b><font color="#FF6600">proportionaly to their
|
||||
relative rates</font></b><font color="#000000"> (see below). </font><font color="#FF0000">Default
|
||||
is 0.6</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pMut=0.1 # -M : Probability
|
||||
of Mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The probability that a given individual (resulting from a crossover or
|
||||
a non-crossover operation, see above) is applied the mutation operator.
|
||||
Whenever an individual undergoes mutation, a choice is made upon available
|
||||
mutation operators </font><b><font color="#FF6600">proportionaly to their
|
||||
relative rates</font></b><font color="#000000"> (see below). </font><font color="#FF0000">Default
|
||||
is 0.1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --alpha=0 # -a : bound
|
||||
for combination factor in real crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Bound for the choices of linear combination factors in both crossover belows
|
||||
(similar to BLX-alpha notation). </font><font color="#FF0000">Default is
|
||||
0</font><font color="#000000"> (i.e. combination factor are chosen in [0,1]).</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --segmentRate=1 # -s :
|
||||
Relative rate for segment crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of application of the segment crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to hypercube and uniform crossovers (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). Segment crossover generates offspring uniformly on the segment
|
||||
joining both parents, i.e. constructs two linear combinations of the parents
|
||||
with a random number uniformly drawn in [</font><b><tt><font color="#CC33CC"><font size=+1>alpha</font></font></tt></b><font color="#000000">,1+</font><b><tt><font color="#CC33CC"><font size=+1>alpha</font></font></tt></b><font color="#000000">].
|
||||
</font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --hypercubeRate=1 # -A
|
||||
: Relative rate for hypercube crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of application of the hypercube crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to segment and uniform crossovers (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). Hypercube crossover generates offspring uniformly on the hypercube
|
||||
whose diagonal is the segment joining both parents, i.e. by doing linear
|
||||
combinations of each variable independently (a random number in [</font><b><tt><font color="#CC33CC"><font size=+1>alpha</font></font></tt></b><font color="#000000">,1+</font><b><tt><font color="#CC33CC"><font size=+1>alpha</font></font></tt></b><font color="#000000">]
|
||||
is drawn anew for each variable). </font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --uxoverRate=1 # -A : Relative
|
||||
rate for uniform crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of application of the segment crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to hypercube and segment crossovers (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). Uniform crossover simply exchanges values of variables, i.e.
|
||||
uniformly picks up two other summits of the hypercube defined by the parents.
|
||||
</font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --epsilon=0.01 # -e : Half-size
|
||||
of interval for Uniform Mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The uniform and deterministic-uniform mutations will choose values of variable
|
||||
X uniformly in </font><b><tt><font size=+1><font color="#993300">[X-</font><font color="#CC33CC">epsilon</font><font color="#993300">,
|
||||
X+</font><font color="#CC33CC">epsilon</font><font color="#993300">]</font></font></tt></b><font color="#000000">.
|
||||
</font><font color="#FF0000">Default
|
||||
is 0.01</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --uniformMutRate=1 # -u
|
||||
: Relative rate for uniform mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the uniform mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to determinitic uniform and the normal mutations (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). Uniform mutation modifies all variables by choosing new values
|
||||
uniformly on an interval centered on the old value of width </font><b><tt><font size=+1><font color="#993300">2*</font><font color="#CC33CC">epsilon</font></font></tt></b><font color="#000000">
|
||||
(see above). </font><font color="#FF0000">Default is1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --detMutRate=1 # -d : Relative
|
||||
rate for deterministic uniform mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the determinisitc-uniform mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to uniform and normal mutations (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). Deterministic-uniform mutation modifies one single variable uniformly
|
||||
based on epsilon </font><b><tt><font color="#CC33CC"><font size=+1>epsilon</font></font></tt></b><font color="#000000">.
|
||||
</font><font color="#FF0000">Default
|
||||
is1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --normalMutRate=1 # -d
|
||||
: Relative rate for Gaussian mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the normal mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to two uniform mutations above (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). </font><font color="#FF0000">Default is1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --sigma=0.3 # -s : Sigma
|
||||
(fixed) for Gaussian mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The value of standard deviation for Gaussian mutation - fixed along evolution
|
||||
(see the Evolution Strategy program below for self-adaptive mutations).</font>
|
||||
<p>
|
||||
<hr ALIGN=LEFT SIZE=5 WIDTH="100%">
|
||||
<p><a NAME="ES"></a><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">ES
|
||||
with self-adative mutation parameters</font></font></b>
|
||||
<br>
|
||||
To run your own SA-ES application, write your fitness function
|
||||
(see <b><tt><font color="#993300" size=+1>real_value.h</font></font></tt></b>),
|
||||
recompile, and run from the command line <br>
|
||||
<center><b><tt><font color="#993300" size=+1>ESEA @ESEA.param</font></tt></b></center><br>
|
||||
in order to use sensible parameters! (see <a href="eoLesson3.html#paraminput">Lesson 3</a>
|
||||
for details on the parameter file).
|
||||
<br><br>
|
||||
The following describes the specific parameters for program <b><tt><font color="#993300"><font size=+1>ESEA</font></font></tt></b>,
|
||||
that implements the full Evolution-Strategy self-adaptive mutation mechanism
|
||||
- together with specific ES crossover operators. The initialization section
|
||||
is the same as the one for plain vector<double> above, so only the opeartor
|
||||
sections will be described here. A new section is now concerned with deciding
|
||||
what kind of self-adaptive mutation strategy will be applied - it has been
|
||||
separated from the other variation operators because it has consequences
|
||||
on the choice of the genotype.
|
||||
<br><b><font color="#FF6600">Warning</font></b>: if you choose not to use
|
||||
any self-adaptive mechanism (i.e. setting all parameters of this section
|
||||
to false) you end up with ... an algorithm that is identical to <b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b>
|
||||
above (try it and take alook at the status file).
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
ES mutation ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section allows to decide which type of self-adaptive
|
||||
mutation will be used. There are three available types: isotropic mutation,
|
||||
using one standard deviation for each individual, that will be applied
|
||||
to all variables; anisotropic mutation, where each individual carries as
|
||||
many standard deviations as it has variables; and correlated mutation where
|
||||
each individuals has its own full correlation matrix.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --Isotropic=1 # -i : Isotropic
|
||||
self-adaptive mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
If true, at least one self-adaptive parameter will be used for each individual.
|
||||
</font><font color="#FF0000">Default
|
||||
is true</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --Stdev=0 # -s : One self-adaptive
|
||||
stDev per variable</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
If true, at least one self-adaptive parameter per variable will be used
|
||||
for each individual. </font><font color="#FF0000">Default is false</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --Correl=0 # -c : Use correlated
|
||||
mutations</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
If true, full correalted self-adaptive mutation will be used for each individual.
|
||||
</font><font color="#FF0000">Default
|
||||
is false</font><font color="#000000">.</font>
|
||||
<p><b><font color="#FF6600">Note</font></b><font color="#000000">: The
|
||||
default values result in an isotropic self-adaptive mutation to be chosen.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Variation Operators ######</font></tt></font></b>
|
||||
<br><font color="#000000">Only the parameters that are specific to ESEA
|
||||
are presented here - the </font><b><tt><font color="#CC33CC"><font size=+1>objectBounds,operator,pCross</font></font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
are exactly the same as for </font><b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b><font color="#000000">
|
||||
above.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --crossType=global # -C
|
||||
: Type of ES recombination (global or standard)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Es crossover can involve only two parents - and it is then identical to
|
||||
the </font><b><tt><font color="#CC33CC"><font size=+1>standard</font></font></tt></b><font color="#000000">
|
||||
hypercube crossover describe for the </font><b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b><font color="#000000">
|
||||
parameters above. But new parents can also be chosen anew for each variable
|
||||
before doing the crossover for that variable - and this is called </font><b><tt><font color="#CC33CC"><font size=+1>global</font></font></tt></b><font color="#000000">
|
||||
recombination.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --crossObj=discrete # -O
|
||||
: Recombination of object variables (discrete or intermediate)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
There are two possible crossovers in plain ES. The </font><b><tt><font color="#CC33CC"><font size=+1>discrete</font></font></tt></b><font color="#000000">
|
||||
crossover simpy exchanges variables among the parents. It is similar to
|
||||
the plain uniform crossover for real variables. The crossover performs
|
||||
a linear combination of parents;variables - it si similar to the hypercube
|
||||
crossover described for with alpah parameter set to 0. This parameter
|
||||
allso to choose the type of crossover that will be applied to the </font><b><font color="#FF6600">object
|
||||
variables</font></b><font color="#000000"> (i.e. the origianl variables
|
||||
of the problem). </font><font color="#FF0000">Default is discrete.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --crossStdev=intermediate
|
||||
# -S : Recombination of mutation strategy parameters (intermediate or discrete)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
This parameter allows to choose the type of crossover (see above) that
|
||||
will be applied to the </font><b><font color="#FF6600">mutation strategy
|
||||
parameters</font></b><font color="#000000"> that are part of the genotype.
|
||||
</font><font color="#FF0000">Default
|
||||
is intermediate.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --TauLoc=1 # -l : Local
|
||||
Tau (before normalization)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The local factor for the mutation of the mutation strategy parameters (the
|
||||
only one used when a single standard deviation is used). </font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --TauGlob=1 # -g : Global
|
||||
Tau (before normalization)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The global factor for the mutation of the mutation strategy parameters
|
||||
(only useful when more than one standard deviation are used). </font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --Beta=0.0873 # -b : Beta</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The factor for the mutation of the rotation angles in the case of the full
|
||||
correlated mutation. </font><font color="#FF0000">Default is 0.0873</font><font color="#000000">
|
||||
(following Schwefel).</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="100%">
|
||||
<br><a NAME="programmerguide"></a><b><font color="#000099"><font size=+2>Programmer's
|
||||
guide</font></font></b>
|
||||
<p>At the moment, you will have to browse in the source (colored!) code
|
||||
(<a href="BitEA.html">Bit</a> - Real) almost by yourself, sorry.
|
||||
<p>Note that the main file is now very slim, as it only contains calls
|
||||
to some <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
functions - these functions contain the actual code, very similar to the
|
||||
code of Lesson3, except for the memory management, performed through an
|
||||
<b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_state.html">eoState</a></font></font></tt></b>
|
||||
object (notice that all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
calls have an eoState as second parameter).
|
||||
<p><b><font color="#000099"><font size=+2>Programmer's guide: </font></font><font color="#FF0000"><font size=+1>The
|
||||
make_xxx files</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>: all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
files have as first two parameters an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_parser.html">eoParser</a></font></font></tt></b>
|
||||
and an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_state.html">eoState</a></font></font></tt></b>.
|
||||
The <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>
|
||||
is be used within all functions to parse the command-line and/or a parameter
|
||||
file in order to read any relevant user-parameter, while the <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>
|
||||
is used here to store all pointers to be allocated inside the function
|
||||
(see <a href="eoProgramming.html#memory">Programming hints</a> for more
|
||||
detailed explanations).
|
||||
<p>There are 2 types of <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
files: the ones that do depend on representation, defining the <b><font color="#FF9900">genotype
|
||||
</font></b>and
|
||||
<b><font color="#CC33CC">initialization</font></b>
|
||||
(<b><tt><font color="#CC33CC"><font size=+1>make_genotype_xxx</font></font></tt></b>,
|
||||
with xxx being the type of genotype) and variation operators (<b><tt><font color="#CC33CC"><font size=+1>make_op_xxx</font></font></tt></b>),
|
||||
and the one that are truly representation-independent (<b><tt><font color="#993300"><font size=+1>make_pop,
|
||||
make_continue, make _checkpoint, make_algo </font></font></tt></b><font color="#000000">and</font><b><tt><font color="#993300"><font size=+1>
|
||||
make_run</font></font></tt></b>).
|
||||
<br>The former are located in the directory corresponding to the actual
|
||||
genotype (<b><tt><font color="#FF9900"><font size=+1>src/ga</font></font></tt></b>
|
||||
for eoBit, <b><tt><font color="#FF9900"><font size=+1>src/es</font></font></tt></b>
|
||||
for eoReal and all eoESxxx genotypes). The latter are in the directory
|
||||
<b><tt><font color="#993300"><font size=+1>src/do.</font></font></tt></b>
|
||||
<p>If you take a close look at the code of <b><tt><font color="#993300"><font size=+1><a href="../../src/do/make_continue.h">make_continue</a></font></font></tt></b>
|
||||
for instance, you will first notice that ... the function declared there
|
||||
is called <b><tt><font color="#993300"><font size=+1>do_make_continue</font></font></tt></b>
|
||||
and is not <a href="BitEA.html#continue">the one you are calling</a> in
|
||||
the main file, though it has the same parameters as arguments.
|
||||
<br>The explanation lies within the file <b><tt><font color="#FF9900"><font size=+1>make_continue_xxx.cpp</font></font></tt></b>
|
||||
(with xxx = ga or real/es)which, as its color (and name) should have
|
||||
told you about, are representation-dependent: in fact the <b><tt><font color="#FF9900"><font size=+1>make_continue_xxx.cpp</font></font></tt></b>
|
||||
files only instanciates the general <EOT> template into one of the possible
|
||||
template for eoBit or eoReal/eoES - and this trick allows to <b><font color="#FF6600">compile
|
||||
them separately</font></b>!
|
||||
<p>The other thing that you should notice is that the code there is very
|
||||
similar to the code that was in Lesson 3, regarding parameter reading
|
||||
and type of object that are allocated - except for memory management. This
|
||||
goes for all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
files - so the only thing you need to understand how it goes is to look
|
||||
at the <a href="#memory">memory management section</a>.
|
||||
<p><b><font color="#FF0000">Pros</font></b>: you don't have to handle a
|
||||
huge main function - and many of the make_xxx files can be directly used
|
||||
in different applications (this is called <b><font color="#FF6600">modularity</font></b>
|
||||
:-)))
|
||||
<br>More interesting, you can even <b><font color="#FF6600">compile</font></b>
|
||||
the <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
files <b><font color="#FF6600">separately</font></b> for a given target
|
||||
template, and link them e.g. with your fitness function when it is ready
|
||||
(remember that up to now you needed to compile everything altogether by
|
||||
including the code into your mail fine). Indeed, if you do a global make,
|
||||
you will notice that there are additional libraries compiled in <b><tt><font color="#FF9900"><font size=+1>src/ga</font></font></tt></b>
|
||||
and <b><tt><font color="#FF9900"><font size=+1>src/es</font></font></tt></b>
|
||||
...
|
||||
<p><b><font color="#FF0000">Cons</font></b>: It makes the code a little
|
||||
more complex to understand, first because of the indirection needed for
|
||||
pre-compilation with a given template, and second because of the memory
|
||||
management that this imposes.
|
||||
<br>
|
||||
<br>
|
||||
<p><a NAME="memory"></a><b><font color="#000099"><font size=+2>Programmer's
|
||||
guide: </font></font><font color="#FF0000"><font size=+1>Memory management</font></font></b>
|
||||
<br>As already said, all functions have an <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>
|
||||
as second argument - and that object is used to store the functor objects
|
||||
that were simply declared as variables of the main function up to now :
|
||||
see <a href="eoProgramming.html#memory">Programming hints</a> for more
|
||||
detailed explanations and take a look at the code of <b><tt><font color="#993300"><font size=+1><a href="../../src/do/make_continue.h">make_continue</a></font></font></tt></b>
|
||||
for instance, you will see the implementation of the memory management
|
||||
in action.
|
||||
<p><a NAME="parameter"></a><b><font color="#000099"><font size=+2>Programmer's
|
||||
guide: </font></font><font color="#FF0000"><font size=+1>Memory management
|
||||
of eoParam objects</font></font></b>
|
||||
<p>It has been seen in Lesson 3 that parameters could be read from command-line
|
||||
and/or a parameter file using an <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>
|
||||
object. However, the memory mangement problem also concerns EO parameter
|
||||
objects (<b><tt><font color="#3366FF"><font size=+1>eoParam</font></font></tt></b>):
|
||||
the way there are read in <a href="eoLesson3.html#parameters">Lesson3</a>
|
||||
makes them local variables of the function they are defined in.
|
||||
<br>It is however possible to ask the <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>
|
||||
to hold them, as done for instance in eoContinue for the maximum number
|
||||
of generations. Local declaration would amount to something like :
|
||||
<p><b><tt><font color="#3366FF"><font size=+1>eoValueParam<unsigned
|
||||
int>& maxGenParam(100, "maxGen", "Maximum number of generations ()
|
||||
= none)",'G');</font></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"><font size=+1> parser.processParam(
|
||||
maxGenParam, "Stopping criterion" );</font></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"><font size=+1> unsigned maxGen =
|
||||
maxGenParam.value();</font></font></tt></b>
|
||||
<p>while if you want the parser to hold those eoParam objects, you will
|
||||
write something like
|
||||
<p><b><tt><font color="#3366FF"><font size=+1>eoValueParam<unsigned>&
|
||||
maxGenParam = _parser.createParam(unsigned(100), "maxGen", "Maximum number
|
||||
of generations () = none)",'G',"Stopping criterion");</font></font></tt></b>
|
||||
<p>and then use <b><tt><font color="#3366FF"><font size=+1>maxGenParam.value()</font></font></tt></b>
|
||||
to get the value enterred by the user. In that case, you get a <b><font color="#FF6600">reference</font></b>
|
||||
to an eoParam object that is hold by the eoParser - and deleted whith it.
|
||||
<br>Note that there are <b><font color="#FF6600">two important differences</font></b>
|
||||
between the arguments of the constructor of an eoParam object and the method
|
||||
createParam of an eoParser object: first, you need to provide the additional
|
||||
section parameter (used only when outputting the eoParser); second you
|
||||
<b><font color="#FF6600">must</font></b>
|
||||
make sure that the first argument is of the correct type otherwise the
|
||||
compiler will complain.
|
||||
<p>Note that if you don't later need the eoParam, but simply its value,
|
||||
you can even diretly write
|
||||
<p><b><tt><font color="#3366FF"><font size=+1>unsigned maxGen = _parser.createParam(unsigned(100),
|
||||
"maxGen", "Maximum number of generations () = none)",'G',"Stopping criterion").value();</font></font></tt></b>
|
||||
<p><b><font color="#FF0000"><font size=+1>Getting parameter values in different
|
||||
functions:</font></font></b>
|
||||
<p>It is often useful (though probably <b><font color="#FF6600">very bad
|
||||
programming style </font></b>:-))) to be able to get the value of a user-defined
|
||||
parameter in two different places of the code without passing it around
|
||||
through many levels of call. You can then use the alternate function <b><tt><font color="#3366FF"><font size=+1>getORcreateParam</font></font></tt></b>
|
||||
with exactly the same syntax than <b><tt><font color="#3366FF"><font size=+1>createParam</font></font></tt></b>.
|
||||
<br>Be careful that the link between both parameters is made through their
|
||||
longmanes (second argument), and that you must so <b><font color="#FF6600">hard-code</font></b>
|
||||
that name in two different places with of course exactly the same spelling!!!
|
||||
<br><b><font color="#FF6600">Examples</font></b> can be found for instance
|
||||
in the make_genotype_xxx files, for the sizes of the genotypes: it is often
|
||||
the case that the definition of the optimization problem requires (or computes)
|
||||
such size. The idea is then that you either read or compute that size,
|
||||
then create a (dummy) parameter with the name that is used later in the
|
||||
make_genotype file. For instance, for bitstrings, the make_genotype_ga.h
|
||||
contains the following line defining the size of the bitstring
|
||||
<p><b><tt><font color="#3366FF"><font size=+1> unsigned theSize =
|
||||
_parser.getORcreateParam(unsigned(10), "chromSize", "The length of the
|
||||
bitstrings", 'n',"Problem").value();</font></font></tt></b>
|
||||
<p>If you want to define that size earlier, you should write somewhere
|
||||
before
|
||||
<br>
|
||||
<p><b><tt><font color="#3366FF"><font size=+1> unsigned requiredSize
|
||||
= ... ;</font></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"><font size=+1> _parser.createParam(requiredSize,
|
||||
"chromSize", "The length of the bitstrings", 'n',"Problem");</font></font></tt></b>
|
||||
<p>Of course, if that size is mandatory, you should NOT modify it at run-time
|
||||
by entering anther value !
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">User's guide:</font></b> <a href="#userguide">General</a>
|
||||
- <a href="#binary">Bitstring</a> - <a href="#real">Real</a> - <a href="#ES">ES</a>
|
||||
- <b><font color="#FF0000">Programmer's guide:</font></b> <a href="#programmerguide">General</a>
|
||||
- <a href="#memory">Memory management </a>- <a href="#parameter">Parameters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%"><font color="#000000"><a href="eoLesson3.html">Lesson
|
||||
3</a> -
|
||||
<a href="eoLesson5.html">Lesson 5</a> -
|
||||
<a href="eoTutorial.html">Main
|
||||
page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Hints</a> -<b> <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b></font>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<font color="#000000"><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></font></address>
|
||||
|
||||
<br><!-- Created: Tue May 1 14:49:12 CET 2001 --><!-- hhmts start --><font color="#000000">Last
|
||||
modified: None of your business!</font><!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue