Changed name of eoEsLocalXover to eoEsStandardXover and made it an eoBinOp
Removed obsolete eoEsStdevXOver.h (see eoEsStandardXover.h above)
This commit is contained in:
parent
8e5e9d14cf
commit
9631c9eb11
2 changed files with 11 additions and 101 deletions
|
|
@ -36,13 +36,14 @@
|
|||
// needs a selector - here random
|
||||
#include <eoRandomSelect.h>
|
||||
|
||||
/** Local (i.e. std eoBinOp) crossover operator for ES genotypes.
|
||||
/** Standard (i.e. eoBinOp) crossover operator for ES genotypes.
|
||||
* Uses some Atom crossovers to handle both the object variables
|
||||
* and the mutation strategy parameters
|
||||
* It is an eoGenOp and not an eoBinOp for consistency with the global version
|
||||
* It is an eoBinOp and has to be wrapped into an eoGenOp before being used
|
||||
* like the global version
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoEsLocalXover: public eoGenOp<EOT>
|
||||
class eoEsStandardXover: public eoBinOp<EOT>
|
||||
{
|
||||
public:
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
|
@ -50,36 +51,25 @@ public:
|
|||
/**
|
||||
* (Default) Constructor.
|
||||
*/
|
||||
eoEsLocalXover(eoBinOp<double> & _crossObj, eoBinOp<double> & _crossMut) :
|
||||
eoEsStandardXover(eoBinOp<double> & _crossObj, eoBinOp<double> & _crossMut) :
|
||||
crossObj(_crossObj), crossMut(_crossMut) {}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
virtual string className() const { return "eoEsLocalXover"; }
|
||||
|
||||
/// The TOTAL number of offspring (here = nb of parents modified in place)
|
||||
unsigned max_production(void) { return 1; }
|
||||
virtual string className() const { return "eoEsStandardXover"; }
|
||||
|
||||
/**
|
||||
* modifies one parents in the populator
|
||||
* using a second parent
|
||||
*
|
||||
* @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
|
||||
const EOT& parent2 = sel(_plop.source()); // and the second, randomly
|
||||
|
||||
bool operator()(EOT& _eo1, const EOT& _eo2)
|
||||
{
|
||||
// first, the object variables
|
||||
for (unsigned i=0; i<parent1.size(); i++)
|
||||
for (unsigned i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
crossObj(parent1[i], parent2[i]); // apply eoBinOp
|
||||
crossObj(_eo1[i], _eo2[i]); // apply eoBinOp
|
||||
}
|
||||
// then the self-adaptation parameters
|
||||
cross_self_adapt(parent1, parent2);
|
||||
// dont' forget to invalidate
|
||||
parent1.invalidate();
|
||||
cross_self_adapt(_eo1, _eo2);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoEsStdevXOver.h
|
||||
// (c) GeNeura Team, 2000 - Maarten Keijzer 2000 - Marc Schoenauer 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
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _eoEsStdevXOver_h
|
||||
#define _eoEsStdevXOver_h
|
||||
|
||||
#include <es/eoEsStdev.h>
|
||||
#include <es/eoRealOp.h>
|
||||
|
||||
/**
|
||||
\ingroup EvolutionStrategies
|
||||
|
||||
Crossover for Evolutionary strategie style representation,
|
||||
supporting co-evolving standard deviations.
|
||||
|
||||
Simply calls a crossover for the object variables,
|
||||
and a crossover for teh StdDev
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
class eoEsStdevXOver : public eoQuadOp<EOT>
|
||||
{
|
||||
public :
|
||||
eoEsStdevXOver(eoQuadOp<vector<double> > & _objectXOver,
|
||||
eoQuadOp<vector<double> > & _stdDevXOver) :
|
||||
objectXOver(_objectXOver), stdDevXOver(_stdDevXOver) {}
|
||||
|
||||
virtual std::string className(void) const { return "eoEsStdevXOver"; }
|
||||
|
||||
bool operator()(EOT & _eo1, EOT & _eo2)
|
||||
{
|
||||
bool objectChanged = objectXOver(_eo1, _eo2); // as vector<double>
|
||||
bool stdDevChanged = stdDevXOver(_eo1.stdevs, _eo2.stdevs);
|
||||
|
||||
return objectChanged;
|
||||
}
|
||||
|
||||
private:
|
||||
eoQuadOp<vector<double> > & objectXOver;
|
||||
eoQuadOp<vector<double> > & stdDevXOver;
|
||||
};
|
||||
|
||||
/* A question: it seems it really makes no difference to have
|
||||
as template the fitness (and use eoEsStdev<FitT> where you need EOs) or
|
||||
directly the EOT itself. But of course if the EOT you use does not have
|
||||
a stdev public member the compiler will crash.
|
||||
There is a difference, however, in the calling instruction, because in
|
||||
on case you have to write eoEsStdevXOver<double> whereas otherwise you
|
||||
simply write eoEsStdevXOver<Indi> (if Indi has been typedef'ed correctly).
|
||||
So to keep everything (or almost :-) in the main program templatized
|
||||
with the Indi i've kept here the EOT template.
|
||||
|
||||
Are there arguments against that???
|
||||
MS - Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
|
||||
#endif
|
||||
Reference in a new issue