void enna_panel_infos_set_rating(Evas_Object *obj, Enna_Metadata *m) { Evas_Object *rating = NULL; const char *rt; Smart_Data *sd = evas_object_data_get(obj, "sd"); if (!sd) return; rt = enna_metadata_meta_get(m, "rating", 1); if (rt) { char rate[16]; int r; r = MMAX(atoi(rt), 0); r = MMIN(r, 5); memset(rate, '\0', sizeof(rate)); snprintf(rate, sizeof(rate), "rating/%d", r); rating = edje_object_add(evas_object_evas_get(sd->o_edje)); edje_object_file_set(rating, enna_config_theme_get(), rate); } ENNA_OBJECT_DEL(sd->o_rating); sd->o_rating = rating; edje_object_part_swallow(sd->o_edje, "panel.rating.swallow", sd->o_rating); eina_stringshare_del(rt); }
WIN32DLL_DEFINE mutils_word32 mhash_count(void) { hashid count = 0; MHASH_LOOP( count = MMAX( p->id, count) ); return count; }
void gs_byte_seek(GsByte *b, int len, int whence) { if(whence == SEEK_SET){ if(len >= 0){ b->mBufPtr = MMIN(b->mBuf + len, b->mBufEnd); } }else if(whence == SEEK_CUR){ b->mBufPtr = MMIN(MMAX(b->mBuf, (b->mBufPtr + len)), b->mBufEnd); } }
unsigned int enna_util_calculate_font_size(Evas_Coord w, Evas_Coord h) { float size = 12; size = sqrt(w * w + h * h) / (float)50.0; size = MMIN(size, 8); size = MMAX(size, 30); return (unsigned int)size; }
int gs_byte_read(GsByte *b, uint8_t* buf, int size) { int len = 0; if (size > 0) { if (b->mBufEnd >= (b->mBufPtr + size)) { len = size; memcpy(buf, b->mBufPtr, len); } else { len = b->mBufEnd - b->mBufPtr; len = MMAX(0, len); memcpy(buf, b->mBufPtr, len); } b->mBufPtr += len; } else if (size == 0) { len = 0; } else { len = -1; } return len; }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ long n_xyz, n; double *xyz; long n_points, p; double *points; long closest_id; mxArray *PLOC; int *ijk, i,j,k; int N[3], max_N; int *IDs, MARK; double D_SCAM, D_SCAM2; int offset_bucket; double min_dist2, this_dist2; int isPLOC; /* //read the inputs */ n_points = mxGetM( prhs[1] ); points = mxGetPr( prhs[1] ); n_xyz = mxGetM( mxGetField( prhs[0], 0, "xyz") ); xyz = mxGetPr( mxGetField( prhs[0], 0, "xyz") ); /* //create the outputs */ plhs[0]= mxCreateDoubleMatrix( n_points,1,mxREAL ); if( nlhs > 1) { plhs[1]= mxCreateDoubleMatrix( n_points,3,mxREAL ); } if( nlhs > 2) { plhs[2]= mxCreateDoubleMatrix( n_points,1,mxREAL ); } /* //MARKS vectors */ IDs = mxMalloc( n_xyz*sizeof( int ) ); /* //if SCAM structure doesn't exists */ if( mxGetField( prhs[0], 0, "SCAM") == NULL ) { D_SCAM= 1; isPLOC= 0; } else { D_SCAM= *mxGetPr( mxGetField( mxGetField( prhs[0], 0, "SCAM"), 0 , "D")); } D_SCAM2= D_SCAM*D_SCAM; PLOC= mxGetField( prhs[0], 0, "PLOC"); /* //if PLOC structure doesn't exists */ if( PLOC == NULL ){ isPLOC= 0; max_N = 1; } else { /* //SCAM coordinates of the points */ ijk = mxMalloc( 3*n_points*sizeof( int ) ); SCAMCOORD( ijk, prhs[0], points, n_points , N ); isPLOC=1; max_N= MMAX( N[0],N[1],N[2] ); } for( p=0 ; p<n_points ; p++ ) { /* //reset the MARKS */ for ( n=0 ; n<n_xyz ; n++ ) { IDs[n]=0; } offset_bucket= 1; MARK=1; min_dist2= 1e+300; while( offset_bucket <= max_N ){ if( isPLOC ) { i= ijk[ p ]; j= ijk[ p + n_points ]; k= ijk[ p + 2*n_points ]; n= MarkIdsOnBuckets( PLOC, MAX(1,i-offset_bucket),MIN(i+offset_bucket,N[0]), MAX(1,j-offset_bucket),MIN(j+offset_bucket,N[1]), MAX(1,k-offset_bucket),MIN(k+offset_bucket,N[2]), IDs, MARK ); if( n < 0 ) { offset_bucket++; continue; } } else { MARK= 0; n= n_xyz-1; } for ( ; n >= 0 ; n-- ) { /* //only the the just marked ones */ if (IDs[n]==MARK) { /* //distance between points(p) and m.xyz(n) */ this_dist2 = (points[p ]-xyz[n ])*(points[p ]-xyz[n ])+ (points[p+ n_points]-xyz[n+ n_xyz])*(points[p+ n_points]-xyz[n+ n_xyz])+ (points[p+2*n_points]-xyz[n+2*n_xyz])*(points[p+2*n_points]-xyz[n+2*n_xyz]); if( this_dist2 < min_dist2 ){ /* //a closer point found */ min_dist2= this_dist2; /* //update the min_dist2 */ closest_id= n; if( min_dist2 < 1e-30 ) { /* //tolerance of the search */ break; /* //a point was found */ } } } } if( offset_bucket*offset_bucket >= min_dist2/D_SCAM2 ) { break; } if( !isPLOC ) { break; } offset_bucket= (int)( sqrt(min_dist2/D_SCAM2) )+1; MARK++; } *(mxGetPr(plhs[0])+p)= closest_id + 1; /* //update the output id */ if( nlhs > 1) { /* //update the output point */ *(mxGetPr(plhs[1])+p )= xyz[closest_id ]; *(mxGetPr(plhs[1])+p+ n_points)= xyz[closest_id+ n_xyz]; *(mxGetPr(plhs[1])+p+2*n_points)= xyz[closest_id+2*n_xyz]; } if( nlhs > 2) { /* //update the output distance */ *(mxGetPr(plhs[2])+p)= sqrt( min_dist2 ) ; } } if( isPLOC ) { mxFree(IDs); mxFree(ijk); } }
// 零窗口完全搜索例程 static int SearchCut(int vlBeta, int nDepth, bool bNoNull = false) { int nNewDepth, vlBest, vl; int mvHash, mv, mvEvade; MoveSortStruct MoveSort; // 完全搜索例程包括以下几个步骤: // 1. 在叶子结点处调用静态搜索; if (nDepth <= 0) { __ASSERT(nDepth >= -NULL_DEPTH); return SearchQuiesc(Search.pos, vlBeta - 1, vlBeta); } Search2.nAllNodes++; // 2. 无害裁剪; vl = HarmlessPruning(Search.pos, vlBeta); if (vl > -MATE_VALUE) { return vl; } // 3. 置换裁剪; vl = ProbeHash(Search.pos, vlBeta - 1, vlBeta, nDepth, bNoNull, mvHash); if (Search.bUseHash && vl > -MATE_VALUE) { return vl; } // 4. 达到极限深度,直接返回评价值; if (Search.pos.nDistance == LIMIT_DEPTH) { return Evaluate(Search.pos, vlBeta - 1, vlBeta); } __ASSERT(Search.pos.nDistance < LIMIT_DEPTH); // 5. 中断调用; Search2.nMainNodes++; vlBest = -MATE_VALUE; if ((Search2.nMainNodes & Search.nCountMask) == 0 && Interrupt()) { return vlBest; } // 6. 尝试空着裁剪; if (Search.bNullMove && !bNoNull && Search.pos.LastMove().ChkChs <= 0 && Search.pos.NullOkay()) { Search.pos.NullMove(); vl = -SearchCut(1 - vlBeta, nDepth - NULL_DEPTH - 1, NO_NULL); Search.pos.UndoNullMove(); if (Search2.bStop) { return vlBest; } if (vl >= vlBeta) { if (Search.pos.NullSafe()) { // a. 如果空着裁剪不带检验,那么记录深度至少为(NULL_DEPTH + 1); RecordHash(Search.pos, HASH_BETA, vl, MMAX(nDepth, NULL_DEPTH + 1), 0); return vl; } else if (SearchCut(vlBeta, nDepth - NULL_DEPTH, NO_NULL) >= vlBeta) { // b. 如果空着裁剪带检验,那么记录深度至少为(NULL_DEPTH); RecordHash(Search.pos, HASH_BETA, vl, MMAX(nDepth, NULL_DEPTH), 0); return vl; } } } // 7. 初始化; if (Search.pos.LastMove().ChkChs > 0) { // 如果是将军局面,那么生成所有应将着法; mvEvade = MoveSort.InitEvade(Search.pos, mvHash, Search2.wmvKiller[Search.pos.nDistance]); } else { // 如果不是将军局面,那么使用正常的着法列表。 MoveSort.InitFull(Search.pos, mvHash, Search2.wmvKiller[Search.pos.nDistance]); mvEvade = 0; } // 8. 按照"MoveSortStruct::NextFull()"例程的着法顺序逐一搜索; while ((mv = MoveSort.NextFull(Search.pos)) != 0) { if (Search.pos.MakeMove(mv)) { // 9. 尝试选择性延伸; nNewDepth = (Search.pos.LastMove().ChkChs > 0 || mvEvade != 0 ? nDepth : nDepth - 1); // 10. 零窗口搜索; vl = -SearchCut(1 - vlBeta, nNewDepth); Search.pos.UndoMakeMove(); if (Search2.bStop) { return vlBest; } // 11. 截断判定; if (vl > vlBest) { vlBest = vl; if (vl >= vlBeta) { RecordHash(Search.pos, HASH_BETA, vlBest, nDepth, mv); if (!MoveSort.GoodCap(Search.pos, mv)) { SetBestMove(mv, nDepth, Search2.wmvKiller[Search.pos.nDistance]); } return vlBest; } } } } // 12. 不截断措施。 if (vlBest == -MATE_VALUE) { __ASSERT(Search.pos.IsMate()); return Search.pos.nDistance - MATE_VALUE; } else { RecordHash(Search.pos, HASH_ALPHA, vlBest, nDepth, mvEvade); return vlBest; } }
// 静态搜索例程 static int SearchQuiesc(PositionStruct &pos, int vlAlpha, int vlBeta) { int vlBest, vl, mv; bool bInCheck; MoveSortStruct MoveSort; // 静态搜索例程包括以下几个步骤: Search2.nAllNodes++; // 1. 无害裁剪; vl = HarmlessPruning(pos, vlBeta); if (vl > -MATE_VALUE) { return vl; } #ifdef HASH_QUIESC // 3. 置换裁剪; vl = ProbeHashQ(pos, vlAlpha, vlBeta); if (Search.bUseHash && vl > -MATE_VALUE) { return vl; } #endif // 4. 达到极限深度,直接返回评价值; if (pos.nDistance == LIMIT_DEPTH) { return Evaluate(pos, vlAlpha, vlBeta); } __ASSERT(Search.pos.nDistance < LIMIT_DEPTH); // 5. 初始化; vlBest = -MATE_VALUE; bInCheck = (pos.LastMove().ChkChs > 0); // 6. 对于被将军的局面,生成全部着法; if (bInCheck) { MoveSort.InitAll(pos); } else { // 7. 对于未被将军的局面,在生成着法前首先尝试空着(空着启发),即对局面作评价; vl = Evaluate(pos, vlAlpha, vlBeta); __ASSERT_BOUND(1 - WIN_VALUE, vl, WIN_VALUE - 1); __ASSERT(vl > vlBest); if (vl >= vlBeta) { #ifdef HASH_QUIESC RecordHashQ(pos, vl, MATE_VALUE); #endif return vl; } vlBest = vl; vlAlpha = MMAX(vl, vlAlpha); // 8. 对于未被将军的局面,生成并排序所有吃子着法(MVV(LVA)启发); MoveSort.InitQuiesc(pos); } // 9. 用Alpha-Beta算法搜索这些着法; while ((mv = MoveSort.NextQuiesc(bInCheck)) != 0) { __ASSERT(bInCheck || pos.ucpcSquares[DST(mv)] > 0); if (pos.MakeMove(mv)) { vl = -SearchQuiesc(pos, -vlBeta, -vlAlpha); pos.UndoMakeMove(); if (vl > vlBest) { if (vl >= vlBeta) { #ifdef HASH_QUIESC if (vl > -WIN_VALUE && vl < WIN_VALUE) { RecordHashQ(pos, vl, MATE_VALUE); } #endif return vl; } vlBest = vl; vlAlpha = MMAX(vl, vlAlpha); } } } // 10. 返回分值。 if (vlBest == -MATE_VALUE) { __ASSERT(pos.IsMate()); return pos.nDistance - MATE_VALUE; } else { #ifdef HASH_QUIESC if (vlBest > -WIN_VALUE && vlBest < WIN_VALUE) { RecordHashQ(pos, vlBest > vlAlpha ? vlBest : -MATE_VALUE, vlBest); } #endif return vlBest; } }
static int sort(struct env *env, int M) { int sp=0; struct tree *left=NULL, *right=NULL; int nBucket = 0; struct particle **ps = env->p; struct tree *node = env->tree; /*======================================================================== * Allocate stack *======================================================================*/ int ns = (int)MMAX(1, floor(log(((double)(env->N+1))/(M+1))/log(2.0))); sp = 0; sortStack = (struct tree **)realloc(sortStack, ns * sizeof(struct tree *)); assert(sortStack != NULL); if (node->iUpper - node->iLower + 1 <= M) return 0; while (1) { int i, p, k; struct particle *t; int nl, nr; int d; real fSplit; assert(node != NULL); split(node, &d, &fSplit); #if 0 i = node->iLower; int j = node->iUpper; //partitionCount++; //PARTITION(ps, t, ->r[d], i,j, < fSplit,> fSplit); while (i <= j && ((ps[i] ->r[d]) < fSplit)) { ++i; } #if 0 while (i <= j) { switch ((i-j) & 0x7) case 7: if } #endif while (i <= j && ((ps[j] ->r[d]) > fSplit)) { --j; } while (i < j) { SWAP(ps[i], ps[j], t); while ((ps[++i] ->r[d]) < fSplit) { } while ((ps[--j] ->r[d]) > fSplit) { } } #else # define PART(A, i, j, t, d, CMPL) \ do { \ int k = i--; \ do { \ if (A[k]->r[d] CMPL) { i++; SWAP(A[i], A[k], t); } \ } while (++k <= j); \ i++; \ } while(0) i = node->iLower; const int j = node->iUpper; switch (d) { case 0: PART(ps, i, j, t, 0, < fSplit); break; case 1: PART(ps, i, j, t, 1, < fSplit); break; case 2: PART(ps, i, j, t, 2, < fSplit); break; } #endif //fprintf(err, "(%i %i)\n", i, node->iUpper); nl = i - node->iLower; nr = node->iUpper - i + 1; //fprintf(err, "nl=%i nr=%i\n", nl, nr); /*======================================================================== * If both sides of the partition are not empty then create two new nodes * and crop the bounding boxes. Otherwise, undo the split operation. *======================================================================*/ if (nl > 0 || nr > 0) { // jpc changed this from && to || so that a split is always created. NEW_NODE(node, left, node->iLower, i - 1); NEW_NODE(node, right, i, node->iUpper); nodeCount += 2; X3( node->left->bnd.r [_] = node->bnd.r [_] ); X3( node->left->bnd.max [_] = node->bnd.max [_] ); node->left->bnd.max[d] *= 0.5; node->left->bnd.r[d] -= node->left->bnd.max[d]; left = node->left; X3( node->right->bnd.r [_] = node->bnd.r [_] ); X3( node->right->bnd.max [_] = node->bnd.max [_] ); node->right->bnd.max[d] *= 0.5; node->right->bnd.r[d] += node->right->bnd.max[d]; right = node->right; } else { node->bnd.max[d] *= 0.5; if (nl > 0) { node->bnd.r[d] -= node->bnd.max[d]; left = node; } else { node->bnd.r[d] += node->bnd.max[d]; right = node; } } /*======================================================================== * Now figure out which subfile to process next *======================================================================*/ if (nl > M && nr > M) { if (nr > nl) sortStack[sp++] = right, node = left; else sortStack[sp++] = left, node = right; } else { if (nl > M) node = left; //else if (nl > 0) left->iLower = 0; if (nr > M) node = right; //else if (nr > 0) right->iLower = 0; } if (nl <= M && nr <= M) { if (sp) node = sortStack[--sp]; /* pop tn */ else break; } } return 0; }
static int sort(struct pqNode **ps, pTree *node, int M) { int sp=0; pTree *pLeft=NULL, *pRight=NULL; int nBucket = 0; /*======================================================================== * Allocate stack *======================================================================*/ int ns = (int)MMAX(1, floor(log(((double)(NPARTICLES+1))/(M+1))/log(2.0))); sp = 0; sortStack = (pTree **)realloc(sortStack, ns * sizeof(pTree *)); assert(sortStack != NULL); if (node->iUpper - node->iLower + 1 <= M) return 0; while (1) { int i, j; struct pqNode *t; int nl, nr; int d; FLOAT fSplit; assert(node != NULL); split(node, &d, &fSplit); i = node->iLower; j = node->iUpper; partitionCount++; PARTITION(ps, t, ->r[d], i,j, < fSplit,> fSplit); nl = i - node->iLower; nr = node->iUpper - i + 1; //fprintf(err, "nl=%i nr=%i\n", nl, nr); /*======================================================================== * If both sides of the partition are not empty then create two new nodes * and crop the bounding boxes. Otherwise, undo the split operation. *======================================================================*/ if (nl > 0 || nr > 0) { // jpc changed this from && to || so that a split is always created. NEW_NODE(node, pLeft, node->iLower, i - 1); NEW_NODE(node, pRight, i, node->iUpper); nodeCount += 2; #if 0 crop(ps, node->pLeft, node->pLeft->iLower, node->pLeft->iUpper); crop(ps, node->pRight, node->pRight->iLower, node->pRight->iUpper); #else _3x_(i) node->pLeft->bnd.fCenter[i] = node->bnd.fCenter[i]; _3x_(i) node->pLeft->bnd.fMax[i] = node->bnd.fMax[i]; _3x_(i) node->pRight->bnd.fCenter[i] = node->bnd.fCenter[i]; _3x_(i) node->pRight->bnd.fMax[i] = node->bnd.fMax[i]; node->pLeft->bnd.fMax[d] *= 0.5; node->pLeft->bnd.fCenter[d] -= node->pLeft->bnd.fMax[d]; node->pRight->bnd.fMax[d] *= 0.5; node->pRight->bnd.fCenter[d] += node->pRight->bnd.fMax[d]; #endif pLeft = node->pLeft; pRight = node->pRight; } else { node->bnd.fMax[d] *= 0.5; if (nl > 0) { node->bnd.fCenter[d] -= node->bnd.fMax[d]; pLeft = node; } else { node->bnd.fCenter[d] += node->bnd.fMax[d]; pRight = node; } } /*======================================================================== * Now figure out which subfile to process next *======================================================================*/ if (nl > M && nr > M) { if (nr > nl) sortStack[sp++] = pRight, node = pLeft; else sortStack[sp++] = pLeft, node = pRight; } else { if (nl > M) node = pLeft; //else if (nl > 0) pLeft->iLower = 0; if (nr > M) node = pRight; //else if (nr > 0) pRight->iLower = 0; } if (nl <= M && nr <= M) { if (sp) node = sortStack[--sp]; /* pop tn */ else break; } } return 0; }