int main(void) { double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5}; double target1[5]; double target2[5]; double target3[5]; int x; printf("\n\n"); copy_arr(target1, source, 5); printf("Array: target1\n"); for (x = 0; x < 5; x++) printf("%d: %f\n", x, target1[x]); printf("\n"); copy_ptr(target2, source, 5); printf("Array: target2\n"); for (x = 0; x < 5; x++) printf("%d: %f\n", x, target2[x]); printf("\n"); copy_ptrs(target3, source, (source + 5)); printf("Array: target3\n"); for (x = 0; x < 5; x++) printf("%d: %f\n", x, target3[x]); printf("\n\n"); return 0; }
PUBLIC int move_adaptive(char *string, short *ptable, short *s, short *s1, int verbosity_level){ srand(time(NULL)); Encoded enc; enc.seq = string; enc.s0 = s; enc.s1 = s1; /* moves*/ enc.bp_left=0; enc.bp_right=0; enc.bp_left2=0; enc.bp_right2=0; /* options*/ enc.noLP=0; enc.verbose_lvl=verbosity_level; enc.first=1; enc.shift=0; /* degeneracy*/ enc.begin_unpr=0; enc.begin_pr=0; enc.end_unpr=0; enc.end_pr=0; enc.current_en=0; // function enc.funct=NULL; // allocate memory for moves enc.moves_from = (int*) space(ptable[0]*ptable[0]*sizeof(int)); enc.moves_to = (int*) space(ptable[0]*ptable[0]*sizeof(int)); int i; for (i=0; i<MAX_DEGEN; i++) enc.processed[i]=enc.unprocessed[i]=NULL; struct_en str; str.structure = allocopy(ptable); str.energy = energy_of_structure_pt(enc.seq, str.structure, enc.s0, enc.s1, 0); while (move_rset(&enc, &str)!=0) { free_degen(&enc); } free_degen(&enc); copy_arr(ptable, str.structure); free(str.structure); free(enc.moves_from); free(enc.moves_to); return str.energy; }
int main() { init_arr(); copy_arr(); int res_a = foo_a(); int res_b = foo_b(); printf("result a:%d, result b:%d\n", res_a, res_b); return 0; }
PRIVATE int move_rset(Encoded *Enc, struct_en *str){ /* 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 MR:\n "); print_str(stderr, str->structure); fprintf(stderr, " %d\n\n", str->energy); } // construct and permute possible moves construct_moves(Enc, str->structure); /* find first lower one*/ int i; for (i=0; i<Enc->num_moves; i++) { Enc->bp_left = Enc->moves_from[i]; Enc->bp_right = Enc->moves_to[i]; cnt = update_deepest(Enc, str, &min); if (cnt) break; } /* if degeneracy occurs, solve it!*/ if (deal_deg && !cnt && (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_rset(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 (deal_deg && (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); } return cnt; }
int *prisonAfterNDays(int *cells, int cellsSize, int N, int *returnSize) { *returnSize = cellsSize; int first_cells[cellsSize]; int *next_cells = (int *) malloc(sizeof(int) * cellsSize); memset(next_cells, 0, sizeof(int) * cellsSize); for (int i = 0; N-- > 0; ++i) { for (int j = 1; j < cellsSize - 1; ++j) { next_cells[j] = cells[j - 1] == cells[j + 1]; } if (i == 0) { copy_arr(next_cells, first_cells, cellsSize); } else if (equals(first_cells, next_cells, cellsSize)) { N %= i; } copy_arr(next_cells, cells, cellsSize); } return next_cells; }
int main(void) { double source[7] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7}; double target1[3]; copy_arr(&source[2], target1, 3); return 0; }
int main(void) { const int source[LEN1] = {1, 2, 3, 4, 5, 6, 7}; int target[LEN2]; copy_arr(source + 2, target, 3); show_arr(target, 3); return 0; }
int main(void) { double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5}; double target1[5]; double target2[5]; copy_arr(source, target1, 5); copy_ptr(source, target2, 5); return 0; }
PUBLIC int move_first( char *string, short *ptable, short *s, short *s1, int verbosity_level, int shifts, int noLP){ cnt_move = 0; Encoded enc; enc.seq = string; enc.s0 = s; enc.s1 = s1; /* moves*/ enc.bp_left=0; enc.bp_right=0; enc.bp_left2=0; enc.bp_right2=0; /* options*/ enc.noLP=noLP; enc.verbose_lvl=verbosity_level; enc.first=1; enc.shift=shifts; /* degeneracy*/ enc.begin_unpr=0; enc.begin_pr=0; enc.end_unpr=0; enc.end_pr=0; enc.current_en=0; /* function */ enc.funct=NULL; int i; for (i=0; i<MAX_DEGEN; i++) enc.processed[i]=enc.unprocessed[i]=NULL; struct_en str; str.structure = allocopy(ptable); str.energy = energy_of_structure_pt(enc.seq, str.structure, enc.s0, enc.s1, 0); while (move_set(&enc, &str)!=0) { free_degen(&enc); } free_degen(&enc); copy_arr(ptable, str.structure); free(str.structure); return str.energy; }
int main(void) { double ar[2][5] = { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }; double ar1[2][5]; double ar2[2][5]; copy_arr(ar, ar1, 2); copy_ptr(ar, ar2, 2); return 0; }
int main(void) { double source[ROWS][COLS]; double target[ROWS][COLS]; fill_arr(source); copy_arr(source, target); print_ptr(source); print_ptr(target); return 0; }
int main (void){ double origin[3][5] = { {1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15} }; double target[ROWS][COLS]; copy_arr ( origin, target, COLS); show_arr ( origin, COLS); show_arr ( target, COLS); }
int main(void) { const double source[3][5] = { {4.4, 5.6, 7.8, 9.3, 7.1}, {3.8, 6.9, 3.5, 7.0, 2.7}, {5.9, 7.8, 4.8, 3.0, 5.9} }; double target[3][5]; copy_arr(3, 5, source, target); show_arr(3, 5, target); return 0; }
int merge(int *arr, int l_1, int r_1, int l_2, int r_2) { int *a, *b; int i = 0, j = 0, k = l_1; int len_a, len_b; a = copy_arr(arr, l_1, r_1); b = copy_arr(arr, l_2, r_2); len_a = r_1 - l_1; len_b = r_2 - l_2; while (i <= len_a && j <= len_b) { if (a[i] <= b[j]) { arr[k] = a[i]; k++; i++; } else if (a[i] >= b[j]) { arr[k] = b[j]; k++; j++; } } if (i > len_a) { while (j <= len_b) { arr[k] = b[j]; k++; j++; } } else if (j > len_b) { while (i <= len_a) { arr[k] = a[i]; k++; i++; } } free(a); free(b); return 0; }
int main() { int A[SIZE]; int B[SIZE]; time_t start, end; srand(time(NULL)); for(int i=0; i<SIZE; i++) A[i] = rand() % UPPER_LIM; copy_arr(B, A, SIZE); start = clock(); kn_origin1(B, SIZE, K); end = clock(); printf("Time Taken: %ld\n", end-start); print_arr(B, SIZE); copy_arr(B, A, SIZE); start = clock(); kn_origin2(B, SIZE, K); end = clock(); printf("Time Taken: %ld\n", end-start); print_arr(B, SIZE); }
int main(void) { double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5}; double target1[5] = {0}, target2[5] = {0}; printf("Before operation:\n"); printf("source :\t%g\t%g\t%g\t%g\t%g\n",source[0],source[1],source[2],source[3],source[4]); printf("target1:\t%g\t%g\t%g\t%g\t%g\n",target1[0],target1[1],target1[2],target1[3],target1[4]); printf("target2:\t%g\t%g\t%g\t%g\t%g\n",target2[0],target2[1],target2[2],target2[3],target2[4]); copy_arr(source, target1, 5); copy_ptr(source, target2, 5); printf("After operation:\n"); printf("source :\t%g\t%g\t%g\t%g\t%g\n",source[0],source[1],source[2],source[3],source[4]); printf("target1:\t%g\t%g\t%g\t%g\t%g\n",target1[0],target1[1],target1[2],target1[3],target1[4]); printf("target2:\t%g\t%g\t%g\t%g\t%g\n",target2[0],target2[1],target2[2],target2[3],target2[4]); return 0; }
int main(void) { double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5}; double target1[5]; double target2[5]; int index; copy_arr (source, target1, 5); copy_ptr (source, target2, 5); for (index = 0; index < 5; index++) { printf("target1[%d] = %.1lf\n", index, target1[index]); printf("target2[%d] = %.1lf\n", index, target2[index]); } system("pause"); return 0; }
int main(void){ int i; copy_arr(source, target1, 5); copy_ptr(source, target2, 5); printf("source[5] = "); for(i=0;i<5;i++) printf("%.1f, ", source[i]); printf("\ntarget1[5] = "); for(i=0;i<5;i++) printf("%.1f, ", target1[i]); printf("\ntarget2[5] = "); for(i=0;i<5;i++) printf("%.1f, ", target2[i]); printf("\n"); return 0; }
/*使用指针操作数组*/ int main(void) { double source[2][5] = { {1.1, 2.2, 3.3, 4.4, 5.5}, {6.6, 7.7, 8.8, 9.9, 10.1} }; double target[2][5]; /*函数原型声明*/ void copy_arr(const double (*)[N], double (*)[N], int row_num); void print_arr(const double (*)[N], int row_num); copy_arr(source, target, 2); puts("source array: "); print_arr(source, 2); puts("target array: "); print_arr(target, 2); return 0; }
// done with all structures along the way to deepest int update_deepest(encoded &enc, int &deepest, short *min_pt, degen °, bool verbose) { // debug /*if (deg.opt->f_point) { fprintf(stderr, "UD: %s %.2f (%d, %d) (%d, %d)\n", pt_to_str(enc.pt).c_str(), deepest/100.0, enc.bp_left, enc.bp_right, enc.bp_left2, enc.bp_right2); }*/ int tmp_en; if (deg.opt->EOM) { tmp_en = deg.current + energy_of_move_pt(enc.pt, enc.s0, enc.s1, enc.bp_left, enc.bp_right); do_moves(enc, true, false); if (enc.bp_left2 != 0) { tmp_en += energy_of_move_pt(enc.pt, enc.s0, enc.s1, enc.bp_left2, enc.bp_right2); do_moves(enc, false, true); } } else { do_moves(enc); tmp_en = energy_of_structure_pt(enc.seq, enc.pt, enc.s0, enc.s1, 0); } // our function bool res = 0; if (deg.opt->f_point) { res = deg.opt->f_point(enc.pt, tmp_en); undo_moves(enc); return res; } // default behaviour if (tmp_en <= deepest) { deepest = tmp_en; copy_arr(min_pt, enc.pt); } //printf("%s %7.2f\n", pt_to_str(enc.pt).c_str(), tmp_en/100.0); undo_moves(enc); return res; }
void dfs_backtrack( int level ) { if( level == case_num ) { if( length > temp_length ) { length = temp_length; copy_arr( solution, temp_solution ); return; } } for( int i = 0; i < case_num; i++ ) { if( !is_vis[i] ) { temp_solution[level] = i; is_vis[i] = true; // start calc distance from the second point if( level ) { int pre_idx = temp_solution[level-1]; double dist = distance( cords[pre_idx][0], cords[pre_idx][1], cords[i][0], cords[i][1] ); temp_length += dist; dfs_backtrack(level+1); // backtrack is_vis[i] = false; // I forgot this, temp_length -= dist; } // for the first point, no need to calc the distance, directly recursion else { dfs_backtrack(level+1); is_vis[i] = false; } } } }
/***********************************************************************\ ** If it has been decided that the incumbent solution should change, ** several values must be updated, including the incumbent X, the ** incumbent cut, the estimate at the incumbent and the standard ** deviation of the estimate, as well as the last_update counter. ** This function performs these updates. It assumes that the candidate ** solution becomes the incumbent solution, with a height corresponding ** to the _est_ parameter. \***********************************************************************/ void new_incumbent(prob_type *p, cell_type *c, soln_type *s, double est) { vector X; double val, stdev; int obs, idx; int count; i_type i; #ifdef TRACE printf("Inside new_incumbent\n"); #endif /* Copy over information about the new incumbent */ copy_arr(s->incumb_x, s->candid_x, p->num->mast_cols) s->incumb_cut = c->cuts->cnt - 1; s->incumb_est = est; s->last_update = c->k; s->incumb_k = c->k; /* ** The cut consists of an average of many pi X omega products. We ** use the mean and standard deviation of this collection of products ** in the check for optimality, so they are updated here. We loop ** through the istar indices of new incumbent cut to find the stdev. */ count = 0; stdev = 0.0; X = s->incumb_x; if (c->cuts->cnt > 0) { for (obs = 0; obs < c->cuts->val[s->incumb_cut]->omega_cnt; obs++) if (valid_omega_idx(s->omega, obs)) { /* Find the pi from the cut's argmax for this observation */ i.sigma = c->cuts->val[s->incumb_cut]->istar[obs]; i.delta = c->sigma->lamb[i.sigma]; /* ** Couldn't this be done only in the optimality check, so we ** don't do it every time we change our minds about the incumbent ? ** Which happens more often -- an optimality check or a change of ** the incumbent x? ** What about when the the incumbent cut is updated, but X is not? */ /* Calculate the height for this observation and dual vector */ val = c->sigma->val[i.sigma].R + s->delta->val[i.delta][obs].R; for (idx = 0; idx < p->num->nz_cols; idx++) val -= c->sigma->val[i.sigma].T[idx] * X[c->sigma->col[idx]]; for (idx = 0; idx < p->num->rv_cols; idx++) val -= s->delta->val[i.delta][obs].T[idx] * X[s->delta->col[idx]]; stdev += s->omega->weight[obs] * SQR(s->incumb_est - val); count += s->omega->weight[obs]; } s->incumb_stdev = sqrt(stdev / (double) count); } s->incumbent_change = TRUE; #ifdef DEBUG printf("\nMade a new incumbent, since it qualified"); print_cut(c->cuts, p->num, s->incumb_cut); #endif }
short *allocopy(short *src) { short *res = (short*) space(sizeof(short)*(src[0]+1)); copy_arr(res, src); return res; }
void DSU::FindNumbers(int begin, int end, path_pk *path, vector<int> &lm_numbers, bool shifts, bool noLP, bool debug, bool no_new) { // first resolve small case: if (end-begin<4) { bool begins = true; for (int i=begin+1; i<end; i++) { // get the minimum short *tmp_str = allocopy(path[i].structure); int tmp_en; if (pknots) { Structure str(seq, tmp_str, s0, s1); tmp_en = move_gradient_pk(seq, &str, s0, s1, shifts, 0); copy_arr(tmp_str, str.str); } else { tmp_en = move_gradient(seq, tmp_str, s0, s1, 0, shifts, noLP); } // speedup if (lm_numbers[begin] != -1 && begins && tmp_en == LM[lm_numbers[begin]].energy && str_eq(LM[lm_numbers[begin]].structure, tmp_str)) { lm_numbers[i] = lm_numbers[begin]; } else { begins = false; if (lm_numbers[end] != -1 && tmp_en == LM[lm_numbers[end]].energy && str_eq(LM[lm_numbers[end]].structure, tmp_str)) { lm_numbers[i] = lm_numbers[end]; } } if (lm_numbers[i]==-1) { lm_numbers[i] = FindNum(tmp_en, tmp_str); // update UBlist if (lm_numbers[i]==-1 && !no_new) { if (gl_maxen < tmp_en) { //fprintf(stderr, "exceeds en.: %s %6.2f\n", pt_to_str(tmp_str).c_str(), tmp_en/100.0); lm_numbers[i] = AddLMtoTBD(tmp_str, tmp_en, EE_DSU, debug); } else { if (debug) fprintf(stderr, "cannot find: %s %6.2f\n", pt_to_str_pk(tmp_str).c_str(), tmp_en/100.0); // add to list of minima and count with them later... lm_numbers[i] = AddLMtoTBD(tmp_str, tmp_en, NORM_CF, debug); } } } else debug_c++; free(tmp_str); } return ; } // da middle one int pivot = (end+begin)/2; short *tmp_str = allocopy(path[pivot].structure); //fprintf(stderr, "%s\n", pt_to_str(tmp_str).c_str()); int tmp_en; if (pknots) { Structure str(seq, tmp_str, s0, s1); tmp_en = move_gradient_pk(seq, &str, s0, s1, shifts, 0); copy_arr(tmp_str, str.str); } else { tmp_en = move_gradient(seq, tmp_str, s0, s1, 0, shifts, noLP); } //fprintf(stderr, "%s\n", pt_to_str(tmp_str).c_str()); // speed up: if (lm_numbers[begin] != -1 && tmp_en == LM[lm_numbers[begin]].energy && str_eq(LM[lm_numbers[begin]].structure, tmp_str)) { lm_numbers[pivot] = lm_numbers[begin]; } else { if (lm_numbers[end] != -1 && tmp_en == LM[lm_numbers[end]].energy && str_eq(LM[lm_numbers[end]].structure, tmp_str)) { lm_numbers[pivot] = lm_numbers[end]; } } // normal behaviour if (lm_numbers[pivot]==-1) { lm_numbers[pivot] = FindNum(tmp_en, tmp_str); // update UBlist if (lm_numbers[pivot]==-1 && !no_new) { if (gl_maxen < tmp_en) { //fprintf(stderr, "exceeds en.: %s %6.2f\n", pt_to_str(tmp_str).c_str(), tmp_en/100.0); lm_numbers[pivot] = AddLMtoTBD(tmp_str, tmp_en, EE_DSU, debug); } else { if (debug) fprintf(stderr, "cannot find: %s %6.2f\n", pt_to_str_pk(tmp_str).c_str(), tmp_en/100.0); // add to list of minima and count with them later... lm_numbers[pivot] = AddLMtoTBD(tmp_str, tmp_en, NORM_CF, debug); } } } else debug_c++; free(tmp_str); // continue recursion: if ((lm_numbers[pivot]!=lm_numbers[begin] || lm_numbers[pivot]==-1) && pivot-begin>1) FindNumbers(begin, pivot, path, lm_numbers, shifts, noLP, debug, no_new); if ((lm_numbers[pivot]!=lm_numbers[end] || lm_numbers[pivot]==-1) && end-pivot>1) FindNumbers(pivot, end, path, lm_numbers, shifts, noLP, debug, no_new); // return maximal energy return ; }
/* 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; }
/* done with all structures along the way to deepest*/ PRIVATE int update_deepest(Encoded *Enc, struct_en *str, struct_en *min){ /* apply move + get its energy*/ int tmp_en; tmp_en = str->energy + energy_of_move_pt(str->structure, Enc->s0, Enc->s1, Enc->bp_left, Enc->bp_right); do_move(str->structure, Enc->bp_left, Enc->bp_right); if (Enc->bp_left2 != 0) { tmp_en += energy_of_move_pt(str->structure, Enc->s0, Enc->s1, Enc->bp_left2, Enc->bp_right2); do_move(str->structure, Enc->bp_left2, Enc->bp_right2); } int last_en = str->energy; str->energy = tmp_en; /* use f_point if we have it */ if (Enc->funct) { int end = Enc->funct(str, min); /* undo moves */ if (Enc->bp_left2!=0) do_move(str->structure, -Enc->bp_left2, -Enc->bp_right2); do_move(str->structure, -Enc->bp_left, -Enc->bp_right); str->energy = last_en; Enc->bp_left=0; Enc->bp_right=0; Enc->bp_left2=0; Enc->bp_right2=0; return (end?1:0); } if (Enc->verbose_lvl>1) { fprintf(stderr, " "); print_str(stderr, str->structure); fprintf(stderr, " %d\n", tmp_en); } /* better deepest*/ if (tmp_en < min->energy) { min->energy = tmp_en; copy_arr(min->structure, str->structure); /* delete degeneracy*/ free_degen(Enc); /* undo moves*/ if (Enc->bp_left2!=0) do_move(str->structure, -Enc->bp_left2, -Enc->bp_right2); do_move(str->structure, -Enc->bp_left, -Enc->bp_right); str->energy = last_en; Enc->bp_left=0; Enc->bp_right=0; Enc->bp_left2=0; Enc->bp_right2=0; return 1; } /* degeneracy*/ if ((str->energy == min->energy) && (Enc->current_en == min->energy)) { int found = 0; int i; for (i=Enc->begin_pr; i<Enc->end_pr; i++) { if (equals(Enc->processed[i], str->structure)) { found = 1; break; } } for (i=Enc->begin_unpr; !found && i<Enc->end_unpr; i++) { if (equals(Enc->unprocessed[i], str->structure)) { found = 1; break; } } if (!found) { /* print_stren(stderr, str); // fprintf(stderr, " %6.2f\n", str->energy); */ Enc->unprocessed[Enc->end_unpr]=allocopy(str->structure); Enc->end_unpr++; } } /* undo moves*/ if (Enc->bp_left2!=0) do_move(str->structure, -Enc->bp_left2, -Enc->bp_right2); do_move(str->structure, -Enc->bp_left, -Enc->bp_right); str->energy = last_en; Enc->bp_left=0; Enc->bp_right=0; Enc->bp_left2=0; Enc->bp_right2=0; return 0; }
PUBLIC short * allocopy(short *src){ short *res = (short*) vrna_alloc(sizeof(short)*(src[0]+1)); copy_arr(res, src); return res; }
// 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; }