EvolvingObjects
eoOp.h
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 //-----------------------------------------------------------------------------
00003 // eoOp.h
00004 // (c) GeNeura Team, 1998
00005 /*
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00021     CVS Info: $Date: 2004-08-10 17:19:46 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoOp.h,v 1.29 2004-08-10 17:19:46 jmerelo Exp $ $Author: jmerelo $
00022  */
00023 //-----------------------------------------------------------------------------
00024 
00025 #ifndef _eoOp_H
00026 #define _eoOp_H
00027 
00028 #include <eoObject.h>
00029 #include <eoPrintable.h>
00030 #include <eoFunctor.h>
00031 #include <utils/eoRNG.h>
00032 
00057 
00086 template<class EOType>
00087 class eoOp
00088 {
00089 public:
00091   enum OpType { unary = 0, binary = 1, quadratic = 2, general = 3};
00093 
00095   eoOp(OpType _type)
00096     :opType( _type ) {};
00097 
00099   eoOp( const eoOp& _eop )
00100     :opType( _eop.opType ) {};
00101 
00103   virtual ~eoOp(){};
00104 
00106   OpType getType() const {return opType;};
00107 
00108 private:
00109 
00111   OpType opType;
00112 };
00113 
00119 template <class EOType>
00120 class eoMonOp: public eoOp<EOType>, public eoUF<EOType&, bool>
00121 {
00122 public:
00124   eoMonOp()
00125     : eoOp<EOType>( eoOp<EOType>::unary ) {};
00126   virtual std::string className() const {return "eoMonOp";};
00127 };
00128 
00129 
00135 template<class EOType>
00136 class eoBinOp: public eoOp<EOType>, public eoBF<EOType&, const EOType&, bool>
00137 {
00138 public:
00140   eoBinOp()
00141       :eoOp<EOType>( eoOp<EOType>::binary ) {};
00142   virtual std::string className() const {return "eoBinOp";};
00143 };
00144 
00150 template<class EOType>
00151 class eoQuadOp: public eoOp<EOType>, public eoBF<EOType&, EOType&, bool> {
00152 public:
00154   eoQuadOp()
00155     :eoOp<EOType>( eoOp<EOType>::quadratic ) {};
00156   virtual std::string className() const {return "eoQuadOp";};
00157 };
00158 
00161 template <class EOT>
00162 class eoQuad2BinOp: public eoBinOp<EOT>
00163 {
00164 public:
00168   eoQuad2BinOp(eoQuadOp<EOT> & _quadOp) : quadOp(_quadOp) {}
00169 
00172   bool operator()(EOT & _eo1, const EOT & _eo2)
00173   {
00174     EOT eoTmp = _eo2;              // a copy that can be modified
00175     // if the embedded eoQuadOp is not symmetrical,
00176     // the result might be biased - hence the flip ...
00177     if (eo::rng.flip(0.5))
00178       return quadOp(_eo1, eoTmp);          // both are modified - that's all
00179     else
00180       return quadOp(eoTmp, _eo1);          // both are modified - that's all
00181   }
00182 
00183 private:
00184   eoQuadOp<EOT> & quadOp;
00185 };
00186 
00187 #endif
00188 
 All Classes Namespaces Files Functions Variables Typedefs Friends