00001 /*************************************************************************** 00002 * Copyright (C) 2008-2011 LpzRobots development team * 00003 * Joerg Weider <joergweide84 at aol dot com> (robot12) * 00004 * Georg Martius <georg dot martius at web dot de> * 00005 * Frank Guettler <guettler at informatik dot uni-leipzig dot de * 00006 * Frank Hesse <frank at nld dot ds dot mpg dot de> * 00007 * Ralf Der <ralfder at mis dot mpg dot de> * 00008 * Joern Hoffmann <jhoffmann at informatik dot uni-leipzig dot de * 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 00027 #ifndef SINGLETONGENFACTORY_H_ 00028 #define SINGLETONGENFACTORY_H_ 00029 00030 //forward declaration 00031 class GenContext; 00032 class Gen; 00033 class Individual; 00034 class GenPrototype; 00035 class IValue; 00036 00037 /** 00038 * This is the factory for the class Gen. It gives 3 Methodes to generate new gens. (random,value and mutation) 00039 * Over this is the class as singleton concepted. Only one Factory for a run. 00040 * 00041 * It use by every method the GenPrototype to be independent from the type of the Gen. 00042 */ 00043 class SingletonGenFactory { 00044 public: 00045 /** 00046 * this method is to become the only existing factory 00047 * @return (SingletonGenFactory*) the one and only factory 00048 */ 00049 inline static SingletonGenFactory* getInstance(void) {if(m_factory==0)m_factory = new SingletonGenFactory();return m_factory;} 00050 00051 /** 00052 * this method is to destroy the one and only factory. 00053 */ 00054 inline static void destroyGenFactory(void) {if(m_factory!=0){delete m_factory;m_factory=0;}} 00055 00056 // 3 methodes to create an Gen 00057 /** 00058 * random generation of a new gen. 00059 * @param context (GenContext*) the context of the new Gen 00060 * @param individual (Individual*) the individual, where the gen is part of. 00061 * @param prototype (GenPrototype*) the prototype of the gen, which should be create. 00062 * @return (Gen*) the new Gen 00063 */ 00064 Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype)const; 00065 /** 00066 * this function generate a new Gen by mutate a old Gen 00067 * @param context (GenContext*) the context of the new Gen 00068 * @param individual (Individual*) the individual, where the gen is part of. 00069 * @param prototype (GenPrototype*) the prototype of the gen, which should be create. 00070 * @param oldContext (GenContext*) the Context of the old Gen 00071 * @param oldIndividual (Individual*) the individua, where the olg gen is part of. 00072 * @param oldGen (Gen*) the old Gen 00073 * @param mutate (bool) should be mutate? 00074 * @return (Gen*) the new (or old gen) 00075 */ 00076 Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype, GenContext* oldContext, Individual* oldIndividual, Gen* oldGen, bool mutate=false)const; // copy + mutation 00077 /** 00078 * create a new Gen by a giving value 00079 * @param context (GenContext*) the context of the new Gen 00080 * @param individual (Individual*) the individual, where the gen is part of. 00081 * @param prototype (GenPrototype*) the prototype of the gen, which should be create. 00082 * @param value (IValue*) the value of the new gen 00083 * @return 00084 */ 00085 Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype, IValue* value); // value 00086 00087 //reset m_number inside restore 00088 /** 00089 * set the member variable m_number to number 00090 * @param number (int) the new value 00091 */ 00092 inline void setNumber(int number) {m_number=number;} 00093 00094 private: 00095 /** 00096 * the one and only factory 00097 */ 00098 static SingletonGenFactory* m_factory; 00099 00100 /** 00101 * counter for giving Gens a individual ID 00102 */ 00103 static int m_number; 00104 00105 /** 00106 * disable the default constructor 00107 */ 00108 SingletonGenFactory(); 00109 00110 /** 00111 * disable destructor 00112 */ 00113 virtual ~SingletonGenFactory(); 00114 }; 00115 00116 #endif /* SINGLETONGENFACTORY_H_ */