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
GenContext.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 GENCONTEXT_H_
28 #define GENCONTEXT_H_
29 
30 // standard includes
31 #include <vector>
32 #include <algorithm>
33 #include <selforg/inspectable.h>
34 
35 // forward declarations
36 class Gen;
37 class GenPrototype;
38 
39 // gen. alg. includes
40 
41 /**
42  * The GenContext class.
43  * This class is used for create a context for some gens. This mean it
44  * saves all gens which have the same prototype and are a part of an
45  * individual which are in ONE generation. It can be useful for some
46  * statistical calculation or for optimizing the mutation factor.
47  *
48  * The Gen Context is inside the gen. alg. only saved in the
49  * GenPrototype.
50  */
51 class GenContext : public Inspectable {
52 public:
53  /**
54  * constructor to create a GenContext. Information which the class need are
55  * the prototype (name an group of gens).
56  *
57  * @param prototype (GenPrototype*) Pointer to the prototype.
58  */
59  GenContext(GenPrototype* prototype);
60 
61  /**
62  * destructor to delete a GenContext.
63  */
64  virtual ~GenContext();
65 
66  /**
67  * [inline], [const]
68  *
69  * This function gives the prototype for hich are the context is make back.
70  *
71  * @return (GenPrototype*) the prototype
72  */
73  inline GenPrototype* getPrototype(void)const {return m_prototype;}
74 
75  /**
76  * [inline]
77  * This function add a Gen to the Context.
78  *
79  * @param gen (Gen*) the new Gen, which should be added
80  */
81  inline void addGen(Gen* gen) {m_storage.push_back(gen);}
82 
83  /**
84  * [inline]
85  * This function removes one gen which is saved inside the context (but NO deleting of the gen!!!).
86  *
87  * param gen (Gen*) The gen, which should be removed
88  */
89  inline void removeGen(Gen* gen) {std::vector<Gen*>::iterator itr = std::find(m_storage.begin(),m_storage.end(),gen); m_storage.erase(itr);}
90 
91  /**
92  * [inline], [const]
93  * This function gives all gens which are saved in this context back.
94  *
95  * @return (vector<Gen*>&) list with all gens.
96  */
97  inline const std::vector<Gen*>& getGene(void)const {return m_storage;}
98 
99  /**
100  * This function makes an update on the statistical values
101  * @param factor (double) this factor is normal 1.5 and is for the whisker distance in the analysation
102  */
103  void update(double factor=1.5);
104 
105  /**
106  * restore all GenContext
107  * @return (bool) if all ok
108  */
109  static bool restore();
110 
111 protected:
112  /**
113  * (vector<Gen*>
114  * Storage for all Genes which are saved in this context.
115  */
116  std::vector<Gen*> m_storage;
117 
118  /**
119  * (GenPrototyp*)
120  * the prototype for which are the context is.
121  */
123 
124  /**
125  * the min value of the gens
126  */
127  double m_min;
128 
129  /**
130  * the under whisker of the gens
131  */
132  double m_w1;
133 
134  /**
135  * the under quartil of the gens
136  */
137  double m_q1;
138 
139  /**
140  * the median of the gens
141  */
142  double m_med;
143 
144  /**
145  * the average of the gens
146  */
147  double m_avg;
148 
149  /**
150  * the upper quartil of the gens
151  */
152  double m_q3;
153 
154  /**
155  * the upper whisker of the gens
156  */
157  double m_w3;
158 
159  /**
160  *
161  * the max value of the gens
162  */
163  double m_max;
164 
165  /*int m_numExtream;
166  std::vector<double> m_extream;*/
167 
168 private:
169  /**
170  * disable default constructor
171  */
172  GenContext();
173 };
174 
175 #endif /* GENCONTEXT_H_ */
void removeGen(Gen *gen)
[inline] This function removes one gen which is saved inside the context (but NO deleting of the gen!...
Definition: GenContext.h:89
double m_med
the median of the gens
Definition: GenContext.h:142
double m_q1
the under quartil of the gens
Definition: GenContext.h:137
double m_avg
the average of the gens
Definition: GenContext.h:147
The Gen class.
Definition: Gen.h:51
The GenContext class.
Definition: GenContext.h:51
double m_w3
the upper whisker of the gens
Definition: GenContext.h:157
GenPrototype * getPrototype(void) const
[inline], [const]
Definition: GenContext.h:73
std::vector< Gen * > m_storage
(vector<Gen*> Storage for all Genes which are saved in this context.
Definition: GenContext.h:116
virtual ~GenContext()
destructor to delete a GenContext.
Definition: GenContext.cpp:58
void update(double factor=1.5)
This function makes an update on the statistical values.
Definition: GenContext.cpp:62
const std::vector< Gen * > & getGene(void) const
[inline], [const] This function gives all gens which are saved in this context back.
Definition: GenContext.h:97
The GenPrototype class.
Definition: GenPrototype.h:55
Interface for inspectable objects.
Definition: inspectable.h:48
double m_min
the min value of the gens
Definition: GenContext.h:127
double m_max
the max value of the gens
Definition: GenContext.h:163
double m_w1
the under whisker of the gens
Definition: GenContext.h:132
void addGen(Gen *gen)
[inline] This function add a Gen to the Context.
Definition: GenContext.h:81
static bool restore()
restore all GenContext
Definition: GenContext.cpp:85
double m_q3
the upper quartil of the gens
Definition: GenContext.h:152
GenPrototype * m_prototype
(GenPrototyp*) the prototype for which are the context is.
Definition: GenContext.h:122