1 | #ifndef MP_PROBE_HXX |
---|
2 | #define MP_PROBE_HXX |
---|
3 | |
---|
4 | #ifndef MULTIPROBE_HXX |
---|
5 | #include "MultiProbe.hxx" |
---|
6 | #endif |
---|
7 | #ifndef SOTL_HXX |
---|
8 | #include "SoTl.hxx" |
---|
9 | #endif |
---|
10 | |
---|
11 | #define NO_GENETIC_ALG 1 |
---|
12 | #define MIN(x,y) (x>y) ? y : x |
---|
13 | #define MAX(x,y) (x>y) ? x : y |
---|
14 | |
---|
15 | #define MAXLIFEFORCOMBI 2 // Eine Sondenkombination lebt maximal MAXLIFEFORCOMBI Generationen |
---|
16 | |
---|
17 | class Generation; |
---|
18 | class GenerationDuplicates; |
---|
19 | class probe_statistic; |
---|
20 | class probe_combi_statistic; |
---|
21 | |
---|
22 | typedef struct |
---|
23 | { |
---|
24 | int probe_index; |
---|
25 | int allowed_mismatches; |
---|
26 | int e_coli_pos; |
---|
27 | }probe; |
---|
28 | |
---|
29 | typedef struct |
---|
30 | { |
---|
31 | probe_combi_statistic *ps; |
---|
32 | char *view_string; |
---|
33 | }result_struct; |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | class probe_tabs |
---|
38 | { |
---|
39 | private: |
---|
40 | int *group_tab; |
---|
41 | int *non_group_tab; |
---|
42 | int length_of_group_tabs; |
---|
43 | public: |
---|
44 | int get_non_group_tab(int j) { return non_group_tab[j]; }; |
---|
45 | int get_group_tab(int j) { return group_tab[j]; }; |
---|
46 | int get_len_group_tabs() { return length_of_group_tabs; }; |
---|
47 | |
---|
48 | probe_tabs *duplicate(); |
---|
49 | void print(); |
---|
50 | probe_tabs(int *new_group_field = NULL, int *new_non_group_field = NULL, int len_group = 0); |
---|
51 | ~probe_tabs(); |
---|
52 | }; |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | class probe_combi_statistic //die Sondenkombis werden in dieser Klasse gespeichert |
---|
57 | { |
---|
58 | private: |
---|
59 | probe **probe_combi; |
---|
60 | probe_tabs *probe_tab; |
---|
61 | |
---|
62 | double expected_children; |
---|
63 | double fitness; |
---|
64 | int life_counter; //Eine Sondenkombination hat nur eine Lebenslaenge von MAXLIFEFORCOMBI |
---|
65 | |
---|
66 | private: |
---|
67 | void quicksort(long left, |
---|
68 | long right); // Randomized Quicksort |
---|
69 | |
---|
70 | int get_dupl_pos(); // gibt Index einer Stelle zurueck, die doppelt vorkommt; field |
---|
71 | // muss sortiert sein !!! |
---|
72 | int modificated_hamming_dist(int one, int two); // pseudo hamming distanz einer Sondenkombi |
---|
73 | |
---|
74 | |
---|
75 | public: |
---|
76 | void set_probe_combi(int ind, probe *f) { probe_combi[ind] = f; }; |
---|
77 | probe *get_probe_combi(int j) { return probe_combi[j]; }; |
---|
78 | double get_fitness() { return fitness; }; |
---|
79 | double get_expected_children() { return expected_children; }; |
---|
80 | int sub_expected_children(double val); |
---|
81 | void init_stats(); |
---|
82 | void scale(double a, double b) { //printf("raw fitness : %f**\n",fitness); |
---|
83 | fitness = a * fitness + b; |
---|
84 | //printf("scaled fitness : %f**\n",fitness); |
---|
85 | //printf("*******************\n\n",fitness); |
---|
86 | }; |
---|
87 | |
---|
88 | BOOL ok_for_next_gen(int &len_roul_wheel); |
---|
89 | |
---|
90 | void sub_life_counter() { life_counter --;}; |
---|
91 | void init_life_counter(); |
---|
92 | BOOL is_dead() { return (life_counter <= 0) ? TRUE : FALSE; }; |
---|
93 | |
---|
94 | void sigma_truncation(double average_fit, double dev); // dient zur Skalierung der Fitness; um zu dominante Kombis zu vermeiden |
---|
95 | double calc_fitness(int len_of_field); // fitness-berechnung einer Sondenkombi |
---|
96 | double calc_expected_children(double average_fitness); |
---|
97 | |
---|
98 | void mutate_Probe(); // mutiert zufaellig die Sondenkombination nr_of_probe. |
---|
99 | void crossover_Probes(probe_combi_statistic *pcombi2); // realisiert den Crossover zwischen Probe1 und Probe2 |
---|
100 | void swap(probe **a, probe **b); |
---|
101 | |
---|
102 | void sort(long feld_laenge); // es wird ein randomized quicksort verwendet |
---|
103 | probe_combi_statistic *duplicate(); //dupliziert dieses Objekt (z.B. fuer naechste Generation) |
---|
104 | probe_combi_statistic *check_duplicates(GenerationDuplicates *dup_tree = NULL); |
---|
105 | // rueckgabewert ist NULL, wenn das Feld duplikate enthaelt bzw. |
---|
106 | // es wird sortiertes field zurueckgegeben. Wenn NULL zurueckkommt, dann |
---|
107 | // wurde field jedoch noch nicht deleted |
---|
108 | int calc_index_system3(int *field); |
---|
109 | void print(); |
---|
110 | void print(probe *p); |
---|
111 | void print(probe **arr, int length); |
---|
112 | |
---|
113 | |
---|
114 | probe_combi_statistic(probe **pc = NULL, probe_tabs *ps = NULL, double exp = 0, double fit = 0 , int lifec = MAXLIFEFORCOMBI); |
---|
115 | ~probe_combi_statistic(); |
---|
116 | }; |
---|
117 | |
---|
118 | class Generation |
---|
119 | { |
---|
120 | private: |
---|
121 | probe_combi_statistic **probe_combi_stat_array; // Liste von Sondenkombinationen, auf denen der genetische Algorithmus aus- |
---|
122 | // gefuehrt wird. |
---|
123 | int probe_combi_array_length; |
---|
124 | GenerationDuplicates *dup_tree; |
---|
125 | double average_fitness; |
---|
126 | double min_fit; |
---|
127 | double max_fit; |
---|
128 | double deviation; //Abweichung |
---|
129 | |
---|
130 | int len_roulette_wheel; //wichtig zur Erstellung der naechsten Generation |
---|
131 | int generation_counter; |
---|
132 | |
---|
133 | |
---|
134 | //***intern variables |
---|
135 | int last_elem; |
---|
136 | |
---|
137 | private: |
---|
138 | void prescale(double *a, double *b); //berechnet Koeffizienten fuer lineare Skalierung |
---|
139 | probe_combi_statistic *choose_combi_for_next_generation(); |
---|
140 | |
---|
141 | public: |
---|
142 | double get_avg_fit() { return average_fitness; }; |
---|
143 | int get_generation() { return generation_counter; }; |
---|
144 | GenerationDuplicates *get_dup_tree() { return dup_tree; }; |
---|
145 | void set_length() { probe_combi_array_length = last_elem; }; // nur verwenden, wenn man weiss was man tut !!!! |
---|
146 | void check_for_results(); //traegt eventuelle. resultate in Ergebnisfenster ein |
---|
147 | |
---|
148 | BOOL insert(probe_combi_statistic *pcs); //FALSE wenn Generation schon MAXPOPULATION Eintraege hat |
---|
149 | |
---|
150 | void init_valuation(); |
---|
151 | void gen_determ_combis(int beg, //wo faengt der Alg. an |
---|
152 | int len, //wieviele probes muessen noch drangehaengt werden |
---|
153 | int &pos_counter, //zaehler fuer probe_combi_stat_array |
---|
154 | probe_combi_statistic *p); //bisher zusammengestellte probe |
---|
155 | |
---|
156 | void calc_fitness(int flag = 0, double old_avg_fit = 0);// fitness-berechnung aller Sondenkombis im Feld; und average_fitness |
---|
157 | // und deviation |
---|
158 | void init_roulette_wheel(); |
---|
159 | Generation *create_next_generation(); // die Kindergeneration wird zurueckgegeben |
---|
160 | |
---|
161 | probe_combi_statistic *single_in_generation(probe_combi_statistic *field); // Nach der Funktion ist sichergestellt, dass dieses field in der |
---|
162 | //Generation nur einmal vorkommt. Achtung: wenn Population sehr klein |
---|
163 | //=> Endlosschleifengefahr ( nicht in dieser Funktion, sondern u.U. in der |
---|
164 | // aufrufenden |
---|
165 | |
---|
166 | void print(); |
---|
167 | |
---|
168 | Generation(int len, int gen_nr); |
---|
169 | ~Generation(); |
---|
170 | }; |
---|
171 | |
---|
172 | class ProbeValuation |
---|
173 | { |
---|
174 | |
---|
175 | private: |
---|
176 | char **sondenarray; |
---|
177 | int *bewertungarray; |
---|
178 | int *mismatch_array; |
---|
179 | int size_sonden_array; |
---|
180 | probe **probe_pool; // Generierung eines Pools, in dem die Wahrscheinlichkeiten fuer die Erfassung |
---|
181 | // der Sonden schon eingearbeitet sind. DIe WS werden vom Benutzer fuer jede |
---|
182 | // einzelne Sonde bestimmt. |
---|
183 | int pool_length, |
---|
184 | max_init_pop_combis; |
---|
185 | Generation *act_generation, |
---|
186 | *child_generation; |
---|
187 | List<result_struct> *computation_result_list; |
---|
188 | |
---|
189 | public: |
---|
190 | void set_act_gen(Generation *g) { act_generation = g; }; |
---|
191 | int get_max_init_for_gen() { return max_init_pop_combis; }; |
---|
192 | int get_pool_length() { return pool_length; }; |
---|
193 | probe **get_probe_pool() { return probe_pool; }; |
---|
194 | int get_size_sondenarray() { return size_sonden_array; }; |
---|
195 | char **get_sondenarray() { return sondenarray; }; |
---|
196 | |
---|
197 | void insert_in_result_list(probe_combi_statistic *pcs); |
---|
198 | |
---|
199 | void init_valuation(); // Zufaellige Auswahl einer Grundmenge von Sondenkombinationen |
---|
200 | void evolution(); // Evolution |
---|
201 | |
---|
202 | ProbeValuation(char **sonden_array, int no_of_sonden, int *bewertung,int *single_mismatch); |
---|
203 | ~ProbeValuation(); |
---|
204 | }; |
---|
205 | |
---|
206 | class GenerationDuplicates // Fuer eine Generation muss ueberprueft werden, ob es doppelte Sondenkombinationen |
---|
207 | { // gibt. |
---|
208 | private: |
---|
209 | int intern_size; //enthaelt size aus dem Konstruktor (size entspricht muss der groesse von sondenarray entsprechen |
---|
210 | GenerationDuplicates **next; //die laenge dieses arrays entspricht der laenge des sondenarrays in ProbeValuation |
---|
211 | int *next_mism; //zu jedem next eintrag merkt man sich wieviele Mismatche schon aufgetreten sind |
---|
212 | //laenge von next_mism ist die maximale anzahl der Mismatche |
---|
213 | |
---|
214 | public: |
---|
215 | BOOL insert(probe_combi_statistic *sondenkombi, BOOL &result, int depth = 0); //fuegt sondenkombination ein, wenn es Sie in dieser Struktur noch nicht gibt(=> TRUE). |
---|
216 | //Wenn es Sie schon gibt, dann FALSE. depth ist nur fuer interne Zwecke. |
---|
217 | |
---|
218 | GenerationDuplicates(int size); |
---|
219 | ~GenerationDuplicates(); //loescht rekursiv nach unten alles. |
---|
220 | }; |
---|
221 | |
---|
222 | #else |
---|
223 | #error MP_probe.hxx included twice |
---|
224 | #endif |
---|
225 | |
---|