COPASI API  4.16.103
COptMethodGA.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2004 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * COptMethodGA class
17  */
18 
19 #ifndef COPASI_COptMethodGA
20 #define COPASI_COptMethodGA
21 #include <limits>
22 
24 #include "utilities/CVector.h"
25 
26 class CRandom;
27 class CPermutation;
28 
29 class COptMethodGA : public COptMethod
30 {
32 
33  // Operations
34 public:
35  /**
36  * Copy Constructor
37  * @param const COptMethodGA & src
38  * @param const CCopasiContainer * pParent (default: NULL)
39  */
40  COptMethodGA(const COptMethodGA & src,
41  const CCopasiContainer * pParent = NULL);
42 
43  /**
44  * Destructor
45  */
46  virtual ~COptMethodGA();
47 
48  /**
49  * Execute the optimization algorithm calling simulation routine
50  * when needed. It is noted that this procedure can give feedback
51  * of its progress by the callback function set with SetCallback.
52  * @ return success;
53  */
54  virtual bool optimise();
55 
56 private:
57  /**
58  * Default Constructor
59  * @param const CCopasiContainer * pParent (default: NULL)
60  */
61  COptMethodGA(const CCopasiContainer * pParent = NULL);
62 
63  /**
64  * Initialize contained objects.
65  */
66  void initObjects();
67 
68  /**
69  * Initialize arrays and pointer.
70  * @return bool success
71  */
72  virtual bool initialize();
73 
74  /**
75  * Cleanup arrays and pointers.
76  * @return bool success
77  */
78  virtual bool cleanup();
79 
80  /**
81  * Evaluate the fitness of one individual
82  * @param const CVector< C_FLOAT64 > & individual
83  * @return bool continue
84  */
85  bool evaluate(const CVector< C_FLOAT64 > & individual);
86 
87  /**
88  * Swap individuals from and to
89  * @param size_t from
90  * @param size_t to
91  * @return bool success
92  */
93  bool swap(size_t from, size_t to);
94 
95  /**
96  * Mutate one individual
97  * @param CVector< C_FLOAT64 > & individual
98  * @return bool success
99  */
100  bool mutate(CVector< C_FLOAT64 > & individual);
101 
102  /**
103  * @param const CVector< C_FLOAT64 > & parent1
104  * @param const CVector< C_FLOAT64 > & parent2
105  * @param CVector< C_FLOAT64 > & child1
106  * @param CVector< C_FLOAT64 > & child2
107  */
108  bool crossover(const CVector< C_FLOAT64 > & parent1,
109  const CVector< C_FLOAT64 > & parent2,
110  CVector< C_FLOAT64 > & child1,
111  CVector< C_FLOAT64 > & child2);
112 
113  /**
114  * Replicate the individuals with crossover
115  * @return bool continue
116  */
117  bool replicate();
118 
119  /**
120  * Select surviving population
121  * @return bool success
122  */
123  bool select();
124 
125  /**
126  * Find the best individual at this generation
127  * @return size_t fittest
128  */
129  size_t fittest();
130 
131  /**
132  * Initialise the population
133  * @param size_t first
134  * @param size_t last (default: population size)
135  * @return bool continue
136  */
137  bool creation(size_t first, size_t last = std::numeric_limits<size_t>::max());
138 
139  /**
140  * Serialize the population for debug
141  * @param size_t first
142  * @param size_t last (default: population size)
143  * @return bool success
144  */
145  bool serializepop(size_t first, size_t last);
146 
147  // Attributes
148 private:
149  /**
150  * number of generations
151  */
153 
154  /**
155  * Handle to the process report item "Current Generation"
156  */
158 
159  /**
160  * size of the population
161  */
163 
164  /**
165  * a pointer to the randomnumber generator.
166  */
168 
169  /**
170  * number of parameters
171  */
173 
174  /**
175  * for array of individuals w/ candidate values for the parameters
176  */
177  std::vector< CVector < C_FLOAT64 > * > mIndividual;
178 
179  /**
180  * Vector used to initialize the crossover point to false
181  */
183 
184  /**
185  * Vector of crossover points.
186  */
188 
189  /**
190  * The value of the last evaluation.
191  */
193 
194  /**
195  * array of values of objective function f/ individuals
196  */
198 
199  /**
200  * A permutation of integers used to create the informants;
201  */
203 
204  /**
205  * number of losses of each individual in the tournament
206  */
208 
209  /**
210  * The pivot vector used for sorting
211  */
213 
214  /**
215  * variance for mutations
216  */
218 
220  size_t mBestIndex;
222 };
223 
224 #endif // COPASI_COptMethodGA
virtual bool initialize()
C_FLOAT64 mMutationVarians
Definition: COptMethodGA.h:217
bool swap(size_t from, size_t to)
unsigned C_INT32 mGenerations
Definition: COptMethodGA.h:152
static COptMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::RandomSearch)
Definition: COptMethod.cpp:50
CVector< size_t > mPivot
Definition: COptMethodGA.h:212
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodGA.h:177
CVector< bool > mCrossOverFalse
Definition: COptMethodGA.h:182
bool crossover(const CVector< C_FLOAT64 > &parent1, const CVector< C_FLOAT64 > &parent2, CVector< C_FLOAT64 > &child1, CVector< C_FLOAT64 > &child2)
C_FLOAT64 mEvaluationValue
Definition: COptMethodGA.h:192
#define C_INT32
Definition: copasi.h:90
size_t fittest()
CRandom * mpRandom
Definition: COptMethodGA.h:167
CVector< size_t > mLosses
Definition: COptMethodGA.h:207
CVector< bool > mCrossOver
Definition: COptMethodGA.h:187
void initObjects()
size_t mVariableSize
Definition: COptMethodGA.h:172
size_t mBestIndex
Definition: COptMethodGA.h:220
unsigned C_INT32 mGeneration
Definition: COptMethodGA.h:221
unsigned C_INT32 mPopulationSize
Definition: COptMethodGA.h:162
bool serializepop(size_t first, size_t last)
virtual ~COptMethodGA()
bool mutate(CVector< C_FLOAT64 > &individual)
COptMethodGA(const COptMethodGA &src, const CCopasiContainer *pParent=NULL)
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 mBestValue
Definition: COptMethodGA.h:219
virtual bool cleanup()
bool evaluate(const CVector< C_FLOAT64 > &individual)
bool creation(size_t first, size_t last=std::numeric_limits< size_t >::max())
CVector< C_FLOAT64 > mValue
Definition: COptMethodGA.h:197
size_t mhGenerations
Definition: COptMethodGA.h:157
virtual bool optimise()
CPermutation * mpPermutation
Definition: COptMethodGA.h:202
#define max(a, b)
Definition: f2c.h:176