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
GenPrototype.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 GENPROTOTYPE_H_
28 #define GENPROTOTYPE_H_
29 
30 // standard includes
31 #include <string>
32 #include <map>
33 
34 // forward declarations
35 class Generation;
36 class GenContext;
37 class IValue;
38 class Gen;
39 
40 // gen. alg. includes
41 #include "IRandomStrategy.h"
42 #include "IMutationStrategy.h"
43 #include "restore.h"
44 
45 /**
46  * The GenPrototype class.
47  *
48  * This class is used for group some gens and is needed from the
49  * genFactory. It saves all GenContexte which are use this prototype.
50  * The group of gens becomes whit it an name.
51  *
52  * The prototypes inside the gen. alg. are saved in the GenContext, in
53  * the Gen and in the GenEngine (only here can be deleted!!!).
54  */
55 class GenPrototype {
56 public:
57  /**
58  * constructor to create a GenPrototype. Information which the class need are
59  * the name of the gen pool group, a strategy how can a Gen of this group be
60  * created (for the IValue) and a strategy how can a Gen mutate.
61  *
62  * @param name (string) Name of the group
63  * @param randomStrategy (IRandomStrategy*) the strategy for creating a gen
64  * @param mutationStrategy (IMutationStrategy*) the strategy for mutating a gen
65  */
66  GenPrototype(std::string name, IRandomStrategy* randomStrategy, IMutationStrategy* mutationStrategy);
67 
68  /**
69  * destructor to delete a GenContext.
70  */
71  virtual ~GenPrototype();
72 
73  /**
74  * [inline], [const]
75  * This function gives the name of the prototype back.
76  *
77  * @return (string) the name
78  */
79  inline std::string getName(void)const {return m_name;}
80 
81  /**
82  * [inline], [const]
83  * This function gives a random value (IValue) which are with the randomStrategy is generated back.
84  */
85  inline IValue* getRandomValue(void)const {return m_randomStrategy->getRandomValue();}
86 
87  /**
88  * This function insert a GenContext in the GenPrototype.
89  *
90  * @param generation (Generation*) to which Generation is the Context related.
91  * @param context (GenContext*) the context which should be insert
92  */
93  void insertContext(Generation* generation, GenContext* context);
94 
95  /**
96  * This function gives the context which is relatedto the Eneration "generation" back.
97  *
98  * @param generation (Generation*) the related generation
99  *
100  * @return (GenContext*) the searched context
101  */
102  GenContext* getContext(Generation* generation);
103 
104  /**
105  * [const]
106  * This function mutate the given gen.
107  *
108  * @param context (GenContext*) param is needed by the mutationStrategy
109  * @param individual (Individual*) param is needed by the mutationStrategy
110  * @param oldGen (Gen*) the gen which should be mutate
111  * @param oldContext (GenContext*) param is needed by the mutationStrategy
112  *
113  * @return (Gen*) The new mutated gen
114  */
115  Gen* mutate(GenContext* context, Individual* individual, Gen* oldGen, GenContext* oldContext)const;
116 
117  /**
118  * [const]
119  * This function gives the mutation probability back (from the mutation strategy)
120  *
121  * @return (int) The mutation probability. Maybe the Typ int will be changed.
122  */
123  int getMutationProbability(void)const;
124 
125  /**
126  * restore gene and the value
127  * @param f (FILE*) here is the value inside
128  * @param gene (RESTORE_GA_GENE*) this gene is to restore
129  * @return (bool) true if all ok
130  */
131  bool restoreGene(FILE* f, RESTORE_GA_GENE* gene, std::vector<Gen*>& storage);
132 
133 protected:
134  /**
135  * (string)
136  * the name
137  */
138  std::string m_name;
139 
140  /**
141  * (map<Generation*, GenContext*>)
142  * The storage for the GenContexte. It related the contexte to the generations.
143  */
144  std::map<Generation*,GenContext*> m_context;
145 
146  /**
147  * (IRandomStrategy*)
148  * the random strategy
149  */
151 
152  /**
153  * (IMutationStrategy*)
154  * the mutation strategy
155  */
157 
158 private:
159  /**
160  * disable the default constructor
161  */
162  GenPrototype();
163 };
164 
165 #endif /* GENPROTOTYPE_H_ */
bool restoreGene(FILE *f, RESTORE_GA_GENE *gene, std::vector< Gen * > &storage)
restore gene and the value
Definition: GenPrototype.cpp:78
IValue * getRandomValue(void) const
[inline], [const] This function gives a random value (IValue) which are with the randomStrategy is ge...
Definition: GenPrototype.h:85
virtual ~GenPrototype()
destructor to delete a GenContext.
Definition: GenPrototype.cpp:45
std::map< Generation *, GenContext * > m_context
(map<Generation*, GenContext*>) The storage for the GenContexte.
Definition: GenPrototype.h:144
This interface gives the structur for the mutation of a gen.
Definition: IMutationStrategy.h:39
int getMutationProbability(void) const
[const] This function gives the mutation probability back (from the mutation strategy) ...
Definition: GenPrototype.cpp:74
The Gen class.
Definition: Gen.h:51
The GenContext class.
Definition: GenContext.h:51
GenContext * getContext(Generation *generation)
This function gives the context which is relatedto the Eneration "generation" back.
Definition: GenPrototype.cpp:66
Definition: restore.h:74
IRandomStrategy * m_randomStrategy
(IRandomStrategy*) the random strategy
Definition: GenPrototype.h:150
IMutationStrategy * m_mutationStrategy
(IMutationStrategy*) the mutation strategy
Definition: GenPrototype.h:156
this interface is to create a random IValue.
Definition: IRandomStrategy.h:36
The GenPrototype class.
Definition: GenPrototype.h:55
The Generation class.
Definition: Generation.h:53
This class is a interface for a value which is part of a gen.
Definition: IValue.h:38
std::string getName(void) const
[inline], [const] This function gives the name of the prototype back.
Definition: GenPrototype.h:79
Gen * mutate(GenContext *context, Individual *individual, Gen *oldGen, GenContext *oldContext) const
[const] This function mutate the given gen.
Definition: GenPrototype.cpp:70
std::string m_name
(string) the name
Definition: GenPrototype.h:138
This class represent one individual of the complete gen.
Definition: Individual.h:45
virtual IValue * getRandomValue(void)=0
gives a random IValue back.
void insertContext(Generation *generation, GenContext *context)
This function insert a GenContext in the GenPrototype.
Definition: GenPrototype.cpp:62