00001 #ifndef TV_HEURISTIC_CPP
00002 #define TV_HEURISTIC_CPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "TVHeuristic.h"
00038 #include "ESTCodec.h"
00039 #include "EST.h"
00040 #include "ParameterSetManager.h"
00041
00042
00043
00044
00045 arg_parser::arg_record TVHeuristic::argsList[] = {
00046 {NULL, NULL, NULL, arg_parser::BOOLEAN}
00047 };
00048
00049 TVHeuristic::TVHeuristic(const std::string& outputFileName)
00050 : NewUVHeuristic("tv", outputFileName) {
00051 matchTable = NULL;
00052 uvSuccessCount = 0;
00053 t = 18;
00054 windowLen = 50;
00055 }
00056
00057 TVHeuristic::~TVHeuristic() {
00058 if (matchTable != NULL) {
00059 delete [] matchTable;
00060 }
00061 }
00062
00063 void
00064 TVHeuristic::showArguments(std::ostream& os) {
00065
00066 NewUVHeuristic::showArguments(os);
00067
00068 arg_parser ap(TVHeuristic::argsList);
00069 os << ap;
00070 }
00071
00072 bool
00073 TVHeuristic::parseArguments(int& argc, char **argv) {
00074
00075 if (!NewUVHeuristic::parseArguments(argc, argv)) {
00076
00077 return false;
00078 }
00079
00080 arg_parser ap(TVHeuristic::argsList);
00081 ap.check_args(argc, argv, false);
00082
00083 if (t < 1) {
00084 std::cerr << heuristicName
00085 << ": t (number of v-words matches) >= 1 "
00086 << "(use --tv_t option)\n";
00087 return false;
00088 }
00089
00090 return true;
00091 }
00092
00093 int
00094 TVHeuristic::initialize() {
00095
00096 NewUVHeuristic::initialize();
00097
00098 size_t maxESTlen = EST::getMaxESTLen();
00099 int maxFrameSize = ParameterSetManager::getParameterSetManager()
00100 ->getMaxFrameSize();
00101
00102
00103 matchTable = new char[maxESTlen + maxFrameSize + v];
00104
00105 return 0;
00106 }
00107
00108 int
00109 TVHeuristic::setReferenceEST(const int estIdx) {
00110 if (refESTidx == estIdx) {
00111
00112 return 0;
00113 }
00114
00115 return NewUVHeuristic::setReferenceEST(estIdx);
00116 }
00117
00118 bool
00119 TVHeuristic::runHeuristic(const int otherEST) {
00120
00121 otherESTLen = (int)strlen(EST::getEST(otherEST)->getSequence());
00122 if (!updateParameters()) {
00123
00124 return false;
00125 }
00126
00127
00128 if (!NewUVHeuristic::runHeuristic(otherEST)) {
00129
00130 return false;
00131 }
00132
00133 uvSuccessCount++;
00134
00135
00136
00137 int numMatches = 0;
00138
00139 ESTCodec::NormalEncoder<bitsToShift, BitMask> encoder;
00140 if (bestMatchIsRC) {
00141 numMatches = countCommonWords(otherEST, encoder, s1RCWordMap);
00142 } else {
00143 numMatches = countCommonWords(otherEST, encoder, s1WordMap);
00144 }
00145
00146
00147
00148
00149
00150
00151 return (numMatches >= t);
00152 }
00153
00154 bool
00155 TVHeuristic::updateParameters() {
00156 ParameterSet* parameterSet = ParameterSetManager::getParameterSetManager()
00157 ->getParameterSet(refESTLen, otherESTLen);
00158 if (parameterSet == NULL) return false;
00159
00160 windowLen = parameterSet->frameSize;
00161 t = parameterSet->t;
00162 u = parameterSet->u;
00163 wordShift = parameterSet->wordShift;
00164 passes = (u < 6) ? 2 : 3;
00165 return true;
00166 }
00167
00168 void
00169 TVHeuristic::printStats(std::ostream& os) const {
00170
00171 NewUVHeuristic::printStats(os);
00172
00173 os << "\tNumber of u/v successes: " << uvSuccessCount << std::endl;
00174 }
00175
00176 #endif