00001 /*************************************************************************** 00002 * Copyright (C) 2005-2009 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * guettler@informatik.uni-leipzig.de * 00007 * jhoffmann@informatik.uni-leipzig.de * 00008 * joergweide84@aol.com (robot12) * 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 * This class is used for create a context for some gens. This mean it * 00027 * saves all gens which have the same prototype and are a part of an * 00028 * individual which are in ONE generation. It can be useful for some * 00029 * statistical calculation or for optimizing the mutation factor. * 00030 * * 00031 * The Gen Context is inside the gen. alg. only saved in the * 00032 * GenPrototype. * 00033 * * 00034 * $Log: GenContext.h,v $ 00035 * Revision 1.5 2009/10/21 14:08:07 robot12 00036 * add restore and store functions to the ga package 00037 * 00038 * Revision 1.4 2009/07/21 08:37:59 robot12 00039 * add some comments 00040 * 00041 * Revision 1.3 2009/06/29 14:32:51 robot12 00042 * finishing the GenContext and add some comments 00043 * 00044 * Revision 1.2 2009/05/07 14:47:47 robot12 00045 * some comments 00046 * 00047 * Revision 1.1 2009/05/04 15:27:56 robot12 00048 * rename of some files and moving files to other positions 00049 * - SingletonGenAlgAPI has one error!!! --> is not ready now 00050 * 00051 * Revision 1.2 2009/04/30 11:35:53 robot12 00052 * some changes: 00053 * - insert a SelectStrategie 00054 * - insert a MutationStrategie 00055 * - reorganisation of the design 00056 * 00057 * Revision 1.1 2009/04/27 10:59:34 robot12 00058 * some implements 00059 * 00060 * 00061 ***************************************************************************/ 00062 00063 #ifndef GENCONTEXT_H_ 00064 #define GENCONTEXT_H_ 00065 00066 // standard includes 00067 #include <vector> 00068 #include <algorithm> 00069 #include <selforg/inspectable.h> 00070 00071 // forward declarations 00072 class Gen; 00073 class GenPrototype; 00074 00075 // gen. alg. includes 00076 00077 /** 00078 * The GenContext class. 00079 * This class is used for create a context for some gens. This mean it 00080 * saves all gens which have the same prototype and are a part of an 00081 * individual which are in ONE generation. It can be useful for some 00082 * statistical calculation or for optimizing the mutation factor. 00083 * 00084 * The Gen Context is inside the gen. alg. only saved in the 00085 * GenPrototype. 00086 */ 00087 class GenContext : public Inspectable { 00088 public: 00089 /** 00090 * constructor to create a GenContext. Information which the class need are 00091 * the prototype (name an group of gens). 00092 * 00093 * @param prototype (GenPrototype*) Pointer to the prototype. 00094 */ 00095 GenContext(GenPrototype* prototype); 00096 00097 /** 00098 * destructor to delete a GenContext. 00099 */ 00100 virtual ~GenContext(); 00101 00102 /** 00103 * [inline], [const] 00104 * 00105 * This function gives the prototype for hich are the context is make back. 00106 * 00107 * @return (GenPrototype*) the prototype 00108 */ 00109 inline GenPrototype* getPrototype(void)const {return m_prototype;} 00110 00111 /** 00112 * [inline] 00113 * This function add a Gen to the Context. 00114 * 00115 * @param gen (Gen*) the new Gen, which should be added 00116 */ 00117 inline void addGen(Gen* gen) {m_storage.push_back(gen);} 00118 00119 /** 00120 * [inline] 00121 * This function removes one gen which is saved inside the context (but NO deleting of the gen!!!). 00122 * 00123 * param gen (Gen*) The gen, which should be removed 00124 */ 00125 inline void removeGen(Gen* gen) {std::vector<Gen*>::iterator itr = std::find(m_storage.begin(),m_storage.end(),gen); m_storage.erase(itr);} 00126 00127 /** 00128 * [inline], [const] 00129 * This function gives all gens which are saved in this context back. 00130 * 00131 * @return (vector<Gen*>&) list with all gens. 00132 */ 00133 inline const std::vector<Gen*>& getGene(void)const {return m_storage;} 00134 00135 /** 00136 * This function makes an update on the statistical values 00137 * @param factor (double) this factor is normal 1.5 and is for the whisker distance in the analysation 00138 */ 00139 void update(double factor=1.5); 00140 00141 /** 00142 * restore all GenContext 00143 * @return (bool) if all ok 00144 */ 00145 static bool restore(); 00146 00147 protected: 00148 /** 00149 * (vector<Gen*> 00150 * Storage for all Genes which are saved in this context. 00151 */ 00152 std::vector<Gen*> m_storage; 00153 00154 /** 00155 * (GenPrototyp*) 00156 * the prototype for which are the context is. 00157 */ 00158 GenPrototype* m_prototype; 00159 00160 /** 00161 * the min value of the gens 00162 */ 00163 double m_min; 00164 00165 /** 00166 * the under whisker of the gens 00167 */ 00168 double m_w1; 00169 00170 /** 00171 * the under quartil of the gens 00172 */ 00173 double m_q1; 00174 00175 /** 00176 * the median of the gens 00177 */ 00178 double m_med; 00179 00180 /** 00181 * the average of the gens 00182 */ 00183 double m_avg; 00184 00185 /** 00186 * the upper quartil of the gens 00187 */ 00188 double m_q3; 00189 00190 /** 00191 * the upper whisker of the gens 00192 */ 00193 double m_w3; 00194 00195 /** 00196 * the max value of the gens 00197 */ 00198 double m_max; 00199 00200 /*int m_numExtream; 00201 std::vector<double> m_extream;*/ 00202 00203 private: 00204 /** 00205 * disable default constructor 00206 */ 00207 GenContext(); 00208 }; 00209 00210 #endif /* GENCONTEXT_H_ */