00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <string>
00024 #include <iostream>
00025 #include "SquareMatrix.h"
00026 #include "TypeDef.h"
00027 #include "Util.h"
00028
00029 using namespace std;
00030
00031 namespace Moses
00032 {
00033 void SquareMatrix::InitTriangle(float val)
00034 {
00035 for(size_t row=0; row < m_size; row++) {
00036 for(size_t col=row; col<m_size; col++) {
00037 SetScore(row, col, -numeric_limits<float>::infinity());
00038 }
00039 }
00040 }
00041
00048 float SquareMatrix::CalcEstimatedScore( Bitmap const &bitmap ) const
00049 {
00050 const size_t notInGap= numeric_limits<size_t>::max();
00051 size_t startGap = notInGap;
00052 float estimatedScore = 0.0f;
00053 for(size_t currPos = 0 ; currPos < bitmap.GetSize() ; currPos++) {
00054
00055 if(bitmap.GetValue(currPos) == false && startGap == notInGap) {
00056 startGap = currPos;
00057 }
00058
00059 else if(bitmap.GetValue(currPos) == true && startGap != notInGap) {
00060 estimatedScore += GetScore(startGap, currPos - 1);
00061 startGap = notInGap;
00062 }
00063 }
00064
00065 if (startGap != notInGap) {
00066 estimatedScore += GetScore(startGap, bitmap.GetSize() - 1);
00067 }
00068
00069 return estimatedScore;
00070 }
00071
00087 float SquareMatrix::CalcEstimatedScore( Bitmap const &bitmap, size_t startPos, size_t endPos ) const
00088 {
00089 const size_t notInGap= numeric_limits<size_t>::max();
00090 float estimatedScore = 0.0f;
00091 size_t startGap = bitmap.GetFirstGapPos();
00092 if (startGap == NOT_FOUND) return estimatedScore;
00093
00094
00095 size_t startLoop = startGap+1;
00096 if (startPos == startGap) {
00097 startGap = notInGap;
00098 startLoop = endPos+1;
00099 }
00100
00101 size_t lastCovered = bitmap.GetLastPos();
00102 if (endPos > lastCovered || lastCovered == NOT_FOUND) lastCovered = endPos;
00103
00104 for(size_t currPos = startLoop; currPos <= lastCovered ; currPos++) {
00105
00106 if(startGap == notInGap && bitmap.GetValue(currPos) == false && (currPos < startPos || currPos > endPos)) {
00107 startGap = currPos;
00108 }
00109
00110 else if(startGap != notInGap && (bitmap.GetValue(currPos) == true || (startPos <= currPos && currPos <= endPos))) {
00111 estimatedScore += GetScore(startGap, currPos - 1);
00112 startGap = notInGap;
00113 }
00114 }
00115
00116 if (lastCovered != bitmap.GetSize() - 1) {
00117 estimatedScore += GetScore(lastCovered+1, bitmap.GetSize() - 1);
00118 }
00119
00120 return estimatedScore;
00121 }
00122
00123 TO_STRING_BODY(SquareMatrix);
00124
00125 }
00126
00127