// browse neighbours without degeneracy (almost the same as move_set) assume deg.first = true bool browse_neighs(encoded &enc, int &energy, degen °, int &saddle_en) { // count how many times called cnt_move++; // unused, just for necessity of functions short *min_pt = allocopy(enc.pt); // used deg.current = energy; // did we just find escape from basin? bool escape = false; //if (deg.opt->verbose_lvl>3) fprintf(stderr, "\n browse neighs:\n %s %d\n\n", pt_to_str(enc.pt).c_str(), energy); escape = insertions(enc, energy, min_pt, deg, deg.opt->verbose_lvl>3); //if (deg.opt->verbose_lvl>3) fprintf(stderr, "\n"); // deletions if (!escape) escape = deletions(enc, energy, min_pt, deg, deg.opt->verbose_lvl>3); // shifts (only if enabled + noLP disabled) if (deg.opt->shift && !deg.opt->noLP) { if (!escape) escape = shifts(enc, energy, min_pt, deg, deg.opt->verbose_lvl>3); } if (escape) saddle_en = deg.current; free(min_pt); return escape; }
set<short*, setcomp> find_equal_energy(encoded &enc, int energy, degen °, bool direct, bool &lm) { bool (*old_funct) (short *, int) = deg.opt->f_point; deg.opt->f_point = equal_energies; // count how many times called cnt_move++; // unused, just for necessity of functions short *min_pt = allocopy(enc.pt); // used deg.current = energy; // setup degen_energy = energy; degen_saddle = false; degen_done.clear(); degen_undone.clear(); degen_undone.insert(allocopy(enc.pt)); //fprintf(stderr, " ins: %s\n", pt_to_str(enc.pt).c_str() ); while (degen_undone.size()!=0) { // take first short *last = enc.pt; enc.pt = *degen_undone.begin(); degen_undone.erase(degen_undone.begin()); // move it insertions(enc, energy, min_pt, deg, deg.opt->verbose_lvl>3); deletions(enc, energy, min_pt, deg, deg.opt->verbose_lvl>3); // shifts (only if enabled + noLP disabled) if (deg.opt->shift && !deg.opt->noLP) { shifts(enc, energy, min_pt, deg, deg.opt->verbose_lvl>3); } degen_done.insert(enc.pt); //fprintf(stderr, "inserting(done): %s\n", pt_to_str(enc.pt).c_str()); enc.pt = last; } free(min_pt); deg.opt->f_point = old_funct; lm = !degen_saddle; return degen_done; }
static void *thread_start (void *arg) { struct thread_info *tinfo = (struct thread_info *) arg; pthread_barrier_wait (tinfo->barrier); switch (tinfo->action) { case ACTION_INSERTION: insertions (tinfo->map, tinfo->size); break; case ACTION_REMOVAL: removals (tinfo->map, tinfo->size); break; case ACTION_RETRIEVAL: retrievals (tinfo->map, tinfo->size); break; } }
/* move to deepest (or first) neighbour*/ PRIVATE int move_set(Encoded *Enc, struct_en *str){ /* count how many times called*/ cnt_move++; /* count better neighbours*/ int cnt = 0; /* deepest descent*/ struct_en min; min.structure = allocopy(str->structure); min.energy = str->energy; Enc->current_en = str->energy; if (Enc->verbose_lvl>0) { fprintf(stderr, " start of MS:\n "); print_str(stderr, str->structure); fprintf(stderr, " %d\n\n", str->energy); } /* if using first dont do all of them*/ bool end = false; /* insertions*/ if (!end) cnt += insertions(Enc, str, &min); if (Enc->first && cnt>0) end = true; if (Enc->verbose_lvl>1) fprintf(stderr, "\n"); /* deletions*/ if (!end) cnt += deletions(Enc, str, &min); if (Enc->first && cnt>0) end = true; /* shifts (only if enabled + noLP disabled)*/ if (!end && Enc->shift && !Enc->noLP) { cnt += shifts(Enc, str, &min); if (Enc->first && cnt>0) end = true; } /* if degeneracy occurs, solve it!*/ if (!end && (Enc->end_unpr - Enc->begin_unpr)>0) { Enc->processed[Enc->end_pr] = str->structure; Enc->end_pr++; str->structure = Enc->unprocessed[Enc->begin_unpr]; Enc->unprocessed[Enc->begin_unpr]=NULL; Enc->begin_unpr++; cnt += move_set(Enc, str); } else { /* write output to str*/ copy_arr(str->structure, min.structure); str->energy = min.energy; } /* release minimal*/ free(min.structure); /* resolve degeneracy in local minima*/ if ((Enc->end_pr - Enc->begin_pr)>0) { Enc->processed[Enc->end_pr]=str->structure; Enc->end_pr++; int min = find_min(Enc->processed, Enc->begin_pr, Enc->end_pr); short *tmp = Enc->processed[min]; Enc->processed[min] = Enc->processed[Enc->begin_pr]; Enc->processed[Enc->begin_pr] = tmp; str->structure = Enc->processed[Enc->begin_pr]; Enc->begin_pr++; free_degen(Enc); } if (Enc->verbose_lvl>1 && !(Enc->first)) { fprintf(stderr, "\n end of MS:\n "); print_str(stderr, str->structure); fprintf(stderr, " %d\n\n", str->energy); } return cnt; }
// move to deepest (or first) neighbour int move_set(encoded &enc, int &deepest, degen °) { // count how many times called cnt_move++; // count better neighbours int cnt = 0; // deepest descent deg.current = deepest; short *min_pt = allocopy(enc.pt); if (deg.opt->verbose_lvl>3) fprintf(stderr, "\n start of MS:\n %s %d\n\n", pt_to_str(enc.pt).c_str(), deepest); // if using first dont do all of them bool end = false; // insertions if (!end) cnt += insertions(enc, deepest, min_pt, deg, deg.opt->verbose_lvl>3); if (deg.opt->first && cnt>0) end = true; fprintf(stderr, "\n"); // deletions if (!end) cnt += deletions(enc, deepest, min_pt, deg, deg.opt->verbose_lvl>3); if (deg.opt->first && cnt>0) end = true; fprintf(stderr, "\n"); // shifts (only if enabled + noLP disabled) if (!end && deg.opt->shift && !deg.opt->noLP) { cnt += shifts(enc, deepest, min_pt, deg, deg.opt->verbose_lvl>3); if (deg.opt->first && cnt>0) end = true; } if (deg.opt->verbose_lvl>3) fprintf(stderr, "\n %s\n %s\n", enc.seq, pt_to_str(min_pt).c_str()); // if degeneracy occurs, solve it! if (!end && deg.unprocessed.size()>0) { deg.processed.insert(allocopy(enc.pt)); // take first if (enc.pt) free(enc.pt); enc.pt = (*deg.unprocessed.begin()); deg.unprocessed.erase(deg.unprocessed.begin()); if (deg.opt->minh>0.1001) { deepest = energy_of_structure_pt(enc.seq, enc.pt, enc.s0, enc.s1, 0); } cnt += move_set(enc, deepest, deg); } else { copy_arr(enc.pt, min_pt); } free(min_pt); // resolve degeneracy in local minima if (deg.processed.size()>0) { deg.processed.insert(enc.pt); enc.pt = *deg.processed.begin(); deg.processed.erase(deg.processed.begin()); erase_set(deg.processed); } return cnt; }