EvolvingObjects
|
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 00042 template< class EOT> 00043 class eoSelectFactory: public eoFactory<eoSelect< EOT> > { 00044 00045 public: 00046 00048 //{@ 00050 eoSelectFactory( ) {} 00051 00053 virtual ~eoSelectFactory() {} 00055 00060 virtual eoSelect<EOT>* make(std::istream& _is) { 00061 eoSelect<EOT> * selectPtr; 00062 std::string objectTypeStr; 00063 _is >> objectTypeStr; 00064 // All selectors have a rate, the proportion of the original population 00065 float rate; 00066 _is >> rate; 00067 if ( objectTypeStr == "eoTournament") { 00068 // another parameter is necessary 00069 unsigned tSize; 00070 _is >> tSize; 00071 selectPtr = new eoTournament<EOT>( rate, tSize ); 00072 } else { 00073 if ( objectTypeStr == "eoRandomSelect" ) { 00074 selectPtr = new eoRandomSelect<EOT>( rate ); 00075 } else { 00076 throw std::runtime_error( "Incorrect selector type" ); 00077 } 00078 } 00079 return selectPtr; 00080 } 00081 00083 00084 void printOn( std::ostream& _os ) const {}; 00085 void readFrom( std::istream& _is ){}; 00086 00089 00090 }; 00091 00092 00093 #endif