EvolvingObjects
|
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 00046 template <class F, class External, class ExternalEO = eoExternalEO<F, External> > 00047 class eoExternalInit : public eoInit<ExternalEO> 00048 { 00049 00050 public : 00051 00052 eoExternalInit(External (*_init)(void)) : init(_init) {} 00053 00054 00055 void operator()(ExternalEO& _eo) 00056 { 00057 _eo.External::operator=( (*init)() ); 00058 _eo.invalidate(); 00059 } 00060 00061 private : 00062 00063 External (*init)(void); 00064 }; 00065 00076 template <class F, class External, class ExternalEO = eoExternalEO<F, External> > 00077 class eoExternalEvalFunc : public eoEvalFunc<ExternalEO> 00078 { 00079 public : 00080 00081 eoExternalEvalFunc(F (*_eval)(const External&)) : eval(_eval) {} 00082 00083 void operator()(ExternalEO& eo) 00084 { 00085 if (eo.invalid()) 00086 eo.fitness( (*eval)(eo) ); 00087 } 00088 00089 private : 00090 00091 F (*eval)(const External&); 00092 }; 00093 00107 template <class F, class External, class ExternalEO = eoExternalEO<F, External> > 00108 class eoExternalMonOp : public eoMonOp<ExternalEO> 00109 { 00110 public : 00111 00112 eoExternalMonOp(bool (*_mutate)(External&)) : mutate(_mutate) {} 00113 00114 bool operator()(ExternalEO& eo) 00115 { 00116 return (*mutate)(eo); 00117 } 00118 00119 private : 00120 00121 bool (*mutate)(External&); 00122 }; 00123 00135 template <class F, class External, class ExternalEO = eoExternalEO<F, External> > 00136 class eoExternalBinOp : public eoBinOp<ExternalEO> 00137 { 00138 public : 00139 00140 eoExternalBinOp(bool (*_binop)(External&, const External&)) : binop(_binop) {} 00141 00142 bool operator()(ExternalEO& eo1, const ExternalEO& eo2) 00143 { 00144 return (*binop)(eo1, eo2); 00145 } 00146 00147 private : 00148 00149 bool (*binop)(External&, const External&); 00150 }; 00151 00163 template <class F, class External, class ExternalEO = eoExternalEO<F, External> > 00164 class eoExternalQuadOp : public eoQuadOp<ExternalEO> 00165 { 00166 public : 00167 00168 eoExternalQuadOp(bool (*_quadop)(External&, External&)) : quadop(_quadop) {} 00169 00170 bool operator()(ExternalEO& eo1, ExternalEO& eo2) 00171 { 00172 return (*quadop)(eo1, eo2); 00173 } 00174 00175 private : 00176 00177 bool (*quadop)(External&, External&); 00178 }; 00179 00180 #endif