Ejemplo n.º 1
0
int CRegionEvaluator::Score(ChessType* board, ChessType color, int emptiesNum) const
{
	ChessType oppcolor = Oppl_ch(color);
	int tmpEval = BorderScore(board, color, oppcolor);		//四边
	tmpEval += AngleScore(board, color, oppcolor);			//四角
	tmpEval += CenterScore(board, color, oppcolor);			//中心区域
	tmpEval += InnerBorderScore(board, color, oppcolor);	//中心区域
	tmpEval += CountScore(board, color, oppcolor, emptiesNum);

	return tmpEval;
}
Ejemplo n.º 2
0
MatchedBlockPair *FindBestSet (MatchedBlockPair *matches, int numMatches, MultipleAlignment *a1, MultipleAlignment *a2, ScoreData *s) {
	Vector min, max = {0.0,0.0,0.0};
	MemoryManagementInfo info = {0,0};
	MatchedBlockPair **list = (MatchedBlockPair **) malloc(numMatches * sizeof(MatchedBlockPair *));
	double displacementRange = s->displacement * 2;
	int best = 0;
	int i;
	int pos;
	OctTreeNode *trees = (OctTreeNode *) malloc(a2->numResidues * sizeof(OctTreeNode));
	double maxBonus = MAX_BONUS;
	double maxPosBonus = MAX_POS_BONUS;

	if (!numMatches) return 0;
	for (i=0; i<a1->numResidues; i++) {
		/* Currently allow missing positions only in single-structure "alignments."
		 * May allow farther on or remove them altogether.  Currently no benefit from
		 * not just removing residues with no alpha carbon coordinates.
		 */
		if (a1->numChains > 1 || a1->residues[0].res[i].exists) {
			max = a1->averages[i++];
			break;
		}
	}
	min = max;
	for (; i<a1->numResidues; i++) {
		/* Safety check. */
		if (a1->numChains == 1 && !a1->residues[0].res[i].exists) continue;

		if (a1->averages[i].x < min.x) {
			min.x = a1->averages[i].x;
		}
		else if (a1->averages[i].x > max.x) {
			max.x = a1->averages[i].x;
		}

		if (a1->averages[i].y < min.y) {
			min.y = a1->averages[i].y;
		}
		else if (a1->averages[i].y > max.y) {
			max.y = a1->averages[i].y;
		}

		if (a1->averages[i].z < min.z) {
			min.z = a1->averages[i].z;
		}
		else if (a1->averages[i].z > max.z) {
			max.z = a1->averages[i].z;
		}
	}

	for (i=0; i<a2->numResidues; i++) {
		InitOctTreeNode(&trees[i], &min, &max);
	}

	for (i=0; i<numMatches; i++) {
		Vector v, first;
		MatchedBlockPair *match = &matches[i];
		match->bestPreviousMatch = -1;
		/* In this case, don't allow it to be added without a previous strand,
		 * unless it's the first strand.
		 */
		if (s->firstStrandLocked) {
			if (i) {
				match->bestAssembledScore = -5000;
			}
			else {
				/* Otherwise, keep previous assembled score.  Means I can
				 * just insert into old alignments without changing scores.
				 */
				match->bestAssembledScore -= match->score;
			}
		}
		else
			match->bestAssembledScore = 0;
		transformVect(&first, &match->m, &a2->averages[match->p2]);
		for (pos=4; pos<match->p2; pos++) {
			int hits, j;
			transformVect(&v, &match->m, &a2->averages[pos]);

			hits = GetEntries((void**)list, &trees[pos], &v, displacementRange);

			for (j=0; j < hits; j++) {
				Vector v1, v2;
				MatchedBlockPair *match2 = list[j];
				double score, invCosHalfTest, angle, displacement;
				if (match2->p1 + match2->len > match->p1) {
					continue;
				}

				if (match2->p2 + match2->len > a2->conflictMap[match->p2][0]) {
					if (match2->p2 + match2->len-1 == a2->conflictMap[match->p2][0] ||
						a2->conflictMap[match->p2][match2->p2 + match2->len-1 - a2->conflictMap[match->p2][0]])
						continue;
				}
				if (match2->p1 + match2->len > a1->conflictMap[match->p1][0]) {
					if (match2->p1 + match2->len-1 == a1->conflictMap[match->p1][0] ||
						a1->conflictMap[match->p1][match2->p1 + match2->len-1 - a1->conflictMap[match->p1][0]])
						continue;
				}

				score = match2->bestAssembledScore;

				if (score + maxBonus < match->bestAssembledScore) continue;

				invCosHalfTest = invHalfCosQuat(&match->q, &match2->q);
				if (invCosHalfTest < s->angleCos) continue;

				angle = 0;
				if (invCosHalfTest<1) angle = 2*acos(invCosHalfTest);
				score += AngleScore(angle);

				if (score + maxPosBonus < match->bestAssembledScore) continue;

				subVect(&v1, &match2->last, &v);
				transformVect(&v2, &match2->m, &a2->averages[match->p2]);
				subVect(&v2, &first,  &v2);

				displacement = (lengthVect(&v1) + lengthVect(&v2))/2;
				if (displacement > s->displacement) continue;
				score += DisplacementScore(displacement);

				if (score < match->bestAssembledScore) continue;

				match->bestAssembledScore = (float) score;
				match->bestPreviousMatch = (int)(match2 - matches);
			}
		}

		if (match->bestAssembledScore < 0) continue;

		match->bestAssembledScore += match->score;
		if (match->bestAssembledScore > matches[best].bestAssembledScore)
			best = i;
		pos = match->p2 + match->len-1;
		AddEntry(&trees[pos], &match->last, &info);
	}

	FreeAllMemory(&info);
	free(trees);
	free(list);

	if (!s->lastStrandLocked)
		return &matches[best];
	else
		return &matches[numMatches-1];
}