From f0813c55cac3dfb1c33f100cf26a02011cc43273 Mon Sep 17 00:00:00 2001 From: evomarc Date: Thu, 5 Apr 2001 16:47:54 +0000 Subject: [PATCH] Added the continue.tmpl template - and modified the html pages accordingly (though eoCheckPoint.html is still a long way to complete). Added some comments in all template files - and replaced the protected by private (don't remember why these were protected!!!). --- eo/tutorial/Templates/binCrossover.tmpl | 11 ++++- eo/tutorial/Templates/continue.tmpl | 46 +++++++++++++++++++ .../lessOffspringExternalSelectorGenOp.tmpl | 11 ++++- .../lessOffspringSameSelectorGenOp.tmpl | 11 ++++- eo/tutorial/Templates/moreOffspringGenOp.tmpl | 11 ++++- eo/tutorial/Templates/mutation.tmpl | 11 ++++- eo/tutorial/Templates/quadCrossover.tmpl | 11 ++++- eo/tutorial/html/eoBottomUp.html | 2 +- eo/tutorial/html/eoCheckPoint.html | 44 ++++++++++++------ eo/tutorial/html/eoLesson2.html | 35 ++++++++++---- 10 files changed, 163 insertions(+), 30 deletions(-) create mode 100644 eo/tutorial/Templates/continue.tmpl diff --git a/eo/tutorial/Templates/binCrossover.tmpl b/eo/tutorial/Templates/binCrossover.tmpl index 4bbd5f277..b90729b29 100644 --- a/eo/tutorial/Templates/binCrossover.tmpl +++ b/eo/tutorial/Templates/binCrossover.tmpl @@ -1,3 +1,8 @@ +/** -*- 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 binary crossover operators ============================================== @@ -11,6 +16,10 @@ based on the second #include +/** + Always write a comment in this format before class definition + if you want the class to be documented by Doxygen +*/ template class eoMyDerivedBinOp: public eoBinOp { @@ -38,7 +47,7 @@ public: // return false; } -protected: +private: paramType anyParameter }; diff --git a/eo/tutorial/Templates/continue.tmpl b/eo/tutorial/Templates/continue.tmpl new file mode 100644 index 000000000..746bfba6e --- /dev/null +++ b/eo/tutorial/Templates/continue.tmpl @@ -0,0 +1,46 @@ +/** -*- 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 _eoMyContinue_h +#define _eoMyContinue_h + +#include + +/** + Always write a comment in this format before class definition + if you want the class to be documented by Doxygen +*/ +template< class EOT> +class eoMyContinue: public eoContinue { +public: + /// Ctor + eoMyContinue( paramType _anyParameter) : + anyParameter(_anyParameter) {} + + + /** Returns false when you want to stop + */ + virtual bool operator() ( const eoPop& _pop ) + { + bool stopCondition = ... ; // compute the stopping condition + if (stopCondition) // the algo will stop upon return FALSE + { + cout << "STOP in eoMyContinue: blablabla \n"; + return false; + } + return true; // == do not stop + } + +private: + paramType anyParameter +}; + +#endif + diff --git a/eo/tutorial/Templates/lessOffspringExternalSelectorGenOp.tmpl b/eo/tutorial/Templates/lessOffspringExternalSelectorGenOp.tmpl index 0bd9bca2f..11ce2b534 100644 --- a/eo/tutorial/Templates/lessOffspringExternalSelectorGenOp.tmpl +++ b/eo/tutorial/Templates/lessOffspringExternalSelectorGenOp.tmpl @@ -1,3 +1,8 @@ +/** -*- 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 =============================== @@ -13,6 +18,10 @@ Second version, get parents using an external eoSelectOne #include +/** + Always write a comment in this format before class definition + if you want the class to be documented by Doxygen +*/ template class eoLessOffspringExternalSelectorGenOp: public eoGenOp { @@ -61,7 +70,7 @@ public: } -protected: +private: eoSelectOne & sel; paramType anyParameter }; diff --git a/eo/tutorial/Templates/lessOffspringSameSelectorGenOp.tmpl b/eo/tutorial/Templates/lessOffspringSameSelectorGenOp.tmpl index 79ca25743..826ebf37b 100644 --- a/eo/tutorial/Templates/lessOffspringSameSelectorGenOp.tmpl +++ b/eo/tutorial/Templates/lessOffspringSameSelectorGenOp.tmpl @@ -1,3 +1,8 @@ +/** -*- 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 =============================== @@ -13,6 +18,10 @@ First version, get parents from populator using the ibbedded select() method #include +/** + Always write a comment in this format before class definition + if you want the class to be documented by Doxygen +*/ template class eoLessOffspringSameSelectorGenOp: public eoGenOp { @@ -57,7 +66,7 @@ public: parentN.invalidate(); } -protected: +private: paramType anyParameter }; diff --git a/eo/tutorial/Templates/moreOffspringGenOp.tmpl b/eo/tutorial/Templates/moreOffspringGenOp.tmpl index 24c19b0be..9753ded61 100644 --- a/eo/tutorial/Templates/moreOffspringGenOp.tmpl +++ b/eo/tutorial/Templates/moreOffspringGenOp.tmpl @@ -1,3 +1,8 @@ +/** -*- 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 =============================== @@ -12,6 +17,10 @@ than there are parents #include +/** + Always write a comment in this format before class definition + if you want the class to be documented by Doxygen +*/ template class eoMoreOffspringGenOp: public eoGenOp { @@ -58,7 +67,7 @@ public: } -protected: +private: paramType anyParameter }; diff --git a/eo/tutorial/Templates/mutation.tmpl b/eo/tutorial/Templates/mutation.tmpl index 824904e5c..41e62e887 100644 --- a/eo/tutorial/Templates/mutation.tmpl +++ b/eo/tutorial/Templates/mutation.tmpl @@ -1,3 +1,8 @@ +/** -*- 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 mutation operators ====================================== @@ -9,6 +14,10 @@ Template for simple mutation operators #include +/** + Always write a comment in this format before class definition + if you want the class to be documented by Doxygen +*/ template class eoMyDerivedMonOp: public eoMonOp { @@ -35,7 +44,7 @@ public: // return false; } -protected: +private: paramType anyParameter }; diff --git a/eo/tutorial/Templates/quadCrossover.tmpl b/eo/tutorial/Templates/quadCrossover.tmpl index a5e598bdd..f66f1ea8c 100644 --- a/eo/tutorial/Templates/quadCrossover.tmpl +++ b/eo/tutorial/Templates/quadCrossover.tmpl @@ -1,3 +1,8 @@ +/** -*- 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 ================================================= @@ -10,6 +15,10 @@ Quadratic crossover operators modify the both parents #include +/** + Always write a comment in this format before class definition + if you want the class to be documented by Doxygen +*/ template class eoMyDerivedQuadOp: public eoQuadOp { @@ -38,7 +47,7 @@ public: // return false; } -protected: +private: paramType anyParameter }; diff --git a/eo/tutorial/html/eoBottomUp.html b/eo/tutorial/html/eoBottomUp.html index ba1919ee8..9589a8d90 100644 --- a/eo/tutorial/html/eoBottomUp.html +++ b/eo/tutorial/html/eoBottomUp.html @@ -54,7 +54,7 @@ to go directly to the corresponding section of the tutorial. - + diff --git a/eo/tutorial/html/eoCheckPoint.html b/eo/tutorial/html/eoCheckPoint.html index aaf8cb486..9ac0ec7fb 100644 --- a/eo/tutorial/html/eoCheckPoint.html +++ b/eo/tutorial/html/eoCheckPoint.html @@ -27,7 +27,7 @@ is Checkpointing about?

EO classes described in this page:

  • -Base classes: eoCheckPoint, eoContinue, +Base classes: eoCheckPoint, eoContinue, eoStat, eoSortedStat, eoMonitor, eoUpdater
  • @@ -40,23 +40,31 @@ eoStat, eoSortedStat, eoMonitor, eoUpdater

  •  


    Continuators: -
     

    Continuators are functors that compute stopping critera. They receive a population and return a boolean value which is set to false only when some stopping vriterion is met. All algorithms in EO have a loop that goes -while(continuator(pop) -{ ... } which means that the algorithm stops only when -the continuator returns false. -

    Interface: -
      +do{...}while(continuator(pop)which +means that the algorithm stops only when the continuator returns false. +

    Interface:  The abstract class +for computing stopping conditions is eoContinue, +and the interface for its operator() is +

                                +bool operator()(const eoPop<EOT>& +) +

    which you could have guessed from the inheritance +diagram for class eoContinue, as +you see there that eoContinue derives +from class eoUF<const eoPop<EOT>&, +bool>.

    Using a continuator:
    You can find an first example of using a continuator in the code for -FirstBitEA in Lesson2. +FirstBitEA +ior more sophisticated continue conditions in  Lesson2.
    If you want to find out how it is used inside an algorithm, go and see for instance in eoSGA, the simplest EA within EO.

    Writing a continuator: -
    There are only two things to modify in the template +
    There are only two things to modify in the
    template class definitions provided (apart from the name of the class you are creating!)

      @@ -66,11 +74,21 @@ any useful parameter (see the private data at end of class definition).
    • The operator() method, which performs the -actual test on the population.
    • +computation of the actual test using the population plus any other parameter +passed at construct time. Don't forget to returnfalse +when the stopping criterion is met!
    -Don't forget to return false -when the stopping criterion is met! -

    +Existing continuators: +Of course you can find out all existing (non-virtual!) subclasses +of eoContinue by looking at its  inheritance +diagram. But you might find it more convenient to have them listed +here: +

      +
    • +
    • +
    + +



    Combining continuators:

    diff --git a/eo/tutorial/html/eoLesson2.html b/eo/tutorial/html/eoLesson2.html index 346ebb3ab..746c8262b 100644 --- a/eo/tutorial/html/eoLesson2.html +++ b/eo/tutorial/html/eoLesson2.html @@ -2,7 +2,7 @@ - + Tutorial: Lesson 2 @@ -67,7 +67,11 @@ argument is a vector<bool> or a Note: Also, +
      +

      +
      +
      +

    Note: Also, a non-templatized fitness can be compiled separately (not done here) into an object file once and for all (remember @@ -82,8 +86,12 @@ have to declare 3 template arguments: the type of EO object it will be applied to, the return type and the type of argument the function actually requires. -


    Note: In -the previous files (Bit - Real) +
      +

      +
      +
      +

    Note: In the +previous files (Bit - Real) , the last 2 types were deduced from the first (2nd argument = fitness type of EO object, third = first).
      @@ -99,13 +107,17 @@ rather than maximize a fitness function (see Exercise of the population is now
    encapsulatedinto a separate initializer (based on a boolean generator or a double-number -generator -see random_generators.h) +generator -see random_generators.h) that is then used in the constructor of the population to build the individuals. You can also use different initializers and call them in turn through the call to pop.append() function (see Exercise 2). -


    Note: Don't +
      +

      +
      +
      +

    Note: Don't forget to evaluate the population: the eoPop has no idea of the eval function, so it has to be done from outside!!!
      @@ -199,12 +211,15 @@ several stopping criteria by using an object of the class
    (Bit - Real). Initialize it with an object of class eoContinue, and -addas -many of other such objects as you wish. And as an eoCombinedContinue +add +as many of other such objects as you wish. And as an eoCombinedContinue is -aneoContinue, +an eoContinue, simply pass it to the algorithm (Bit -- Real). +- Real). To find out more, and +to get the list and syntax of existing eoContinue subclasses, check out +the corresponding component-based +page.