Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MakeStateSetObservationClosed.cpp
Go to the documentation of this file.
2
4
5namespace storm {
6namespace transformer {
7
8template<typename ValueType>
10
11template<typename ValueType>
12std::pair<std::shared_ptr<storm::models::sparse::Pomdp<ValueType>>, std::set<uint32_t>> MakeStateSetObservationClosed<ValueType>::transform(
13 storm::storage::BitVector const& stateSet) const {
14 // Collect observations of target states
15 std::set<uint32_t> oldObservations;
16 for (auto const state : stateSet) {
17 oldObservations.insert(pomdp->getObservation(state));
18 }
19
20 // Collect observations that belong to both, target states and non-target states.
21 // Add a fresh observation for each of them
22 std::map<uint32_t, uint32_t> oldToNewObservationMap;
23 uint32_t freshObs = pomdp->getNrObservations();
24 for (uint64_t state = stateSet.getNextUnsetIndex(0); state < stateSet.size(); state = stateSet.getNextUnsetIndex(state + 1)) {
25 uint32_t obs = pomdp->getObservation(state);
26 if (oldObservations.count(obs) > 0) {
27 // this observation belongs to both, target and non-target states.
28 if (oldToNewObservationMap.emplace(obs, freshObs).second) {
29 // We actually inserted something, i.e., we have not seen this observation before.
30 // For the next observation (that is different from obs) we want to insert another fresh observation index
31 // This is to preserve the assumption that states with the same observation have the same enabled actions.
32 ++freshObs;
33 }
34 }
35 }
36
37 // Check whether the state set already is observation closed.
38 if (oldToNewObservationMap.empty()) {
39 return {pomdp, std::move(oldObservations)};
40 } else {
41 // Create new observations
42 auto newObservationVector = pomdp->getObservations();
43 for (auto const state : stateSet) {
44 auto findRes = oldToNewObservationMap.find(pomdp->getObservation(state));
45 if (findRes != oldToNewObservationMap.end()) {
46 newObservationVector[state] = findRes->second;
47 }
48 }
49 // Create a copy of the pomdp and change observations accordingly.
50 // This transformation preserves canonicity.
51 auto transformed = std::make_shared<storm::models::sparse::Pomdp<ValueType>>(*pomdp);
52 transformed->updateObservations(std::move(newObservationVector), true);
53
54 // Finally, get the new set of target observations
55 std::set<uint32_t> newObservations;
56 for (auto const& obs : oldObservations) {
57 auto findRes = oldToNewObservationMap.find(obs);
58 if (findRes == oldToNewObservationMap.end()) {
59 newObservations.insert(obs);
60 } else {
61 newObservations.insert(findRes->second);
62 }
63 }
64
65 return {transformed, std::move(newObservations)};
66 }
67}
68
71} // namespace transformer
72} // namespace storm
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
uint64_t getNextUnsetIndex(uint64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to false in the bit vector.
size_t size() const
Retrieves the number of bits this bit vector can store.
std::pair< std::shared_ptr< storm::models::sparse::Pomdp< ValueType > >, std::set< uint32_t > > transform(storm::storage::BitVector const &stateSet) const
Ensures that the given set of states is observation closed, potentially, adding new observation(s) A ...
MakeStateSetObservationClosed(std::shared_ptr< storm::models::sparse::Pomdp< ValueType > > pomdp)