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