Storm 1.13.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
NondeterministicBeliefTracker.h
Go to the documentation of this file.
1#pragma once
3
4namespace storm {
5namespace generator {
10template<typename ValueType>
12 public:
15 uint64_t getActionsForObservation(uint32_t observation) const;
16 ValueType getRisk(uint64_t) const;
17 void setRiskPerState(std::vector<ValueType> const& risk);
18 uint64_t getFreshId();
19 uint32_t getObservation(uint64_t state) const;
20 uint64_t getObservationOffset(uint64_t state) const;
21 uint64_t getState(uint32_t obs, uint64_t offset) const;
22 uint64_t getNumberOfStates() const;
23 uint64_t numberOfStatesPerObservation(uint32_t observation) const;
24
25 private:
27 std::vector<ValueType> riskPerState;
28 std::vector<uint64_t> numberActionsPerObservation;
29 uint64_t beliefIdCounter = 0;
30 std::vector<uint64_t> observationOffsetId;
31 std::vector<std::vector<uint64_t>> statePerObservationAndOffset;
32};
33
34template<typename ValueType>
36template<typename ValueType>
38
42template<typename ValueType>
44 public:
45 SparseBeliefState(std::shared_ptr<BeliefStateManager<ValueType>> const& manager, uint64_t state);
51 void update(uint32_t newObservation, std::unordered_set<SparseBeliefState>& previousBeliefs) const;
52 std::size_t hash() const noexcept;
58 ValueType get(uint64_t state) const;
63 ValueType getRisk() const;
64
65 // Various getters
66 std::string toString() const;
67 bool isValid() const;
68 uint64_t getSupportSize() const;
70 std::map<uint64_t, ValueType> const& getBeliefMap() const;
71
73
74 private:
75 void updateHelper(std::vector<std::map<uint64_t, ValueType>> const& partialBeliefs, std::vector<ValueType> const& sums,
76 typename std::map<uint64_t, ValueType>::const_iterator nextStateIt, uint32_t newObservation,
77 std::unordered_set<SparseBeliefState<ValueType>>& previousBeliefs) const;
78 SparseBeliefState(std::shared_ptr<BeliefStateManager<ValueType>> const& manager, std::map<uint64_t, ValueType> const& belief, std::size_t newHash,
79 ValueType const& risk, uint64_t prevId);
80 std::shared_ptr<BeliefStateManager<ValueType>> manager;
81
82 std::map<uint64_t, ValueType> belief; // map is ordered for unique hashing.
83 std::size_t prestoredhash = 0;
84 ValueType risk;
85 uint64_t id;
86 uint64_t prevId;
87};
88
96template<typename ValueType, typename BeliefState>
98 public:
99 struct Options {
100 uint64_t trackTimeOut = 0;
101 uint64_t timeOut = 0; // for reduction, in milliseconds, 0 is no timeout
102 ValueType wiggle; // tolerance, anything above 0 means that we are incomplete.
103 };
111 bool reset(uint32_t observation);
117 bool track(uint64_t newObservation);
122 std::unordered_set<BeliefState> const& getCurrentBeliefs() const;
127 uint32_t getCurrentObservation() const;
132 uint64_t getNumberOfBeliefs() const;
138 ValueType getCurrentRisk(bool max = true);
143 void setRisk(std::vector<ValueType> const& risk);
149 uint64_t getCurrentDimension() const;
154 uint64_t reduce();
159 bool hasTimedOut() const;
160
161 private:
163 std::shared_ptr<BeliefStateManager<ValueType>> manager;
164 std::unordered_set<BeliefState> beliefs;
165 bool reductionTimedOut = false;
166 Options options;
167 uint32_t lastObservation;
168};
169} // namespace generator
170} // namespace storm
171
172//
173namespace std {
174template<typename T>
175struct hash<storm::generator::SparseBeliefState<T>> {
176 std::size_t operator()(storm::generator::SparseBeliefState<T> const& s) const noexcept {
177 return s.hash();
178 }
179};
180} // namespace std
This class keeps track of common information of a set of beliefs.
BeliefStateManager(storm::models::sparse::Pomdp< ValueType > const &pomdp)
storm::models::sparse::Pomdp< ValueType > const & getPomdp() const
uint64_t getState(uint32_t obs, uint64_t offset) const
uint64_t numberOfStatesPerObservation(uint32_t observation) const
void setRiskPerState(std::vector< ValueType > const &risk)
uint64_t getActionsForObservation(uint32_t observation) const
std::unordered_set< BeliefState > const & getCurrentBeliefs() const
Provides access to the current beliefs.
NondeterministicBeliefTracker(storm::models::sparse::Pomdp< ValueType > const &pomdp, typename NondeterministicBeliefTracker< ValueType, BeliefState >::Options options=Options())
uint64_t reduce()
Apply reductions to the belief state.
ValueType getCurrentRisk(bool max=true)
What is the (worst-case/best-case) risk over all beliefs.
void setRisk(std::vector< ValueType > const &risk)
Sets the state-risk to use for all beliefs.
uint64_t getCurrentDimension() const
What is the dimension of the current set of beliefs, i.e., what is the number of states we could poss...
uint32_t getCurrentObservation() const
What was the last obervation that we made?
bool hasTimedOut() const
Did we time out during the computation?
bool reset(uint32_t observation)
Start with a new trace.
uint64_t getNumberOfBeliefs() const
How many beliefs are we currently tracking?
bool track(uint64_t newObservation)
Extend the observed trace with the new observation.
SparseBeliefState stores beliefs in a sparse format.
void setSupport(storm::storage::BitVector &) const
void update(uint32_t newObservation, std::unordered_set< SparseBeliefState > &previousBeliefs) const
Update the belief using the new observation.
std::map< uint64_t, ValueType > const & getBeliefMap() const
ValueType get(uint64_t state) const
Get the estimate to be in the given state.
friend bool operator==(SparseBeliefState< ValueType > const &lhs, SparseBeliefState< ValueType > const &rhs)
ValueType getRisk() const
Get the weighted risk.
SparseBeliefState(std::shared_ptr< BeliefStateManager< ValueType > > const &manager, uint64_t state)
This class represents a partially observable Markov decision process.
Definition Pomdp.h:13
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
bool operator==(SparseBeliefState< ValueType > const &lhs, SparseBeliefState< ValueType > const &rhs)
std::size_t operator()(storm::generator::SparseBeliefState< T > const &s) const noexcept