Modified the tempaltes to take into account
- the last modifications of the eopopulator class - the include files (were totally missing in the old templates) - JJ's demand for one class - one file :-)
This commit is contained in:
parent
d634d95838
commit
7ec7a856e5
6 changed files with 301 additions and 7 deletions
64
eo/tutorial/Templates/lessOffspringSameSelectorGenOp.tmpl
Normal file
64
eo/tutorial/Templates/lessOffspringSameSelectorGenOp.tmpl
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
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 ibbedded select() method
|
||||
*/
|
||||
|
||||
#ifndef eoLessOffspringSameSelectorGenOp_H
|
||||
#define eoLessOffspringSameSelectorGenOp_H
|
||||
|
||||
#include <eoGenOp.h>
|
||||
|
||||
template<class Indi>
|
||||
class eoLessOffspringSameSelectorGenOp: public eoGenOp<Indi>
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
protected:
|
||||
paramType anyParameter
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue