| 1 | #include "muscle.h" |
|---|
| 2 | #include "scorehistory.h" |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | |
|---|
| 5 | #define TRACE 0 |
|---|
| 6 | |
|---|
| 7 | ScoreHistory::ScoreHistory(unsigned uIters, unsigned uNodeCount) |
|---|
| 8 | { |
|---|
| 9 | m_uNodeCount = uNodeCount; |
|---|
| 10 | m_uIters = uIters; |
|---|
| 11 | |
|---|
| 12 | m_Score = new SCORE *[uIters]; |
|---|
| 13 | m_bScoreSet = new bool *[uIters]; |
|---|
| 14 | for (unsigned n = 0; n < uIters; ++n) |
|---|
| 15 | { |
|---|
| 16 | m_Score[n] = new SCORE[uNodeCount*2]; |
|---|
| 17 | m_bScoreSet[n] = new bool[uNodeCount*2]; |
|---|
| 18 | memset(m_bScoreSet[n], 0, uNodeCount*2*sizeof(bool)); |
|---|
| 19 | } |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | ScoreHistory::~ScoreHistory() |
|---|
| 23 | { |
|---|
| 24 | for (unsigned n = 0; n < m_uIters; ++n) |
|---|
| 25 | { |
|---|
| 26 | delete[] m_Score[n]; |
|---|
| 27 | delete[] m_bScoreSet[n]; |
|---|
| 28 | } |
|---|
| 29 | delete[] m_Score; |
|---|
| 30 | delete[] m_bScoreSet; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | bool ScoreHistory::SetScore(unsigned uIter, unsigned uNodeIndex, bool bRight, SCORE Score) |
|---|
| 34 | { |
|---|
| 35 | #if TRACE |
|---|
| 36 | Log("ScoreHistory::SetScore(Iter=%u Node=%u Right=%d Score=%g)\n", |
|---|
| 37 | uIter, uNodeIndex, bRight, Score); |
|---|
| 38 | #endif |
|---|
| 39 | if (uIter >= m_uIters) |
|---|
| 40 | Quit("ScoreHistory::SetScore-1"); |
|---|
| 41 | if (uNodeIndex >= m_uNodeCount) |
|---|
| 42 | Quit("ScoreHistory::SetScore-2"); |
|---|
| 43 | |
|---|
| 44 | const unsigned uIndex = uNodeIndex*2 + bRight; |
|---|
| 45 | for (unsigned n = 1; n < uIter; ++n) |
|---|
| 46 | { |
|---|
| 47 | const unsigned uPrevIter = n - 1; |
|---|
| 48 | if (!m_bScoreSet[uPrevIter][uIndex]) |
|---|
| 49 | { |
|---|
| 50 | LogMe(); |
|---|
| 51 | Quit("ScoreHistory::SetScore-3"); |
|---|
| 52 | } |
|---|
| 53 | if (m_Score[uPrevIter][uIndex] == Score) |
|---|
| 54 | { |
|---|
| 55 | ProgressStepsDone(); |
|---|
| 56 | #if TRACE |
|---|
| 57 | Log("Oscillating\n"); |
|---|
| 58 | #endif |
|---|
| 59 | return true; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | m_Score[uIter][uIndex] = Score; |
|---|
| 63 | m_bScoreSet[uIter][uIndex] = true; |
|---|
| 64 | return false; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void ScoreHistory::LogMe() const |
|---|
| 68 | { |
|---|
| 69 | Log("ScoreHistory\n"); |
|---|
| 70 | Log("Iter Node Right Score\n"); |
|---|
| 71 | Log("---- ---- ----- ---------\n"); |
|---|
| 72 | for (unsigned uIter = 0; uIter < m_uIters; ++uIter) |
|---|
| 73 | { |
|---|
| 74 | bool bAnySet = false; |
|---|
| 75 | for (unsigned n = 0; n < m_uNodeCount*2; ++n) |
|---|
| 76 | if (m_bScoreSet[uIter][n]) |
|---|
| 77 | { |
|---|
| 78 | bAnySet = true; |
|---|
| 79 | break; |
|---|
| 80 | } |
|---|
| 81 | if (!bAnySet) |
|---|
| 82 | return; |
|---|
| 83 | for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex) |
|---|
| 84 | { |
|---|
| 85 | const unsigned uBase = 2*uNodeIndex; |
|---|
| 86 | if (m_bScoreSet[uIter][uBase]) |
|---|
| 87 | Log("%4u %4u F %9.3f\n", uIter, uNodeIndex, m_Score[uIter][uBase]); |
|---|
| 88 | if (m_bScoreSet[uIter][uBase+1]) |
|---|
| 89 | Log("%4u %4u T %9.3f\n", uIter, uNodeIndex, m_Score[uIter][uBase+1]); |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | SCORE ScoreHistory::GetScore(unsigned uIter, unsigned uNodeIndex, |
|---|
| 95 | bool bReverse, bool bRight) const |
|---|
| 96 | { |
|---|
| 97 | const unsigned uIndex = uNodeIndex*2 + bRight; |
|---|
| 98 | if (!m_bScoreSet[uIter][uIndex]) |
|---|
| 99 | Quit("ScoreHistory::GetScore"); |
|---|
| 100 | return m_Score[uIter][uIndex]; |
|---|
| 101 | } |
|---|