COPASI API  4.16.103
CGA.h
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/optimization/CGA.h,v $
3  $Revision: 1.17 $
4  $Name: $
5  $Author: gauges $
6  $Date: 2006/10/15 07:43:32 $
7  End CVS Header */
8 
9 // Copyright 2005 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc. and EML Research, gGmbH.
11 // All rights reserved.
12 
13 /**
14  * File name: CGA.h
15  *
16  * Programmer: Yongqun He
17  * Contact email: yohe@vt.edu
18  * Purpose: This is the interface (.h file) of the CGA class.
19  * It is to implement the genetic algorithm for COPASI optimization
20  */
21 
22 #ifndef CGA_H
23 #define CGA_H
24 
25 #define TRUE 1
26 #define FALSE 0
27 
28 #include "r250.h"
29 
30 #include "optimization/COptAlgorithm.h"
32 
33 //using namespace std;
34 
35 class CGA : public COptAlgorithm
36  {
37  //private members
38 
39  private:
40  unsigned int mGener; // number of generations
41  unsigned int mPopSize; // size of the population
42  int mCrossNum; // number of crossover points
43  double mMin, mMax;
44  double mMutVar; // variance for mutations
45  double mMutProb; // probability of mutations
46  unsigned int mBest; // index of the best individual
47  int mParamNum; // number of parameters
48  double **mIndV; // for array of individuals w/ candidate values for the parameters
49  double *mCandX; // array of values of objective function f/ individuals
50  unsigned int *mCrp; // indexes of the crossover points
51  unsigned int *mMidX; // indexes for shuffling the population
52  unsigned int *mWins; // number of wins of each individual in the tournament
53 
54  //YOHE: new: add CRealProblem class for testing purpose
56 
57  //implementations
58 
59  public:
60 
61  /**
62  * default constructor
63  */
64  CGA();
65 
66  /**
67  * constructor for initializing population
68  */
69  //CGA(int psize,int num,int param);
70 
71  /**
72  * Copy constructor
73  * @param source a CGA object for copy
74  */
75  CGA(const CGA& source);
76 
77  /**
78  * Object assignment overloading
79  * @param source a CGA object for copy
80  * @return an assigned CGA object
81  */
82  CGA& operator=(const CGA& source);
83 
84  /**
85  * destructor
86  */
87  ~CGA();
88 
89  /**
90  * initialize function
91  */
92  bool initialize();
93 
94  /**
95  * initialize the first generation
96  */
97  void initFirstGeneration();
98 
99  /**
100  * clean up
101  */
102  int cleanup();
103 
104  /**Declare the prototype of member functions ***/
105 
106  // define mutation functions
107 
108  /**
109  * set real problem
110  */
111  void setRealProblem(CRealProblem & aProb);
112 
113  /**
114  * set parameter
115  */
116  void setParamNum (int num);
117 
118  /**
119  * set population size
120  */
121  void setPopSize(int num);
122 
123  /**
124  * set generation number
125  */
126  void setGeneration(int num);
127 
128  /**
129  * set mIndV, the private member
130  */
131  void setIndv(int i, int j, double num);
132 
133  /**
134  * set mCandX, the private member
135  */
136  void setCandx(int i, double num);
137 
138  /**
139  * set the best result
140  */
141  void setBest(unsigned int num);
142 
143  /**
144  * set the mutation variance
145  */
146  void setMutVar(double num);
147 
148  /**
149  * set the minimum
150  */
151  void setMin(double num);
152 
153  /**
154  * set the max
155  */
156  void setMax(double num);
157 
158  // define access functions
159 
160  /**
161  * get the parameter number
162  */
163  int getParamNum();
164 
165  /**
166  * get the best candidate
167  */
168  double getBestCandidate();
169 
170  /**
171  * get generation number
172  */
173  unsigned int getGeneration();
174 
175  /**
176  * get population size
177  */
178  int getPopSize();
179 
180  /*****define functional functions here**********/
181 
182  /**
183  * Set the random seed with time
184  */
185  int initOptRandom();
186 
187  /**
188  * evaluate the fitness of one individual
189  */
190  double evaluate(unsigned int i);
191 
192  /**
193  * copy individual o to position d
194  */
195  void copy(unsigned int o, unsigned int d);
196 
197  /**
198  * swap individuals o and d
199  */
200  void swap(unsigned int o, unsigned int d);
201 
202  /**
203  * process mutation
204  */
205  void mutate(unsigned int i);
206 
207  /**
208  * process crossover
209  */
210  void crossover(unsigned int p1, unsigned int p2, unsigned int c1, unsigned int c2);
211 
212  /**
213  * shuffle data
214  */
215  void shuffle(void);
216 
217  /**
218  * replicate the individuals w/ crossover
219  */
220  void replicate(void);
221 
222  /**
223  * select popsize individuals
224  */
225  void select(int method);
226 
227  /**
228  * check the best individual at this generation
229  */
230  unsigned int fittest(void);
231 
232  /**
233  * initialise the population
234  */
235  void creation(unsigned int l, unsigned int u);
236 
237  /**
238  * dump data to a file
239  */
240  void dumpData(unsigned int i);
241 
242  /**
243  * optimization function
244  */
245  int optimise();
246  };
247 
248 #endif //
void setPopSize(int num)
Definition: CGA.cpp:213
Definition: CGA.h:35
void dumpData(unsigned int i)
Definition: CGA.cpp:671
void setGeneration(int num)
Definition: CGA.cpp:219
double getBestCandidate()
Definition: CGA.cpp:269
bool initialize()
Definition: CGA.cpp:74
double mMutProb
Definition: CGA.h:45
CGA()
Definition: CGA.cpp:42
void select(int method)
Definition: CGA.cpp:539
unsigned int mPopSize
Definition: CGA.h:41
void mutate(unsigned int i)
Definition: CGA.cpp:384
void setMax(double num)
Definition: CGA.cpp:237
void replicate(void)
Definition: CGA.cpp:518
void setCandx(int i, double num)
Definition: CGA.cpp:249
double ** mIndV
Definition: CGA.h:48
int mParamNum
Definition: CGA.h:47
double mMax
Definition: CGA.h:43
unsigned int * mCrp
Definition: CGA.h:50
int getPopSize()
Definition: CGA.cpp:281
void setBest(unsigned int num)
Definition: CGA.cpp:255
double mMutVar
Definition: CGA.h:44
CGA & operator=(const CGA &source)
Definition: CGA.cpp:159
unsigned int mBest
Definition: CGA.h:46
double evaluate(unsigned int i)
Definition: CGA.cpp:296
void swap(unsigned int o, unsigned int d)
Definition: CGA.cpp:363
CRealProblem mRealProblem
Definition: CGA.h:55
void setIndv(int i, int j, double num)
Definition: CGA.cpp:243
int initOptRandom()
Definition: CGA.cpp:287
int getParamNum()
Definition: CGA.cpp:263
unsigned int mGener
Definition: CGA.h:40
void creation(unsigned int l, unsigned int u)
Definition: CGA.cpp:609
unsigned int * mMidX
Definition: CGA.h:51
int cleanup()
Definition: CGA.cpp:185
void initFirstGeneration()
Definition: CGA.cpp:116
unsigned int fittest(void)
Definition: CGA.cpp:591
void crossover(unsigned int p1, unsigned int p2, unsigned int c1, unsigned int c2)
Definition: CGA.cpp:430
void setParamNum(int num)
Definition: CGA.cpp:207
void setRealProblem(CRealProblem &aProb)
Definition: CGA.cpp:201
int mCrossNum
Definition: CGA.h:42
int optimise()
Definition: CGA.cpp:696
unsigned int getGeneration()
Definition: CGA.cpp:275
void copy(unsigned int o, unsigned int d)
Definition: CGA.cpp:352
double * mCandX
Definition: CGA.h:49
double mMin
Definition: CGA.h:43
void shuffle(void)
Definition: CGA.cpp:500
void setMin(double num)
Definition: CGA.cpp:231
~CGA()
Definition: CGA.cpp:189
void setMutVar(double num)
Definition: CGA.cpp:225
unsigned int * mWins
Definition: CGA.h:52