1 | #define CLUSTER_ANZ_MAX 10 |
---|
2 | #define GA_SAFETY 40 |
---|
3 | // max loop repeat count |
---|
4 | #define GB_read_APfloat (AP_FLOAT)GB_read_float |
---|
5 | #define GB_write_APfloat GB_write_float |
---|
6 | |
---|
7 | enum AP_init_status { |
---|
8 | INIT_NONE = 0, |
---|
9 | INIT_MAIN = 1, |
---|
10 | INIT_START = 2, |
---|
11 | INIT_OPT = 4, |
---|
12 | INIT_JOB = 8, |
---|
13 | INIT_ALL = 15 |
---|
14 | }; |
---|
15 | |
---|
16 | enum GA_JOB_MODE { |
---|
17 | GA_CROSSOVER, |
---|
18 | GA_KERNIGHAN, |
---|
19 | GA_CREATEJOBS, |
---|
20 | GA_NNI, |
---|
21 | GA_NONE |
---|
22 | }; |
---|
23 | |
---|
24 | struct GA_tree { |
---|
25 | int ref_count; |
---|
26 | AP_FLOAT criteria; |
---|
27 | AP_tree_nlen *tree; |
---|
28 | long id; |
---|
29 | |
---|
30 | }; |
---|
31 | |
---|
32 | struct GA_job { |
---|
33 | AP_FLOAT criteria; |
---|
34 | int cluster0; |
---|
35 | int cluster1; |
---|
36 | GA_tree * tree0; // fuer return |
---|
37 | GA_tree * tree1; |
---|
38 | long id0; |
---|
39 | long id1; |
---|
40 | GA_JOB_MODE mode; |
---|
41 | void printl() { |
---|
42 | cout << "JOB Clu0 " << cluster0 << |
---|
43 | " tr " << id0 << |
---|
44 | " * CLu1 " << cluster1 << " tr " << id1 << |
---|
45 | " * mode " << mode << " crit " << criteria |
---|
46 | << "\n"; cout.flush(); }; |
---|
47 | void calcCrit(AP_FLOAT crit0, AP_FLOAT crit1) { |
---|
48 | criteria = crit0 + crit1; }; |
---|
49 | }; |
---|
50 | |
---|
51 | |
---|
52 | class GA_genetic { |
---|
53 | AP_init_status init_status; |
---|
54 | AP_tree *tree_prototype; |
---|
55 | // presets |
---|
56 | int min_job; // min jobs per cluster before removing jobs |
---|
57 | int max_cluster; // max cluster |
---|
58 | int max_jobs; // max jobs |
---|
59 | int maxTree; // max trees per clustergbp |
---|
60 | int jobCount; |
---|
61 | AP_FLOAT bestTree; |
---|
62 | |
---|
63 | int jobOpt; |
---|
64 | int jobCrossover; |
---|
65 | int jobOther; |
---|
66 | int jobKL; |
---|
67 | |
---|
68 | // array of trees in cluster |
---|
69 | long **treelist; // treeids |
---|
70 | int *treePerCluster; // clusterid |
---|
71 | |
---|
72 | int clusterCount; |
---|
73 | |
---|
74 | |
---|
75 | // stored DB pointers (which won't change) |
---|
76 | GBDATA *gb_tree_start; |
---|
77 | GBDATA *gb_treeName; |
---|
78 | GBDATA *gb_tree_opt; |
---|
79 | GBDATA *gb_joblist; |
---|
80 | GBDATA *gb_genetic; |
---|
81 | GBDATA *gb_main; |
---|
82 | GBDATA *gb_presets; |
---|
83 | GBDATA *gb_jobCount; |
---|
84 | GBDATA *gb_bestTree; |
---|
85 | GBDATA *gb_maxTree; |
---|
86 | // writes and reads compressd tree from database |
---|
87 | double AP_atof(char *str); |
---|
88 | char * write_tree_rek(AP_tree *node, char *dest, long mode); |
---|
89 | AP_tree *read_tree_rek(char **data); |
---|
90 | AP_ERR *write_tree(GBDATA *gb_tree, GA_tree *tree); |
---|
91 | GA_tree *read_tree(GBDATA *gb_tree, long tree_id); |
---|
92 | AP_ERR *create_job_container(GA_job *job); |
---|
93 | GBDATA *get_cluster(GBDATA * container, int cluster); |
---|
94 | GBDATA *get_tree(GBDATA *container, long tree_id); |
---|
95 | long get_treeid(GBDATA *gbtree); |
---|
96 | |
---|
97 | AP_ERR * read_presets(); |
---|
98 | public: |
---|
99 | GA_genetic(); |
---|
100 | ~GA_genetic(); |
---|
101 | void init(GBDATA *gbmain); |
---|
102 | void init_first(GBDATA *gbmain); // dummy zum testen der db eintraege generiert |
---|
103 | void exit(); |
---|
104 | // for errorfile |
---|
105 | FILE *fout; |
---|
106 | |
---|
107 | AP_ERR *put_start_tree(AP_tree *tree, const long name, int cluster); |
---|
108 | AP_ERR *remove_job(GBDATA *gb_cluster); |
---|
109 | AP_ERR *delete_job(GBDATA *gb_job); |
---|
110 | AP_ERR *delete_tree(GBDATA *gb_cluster, GBDATA *gb_tree); |
---|
111 | AP_ERR *create_jobs(GA_tree *tree, int cluster); |
---|
112 | GA_tree *get_start_tree(int cluster); |
---|
113 | AP_ERR *put_opt_tree(char *tree, int cluster); |
---|
114 | GA_job *get_job(int cluster); |
---|
115 | AP_ERR *put_job(int cluster, GA_job *job); |
---|
116 | AP_ERR * put_optimized(GA_tree *tree, int cluster); |
---|
117 | |
---|
118 | int getMaxCluster() { return max_cluster; }; |
---|
119 | int getMaxJob() { return max_jobs; }; |
---|
120 | }; |
---|