From a65c445243d28796272ce3913111b1d6958eb843 Mon Sep 17 00:00:00 2001 From: Alexander Bork Date: Fri, 8 Nov 2019 10:20:49 +0100 Subject: [PATCH] Avoid multiple computation of size in subsimplex computation --- .../ApproximatePOMDPModelchecker.cpp | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.cpp b/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.cpp index ad2fd4973..063f80146 100644 --- a/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.cpp +++ b/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.cpp @@ -944,13 +944,14 @@ namespace storm { std::vector probabilities, uint64_t resolution) { // This is the Freudenthal Triangulation as described in Lovejoy (a whole lotta math) // Variable names are based on the paper - std::vector x(probabilities.size()); - std::vector v(probabilities.size()); - std::vector d(probabilities.size()); + uint64_t probSize = probabilities.size(); + std::vector x(probSize); + std::vector v(probSize); + std::vector d(probSize); auto convResolution = storm::utility::convertNumber(resolution); - for (size_t i = 0; i < probabilities.size(); ++i) { - for (size_t j = i; j < probabilities.size(); ++j) { + for (size_t i = 0; i < probSize; ++i) { + for (size_t j = i; j < probSize; ++j) { x[i] += convResolution * probabilities[j]; } v[i] = storm::utility::floor(x[i]); @@ -959,14 +960,14 @@ namespace storm { auto p = storm::utility::vector::getSortedIndices(d); - std::vector> qs(probabilities.size(), std::vector(probabilities.size())); - for (size_t i = 0; i < probabilities.size(); ++i) { + std::vector> qs(probSize, std::vector(probSize)); + for (size_t i = 0; i < probSize; ++i) { if (i == 0) { - for (size_t j = 0; j < probabilities.size(); ++j) { + for (size_t j = 0; j < probSize; ++j) { qs[i][j] = v[j]; } } else { - for (size_t j = 0; j < probabilities.size(); ++j) { + for (size_t j = 0; j < probSize; ++j) { if (j == p[i - 1]) { qs[i][j] = qs[i - 1][j] + storm::utility::one(); } else { @@ -975,18 +976,18 @@ namespace storm { } } } - std::vector> subSimplex(qs.size(), std::vector(probabilities.size())); - for (size_t j = 0; j < qs.size(); ++j) { - for (size_t i = 0; i < probabilities.size() - 1; ++i) { + std::vector> subSimplex(probSize, std::vector(probSize)); + for (size_t j = 0; j < probSize; ++j) { + for (size_t i = 0; i < probSize - 1; ++i) { subSimplex[j][i] = (qs[j][i] - qs[j][i + 1]) / convResolution; } - subSimplex[j][probabilities.size() - 1] = qs[j][probabilities.size() - 1] / convResolution; + subSimplex[j][probSize - 1] = qs[j][probSize - 1] / convResolution; } - std::vector lambdas(probabilities.size(), storm::utility::zero()); + std::vector lambdas(probSize, storm::utility::zero()); auto sum = storm::utility::zero(); - for (size_t i = 1; i < probabilities.size(); ++i) { + for (size_t i = 1; i < probSize; ++i) { lambdas[i] = d[p[i - 1]] - d[p[i]]; sum += d[p[i - 1]] - d[p[i]]; }