10namespace transformer {
12template<
typename ValueType>
17template<
typename ValueType>
19 bool keepStateValuations)
const {
20 auto data = transformTransitions(pomdp, transformSimple);
22 components.
stateLabeling = transformStateLabeling(pomdp, data);
32 result.
transformedPomdp = std::make_shared<storm::models::sparse::Pomdp<ValueType>>(std::move(components),
true);
53 std::vector<BinaryPomdpTransformerRowGroup>
split()
const {
56 std::vector<BinaryPomdpTransformerRowGroup> res;
60 res.back().auxStateId = newAuxStateId;
63 res.back().auxStateId = newAuxStateId;
78template<
typename ValueType>
79typename BinaryPomdpTransformer<ValueType>::TransformationData BinaryPomdpTransformer<ValueType>::transformTransitions(
84 std::queue<BinaryPomdpTransformerRowGroup> queue;
85 for (uint64_t state = 0; state < matrix.getRowGroupCount(); ++state) {
86 queue.emplace(state, matrix.getRowGroupIndices()[state], matrix.getRowGroupIndices()[state + 1], pomdp.
getObservation(state));
89 std::vector<uint32_t> newObservations;
90 std::map<BinaryPomdpTransformerRowGroup, uint32_t, BinaryPomdpTransformerRowGroupCompare> observationMap;
93 std::vector<uint64_t> origRowToSimpleRowMap(pomdp.
getNumberOfChoices(), std::numeric_limits<uint64_t>::max());
94 uint64_t currAuxState = queue.size();
95 std::vector<uint64_t> origStates;
97 while (!queue.empty()) {
98 auto group = std::move(queue.front());
102 uint64_t newObservation = observationMap.insert(std::make_pair(group, observationMap.size())).first->second;
103 newObservations.push_back(newObservation);
106 builder.newRowGroup(currRow);
107 if (group.size() == 1) {
109 for (
auto const& entry : matrix.getRow(group.firstRow)) {
110 builder.addNextValue(currRow, entry.getColumn(), entry.getValue());
112 origRowToSimpleRowMap[group.firstRow] = currRow;
114 }
else if (group.size() > 1) {
116 for (
auto& splittedGroup : group.split()) {
118 if (splittedGroup.size() == 1 && (!transformSimple || matrix.getRow(splittedGroup.firstRow).getNumberOfEntries() < 2)) {
119 for (
auto const& entry : matrix.getRow(splittedGroup.firstRow)) {
120 builder.addNextValue(currRow, entry.getColumn(), entry.getValue());
122 origRowToSimpleRowMap[splittedGroup.firstRow] = currRow;
125 queue.push(std::move(splittedGroup));
126 builder.addNextValue(currRow, currAuxState, storm::utility::one<ValueType>());
133 origStates.push_back(group.origState);
136 TransformationData result;
137 result.simpleMatrix = builder.build(currRow, currAuxState, currAuxState);
138 result.simpleObservations = std::move(newObservations);
139 result.originalToSimpleChoiceMap = std::move(origRowToSimpleRowMap);
140 result.simpleStateToOriginalState = std::move(origStates);
144template<
typename ValueType>
146 TransformationData
const& data)
const {
148 for (
auto const& labelName : pomdp.getStateLabeling().getLabels()) {
150 newStates.
resize(data.simpleMatrix.getRowGroupCount(),
false);
151 if (labelName !=
"init") {
152 for (uint64_t newState = pomdp.
getNumberOfStates(); newState < data.simpleMatrix.getRowGroupCount(); ++newState) {
153 newStates.
set(newState, newStates[data.simpleStateToOriginalState[newState]]);
156 labeling.addLabel(labelName, std::move(newStates));
161template<
typename ValueType>
164 TransformationData
const& data)
const {
165 std::optional<std::vector<ValueType>> stateRewards, actionRewards;
168 stateRewards.value().resize(data.simpleMatrix.getRowGroupCount(), storm::utility::zero<ValueType>());
171 actionRewards = std::vector<ValueType>(data.simpleMatrix.getRowCount(), storm::utility::zero<ValueType>());
172 for (uint64_t pomdpChoice = 0; pomdpChoice < pomdp.
getNumberOfChoices(); ++pomdpChoice) {
173 STORM_LOG_ASSERT(data.originalToSimpleChoiceMap[pomdpChoice] < data.simpleMatrix.getRowCount(),
"Invalid entry in map for choice " << pomdpChoice);
174 actionRewards.value()[data.originalToSimpleChoiceMap[pomdpChoice]] = rewardModel.
getStateActionReward(pomdpChoice);
181template class BinaryPomdpTransformer<storm::RationalNumber>;
183template class BinaryPomdpTransformer<double>;
184template class BinaryPomdpTransformer<storm::RationalFunction>;
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
bool hasStateValuations() const
Retrieves whether this model was build with state valuations.
storm::storage::sparse::StateValuations const & getStateValuations() const
Retrieves the valuations of the states of the model.
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
uint_fast64_t getNumberOfChoices(uint_fast64_t state) const
This class represents a partially observable Markov decision process.
uint32_t getObservation(uint64_t state) const
bool hasTransitionRewards() const
Retrieves whether the reward model has transition rewards.
std::vector< ValueType > const & getStateRewardVector() const
Retrieves the state rewards of the reward model.
ValueType const & getStateActionReward(uint_fast64_t choiceIndex) const
Retrieves the state-action reward for the given choice.
bool hasStateRewards() const
Retrieves whether the reward model has state rewards.
bool hasStateActionRewards() const
Retrieves whether the reward model has state-action rewards.
This class manages the labeling of the state space with a number of (atomic) labels.
storm::storage::BitVector const & getStates(std::string const &label) const
Returns the labeling of states associated with the given label.
A bit vector that is internally represented as a vector of 64-bit values.
void resize(uint_fast64_t newLength, bool init=false)
Resizes the bit vector to hold the given new number of bits.
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
size_t size() const
Retrieves the number of bits this bit vector can store.
A class that can be used to build a sparse matrix by adding value by value.
StateValuations blowup(std::vector< uint64_t > const &mapNewToOld) const
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
std::optional< storm::storage::sparse::StateValuations > stateValuations
std::unordered_map< std::string, RewardModelType > rewardModels
storm::storage::SparseMatrix< ValueType > transitionMatrix
storm::models::sparse::StateLabeling stateLabeling
std::optional< std::vector< uint32_t > > observabilityClasses