static int calc_num_children_bin(node_t *parent) { int v = rng_rand(parent->state.state); double d = normalize(v); return (d < non_leaf_prob) ? non_leaf_bf : 0; }
/* Taken from GLib 2.0 v2.25.3, g_rand_int_range(), GPLv2+ */ int32_t rng_rand_range(struct rng_ctx *ctx, int32_t min, int32_t max) { int32_t res; int32_t dist; uint32_t maxvalue; uint32_t leftover; dist = max - min; if (dist <= 0) return min; /* maxvalue is set to the predecessor of the greatest * multiple of dist less or equal 2^32. */ if (dist <= 0x80000000u) /* 2^31 */ { /* maxvalue = 2^32 - 1 - (2^32 % dist) */ leftover = (0x80000000u % dist) * 2; if (leftover >= dist) leftover -= dist; maxvalue = 0xffffffffu - leftover; } else maxvalue = dist - 1; do res = rng_rand(ctx); while (res > maxvalue); res %= dist; return min + res; }
int uts_numChildren(Node *node) { int numChildren = 0; // determine the number of children if (node->height == 0) numChildren = (int) floor(b_0); else { // distribution is identical everywhere below root int v = rng_rand(node->state.state); double d = rng_toProb(v); numChildren = (d < nonLeafProb) ? nonLeafBF : 0; } // limit number of children (only a BIN root can have more than MAXNUMCHILDREN) if (node->height != 0) { if (numChildren > MAXNUMCHILDREN) { bots_debug("*** Number of children truncated from %d to %d\n", numChildren, MAXNUMCHILDREN); numChildren = MAXNUMCHILDREN; } } /* including info into node */ node->numChildren = numChildren; return numChildren; }
int uts_numChildren_bin(Node * parent) { // distribution is identical everywhere below root int v = rng_rand(parent->state.state); double d = rng_toProb(v); return (d < nonLeafProb) ? nonLeafBF : 0; }
/* addTag() insert a tag into the logging stream list. caller must have rtdb locked. */ bool CInMemoryBuffer::addTag(PCTAG_NAME name) { CHislogStream * str; hislog_stream_list::iterator it; pair<hislog_stream_list::iterator,bool> pib; PCRTK_TAG p; it = m_streams.find(*name); if(it != m_streams.end()){ // already logged, reset the pending-deletion flag it->second->m_deletePending = false; return true; } p = query_tag_f(name); if(!p){ return false; } str = new CHislogStream(this); if(!str){ return false; } str->m_type = get_value_type(p->s.Flags); str->m_name = *name; str->m_color = rng_rand(0, hislogRecordColors); pib = m_streams.insert(hislog_stream_list::value_type(*name, str)); if(!pib.second){ delete str; return false; } return true; }
double CExpression::vexp ( arbore a ) { double v; SYSTEMTIME tm; GetSystemTime(&tm); if (a->operatie==NULL) {error_code=10;return 0;} switch(a->operatie){ case '+' : return( vexp(a->left)+vexp(a->right) ); case '-' : return( vexp(a->left)-vexp(a->right) ); case '*' : return( vexp(a->left)*vexp(a->right) ); case '%': { v = vexp(a->right); if(v == 0){ error_code = DIVISION_BY_0; return 0; } return (int)vexp(a->left) % (int)v; } case '/' : v=vexp(a->right) ; if (v==0){ error_code=DIVISION_BY_0; return -vexp(a->left)/0.001; }else{ return(vexp(a->left)/v); } case 150 : return(sin(vexp(a->left))); case 151 : return(cos(vexp(a->left))); case 152 : return(exp(vexp(a->left))); case 153 : v=vexp(a->left) ; if (v<0) {error_code=INVALID_DOMAIN;return 0;} else return(sqrt(v)); case 154 : v=vexp(a->left) ; if (v<=0) {error_code=INVALID_DOMAIN;return 0;} else return(log(v)); case 155 : return (tan (vexp(a->left))); case 156 : return (1 / tan (vexp(a->left))); case 157 : return (asin (vexp(a->left))); case 158 : return (acos (vexp(a->left))); case 159 : return (atan (vexp(a->left))); case 173 : return (fabs (vexp(a->left))); case 160 : return tm.wYear; case 161 : return tm.wMonth; case 162 : return tm.wDay; case 163 : return tm.wHour; case 164 : return tm.wMinute; case 165 : return tm.wSecond; case 166 : return max(vexp(a->left),vexp(a->right)); case 167 : return min(vexp(a->left),vexp(a->right)); case 168 : return rng_rand(0,RAND_MAX)*vexp(a->left)/RAND_MAX; //case '|' : return(fabs(vexp(a->left))); case '^' : return(pow(vexp(a->left),vexp(a->right))); case '@' : return (a->valoare); //logical operations evaluation case '<' : return( vexp(a->left) < vexp(a->right) ); case '>' : return( vexp(a->left) > vexp(a->right) ); case '!' : return(!vexp(a->right)) ; // added by chenj, @2008-5-22 case '=' : return( vexp(a->left) == vexp(a->right) ); case '&' : return (int)(vexp(a->left)) & (int)(vexp(a->right)); case '|' : return (int)(vexp(a->left)) | (int)(vexp(a->right)); case 169: { RTK_TIME t; rtk_time_mark(&t); return (double)(__int64)t.Data / 1e7; } case 170: { /* last update time */ PRTK_TAG tte; __r8 retval = 0; tte = (PRTK_TAG)a->left->pvObj; if(!tte){ error_code=UNDEFINED_VARIABLE; retval = 0; }else{ if(!(tte->d.Value.Flags & TF_Valid)){ error_code=UNDEFINED_VARIABLE; retval = 0; }else{ PRTK_TIME pTime = (PRTK_TIME)&tte->d.BinaryAddress[8]; retval = (double)(__int64)pTime->Data / 1e7; rtk_time_mark(pTime); } } return retval; } case 171 : { // a database tag PRTK_TAG tte; __r8 retval = 0; tte = (PRTK_TAG)a->pvObj; if(!tte){ error_code=UNDEFINED_VARIABLE; retval = 0; }else{ if(!(tte->d.Value.Flags & TF_Valid)){ error_code=UNDEFINED_VARIABLE; retval = 0; }else{ pmc_value_t dblVal; set_value_type(dblVal.Flags, dt_real8); pmc_type_cast(&tte->d.Value, &dblVal); retval = dblVal.Value.dbl; } } return retval; } case 172: { /* span time */ PRTK_TAG tte; RTK_TIME now; __r8 retval = 0; tte = (PRTK_TAG)a->left->pvObj; if(!tte){ error_code=UNDEFINED_VARIABLE; retval = 0; }else{ if(!(tte->d.Value.Flags & TF_Valid)){ error_code=UNDEFINED_VARIABLE; retval = 0; }else{ PRTK_TIME pTime = (PRTK_TIME)&(tte->d.BinaryAddress[8]); rtk_time_mark(&now); if(pTime->Data != 0){ /* yes, the field is previouly stored with a resonable value, thus valid for a sub-operation to get a duration time */ retval = rtk_time_diff(&now, pTime); }else{ /* this might be the first time that a time-span was requested for this tag */ retval = 0; } *pTime = now; } } return retval; } } return 0; }