Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SingletonGenFactory.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008-2011 LpzRobots development team *
3  * Joerg Weider <joergweide84 at aol dot com> (robot12) *
4  * Georg Martius <georg dot martius at web dot de> *
5  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
6  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
7  * Ralf Der <ralfder at mis dot mpg dot de> *
8  * Joern Hoffmann <jhoffmann at informatik dot uni-leipzig dot de *
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24  * *
25  ***************************************************************************/
26 
27 #ifndef SINGLETONGENFACTORY_H_
28 #define SINGLETONGENFACTORY_H_
29 
30 //forward declaration
31 class GenContext;
32 class Gen;
33 class Individual;
34 class GenPrototype;
35 class IValue;
36 
37 /**
38  * This is the factory for the class Gen. It gives 3 Methodes to generate new gens. (random,value and mutation)
39  * Over this is the class as singleton concepted. Only one Factory for a run.
40  *
41  * It use by every method the GenPrototype to be independent from the type of the Gen.
42  */
44 public:
45  /**
46  * this method is to become the only existing factory
47  * @return (SingletonGenFactory*) the one and only factory
48  */
49  inline static SingletonGenFactory* getInstance(void) {if(m_factory==0)m_factory = new SingletonGenFactory();return m_factory;}
50 
51  /**
52  * this method is to destroy the one and only factory.
53  */
54  inline static void destroyGenFactory(void) {if(m_factory!=0){delete m_factory;m_factory=0;}}
55 
56  // 3 methodes to create an Gen
57  /**
58  * random generation of a new gen.
59  * @param context (GenContext*) the context of the new Gen
60  * @param individual (Individual*) the individual, where the gen is part of.
61  * @param prototype (GenPrototype*) the prototype of the gen, which should be create.
62  * @return (Gen*) the new Gen
63  */
64  Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype)const;
65  /**
66  * this function generate a new Gen by mutate a old Gen
67  * @param context (GenContext*) the context of the new Gen
68  * @param individual (Individual*) the individual, where the gen is part of.
69  * @param prototype (GenPrototype*) the prototype of the gen, which should be create.
70  * @param oldContext (GenContext*) the Context of the old Gen
71  * @param oldIndividual (Individual*) the individua, where the olg gen is part of.
72  * @param oldGen (Gen*) the old Gen
73  * @param mutate (bool) should be mutate?
74  * @return (Gen*) the new (or old gen)
75  */
76  Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype, GenContext* oldContext, Individual* oldIndividual, Gen* oldGen, bool mutate=false)const; // copy + mutation
77  /**
78  * create a new Gen by a giving value
79  * @param context (GenContext*) the context of the new Gen
80  * @param individual (Individual*) the individual, where the gen is part of.
81  * @param prototype (GenPrototype*) the prototype of the gen, which should be create.
82  * @param value (IValue*) the value of the new gen
83  * @return
84  */
85  Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype, IValue* value); // value
86 
87  //reset m_number inside restore
88  /**
89  * set the member variable m_number to number
90  * @param number (int) the new value
91  */
92  inline void setNumber(int number) {m_number=number;}
93 
94 private:
95  /**
96  * the one and only factory
97  */
98  static SingletonGenFactory* m_factory;
99 
100  /**
101  * counter for giving Gens a individual ID
102  */
103  static int m_number;
104 
105  /**
106  * disable the default constructor
107  */
109 
110  /**
111  * disable destructor
112  */
113  virtual ~SingletonGenFactory();
114 };
115 
116 #endif /* SINGLETONGENFACTORY_H_ */
This is the factory for the class Gen.
Definition: SingletonGenFactory.h:43
The Gen class.
Definition: Gen.h:51
The GenContext class.
Definition: GenContext.h:51
static void destroyGenFactory(void)
this method is to destroy the one and only factory.
Definition: SingletonGenFactory.h:54
The GenPrototype class.
Definition: GenPrototype.h:55
This class is a interface for a value which is part of a gen.
Definition: IValue.h:38
void setNumber(int number)
set the member variable m_number to number
Definition: SingletonGenFactory.h:92
static SingletonGenFactory * getInstance(void)
this method is to become the only existing factory
Definition: SingletonGenFactory.h:49
Gen * createGen(GenContext *context, Individual *individual, GenPrototype *prototype) const
random generation of a new gen.
Definition: SingletonGenFactory.cpp:48
This class represent one individual of the complete gen.
Definition: Individual.h:45