File: scorehistory.cpp

package info (click to toggle)
muscle 3.52-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,196 kB
  • ctags: 1,763
  • sloc: cpp: 21,335; xml: 185; makefile: 104
file content (101 lines) | stat: -rw-r--r-- 2,526 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "muscle.h"
#include "scorehistory.h"
#include <stdio.h>

#define TRACE	0

ScoreHistory::ScoreHistory(unsigned uIters, unsigned uNodeCount)
	{
	m_uNodeCount = uNodeCount;
	m_uIters = uIters;

	m_Score = new SCORE *[uIters];
	m_bScoreSet = new bool *[uIters];
	for (unsigned n = 0; n < uIters; ++n)
		{
		m_Score[n] = new SCORE[uNodeCount*2];
		m_bScoreSet[n] = new bool[uNodeCount*2];
		memset(m_bScoreSet[n], 0, uNodeCount*2*sizeof(bool));
		}
	}

ScoreHistory::~ScoreHistory()
	{
	for (unsigned n = 0; n < m_uIters; ++n)
		{
		delete[] m_Score[n];
		delete[] m_bScoreSet[n];
		}
	delete[] m_Score;
	delete[] m_bScoreSet;
	}

bool ScoreHistory::SetScore(unsigned uIter, unsigned uNodeIndex, bool bRight, SCORE Score)
	{
#if	TRACE
	Log("ScoreHistory::SetScore(Iter=%u Node=%u Right=%d Score=%g)\n",
	  uIter, uNodeIndex, bRight, Score);
#endif
	if (uIter >= m_uIters)
		Quit("ScoreHistory::SetScore-1");
	if (uNodeIndex >= m_uNodeCount)
		Quit("ScoreHistory::SetScore-2");

	const unsigned uIndex = uNodeIndex*2 + bRight;
	for (unsigned n = 1; n < uIter; ++n)
		{
		const unsigned uPrevIter = n - 1;
		if (!m_bScoreSet[uPrevIter][uIndex])
			{
			LogMe();
			Quit("ScoreHistory::SetScore-3");
			}
		if (m_Score[uPrevIter][uIndex] == Score)
			{
			ProgressStepsDone();
#if	TRACE
			Log("Oscillating\n");
#endif
			return true;
			}
		}
	m_Score[uIter][uIndex] = Score;
	m_bScoreSet[uIter][uIndex] = true;
	return false;
	}

void ScoreHistory::LogMe() const
	{
	Log("ScoreHistory\n");
	Log("Iter  Node  Right      Score\n");
	Log("----  ----  -----  ---------\n");
	for (unsigned uIter = 0; uIter < m_uIters; ++uIter)
		{
		bool bAnySet = false;
		for (unsigned n = 0; n < m_uNodeCount*2; ++n)
			if (m_bScoreSet[uIter][n])
				{
				bAnySet = true;
				break;
				}
		if (!bAnySet)
			return;
		for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex)
			{
			const unsigned uBase = 2*uNodeIndex;
			if (m_bScoreSet[uIter][uBase])
				Log("%4u  %4u         F  %9.3f\n", uIter, uNodeIndex, m_Score[uIter][uBase]);
			if (m_bScoreSet[uIter][uBase+1])
				Log("%4u  %4u         T  %9.3f\n", uIter, uNodeIndex, m_Score[uIter][uBase+1]);
			}
		}
	}

SCORE ScoreHistory::GetScore(unsigned uIter, unsigned uNodeIndex,
  bool bReverse, bool bRight) const
	{
	const unsigned uIndex = uNodeIndex*2 + bRight;
	if (!m_bScoreSet[uIter][uIndex])
		Quit("ScoreHistory::GetScore");
	return m_Score[uIter][uIndex];
	}