Cosmetic changes
This commit is contained in:
parent
dabbcdc7b4
commit
c853631219
2 changed files with 189 additions and 187 deletions
|
|
@ -53,6 +53,8 @@ public:
|
||||||
It takes a vector of pointers to eo
|
It takes a vector of pointers to eo
|
||||||
* @param _vEO is a vector of pointers to eo, that will be evaluated
|
* @param _vEO is a vector of pointers to eo, that will be evaluated
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
virtual void operator() ( EOT& _eot ) const = 0;
|
||||||
|
|
||||||
///@name eoObject methods
|
///@name eoObject methods
|
||||||
//@{
|
//@{
|
||||||
|
|
|
||||||
374
eo/src/eoOp.h
374
eo/src/eoOp.h
|
|
@ -1,8 +1,8 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoOp.h
|
// eoOp.h
|
||||||
// (c) GeNeura Team, 1998
|
// (c) GeNeura Team, 1998
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -20,185 +20,185 @@
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _eoOp_H
|
#ifndef _eoOp_H
|
||||||
#define _eoOp_H
|
#define _eoOp_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <eoObject.h>
|
#include <eoObject.h>
|
||||||
#include <eoPrintable.h>
|
#include <eoPrintable.h>
|
||||||
|
|
||||||
/** @name Genetic operators
|
/** @name Genetic operators
|
||||||
|
|
||||||
What is a genetic algorithm without genetic operators? There is a genetic operator hierarchy, with
|
What is a genetic algorithm without genetic operators? There is a genetic operator hierarchy, with
|
||||||
eoOp as father and eoMonOp (monary or unary operator) and eoBinOp (binary operator) as siblings. Nobody
|
eoOp as father and eoMonOp (monary or unary operator) and eoBinOp (binary operator) as siblings. Nobody
|
||||||
should subclass eoOp, you should subclass eoBinOp or eoMonOp, those are the ones actually used here.\\
|
should subclass eoOp, you should subclass eoBinOp or eoMonOp, those are the ones actually used here.\\
|
||||||
#eoOp#s are only printable objects, so if you want to build them from a file, it has to
|
#eoOp#s are only printable objects, so if you want to build them from a file, it has to
|
||||||
be done in another class, namely factories. Each hierarchy of #eoOp#s should have its own
|
be done in another class, namely factories. Each hierarchy of #eoOp#s should have its own
|
||||||
factory, which know how to build them from a description in a file.
|
factory, which know how to build them from a description in a file.
|
||||||
@author GeNeura Team
|
@author GeNeura Team
|
||||||
@version 0.1
|
@version 0.1
|
||||||
@see eoOpFactory
|
@see eoOpFactory
|
||||||
*/
|
*/
|
||||||
//@{
|
//@{
|
||||||
|
|
||||||
///
|
///
|
||||||
enum Arity { unary = 0, binary = 1, Nary = 2};
|
enum Arity { unary = 0, binary = 1, Nary = 2};
|
||||||
|
|
||||||
/** Abstract data types for EO operators.
|
/** Abstract data types for EO operators.
|
||||||
* Genetic operators act on chromosomes, changing them. The type to instantiate them should
|
* Genetic operators act on chromosomes, changing them. The type to instantiate them should
|
||||||
* be an eoObject, but in any case, they are type-specific; each kind of evolvable object
|
* be an eoObject, but in any case, they are type-specific; each kind of evolvable object
|
||||||
* can have its own operators
|
* can have its own operators
|
||||||
*/
|
*/
|
||||||
template<class EOType>
|
template<class EOType>
|
||||||
class eoOp: public eoObject, public eoPrintable {
|
class eoOp: public eoObject, public eoPrintable {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ctor
|
/// Ctor
|
||||||
eoOp( Arity _arity = unary )
|
eoOp( Arity _arity = unary )
|
||||||
:arity( _arity ) {};
|
:arity( _arity ) {};
|
||||||
|
|
||||||
/// Copy Ctor
|
/// Copy Ctor
|
||||||
eoOp( const eoOp& _eop )
|
eoOp( const eoOp& _eop )
|
||||||
:arity( _eop.arity ) {};
|
:arity( _eop.arity ) {};
|
||||||
|
|
||||||
/// Needed virtual destructor
|
/// Needed virtual destructor
|
||||||
virtual ~eoOp(){};
|
virtual ~eoOp(){};
|
||||||
|
|
||||||
/// Arity: number of operands
|
/// Arity: number of operands
|
||||||
Arity readArity() const {return arity;};
|
Arity readArity() const {return arity;};
|
||||||
|
|
||||||
/** @name Methods from eoObject */
|
/** @name Methods from eoObject */
|
||||||
//@{
|
//@{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write object. It's called printOn since it prints the object _on_ a stream.
|
* Write object. It's called printOn since it prints the object _on_ a stream.
|
||||||
* @param _os A ostream.
|
* @param _os A ostream.
|
||||||
*/
|
*/
|
||||||
virtual void printOn(ostream& _os) const {
|
virtual void printOn(ostream& _os) const {
|
||||||
_os << className();
|
_os << className();
|
||||||
// _os << arity;
|
// _os << arity;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Inherited from eoObject
|
/** Inherited from eoObject
|
||||||
@see eoObject
|
@see eoObject
|
||||||
*/
|
*/
|
||||||
virtual string className() const {return "eoOp";};
|
virtual string className() const {return "eoOp";};
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// arity is the number of operands it takes
|
/// arity is the number of operands it takes
|
||||||
Arity arity;
|
Arity arity;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Binary genetic operator: subclasses eoOp, and defines
|
/** Binary genetic operator: subclasses eoOp, and defines
|
||||||
basically the operator() with two operands
|
basically the operator() with two operands
|
||||||
*/
|
*/
|
||||||
template<class EOType>
|
template<class EOType>
|
||||||
class eoBinOp: public eoOp<EOType> {
|
class eoBinOp: public eoOp<EOType> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ctor
|
/// Ctor
|
||||||
eoBinOp()
|
eoBinOp()
|
||||||
:eoOp<EOType>( binary ) {};
|
:eoOp<EOType>( binary ) {};
|
||||||
|
|
||||||
/// Copy Ctor
|
/// Copy Ctor
|
||||||
eoBinOp( const eoBinOp& _ebop )
|
eoBinOp( const eoBinOp& _ebop )
|
||||||
: eoOp<EOType>( _ebop ){};
|
: eoOp<EOType>( _ebop ){};
|
||||||
|
|
||||||
/// Dtor
|
/// Dtor
|
||||||
~eoBinOp () {};
|
~eoBinOp () {};
|
||||||
|
|
||||||
/** applies operator, to the object. If arity is more than 1,
|
/** applies operator, to the object. If arity is more than 1,
|
||||||
* keeps a copy of the operand in a cache.
|
* keeps a copy of the operand in a cache.
|
||||||
*/
|
*/
|
||||||
virtual void operator()( EOType& _eo1, EOType& _eo2 ) const = 0;
|
virtual void operator()( EOType& _eo1, EOType& _eo2 ) const = 0;
|
||||||
|
|
||||||
/** @name Methods from eoObject
|
/** @name Methods from eoObject
|
||||||
readFrom and printOn are directly inherited from eoObject
|
readFrom and printOn are directly inherited from eoObject
|
||||||
*/
|
*/
|
||||||
//@{
|
//@{
|
||||||
/** Inherited from eoObject
|
/** Inherited from eoObject
|
||||||
@see eoObject
|
@see eoObject
|
||||||
*/
|
*/
|
||||||
virtual string className() const {return "eoBinOp";};
|
virtual string className() const {return "eoBinOp";};
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** eoMonOp is the monary operator: genetic operator that takes
|
/** eoMonOp is the monary operator: genetic operator that takes
|
||||||
only one EO
|
only one EO
|
||||||
*/
|
*/
|
||||||
template <class EOType>
|
template <class EOType>
|
||||||
class eoMonOp: public eoOp<EOType> {
|
class eoMonOp: public eoOp<EOType> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ctor
|
/// Ctor
|
||||||
eoMonOp( )
|
eoMonOp( )
|
||||||
:eoOp<EOType>( unary ) {};
|
:eoOp<EOType>( unary ) {};
|
||||||
|
|
||||||
/// Copy Ctor
|
/// Copy Ctor
|
||||||
eoMonOp( const eoMonOp& _emop )
|
eoMonOp( const eoMonOp& _emop )
|
||||||
: eoOp<EOType>( _emop ){};
|
: eoOp<EOType>( _emop ){};
|
||||||
|
|
||||||
/// Dtor
|
/// Dtor
|
||||||
~eoMonOp() {};
|
~eoMonOp() {};
|
||||||
|
|
||||||
/** applies randomly operator, to the object. If arity is more than 1,
|
/** applies randomly operator, to the object. If arity is more than 1,
|
||||||
* keeps a copy of the operand in a cache.
|
* keeps a copy of the operand in a cache.
|
||||||
*/
|
*/
|
||||||
virtual void operator()( EOType& _eo1) const = 0;
|
virtual void operator()( EOType& _eo1) const = 0;
|
||||||
|
|
||||||
/** @name Methods from eoObject
|
/** @name Methods from eoObject
|
||||||
readFrom and printOn are directly inherited from eoObject
|
readFrom and printOn are directly inherited from eoObject
|
||||||
*/
|
*/
|
||||||
//@{
|
//@{
|
||||||
/** Inherited from eoObject
|
/** Inherited from eoObject
|
||||||
@see eoObject
|
@see eoObject
|
||||||
*/
|
*/
|
||||||
virtual string className() const {return "eoMonOp";};
|
virtual string className() const {return "eoMonOp";};
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
/** eoNaryOp is the N-ary operator: genetic operator that takes
|
/** eoNaryOp is the N-ary operator: genetic operator that takes
|
||||||
several EOs. It could be called an {\em orgy} operator
|
several EOs. It could be called an {\em orgy} operator
|
||||||
*/
|
*/
|
||||||
template <class EOType>
|
template <class EOType>
|
||||||
class eoNaryOp: public eoOp<EOType> {
|
class eoNaryOp: public eoOp<EOType> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ctor
|
/// Ctor
|
||||||
eoNaryOp( )
|
eoNaryOp( )
|
||||||
:eoOp<EOType>( Nary ) {};
|
:eoOp<EOType>( Nary ) {};
|
||||||
|
|
||||||
/// Copy Ctor
|
/// Copy Ctor
|
||||||
eoNaryOp( const eoNaryOp& _emop )
|
eoNaryOp( const eoNaryOp& _emop )
|
||||||
: eoOp<EOType>( _emop ){};
|
: eoOp<EOType>( _emop ){};
|
||||||
|
|
||||||
/// Dtor
|
/// Dtor
|
||||||
~eoNaryOp() {};
|
~eoNaryOp() {};
|
||||||
|
|
||||||
/** applies randomly operator, to the object.
|
/** applies randomly operator, to the object.
|
||||||
*/
|
*/
|
||||||
virtual void operator()( eoPop<EOType> & _eop) const = 0;
|
virtual void operator()( eoPop<EOType> & _eop) const = 0;
|
||||||
|
|
||||||
/** @name Methods from eoObject
|
/** @name Methods from eoObject
|
||||||
readFrom and printOn are directly inherited from eoObject.
|
readFrom and printOn are directly inherited from eoObject.
|
||||||
*/
|
*/
|
||||||
//@{
|
//@{
|
||||||
/** Inherited from eoObject
|
/** Inherited from eoObject
|
||||||
@see eoObject
|
@see eoObject
|
||||||
*/
|
*/
|
||||||
string className() const {return "eoNaryOp";};
|
string className() const {return "eoNaryOp";};
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
};
|
};
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Reference in a new issue