comparison src/Matcher.cpp @ 203:3662865740da memory

Make isRowAvailable/isColAvailable operate on first matcher only
author Chris Cannam
date Fri, 27 Feb 2015 12:09:43 +0000
parents b5deca82e074
children 006fd4cb95b3
comparison
equal deleted inserted replaced
202:b5deca82e074 203:3662865740da
75 75
76 m_initialised = true; 76 m_initialised = true;
77 } 77 }
78 78
79 bool 79 bool
80 Matcher::isAvailable(int i, int j)
81 {
82 if (m_firstPM) {
83 if (isInRange(i, j)) {
84 return (m_bestPathCost[i][j - m_first[i]] != InvalidPathCost);
85 } else {
86 return false;
87 }
88 } else {
89 return m_otherMatcher->isAvailable(j, i);
90 }
91 }
92
93 bool
80 Matcher::isRowAvailable(int i) 94 Matcher::isRowAvailable(int i)
81 { 95 {
82 if (i < 0 || i >= int(m_first.size())) return false; 96 if (m_firstPM) {
83 97
84 for (int j = m_first[i]; j < int(m_first[i] + m_bestPathCost[i].size()); ++j) { 98 if (i < 0 || i >= int(m_first.size())) return false;
85 if (isAvailable(i, j)) { 99 for (auto c: m_bestPathCost[i]) {
86 return true; 100 if (c != InvalidPathCost) return true;
87 } 101 }
88 } 102 return false;
89 103
90 return false; 104 } else {
105 return m_otherMatcher->isColAvailable(i);
106 }
91 } 107 }
92 108
93 bool 109 bool
94 Matcher::isColAvailable(int i) 110 Matcher::isColAvailable(int j)
95 { 111 {
96 return m_otherMatcher->isRowAvailable(i); 112 if (m_firstPM) {
113 for (int i = 0; i < int(m_first.size()); ++i) {
114 if (j >= m_first[i] &&
115 j < int(m_first[i] + m_bestPathCost[i].size())) {//!!! m_last[i]?
116 if (m_bestPathCost[i][j - m_first[i]] != InvalidPathCost) {
117 return true;
118 }
119 }
120 }
121 return false;
122 } else {
123 return m_otherMatcher->isRowAvailable(j);
124 }
97 } 125 }
98 126
99 bool 127 bool
100 Matcher::isInRange(int i, int j) 128 Matcher::isInRange(int i, int j)
101 { 129 {
104 (i < int(m_first.size())) && 132 (i < int(m_first.size())) &&
105 (j >= m_first[i]) && 133 (j >= m_first[i]) &&
106 (j < int(m_first[i] + m_bestPathCost[i].size()))); 134 (j < int(m_first[i] + m_bestPathCost[i].size())));
107 } else { 135 } else {
108 return m_otherMatcher->isInRange(j, i); 136 return m_otherMatcher->isInRange(j, i);
109 }
110 }
111
112 bool
113 Matcher::isAvailable(int i, int j)
114 {
115 if (m_firstPM) {
116 if (isInRange(i, j)) {
117 return (m_bestPathCost[i][j - m_first[i]] >= 0);
118 } else {
119 return false;
120 }
121 } else {
122 return m_otherMatcher->isAvailable(j, i);
123 } 137 }
124 } 138 }
125 139
126 pair<int, int> 140 pair<int, int>
127 Matcher::getColRange(int i) 141 Matcher::getColRange(int i)
189 203
190 pathcost_t 204 pathcost_t
191 Matcher::getPathCost(int i, int j) 205 Matcher::getPathCost(int i, int j)
192 { 206 {
193 if (m_firstPM) { 207 if (m_firstPM) {
208 #ifdef PERFORM_ERROR_CHECKS
194 if (!isAvailable(i, j)) { 209 if (!isAvailable(i, j)) {
195 if (!isInRange(i, j)) { 210 if (!isInRange(i, j)) {
196 cerr << "ERROR: Matcher::getPathCost(" << i << ", " << j << "): " 211 cerr << "ERROR: Matcher::getPathCost(" << i << ", " << j << "): "
197 << "Location is not in range" << endl; 212 << "Location is not in range" << endl;
198 } else { 213 } else {
201 << m_bestPathCost[i][j - m_first[i]] 216 << m_bestPathCost[i][j - m_first[i]]
202 << ") is invalid or has not been set" << endl; 217 << ") is invalid or has not been set" << endl;
203 } 218 }
204 throw "Path cost not available"; 219 throw "Path cost not available";
205 } 220 }
221 #endif
206 return m_bestPathCost[i][j - m_first[i]]; 222 return m_bestPathCost[i][j - m_first[i]];
207 } else { 223 } else {
208 return m_otherMatcher->getPathCost(j, i); 224 return m_otherMatcher->getPathCost(j, i);
209 } 225 }
210 } 226 }
491 } 507 }
492 if (m_distance.empty()) { 508 if (m_distance.empty()) {
493 cerr << "- have no cells in matrix" << endl; 509 cerr << "- have no cells in matrix" << endl;
494 } else { 510 } else {
495 cerr << "- have " << m_distance.size() << " cols in matrix with avg " 511 cerr << "- have " << m_distance.size() << " cols in matrix with avg "
496 << double(cells) / m_distance.size() << " rows, total " 512 << double(cells) / double(m_distance.size()) << " rows, total "
497 << cells << " cells" << endl; 513 << cells << " cells" << endl;
498 cerr << "- path costs " << k(cells * sizeof(pathcost_t)) 514 cerr << "- path costs " << k(cells * sizeof(pathcost_t))
499 << "K, distances " << k(cells * sizeof(distance_t)) 515 << "K, distances " << k(cells * sizeof(distance_t))
500 << "K, advances " << k(cells * sizeof(advance_t)) << "K" << endl; 516 << "K, advances " << k(cells * sizeof(advance_t)) << "K" << endl;
501 } 517 }