Added a new atommutator to Variable Length, and corrected some headers which had problems
This commit is contained in:
parent
06dd2dc314
commit
d8fe00183a
4 changed files with 31 additions and 140 deletions
|
|
@ -1,98 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoAtomMutation.h
|
||||
// (c) GeNeura Team, 1998
|
||||
/*
|
||||
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
|
||||
|
||||
CVS Info: $Date: 2001-03-21 12:10:13 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/Attic/eoAtomMutation.h,v 1.7 2001-03-21 12:10:13 jmerelo Exp $ $Author: jmerelo $
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _EOATOMMUTATION_H
|
||||
#define _EOATOMMUTATION_H
|
||||
|
||||
// STL includes
|
||||
#include <iterator>
|
||||
|
||||
// EO includes
|
||||
#include <eoOp.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <eoAtomMutator.h>
|
||||
|
||||
/** Atomic mutation of an EO. Acts on containers, and applies a mutation
|
||||
operator to each element of the container with some probability. EOT must
|
||||
be a container of any type
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoAtomMutation: public eoMonOp<EOT> {
|
||||
public:
|
||||
|
||||
#ifdef _MSC_VER
|
||||
typedef EOT::AtomType Type;
|
||||
#else
|
||||
typedef typename EOT::AtomType Type;
|
||||
#endif
|
||||
|
||||
///
|
||||
eoAtomMutation(eoAtomMutator<Type>& _atomMut, const double _rate=0.0)
|
||||
: eoMonOp< EOT >(), rate(_rate), atomMutator( _atomMut ) {};
|
||||
|
||||
///
|
||||
virtual ~eoAtomMutation() {};
|
||||
|
||||
///
|
||||
virtual bool operator()( EOT& _eo ) {
|
||||
typename EOT::iterator i;
|
||||
for ( i = _eo.begin(); i != _eo.end(); i ++ )
|
||||
if ( rng.flip( rate ) ) {
|
||||
atomMutator( *i );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** To print me on a stream.
|
||||
@param os The ostream.
|
||||
*/
|
||||
void printOn(ostream& os) const {
|
||||
os << rate ;
|
||||
}
|
||||
|
||||
/** To read me from a stream.
|
||||
@param is The istream */
|
||||
void readFrom(istream& is) {
|
||||
is >> rate ;
|
||||
}
|
||||
|
||||
/** @name Methods from eoObject
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eoMutation";};
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
double rate;
|
||||
eoAtomMutator<Type>& atomMutator;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoAtomMutator.h
|
||||
// (c) GeNeura Team, 1998
|
||||
/*
|
||||
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
|
||||
CVS Info: $Date: 2001-03-21 12:10:13 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/Attic/eoAtomMutator.h,v 1.4 2001-03-21 12:10:13 jmerelo Exp $ $Author: jmerelo $
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _EOATOMMUTATOR_H
|
||||
#define _EOATOMMUTATOR_H
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
/** Abstract base class for functors that modify a single element in an EO
|
||||
that is composed of several atomic components. An atom would, for instance, flip
|
||||
a bit, or change a real number, or things like that. The header is completely
|
||||
empty and thus just provides a name rather than functionality.
|
||||
*/
|
||||
|
||||
template <class T>
|
||||
class eoAtomMutator: public eoUF<T&, bool> {};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mak@dhi.dk
|
||||
CVS Info: $Date: 2001-03-21 13:09:47 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoVariableLengthCrossover.h,v 1.5 2001-03-21 13:09:47 jmerelo Exp $ $Author: jmerelo $
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mak@dhi.dk
|
||||
CVS Info: $Date: 2001-03-21 13:09:47 $ $Version$ $Author: jmerelo $
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -28,8 +29,8 @@
|
|||
#define _eoVariableLengthMutation_h
|
||||
|
||||
#include <eoFunctor.h>
|
||||
#include <eoVariableLength.h>
|
||||
#include <eoOp.h>
|
||||
#include <eoInit.h>
|
||||
|
||||
/**
|
||||
Base classes for generic mutations on variable length chromosomes.
|
||||
|
|
@ -64,6 +65,34 @@ private:
|
|||
eoMonOp<AtomType> & atomMutation;
|
||||
};
|
||||
|
||||
/** THis ones applies its atomic mutation depending on a probability
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoVlRateMutation : public eoMonOp<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
typedef typename EOT::AtomType AtomType;
|
||||
|
||||
// default ctor: requires an Atom mutation
|
||||
eoVlRateMutation(eoMonOp<AtomType> & _atomMutation, double _rate=0.0) :
|
||||
atomMutation(_atomMutation), rate( _rate ) {}
|
||||
|
||||
bool operator()(EOT & _eo)
|
||||
{
|
||||
bool modified=false;
|
||||
typename EOT::iterator i;
|
||||
for ( i = _eo.begin(); i != _eo.end(); i ++ )
|
||||
if ( rng.flip( rate ) ) {
|
||||
modified |= atomMutation( *i );
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
private:
|
||||
double rate;
|
||||
eoMonOp<AtomType> & atomMutation;
|
||||
};
|
||||
|
||||
/** This ones applies its atomic mutation to a fixed
|
||||
number of genes (1 by default)
|
||||
*/
|
||||
|
|
|
|||
Reference in a new issue