00001 /*************************************************************************** 00002 * Copyright (C) 2005-2009 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * guettler@informatik.uni-leipzig.de * 00007 * jhoffmann@informatik.uni-leipzig.de * 00008 * joergweide84@aol.com (robot12) * 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 * This program is distributed in the hope that it will be useful, * 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00018 * GNU General Public License for more details. * 00019 * * 00020 * You should have received a copy of the GNU General Public License * 00021 * along with this program; if not, write to the * 00022 * Free Software Foundation, Inc., * 00023 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00024 *************************************************************************** 00025 * * 00026 * This class is a factory for the class individual. It use the * 00027 * GenFactory to create a new individual, because the individual is a * 00028 * combination of Gens. * 00029 * * 00030 * $Log: SingletonIndividualFactory.h,v $ 00031 * Revision 1.5 2009/07/28 09:38:23 robot12 00032 * update the Singleton::destroy 00033 * 00034 * Revision 1.4 2009/07/21 08:37:58 robot12 00035 * add some comments 00036 * 00037 * Revision 1.3 2009/06/29 15:20:25 robot12 00038 * finishing Individual Factory and add some comments 00039 * 00040 * Revision 1.2 2009/05/11 14:08:52 robot12 00041 * patch some bugfix.... 00042 * 00043 * Revision 1.1 2009/05/04 15:27:55 robot12 00044 * rename of some files and moving files to other positions 00045 * - SingletonGenAlgAPI has one error!!! --> is not ready now 00046 * 00047 * Revision 1.5 2009/04/30 11:35:53 robot12 00048 * some changes: 00049 * - insert a SelectStrategie 00050 * - insert a MutationStrategie 00051 * - reorganisation of the design 00052 * 00053 * Revision 1.4 2009/04/27 10:59:33 robot12 00054 * some implements 00055 * 00056 * 00057 ***************************************************************************/ 00058 00059 #ifndef SINGLETONINDIVIDUALFACTORY_H_ 00060 #define SINGLETONINDIVIDUALFACTORY_H_ 00061 00062 //includes 00063 #include <selforg/randomgenerator.h> 00064 00065 //forward declaration 00066 class Gen; 00067 class Generation; 00068 00069 //ga_tools includes 00070 #include "Individual.h" 00071 00072 /** 00073 * this is a factory for the individual class. It use the SingletonGenFactory to create new individuals. 00074 * It have 2 methods to create a individual. (random and recombination) 00075 * 00076 * Over this is the class as singleton concepted. Only one Factory for a run. 00077 */ 00078 class SingletonIndividualFactory { 00079 public: 00080 /** 00081 * this method gives the one and only existing factory back. 00082 * @return (SingletonIndividualFactory*) the factory 00083 */ 00084 inline static SingletonIndividualFactory* getInstance(void) { 00085 if(m_factory==0)m_factory = new SingletonIndividualFactory; 00086 return m_factory; 00087 } 00088 00089 /** 00090 * destroy the only existing factory 00091 */ 00092 inline static void destroyFactory(void) {if(m_factory!=0){delete m_factory; m_factory=NULL;}} 00093 00094 // 2 methods to create an individual 00095 /** 00096 * random creation by random creation of Gen for every GenPrototype. 00097 * @param name (string) the name of the new individual. Will be automaticly created 00098 * @return (Individual*) the new individual 00099 */ 00100 Individual* createIndividual(std::string name=createName())const; // random 00101 /** 00102 * create a new individual by recombination of the gens of there parents 00103 * @param individual1 (Individual*) parent 1 00104 * @param individual2 (Individual*) parent 2 00105 * @param random (RandGen*) a random generator 00106 * @param name (string) the name of the new individual. Will be automaticly created 00107 * @return (Individual*) the new individual 00108 */ 00109 Individual* createIndividual(Individual* individual1, Individual* individual2, RandGen* random, std::string name=createName())const; // recombinate 00110 00111 private: 00112 /** 00113 * the one and only factory 00114 */ 00115 static SingletonIndividualFactory* m_factory; 00116 00117 /** 00118 * a counter for individual IDs 00119 */ 00120 static int m_number; 00121 00122 /** 00123 * disable the default constructor 00124 * only usable for itself 00125 */ 00126 SingletonIndividualFactory(); 00127 00128 /** 00129 * disable the default destructor 00130 * only usable for itself 00131 */ 00132 virtual ~SingletonIndividualFactory(); 00133 00134 /** 00135 * methode to generate a name for the new individual automatically 00136 * @return (string) the name 00137 */ 00138 inline static std::string createName(void) {std::string s = "Ind ";char buffer[128];sprintf(buffer,"%i",m_number);s+=buffer;return s;} 00139 }; 00140 00141 #endif /* SINGLETONINDIVIDUALFACTORY_H_ */