/* * Convert filter information format into vlan[-mac][-group] string. * Return the number of bytes written into buffer. Return 0 if not * enough buffer space. */ static int fid2str(char *s, size_t length, int fif, struct vdpnl_mac *p) { int c; size_t total = 0; c = snprintf(s, length, "%d", vdp22_set_qos(p->qos) | vdp22_set_vlanid(p->vlan)); s = check_and_update(&total, &length, s, c); if (!s) goto out; if (fif == VDP22_FFMT_MACVID || fif == VDP22_FFMT_GROUPMACVID) { c = snprintf(s, length, "-%02x:%02x:%02x:%02x:%02x:%02x", p->mac[0], p->mac[1], p->mac[2], p->mac[3], p->mac[4], p->mac[5]); s = check_and_update(&total, &length, s, c); if (!s) goto out; } if (fif == VDP22_FFMT_GROUPVID || fif == VDP22_FFMT_GROUPMACVID) { c = snprintf(s, length, "-%ld", p->gpid); s = check_and_update(&total, &length, s, c); if (!s) goto out; } out: return s ? total : 0; }
/* * Convert a vdpnl_vsi to string. */ int vdp_vdpnl2str(struct vdpnl_vsi *p, char *s, size_t length) { int c, i; size_t total = 0; char instance[VDP_UUID_STRLEN + 2]; mgrid2str(instance, p, sizeof(instance)); c = snprintf(s, length, "%s,%s,%ld,%d,", mode2str(p->request), instance, p->vsi_typeid, p->vsi_typeversion); s = check_and_update(&total, &length, s, c); if (!s) goto out; vdp_uuid2str(p->vsi_uuid, instance, sizeof(instance)); c = snprintf(s, length, "%s,%d,", instance, p->response); s = check_and_update(&total, &length, s, c); if (!s) goto out; /* Add Filter information data */ for (i = 0; i < p->macsz; ++i) { c = fid2str(s, length, p->filter_fmt, &p->maclist[i]); s = check_and_update(&total, &length, s, c); if (!c) goto out; if (p->macsz > 1 && i < p->macsz - 1) { c = snprintf(s, length, ","); s = check_and_update(&total, &length, s, c); if (!s) goto out; } } out: return s ? total : 0; }
void run_test(Cost_Map &map, Point &start, Point &goal, vector<int> ×) { struct timeval pre; struct timeval post; /// printf("UCS\n"); UCS ucs(&map, start, goal); gettimeofday(&pre, NULL); Path path = ucs.search(); gettimeofday(&post, NULL); double reference_cost = path.length; check_and_update(start, goal, pre, post, reference_cost, path.length, times); check_and_update(start, goal, pre, post, reference_cost, path.length, times); /// printf("A*\n"); Manhattan Manhattan(&map, start, goal); gettimeofday(&pre, NULL); path = Manhattan.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); check_and_update(start, goal, pre, post, reference_cost, path.length, times); /// printf("A*\n"); Euclidean euclidean(&map, start, goal); gettimeofday(&pre, NULL); path = euclidean.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); check_and_update(start, goal, pre, post, reference_cost, path.length, times); /// printf("A*\n"); Octile octile(&map, start, goal); gettimeofday(&pre, NULL); path = octile.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); check_and_update(start, goal, pre, post, reference_cost, path.length, times); /// printf("Coarse single\n"); CUCS_Heuristic cucs(&map, start, goal); gettimeofday(&pre, NULL); path = cucs.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); check_and_update(start, goal, pre, post, reference_cost, path.length, times); /// printf("BB\n"); Boundaries_Blocking bb2(&map, start, goal, 2, xscale, yscale); gettimeofday(&pre, NULL); path = bb2.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); Boundaries_Blocking bb(&map, start, goal, levels, xscale, yscale); gettimeofday(&pre, NULL); path = bb.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); /// printf("BN\n"); Boundaries_NonBlocking bnb2(&map, start, goal, 2, xscale, yscale); gettimeofday(&pre, NULL); path = bnb2.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); Boundaries_NonBlocking bnb(&map, start, goal, levels, xscale, yscale); gettimeofday(&pre, NULL); path = bnb.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); /// printf("CB\n"); Corners_Blocking cb2(&map, start, goal, 2, xscale, yscale); gettimeofday(&pre, NULL); path = cb2.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); Corners_Blocking cb(&map, start, goal, levels, xscale, yscale); gettimeofday(&pre, NULL); path = cb.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); /// printf("CN\n"); Corners_NonBlocking cnb2(&map, start, goal, 2, xscale, yscale); gettimeofday(&pre, NULL); path = cnb2.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); Corners_NonBlocking cnb(&map, start, goal, levels, xscale, yscale); gettimeofday(&pre, NULL); path = cnb.search(); gettimeofday(&post, NULL); check_and_update(start, goal, pre, post, reference_cost, path.length, times); }
struct cb_alignment cb_align_nw(struct cb_align_nw_memory *mem, char *rseq, int dp_len1, int i1, int dir1, char *oseq, int dp_len2, int i2, int dir2, bool *matches, int *matches_index) { struct cb_alignment align; int matches_count = 0, i = 0; struct cb_nw_tables tables = make_nw_tables(rseq, dp_len1, i1, dir1, oseq, dp_len2, i2, dir2); int *best = best_edge(tables.dp_score, dp_len1, dp_len2); int cur_j1, cur_j2; int dir_prod; int **dp_score, **dp_from; bool *matches_to_add; char *subs1_dp, *subs2_dp; int num_steps; best = backtrack_to_clump(tables, best); if (best[0] <= 0) { align.ref = "\0"; align.org = "\0"; align.length = -1; free(best); for (i = 0; i <= dp_len1; i++) { free(tables.dp_score[i]); free(tables.dp_from[i]); } free(tables.dp_score); free(tables.dp_from); return align; } cur_j1 = best[0]; cur_j2 = best[1]; dir_prod = dir1 * dir2; dp_score = tables.dp_score; dp_from = tables.dp_from; matches_to_add = malloc((cur_j1 + cur_j2)*sizeof(*matches_to_add)); assert(matches_to_add); subs1_dp = malloc((cur_j1 + cur_j2)*sizeof(*subs1_dp)); assert(subs1_dp); subs2_dp = malloc((cur_j1 + cur_j2)*sizeof(*subs2_dp)); assert(subs2_dp); num_steps = 0; align.ref = "\0"; align.org = "\0"; align.length = -1; while (!(cur_j1 == 0 && cur_j2 == 0)) { int prev_j1, prev_j2; switch (dp_from[cur_j1][cur_j2]) { char c1, c2; case 0: prev_j1 = cur_j1-1; prev_j2 = cur_j2-1; /*match or substitution*/ c1 = rseq[i1+dir1*prev_j1]; /*comp if antisense*/ c2 = oseq[i2+dir2*prev_j2]; if (dir_prod == -1) c2 = base_complement(c2); subs1_dp[num_steps] = c1; subs2_dp[num_steps] = c2; break; case 2: prev_j1 = cur_j1; prev_j2 = cur_j2-1; /*advance 2; gap in 1*/ c2 = oseq[i2+dir2*prev_j2]; if (dir_prod == -1) c2 = base_complement(c2); /*comp if antisense*/ subs1_dp[num_steps] = '-'; subs2_dp[num_steps] = c2; break; default: prev_j1 = cur_j1-1; prev_j2 = cur_j2; /*advance 1; gap in 2*/ c1 = rseq[i1+dir1*prev_j1]; subs1_dp[num_steps] = c1; subs2_dp[num_steps] = '-'; } matches_to_add[num_steps] = dp_score[cur_j1][cur_j2] > dp_score[prev_j1][prev_j2]; num_steps++; cur_j1 = prev_j1; cur_j2 = prev_j2; } for (i = 0; i < num_steps/2; i++) { /* flip order */ bool temp = matches_to_add[num_steps-i-1]; matches_to_add[num_steps-1-i] = matches_to_add[i]; matches_to_add[i] = temp; } /*note: need to flip order*/ if (dp_len1 < compress_flags.min_match_len && dp_len2 < compress_flags.min_match_len) for (i = *matches_index - 100; i < *matches_index; i++) if (matches[i]) matches_count++; /*Make sure we don't have a bad window unless we are running Needleman-Wunsch alignment on a match. If we have a bad window, then throw out this alignment. Otherwise, copy the alignment into align.org and align.ref.*/ if (dp_len1 < compress_flags.min_match_len && dp_len2 < compress_flags.min_match_len && check_and_update(matches, matches_index, &matches_count, matches_to_add, num_steps) != num_steps) align.length = -1; else { align.length = num_steps; align.org = malloc((align.length+1)*sizeof(*(align.org))); assert(align.org); align.ref = malloc((align.length+1)*sizeof(*(align.ref))); assert(align.ref); for (i = 0; i < align.length; i++) { /*Don't update the matches array if we are running Needleman-Wunsch alignment on a match.*/ if (dp_len1 < compress_flags.min_match_len && dp_len2 < compress_flags.min_match_len) matches[(*matches_index)+i] = matches_to_add[i]; align.ref[i] = subs1_dp[align.length-i-1]; align.org[i] = subs2_dp[align.length-i-1]; } align.org[align.length] = '\0'; align.ref[align.length] = '\0'; } free(best); for (i = 0; i <= dp_len1; i++) { free(tables.dp_score[i]); free(tables.dp_from[i]); } free(tables.dp_score); free(tables.dp_from); free(subs1_dp); free(subs2_dp); free(matches_to_add); return align; }
struct ungapped_alignment cb_align_ungapped(char *rseq, int32_t rstart, int32_t rend, int32_t dir1, int32_t i1, char *oseq, int32_t ostart, int32_t oend, int32_t dir2, int32_t i2, bool *matches, bool *matches_past_clump, int *matches_index) { int32_t length, scanned, successive; int32_t rlen, olen; int32_t i; int32_t matches_since_last_consec; int consec_match_clump_size; int32_t dir_prod; int matches_count; int temp_index; struct ungapped_alignment ungapped; ungapped.length = -1; ungapped.found_bad_window = false; length = 0; scanned = 0; consec_match_clump_size = compress_flags.consec_match_clump_size; successive = consec_match_clump_size; rlen = rend - rstart; olen = oend - ostart; dir_prod = dir1 * dir2; temp_index = 0; matches_count = 0; matches_since_last_consec = 0; for (i = *matches_index - 100; i < *matches_index; i++) if (matches[i]) matches_count++; while (i1 >= rstart && i1 < rend && i2 >= ostart && i2 < oend) { int cur_ismatch = bases_match(rseq[i1], oseq[i2], dir_prod); i1 += dir1; i2 += dir2; scanned++; if (cur_ismatch == 1) { matches_past_clump[temp_index] = true; temp_index++; successive++; if (successive >= consec_match_clump_size) { int update = check_and_update(matches, matches_index, &matches_count, matches_past_clump, temp_index); length += update; if (update != temp_index) { ungapped.length = length; ungapped.found_bad_window = true; return ungapped; } temp_index = 0; matches_since_last_consec = 0; } else matches_since_last_consec++; } else { matches_past_clump[temp_index] = false; temp_index++; successive = 0; if (scanned - length >= compress_flags.btwn_match_min_dist_check) { if ((double)matches_since_last_consec < (scanned-length)*0.5) { ungapped.length = length; return ungapped; } } } } ungapped.length = scanned; return ungapped; }