EvolvingObjects
eoBitOpFactory.h
00001 // eoBitOpFactory.h
00002 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00003 
00004 //-----------------------------------------------------------------------------
00005 // eoOpFactory.h
00006 // (c) GeNeura Team, 1998
00007 /*
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Lesser General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public
00019     License along with this library; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00023  */
00024 //-----------------------------------------------------------------------------
00025 
00026 #ifndef _EOBITOPFACTORY_H
00027 #define _EOBITOPFACTORY_H
00028 
00029 #include <eoFactory.h>
00030 #include <ga/eoBitOp.h>
00031 
00032 //-----------------------------------------------------------------------------
00033 
00041 template< class EOT>
00042 class eoBitOpFactory: public eoFactory<EOT>
00043 {
00044 
00045 public:
00046 
00048         //{@
00050         eoBitOpFactory( ) {};
00051 
00053         virtual ~eoBitOpFactory() {};
00055 
00066         virtual eoOp<EOT>* make(std::istream& _is)
00067     {
00068                 eoOp<EOT> * opPtr = NULL;
00069                 try {
00070                         opPtr = eoFactory<EOT>::make( _is );
00071                 } catch ( const std::string& objectTypeStr ) {
00072                         if ( objectTypeStr == "eoBinBitFlip" ) {
00073                                 opPtr = new eoOneBitFlip<EOT>( );
00074                         }
00075                         // handles old operator names as well as new ones
00076                         if ( objectTypeStr == "eoOneBitFlip" ) {
00077                                 opPtr = new eoOneBitFlip<EOT>( );
00078                         }
00079 
00080                         // Standard BitFilp Mutation
00081                         if ( objectTypeStr == "eoBinMutation" ) {
00082                                 float rate;
00083                                 _is >> rate;
00084                                 opPtr = new eoBitMutation<EOT>( rate );
00085                         }
00086                         if ( objectTypeStr == "eoBitMutation" ) {
00087                                 float rate;
00088                                 _is >> rate;
00089                                 opPtr = new eoBitMutation<EOT>( rate );
00090                         }
00091 
00092                         // Bit inversion
00093                         if ( objectTypeStr == "eoBinInversion" ) {
00094                                 opPtr = new eoBitInversion<EOT>( );
00095                         }
00096                         if ( objectTypeStr == "eoBitInversion" ) {
00097                                 opPtr = new eoBitInversion<EOT>( );
00098                         }
00099 
00100                         // Next binary value
00101                         if ( objectTypeStr == "eoBinNext" ) {
00102                                 opPtr = new eoBitNext<EOT>( );
00103                         }
00104                         if ( objectTypeStr == "eoBitNext" ) {
00105                                 opPtr = new eoBitNext<EOT>( );
00106                         }
00107 
00108                         // Previous binary value
00109                         if ( objectTypeStr == "eoBinPrev" ) {
00110                                 opPtr = new eoBitPrev<EOT>( );
00111                         }
00112                         if ( objectTypeStr == "eoBitPrev" ) {
00113                                 opPtr = new eoBitPrev<EOT>( );
00114                         }
00115 
00116                         // 1 point Xover
00117                         if ( objectTypeStr == "eoBinCrossover" ) {
00118                                 opPtr = new eo1PtBitXover<EOT>( );
00119                         }
00120                         if ( objectTypeStr == "eo1PtBitXover" ) {
00121                                 opPtr = new eo1PtBitXover<EOT>( );
00122                         }
00123 
00124                         // Npts Xover
00125                         if ( objectTypeStr == "eoBinNxOver" ) {
00126                                 unsigned nPoints;
00127                                 _is >> nPoints;
00128                                 opPtr = new eoNPtsBitXover<EOT>( nPoints );
00129                         }
00130                         if ( objectTypeStr == "eoNPtsBitXover" ) {
00131                                 unsigned nPoints;
00132                                 _is >> nPoints;
00133                                 opPtr = new eoNPtsBitXover<EOT>( nPoints );
00134                         }
00135 
00136                         // Gene Xover (obsolete)
00137                         if ( objectTypeStr == "eoBinGxOver" ) {
00138                                 unsigned geneSize, nPoints;
00139                                 _is >> geneSize >> nPoints;
00140                                 opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
00141                         }
00142                         if ( objectTypeStr == "eoBitGxOver" ) {
00143                                 unsigned geneSize, nPoints;
00144                                 _is >> geneSize >> nPoints;
00145                                 opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
00146                         }
00147 
00148                         // Uniform Xover
00149                         if ( objectTypeStr == "eoBinUxOver" ) {
00150                                 float rate;
00151                                 _is >> rate;
00152                                 opPtr = new eoUBitXover<EOT>( rate );
00153                         }
00154                         if ( objectTypeStr == "eoUBitXover" ) {
00155                                 float rate;
00156                                 _is >> rate;
00157                                 opPtr = new eoUBitXover<EOT>( rate );
00158                         }
00159 
00160                         // nothing read!
00161                         if ( !opPtr ) { // to be caught by the upper level
00162                                 throw objectTypeStr;
00163                         }
00164                 }
00165                 return opPtr;
00166         };
00167 
00168 
00169 };
00170 
00171 
00172 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends