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

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

- Search for |

- File List
- File Members

# SingletonGenFactory.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 a factory for the class Gen. It use some parameters and *
    00027  *   a GenPrototype to create new Gens. (randomized gens or mutated gens)  *
    00028  *                                                                         *
    00029  *   $Log: SingletonGenFactory.h,v $
    00030  *   Revision 1.4  2009/07/28 09:38:23  robot12
    00031  *   update the Singleton::destroy
    00032  *
    00033  *   Revision 1.3  2009/07/21 08:37:58  robot12
    00034  *   add some comments
    00035  *
    00036  *   Revision 1.2  2009/06/29 14:27:13  robot12
    00037  *   finishing the Gen Factory and add some comments
    00038  *
    00039  *   Revision 1.1  2009/05/04 15:27:55  robot12
    00040  *   rename of some files and moving files to other positions
    00041  *    - SingletonGenAlgAPI has one error!!! --> is not ready now
    00042  *
    00043  *   Revision 1.3  2009/04/30 11:35:53  robot12
    00044  *   some changes:
    00045  *    - insert a SelectStrategie
    00046  *    - insert a MutationStrategie
    00047  *    - reorganisation of the design
    00048  *
    00049  *   Revision 1.2  2009/04/27 10:59:34  robot12
    00050  *   some implements
    00051  *
    00052  *
    00053  ***************************************************************************/
    00054
    00055 #ifndef SINGLETONGENFACTORY_H_
    00056 #define SINGLETONGENFACTORY_H_
    00057
    00058 //forward declaration
    00059 class GenContext;
    00060 class Gen;
    00061 class Individual;
    00062 class GenPrototype;
    00063 class IValue;
    00064
    00065 /**
    00066  * This is the factory for the class Gen. It gives 3 Methodes to generate new gens. (random,value and mutation)
    00067  * Over this is the class as singleton concepted. Only one Factory for a run.
    00068  *
    00069  * It use by every method the GenPrototype to be independent from the type of the Gen.
    00070  */
    00071 class SingletonGenFactory {
    00072 public:
    00073         /**
    00074          * this method is to become the only existing factory
    00075          * @return (SingletonGenFactory*) the one and only factory
    00076          */
    00077         inline static SingletonGenFactory* getInstance(void) {if(m_factory==0)m_factory = new SingletonGenFactory();return m_factory;}
    00078
    00079         /**
    00080          * this method is to destroy the one and only factory.
    00081          */
    00082         inline static void destroyGenFactory(void) {if(m_factory!=0){delete m_factory;m_factory=0;}}
    00083
    00084         // 3 methodes to create an Gen
    00085         /**
    00086          * random generation of a new gen.
    00087          * @param context (GenContext*) the context of the new Gen
    00088          * @param individual (Individual*) the individual, where the gen is part of.
    00089          * @param prototype (GenPrototype*) the prototype of the gen, which should be create.
    00090          * @return (Gen*) the new Gen
    00091          */
    00092         Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype)const;
    00093         /**
    00094          * this function generate a new Gen by mutate a old Gen
    00095          * @param context (GenContext*) the context of the new Gen
    00096          * @param individual (Individual*) the individual, where the gen is part of.
    00097          * @param prototype (GenPrototype*) the prototype of the gen, which should be create.
    00098          * @param oldContext (GenContext*) the Context of the old Gen
    00099          * @param oldIndividual (Individual*) the individua, where the olg gen is part of.
    00100          * @param oldGen (Gen*) the old Gen
    00101          * @param mutate (bool) should be mutate?
    00102          * @return (Gen*) the new (or old gen)
    00103          */
    00104         Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype, GenContext* oldContext, Individual* oldIndividual, Gen* oldGen, bool mutate=false)const;           // copy + mutation
    00105         /**
    00106          * create a new Gen by a giving value
    00107          * @param context (GenContext*) the context of the new Gen
    00108          * @param individual (Individual*) the individual, where the gen is part of.
    00109          * @param prototype (GenPrototype*) the prototype of the gen, which should be create.
    00110          * @param value (IValue*) the value of the new gen
    00111          * @return
    00112          */
    00113         Gen* createGen(GenContext* context, Individual* individual, GenPrototype* prototype, IValue* value);                                                                                                                                                            // value
    00114
    00115 private:
    00116         /**
    00117          * the one and only factory
    00118          */
    00119         static SingletonGenFactory* m_factory;
    00120
    00121         /**
    00122          * counter for giving Gens a individual ID
    00123          */
    00124         static int m_number;
    00125
    00126         /**
    00127          * disable the default constructor
    00128          */
    00129         SingletonGenFactory();
    00130
    00131         /**
    00132          * disable destructor
    00133          */
    00134         virtual ~SingletonGenFactory();
    00135 };
    00136
    00137 #endif /* SINGLETONGENFACTORY_H_ */