Changed functor base names and added to version

This commit is contained in:
maartenkeijzer 2000-10-09 16:13:20 +00:00
commit f7c98d5b31
23 changed files with 64 additions and 48 deletions

View file

@ -10,3 +10,12 @@ instead of
$> ./configure $> ./configure
before making the libraries. before making the libraries.
Documentation can be found in:
eo/doc/html
And \latex sources for a reference manual in:
eo/doc/latex
There are currently no examples except the programs in the test directory.
Only the files mentioned in Makefile.am will actually compile.

View file

@ -1,7 +1,7 @@
AC_INIT(src/eo) AC_INIT(src/eo)
dnl Change the version number here dnl Change the version number here
AM_INIT_AUTOMAKE(eo, 0.9.1) AM_INIT_AUTOMAKE(eo, 0.9.11)
AC_PROG_CXX AC_PROG_CXX

View file

@ -29,8 +29,11 @@
#include <eoFunctor.h> #include <eoFunctor.h>
#include <vector> #include <vector>
/**
Applies a unary function to a vector of things.
*/
template <class EOT> template <class EOT>
void apply(eoUnaryFunctor<void, EOT&>& _proc, std::vector<EOT>& _pop) void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
{ {
for (unsigned i = 0; i < _pop.size(); ++i) for (unsigned i = 0; i < _pop.size(); ++i)
{ {

View file

@ -36,7 +36,7 @@
population-transforming algorithms. population-transforming algorithms.
*/ */
template< class EOT > template< class EOT >
class eoAlgo : public eoUnaryFunctor<void, eoPop<EOT>&> class eoAlgo : public eoUF<eoPop<EOT>&, void>
{}; {};

View file

@ -40,7 +40,7 @@ function.
@see eoSelect, eoTransform, eoSelectTransform @see eoSelect, eoTransform, eoSelectTransform
*/ */
template<class EOT> template<class EOT>
class eoBreed : public eoBinaryFunctor<void, const eoPop<EOT>&, eoPop<EOT>&> class eoBreed : public eoBF<const eoPop<EOT>&, eoPop<EOT>&, void>
{}; {};
/** /**

View file

@ -33,7 +33,7 @@
* false for termination * false for termination
*/ */
template< class EOT> template< class EOT>
class eoContinue : public eoUnaryFunctor<bool, const eoPop<EOT>&> {}; class eoContinue : public eoUF<const eoPop<EOT>&, bool> {};
#endif #endif

View file

@ -38,7 +38,7 @@
EO, the requirements on this EO will depend on the evaluator. EO, the requirements on this EO will depend on the evaluator.
*/ */
template<class EOT> class eoEvalFunc : public eoUnaryFunctor<void, EOT&> template<class EOT> class eoEvalFunc : public eoUF<EOT&, void>
{ {
public : public :
typedef typename EOT::Fitness EOFitT; typedef typename EOT::Fitness EOFitT;

View file

@ -26,6 +26,8 @@
#ifndef _eoFunctor_h #ifndef _eoFunctor_h
#define _eoFunctor_h #define _eoFunctor_h
#include <functional>
/// Base class for functors to get a nice hierarchy diagram /// Base class for functors to get a nice hierarchy diagram
class eoFunctorBase class eoFunctorBase
{ {
@ -41,19 +43,19 @@ public :
}; };
/** /**
Basic Procedure. Derive from this class when defining Basic Function. Derive from this class when defining
any procedure. It defines a result_type that can be used any procedure. It defines a result_type that can be used
to determine the return type to determine the return type
Argument and result types can be any type including void for Argument and result types can be any type including void for
result_type result_type
**/ **/
template <class R> template <class R>
class eoProcedure : public eoFunctorBase class eoF : public eoFunctorBase
{ {
public : public :
/// virtual dtor here so there is no need to define it in derived classes /// virtual dtor here so there is no need to define it in derived classes
virtual ~eoProcedure() {} virtual ~eoF() {}
typedef R result_type; typedef R result_type;
@ -68,28 +70,25 @@ public :
@see eoCounter, make_counter @see eoCounter, make_counter
*/ */
template<class R> template<class R>
eoFunctorBase::procedure_tag functor_category(const eoProcedure<R>&) eoFunctorBase::procedure_tag functor_category(const eoF<R>&)
{ {
return eoFunctorBase::procedure_tag(); return eoFunctorBase::procedure_tag();
} }
/** /**
Basic Unary Functor. Derive from this class when defining Basic Unary Functor. Derive from this class when defining
any unary function. First template argument is result_type, second any unary function. First template argument is the first_argument_type,
is first_argument_type. second result_type.
Argument and result types can be any type including void for Argument and result types can be any type including void for
result_type result_type
**/ **/
template <class R, class A1> template <class A1, class R>
class eoUnaryFunctor : public eoFunctorBase class eoUF : public eoFunctorBase, public std::unary_function<A1, R>
{ {
public : public :
/// virtual dtor here so there is no need to define it in derived classes /// virtual dtor here so there is no need to define it in derived classes
virtual ~eoUnaryFunctor() {} virtual ~eoUF() {}
typedef R result_type;
typedef A1 first_argument_type;
/// The pure virtual function that needs to be implemented by the subclass /// The pure virtual function that needs to be implemented by the subclass
virtual R operator()(A1) = 0; virtual R operator()(A1) = 0;
@ -101,7 +100,7 @@ public :
@see eoCounter, make_counter @see eoCounter, make_counter
*/ */
template<class R, class A1> template<class R, class A1>
eoFunctorBase::unary_function_tag functor_category(const eoUnaryFunctor<R, A1>&) eoFunctorBase::unary_function_tag functor_category(const eoUF<A1, R>&)
{ {
return eoFunctorBase::unary_function_tag(); return eoFunctorBase::unary_function_tag();
} }
@ -114,16 +113,16 @@ eoFunctorBase::unary_function_tag functor_category(const eoUnaryFunctor<R, A1>&)
Argument and result types can be any type including void for Argument and result types can be any type including void for
result_type result_type
**/ **/
template <class R, class A1, class A2> template <class A1, class A2, class R>
class eoBinaryFunctor : public eoFunctorBase class eoBF : public eoFunctorBase, public std::binary_function<A1, A2, R>
{ {
public : public :
/// virtual dtor here so there is no need to define it in derived classes /// virtual dtor here so there is no need to define it in derived classes
virtual ~eoBinaryFunctor() {} virtual ~eoBF() {}
typedef R result_type; //typedef R result_type;
typedef A1 first_argument_type; //typedef A1 first_argument_type;
typedef A2 second_argument_type; //typedef A2 second_argument_type;
/// The pure virtual function that needs to be implemented by the subclass /// The pure virtual function that needs to be implemented by the subclass
virtual R operator()(A1, A2) = 0; virtual R operator()(A1, A2) = 0;
@ -135,7 +134,7 @@ public :
@see eoCounter, make_counter @see eoCounter, make_counter
*/ */
template<class R, class A1, class A2> template<class R, class A1, class A2>
eoFunctorBase::binary_function_tag functor_category(const eoBinaryFunctor<R, A1, A2>&) eoFunctorBase::binary_function_tag functor_category(const eoBF<A1, A2, R>&)
{ {
return eoFunctorBase::binary_function_tag(); return eoFunctorBase::binary_function_tag();
} }

View file

@ -18,8 +18,13 @@
#include <eoIndiSelector.h> #include <eoIndiSelector.h>
#include <eoBackInserter.h> #include <eoBackInserter.h>
/**
Base class for breeders using generalized operators, I'm not sure if we
will maintain the generalized operators in their current form, so
it might change.
*/
template<class EOT> template<class EOT>
class eoGOpBreeder: public eoUnaryFunctor<void, eoPop<EOT>&> class eoGOpBreeder: public eoUF<eoPop<EOT>&, void>
{ {
public: public:
/// Default constructor. /// Default constructor.

View file

@ -41,7 +41,7 @@
*/ */
template <class EOT> template <class EOT>
class eoIndiSelector : public eoProcedure<const EOT&> class eoIndiSelector : public eoF<const EOT&>
{ {
public : public :

View file

@ -38,7 +38,7 @@
*/ */
template <class EOT> template <class EOT>
class eoInit : public eoUnaryFunctor<void, EOT&> class eoInit : public eoUF<EOT&, void>
{}; {};
/** /**

View file

@ -38,7 +38,7 @@
new individuals into the (intermediate) population for example. new individuals into the (intermediate) population for example.
*/ */
template <class EOT> template <class EOT>
class eoInserter : public eoUnaryFunctor<eoInserter<EOT>&, const EOT&> class eoInserter : public eoUF<const EOT&, eoInserter<EOT>&>
{ {
public : public :
virtual ~eoInserter() {} virtual ~eoInserter() {}

View file

@ -45,7 +45,7 @@
* next generation. * next generation.
*/ */
template<class Chrom> class eoMerge: public eoBinaryFunctor<void, const eoPop<Chrom>&, eoPop<Chrom>&> template<class Chrom> class eoMerge: public eoBF<const eoPop<Chrom>&, eoPop<Chrom>&, void>
{}; {};
/** /**

View file

@ -79,7 +79,7 @@ private:
/** eoMonOp is the monary operator: genetic operator that takes only one EO */ /** eoMonOp is the monary operator: genetic operator that takes only one EO */
template <class EOType> template <class EOType>
class eoMonOp: public eoOp<EOType>, public eoUnaryFunctor<void, EOType&> class eoMonOp: public eoOp<EOType>, public eoUF<EOType&, void>
{ {
public: public:
/// Ctor /// Ctor
@ -92,7 +92,7 @@ public:
* operator() with two operands, only the first one can be modified * operator() with two operands, only the first one can be modified
*/ */
template<class EOType> template<class EOType>
class eoBinOp: public eoOp<EOType>, public eoBinaryFunctor<void, EOType&, const EOType&> class eoBinOp: public eoOp<EOType>, public eoBF<EOType&, const EOType&, void>
{ {
public: public:
/// Ctor /// Ctor
@ -105,7 +105,7 @@ public:
*/ */
template<class EOType> template<class EOType>
class eoQuadraticOp: public eoOp<EOType>, public eoBinaryFunctor<void, EOType&, EOType&> { class eoQuadraticOp: public eoOp<EOType>, public eoBF<EOType&, EOType&, void> {
public: public:
/// Ctor /// Ctor
eoQuadraticOp() eoQuadraticOp()
@ -129,7 +129,7 @@ class eoInserter;
* eGeneralOp: General genetic operator; for objects used to transform sets * eGeneralOp: General genetic operator; for objects used to transform sets
* of EOs. Nary ("orgy") operators should be derived from this class * of EOs. Nary ("orgy") operators should be derived from this class
Derived from eoBinaryFunctor Derived from eoB(inary)F(unction)
Applies the genetic operator Applies the genetic operator
to a individuals dispensed by an eoIndividualSelector, to a individuals dispensed by an eoIndividualSelector,
and puts the results in the eoIndividualInserter. and puts the results in the eoIndividualInserter.
@ -139,7 +139,7 @@ class eoInserter;
template<class EOT> template<class EOT>
class eoGeneralOp: public eoOp<EOT>, public eoBinaryFunctor<void, eoIndiSelector<EOT>&, eoInserter<EOT>&> class eoGeneralOp: public eoOp<EOT>, public eoBF<eoIndiSelector<EOT>&, eoInserter<EOT>&, void>
{ {
public: public:
/// Ctor that honors its superclass /// Ctor that honors its superclass

View file

@ -38,7 +38,7 @@
* eoReduce: .reduce the new generation to the specified size * eoReduce: .reduce the new generation to the specified size
*/ */
template<class Chrom> class eoReduce: public eoBinaryFunctor<void, eoPop<Chrom>&, unsigned> template<class Chrom> class eoReduce: public eoBF<eoPop<Chrom>&, unsigned, void>
{}; {};
template <class EOT> class eoTruncate : public eoReduce<EOT> template <class EOT> class eoTruncate : public eoReduce<EOT>

View file

@ -41,7 +41,7 @@ so there is an implementation called eoMergeReduce that can be found below
@see eoMerge, eoReduce, eoMergeReduce @see eoMerge, eoReduce, eoMergeReduce
*/ */
template<class EOT> template<class EOT>
class eoReplacement : public eoBinaryFunctor<void, const eoPop<EOT>&, eoPop<EOT>&> class eoReplacement : public eoBF<const eoPop<EOT>&, eoPop<EOT>&, void>
{}; {};
/** /**

View file

@ -37,7 +37,7 @@ the population, the second argument is an eoPopRange, a simple struct
that holds a begin and end iterator to the population that holds a begin and end iterator to the population
*/ */
template<class EOT> template<class EOT>
class eoSelect : public eoBinaryFunctor<void, const eoPop<EOT>&, eoPop<EOT>&> class eoSelect : public eoBF<const eoPop<EOT>&, eoPop<EOT>&, void>
{}; {};
#endif #endif

View file

@ -38,7 +38,7 @@
@see eoSelectMany, eoSelectRandom, eoDetTournament, eoStochTournament, eoProportional @see eoSelectMany, eoSelectRandom, eoDetTournament, eoStochTournament, eoProportional
*/ */
template<class EOT> template<class EOT>
class eoSelectOne : public eoUnaryFunctor<const EOT&, const eoPop<EOT>&> class eoSelectOne : public eoUF<const eoPop<EOT>&, const EOT&>
{ {
public : public :

View file

@ -35,7 +35,7 @@ eoTransform transforms a population by applying genetic operators on
it. it.
*/ */
template<class EOT> template<class EOT>
class eoTransform : public eoUnaryFunctor<void, eoPop<EOT>&> class eoTransform : public eoUF<eoPop<EOT>&, void>
{}; {};
#endif #endif

View file

@ -41,7 +41,7 @@ class eoParam;
will stream or pipe the current values of the parameters to wherever you will stream or pipe the current values of the parameters to wherever you
want it streamed or piped to. want it streamed or piped to.
*/ */
class eoMonitor : public eoProcedure<eoMonitor&> class eoMonitor : public eoF<eoMonitor&>
{ {
public : public :

View file

@ -36,7 +36,7 @@
over the (unsorted) population over the (unsorted) population
*/ */
template <class EOT> template <class EOT>
class eoStatBase : public eoUnaryFunctor<void, const eoPop<EOT>&> class eoStatBase : public eoUF<const eoPop<EOT>&, void>
{}; {};
template <class EOT, class T> template <class EOT, class T>
@ -50,7 +50,7 @@ public :
Base class for statistics calculated over a sorted snapshot of the population Base class for statistics calculated over a sorted snapshot of the population
*/ */
template <class EOT> template <class EOT>
class eoSortedStatBase : public eoUnaryFunctor<void, const vector<const EOT*>&> class eoSortedStatBase : public eoUF<const vector<const EOT*>&, void>
{ {
}; };

View file

@ -34,7 +34,7 @@
eoUpdater is a generic procudere for updating whatever you want. eoUpdater is a generic procudere for updating whatever you want.
Yet again an empty name Yet again an empty name
*/ */
class eoUpdater : public eoProcedure<void> class eoUpdater : public eoF<void>
{}; {};
/** /**

View file

@ -5,12 +5,12 @@
using namespace std; using namespace std;
struct eo1 : public eoProcedure<void> struct eo1 : public eoF<void>
{ {
void operator()(void) {} void operator()(void) {}
}; };
struct eo2 : public eoProcedure<int> struct eo2 : public eoF<int>
{ {
int operator()(void) { return 1; } int operator()(void) { return 1; }
}; };