source: tags/arb_5.2/MULTI_PROBE/MP_probe.cxx

Last change on this file was 5942, checked in by westram, 15 years ago
  • added AW_window::activate (activates window using show() and sending _NET_ACTIVE_WINDOW to WM)
  • use activate in
    • standard popups (all menu/button popups using AW_POPUP)
    • special popup functions that don't bind window to menu/button
    • small requesters (aw_input, aw_question, …)
    • in popup-functions of information windows. But not if info-window is minimized and user just selects a new result in search window.
    • popup message window on each new message
  • no-exit-shells now popdown when X-Button is pressed (e.g. MESSAGE BOX)
  • fixed several special popup functions
  • renamed AW_window::get_show() → is_shown()
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1#include <MP_probe.hxx>
2
3#include <aw_root.hxx>
4#include <aw_window.hxx>
5#include <stdlib.h>
6#include <time.h>
7#include <string.h>
8
9extern BOOL check_status(int gen_cnt, double avg_fit, double min_fit, double max_fit);
10extern char     *MP_get_comment(int which, char *str);
11
12void ProbeValuation::evolution()
13{
14    long n=0;
15    long moeglichkeiten;
16    double avg_fit = 0;
17
18    for (int i=0; i<size_sonden_array; i++)             // Mismatche (=duplikate) aufsummieren, um Groesse von Pool zu bestimmen.
19        n += mismatch_array[i]+1;
20
21    moeglichkeiten = k_aus_n(mp_gl_awars.no_of_probes, n);
22
23    if (moeglichkeiten <= MAXINITPOPULATION)
24    {
25        act_generation->calc_fitness(NO_GENETIC_ALG);
26        act_generation->check_for_results();
27        return;
28    }
29
30    check_status(0, 0.0, 0.0, 0.0);
31
32
33
34    // hier beginnt der genetische Algorithmus
35    do
36    {
37        act_generation->calc_fitness(0, avg_fit);       // hier wird auch init_roulette_wheel gemacht
38        avg_fit = act_generation->get_avg_fit();
39
40        if (avg_fit == 0 && !Stop_evaluation)
41        {
42            aw_message("Please choose better Probes!");
43            return;
44        }
45
46        if (Stop_evaluation)            //Abgebrochen durch Benutzer
47        {
48            Stop_evaluation = FALSE;
49            act_generation->check_for_results();
50            return;
51        }
52
53        child_generation = act_generation->create_next_generation();
54        delete act_generation;
55        act_generation = NULL;
56
57
58        child_generation->check_for_results();
59
60        act_generation = child_generation;  // zum testen hier nur generierung einer Generation
61    }
62    while (moeglichkeiten/3 > act_generation->get_generation() * MAXPOPULATION); //hier abbruchbedingung
63
64    //Abbruchbedingung deshalb, weil der genetische Alg. keinesfalls mehr Versuche
65    // benoetigt als sequentielles probieren. Hier: Annahme, dass er max.
66    // ein drittel der Versuche benoetigt
67
68    if (act_generation)
69        act_generation->check_for_results();
70}
71
72void ProbeValuation::insert_in_result_list(probe_combi_statistic *pcs)      //pcs darf nur eingetragen werden, wenn es nicht schon vorhanden ist
73{
74    char    *new_list_string,
75        *misms,
76        *probe_string,
77        temp_misms[3];
78    int     probe_len = 0;
79    char      buf[25];
80    char    ecoli_pos[40],temp_ecol[10];
81    int buf_len, i;
82    result_struct *rs = new result_struct,
83        *elem;
84    AW_window   *aww = mp_main->get_mp_window()->get_result_window();
85
86    memset(rs, 0, sizeof(result_struct));
87    memset(ecoli_pos,0, 40);
88
89    for (i=0; i<mp_gl_awars.no_of_probes; i++)
90        probe_len += strlen(sondenarray[pcs->get_probe_combi(i)->probe_index]) + 1; //1 fuer space bzw. 0-Zeichen
91
92    misms = new char[2*mp_gl_awars.no_of_probes+1];
93    probe_string = new char[probe_len+1];
94
95    probe_string[0] = misms[0] = 0;
96    for (i=0; i<mp_gl_awars.no_of_probes; i++)
97    {
98        if (i>0)
99        {
100            strcat(misms," ");
101            strcat(probe_string," ");
102        }
103
104
105        sprintf(temp_misms,"%1d",pcs->get_probe_combi(i)->allowed_mismatches);
106        strcat(misms, temp_misms);
107        sprintf(temp_ecol,"%6d ",pcs->get_probe_combi(i)->e_coli_pos);
108        strcat(ecoli_pos,temp_ecol);
109        strcat(probe_string, sondenarray[pcs->get_probe_combi(i)->probe_index]);
110    }
111
112    ecoli_pos[strlen(ecoli_pos)-1] = 0;
113
114    new_list_string = new char[21+
115                               probe_len+
116                               2*mp_gl_awars.no_of_probes+2+
117                               2*strlen(SEPARATOR)+ strlen(ecoli_pos)+
118                               1];  //1 fuer 0-Zeichen
119
120    sprintf(buf,"%f",pcs->get_fitness());
121    buf_len= strlen(buf);
122    for(i=0;i<20-buf_len;i++)
123        strcat(buf," ");
124
125    sprintf(new_list_string,"%20s%s%s%s%s%s%s",buf,SEPARATOR,misms,SEPARATOR,ecoli_pos,SEPARATOR,probe_string);
126    delete [] misms;
127    delete [] probe_string;
128
129    rs->ps = pcs->duplicate();
130    rs->view_string = new_list_string;
131    elem = computation_result_list->get_first();
132    if (! elem)
133        computation_result_list->insert_as_first(rs);
134    else
135    {
136        while (elem)                    //Liste ist sortiert von groesster Fitness bis kleinster Fitness
137        {
138            if (strcmp(elem->view_string, new_list_string) == 0)
139            {
140                delete new_list_string;
141                delete rs->ps;
142                delete rs;
143                return;
144            }
145
146            if (pcs->get_fitness() > elem->ps->get_fitness())
147            {
148                computation_result_list->insert_before_current(rs);
149                break;
150            }
151
152            elem = computation_result_list->get_next();
153        }
154
155        if (!elem)
156            computation_result_list->insert_as_last(rs);
157    }
158
159
160
161    aww->clear_selection_list( result_probes_list );
162
163    elem = computation_result_list->get_first();
164    while (elem)
165    {
166        aww->insert_selection( result_probes_list, elem->view_string, elem->view_string );
167        elem = computation_result_list->get_next();
168    }
169
170    aww->insert_default_selection( result_probes_list, "", "");
171    aww->update_selection_list( result_probes_list );
172}
173
174void ProbeValuation::init_valuation()
175{
176    int         i, j, k, counter=0;
177    probe       *temp_probe;
178    ST_Container    *stc;
179    AW_window       *aww;
180    char        *ptr, *ptr2;
181
182    if (new_pt_server)
183    {
184        new_pt_server = FALSE;
185
186        if (mp_main->get_stc())
187            delete mp_main->get_stc();
188
189        aw_status("Starting computation");
190        mp_main->set_stc(new ST_Container(MAXSONDENHASHSIZE));
191    }
192
193    if (pt_server_different)
194    {
195        mp_main->set_stc(NULL);
196        new_pt_server = TRUE;
197        return;
198    }
199
200    stc = mp_main->get_stc();
201    aww = mp_main->get_mp_window()->get_window();
202    aww->init_list_entry_iterator(selected_list); //initialisieren
203
204    if (max_init_pop_combis < MAXINITPOPULATION) {
205        for (i=0; i<size_sonden_array; i++)         // generierung eines pools, in dem jede Sonde nur einmal pro Mismatch
206        {                           // vorkommt, damit alle moeglichen Kombinationen deterministisch
207            ptr2 = (char *)aww->get_list_entry_char_value();
208            aww->iterate_list_entry(1);
209
210            for(j=0; j<=mismatch_array[i]; j++)         // generiert werden koennen.
211            {
212                temp_probe = new probe;
213                temp_probe->probe_index = i;
214                temp_probe->allowed_mismatches = j;
215                temp_probe->e_coli_pos = atoi(ptr = MP_get_comment(3,ptr2));
216                free(ptr);
217
218                probe_pool[counter++] = temp_probe;
219            }
220        }
221        pool_length = counter;
222    }
223    else {
224        for (i=0; i<size_sonden_array; i++)
225        {                               // Generierung eines Pools, in dem die Wahrscheinlichkeiten fuer die Erfassung
226            ptr2 = (char *)aww->get_list_entry_char_value();
227            aww->iterate_list_entry(1);
228
229            for(j=0; j<=mismatch_array[i]; j++)         // der Sonden schon eingearbeitet sind. DIe WS werden vom Benutzer fuer jedE
230            {                           // einzelne Sonde bestimmt
231                for (k=0; k < bewertungarray[i]; k++)
232                {
233                    temp_probe = new probe;
234                    temp_probe->probe_index = i;
235                    temp_probe->allowed_mismatches = j;
236                    temp_probe->e_coli_pos = atoi(ptr = MP_get_comment(3,ptr2));
237                    delete ptr;
238
239                    probe_pool[counter++] = temp_probe;
240                }
241            }
242        }
243    }
244
245    act_generation->init_valuation();
246    evolution();
247   
248    aww = mp_main->get_mp_window()->get_result_window();
249    aww->activate();
250}
251
252
253
254ProbeValuation::ProbeValuation(char **sonden_array, int no_of_sonden, int *bewertung, int *mismatch)
255{
256
257    memset(this, 0, sizeof(ProbeValuation));
258
259    sondenarray     = sonden_array;
260    bewertungarray  = bewertung;
261    size_sonden_array   = no_of_sonden;
262    mismatch_array  = mismatch;
263
264    computation_result_list = new List<result_struct>;
265
266    for (int i=0; i<size_sonden_array; i++)             // Mismatche (=duplikate) aufsummieren, um Groesse von Pool zu bestimmen.
267    {
268        max_init_pop_combis += mismatch[i]+1;
269        pool_length += (mismatch_array[i]+1) * bewertungarray[i];
270    }
271
272    max_init_pop_combis = k_aus_n(mp_gl_awars.no_of_probes, max_init_pop_combis);
273
274    if (max_init_pop_combis > MAXINITPOPULATION)        // Ausgangspopulationsgroesse ist limitiert
275        max_init_pop_combis = MAXINITPOPULATION;
276
277    probe_pool = new probe*[pool_length];
278    memset(probe_pool, 0, pool_length * sizeof(probe*));    // Struktur mit 0 initialisieren.
279
280}
281
282
283ProbeValuation::~ProbeValuation()
284{
285    int i;
286    result_struct *elem;
287
288    for (i=0; i<size_sonden_array; i++) free(sondenarray[i]);
289    for (i=0; i<pool_length; i++) delete probe_pool[i];
290
291    elem = computation_result_list->get_first();
292    while (elem) {
293        computation_result_list->remove_first();
294        delete [] elem->view_string;
295        delete elem;
296        elem = computation_result_list->get_first();
297    }
298
299    delete computation_result_list;
300
301    if (act_generation == child_generation) delete act_generation;
302    else {
303        delete act_generation;
304        delete child_generation;
305    }
306
307    delete [] sondenarray;
308    delete [] bewertungarray;
309    delete [] mismatch_array;
310    delete [] probe_pool;
311}
312
Note: See TracBrowser for help on using the repository browser.