Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# 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
    00038 template< class EOT>
    00039 class eoBitOpFactory: public eoFactory<EOT>
    00040 {
    00041
    00042 public:
    00043
    00045         //{@
    00047         eoBitOpFactory( ) {};
    00048
    00050         virtual ~eoBitOpFactory() {};
    00052
    00063         virtual eoOp<EOT>* make(std::istream& _is)
    00064     {
    00065                 eoOp<EOT> * opPtr = NULL;
    00066                 try {
    00067                         opPtr = eoFactory<EOT>::make( _is );
    00068                 } catch ( const std::string& objectTypeStr ) {
    00069                         if ( objectTypeStr == "eoBinBitFlip" ) {
    00070                                 opPtr = new eoOneBitFlip<EOT>( );
    00071                         }
    00072                         // handles old operator names as well as new ones
    00073                         if ( objectTypeStr == "eoOneBitFlip" ) {
    00074                                 opPtr = new eoOneBitFlip<EOT>( );
    00075                         }
    00076
    00077                         // Standard BitFilp Mutation
    00078                         if ( objectTypeStr == "eoBinMutation" ) {
    00079                                 float rate;
    00080                                 _is >> rate;
    00081                                 opPtr = new eoBitMutation<EOT>( rate );
    00082                         }
    00083                         if ( objectTypeStr == "eoBitMutation" ) {
    00084                                 float rate;
    00085                                 _is >> rate;
    00086                                 opPtr = new eoBitMutation<EOT>( rate );
    00087                         }
    00088
    00089                         // Bit inversion
    00090                         if ( objectTypeStr == "eoBinInversion" ) {
    00091                                 opPtr = new eoBitInversion<EOT>( );
    00092                         }
    00093                         if ( objectTypeStr == "eoBitInversion" ) {
    00094                                 opPtr = new eoBitInversion<EOT>( );
    00095                         }
    00096
    00097                         // Next binary value
    00098                         if ( objectTypeStr == "eoBinNext" ) {
    00099                                 opPtr = new eoBitNext<EOT>( );
    00100                         }
    00101                         if ( objectTypeStr == "eoBitNext" ) {
    00102                                 opPtr = new eoBitNext<EOT>( );
    00103                         }
    00104
    00105                         // Previous binary value
    00106                         if ( objectTypeStr == "eoBinPrev" ) {
    00107                                 opPtr = new eoBitPrev<EOT>( );
    00108                         }
    00109                         if ( objectTypeStr == "eoBitPrev" ) {
    00110                                 opPtr = new eoBitPrev<EOT>( );
    00111                         }
    00112
    00113                         // 1 point Xover
    00114                         if ( objectTypeStr == "eoBinCrossover" ) {
    00115                                 opPtr = new eo1PtBitXover<EOT>( );
    00116                         }
    00117                         if ( objectTypeStr == "eo1PtBitXover" ) {
    00118                                 opPtr = new eo1PtBitXover<EOT>( );
    00119                         }
    00120
    00121                         // Npts Xover
    00122                         if ( objectTypeStr == "eoBinNxOver" ) {
    00123                                 unsigned nPoints;
    00124                                 _is >> nPoints;
    00125                                 opPtr = new eoNPtsBitXover<EOT>( nPoints );
    00126                         }
    00127                         if ( objectTypeStr == "eoNPtsBitXover" ) {
    00128                                 unsigned nPoints;
    00129                                 _is >> nPoints;
    00130                                 opPtr = new eoNPtsBitXover<EOT>( nPoints );
    00131                         }
    00132
    00133                         // Gene Xover (obsolete)
    00134                         if ( objectTypeStr == "eoBinGxOver" ) {
    00135                                 unsigned geneSize, nPoints;
    00136                                 _is >> geneSize >> nPoints;
    00137                                 opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
    00138                         }
    00139                         if ( objectTypeStr == "eoBitGxOver" ) {
    00140                                 unsigned geneSize, nPoints;
    00141                                 _is >> geneSize >> nPoints;
    00142                                 opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
    00143                         }
    00144
    00145                         // Uniform Xover
    00146                         if ( objectTypeStr == "eoBinUxOver" ) {
    00147                                 float rate;
    00148                                 _is >> rate;
    00149                                 opPtr = new eoUBitXover<EOT>( rate );
    00150                         }
    00151                         if ( objectTypeStr == "eoUBitXover" ) {
    00152                                 float rate;
    00153                                 _is >> rate;
    00154                                 opPtr = new eoUBitXover<EOT>( rate );
    00155                         }
    00156
    00157                         // nothing read!
    00158                         if ( !opPtr ) { // to be caught by the upper level
    00159                                 throw objectTypeStr;
    00160                         }
    00161                 }
    00162                 return opPtr;
    00163         };
    00164
    00165
    00166 };
    00167
    00168
    00169 #endif
    00170