From 527713964085ae21879994fc5235106ebd9126c0 Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Thu, 23 Apr 2020 15:49:43 -0700 Subject: [PATCH] first version of a generator for belief support MDPs --- .../generator/BeliefSupportTracker.cpp | 35 +++++++++++++++++++ .../generator/BeliefSupportTracker.h | 26 ++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/storm-pomdp/generator/BeliefSupportTracker.cpp create mode 100644 src/storm-pomdp/generator/BeliefSupportTracker.h diff --git a/src/storm-pomdp/generator/BeliefSupportTracker.cpp b/src/storm-pomdp/generator/BeliefSupportTracker.cpp new file mode 100644 index 000000000..be2138121 --- /dev/null +++ b/src/storm-pomdp/generator/BeliefSupportTracker.cpp @@ -0,0 +1,35 @@ +#include "storm-pomdp/generator/BeliefSupportTracker.h" + +namespace storm { + namespace generator { + template + BeliefSupportTracker::BeliefSupportTracker(storm::models::sparse::Pomdp const& pomdp) : + pomdp(pomdp), currentBeliefSupport(pomdp.getInitialStates()) + { + + } + + template + storm::storage::BitVector const& BeliefSupportTracker::getCurrentBeliefSupport() const { + return currentBeliefSupport; + } + + template + void BeliefSupportTracker::track(uint64_t action, uint64_t observation) { + storm::storage::BitVector newBeliefSupport(pomdp.getNumberOfStates()); + for (uint64_t oldState : currentBeliefSupport) { + uint64_t row = pomdp.getTransitionMatrix().getRowGroupIndices()[oldState] + action; + for (auto const& successor : pomdp.getTransitionMatrix().getRow(row)) { + assert(!storm::utility::isZero(successor.getValue())); + if (pomdp.getObservation(successor.getColumn()) == observation) { + newBeliefSupport.set(successor.getColumn(), true); + } + } + } + currentBeliefSupport = newBeliefSupport; + } + + template class BeliefSupportTracker; + + } +} \ No newline at end of file diff --git a/src/storm-pomdp/generator/BeliefSupportTracker.h b/src/storm-pomdp/generator/BeliefSupportTracker.h new file mode 100644 index 000000000..dcd133043 --- /dev/null +++ b/src/storm-pomdp/generator/BeliefSupportTracker.h @@ -0,0 +1,26 @@ +#include "storm/models/sparse/Pomdp.h" +#include "storm/storage/BitVector.h" + +namespace storm { + namespace generator { + template + class BeliefSupportTracker { + /** + * Tracks the current belief support. + * TODO refactor into tracker and generator. + * @param pomdp + */ + public: + BeliefSupportTracker(storm::models::sparse::Pomdp const& pomdp); + + storm::storage::BitVector const& getCurrentBeliefSupport() const; + + void track(uint64_t action, uint64_t observation); + + private: + storm::models::sparse::Pomdp const& pomdp; + storm::storage::BitVector currentBeliefSupport; + + }; + } +} \ No newline at end of file