11namespace transformer {
13template<
typename ValueType>
18template<
typename ValueType>
20 bool keepStateValuations)
const {
21 auto data = transformTransitions(pomdp, transformSimple);
23 components.
stateLabeling = transformStateLabeling(pomdp, data);
33 result.
transformedPomdp = std::make_shared<storm::models::sparse::Pomdp<ValueType>>(std::move(components),
true);
54 std::vector<BinaryPomdpTransformerRowGroup>
split()
const {
57 std::vector<BinaryPomdpTransformerRowGroup> res;
61 res.back().auxStateId = newAuxStateId;
64 res.back().auxStateId = newAuxStateId;
79template<
typename ValueType>
80typename BinaryPomdpTransformer<ValueType>::TransformationData BinaryPomdpTransformer<ValueType>::transformTransitions(
85 std::queue<BinaryPomdpTransformerRowGroup> queue;
86 for (uint64_t state = 0; state < matrix.getRowGroupCount(); ++state) {
87 queue.emplace(state, matrix.getRowGroupIndices()[state], matrix.getRowGroupIndices()[state + 1], pomdp.
getObservation(state));
90 std::vector<uint32_t> newObservations;
91 std::map<BinaryPomdpTransformerRowGroup, uint32_t, BinaryPomdpTransformerRowGroupCompare> observationMap;
94 std::vector<uint64_t> origRowToSimpleRowMap(pomdp.
getNumberOfChoices(), std::numeric_limits<uint64_t>::max());
95 uint64_t currAuxState = queue.size();
96 std::vector<uint64_t> origStates;
98 while (!queue.empty()) {
99 auto group = std::move(queue.front());
103 uint64_t newObservation = observationMap.insert(std::make_pair(group, observationMap.size())).first->second;
104 newObservations.push_back(newObservation);
107 builder.newRowGroup(currRow);
108 if (group.size() == 1) {
110 for (
auto const& entry : matrix.getRow(group.firstRow)) {
111 builder.addNextValue(currRow, entry.getColumn(), entry.getValue());
113 origRowToSimpleRowMap[group.firstRow] = currRow;
115 }
else if (group.size() > 1) {
117 for (
auto& splittedGroup : group.split()) {
119 if (splittedGroup.size() == 1 && (!transformSimple || matrix.getRow(splittedGroup.firstRow).getNumberOfEntries() < 2)) {
120 for (
auto const& entry : matrix.getRow(splittedGroup.firstRow)) {
121 builder.addNextValue(currRow, entry.getColumn(), entry.getValue());
123 origRowToSimpleRowMap[splittedGroup.firstRow] = currRow;
126 queue.push(std::move(splittedGroup));
127 builder.addNextValue(currRow, currAuxState, storm::utility::one<ValueType>());
134 origStates.push_back(group.origState);
137 TransformationData result;
138 result.simpleMatrix = builder.build(currRow, currAuxState, currAuxState);
139 result.simpleObservations = std::move(newObservations);
140 result.originalToSimpleChoiceMap = std::move(origRowToSimpleRowMap);
141 result.simpleStateToOriginalState = std::move(origStates);
145template<
typename ValueType>
147 TransformationData
const& data)
const {
149 for (
auto const& labelName : pomdp.getStateLabeling().getLabels()) {
151 newStates.
resize(data.simpleMatrix.getRowGroupCount(),
false);
152 if (labelName !=
"init") {
153 for (uint64_t newState = pomdp.
getNumberOfStates(); newState < data.simpleMatrix.getRowGroupCount(); ++newState) {
154 newStates.
set(newState, newStates[data.simpleStateToOriginalState[newState]]);
157 labeling.addLabel(labelName, std::move(newStates));
162template<
typename ValueType>
165 TransformationData
const& data)
const {
166 std::optional<std::vector<ValueType>> stateRewards, actionRewards;
169 stateRewards.value().resize(data.simpleMatrix.getRowGroupCount(), storm::utility::zero<ValueType>());
172 actionRewards = std::vector<ValueType>(data.simpleMatrix.getRowCount(), storm::utility::zero<ValueType>());
173 for (uint64_t pomdpChoice = 0; pomdpChoice < pomdp.
getNumberOfChoices(); ++pomdpChoice) {
174 STORM_LOG_ASSERT(data.originalToSimpleChoiceMap[pomdpChoice] < data.simpleMatrix.getRowCount(),
"Invalid entry in map for choice " << pomdpChoice);
175 actionRewards.value()[data.originalToSimpleChoiceMap[pomdpChoice]] = rewardModel.
getStateActionReward(pomdpChoice);
182template class BinaryPomdpTransformer<storm::RationalNumber>;
184template class BinaryPomdpTransformer<double>;
185template 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 set(uint64_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.
void resize(uint64_t newLength, bool init=false)
Resizes the bit vector to hold the given new number of bits.
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