From 26a0544e4ba075bfbc773f75ee5b1489f41ada1f Mon Sep 17 00:00:00 2001 From: Tim Quatmann Date: Wed, 8 Apr 2020 10:10:34 +0200 Subject: [PATCH] BeiliefManager: Use flat_maps for beliefs and hash_maps for belief storage. --- src/storm-pomdp/storage/BeliefManager.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/storm-pomdp/storage/BeliefManager.h b/src/storm-pomdp/storage/BeliefManager.h index 95c596005..25ec3a3d2 100644 --- a/src/storm-pomdp/storage/BeliefManager.h +++ b/src/storm-pomdp/storage/BeliefManager.h @@ -1,9 +1,9 @@ #pragma once -#include +#include #include -//#include - +#include +#include "storm/adapters/RationalNumberAdapter.h" #include "storm/utility/macros.h" #include "storm/exceptions/UnexpectedException.h" @@ -15,8 +15,7 @@ namespace storm { public: typedef typename PomdpType::ValueType ValueType; - //typedef boost::container::flat_map BeliefType - typedef std::map BeliefType; + typedef boost::container::flat_map BeliefType; // iterating over this shall be ordered (for correct hash computation) typedef uint64_t BeliefId; BeliefManager(PomdpType const& pomdp, BeliefValueType const& precision) : pomdp(pomdp), cc(precision, false) { @@ -343,7 +342,6 @@ namespace storm { std::vector> expandInternal(BeliefId const& beliefId, uint64_t actionIndex, boost::optional> const& observationTriangulationResolutions = boost::none) { std::vector> destinations; - // TODO: Output as vector? BeliefType belief = getBelief(beliefId); @@ -411,11 +409,23 @@ namespace storm { return insertioRes.first->second; } + struct BeliefHash { + std::size_t operator()(const BeliefType& belief) const { + std::size_t seed = 0; + // Assumes that beliefs are ordered + for (auto const& entry : belief) { + boost::hash_combine(seed, entry.first); + boost::hash_combine(seed, entry.second); + } + return seed; + } + }; + PomdpType const& pomdp; std::vector pomdpActionRewardVector; std::vector beliefs; - std::map beliefToIdMap; + std::unordered_map beliefToIdMap; BeliefId initialBeliefId; storm::utility::ConstantsComparator cc;