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 GENCONTEXT_H_ 00028 #define GENCONTEXT_H_ 00029 00030 // standard includes 00031 #include <vector> 00032 #include <algorithm> 00033 #include <selforg/inspectable.h> 00034 00035 // forward declarations 00036 class Gen; 00037 class GenPrototype; 00038 00039 // gen. alg. includes 00040 00041 /** 00042 * The GenContext class. 00043 * This class is used for create a context for some gens. This mean it 00044 * saves all gens which have the same prototype and are a part of an 00045 * individual which are in ONE generation. It can be useful for some 00046 * statistical calculation or for optimizing the mutation factor. 00047 * 00048 * The Gen Context is inside the gen. alg. only saved in the 00049 * GenPrototype. 00050 */ 00051 class GenContext : public Inspectable { 00052 public: 00053 /** 00054 * constructor to create a GenContext. Information which the class need are 00055 * the prototype (name an group of gens). 00056 * 00057 * @param prototype (GenPrototype*) Pointer to the prototype. 00058 */ 00059 GenContext(GenPrototype* prototype); 00060 00061 /** 00062 * destructor to delete a GenContext. 00063 */ 00064 virtual ~GenContext(); 00065 00066 /** 00067 * [inline], [const] 00068 * 00069 * This function gives the prototype for hich are the context is make back. 00070 * 00071 * @return (GenPrototype*) the prototype 00072 */ 00073 inline GenPrototype* getPrototype(void)const {return m_prototype;} 00074 00075 /** 00076 * [inline] 00077 * This function add a Gen to the Context. 00078 * 00079 * @param gen (Gen*) the new Gen, which should be added 00080 */ 00081 inline void addGen(Gen* gen) {m_storage.push_back(gen);} 00082 00083 /** 00084 * [inline] 00085 * This function removes one gen which is saved inside the context (but NO deleting of the gen!!!). 00086 * 00087 * param gen (Gen*) The gen, which should be removed 00088 */ 00089 inline void removeGen(Gen* gen) {std::vector<Gen*>::iterator itr = std::find(m_storage.begin(),m_storage.end(),gen); m_storage.erase(itr);} 00090 00091 /** 00092 * [inline], [const] 00093 * This function gives all gens which are saved in this context back. 00094 * 00095 * @return (vector<Gen*>&) list with all gens. 00096 */ 00097 inline const std::vector<Gen*>& getGene(void)const {return m_storage;} 00098 00099 /** 00100 * This function makes an update on the statistical values 00101 * @param factor (double) this factor is normal 1.5 and is for the whisker distance in the analysation 00102 */ 00103 void update(double factor=1.5); 00104 00105 /** 00106 * restore all GenContext 00107 * @return (bool) if all ok 00108 */ 00109 static bool restore(); 00110 00111 protected: 00112 /** 00113 * (vector<Gen*> 00114 * Storage for all Genes which are saved in this context. 00115 */ 00116 std::vector<Gen*> m_storage; 00117 00118 /** 00119 * (GenPrototyp*) 00120 * the prototype for which are the context is. 00121 */ 00122 GenPrototype* m_prototype; 00123 00124 /** 00125 * the min value of the gens 00126 */ 00127 double m_min; 00128 00129 /** 00130 * the under whisker of the gens 00131 */ 00132 double m_w1; 00133 00134 /** 00135 * the under quartil of the gens 00136 */ 00137 double m_q1; 00138 00139 /** 00140 * the median of the gens 00141 */ 00142 double m_med; 00143 00144 /** 00145 * the average of the gens 00146 */ 00147 double m_avg; 00148 00149 /** 00150 * the upper quartil of the gens 00151 */ 00152 double m_q3; 00153 00154 /** 00155 * the upper whisker of the gens 00156 */ 00157 double m_w3; 00158 00159 /** 00160 * 00161 * the max value of the gens 00162 */ 00163 double m_max; 00164 00165 /*int m_numExtream; 00166 std::vector<double> m_extream;*/ 00167 00168 private: 00169 /** 00170 * disable default constructor 00171 */ 00172 GenContext(); 00173 }; 00174 00175 #endif /* GENCONTEXT_H_ */