sint * calc_seq_weights(sint fseq, sint nseq, IN_TREEPTR itree,Boolean no_weights) { sint i; sint temp, sum, *weight; sint *sweight; sweight = (sint *)ckalloc((nseq+1) * sizeof(sint)); /* If there are more than three sequences.... */ if ((nseq-fseq >= 2) && (itree->distance_tree == TRUE) && (no_weights==FALSE)) { /* Calculate sequence weights based on Phylip tree. */ weight = (sint *)ckalloc((nseq+1) * sizeof(sint)); for (i=fseq; i<nseq; i++) weight[i] = calc_weight(itree,i); /* Normalise the weights, such that the sum of the weights = INT_SCALE_FACTOR */ sum = 0; for (i=fseq; i<nseq; i++) sum += weight[i]; if (sum == 0) { for (i=fseq; i<nseq; i++) weight[i] = 1; sum = i; } for (i=fseq; i<nseq; i++) { sweight[i] = (weight[i] * INT_SCALE_FACTOR) / sum; if (sweight[i] < 1) sweight[i] = 1; } weight=ckfree((void *)weight); } else { /* Otherwise, use identity weights. */ temp = INT_SCALE_FACTOR / nseq; for (i=fseq; i<nseq; i++) sweight[i] = temp; } return sweight; }
void calc_seq_weights(sint first_seq, sint last_seq, sint *sweight) { sint i, nseqs; sint temp, sum, *weight; /* If there are more than three sequences.... */ nseqs = last_seq-first_seq; if ((nseqs >= 2) && (distance_tree == TRUE) && (no_weights == FALSE)) { /* Calculate sequence weights based on Phylip tree. */ weight = (sint *)ckalloc((last_seq+1) * sizeof(sint)); for (i=first_seq; i<last_seq; i++) weight[i] = calc_weight(i); /* Normalise the weights, such that the sum of the weights = INT_SCALE_FACTOR */ sum = 0; for (i=first_seq; i<last_seq; i++) sum += weight[i]; if (sum == 0) { for (i=first_seq; i<last_seq; i++) weight[i] = 1; sum = i; } for (i=first_seq; i<last_seq; i++) { sweight[i] = (weight[i] * INT_SCALE_FACTOR) / sum; if (sweight[i] < 1) sweight[i] = 1; } weight=ckfree((void *)weight); } else { /* Otherwise, use identity weights. */ temp = INT_SCALE_FACTOR / nseqs; for (i=first_seq; i<last_seq; i++) sweight[i] = temp; } }
int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int T; int a, b; // clock_t begin_time = clock(); ten[0] = 1; for(int i = 1; i < 10; ++i) ten[i] = ten[i-1]*10; scanf("%d", &T); for(int tc = 1; tc <= T; ++tc) { memset(dp, -1, sizeof(dp)); scanf("%d%d", &a, &b); calc_weight(a); printf("Case #%d: %d\n", tc, solve(b)); } // printf("%lf\n", float( clock () - begin_time )); }
//FUNC 执行抽取 //IN _doc_pointer: 待抽取的文本指针 //IN _doc_len: 待抽取的文本长度 //RET 0:正常 其他:错误码 可用get_error_description获取错误信息 var_4 TF_word_extractor::extract( var_u4 _doc_len, var_1* _doc_pointer) { if (!TEST_FLAG(m_status, WE_init)) { LOG_ERROR("请先调用", "TF_word_extractor::init"); return RET_ERROR_INVALID_PARAM; } RESET_FLAG(m_status, WE_EXTR); m_features_size = 0; m_feature_map.ClearHashSearch(); var_4 ret = base_word_extractor::parse_news_buf(_doc_pointer, _doc_len); if (ret) { LOG_FAILE_CALL_RET("TF_word_extractor::extract", "base_word_extractor::parse_news_buf", ret); return RET_ERROR_INVALID_PARAM; } ret = calc_weight(m_tit_inf.left, m_tit_inf.right, m_base_conf._tit_weight); if (ret) { LOG_FAILE_CALL_RET("TF_word_extractor::extract", "TF_word_extractor::calc_weight", ret); return RET_ERROR_INVALID_PARAM; } ret = calc_weight(m_text_inf.left, m_text_inf.right, 1); if (ret) { LOG_FAILE_CALL_RET("TF_word_extractor::extract", "TF_word_extractor::calc_weight", ret); return RET_ERROR_INVALID_PARAM; } // if (m_features_size < m_base_conf._feature_min_num) // {//! 关键词个数太少,抛弃掉(常常是英文新闻、乱码新闻、无正文、短新闻) // return RET_FALSE; // } ret = select_feature(); if (ret) {// 计算权重,选特征词 LOG_FAILE_CALL_RET("TF_word_extractor::extract", "TF_word_extractor::select_feature", ret); return RET_ERROR_INVALID_PARAM; } ret = m_share_container->exist_nid(m_news_ID); if (!ret) {// 不存在, 更新DF ret = m_share_container->update_DF(m_sel_features, m_sel_cnt); if (ret) { LOG_FAILE_CALL_RET("TF_word_extractor::extract", "m_share_container->update_DF", ret); return RET_ERROR_INVALID_PARAM; } ret = m_share_container->add_nid(m_news_ID); if (ret) { LOG_FAILE_CALL_RET("TF_word_extractor::extract", "m_share_container->add_nid", ret); return RET_ERROR_INVALID_PARAM; } } SET_FLAG(m_status, WE_EXTR); return RET_SECCEED; }
/* This is to be called whenever anything might change player performance in melee, such as changing weapon, statistics, etc. */ void calc_melee(void) { calc_weight(); Player.maxweight = (Player.str * Player.agi * 10); Player.absorption = Player.status[PROTECTION]; Player.defense = 2 * statmod(Player.agi)+(Player.level/2); Player.hit = Player.level + statmod(Player.dex)+1; Player.dmg = statmod(Player.str)+3; Player.speed = 5 - min(4,(statmod(Player.agi)/2)); if (Player.status[HASTED] > 0) Player.speed = Player.speed / 2; if (Player.status[SLOWED] > 0) Player.speed = Player.speed * 2; if (Player.itemweight > 0) switch(Player.maxweight / Player.itemweight) { case 0: Player.speed+=6; break; case 1: Player.speed+=3; break; case 2: Player.speed+=2; break; case 3: Player.speed+=1; break; } if (Player.status[ACCURATE]) Player.hit+=20; if (Player.status[HERO]) Player.hit+=Player.dex; if (Player.status[HERO]) Player.dmg+=Player.str; if (Player.status[HERO]) Player.defense+=Player.agi; if (Player.status[HERO]) Player.speed=Player.speed / 2; Player.speed = max(1,min(25,Player.speed)); if (State.getMounted()) { Player.speed = 3; Player.hit += 10; Player.dmg += 10; } else if (Player.rank[MONKS] > 0) { /* monks are faster when not in armor or on horseback */ if (Player.possessions[O_ARMOR] == NULL) { Player.speed += (min(0,(Player.rank[MONKS] -1))); } } /* weapon */ /* have to check for used since it could be a 2h weapon just carried in one hand */ if (Player.possessions[O_WEAPON_HAND] != NULL) if (Player.possessions[O_WEAPON_HAND]->used && ((Player.possessions[O_WEAPON_HAND]->objchar==WEAPON)|| (Player.possessions[O_WEAPON_HAND]->objchar==MISSILEWEAPON))) { Player.hit += Player.possessions[O_WEAPON_HAND]->hit + Player.possessions[O_WEAPON_HAND]->plus; Player.dmg += Player.possessions[O_WEAPON_HAND]->dmg + Player.possessions[O_WEAPON_HAND]->plus; } if (Player.rank[MONKS] > 0) { /* monks */ /* aren't monks just obscene? PGM */ if (Player.possessions[O_WEAPON_HAND] == NULL) /*barehanded*/ { /* all monks get a bonus in unarmed combat */ Player.hit += ( Player.rank[MONKS] * Player.level ); Player.dmg += ( Player.rank[MONKS] * Player.level ); Player.defense += ( Player.rank[MONKS] * Player.level ); if (Player.rank[MONKS] == MONK_GRANDMASTER) { /* Grandmaster does 3x damage in unarmed combat. */ Player.dmg *= 3; } } } /* shield or defensive weapon */ if (Player.possessions[O_SHIELD] != NULL) { Player.defense += Player.possessions[O_SHIELD]->aux + Player.possessions[O_SHIELD]->plus; } /* armor */ if (Player.possessions[O_ARMOR] != NULL) { Player.absorption += Player.possessions[O_ARMOR]->dmg; Player.defense += Player.possessions[O_ARMOR]->plus - Player.possessions[O_ARMOR]->aux; } if (strlen(Player.combatManeuvers) > 2*maneuvers()) default_maneuvers(); comwinprint(); showflags(); dataprint(); }
static int load_config(int reloading) { struct dist_list *main_list = NULL, *new_list, *old_list = NULL, *lp = NULL; switch_status_t status = SWITCH_STATUS_FALSE; char *cf = "distributor.conf"; switch_xml_t cfg, xml, lists, list, param; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; } if (!(lists = switch_xml_child(cfg, "lists"))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find any lists!\n"); return status; } switch_mutex_lock(globals.mod_lock); for (list = switch_xml_child(lists, "list"); list; list = list->next) { const char *name = switch_xml_attr(list, "name"); const char *tweight = switch_xml_attr(list, "total-weight"); struct dist_node *node, *np = NULL; if (zstr(name)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing NAME!\n"); continue; } if (!zstr(tweight)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "The total-weight attribute is no longer necessary.\n"); } switch_zmalloc(new_list, sizeof(*new_list)); new_list->name = strdup(name); new_list->last = -1; if (lp) { lp->next = new_list; } else { main_list = new_list; } lp = new_list; for (param = switch_xml_child(list, "node"); param; param = param->next) { char *name_attr = (char *) switch_xml_attr_soft(param, "name"); char *weight_val = (char *) switch_xml_attr_soft(param, "weight"); int tmp; if ((tmp = atoi(weight_val)) < 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Weight %d value incorrect, must be > 0\n", tmp); continue; } switch_zmalloc(node, sizeof(*node)); node->name = strdup(name_attr); node->wval = tmp; if (np) { np->next = node; } else { lp->nodes = node; } np = node; lp->node_count++; } calc_weight(lp); } if (main_list) { old_list = globals.list; globals.list = main_list; status = SWITCH_STATUS_SUCCESS; } switch_mutex_unlock(globals.mod_lock); if (old_list) { destroy_list(old_list); } if (xml) { switch_xml_free(xml); } return status; }
/** * test function that constructs an arbitrary consistent alignment.this function * is used to check the the correctness of adapt_diag() and align_diag() * * Returns whether something new could be aligned */ char simple_aligner(struct seq_col *scol, struct diag_col *dcol, struct scr_matrix* smatrix, struct prob_dist *pdist, struct alignment *algn, int round) { int dlen = dcol->diag_amount; int i; struct diag * dg,*tdg; char changed; char alignedSomething = 0; // compute counter weights // heapify struct diag **diags = dcol->diags; //calloc(dlen, sizeof(struct diag *)); int alloc_dlen = dlen; for(i= (dlen+1)/2-1;i>=0;i--) { heapify_diag_array(diags, i, dlen,0); } //memset(algn->redo_seqs, 0, sizeof(char)*slen*slen); double oldweight=0.0, prevweight; i=0; double total_weight = 0.0; double alig_time = 0.0; double tclock; struct diag tmp_diag; int tmp_end; int offset; struct diag *hookdg; while(dlen>0) { // printf(" dlen %i\n", dlen); dg = diags[0]; //if(dg->score==217) print_diag(dg); changed = 0; // print_diag(dg); // hookdg = NULL; if(dg!=NULL) { if((dg->length>0) && (dg->meetsThreshold || dg->anchor) ) { /* if(oldweight > 0.0) if(dg->weight > oldweight) { //printf(" ALARM %.20f %.20f\n", oldweight, dg->weight); //print_diag(&odg); //print_diag(dg); //intf(" %i %i \n", odg, dg); } */ //odg = *dg; //printf(" pre changed\n"); prevweight = dg->weight; tmp_diag = *dg; changed= adapt_diag(algn,smatrix, dg); //changed= adapt_diag(algn,NULL, dg); //print_diag(dg); //printf(" after changed %i\n", dg->length); //if(dg!=NULL) printf(" diag %i %i %i %i %.20f %i %i\n", dg, dg->multi_dg, dg->length, dg->meetsThreshold,dg->weight, dg->multi_length,changed); if(changed) { //printf("\nCHANGED\n"); //print_diag(dg); //printf(" pre recalc\n"); calc_weight(dg, smatrix, pdist); if(dg->anchor) { *dg = tmp_diag; } if( (dg->length > 0) && !(dg->anchor)) { tmp_end = tmp_diag.seq_p1.startpos+tmp_diag.length-1; if( ((dg->seq_p1.startpos+dg->length-1)< tmp_end) && !(dg->multi_dg)) { offset = dg->seq_p1.startpos+dg->length-tmp_diag.seq_p1.startpos; tmp_diag.seq_p1.startpos += offset; tmp_diag.seq_p2.startpos += offset; tmp_diag.length -= offset; adapt_diag(algn,smatrix, &tmp_diag); tmp_diag.length = tmp_end - tmp_diag.seq_p1.startpos+1; calc_weight(&tmp_diag, smatrix, pdist); if((tmp_diag.length>0)&& tmp_diag.meetsThreshold) { hookdg = malloc(sizeof(struct diag)); *hookdg = tmp_diag; hookdg->marked = 1; dcol->diag_amount++; if(dcol->diag_amount>alloc_dlen) { //printf("\n\n\nresize %i %i\n\n\n", dlen, alloc_dlen); alloc_dlen += 8; dcol->diags = (diags = realloc(diags, sizeof(struct diag*)*alloc_dlen)); if(diags==NULL) error("Error increasing diag heap durign aligning."); } //print_diag(hookdg); //printf("dlen %i damount %i %i\n", dlen, dcol->diag_amount, hookdg); //free(diags[dcol->diag_amount-1]); dlen++; diags[dcol->diag_amount-1] = diags[dlen-1]; diags[dlen-1]=hookdg; if(dlen>=2) { //printf("heapify: %i\n", dlen-1); heapify_diag_array(diags,dlen-1,dlen,1); } //print_diag(hookdg); } } } else { dg->meetsThreshold=0; } //printf(" \nafter recalc %i %.20f %.20f\n",dg->length, oldweight, dg->weight); //printf("%.20f %.20f\n", oldweight, dg->weight); //if(dg->weight<prevweight*0.5) dg->meetsThreshold = 0; // TODO: reactivate !!! //(dg->weight<oldweight*0.5) { //if(dg->weight>oldweight) printf(" WEIGHT %e %e\n", dg->weight, oldweight); //algn->redo_seqs[dg->seq_p1.num*slen+dg->seq_p2.num] = 1; //algn->redo_seqs[dg->seq_p2.num*slen+dg->seq_p1.num] = 1; // DELETE THIS: //dg->meetsThreshold = 0; //if(para->DO_OVERLAP) calc_ov_weight(dg, dcol, smatrix, pdist); } else { //printf(" Pre align\n"); //print_diag(dg); if(para->DEBUG >1) tclock = clock(); //if(dg->anchor) printf(" ANCHOR %.20f %.20f\n", dg->weight, dg->total_weight); alignedSomething = align_diag(algn, smatrix, dg) || alignedSomething; if(para->DEBUG >1) alig_time += clock()-tclock; if(para->DEBUG >1) total_weight += dg->total_weight; //printf(" After align\n"); //if(para->DEBUG >2) printf(" aligned diag %i %e\n", i, dg->weight); //dg->length = 0; //dg->weight = 0.0; dg->meetsThreshold = 0; } } else { // printf("ALARM %i %i %Le\n", i, dg->length, dg->weight); oldweight = dg->weight; } } if((dg==NULL) || (!dg->meetsThreshold)) { tdg = diags[dlen-1]; diags[dlen-1]=dg; diags[0] = tdg; dlen--; } heapify_diag_array(diags, 0, dlen,0); } // if(para->DEBUG >1) printf(" Total Weight: %.20f (total %f) with pure alignment time %f \n", total_weight, algn->total_weight, alig_time/CLOCKS_PER_SEC); if(para->DEBUG >1) printf(" Total Weight: %.20f with pure alignment time %f \n", total_weight, alig_time/CLOCKS_PER_SEC); // return algn; return alignedSomething; }