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
65
eo/tutorial/Templates/moreOffspringGenOp.tmpl
Normal file
65
eo/tutorial/Templates/moreOffspringGenOp.tmpl
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
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>
|
||||
|
||||
template<class Indi>
|
||||
class eoMoreOffspringGenOp: public eoGenOp<Indi>
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
paramType anyParameter
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in a new issue