Evolutionary Algorithm for Adaptive Phase Estimation  1.0.2
candidate.h
1 #ifndef CANDIDATE_H
2 #define CANDIDATE_H
3 #include <stdexcept>
4 #include <cstring>
5 
6 using namespace std;
7 
11 class Candidate {
12 
13  friend class OptAlg;
14 
19  public:
21  is_velocity_initialized = false;
22  is_candidate_initialized = false;
23  };
24  ~Candidate();
25 
26  void init_can(int numvar, int fit_size);
27  void init_velocity();
29  void update_cont(double *input);
30  void update_vel(double *input);
31  void update_best();
32  void update_global(double *input);
33  void put_to_global();
35  void read_cont(double *output);
36  void read_vel(double *output);
37  void read_best(double *output);
38  void read_global(double *output);
40  void write_contfit(double *fit, int tt);
41  void write_bestfit(double *fit);
42  void write_globalfit(double *fit);
44  double read_contfit(int i ) {
45  return cont_fit[i];
46  }
47  double read_bestfit(int i ) {
48  return best_fit[i];
49  }
50  double read_globalfit(int i ) {
51  return global_fit[i];
52  }
53  int read_bestt() {
54  return best_times;
55  }
56 
57 
58  private:
59 
60  int num; /*number of variables*/
61  int num_fit; /*number of fitness values (i.e., total number of contraints and objetive functions)*/
62  double *best_fit; /*pointer to array for storing fitness values calculated from the data in contender array*/
63  double *cont_fit; /*pointer to array for storing fitness values calculated from the data in can_best array*/
64  double *global_fit; /*pointer to array for storing fitness values calculated from the data in global_best array*/
65  int times; /*the number of time the fitess value is computed for contender*/
66  int best_times; /*the number of time the fitess value is computed for can_best*/
67  int global_times; /*the number of time the fitess value is computed for global_best*/
68  bool is_velocity_initialized; /*indicating whether addition memory needs to be allocated*/
69  bool is_candidate_initialized; /*indicating whether memories are allocated*/
70 
71  //memory arrays
72  double *can_best; /*the pointer to array that contains solution that would survive several iterations*/
73  double *contender; /*the pointer to array that serves mostly as temporary memory that does not survive an interation*/
74  double *velocity; /*the pointer to additional array*/
75  double *global_best; /*the pointer to array that contains solution to be compared for the final solution*/
76  };
77 
78 #endif // CANDIDATE_H
Candidate()
Definition: candidate.h:20
int read_bestt()
Definition: candidate.h:53
double read_contfit(int i)
Definition: candidate.h:44
double read_globalfit(int i)
Definition: candidate.h:50
Candidate class contains arrays to be used by optimization algorithm to store data of a solution cand...
Definition: candidate.h:11
double read_bestfit(int i)
Definition: candidate.h:47
int num_fit
Definition: mpi_optalg.h:72
int num
Definition: mpi_optalg.h:71
OptAlg class contains the functions that can be used to contruct an optimization algorithm in the mai...
Definition: mpi_optalg.h:17