Robot Simulator of the Robotics Group for Self-Organization of Control: GenPrototype.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

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