src/utilities/data/Matrix.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "Matrix.hpp" | ||
| 7 | |||
| 8 | #include "../math/FloatCompare.hpp" | ||
| 9 | |||
| 10 | #include <random> | ||
| 11 | |||
| 12 | // this should all be moved to a utilities/core/Random.h | ||
| 13 | #include <boost/random/uniform_real.hpp> | ||
| 14 | #include <boost/random/variate_generator.hpp> | ||
| 15 | |||
| 16 | namespace openstudio { | ||
| 17 | |||
| 18 | 10 | bool operator==(const Matrix& lhs, const Matrix& rhs) { | |
| 19 | 10 | bool result = false; | |
| 20 |
1/2✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | if (lhs.size1() == rhs.size1()) { |
| 21 |
2/2✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2 times.
|
10 | if (lhs.size2() == rhs.size2()) { |
| 22 | 8 | result = true; | |
| 23 |
2/2✓ Branch 1 taken 30 times.
✓ Branch 2 taken 8 times.
|
38 | for (unsigned i = 0; i < lhs.size1(); ++i) { |
| 24 |
2/2✓ Branch 1 taken 118 times.
✓ Branch 2 taken 30 times.
|
148 | for (unsigned j = 0; j < lhs.size2(); ++j) { |
| 25 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 118 times.
|
118 | if (lhs(i, j) != rhs(i, j)) { |
| 26 | ✗ | return false; | |
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | 10 | return result; | |
| 33 | } | ||
| 34 | |||
| 35 | 1 | bool operator!=(const Matrix& lhs, const Matrix& rhs) { | |
| 36 | 1 | return !(lhs == rhs); | |
| 37 | } | ||
| 38 | |||
| 39 | /// linear interpolation of the function v = f(x, y) at point xi, yi | ||
| 40 | /// assumes that x and y are strictly increasing | ||
| 41 | 72 | double interp(const Vector& x, const Vector& y, const Matrix& v, double xi, double yi, InterpMethod interpMethod, ExtrapMethod extrapMethod, | |
| 42 | double ti) { | ||
| 43 | 72 | double result = 0.0; | |
| 44 | |||
| 45 |
1/1✓ Branch 1 taken 72 times.
|
72 | size_t M = x.size(); |
| 46 |
1/1✓ Branch 1 taken 72 times.
|
72 | size_t N = y.size(); |
| 47 | |||
| 48 |
3/6✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 72 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 72 times.
|
72 | if ((M != v.size1()) || (N != v.size2())) { |
| 49 | ✗ | return result; | |
| 50 | } | ||
| 51 | |||
| 52 |
1/1✓ Branch 1 taken 72 times.
|
72 | InterpInfo xInfo = interpInfo(x, xi, ti); |
| 53 | |||
| 54 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 54 times.
|
72 | if (xInfo.extrapolated) { |
| 55 |
2/3✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
18 | switch (extrapMethod) { |
| 56 | 6 | case NoneExtrap: | |
| 57 | // set all weights to zero | ||
| 58 | 6 | xInfo.wa = 0.0; | |
| 59 | 6 | xInfo.wb = 0.0; | |
| 60 | 6 | break; | |
| 61 | 12 | case NearestExtrap: | |
| 62 | // pick closest point | ||
| 63 | // no-op | ||
| 64 | 12 | break; | |
| 65 | } | ||
| 66 | } else { | ||
| 67 |
2/6✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
54 | switch (interpMethod) { |
| 68 | 33 | case LinearInterp: | |
| 69 | // linear interpolation | ||
| 70 | // no-op | ||
| 71 | 33 | break; | |
| 72 | ✗ | case AverageInterp: | |
| 73 | // average interpolation | ||
| 74 | // no-op | ||
| 75 | ✗ | break; | |
| 76 | 21 | case NearestInterp: | |
| 77 | // pick closest point | ||
| 78 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 12 times.
|
21 | if (xInfo.wa > xInfo.wb) { |
| 79 | 9 | xInfo.wa = 1.0; | |
| 80 | 9 | xInfo.wb = 0.0; | |
| 81 | } else { | ||
| 82 | 12 | xInfo.wa = 0.0; | |
| 83 | 12 | xInfo.wb = 1.0; | |
| 84 | } | ||
| 85 | 21 | break; | |
| 86 | ✗ | case HoldLastInterp: | |
| 87 | // set to previous value | ||
| 88 | ✗ | xInfo.wa = 1.0; | |
| 89 | ✗ | xInfo.wb = 0.0; | |
| 90 | ✗ | break; | |
| 91 | ✗ | case HoldNextInterp: | |
| 92 | // set to next value | ||
| 93 | ✗ | xInfo.wa = 0.0; | |
| 94 | ✗ | xInfo.wb = 1.0; | |
| 95 | ✗ | break; | |
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 |
1/1✓ Branch 1 taken 72 times.
|
72 | InterpInfo yInfo = interpInfo(y, yi, ti); |
| 100 | |||
| 101 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 54 times.
|
72 | if (yInfo.extrapolated) { |
| 102 |
2/3✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
18 | switch (extrapMethod) { |
| 103 | 6 | case NoneExtrap: | |
| 104 | // set all weights to zero | ||
| 105 | 6 | yInfo.wa = 0.0; | |
| 106 | 6 | yInfo.wb = 0.0; | |
| 107 | 6 | break; | |
| 108 | 12 | case NearestExtrap: | |
| 109 | // pick closest point | ||
| 110 | // no-op | ||
| 111 | 12 | break; | |
| 112 | } | ||
| 113 | } else { | ||
| 114 |
2/6✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
54 | switch (interpMethod) { |
| 115 | 33 | case LinearInterp: | |
| 116 | // linear interpolation | ||
| 117 | // no-op | ||
| 118 | 33 | break; | |
| 119 | ✗ | case AverageInterp: | |
| 120 | // average interpolation | ||
| 121 | // no-op | ||
| 122 | ✗ | break; | |
| 123 | 21 | case NearestInterp: | |
| 124 | // pick closest point | ||
| 125 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 9 times.
|
21 | if (yInfo.wa > yInfo.wb) { |
| 126 | 12 | yInfo.wa = 1.0; | |
| 127 | 12 | yInfo.wb = 0.0; | |
| 128 | } else { | ||
| 129 | 9 | yInfo.wa = 0.0; | |
| 130 | 9 | yInfo.wb = 1.0; | |
| 131 | } | ||
| 132 | 21 | break; | |
| 133 | ✗ | case HoldLastInterp: | |
| 134 | // set to previous value | ||
| 135 | ✗ | yInfo.wa = 1.0; | |
| 136 | ✗ | yInfo.wb = 0.0; | |
| 137 | ✗ | break; | |
| 138 | ✗ | case HoldNextInterp: | |
| 139 | // set to next value | ||
| 140 | ✗ | yInfo.wa = 0.0; | |
| 141 | ✗ | yInfo.wb = 1.0; | |
| 142 | ✗ | break; | |
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | // we have set weights appropriately so that here we can compute in the same way all the time | ||
| 147 |
3/3✓ Branch 1 taken 72 times.
✓ Branch 4 taken 72 times.
✓ Branch 7 taken 72 times.
|
72 | result = xInfo.wa * yInfo.wa * v(xInfo.ia, yInfo.ia) + xInfo.wa * yInfo.wb * v(xInfo.ia, yInfo.ib) + xInfo.wb * yInfo.wa * v(xInfo.ib, yInfo.ia) |
| 148 |
1/1✓ Branch 1 taken 72 times.
|
72 | + xInfo.wb * yInfo.wb * v(xInfo.ib, yInfo.ib); |
| 149 | |||
| 150 | 72 | return result; | |
| 151 | } | ||
| 152 | |||
| 153 | /// linear interpolation of the function v = f(x, y) at points xi, yi | ||
| 154 | /// assumes that x and y are strictly increasing | ||
| 155 | ✗ | Vector interp(const Vector& x, const Vector& y, const Matrix& v, const Vector& xi, double yi, InterpMethod interpMethod, ExtrapMethod extrapMethod, | |
| 156 | double ti) { | ||
| 157 | ✗ | size_t M = x.size(); | |
| 158 | |||
| 159 | ✗ | Vector result(M); | |
| 160 | |||
| 161 | ✗ | if (M != v.size1()) { | |
| 162 | ✗ | return result; | |
| 163 | } | ||
| 164 | |||
| 165 | ✗ | for (unsigned i = 0; i < M; ++i) { | |
| 166 | ✗ | result(i) = interp(x, y, v, xi(i), yi, interpMethod, extrapMethod, ti); | |
| 167 | } | ||
| 168 | |||
| 169 | ✗ | return result; | |
| 170 | ✗ | } | |
| 171 | |||
| 172 | /// linear interpolation of the function v = f(x, y) at points xi, yi | ||
| 173 | /// assumes that x and y are strictly increasing | ||
| 174 | ✗ | Vector interp(const Vector& x, const Vector& y, const Matrix& v, double xi, const Vector& yi, InterpMethod interpMethod, ExtrapMethod extrapMethod, | |
| 175 | double ti) { | ||
| 176 | ✗ | size_t N = y.size(); | |
| 177 | |||
| 178 | ✗ | Vector result(N); | |
| 179 | |||
| 180 | ✗ | if (N != v.size2()) { | |
| 181 | ✗ | return result; | |
| 182 | } | ||
| 183 | |||
| 184 | ✗ | for (unsigned j = 0; j < N; ++j) { | |
| 185 | ✗ | result(j) = interp(x, y, v, xi, yi(j), interpMethod, extrapMethod, ti); | |
| 186 | } | ||
| 187 | |||
| 188 | ✗ | return result; | |
| 189 | ✗ | } | |
| 190 | |||
| 191 | /// linear interpolation of the function v = f(x, y) at points xi, yi | ||
| 192 | /// assumes that x and y are strictly increasing | ||
| 193 | ✗ | Matrix interp(const Vector& x, const Vector& y, const Matrix& v, const Vector& xi, const Vector& yi, InterpMethod interpMethod, | |
| 194 | ExtrapMethod extrapMethod, double ti) { | ||
| 195 | ✗ | size_t M = x.size(); | |
| 196 | ✗ | size_t N = y.size(); | |
| 197 | |||
| 198 | ✗ | Matrix result(M, N); | |
| 199 | |||
| 200 | ✗ | if ((M != v.size1()) || (N != v.size2())) { | |
| 201 | ✗ | return result; | |
| 202 | } | ||
| 203 | |||
| 204 | ✗ | for (unsigned i = 0; i < M; ++i) { | |
| 205 | ✗ | for (unsigned j = 0; j < N; ++j) { | |
| 206 | ✗ | result(i, j) = interp(x, y, v, xi(i), yi(j), interpMethod, extrapMethod, ti); | |
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | ✗ | return result; | |
| 211 | ✗ | } | |
| 212 | |||
| 213 | /// matrix product | ||
| 214 | 509948 | Matrix prod(const Matrix& lop, const Matrix& rop) { | |
| 215 |
2/2✓ Branch 1 taken 509948 times.
✓ Branch 4 taken 509948 times.
|
509948 | return boost::numeric::ublas::prod(lop, rop); |
| 216 | } | ||
| 217 | |||
| 218 | /// vector product | ||
| 219 | 6725431 | Vector prod(const Matrix& m, const Vector& v) { | |
| 220 |
2/2✓ Branch 1 taken 6725431 times.
✓ Branch 4 taken 6725431 times.
|
6725431 | return boost::numeric::ublas::prod(m, v); |
| 221 | } | ||
| 222 | |||
| 223 | /// outer product | ||
| 224 | 1 | Matrix outerProd(const Vector& lhs, const Vector& rhs) { | |
| 225 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | return boost::numeric::ublas::outer_prod(lhs, rhs); |
| 226 | } | ||
| 227 | |||
| 228 | /// take the natural logarithm of a Matrix | ||
| 229 | 1 | Matrix log(const Matrix& v) { | |
| 230 | 1 | size_t M = v.size1(); | |
| 231 | 1 | size_t N = v.size2(); | |
| 232 | 1 | Matrix result(M, N); | |
| 233 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
|
4 | for (size_t i = 0; i < M; ++i) { |
| 234 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | for (size_t j = 0; j < N; ++j) { |
| 235 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | result(i, j) = std::log(v(i, j)); |
| 236 | } | ||
| 237 | } | ||
| 238 | 1 | return result; | |
| 239 | ✗ | } | |
| 240 | |||
| 241 | /// take the logarithm of a Matrix with certain base | ||
| 242 | 3 | Matrix log(const Matrix& v, double base) { | |
| 243 | 3 | double logBase = std::log(base); | |
| 244 | 3 | size_t M = v.size1(); | |
| 245 | 3 | size_t N = v.size2(); | |
| 246 | 3 | Matrix result(M, N); | |
| 247 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | for (size_t i = 0; i < M; ++i) { |
| 248 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 9 times.
|
36 | for (size_t j = 0; j < N; ++j) { |
| 249 |
2/2✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
|
27 | result(i, j) = std::log(v(i, j)) / logBase; |
| 250 | } | ||
| 251 | } | ||
| 252 | 3 | return result; | |
| 253 | ✗ | } | |
| 254 | |||
| 255 | /// generates a Matrix of M*N points randomly drawn between and including a and b. | ||
| 256 | 6 | Matrix randMatrix(double a, double b, unsigned M, unsigned N) { | |
| 257 |
1/1✓ Branch 1 taken 6 times.
|
6 | Matrix result(M, N); |
| 258 | |||
| 259 | // handle degenerate case | ||
| 260 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
|
6 | if (equal(a, b)) { |
| 261 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 3 times.
|
33 | for (unsigned i = 0; i < M; ++i) { |
| 262 |
2/2✓ Branch 0 taken 300 times.
✓ Branch 1 taken 30 times.
|
330 | for (unsigned j = 0; j < N; ++j) { |
| 263 |
1/1✓ Branch 1 taken 300 times.
|
300 | result(i, j) = a; |
| 264 | } | ||
| 265 | } | ||
| 266 | 3 | return result; | |
| 267 | } | ||
| 268 | |||
| 269 | // ETH@20100120. What library does this come from? The user should be able to seed the | ||
| 270 | // generator independently of this function. | ||
| 271 | // seed random number generator | ||
| 272 |
2/3✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 3 times.
|
3 | thread_local std::minstd_rand generator(42u); |
| 273 | |||
| 274 | // define distribution | ||
| 275 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::uniform_real<> dist(a, b); |
| 276 | |||
| 277 | // create a generator | ||
| 278 | 3 | boost::variate_generator<std::minstd_rand&, boost::uniform_real<>> uniformGenerator(generator, dist); | |
| 279 | |||
| 280 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 3 times.
|
33 | for (unsigned i = 0; i < M; ++i) { |
| 281 |
2/2✓ Branch 0 taken 300 times.
✓ Branch 1 taken 30 times.
|
330 | for (unsigned j = 0; j < N; ++j) { |
| 282 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
|
300 | result(i, j) = uniformGenerator(); |
| 283 | } | ||
| 284 | } | ||
| 285 | 3 | return result; | |
| 286 | ✗ | } | |
| 287 | |||
| 288 | /// sum | ||
| 289 | 4 | double sum(const Matrix& matrix) { | |
| 290 | 4 | double result = 0.0; | |
| 291 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 4 times.
|
14 | for (unsigned i = 0; i < matrix.size1(); ++i) { |
| 292 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 2 taken 10 times.
|
30 | for (unsigned j = 0; j < matrix.size2(); ++j) { |
| 293 | 20 | result += matrix(i, j); | |
| 294 | } | ||
| 295 | } | ||
| 296 | 4 | return result; | |
| 297 | } | ||
| 298 | |||
| 299 | /// maximum | ||
| 300 | 8 | double maximum(const Matrix& matrix) { | |
| 301 | 8 | double max = 0; | |
| 302 |
3/6✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
|
8 | if ((matrix.size1() > 0) && (matrix.size2() > 0)) { |
| 303 |
1/1✓ Branch 1 taken 8 times.
|
8 | max = matrix(0, 0); |
| 304 |
2/2✓ Branch 1 taken 65 times.
✓ Branch 2 taken 8 times.
|
73 | for (unsigned i = 0; i < matrix.size1(); ++i) { |
| 305 |
2/2✓ Branch 1 taken 610 times.
✓ Branch 2 taken 65 times.
|
675 | for (unsigned j = 0; j < matrix.size2(); ++j) { |
| 306 |
1/1✓ Branch 1 taken 610 times.
|
610 | max = std::max(max, matrix(i, j)); |
| 307 | } | ||
| 308 | } | ||
| 309 | } | ||
| 310 | 8 | return max; | |
| 311 | } | ||
| 312 | |||
| 313 | /// minimum | ||
| 314 | 8 | double minimum(const Matrix& matrix) { | |
| 315 | 8 | double min = 0; | |
| 316 |
3/6✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
|
8 | if ((matrix.size1() > 0) && (matrix.size2() > 0)) { |
| 317 |
1/1✓ Branch 1 taken 8 times.
|
8 | min = matrix(0, 0); |
| 318 |
2/2✓ Branch 1 taken 65 times.
✓ Branch 2 taken 8 times.
|
73 | for (unsigned i = 0; i < matrix.size1(); ++i) { |
| 319 |
2/2✓ Branch 1 taken 610 times.
✓ Branch 2 taken 65 times.
|
675 | for (unsigned j = 0; j < matrix.size2(); ++j) { |
| 320 |
1/1✓ Branch 1 taken 610 times.
|
610 | min = std::min(min, matrix(i, j)); |
| 321 | } | ||
| 322 | } | ||
| 323 | } | ||
| 324 | 8 | return min; | |
| 325 | } | ||
| 326 | |||
| 327 | /// mean | ||
| 328 | 2 | double mean(const Matrix& matrix) { | |
| 329 | 2 | double avg = 0; | |
| 330 | 2 | size_t N = matrix.size1() * matrix.size2(); | |
| 331 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (N > 0) { |
| 332 | 2 | avg = sum(matrix) / N; | |
| 333 | } | ||
| 334 | 2 | return avg; | |
| 335 | } | ||
| 336 | |||
| 337 | /// get the connected components from an NxN adjacency matrix (1.0 for i-j connected, 0.0 for i-j not connected) | ||
| 338 | 421 | std::vector<std::vector<unsigned>> findConnectedComponents(const Matrix& matrix) { | |
| 339 | 421 | double tol = 0.001; | |
| 340 | |||
| 341 | 421 | std::vector<std::vector<unsigned>> result; | |
| 342 | |||
| 343 | 421 | size_t N = matrix.size1(); | |
| 344 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 420 times.
|
421 | if (N != matrix.size2()) { |
| 345 | 1 | return result; | |
| 346 | } | ||
| 347 | |||
| 348 |
1/1✓ Branch 1 taken 420 times.
|
420 | Matrix A(N, N, 0.0); |
| 349 |
2/2✓ Branch 0 taken 2293 times.
✓ Branch 1 taken 420 times.
|
2713 | for (unsigned i = 0; i < N; ++i) { |
| 350 | |||
| 351 |
1/1✓ Branch 1 taken 2293 times.
|
2293 | A(i, i) = 1.0; // must be self connected |
| 352 |
1/1✓ Branch 1 taken 2293 times.
|
2293 | if (std::abs(matrix(i, i) - 1.0) > tol) { |
| 353 | // warn | ||
| 354 | } | ||
| 355 | |||
| 356 |
2/2✓ Branch 0 taken 14886 times.
✓ Branch 1 taken 2293 times.
|
17179 | for (unsigned j = i + 1; j < N; ++j) { |
| 357 | |||
| 358 |
2/3✓ Branch 1 taken 14886 times.
✓ Branch 3 taken 14886 times.
✗ Branch 4 not taken.
|
14886 | if (matrix(i, j) < 0) { |
| 359 | // warn | ||
| 360 |
3/3✓ Branch 1 taken 14886 times.
✓ Branch 3 taken 707 times.
✓ Branch 4 taken 14179 times.
|
14886 | } else if (matrix(i, j) > tol) { |
| 361 |
1/1✓ Branch 1 taken 707 times.
|
707 | A(i, j) = 1.0; |
| 362 | } | ||
| 363 | |||
| 364 |
2/3✓ Branch 1 taken 14886 times.
✓ Branch 3 taken 14886 times.
✗ Branch 4 not taken.
|
14886 | if (matrix(j, i) < 0) { |
| 365 | // warn | ||
| 366 |
3/3✓ Branch 1 taken 14886 times.
✓ Branch 3 taken 707 times.
✓ Branch 4 taken 14179 times.
|
14886 | } else if (matrix(j, i) > tol) { |
| 367 |
1/1✓ Branch 1 taken 707 times.
|
707 | A(j, i) = 1.0; |
| 368 | } | ||
| 369 | } | ||
| 370 | } | ||
| 371 | |||
| 372 | // raise A to the Nth power, maximum distance between two nodes | ||
| 373 |
2/2✓ Branch 0 taken 2293 times.
✓ Branch 1 taken 420 times.
|
2713 | for (unsigned n = 0; n < N; ++n) { |
| 374 |
2/2✓ Branch 1 taken 2293 times.
✓ Branch 4 taken 2293 times.
|
2293 | A = prod(A, A); |
| 375 | |||
| 376 | // re-normalize | ||
| 377 |
2/2✓ Branch 0 taken 32065 times.
✓ Branch 1 taken 2293 times.
|
34358 | for (unsigned i = 0; i < N; ++i) { |
| 378 |
2/2✓ Branch 0 taken 895447 times.
✓ Branch 1 taken 32065 times.
|
927512 | for (unsigned j = 0; j < N; ++j) { |
| 379 |
3/3✓ Branch 1 taken 895447 times.
✓ Branch 3 taken 126803 times.
✓ Branch 4 taken 768644 times.
|
895447 | if (A(j, i) > 1) { |
| 380 |
1/1✓ Branch 1 taken 126803 times.
|
126803 | A(j, i) = 1; |
| 381 | } | ||
| 382 | } | ||
| 383 | } | ||
| 384 | } | ||
| 385 | |||
| 386 | 420 | std::set<unsigned> added; | |
| 387 |
2/2✓ Branch 0 taken 2293 times.
✓ Branch 1 taken 420 times.
|
2713 | for (unsigned i = 0; i < N; ++i) { |
| 388 |
3/3✓ Branch 2 taken 2293 times.
✓ Branch 5 taken 302 times.
✓ Branch 6 taken 1991 times.
|
2293 | if (added.find(i) != added.end()) { |
| 389 | 302 | continue; | |
| 390 | } | ||
| 391 | |||
| 392 | 1991 | std::vector<unsigned> group; | |
| 393 |
1/1✓ Branch 1 taken 1991 times.
|
1991 | group.push_back(i); |
| 394 |
1/1✓ Branch 1 taken 1991 times.
|
1991 | added.insert(i); |
| 395 | |||
| 396 |
2/2✓ Branch 0 taken 12371 times.
✓ Branch 1 taken 1991 times.
|
14362 | for (unsigned j = i + 1; j < N; ++j) { |
| 397 |
8/8✓ Branch 1 taken 12371 times.
✓ Branch 3 taken 12070 times.
✓ Branch 4 taken 301 times.
✓ Branch 6 taken 12070 times.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 12069 times.
✓ Branch 10 taken 302 times.
✓ Branch 11 taken 12069 times.
|
12371 | if ((A(i, j) > 0) || (A(j, i) > 0)) { |
| 398 |
1/1✓ Branch 1 taken 302 times.
|
302 | group.push_back(j); |
| 399 |
1/1✓ Branch 1 taken 302 times.
|
302 | added.insert(j); |
| 400 | } | ||
| 401 | } | ||
| 402 | |||
| 403 |
1/1✓ Branch 1 taken 1991 times.
|
1991 | result.push_back(group); |
| 404 | 1991 | } | |
| 405 | |||
| 406 | 420 | return result; | |
| 407 | 420 | } | |
| 408 | |||
| 409 | } // namespace openstudio | ||
| 410 |