# eoExternalOpFunctions.h

    00001 /* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003   -----------------------------------------------------------------------------
    00004   eoExternalOpFunc.h
    00005         Defines eoExternalInitOpFunc, eoExternalMonOpFunc, eoExternalBinOpFunc, eoExternalQuadOpFunc
    00006         that are used to wrap a function pointer to externally defined initialization
    00007         and 'genetic' operators
    00008
    00009  (c) Maarten Keijzer (mkeijzer@mad.scientist.com) and GeNeura Team, 1999, 2000
    00010
    00011     This library is free software; you can redistribute it and/or
    00012     modify it under the terms of the GNU Lesser General Public
    00013     License as published by the Free Software Foundation; either
    00014     version 2 of the License, or (at your option) any later version.
    00015
    00016     This library is distributed in the hope that it will be useful,
    00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00019     Lesser General Public License for more details.
    00020
    00021     You should have received a copy of the GNU Lesser General Public
    00022     License along with this library; if not, write to the Free Software
    00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00024
    00025     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
    00026  */
    00027
    00028 #ifndef eoExternalOpFunc_h
    00029 #define eoExternalOpFunc_h
    00030
    00031 #include <other/eoExternalEO.h>
    00032 #include <eoOp.h>
    00033 #include <eoInit.h>
    00034 #include <eoEvalFunc.h>
    00035
    00044 template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
    00045 class eoExternalInit : public eoInit<ExternalEO>
    00046 {
    00047
    00048 public :
    00049
    00050     eoExternalInit(External (*_init)(void)) : init(_init) {}
    00051
    00052
    00053     void operator()(ExternalEO& _eo)
    00054     {
    00055         _eo.External::operator=( (*init)() );
    00056         _eo.invalidate();
    00057     }
    00058
    00059 private :
    00060
    00061     External (*init)(void);
    00062 };
    00063
    00072 template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
    00073 class eoExternalEvalFunc : public eoEvalFunc<ExternalEO>
    00074 {
    00075     public :
    00076
    00077     eoExternalEvalFunc(F (*_eval)(const External&)) : eval(_eval) {}
    00078
    00079     void operator()(ExternalEO& eo)
    00080     {
    00081         if (eo.invalid())
    00082             eo.fitness( (*eval)(eo) );
    00083     }
    00084
    00085     private :
    00086
    00087     F (*eval)(const External&);
    00088 };
    00089
    00101 template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
    00102 class eoExternalMonOp : public eoMonOp<ExternalEO>
    00103 {
    00104     public :
    00105
    00106     eoExternalMonOp(bool (*_mutate)(External&)) : mutate(_mutate) {}
    00107
    00108     bool operator()(ExternalEO& eo)
    00109     {
    00110         return (*mutate)(eo);
    00111     }
    00112
    00113     private :
    00114
    00115     bool (*mutate)(External&);
    00116 };
    00117
    00127 template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
    00128 class eoExternalBinOp : public eoBinOp<ExternalEO>
    00129 {
    00130     public :
    00131
    00132     eoExternalBinOp(bool (*_binop)(External&, const External&)) : binop(_binop) {}
    00133
    00134     bool operator()(ExternalEO& eo1, const ExternalEO& eo2)
    00135     {
    00136         return (*binop)(eo1, eo2);
    00137     }
    00138
    00139     private :
    00140
    00141     bool (*binop)(External&, const External&);
    00142 };
    00143
    00153 template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
    00154 class eoExternalQuadOp : public eoQuadOp<ExternalEO>
    00155 {
    00156     public :
    00157
    00158     eoExternalQuadOp(bool (*_quadop)(External&, External&)) : quadop(_quadop) {}
    00159
    00160     bool operator()(ExternalEO& eo1, ExternalEO& eo2)
    00161     {
    00162         return (*quadop)(eo1, eo2);
    00163     }
    00164
    00165     private :
    00166
    00167     bool (*quadop)(External&, External&);
    00168 };
    00169
    00170 #endif