GenPrototype.h

Go to the documentation of this file.
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 group some gens and is needed from the         *
00027  *   genFactory. It saves all GenContexte which are use this prototype.    *
00028  *   The group of gens becomes whit it an name.                            *
00029  *                                                                         *
00030  *   The prototypes inside the gen. alg. are saved in the GenContext, in   *
00031  *   the Gen and in the GenEngine (only here can be deleted!!!).           *
00032  *                                                                         *
00033  *   $Log: GenPrototype.h,v $
00034  *   Revision 1.6  2009/11/05 14:07:41  robot12
00035  *   bugfix for restore and store
00036  *
00037  *   Revision 1.5  2009/10/21 14:08:07  robot12
00038  *   add restore and store functions to the ga package
00039  *
00040  *   Revision 1.4  2009/07/21 08:37:58  robot12
00041  *   add some comments
00042  *
00043  *   Revision 1.3  2009/05/14 15:29:56  robot12
00044  *   bugfix: mutation change the oldGen, not the new!!! now fixed
00045  *
00046  *   Revision 1.2  2009/05/07 14:47:47  robot12
00047  *   some comments
00048  *
00049  *   Revision 1.1  2009/05/04 15:27:56  robot12
00050  *   rename of some files and moving files to other positions
00051  *    - SingletonGenAlgAPI has one error!!! --> is not ready now
00052  *
00053  *   Revision 1.2  2009/04/30 11:35:53  robot12
00054  *   some changes:
00055  *    - insert a SelectStrategie
00056  *    - insert a MutationStrategie
00057  *    - reorganisation of the design
00058  *
00059  *   Revision 1.1  2009/04/27 10:59:33  robot12
00060  *   some implements
00061  *
00062  *
00063  ***************************************************************************/
00064 
00065 #ifndef GENPROTOTYPE_H_
00066 #define GENPROTOTYPE_H_
00067 
00068 // standard includes
00069 #include <string>
00070 #include <map>
00071 
00072 // forward declarations
00073 class Generation;
00074 class GenContext;
00075 class IValue;
00076 class Gen;
00077 
00078 // gen. alg. includes
00079 #include "IRandomStrategy.h"
00080 #include "IMutationStrategy.h"
00081 #include "restore.h"
00082 
00083 /**
00084  * The GenPrototype class.
00085  *
00086  *   This class is used for group some gens and is needed from the
00087  *   genFactory. It saves all GenContexte which are use this prototype.
00088  *   The group of gens becomes whit it an name.
00089  *
00090  *   The prototypes inside the gen. alg. are saved in the GenContext, in
00091  *   the Gen and in the GenEngine (only here can be deleted!!!).
00092  */
00093 class GenPrototype {
00094 public:
00095         /**
00096          * constructor to create a GenPrototype. Information which the class need are
00097          * the name of the gen pool group, a strategy how can a Gen of this group be
00098          * created (for the IValue) and a strategy how can a Gen mutate.
00099          *
00100          * @param name (string) Name of the group
00101          * @param randomStrategy (IRandomStrategy*) the strategy for creating a gen
00102          * @param mutationStrategy (IMutationStrategy*) the strategy for mutating a gen
00103          */
00104         GenPrototype(std::string name, IRandomStrategy* randomStrategy, IMutationStrategy* mutationStrategy);
00105 
00106         /**
00107          * destructor to delete a GenContext.
00108          */
00109         virtual ~GenPrototype();
00110 
00111         /**
00112          * [inline], [const]
00113          * This function gives the name of the prototype back.
00114          *
00115          * @return (string) the name
00116          */
00117         inline std::string getName(void)const {return m_name;}
00118 
00119         /**
00120          * [inline], [const]
00121          * This function gives a random value (IValue) which are with the randomStrategy is generated back.
00122          */
00123         inline IValue* getRandomValue(void)const {return m_randomStrategy->getRandomValue();}
00124 
00125         /**
00126          * This function insert a GenContext in the GenPrototype.
00127          *
00128          * @param generation (Generation*) to which Generation is the Context related.
00129          * @param context (GenContext*) the context which should be insert
00130          */
00131         void insertContext(Generation* generation, GenContext* context);
00132 
00133         /**
00134          * This function gives the context which is relatedto the Eneration "generation" back.
00135          *
00136          * @param generation (Generation*) the related generation
00137          *
00138          * @return (GenContext*) the searched context
00139          */
00140         GenContext* getContext(Generation* generation);
00141 
00142         /**
00143          * [const]
00144          * This function mutate the given gen.
00145          *
00146          * @param context (GenContext*) param is needed by the mutationStrategy
00147          * @param individual (Individual*) param is needed by the mutationStrategy
00148          * @param oldGen (Gen*) the gen which should be mutate
00149          * @param oldContext (GenContext*) param is needed by the mutationStrategy
00150          *
00151          * @return (Gen*) The new mutated gen
00152          */
00153         Gen* mutate(GenContext* context, Individual* individual, Gen* oldGen, GenContext* oldContext)const;
00154 
00155         /**
00156          * [const]
00157          * This function gives the mutation probability back (from the mutation strategy)
00158          *
00159          * @return (int) The mutation probability. Maybe the Typ int will be changed.
00160          */
00161         int getMutationProbability(void)const;
00162 
00163         /**
00164          * restore gene and the value
00165          * @param f (FILE*) here is the value inside
00166          * @param gene (RESTORE_GA_GENE*) this gene is to restore
00167          * @return (bool) true if all ok
00168          */
00169         bool restoreGene(FILE* f, RESTORE_GA_GENE* gene, std::vector<Gen*>& storage);
00170 
00171 protected:
00172         /**
00173          * (string)
00174          * the name
00175          */
00176         std::string m_name;
00177 
00178         /**
00179          * (map<Generation*, GenContext*>)
00180          * The storage for the GenContexte. It related the contexte to the generations.
00181          */
00182         std::map<Generation*,GenContext*> m_context;
00183 
00184         /**
00185          * (IRandomStrategy*)
00186          * the random strategy
00187          */
00188         IRandomStrategy* m_randomStrategy;
00189 
00190         /**
00191          * (IMutationStrategy*)
00192          * the mutation strategy
00193          */
00194         IMutationStrategy* m_mutationStrategy;
00195 
00196 private:
00197         /**
00198          * disable the default constructor
00199          */
00200         GenPrototype();
00201 };
00202 
00203 #endif /* GENPROTOTYPE_H_ */
Generated on Fri Nov 4 10:59:38 2011 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3