Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
RewardBoundedBeliefSplitter.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <string>
5#include <vector>
6
10
11namespace storm::pomdp::beliefs {
12
19template<typename RewardValueType, typename PomdpType, typename BeliefType>
21 public:
22 using PomdpValueType = typename PomdpType::ValueType;
23 using BeliefValueType = typename BeliefType::ValueType;
24 using RewardVectorType = std::vector<RewardValueType>;
25
27 RewardBoundedBeliefSplitter(PomdpType const& pomdp);
29 void setRewardModel(std::string const& rewardModelName = "");
31 void setRewardModels(std::vector<std::string> const& rewardModelNames);
33 void unsetRewardModels();
35 std::size_t getNumberOfSetRewardModels() const;
36
43 template<typename ExpandCallback>
44 void abstract(BeliefType const& belief, uint64_t localActionIndex, ExpandCallback const& callback) {
45 // gather the occurring reward vectors and build the sub-beliefs
46 std::map<RewardVectorType, BeliefBuilder<BeliefType>> splitBeliefs;
47 belief.forEach([&localActionIndex, &splitBeliefs, this](BeliefStateType const& state, BeliefValueType const& beliefValue) {
48 auto const globalActionIndex = pomdp.getTransitionMatrix().getRowGroupIndices()[state] + localActionIndex;
49 auto const& rewVector = actionRewardVectors[globalActionIndex];
50 splitBeliefs[rewVector].addValue(state, beliefValue);
51 });
52
53 for (auto& [rewardVector, builder] : splitBeliefs) {
54 // Index 0 shares the original POMDP observation encoding used by the initial belief.
55 // The initial occurrence has no incoming reward; generated successors carry their reward vector
56 // on the transition. Do not infer an initial reward from the observation value.
57 BeliefActionObservationType const freshIndex = rewardVectorToIndex.size();
58 auto const rewVectorIndex = rewardVectorToIndex.emplace(rewardVector, freshIndex).first->second;
59 builder.setObservation(belief.observation());
60 if (splitBeliefs.size() == 1u) {
61 // Fix the distribution to diminish numerical issues a bit
62 callback(builder.build(), storm::utility::one<BeliefValueType>(), rewVectorIndex, rewardVector);
63 } else {
64 auto val = builder.normalize();
65 callback(builder.build(), std::move(val), rewVectorIndex, rewardVector);
66 }
67 }
68 }
69
70 private:
71 PomdpType const& pomdp;
72 std::vector<RewardVectorType> actionRewardVectors;
73 std::map<RewardVectorType, BeliefActionObservationType> rewardVectorToIndex;
74};
75} // namespace storm::pomdp::beliefs
void setRewardModel(std::string const &rewardModelName="")
Selects one reward model; an empty name selects Storm's default reward model.
RewardBoundedBeliefSplitter(PomdpType const &pomdp)
Creates a splitter for pomdp.
void abstract(BeliefType const &belief, uint64_t localActionIndex, ExpandCallback const &callback)
Splits belief into normalized sub-beliefs with equal reward vectors for localActionIndex.
void unsetRewardModels()
Clears the selected reward models and all generated reward-vector observation indices.
void setRewardModels(std::vector< std::string > const &rewardModelNames)
Selects a nonempty list of reward models used to form reward vectors.
uint64_t BeliefStateType
Shared identifiers and sparse-container types used by the belief subsystem.
Definition types.h:10
uint32_t BeliefActionObservationType
Definition types.h:13
ValueType one()
Definition constants.cpp:21