| 55 | } |
| 56 | |
| 57 | int MinorProcessor::getBestLine (const int k, const MinorKey& mk) const |
| 58 | { |
| 59 | /* This method identifies the row or column with the most zeros. |
| 60 | The returned index (bestIndex) is absolute within the pre- |
| 61 | defined matrix. |
| 62 | If some row has the most zeros, then the absolute (0-based) |
| 63 | row index is returned. |
| 64 | If, contrariwise, some column has the most zeros, then -1 minus |
| 65 | the absolute (0-based) column index is returned. */ |
| 66 | int numberOfZeros = 0; |
| 67 | int bestIndex = 100000; /* We start with an invalid row/column index. */ |
| 68 | int maxNumberOfZeros = -1; /* We update this variable whenever we find |
| 69 | a new so-far optimal row or column. */ |
| 70 | for (int r = 0; r < k; r++) |
| 71 | { |
| 72 | /* iterate through all k rows of the momentary minor */ |
| 73 | int absoluteR = mk.getAbsoluteRowIndex(r); |
| 74 | numberOfZeros = 0; |
| 75 | for (int c = 0; c < k; c++) |
| 76 | { |
| 77 | int absoluteC = mk.getAbsoluteColumnIndex(c); |
| 78 | if (isEntryZero(absoluteR, absoluteC)) numberOfZeros++; |
| 79 | } |
| 80 | if (numberOfZeros > maxNumberOfZeros) |
| 81 | { |
| 82 | /* We found a new best line which is a row. */ |
| 83 | bestIndex = absoluteR; |
| 84 | maxNumberOfZeros = numberOfZeros; |
| 85 | } |
| 86 | }; |
| 87 | for (int c = 0; c < k; c++) |
| 88 | { |
| 89 | int absoluteC = mk.getAbsoluteColumnIndex(c); |
| 90 | numberOfZeros = 0; |
| 91 | for (int r = 0; r < k; r++) |
| 92 | { |
| 93 | int absoluteR = mk.getAbsoluteRowIndex(r); |
| 94 | if (isEntryZero(absoluteR, absoluteC)) numberOfZeros++; |
| 95 | } |
| 96 | if (numberOfZeros > maxNumberOfZeros) |
| 97 | { |
| 98 | /* We found a new best line which is a column. So we transform |
| 99 | the return value. Note that we can easily retrieve absoluteC |
| 100 | from bestLine: absoluteC = - 1 - bestLine. */ |
| 101 | bestIndex = - absoluteC - 1; |
| 102 | maxNumberOfZeros = numberOfZeros; |
| 103 | } |
| 104 | }; |
| 105 | return bestIndex; |
| 106 | } |
| 107 | |
| 108 | void MinorProcessor::setMinorSize(const int minorSize) |
| 109 | { |
nothing calls this directly
no test coverage detected