GenPrototype.h

Go to the documentation of this file.
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 GENPROTOTYPE_H_
00028 #define GENPROTOTYPE_H_
00029 
00030 // standard includes
00031 #include <string>
00032 #include <map>
00033 
00034 // forward declarations
00035 class Generation;
00036 class GenContext;
00037 class IValue;
00038 class Gen;
00039 
00040 // gen. alg. includes
00041 #include "IRandomStrategy.h"
00042 #include "IMutationStrategy.h"
00043 #include "restore.h"
00044 
00045 /**
00046  * The GenPrototype class.
00047  *
00048  *   This class is used for group some gens and is needed from the
00049  *   genFactory. It saves all GenContexte which are use this prototype.
00050  *   The group of gens becomes whit it an name.
00051  *
00052  *   The prototypes inside the gen. alg. are saved in the GenContext, in
00053  *   the Gen and in the GenEngine (only here can be deleted!!!).
00054  */
00055 class GenPrototype {
00056 public:
00057         /**
00058          * constructor to create a GenPrototype. Information which the class need are
00059          * the name of the gen pool group, a strategy how can a Gen of this group be
00060          * created (for the IValue) and a strategy how can a Gen mutate.
00061          *
00062          * @param name (string) Name of the group
00063          * @param randomStrategy (IRandomStrategy*) the strategy for creating a gen
00064          * @param mutationStrategy (IMutationStrategy*) the strategy for mutating a gen
00065          */
00066         GenPrototype(std::string name, IRandomStrategy* randomStrategy, IMutationStrategy* mutationStrategy);
00067 
00068         /**
00069          * destructor to delete a GenContext.
00070          */
00071         virtual ~GenPrototype();
00072 
00073         /**
00074          * [inline], [const]
00075          * This function gives the name of the prototype back.
00076          *
00077          * @return (string) the name
00078          */
00079         inline std::string getName(void)const {return m_name;}
00080 
00081         /**
00082          * [inline], [const]
00083          * This function gives a random value (IValue) which are with the randomStrategy is generated back.
00084          */
00085         inline IValue* getRandomValue(void)const {return m_randomStrategy->getRandomValue();}
00086 
00087         /**
00088          * This function insert a GenContext in the GenPrototype.
00089          *
00090          * @param generation (Generation*) to which Generation is the Context related.
00091          * @param context (GenContext*) the context which should be insert
00092          */
00093         void insertContext(Generation* generation, GenContext* context);
00094 
00095         /**
00096          * This function gives the context which is relatedto the Eneration "generation" back.
00097          *
00098          * @param generation (Generation*) the related generation
00099          *
00100          * @return (GenContext*) the searched context
00101          */
00102         GenContext* getContext(Generation* generation);
00103 
00104         /**
00105          * [const]
00106          * This function mutate the given gen.
00107          *
00108          * @param context (GenContext*) param is needed by the mutationStrategy
00109          * @param individual (Individual*) param is needed by the mutationStrategy
00110          * @param oldGen (Gen*) the gen which should be mutate
00111          * @param oldContext (GenContext*) param is needed by the mutationStrategy
00112          *
00113          * @return (Gen*) The new mutated gen
00114          */
00115         Gen* mutate(GenContext* context, Individual* individual, Gen* oldGen, GenContext* oldContext)const;
00116 
00117         /**
00118          * [const]
00119          * This function gives the mutation probability back (from the mutation strategy)
00120          *
00121          * @return (int) The mutation probability. Maybe the Typ int will be changed.
00122          */
00123         int getMutationProbability(void)const;
00124 
00125         /**
00126          * restore gene and the value
00127          * @param f (FILE*) here is the value inside
00128          * @param gene (RESTORE_GA_GENE*) this gene is to restore
00129          * @return (bool) true if all ok
00130          */
00131         bool restoreGene(FILE* f, RESTORE_GA_GENE* gene, std::vector<Gen*>& storage);
00132 
00133 protected:
00134         /**
00135          * (string)
00136          * the name
00137          */
00138         std::string m_name;
00139 
00140         /**
00141          * (map<Generation*, GenContext*>)
00142          * The storage for the GenContexte. It related the contexte to the generations.
00143          */
00144         std::map<Generation*,GenContext*> m_context;
00145 
00146         /**
00147          * (IRandomStrategy*)
00148          * the random strategy
00149          */
00150         IRandomStrategy* m_randomStrategy;
00151 
00152         /**
00153          * (IMutationStrategy*)
00154          * the mutation strategy
00155          */
00156         IMutationStrategy* m_mutationStrategy;
00157 
00158 private:
00159         /**
00160          * disable the default constructor
00161          */
00162         GenPrototype();
00163 };
00164 
00165 #endif /* GENPROTOTYPE_H_ */
Generated on Thu Jun 28 14:45:36 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3