From b3493b5888c75d96214ee329523ad1e724cf41b7 Mon Sep 17 00:00:00 2001 From: Tim Quatmann Date: Wed, 18 Mar 2020 13:49:42 +0100 Subject: [PATCH] Grid: Added cli setting to cache subsimplices. --- .../modules/GridApproximationSettings.cpp | 7 ++++++ .../modules/GridApproximationSettings.h | 1 + src/storm-pomdp-cli/storm-pomdp.cpp | 1 + .../ApproximatePOMDPModelchecker.cpp | 24 +++++++++---------- .../ApproximatePOMDPModelchecker.h | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/storm-pomdp-cli/settings/modules/GridApproximationSettings.cpp b/src/storm-pomdp-cli/settings/modules/GridApproximationSettings.cpp index 2aaf3239c..8006b3851 100644 --- a/src/storm-pomdp-cli/settings/modules/GridApproximationSettings.cpp +++ b/src/storm-pomdp-cli/settings/modules/GridApproximationSettings.cpp @@ -18,6 +18,7 @@ namespace storm { const std::string resolutionOption = "resolution"; const std::string limitBeliefExplorationOption = "limit-exploration"; const std::string numericPrecisionOption = "numeric-precision"; + const std::string cacheSimplicesOption = "cache-simplices"; GridApproximationSettings::GridApproximationSettings() : ModuleSettings(moduleName) { @@ -32,6 +33,8 @@ namespace storm { this->addOption(storm::settings::OptionBuilder(moduleName, numericPrecisionOption, false,"Sets the precision used to determine whether two belief-states are equal.").addArgument( storm::settings::ArgumentBuilder::createDoubleArgument("value","the precision").setDefaultValueDouble(1e-9).makeOptional().addValidatorDouble(storm::settings::ArgumentValidatorFactory::createDoubleRangeValidatorIncluding(0, 1)).build()).build()); + this->addOption(storm::settings::OptionBuilder(moduleName, cacheSimplicesOption, false,"Enables caching of simplices which requires more memory but can be faster.").build()); + } bool GridApproximationSettings::isRefineSet() const { @@ -58,6 +61,10 @@ namespace storm { return this->getOption(numericPrecisionOption).getArgumentByName("value").getValueAsDouble(); } + bool GridApproximationSettings::isCacheSimplicesSet() const { + return this->getOption(cacheSimplicesOption).getHasOptionBeenSet(); + } + } // namespace modules } // namespace settings } // namespace storm diff --git a/src/storm-pomdp-cli/settings/modules/GridApproximationSettings.h b/src/storm-pomdp-cli/settings/modules/GridApproximationSettings.h index 5c1e281d4..a01fdbd77 100644 --- a/src/storm-pomdp-cli/settings/modules/GridApproximationSettings.h +++ b/src/storm-pomdp-cli/settings/modules/GridApproximationSettings.h @@ -26,6 +26,7 @@ namespace storm { double getExplorationThreshold() const; bool isNumericPrecisionSetFromDefault() const; double getNumericPrecision() const; + bool isCacheSimplicesSet() const; // The name of the module. static const std::string moduleName; diff --git a/src/storm-pomdp-cli/storm-pomdp.cpp b/src/storm-pomdp-cli/storm-pomdp.cpp index e62b93f4b..e0000c0d6 100644 --- a/src/storm-pomdp-cli/storm-pomdp.cpp +++ b/src/storm-pomdp-cli/storm-pomdp.cpp @@ -92,6 +92,7 @@ namespace storm { options.doRefinement = gridSettings.isRefineSet(); options.refinementPrecision = gridSettings.getRefinementPrecision(); options.numericPrecision = gridSettings.getNumericPrecision(); + options.cacheSubsimplices = gridSettings.isCacheSimplicesSet(); if (storm::NumberTraits::IsExact) { if (gridSettings.isNumericPrecisionSetFromDefault()) { STORM_LOG_WARN_COND(storm::utility::isZero(options.numericPrecision), "Setting numeric precision to zero because exact arithmethic is used."); diff --git a/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.cpp b/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.cpp index 90fa96039..1c40e96f6 100644 --- a/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.cpp +++ b/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.cpp @@ -34,6 +34,7 @@ namespace storm { doRefinement = true; refinementPrecision = storm::utility::convertNumber(1e-4); numericPrecision = storm::NumberTraits::IsExact ? storm::utility::zero() : storm::utility::convertNumber(1e-9); + cacheSubsimplices = false; } template @@ -41,7 +42,6 @@ namespace storm { cc = storm::utility::ConstantsComparator(storm::utility::convertNumber(this->options.numericPrecision), false); useMdp = true; maxIterations = 1000; - cacheSubsimplices = false; } template @@ -299,7 +299,7 @@ namespace storm { auto initTemp = computeSubSimplexAndLambdas(initialBelief.probabilities, observationResolutionVector[initialBelief.observation], pomdp.getNumberOfStates()); auto initSubSimplex = initTemp.first; auto initLambdas = initTemp.second; - if (cacheSubsimplices) { + if (options.cacheSubsimplices) { subSimplexCache[0] = initSubSimplex; lambdaCache[0] = initLambdas; } @@ -406,7 +406,7 @@ namespace storm { //Triangulate here and put the possibly resulting belief in the grid std::vector> subSimplex; std::vector lambdas; - if (cacheSubsimplices && subSimplexCache.count(idNextBelief) > 0) { + if (options.cacheSubsimplices && subSimplexCache.count(idNextBelief) > 0) { subSimplex = subSimplexCache[idNextBelief]; lambdas = lambdaCache[idNextBelief]; } else { @@ -414,7 +414,7 @@ namespace storm { observationResolutionVector[beliefList[idNextBelief].observation], pomdp.getNumberOfStates()); subSimplex = temp.first; lambdas = temp.second; - if (cacheSubsimplices) { + if (options.cacheSubsimplices) { subSimplexCache[idNextBelief] = subSimplex; lambdaCache[idNextBelief] = lambdas; } @@ -600,7 +600,7 @@ namespace storm { std::vector> subSimplex; std::vector lambdas; //TODO add caching - if (cacheSubsimplices && subSimplexCache.count(idNextBelief) > 0) { + if (options.cacheSubsimplices && subSimplexCache.count(idNextBelief) > 0) { subSimplex = subSimplexCache[idNextBelief]; lambdas = lambdaCache[idNextBelief]; } else { @@ -609,7 +609,7 @@ namespace storm { pomdp.getNumberOfStates()); subSimplex = temp.first; lambdas = temp.second; - if (cacheSubsimplices) { + if (options.cacheSubsimplices) { subSimplexCache[idNextBelief] = subSimplex; lambdaCache[idNextBelief] = lambdas; } @@ -693,7 +693,7 @@ namespace storm { std::vector> subSimplex; std::vector lambdas; /* TODO Caching - if (cacheSubsimplices && subSimplexCache.count(idNextBelief) > 0) { + if (options.cacheSubsimplices && subSimplexCache.count(idNextBelief) > 0) { subSimplex = subSimplexCache[idNextBelief]; lambdas = lambdaCache[idNextBelief]; } else { */ @@ -702,7 +702,7 @@ namespace storm { pomdp.getNumberOfStates()); subSimplex = temp.first; lambdas = temp.second; - /*if (cacheSubsimplices) { + /*if (options.cacheSubsimplices) { subSimplexCache[idNextBelief] = subSimplex; lambdaCache[idNextBelief] = lambdas; } @@ -882,14 +882,14 @@ namespace storm { // cache the values to not always re-calculate std::vector> subSimplex; std::vector lambdas; - if (cacheSubsimplices && subSimplexCache.count(nextBelief.id) > 0) { + if (options.cacheSubsimplices && subSimplexCache.count(nextBelief.id) > 0) { subSimplex = subSimplexCache[nextBelief.id]; lambdas = lambdaCache[nextBelief.id]; } else { auto temp = computeSubSimplexAndLambdas(nextBelief.probabilities, gridResolution, pomdp.getNumberOfStates()); subSimplex = temp.first; lambdas = temp.second; - if (cacheSubsimplices) { + if (options.cacheSubsimplices) { subSimplexCache[nextBelief.id] = subSimplex; lambdaCache[nextBelief.id] = lambdas; } @@ -937,7 +937,7 @@ namespace storm { std::vector initialLambda; std::vector> initialSubsimplex; - if (cacheSubsimplices) { + if (options.cacheSubsimplices) { initialLambda = lambdaCache[0]; initialSubsimplex = subSimplexCache[0]; } else { @@ -1007,7 +1007,7 @@ namespace storm { std::map> lambdaCache; auto temp = computeSubSimplexAndLambdas(initialBelief.probabilities, gridResolution, pomdp.getNumberOfStates()); - if (cacheSubsimplices) { + if (options.cacheSubsimplices) { subSimplexCache[0] = temp.first; lambdaCache[0] = temp.second; } diff --git a/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.h b/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.h index 3cd5f06ba..e5cb6ea1b 100644 --- a/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.h +++ b/src/storm-pomdp/modelchecker/ApproximatePOMDPModelchecker.h @@ -59,6 +59,7 @@ namespace storm { bool doRefinement; /// Sets whether the bounds should be refined automatically until the refinement precision is reached ValueType refinementPrecision; /// Used to decide when the refinement should terminate ValueType numericPrecision; /// Used to decide whether two values are equal + bool cacheSubsimplices; /// Enables caching of subsimplices }; ApproximatePOMDPModelchecker(storm::models::sparse::Pomdp const& pomdp, Options options = Options()); @@ -349,7 +350,6 @@ namespace storm { storm::utility::ConstantsComparator cc; // TODO: these should be obsolete, right? bool useMdp; - bool cacheSubsimplices; uint64_t maxIterations; };