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

# eoSelectFactory.h

    00001 // eoSelectFactory.h
    00002 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00003
    00004 //-----------------------------------------------------------------------------
    00005 // EOFactory.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 _EOSELECTFACTORY_H
    00027 #define _EOSELECTFACTORY_H
    00028
    00029 #include <eoFactory.h>
    00030 #include <eoRandomSelect.h>
    00031 #include <eoTournament.h>
    00032
    00033 //-----------------------------------------------------------------------------
    00034
    00038 template< class EOT>
    00039 class eoSelectFactory: public eoFactory<eoSelect< EOT> > {
    00040
    00041 public:
    00042
    00044         //{@
    00046         eoSelectFactory( ) {}
    00047
    00049         virtual ~eoSelectFactory() {}
    00051
    00056         virtual eoSelect<EOT>* make(std::istream& _is) {
    00057                 eoSelect<EOT> * selectPtr;
    00058                 std::string objectTypeStr;
    00059                 _is >> objectTypeStr;
    00060                 // All selectors have a rate, the proportion of the original population
    00061                 float rate;
    00062                 _is >> rate;
    00063                 if  ( objectTypeStr == "eoTournament") {
    00064                         // another parameter is necessary
    00065                         unsigned tSize;
    00066                         _is >> tSize;
    00067                         selectPtr = new eoTournament<EOT>( rate, tSize );
    00068                 } else  {
    00069                         if ( objectTypeStr == "eoRandomSelect" ) {
    00070                                 selectPtr = new eoRandomSelect<EOT>( rate );
    00071                         } else {
    00072                                                 throw std::runtime_error( "Incorrect selector type" );
    00073                         }
    00074                 }
    00075                 return selectPtr;
    00076         }
    00077
    00079
    00080         void printOn( std::ostream& _os ) const {};
    00081         void readFrom( std::istream& _is ){};
    00082
    00085
    00086 };
    00087
    00088
    00089 #endif