Migration from SVN
This commit is contained in:
parent
d7d6c3a217
commit
8cd56f37db
29069 changed files with 0 additions and 4096888 deletions
45
eo/tutorial/Templates/CMakeLists.txt.src-tmpl
Executable file
45
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
eo/tutorial/Templates/CMakeLists.txt.top-tmpl
Executable file
40
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
eo/tutorial/Templates/ChangeLog
Normal file
48
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
eo/tutorial/Templates/EO.tpl
Normal file
938
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
eo/tutorial/Templates/Makefile.am.src-tmpl
Normal file
16
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
eo/tutorial/Templates/Makefile.am.top-tmpl
Normal file
8
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
eo/tutorial/Templates/MyStructEA.cpp
Normal file
188
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
eo/tutorial/Templates/MyStructLibEA.cpp
Normal file
162
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
eo/tutorial/Templates/MyStructSEA.cpp
Normal file
350
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
eo/tutorial/Templates/README
Normal file
34
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
eo/tutorial/Templates/README.manual
Normal file
143
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
eo/tutorial/Templates/README.tmpl
Normal file
21
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
eo/tutorial/Templates/binCrossover.tmpl
Normal file
70
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
eo/tutorial/Templates/configure.ac.tmpl
Normal file
39
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
eo/tutorial/Templates/continue.tmpl
Normal file
64
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
eo/tutorial/Templates/createEOproject.sh
Executable file
116
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
eo/tutorial/Templates/eoMyStruct.tmpl
Normal file
117
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
eo/tutorial/Templates/evalFunc.tmpl
Normal file
65
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
eo/tutorial/Templates/init.tmpl
Normal file
57
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
|
||||
76
eo/tutorial/Templates/lessOffspringSameSelectorGenOp.tmpl
Normal file
76
eo/tutorial/Templates/lessOffspringSameSelectorGenOp.tmpl
Normal file
|
|
@ -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
eo/tutorial/Templates/make_MyStruct.cpp
Normal file
128
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
eo/tutorial/Templates/make_genotype_MyStruct.h
Normal file
73
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
eo/tutorial/Templates/make_op_MyStruct.h
Normal file
210
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
eo/tutorial/Templates/moreOffspringGenOp.tmpl
Normal file
77
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
eo/tutorial/Templates/mutation.tmpl
Normal file
68
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
eo/tutorial/Templates/quadCrossover.tmpl
Normal file
71
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
eo/tutorial/Templates/stat.tmpl
Normal file
63
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue