Пример #1
0
// If the ball hits this wall, returns the score of this hit, else return 0
int Wall::getScore(POINT center, double radius){
    double distX = fmin(fabs(center.X - startCorner.X), fabs(center.X - endCorner.X));
    double distY = fmin(fabs(center.Y - startCorner.Y), fabs(center.Y - endCorner.Y));
    double distZ = fmin(fabs(center.Z - startCorner.Z), fabs(center.Z - endCorner.Z));
    distX *= planeVector.X;
    distY *= planeVector.Y;
    distZ *= planeVector.Z;
    //printf("%lf %lf %lf, %lf %lf %lf\n", center.X, center.Y, center.Z, distX, distY, distZ);
    if(distX + distY + distZ <= epsilon + radius * 9.0 / 10 - 1e-9){
        return -111111111;
    }
    if(distX + distY + distZ <= radius + 1e-9 + epsilon && distX + distY + distZ >= epsilon + radius * 9.0 / 10 - 1e-9){
        center.X = fabs((center.X - startCorner.X) / deltaVector.X);
        center.Y = fabs((center.Y - startCorner.Y) / deltaVector.Y);
        center.Z = fabs((center.Z - startCorner.Z) / deltaVector.Z);

        center.X *= 1 - planeVector.X;
        center.Y *= 1 - planeVector.Y;
        center.Z *= 1 - planeVector.Z;

        //printf("..... %lf %lf %lf %lf %lf %lf\n", center.X, center.Y, center.Z, planeVector.X, planeVector.Y, planeVector.Z);
        //printf("%lf %lf %lf\n", size.X, size.Y, size.Z);
        return getCellScore(center);
    }
    return 0;
}
Пример #2
0
MOATypeElmVal averageNeighborsScore (ProcessData * pData, ScoringData * sData, WavesData * wData, MOATypeShape * cellIndex) {
    /*Otherwise, average the score value based on neighbor's lower neighbors that are inside the search space*/
    MOATypeElmVal averageScore = 0;
    MOATypeInd j, n, NeighbFlatIndex;
    MOA_rec * NnghbMOA;
    int ret, inSearchSpace;
    if (getNeighbors (2, cellIndex, sData->msaAlgn->dimn, sData->seqLen, &NnghbMOA) == 0) {
        MOATypeElmVal * NneighborScores = mmalloc ((NnghbMOA->elements_ub - 1) * sizeof *NneighborScores);
        n = 0; /*Number of Neighbors scored*/
        for (j=0;j<NnghbMOA->elements_ub - 1;j++) { 
            ret = getCellScore (pData, sData, wData, NnghbMOA->indexes[j], &NneighborScores[n], &inSearchSpace, 1, -1);
            /*if (ret < 0)
                NneighborScores[j] =  a_average (NneighborScores, j-1); /*Last resort - average the values read so far*/
            if (ret == 0) 
                n ++;            
        } /*End loop for neighbor's neighbors*/
        averageScore = a_average (NneighborScores, n);        
        free (NneighborScores);
        deleteMOA(NnghbMOA);
    }
    return averageScore;
}
Пример #3
0
/****************************************************************************
	Function: getNeighborScores - based on Global partition neighbors (the right one I hope)
		Examine all neighbors scores to determine the current score of the new 
		cell being scored.
****************************************************************************/
int getNeighborScores (ProcessData * pData, ScoringData * sData, WavesData * wData) {
    MOATypeInd i, locCellIndex, partIndex, NeighbFlatIndex;
    MOATypeDimn k, l;
    MOATypeElmVal maxScore = 0, nghbScore = 0;
    char msg[SHORT_MESSAGE_SIZE];
    int inSearchSpace;
#ifndef NDEBUG
    int dbglevel = 4;

    sprintf (msg, "[%d]>getNeighborScores: cell {%lld", myProcid, sData->gm_index[0]);
    mprintf (dbglevel, msg, 1);
    for (k=1;k<sData->seqNum;k++) {
        sprintf (msg, ", %lld", sData->gm_index[k]);
        mprintf (dbglevel, msg, 1);
    }
    mprintf (dbglevel, "}\n", 1);
#endif
    /*Fill in the pair wise score matrix for the current cell*/
    for (l=0;l<pData->seqNum  - 1; l++) {
        for (k=l+1;k<pData->seqNum; k++) {
            sData->pwScores[l][k] = subScore(sData->sequences[l][sData->gm_index[l]-1], sData->sequences[k][sData->gm_index[k]-1], sData->stype);
#ifndef NDEBUG
            sprintf(msg, "[%d]>getNeighborScores: (%lld, %lld), (%c-%c) => score %lld\n", myProcid,l, k, sData->sequences[l][sData->gm_index[l]-1], sData->sequences[k][sData->gm_index[k]-1], sData->pwScores[l][k]);
            mprintf(dbglevel+2, msg, 1);
#endif
        }
    }
  
    /*get neighbors of the current cell */
    if (getLowerNeighbors (2, sData->gm_index, sData->msaAlgn->dimn, sData->seqLen, &sData->NghbMOA) != 0) {
        sprintf(msg, "[%d]>getNeighborScores: No Lower neighbors while expecting, returning\n", myProcid);
        mprintf(0, msg, 1);
        fflush(stdout);
        return -1; /* Error - need debugging*/
    }
    /* loop throught neighbors */        
    for (i=0;i<sData->NghbMOA->elements_ub - 1;i++) { 
        /*Check if Sequential Processing, read neighbor score locally*/
        if (Mode != Distributed)  {
            MOATypeInd NeighbFlatIndex = Gamma(sData->NghbMOA->indexes[i], sData->msaAlgn->dimn, sData->msaAlgn->shape,  sData->msaAlgn->dimn, 1);
            nghbScore = sData->NghbMOA->elements[i].val = sData->msaAlgn->elements[NeighbFlatIndex].val;
            if (sData->msaAlgn->elements[NeighbFlatIndex].prev != NULL && sData->msaAlgn->elements[NeighbFlatIndex].prev_ub > 0) {
                sData->NghbMOA->elements[i].prev = mmalloc(sizeof *sData->NghbMOA->elements[i].prev);
                sData->NghbMOA->elements[i].prev_ub = 1;
                sData->NghbMOA->elements[i].prev[0] = mmalloc(sData->seqNum * sizeof *sData->NghbMOA->elements[i].prev[0]);
                for (k=0;k<sData->seqNum;k++)
                        sData->NghbMOA->elements[i].prev[0][k] = sData->msaAlgn->elements[NeighbFlatIndex].prev[0][k];
            }
        }
        else 
            getCellScore (pData, sData, wData, sData->NghbMOA->indexes[i], &nghbScore, &inSearchSpace, 1, i);
        nghbScore += getNeghbScore (sData, i);
        if (i == 0) {
            maxScore = nghbScore;            
            sData->msaAlgn->elements[sData->findex].prev = mmalloc ((MOATypeInd) sizeof *(sData->msaAlgn->elements[sData->findex].prev));
            if (sData->msaAlgn->elements[sData->findex].prev == NULL) {
                printf ("[%d]Error creating memory for cells Previous cells chains.\n", myProcid);
                return -1;
            }
            sData->msaAlgn->elements[sData->findex].prev[0] = NULL;
            sData->msaAlgn->elements[sData->findex].prev[0] = mcalloc ((MOATypeInd) sData->seqNum, (MOATypeInd) sizeof *(sData->msaAlgn->elements[sData->findex].prev[0]));
            if (sData->msaAlgn->elements[sData->findex].prev[0] == NULL) {
                printf ("[%d]Error creating memory for cells Previous cells chains.\n", myProcid);
                return -1;
            }

            for (k=0;k<sData->seqNum;k++) 
                sData->msaAlgn->elements[sData->findex].prev[0][k] = sData->NghbMOA->indexes[i][k];

            sData->msaAlgn->elements[sData->findex].prev_ub = 1;
        }
        else if (nghbScore > maxScore) {
            if (sData->msaAlgn->elements[sData->findex].prev != NULL) {
                for (k=0;k<sData->msaAlgn->elements[sData->findex].prev_ub;k++) {
                    if (sData->msaAlgn->elements[sData->findex].prev[k] != NULL)
                        free (sData->msaAlgn->elements[sData->findex].prev[k]);
                    sData->msaAlgn->elements[sData->findex].prev[k] = NULL;
                }
                free (sData->msaAlgn->elements[sData->findex].prev);
            }
            sData->msaAlgn->elements[sData->findex].prev = NULL;            
            sData->msaAlgn->elements[sData->findex].prev  = mmalloc ((MOATypeInd) sizeof *(sData->msaAlgn->elements[sData->findex].prev));
            if (sData->msaAlgn->elements[sData->findex].prev == NULL) {
                printf ("[%d]Error creating memory for cells Previous cells chains.\n", myProcid);
                return -1;
            }
            maxScore = nghbScore;
            sData->msaAlgn->elements[sData->findex].prev[0] = NULL;
            sData->msaAlgn->elements[sData->findex].prev[0] = mcalloc ((MOATypeInd) sData->seqNum, (MOATypeInd) sizeof *(sData->msaAlgn->elements[sData->findex].prev[0]));
            if (sData->msaAlgn->elements[sData->findex].prev[0] == NULL) {
                printf ("[%d]Error creating memory for cells Previous cells chains.\n", myProcid);
                return -1;
            }

            for (k=0;k<sData->seqNum;k++) 
                sData->msaAlgn->elements[sData->findex].prev[0][k] = sData->NghbMOA->indexes[i][k];        
            sData->msaAlgn->elements[sData->findex].prev_ub = 1;
        }
        else if (nghbScore == maxScore) {
            sData->msaAlgn->elements[sData->findex].prev  = realloc (sData->msaAlgn->elements[sData->findex].prev, ((MOATypeInd) (sData->msaAlgn->elements[sData->findex].prev_ub + 1)) * ((MOATypeInd) sizeof *(sData->msaAlgn->elements[sData->findex].prev)));
            if (sData->msaAlgn->elements[sData->findex].prev == NULL) {
                printf ("[%d]Error reallocating memory for Previous cells chains.\n", myProcid);
                return -1;
            }
            sData->msaAlgn->elements[sData->findex].prev[sData->msaAlgn->elements[sData->findex].prev_ub] = NULL;
            sData->msaAlgn->elements[sData->findex].prev[sData->msaAlgn->elements[sData->findex].prev_ub] = mcalloc ((MOATypeInd) sData->seqNum, ((MOATypeInd) sizeof *(sData->msaAlgn->elements[sData->findex].prev[sData->msaAlgn->elements[sData->findex].prev_ub])));
            if (sData->msaAlgn->elements[sData->findex].prev[sData->msaAlgn->elements[sData->findex].prev_ub] == NULL) {
                printf ("[%d]Error reallocating memory for Previous cells chains.\n", myProcid);
                return -1;
            }	

            for (k=0;k<sData->seqNum;k++)
                sData->msaAlgn->elements[sData->findex].prev[sData->msaAlgn->elements[sData->findex].prev_ub][k] = sData->NghbMOA->indexes[i][k];

            sData->msaAlgn->elements[sData->findex].prev_ub ++;
        }
    }

    sData->score = maxScore;
    return 0;  
}
Пример #4
0
/***********************************************************************
	Function: getCellDPScore
		Computes Dynamic Programming score for cell of index findex, 
	1. by initializing : If a Global lower Overlapping Cell in distributed mode, or lower border cell generally in sequential mode
	2. or reading from a local other partition, if a local lower Overlapping Cell 
	3. or receiving from a remote processor, if a rempte local lower Overlapping Cell 
	4. or retrieve its lower neighbors scores, if in sequential mode, or an inner local cell. 
***********************************************************************/
MOATypeElmVal getCellDPScore (ProcessData * pData, ScoringData * sData, WavesData * wData) {
    MOATypeInd startOC;
    int ret, inSearchSpace;
    MOATypeDimn i;
#ifndef NDEBUG
    MOATypeDimn k;
    char msg[MID_MESSAGE_SIZE];
    int dbglevel = 3;
#endif

	
#ifndef NDEBUG
    sprintf (msg, "[%d] gloc %d lloc %d lhoc %d Cell: {%lld", myProcid, sData->msaAlgn->elements[sData->findex].cp.glOC, sData->msaAlgn->elements[sData->findex].cp.llOC, sData->msaAlgn->elements[sData->findex].cp.lhOC, sData->gm_index[0]);
    mprintf (dbglevel, msg, 1); 
    for (i = 1; i < sData->seqNum; i++)  {
    	sprintf (msg, ", %lld", sData->gm_index[i]);
        mprintf (dbglevel, msg, 1); 
    }
    mprintf (dbglevel, "} ", 1);
#endif
    if (Mode == Distributed) {    
        if (sData->msaAlgn->elements[sData->findex].cp.glOC == 1) {
            /*if (GLB) Global lower border cell from the whole tensor, then initialize with gabscores multiplied by indices if global, or zero if local alignment*/
            sData->score = initLBCell (sData->gm_index, pData->seqNum,pData->stype);
#ifndef NDEBUG
            sprintf (msg, ">Initialized: 1. score %lld\n", sData->score);
            mprintf (dbglevel, msg, 1);
#endif
        } else if (sData->msaAlgn->elements[sData->findex].cp.llOC == 1) { 
            /*search for the local lower Overlapping Cell in previously calculated partitions in local processor first*/
            /* if not found, then block till it is received from the adjacent processor  */
            ret = getCellScore (pData, sData, wData, sData->gm_index, &sData->score, &inSearchSpace, 1, -1);
            
            while ((inSearchSpace == 0) && (ret < 0))
                ret = receiveOC(pData, sData); 
        } else {
            /*Inner Cell not gloc or lloc, score*/
            ret = getNeighborScores (pData, sData, wData);
            if (ret == -2) {
                /* Lower Border Cell - Initialize ===========================*/
                sData->score = initLBCell (sData->gm_index, pData->seqNum,sData->stype);
#ifndef NDEBUG
                sprintf (msg, ">initLBCell: 6. score %lld\n", sData->score);
                mprintf(dbglevel, msg, 1);
#endif
            } 
            else {
#ifndef NDEBUG
                sprintf (msg, ">getNeighborScores: 5. score %lld\n", sData->score);
                mprintf(dbglevel, msg, 1);
#endif
            }
        }
    } else {
	/* If Sequential Scoring  Mode NOT Distributed ============================*/
        if ((sData->msaAlgn->elements[sData->findex].cp.glOC == 1) || (sData->msaAlgn->elements[sData->findex].cp.llOC == 1)) {
            /* Lower Border Cell - Initialize ===========================*/
            sData->score = initLBCell (sData->gm_index, pData->seqNum, sData->stype);
#ifndef NDEBUG
            sprintf (msg, "[%d]>getScore: Seq Lower Bound => score %lld\n", myProcid, sData->score);
            mprintf(dbglevel, msg, 1);
#endif
        }
        else {
            ret = getNeighborScores (pData, sData, wData);
            if (ret == -2) {
                /* Can not get neighbors, Initialize, and check design :) ==*/
                sData->score = initLBCell (sData->gm_index, pData->seqNum,sData->stype);
#ifndef NDEBUG
                sprintf (msg, "[%d]>getScore: Seq Inner Cell Initialized, error to check=> score %lld\n", myProcid, sData->score);
                mprintf(dbglevel, msg, 1);
#endif
            } 
        }
    }
    
    if (AlignmentType == Local) {
        if (sData->score < 0)
            sData->score = 0;
    }
#ifndef NDEBUG
    sprintf (msg, "[%d]>getScore: element %lld score %lld\n", myProcid, sData->msaAlgn->indexes[sData->findex], sData->msaAlgn->elements[sData->findex].val);
    mprintf (dbglevel, msg, 1);
    sprintf (msg, "will check lhOC\n");
    mprintf(dbglevel, msg, 1);
#endif
    if ((Mode == Distributed) && (sData->msaAlgn->elements[sData->findex].cp.lhOC == 1) && (sData->msaAlgn->elements[sData->findex].cp.glOC == 0)) {
#ifndef NDEBUG
        mprintf (dbglevel, "Will Add to OCout Buffer", 1);
#endif		
        addOC (pData, sData, wData);
#ifndef NDEBUG
        sprintf (msg, "after addOC wavesOC %ld\n", pData->OCout[pData->waveNo].wavesOC);
        mprintf(dbglevel, msg, 1);
#endif
    }
    return sData->score;
}