O_TYPE execsym(O_ARGS, int th, int m) { mpdm_t s, v, p, o = NULL, r = NULL; /* gets the symbol name */ s = RF(M1); /* gets the arguments */ p = RF(M2); /* if it's to be called as a method, the object should be inserted into the local symtable before searching the symbol */ if (m && (o = mpdm_aget(p, 0)) && MPDM_IS_HASH(o)) { mpdm_push(l, o); } else m = 0; /* gets the symbol value */ v = GET(s); if (!MPDM_IS_EXEC(v)) { /* not found or NULL value? error */ mpdm_t t, w; char tmp[128]; w = RF(mpdm_join_s(s, L".")); t = RF(MPDM_2MBS((wchar_t *) w->data)); snprintf(tmp, sizeof(tmp), "Undefined function %s()", (char *) t->data); mpsl_error(MPDM_MBS(tmp)); UF(w); UF(t); } else { /* execute */ r = RF(th ? mpdm_exec_thread(v, p, l) : mpdm_exec(v, p, l)); } UF(s); UF(p); /* drop the object from the local symtable */ if (m) mpdm_adel(l, -1); return UFND(r); }
O_TYPE O_numeq(O_ARGS) { mpdm_t v1 = RF(M1); mpdm_t v2 = RF(M2); mpdm_t r = BOOL((v1 == NULL || v2 == NULL) ? (v1 == v2) : (R(v1) == R(v2)) ); UF(v2); UF(v1); return r; }
O_TYPE O_blkframe(O_ARGS) /* runs an instruction under a block frame */ { mpdm_t ret; /* no context? create one */ if (l == NULL) l = MPDM_A(0); RF(l); /* create a new local symbol table */ mpdm_push(l, MPDM_H(0)); /* creates the arguments (if any) as local variables */ set_local_symbols(M2, a, l); /* execute instruction */ ret = RF(M1); /* destroy the local symbol table */ mpdm_adel(l, -1); UF(l); return UFND(ret); }
int main(int argc, char *argv[]) { UnionFind UF(5); assert(UF.isSameSet(0, 1) == false); assert(UF.isSameSet(1, 2) == false); assert(UF.isSameSet(2, 3) == false); assert(UF.isSameSet(3, 4) == false); assert(UF.sizeOfSet(0) == 1); assert(UF.sizeOfSet(1) == 1); assert(UF.sizeOfSet(2) == 1); assert(UF.sizeOfSet(3) == 1); assert(UF.sizeOfSet(4) == 1); UF.unionSet(0, 1); assert(UF.isSameSet(0, 1)); UF.unionSet(2, 3); assert(UF.isSameSet(2, 3)); UF.unionSet(4, 3); assert(UF.isSameSet(4, 3)); assert(UF.isSameSet(0, 3) == false); UF.unionSet(0, 3); assert(UF.isSameSet(1, 3)); assert(UF.isSameSet(0, 3)); assert(UF.sizeOfSet(3) == 5); assert(UF.numDisjointSets() == 1); return 0; }
static int is_true_uf(mpdm_t v) { int r; RF(v); r = mpsl_is_true(v); UF(v); return r; }
O_TYPE O_foreach(O_ARGS) /* foreach loop */ { mpdm_t s = RF(M1); mpdm_t v = RF(M2); mpdm_t r = NULL; int n; for (n = 0; n < mpdm_size(v) && !*f; n++) { SET(s, mpdm_aget(v, n)); UF(r); r = RF(M3); } if (*f == 1) *f = 0; UF(s); UF(v); return UFND(r); }
pair<intT*,intT> st(edgeArray<intT> G){ intT m = G.nonZeros; intT n = G.numRows; unionFind UF(n); reservation *R = new reservation[n]; intT l = (4*n)/3; unionFindStep<intT> UFStep(G.E, UF, R); speculative_for(UFStep, 0, m, 100); _seq<intT> stIdx = sequence::filter((intT*) R, n, notMax()); cout << "Tree size = " << stIdx.n << endl; UF.del(); delete[] R; return pair<intT*,intT>(stIdx.A, stIdx.n); }
/* ============== JoinedTeam ============== A player just joined a team, so do things. */ void JoinedTeam (edict_t *ent, qboolean reconnected, qboolean notify) { PMenu_Close (ent); if (notify) { if (g_gamemode->value != GAMEMODE_1V1) gi.bprintf (PRINT_HIGH, "%s %sjoined team '%s'\n", ent->client->pers.netname, reconnected ? "re" : "", teaminfo[ent->client->pers.team].name); else gi.bprintf (PRINT_HIGH, "%s %sjoined the game.\n", ent->client->pers.netname, reconnected ? "re" : ""); } ent->client->resp.ready = false; //joining a team with no captain by default assigns. //FIXME: should this still assign even if the team has existing players? if (!teaminfo[ent->client->pers.team].captain) TDM_SetCaptain (ent->client->pers.team, ent); //nasty hack for setting team names for 1v1 mode TDM_UpdateTeamNames (); //if we were invited mid-game, reallocate and insert into teamplayers // wision: do not add if a player reconnected and used his joincode // skuller: force add if player was picked/invited to the different team if (tdm_match_status != MM_WARMUP && !reconnected && (!ent->client->resp.teamplayerinfo || ent->client->resp.teamplayerinfo->team != ent->client->pers.team)) TDM_AddPlayerToMatchinfo (ent); //wision: set skin for new player gi.configstring (CS_PLAYERSKINS + (ent - g_edicts) - 1, va("%s\\%s", ent->client->pers.netname, teaminfo[ent->client->pers.team].skin)); //set everyone elses teamskin for this player based on what team he is on TDM_SetAllTeamSkins (ent); //set this players teamskins based on his team TDM_SetTeamSkins (ent, NULL); if (g_gamemode->value != GAMEMODE_1V1) gi.configstring (CS_TDM_SPECTATOR_STRINGS + (ent - g_edicts) - 1, va ("%s (%s)", ent->client->pers.netname, teaminfo[ent->client->pers.team].name)); else gi.configstring (CS_TDM_SPECTATOR_STRINGS + (ent - g_edicts) - 1, ent->client->pers.netname); TDM_TeamsChanged (); respawn (ent); // switch from spec to player statusbar, if weapon hud is enabled, that'll happen in respawn() if (!UF(ent, WEAPON_HUD)) { TDM_UpdateHud(ent, true); } }
pair<int*,int> st(edgeArray G){ int m = G.nonZeros; int n = G.numRows; unionFind UF(n); int *R = newArray(n, INT_MAX); int l = (4*n)/3; unionFindStep UFStep(G.E, UF, R); speculative_for(UFStep, 0, l, 80 ); speculative_for(UFStep, l, m, 40); _seq<int> stIdx = sequence::filter(R, n, notMax()); cout << "Tree size = " << stIdx.n << endl; UF.del(); delete[] R; return pair<int*,int>(stIdx.A, stIdx.n); }
O_TYPE O_while(O_ARGS) /* while/for loop */ { mpdm_t r = NULL; for (mpdm_void(M3); !*f && is_true_uf(M1); mpdm_void(M4)) { UF(r); r = RF(M2); } if (*f == 1) *f = 0; return UFND(r); }
O_TYPE O_global(O_ARGS) { mpdm_t v = RF(M1); if (MPDM_IS_ARRAY(v)) { int n; for (n = 0; n < mpdm_size(v); n++) mpdm_hset(mpdm_root(), mpdm_aget(v, n), NULL); } else mpdm_hset(mpdm_root(), v, NULL); UF(v); return NULL; }
int TTop2FriendNet::GetTop2WccSz(const double ProbPick2nd) const { TUnionFind UF(Top1UF); for (int n = 0; n < Top2NIdH.Len(); n++) { if (TInt::Rnd.GetUniDev() <= ProbPick2nd && Top2NIdH[n].Val2 != -1) { UF.Union(Top2NIdH.GetKey(n), Top2NIdH[n].Val2); } } TIntH CcSzH; for (int i = 0; i < UF.Len(); i++) { CcSzH.AddDat(UF.Find(UF.GetKeyI(i))) += 1; } int MxCcSz = -1; for (int c = 0; c < CcSzH.Len(); c++) { if (CcSzH[c] > MxCcSz) { MxCcSz = CcSzH[c]; } } return MxCcSz; }
/* ============== TDM_CreatePlayerDmStatusBar ============== Create player's own customized dm_statusbar. */ const char *TDM_CreatePlayerDmStatusBar (edict_t *player) { static char *dm_statusbar; static char weaponhud[175]; // the weapon icons static char ammohud[135]; // the ammo counts int id_x, id_y; int hud_x, hud_y; // opentdm default id_x = -100; id_y = -80; hud_y = 0; hud_x = -25; id_x += player->client->pers.config.id_x; id_y += player->client->pers.config.id_y; hud_x += player->client->pers.config.weapon_hud_x; hud_y += player->client->pers.config.weapon_hud_y; weaponhud[0] = 0; ammohud[0] = 0; if (UF(player, WEAPON_HUD) && g_weapon_hud->value > 0) { // set x position at first for all weapon icons, to save the chars since CS max is 1000 strcpy(weaponhud, va("xr %d ", hud_x)); // set x position for ammo quantities ^ strcpy(ammohud, va("xr %d ", hud_x - 50)); // super/shotgun if (player->client->inventory[ITEM_WEAPON_SUPERSHOTGUN]) { strcat(weaponhud, va("yv %d picn w_sshotgun ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_SHELLS)); hud_y += 25; } else if (player->client->inventory[ITEM_WEAPON_SHOTGUN]) { strcat(weaponhud, va("yv %d picn w_shotgun ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_SHELLS)); hud_y += 25; } // chaingun/machinegun if (player->client->inventory[ITEM_WEAPON_CHAINGUN]) { strcat(weaponhud, va("yv %d picn w_chaingun ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_BULLETS)); hud_y += 25; } else if (player->client->inventory[ITEM_WEAPON_MACHINEGUN]) { strcat(weaponhud, va("yv %d picn w_machinegun ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_SHELLS)); hud_y += 25; } // hand grenades/launcher if (player->client->inventory[ITEM_WEAPON_GRENADELAUNCHER]) { strcat(weaponhud, va("yv %d picn w_glauncher ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_GRENADES)); hud_y += 25; } else if (player->client->inventory[ITEM_AMMO_GRENADES]) { strcat(weaponhud, va("yv %d picn w_hgrenade ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_GRENADES)); hud_y += 25; } // hyper blaster if (player->client->inventory[ITEM_WEAPON_HYPERBLASTER]) { strcat(weaponhud, va("yv %d picn w_hyperblaster ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_CELLS)); hud_y += 25; } // rocket launcher if (player->client->inventory[ITEM_WEAPON_ROCKETLAUNCHER]) { strcat(weaponhud, va("yv %d picn w_rlauncher ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_ROCKETS)); hud_y += 25; } // railgun if (player->client->inventory[ITEM_WEAPON_RAILGUN]) { strcat(weaponhud, va("yv %d picn w_railgun ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_SLUGS)); hud_y += 25; } // BFG if (player->client->inventory[ITEM_WEAPON_BFG]) { strcat(weaponhud, va("yv %d picn w_bfg ", hud_y)); strcat(ammohud, va("yv %d num 3 %d ", hud_y, STAT_WEAPHUD_CELLS)); hud_y += 25; } } dm_statusbar = va( "yb -24 " // health "xv 0 " "hnum " "xv 50 " "pic 0 " // ammo "if 2 " "xv 100 " "anum " "xv 150 " "pic 2 " "endif " // armor "if 4 " "xv 200 " "rnum " "xv 250 " "pic 4 " "endif " "yb -50 " // picked up item "if 7 " "xv 0 " "pic 7 " "xv 26 " "yb -42 " "stat_string 8 " "yb -50 " "endif " // timer (quad, rebreather, envirosuit) "if 9 " "xv 246 " "num 2 10 " "xv 296 " "pic 9 " "endif " // help / weapon icon "if 11 " "xv 148 " "pic 11 " "endif " // timer (pent) "if 30 " "yb -80 " "xv 246 " "num 2 30 " "xv 296 " "picn p_invulnerability " "endif " // First team name "xr -%ld " "yb -96 " "string \"%s\" " // Second team name "xr -%ld " "yb -48 " "string \"%s\" " // First team score / status "xr -66 " "yb -120 " "num 4 23 " // Second team score / status "yb -72 " "num 4 24 " // Time "xv 175 " "yb -48 " "stat_string 26 " // Time value "yb -39 " "stat_string 31 " // Timeout message "if 25 " "xr -58 " "yt 50 " "string \"Timeout\" " // Timeout value "xr -42 " "yt 58 " "stat_string 25 " "endif " // frags "xr -50 " "yt 2 " "num 3 14 " // player id view "if 27 " "xv %d " "yb %d " "stat_string 27 " "endif " // vote notice "if 28 " "xl 10 " "yb -180 " "stat_string 28 " "endif " "%s%s", strlen(teaminfo[TEAM_A].name) * 8, teaminfo[TEAM_A].name, strlen(teaminfo[TEAM_B].name) * 8, teaminfo[TEAM_B].name, id_x, id_y, weaponhud, ammohud ); return dm_statusbar; }
/** * * loop momentums,propagator expressions, * invariants substitutions,propagator powers,number of loops * \param k_lst loop momentums list \param p_lst propagator expressions list \param subs_lst invariants substitutions list \param nu propagator powers list \param l number of loops \return * */ RoMB_loop_by_loop:: RoMB_loop_by_loop( lst k_lst, lst p_lst, lst subs_lst, lst nu, bool subs_U ) { try { /* empty integral */ MBintegral MBlbl_int(lst(),lst(),1); /* Full set of unused propagators, will change */ exlist input_prop_set;//( p_lst.begin(),p_lst.end()); /* map for propagator powers */ exmap prop_pow_map; for(lst::const_iterator Pit = p_lst.begin(); Pit != p_lst.end(); ++Pit) { input_prop_set.push_back(Pit->expand()); prop_pow_map[Pit->expand()] = nu.op(std::distance(p_lst.begin(),Pit)); } cout<<"INPSET: "<<input_prop_set<<endl; /* Iterate over momentums k1,k2,k3,etc. */ unsigned int displacement_x = 0; unsigned int displacement_w = 0; for(lst::const_iterator kit = k_lst.begin(); kit != k_lst.end(); ++kit) { // Integral Normalization coefficient // MBlbl_int *= pow(I,k_lst.nops()); MBlbl_int *= 1/tgamma(1+get_symbol("eps")); //MBlbl_int *= pow(Pi,2-get_symbol("eps")); //MBlbl_int *= exp(Euler*get_symbol("eps")); cout<<"PROP_POW_MAP "<<prop_pow_map<<endl; /* temporary set of propagators, with all momentum,except deleted */ exlist tmp_p_lst(input_prop_set.begin(), input_prop_set.end()); /* temporary set of propagators, with KIT momentum */ lst P_with_k_lst; BOOST_FOREACH(ex prop_tmp, tmp_p_lst) { if(prop_tmp.has(*kit)) { P_with_k_lst.append(prop_tmp); input_prop_set.remove(prop_tmp); } } cout<< "Set wo k_i "<<input_prop_set<<endl; cout<<" PWKlst "<<P_with_k_lst<<endl; bool direct_formula_applied = false; // if only one term in PWKLST use well known formulas // [Smirnov A.1] if(!direct_formula_applied && (P_with_k_lst.nops() == 1)) { ex pr_t = P_with_k_lst.op(0); ex nu_t = prop_pow_map[pr_t]; exmap repls; BOOST_ASSERT_MSG(pr_t.match(-pow(*kit,2) + wild(2)),"ONE PROP"); if(pr_t.match(-pow(*kit,2) + wild(2),repls))cout<<"repls: "<<repls<<endl; ex mass_tadpole = (tgamma(nu_t+get_symbol("eps")-2)/tgamma(nu_t)*pow(wild(2).subs(repls),-nu_t-get_symbol("eps")+2)); cout<<mass_tadpole<<endl; MBlbl_int *= mass_tadpole; MBlbl_int.add_pole(nu_t+get_symbol("eps")-2); direct_formula_applied = true; } if(!direct_formula_applied && (P_with_k_lst.nops() == 2)) { //TWO terms in PWK_LST, [Smirnov A.4] exmap repls_tad; if((P_with_k_lst.nops()==2) && (( (P_with_k_lst.op(0).match(-pow(*kit,2))) && (P_with_k_lst.op(1).match(-pow(*kit,2)+wild())))|| ( (P_with_k_lst.op(1).match(-pow(*kit,2))) && (P_with_k_lst.op(0).match(-pow(*kit,2)+wild())))) && !wild().has(*kit) ) { cout<<"Two prop tadpole "<<wild()<<endl; exmap r1,r2; ex mm,lmb1,lmb2; if( (P_with_k_lst.op(0).match(-pow(*kit,2))) && (P_with_k_lst.op(1).match(-pow(*kit,2)+wild(),r1))) { lmb1 = prop_pow_map[P_with_k_lst.op(1)]; lmb2 = prop_pow_map[P_with_k_lst.op(0)]; mm=wild().subs(r1); } else if( (P_with_k_lst.op(1).match(-pow(*kit,2))) && (P_with_k_lst.op(0).match(-pow(*kit,2)+wild(),r2))) { lmb1 = prop_pow_map[P_with_k_lst.op(0)]; lmb2 = prop_pow_map[P_with_k_lst.op(1)]; mm=wild().subs(r2); } else throw std::logic_error(std::string("Wrong two prop topology to use eq [Smir:A.4]")); ex mass_tadpole = tgamma(lmb1+lmb2+get_symbol("eps")-2)*tgamma(-lmb2-get_symbol("eps")+2)/tgamma(lmb1)/tgamma(2-get_symbol("eps"))*pow(mm,-lmb1-lmb2-get_symbol("eps")+2); cout<<mass_tadpole<<endl; } } if(!direct_formula_applied) { // cout<< " coe: "<<coe_prop_lst<<endl; /* lexi sort of input prop list, and it's modification */ // uf and then MB represenatation construction // subs only in F for last momentum UFXmap inUFmap; if(boost::next(kit) == k_lst.end()) inUFmap = UF(lst(*kit),P_with_k_lst,subs_lst,displacement_x); else inUFmap = UF(lst(*kit),P_with_k_lst,subs_lst,displacement_x); // no substitution!!! displacement_x +=fusion::at_key<UFX::xlst>(inUFmap).nops(); lst nu_into; for(lst::const_iterator nuit = P_with_k_lst.begin(); nuit != P_with_k_lst.end(); ++nuit ) nu_into.append(prop_pow_map[*nuit]); cout<<" Powers list before input: "<<nu_into<<endl; /* MBintegral Uint( fusion::make_map<UFX::F,UFX::xlst>(fusion::at_key<UFX::F>(inUFmap), fusion::at_key<UFX::xlst>(inUFmap) ),nu_into,1,displacement_w); */ MBintegral Uint(inUFmap,nu_into,1,subs_U,displacement_w); displacement_w+=Uint.w_size(); cout<<"ui9nt eps (no gamma) : "<<Uint.get_expr().subs(tgamma(wild()) == 1)<<endl; cout<<"ui9nt eps : "<<Uint.get_expr()<<endl; /* expression to mul root integral where to subs prop(k_prev)==1 */ ex expr_k_to_subs_1= Uint.get_expr(); ex mom_find = Uint.get_expr(); cout<< "where find props: "<<mom_find<<endl; if(is_a<mul>(mom_find)) { // set of a^b?, need to have momentums from *kit to *k_lst.end() exset found_prop_raw,found_prop; mom_find.find(pow(wild(1),wild(2)),found_prop_raw); cout<<" is a mul raw "<<found_prop_raw<<endl; // really props BOOST_FOREACH(ex px_c,found_prop_raw) { bool is_a_p = false; for(lst::const_iterator kpi = kit; kpi != k_lst.end(); ++kpi) if(px_c.has(*kpi)) { is_a_p = true; break; } if(is_a_p) found_prop.insert(px_c); } cout<<" is a mul "<<found_prop<<endl; BOOST_FOREACH(ex propex_c,found_prop) { // next momentum in loop momentum list ex next_k ; for(lst::const_iterator nkit = kit; nkit != k_lst.end(); ++nkit) if(propex_c.has(*nkit)) { next_k = *nkit; break; } cout<<"before subs kex : "<<expr_k_to_subs_1.subs(tgamma(wild()) == 1)<<endl; expr_k_to_subs_1 = expr_k_to_subs_1.subs(propex_c == 1); cout<<"after subs kex : "<<expr_k_to_subs_1.subs(tgamma(wild()) == 1)<<endl; /* converting prop to form -p^2+m^2 */ ex p_power; ex p_expr; ex p_not_corr = ex_to<power>(propex_c).op(0); ex coeff_ksq = p_not_corr.expand().coeff(next_k,2); // coeff infront of K^2 if( coeff_ksq != -1 ) { p_not_corr /=coeff_ksq; cout<<"koeff_ksq "<<coeff_ksq<<endl; MBlbl_int*= pow(coeff_ksq,ex_to<power>(propex_c).op(1)); // propex = pow(p_not_corr,ex_to<power>(propex_c).op(1)); p_power = ex_to<power>(propex_c).op(1); p_expr = p_not_corr.expand(); } else { p_power = ex_to<power>(propex_c).op(1); p_expr = ex_to<power>(propex_c).op(0).expand(); } /* Search for duplications in prop set */ cout<<"where to find props: "<<input_prop_set<<endl; cout<< input_prop_set.size()<<endl; cout<<"PWK_MAP to modiff"<<prop_pow_map<<endl; if(prop_pow_map.count(p_expr) > 0) { BOOST_ASSERT_MSG(count(input_prop_set.begin(),input_prop_set.end(),p_expr) > 0,"Propagator not found in prop set"); cout<<"PPM bef: "<< prop_pow_map[p_expr]<<endl; prop_pow_map[p_expr] -=p_power; cout<<"PPM aft: "<< prop_pow_map[p_expr]<<endl; } else { prop_pow_map[p_expr] = (-1)*p_power; input_prop_set.push_back(p_expr); } cout<<"PWK_MAP after modiff"<<prop_pow_map<<endl; } } //cout<<"needed props "<<prop_pow_lst<<endl; cout<<"ya tut"<<endl; MBlbl_int*=expr_k_to_subs_1; cout<<"ya tut"<<endl; // cout<<"HAS INT : "<<MBlbl_int.get_expr().subs(tgamma(wild(4)) == 0)<<endl; MBlbl_int+=Uint; cout<<"bad"<<endl; // MBlbl_int.insert_w_lst(Uint.get_w_lst()); // MBlbl_int.insert_pole_lst(Uint.get_pole_lst()); //}// else more then one prop }// two prop formula