Added the signal handling - see eoCtrlCContinue.h

I've disabled it in case of MSC as I don't know if this works there ...

Also added a couple of "virtual" in the ga dir
This commit is contained in:
evomarc 2001-04-04 03:47:33 +00:00
commit ddc6650ce5
8 changed files with 180 additions and 265 deletions

View file

@ -238,7 +238,11 @@ void main_function(int argc, char **argv)
eoCombinedContinue<Indi> continuator(genCont);
continuator.add(steadyCont);
// continuator.add(fitCont);
// Ctrl C signal handling: don't know if that works in MSC ...
#ifndef _MSC_VER
eoCtrlCContinue<Indi> ctrlC;
continuator.add(ctrlC);
#endif
// CHECKPOINT
// but now you want to make many different things every generation

View file

@ -1,71 +0,0 @@
Template for simple operators
=============================
===========================================================================
eoQuad : crossover operators that take 2 parents and modify both
======
template<class Indi> class eoMyDerivedQuadOp: public eoQuadOp<Indi>
{
public:
/**
* (Default) Constructor.
*/
eoMyDerivedQuadOp(paramType _anyParameter) :
anyParameter(_anyParameter) {}
/// The class name. Used to display statistics
string className() const { return "eoMyDerivedQuadOp"; }
/**
* eoQuad crossover - modifies both parents
* @param Indi1 The first parent
* @param Indi2 The first parent
*/
bool operator()(Indi& Indi1, Indi& Indi2)
{
// do whatever needs to be done
// if at least one individual has been modified
return true;
// otherwise
// return false;
}
protected:
paramType anyParameter
};
===========================================================================
eoBin : crossover operators that take 2 parents and modify the first one
=====
template<class Indi> class eoMyDerivedBinOp: public eoBinOp<Indi>
{
public:
/**
* (Default) Constructor.
*/
eoMyDerivedBinOp(paramType _anyParameter) :
anyParameter(_anyParameter) {}
/// The class name. Used to display statistics
string className() const { return "eoMyDerivedBinOp"; }
/**
* eoQuad crossover - modifies first parent only
* @param Indi1 The first parent
* @param Indi2 The first parent - const
*/
bool operator()(Indi& Indi1, const Indi& Indi2)
{
// do whatever needs to be done
// if Indi1 has been modified
return true;
// otherwise
// return false;
}
protected:
paramType anyParameter
};

View file

@ -1,172 +0,0 @@
Template for simple operators
=============================
===========================================================================
eoGen : general operator that takes any number of parents and generates
====== any number of offspring
First, a GenOp that creates more offspring than there are parents
-----------------------------------------------------------------
template<class Indi> class eoMyDerivedGrowGenOp: public eoGenOp<Indi>
{
public:
/**
* (Default) Constructor.
*/
eoMyDerivedGrowGenOp(paramType _anyParameter) :
anyParameter(_anyParameter) {}
/// The class name. Used to display statistics
string className() const { return "eoMyDerivedGrowGenOp"; }
/// The TOTAL number of offspring (including modified parents)
unsigned max_production(void) { return NbOffspring; }
/**
* eoGrowGen 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.insert(ofs1);
++_plop; // advance after each insertion
...
_plop.insert(ofsN);
// don't advance after the last one: _plop always
// points to the last that has already been treated
// oh right, and invalidate fitnesses of modified parents
parent1.invalidate();
...
parentN.invalidate();
}
protected:
paramType anyParameter
};
===========================================================================
Now, a GenOp that creates less offspring than there are parents
---------------------------------------------------------------
First version, get parents from populator, and erase some of them
-----------------------------------------------------------------
template<class Indi> class eoMyDerivedShrink1GenOp: public eoGenOp<Indi>
{
public:
/**
* (Default) Constructor.
*/
eoMyDerivedShrink1GenOp(paramType _anyParameter) :
anyParameter(_anyParameter) {}
/// The class name. Used to display statistics
string className() const { return "eoMyDerivedShrink1GenOp"; }
/// The TOTAL number of offspring (here = nb of remaining modified parents)
unsigned max_production(void) { return NbLeftParents; }
/**
* eoShrinkGen operator - modifies some of the parents
* and kills the rest
*
* @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
// modify some of the parents (the first ones
// as erase removes backwards)
...
// then kill the ones that are now useless
_plop.erase(); // as many times as necessary
...
// oh right, and invalidate fitnesses of remaining modified parents
parent1.invalidate();
...
parentK.invalidate();
}
protected:
paramType anyParameter
};
===========================================================================
Now, a GenOp that creates less offspring than there are parents
---------------------------------------------------------------
Second version, get parents from an external selector (no erasing)
------------------------------------------------------------------
template<class Indi> class eoMyDerivedShrink2GenOp: public eoGenOp<Indi>
{
public:
/**
* (Default) Constructor.
*/
eoMyDerivedShrink2GenOp(eoSelectOne<EOT> & _sel, paramType _anyParameter) :
sel(_sel), anyParameter(_anyParameter) {}
/// The class name. Used to display statistics
string className() const { return "eoMyDerivedShrink2GenOp"; }
/// 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)
{
EOT& parent1 = *_plop; // select the first parent
++_plop; // advance once for each selected parents
...
EOT& parentN = *_plop; // select the last parent you need
// don't advance after the last one: _plop always
// points to the last that has already been treated
// 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& parentM = sel(_plop.source());
// modify (in place) the "true" parents
// (i.e. parent1, ..., parentsN)
...
// invalidate fitnesses of modified parents
parent1.invalidate();
...
parentN.invalidate();
}
protected:
eoSelectoIne<EOT> & sel;
paramType anyParameter
};