Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
FirstStateNextStateGenerator.cpp
Go to the documentation of this file.
3
8
9namespace storm::pomdp::beliefs {
10
11template<typename PomdpType, typename BeliefType>
13 // Intentionally left empty.
14}
15
16template<typename PomdpType, typename BeliefType>
18 auto const& rewardModel = pomdp.getRewardModel(rewardModelName);
19 actionRewards = rewardModel.getTotalRewardVector(pomdp.getTransitionMatrix());
20}
21
22template<typename PomdpType, typename BeliefType>
24 return !actionRewards.empty();
25}
26
27template<typename PomdpType, typename BeliefType>
31
32template<typename PomdpType, typename BeliefType>
35 pomdp.getInitialStates().getNumberOfSetBits() == 1, storm::exceptions::NotSupportedException,
36 "Only a single initial state is supported, but the given POMDP contains " << pomdp.getInitialStates().getNumberOfSetBits() << " initial states.");
37 BeliefStateType const init = *pomdp.getInitialStates().begin();
40 builder.setObservation(pomdp.getObservation(init));
41 return builder.build();
42}
43
44template<typename PomdpType, typename BeliefType>
46 auto result = pomdp.getTransitionMatrix().getRowGroupSize(belief.representativeState());
47 // Assert consistency with other states in the support
48 STORM_LOG_ASSERT(belief.allOf([&result, this](BeliefStateType const& state, typename BeliefType::ValueType const&) {
49 return pomdp.getTransitionMatrix().getRowGroupSize(state) == result;
50 }),
51 "Belief considers states with inconsistent number of choices.");
52 return result;
53}
54
55template<typename PomdpType, typename BeliefType>
56typename PomdpType::ValueType FirstStateNextStateGenerator<PomdpType, BeliefType>::getBeliefActionReward(BeliefType const& belief,
57 uint64_t const& localActionIndex) const {
58 using PomdpValueType = typename PomdpType::ValueType;
59 using BeliefValueType = typename BeliefType::ValueType;
60
61 STORM_LOG_ASSERT(hasRewardModel(), "Requested a reward although no reward model was specified.");
62 STORM_LOG_ASSERT(localActionIndex < getBeliefNumberOfActions(belief), "Invalid action index " << localActionIndex << ".");
64 auto const& actionIndices = pomdp.getTransitionMatrix().getRowGroupIndices();
65 belief.forEach([&localActionIndex, &actionIndices, &result, this](BeliefStateType const& state, BeliefValueType const& val) {
66 uint64_t const actionIndex = actionIndices[state] + localActionIndex;
67 result += storm::utility::convertNumber<PomdpValueType>(val) * this->actionRewards[actionIndex];
68 });
69 return result;
70}
71
72template<typename PomdpType, typename BeliefType>
74 uint64_t const& localActionIndex) const {
75 STORM_LOG_ASSERT(pomdp.hasChoiceLabeling(), "Requested a choice label although no choice labeling was specified in the POMDP.");
76 STORM_LOG_ASSERT(localActionIndex < getBeliefNumberOfActions(belief), "Invalid action index " << localActionIndex << ".");
77 return pomdp.getChoiceLabeling().getLabelsOfChoice(pomdp.getTransitionMatrix().getRowGroupIndices().at(belief.representativeState()) + localActionIndex);
78}
79
84
85} // namespace storm::pomdp::beliefs
Represents a belief of a Pomdp, i.e.
Definition Belief.h:21
This class implements a first-state-next-state generator interface for exploring the belief MDP of a ...
FirstStateNextStateGenerator(PomdpType const &pomdp)
Creates a successor generator for pomdp.
PomdpType::ValueType getBeliefActionReward(BeliefType const &belief, uint64_t const &localActionIndex) const
void setRewardModel(std::string const &rewardModelName="")
Selects the reward model whose expected action rewards are queried; an empty name selects the default...
std::set< std::string > getBeliefActionChoiceLabels(BeliefType const &belief, uint64_t const &localActionIndex) const
uint64_t getBeliefNumberOfActions(BeliefType const &belief) const
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
uint64_t BeliefStateType
Shared identifiers and sparse-container types used by the belief subsystem.
Definition types.h:10
ValueType zero()
Definition constants.cpp:26
ValueType one()
Definition constants.cpp:21
TargetType convertNumber(SourceType const &number)