Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SingletonIndividualFactory.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008-2011 LpzRobots development team *
3  * Joerg Weider <joergweide84 at aol dot com> (robot12) *
4  * Georg Martius <georg dot martius at web dot de> *
5  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
6  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
7  * Ralf Der <ralfder at mis dot mpg dot de> *
8  * Joern Hoffmann <jhoffmann at informatik dot uni-leipzig dot de *
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24  * *
25  ***************************************************************************/
26 
27 #ifndef SINGLETONINDIVIDUALFACTORY_H_
28 #define SINGLETONINDIVIDUALFACTORY_H_
29 
30 //includes
31 #include <selforg/randomgenerator.h>
32 
33 //forward declaration
34 class Gen;
35 class Generation;
36 
37 //ga_tools includes
38 #include "Individual.h"
39 
40 /**
41  * this is a factory for the individual class. It use the SingletonGenFactory to create new individuals.
42  * It have 2 methods to create a individual. (random and recombination)
43  *
44  * Over this is the class as singleton concepted. Only one Factory for a run.
45  */
47 public:
48  /**
49  * this method gives the one and only existing factory back.
50  * @return (SingletonIndividualFactory*) the factory
51  */
52  inline static SingletonIndividualFactory* getInstance(void) {
53  if(m_factory==0)m_factory = new SingletonIndividualFactory;
54  return m_factory;
55  }
56 
57  /**
58  * destroy the only existing factory
59  */
60  inline static void destroyFactory(void) {if(m_factory!=0){delete m_factory; m_factory=NULL;}}
61 
62  // 2 methods to create an individual
63  /**
64  * random creation by random creation of Gen for every GenPrototype.
65  * @param name (string) the name of the new individual. Will be automaticly created
66  * @return (Individual*) the new individual
67  */
68  Individual* createIndividual(std::string name=createName())const; // random
69  /**
70  * create a new individual by recombination of the gens of there parents
71  * @param individual1 (Individual*) parent 1
72  * @param individual2 (Individual*) parent 2
73  * @param random (RandGen*) a random generator
74  * @param name (string) the name of the new individual. Will be automaticly created
75  * @return (Individual*) the new individual
76  */
77  Individual* createIndividual(Individual* individual1, Individual* individual2, RandGen* random, std::string name=createName())const; // recombinate
78 
79  //reset m_number inside restore
80  /**
81  * set the member variable m_number to number
82  * @param number (int) the new value
83  */
84  inline void setNumber(int number) {m_number=number;}
85 
86 private:
87  /**
88  * the one and only factory
89  */
90  static SingletonIndividualFactory* m_factory;
91 
92  /**
93  * a counter for individual IDs
94  */
95  static int m_number;
96 
97  /**
98  * disable the default constructor
99  * only usable for itself
100  */
102 
103  /**
104  * disable the default destructor
105  * only usable for itself
106  */
107  virtual ~SingletonIndividualFactory();
108 
109  /**
110  * methode to generate a name for the new individual automatically
111  * @return (string) the name
112  */
113  inline static std::string createName(void) {std::string s = "Ind ";char buffer[128];sprintf(buffer,"%i",m_number);s+=buffer;return s;}
114 };
115 
116 #endif /* SINGLETONINDIVIDUALFACTORY_H_ */
void setNumber(int number)
set the member variable m_number to number
Definition: SingletonIndividualFactory.h:84
The Gen class.
Definition: Gen.h:51
Individual * createIndividual(std::string name=createName()) const
random creation by random creation of Gen for every GenPrototype.
Definition: SingletonIndividualFactory.cpp:47
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
static void destroyFactory(void)
destroy the only existing factory
Definition: SingletonIndividualFactory.h:60
this is a factory for the individual class.
Definition: SingletonIndividualFactory.h:46
The Generation class.
Definition: Generation.h:53
static SingletonIndividualFactory * getInstance(void)
this method gives the one and only existing factory back.
Definition: SingletonIndividualFactory.h:52
This class represent one individual of the complete gen.
Definition: Individual.h:45