Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BeliefMdpBuilder.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <unordered_map>
5#include <utility>
6#include <vector>
7
9
16
19
20namespace storm::pomdp::beliefs {
21
22std::shared_ptr<storm::logic::Formula const> createFormulaForBeliefMdp(PropertyInformation const& propertyInformation) {
26 "Unexpected kind of property.");
27 switch (propertyInformation.kind) {
29 auto target = std::make_shared<storm::logic::AtomicLabelFormula const>("target");
30 auto eventuallyTarget = std::make_shared<storm::logic::EventuallyFormula const>(target, storm::logic::FormulaContext::Probability);
31 return std::make_shared<storm::logic::ProbabilityOperatorFormula const>(eventuallyTarget,
32 storm::logic::OperatorInformation(propertyInformation.dir));
33 }
35 auto bottom = std::make_shared<storm::logic::AtomicLabelFormula const>("target");
36 auto eventuallyBottom = std::make_shared<storm::logic::EventuallyFormula const>(bottom, storm::logic::FormulaContext::Reward,
37 storm::logic::RewardAccumulation(true, false, false));
38 return std::make_shared<storm::logic::RewardOperatorFormula const>(eventuallyBottom, propertyInformation.rewardModelName.value(),
39 storm::logic::OperatorInformation(propertyInformation.dir));
40 }
42 auto target = std::make_shared<storm::logic::AtomicLabelFormula const>("target");
43 auto trueFormula = std::make_shared<storm::logic::BooleanLiteralFormula const>(true);
44
45 std::vector<std::optional<logic::TimeBound>> lowerBounds;
46 std::vector<std::optional<logic::TimeBound>> upperBounds;
47 std::vector<logic::TimeBoundReference> timeBoundReferences;
48
49 for (auto const& rewardBound : propertyInformation.rewardBounds) {
50 if (rewardBound.rewardModelName.empty()) {
51 timeBoundReferences.emplace_back();
52 } else {
53 timeBoundReferences.emplace_back(rewardBound.rewardModelName);
54 }
55 if (rewardBound.lowerBound.has_value()) {
56 lowerBounds.emplace_back(rewardBound.lowerBound.value());
57 } else {
58 lowerBounds.emplace_back(std::nullopt);
59 }
60 if (rewardBound.upperBound.has_value()) {
61 upperBounds.emplace_back(rewardBound.upperBound.value());
62 } else {
63 upperBounds.emplace_back(std::nullopt);
64 }
65 }
66 auto eventuallyTarget =
67 std::make_shared<storm::logic::BoundedUntilFormula const>(trueFormula, target, lowerBounds, upperBounds, timeBoundReferences);
68 return std::make_shared<storm::logic::ProbabilityOperatorFormula const>(eventuallyTarget,
69 storm::logic::OperatorInformation(propertyInformation.dir));
70 }
71 }
72 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Unhandled case.");
73}
74
75template<typename MatrixType>
76bool hasUniqueTransitionRewardsInChoice(MatrixType const& matrix, uint64_t choice, uint64_t numRewardModels) {
77 std::unordered_map<BeliefId, bool> targetHasReward;
78 for (auto i = matrix.rowIndications[choice]; i < matrix.rowIndications[choice + 1]; ++i) {
79 auto const& entry = matrix.transitions[i];
80 bool hasReward = false;
81 for (uint64_t rewardIndex = 0; rewardIndex < numRewardModels; ++rewardIndex) {
82 if (!storm::utility::isZero(entry.data[rewardIndex])) {
83 hasReward = true;
84 break;
85 }
86 }
87 auto [it, inserted] = targetHasReward.emplace(entry.targetBelief, hasReward);
88 if (!inserted && (hasReward || it->second)) {
89 return false;
90 }
91 }
92 return true;
93}
94
95template<typename BeliefMdpValueType, typename BeliefType, typename... ExtraTransitionData>
96std::pair<std::shared_ptr<models::sparse::Mdp<BeliefMdpValueType>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
98 PropertyInformation const& propertyInformation,
99 std::function<std::unordered_map<std::string, BeliefMdpValueType>(BeliefType const&)> const& computeCutOffValueMap) {
100 bool const isReachProb = propertyInformation.kind == PropertyInformation::Kind::ReachabilityProbability;
101 bool const isTotRew = propertyInformation.kind == PropertyInformation::Kind::ExpectedTotalReachabilityReward;
102 bool const isRewBndReachProb = propertyInformation.kind == PropertyInformation::Kind::RewardBoundedReachabilityProbability;
103 STORM_LOG_ASSERT(isReachProb || isTotRew || isRewBndReachProb, "Unexpected kind of property.");
104
105 bool constexpr extraDataCompatibleWithRewardAwareness =
106 sizeof...(ExtraTransitionData) == 1 && (std::is_same_v<std::vector<BeliefMdpValueType>, ExtraTransitionData> || ...);
107
108 // A rewarding cut-off loop may leave a two-sided interval before all dimensions satisfy their bounds.
109 // TODO: Support two-sided Pmin bounds by splitting each such dimension into lower-only and upper-only copies with distinct
110 // internal reward-model names. Keep identical original rewards in both copies on ordinary transitions. On the successful
111 // cut-off transition to the target, add enough reward only to lower-bound copies to satisfy all lower bounds immediately
112 // (including strict ones), and zero reward to upper-bound copies. This is an optimistic continuation: upper-bound violations
113 // incurred before the cut-off still fail. Splitting the formula bounds alone is insufficient because the copies need
114 // different cut-off rewards.
115 STORM_LOG_THROW(!(isRewBndReachProb && propertyInformation.dir == storm::OptimizationDirection::Minimize &&
116 std::any_of(propertyInformation.rewardBounds.begin(), propertyInformation.rewardBounds.end(),
117 [](RewardBound const& bound) { return bound.lowerBound.has_value() && bound.upperBound.has_value(); })),
118 storm::exceptions::NotSupportedException,
119 "Reward-bounded probability minimisation does not support dimensions with both lower and upper reward bounds.");
120 auto const frontierBeliefs = explorationInformation.getFrontierBeliefs();
121 bool const initialBeliefIsTerminal = explorationInformation.terminalBeliefValues.contains(explorationInformation.initialBeliefId);
122
123 // First gather all cut-off information
124 uint64_t nrCutOffChoices = 0ull;
125 std::unordered_map<BeliefId, std::unordered_map<std::string, BeliefMdpValueType>> cutOffInformationMap;
126 for (auto const& frontierBeliefId : frontierBeliefs) {
127 auto const& frontierBelief = explorationInformation.discoveredBeliefs.getBeliefFromId(frontierBeliefId);
128 cutOffInformationMap[frontierBeliefId] = computeCutOffValueMap(frontierBelief);
129 nrCutOffChoices += cutOffInformationMap[frontierBeliefId].size();
130 }
131
132 constexpr bool clippingUsed = std::is_same_v<ExplorationInformation<BeliefMdpValueType, BeliefType, ExtraTransitionData...>,
134
135 // Reachability probabilities and reward-bounded cut-offs get dedicated target and bottom states.
136 // The target state used for reward-bounded cut-offs is distinct from ordinary target beliefs, which are not terminal
137 // (e.g. because of lower reward bounds).
138 uint64_t const numBottomTargetStates = isReachProb || isRewBndReachProb || clippingUsed ? 2ull : 1ull;
139 uint64_t const numInitialTerminalStates = initialBeliefIsTerminal ? 1ull : 0ull;
140 uint64_t const numExtraStates = numBottomTargetStates + frontierBeliefs.size() + numInitialTerminalStates;
141 uint64_t const numStates = explorationInformation.matrix.groups() + numExtraStates;
142 uint64_t const numChoices = explorationInformation.matrix.rows() + numBottomTargetStates + nrCutOffChoices + numInitialTerminalStates;
143 uint64_t const targetState = numStates - numBottomTargetStates;
144 uint64_t const bottomState = numStates - 1;
145 std::optional<models::sparse::ChoiceLabeling> optionalChoiceLabeling;
146 // Even if no belief actions were explored (the initial belief is terminal or exploration stopped before expanding it),
147 // generated cut-off actions and sink self-loops still need choice labels when requested.
148 if (explorationInformation.generateChoiceLabeling || explorationInformation.matrix.hasChoiceLabels()) {
149 optionalChoiceLabeling = models::sparse::ChoiceLabeling(numChoices);
150 }
151
152 std::vector<BeliefMdpValueType> actionRewards;
153 if (isTotRew) {
154 actionRewards.reserve(numChoices);
155 actionRewards.insert(actionRewards.end(), explorationInformation.actionRewards.begin(), explorationInformation.actionRewards.end());
156 // Insert 0 for all cut-off choices, an optional initial terminal state, and bottom/target states.
157 actionRewards.insert(actionRewards.end(), nrCutOffChoices + numInitialTerminalStates + numBottomTargetStates,
159 STORM_LOG_ASSERT(numChoices == actionRewards.size(),
160 "Unexpected size of action rewards: Expected " << numChoices << " got " << actionRewards.size() << ".");
161 }
162
163 std::unordered_map<BeliefId, uint64_t> frontierBeliefToStateMap;
164 std::unordered_map<uint64_t, BeliefId> stateToFrontierBeliefMap;
165 uint64_t nextStateId = numStates - numExtraStates;
166 std::optional<uint64_t> initialTerminalState;
167 if (initialBeliefIsTerminal) {
168 initialTerminalState = nextStateId++;
169 }
170 for (auto const& frontierBeliefId : frontierBeliefs) {
171 frontierBeliefToStateMap.emplace(frontierBeliefId, nextStateId);
172 stateToFrontierBeliefMap.emplace(nextStateId, frontierBeliefId);
173 ++nextStateId;
174 }
175 STORM_LOG_ASSERT(nextStateId == targetState, "Unexpected state layout.");
176
177 std::vector<storm::storage::SparseMatrixBuilder<BeliefMdpValueType>> transitionRewardBuilderVector;
178
179 if constexpr (extraDataCompatibleWithRewardAwareness) {
180 if (isRewBndReachProb) {
181 for (uint64_t i = 0; i < propertyInformation.rewardBounds.size(); ++i) {
182 transitionRewardBuilderVector.emplace_back(numChoices, numStates, 0, true, true, numStates);
183 }
184 }
185 }
186
187 storm::storage::SparseMatrixBuilder<BeliefMdpValueType> transitionBuilder(numChoices, numStates, 0, true, true, numStates);
188 // Keep source indices so probabilities and reward vectors share the same successor ordering without copying the data.
189 std::vector<std::pair<uint64_t, uint64_t>> rowSuccessors;
190 // Treat explored beliefs
191 for (uint64_t state = 0; state < numStates - numExtraStates; ++state) {
192 uint64_t choice = explorationInformation.matrix.rowGroupIndices[state];
193 transitionBuilder.newRowGroup(choice);
194 for (auto& transitionRewardBuilder : transitionRewardBuilderVector) {
195 transitionRewardBuilder.newRowGroup(choice);
196 }
197 for (uint64_t const groupEnd = explorationInformation.matrix.rowGroupIndices[state + 1]; choice < groupEnd; ++choice) {
198 if constexpr (extraDataCompatibleWithRewardAwareness) {
200 !isRewBndReachProb || hasUniqueTransitionRewardsInChoice(explorationInformation.matrix, choice, propertyInformation.rewardBounds.size()),
201 "Duplicate transition reward in choice " << choice << ".");
202 }
203 auto probabilityToBottom = storm::utility::zero<BeliefMdpValueType>();
204 auto probabilityToTarget = storm::utility::zero<BeliefMdpValueType>();
205 rowSuccessors.clear();
206 for (uint64_t entryIndex = explorationInformation.matrix.rowIndications[choice];
207 entryIndex < explorationInformation.matrix.rowIndications[choice + 1]; ++entryIndex) {
208 auto const& entry = explorationInformation.matrix.transitions[entryIndex];
209 if (auto explIt = explorationInformation.exploredBeliefs.find(entry.targetBelief); explIt != explorationInformation.exploredBeliefs.end()) {
210 // Transition to explored belief
211 rowSuccessors.emplace_back(explIt->second, entryIndex);
212 } else {
213 // Transition to unexplored belief (either terminal or cut-off)
214 BeliefMdpValueType successorValue;
215 // Reward-aware exploration never inserts terminal beliefs: whether a target observation satisfies a
216 // reward bound depends on the transition reward. Those beliefs stay explored or on the frontier.
217 if (auto terminalIt = explorationInformation.terminalBeliefValues.find(entry.targetBelief);
218 // Transition to terminal belief
219 terminalIt != explorationInformation.terminalBeliefValues.end()) {
220 successorValue = entry.probability * terminalIt->second; // terminal value determined during exploration
221 if (isReachProb) {
222 probabilityToTarget += successorValue;
223 probabilityToBottom += entry.probability - successorValue;
224 } else {
225 STORM_LOG_THROW(isTotRew, storm::exceptions::UnexpectedException,
226 "Terminal reward accumulation requires an expected total reachability reward property.");
227 probabilityToTarget += entry.probability;
228 actionRewards[choice] += successorValue;
229 }
230 } else {
231 // Transition to frontier belief
232 auto const frontierIt = frontierBeliefToStateMap.find(entry.targetBelief);
233 STORM_LOG_ASSERT(frontierIt != frontierBeliefToStateMap.end(), "Unknown frontier belief.");
234 rowSuccessors.emplace_back(frontierIt->second, entryIndex);
235 }
236 }
237 if constexpr (clippingUsed) {
238 // Apply clipping metadata regardless of whether the successor is explored, terminal, or on the frontier.
239 auto const& clippingProbability = std::get<0>(entry.data);
240 auto const& rewardPenalty = std::get<1>(entry.data);
241
242 if (clippingProbability) {
243 if (isReachProb) {
244 if (storm::solver::minimize(propertyInformation.dir)) {
245 probabilityToTarget += *clippingProbability;
246 } else {
247 probabilityToBottom += *clippingProbability;
248 }
249 } else if (rewardPenalty) {
250 if (storm::utility::isInfinity(*rewardPenalty)) {
251 /* Infinite reward on transitions is not correctly handled by the model checker. Therefore, we treat it by adding a
252 * transition to the bottom state which due to the semantics of expected reward until reaching a target has infinite
253 * expected reward.This causes the expected reward for the transition to become infinite. */
254 probabilityToBottom += *clippingProbability;
255 } else {
256 actionRewards[choice] += *rewardPenalty;
257 probabilityToTarget += *clippingProbability;
258 }
259 } else {
260 probabilityToTarget += *clippingProbability;
261 }
262 }
263 }
264 }
265 // Sort each choice once by its final state IDs, preserving source order for duplicate successors.
266 if (!std::is_sorted(rowSuccessors.begin(), rowSuccessors.end())) {
267 std::sort(rowSuccessors.begin(), rowSuccessors.end());
268 }
269 for (auto const& [successorState, entryIndex] : rowSuccessors) {
270 auto const& entry = explorationInformation.matrix.transitions[entryIndex];
271 transitionBuilder.addNextValue(choice, successorState, entry.probability);
272 if constexpr (extraDataCompatibleWithRewardAwareness) {
273 if (isRewBndReachProb) {
274 for (uint64_t i = 0; i < propertyInformation.rewardBounds.size(); ++i) {
275 if (!storm::utility::isZero(entry.data[i])) {
276 transitionRewardBuilderVector.at(i).addNextValue(choice, successorState, entry.data[i]);
277 }
278 }
279 }
280 }
281 }
282 // Sink state IDs follow all ordinary successors, so these insertions remain ordered.
283 if (!storm::utility::isZero(probabilityToTarget)) {
284 transitionBuilder.addNextValue(choice, targetState, probabilityToTarget);
285 }
286 if (!storm::utility::isZero(probabilityToBottom)) {
287 transitionBuilder.addNextValue(choice, bottomState, probabilityToBottom);
288 }
289 if (optionalChoiceLabeling.has_value()) {
290 for (auto const& label : explorationInformation.matrix.choiceLabels.at(choice)) {
291 if (!optionalChoiceLabeling.value().containsLabel(label)) {
292 optionalChoiceLabeling.value().addLabel(label);
293 }
294 optionalChoiceLabeling.value().addLabelToChoice(label, choice);
295 }
296 }
297 }
298 }
299 // Treat frontier beliefs
300 uint64_t choice = explorationInformation.matrix.rows();
301 uint64_t const firstFrontierState = numStates - numExtraStates + numInitialTerminalStates;
302 for (uint64_t state = firstFrontierState; state < numStates - numBottomTargetStates; ++state) {
303 transitionBuilder.newRowGroup(choice);
304 for (auto& transitionRewardBuilder : transitionRewardBuilderVector) {
305 transitionRewardBuilder.newRowGroup(choice);
306 }
307 std::unordered_map<std::string, BeliefMdpValueType> cutOffInformationForBelief = cutOffInformationMap.at(stateToFrontierBeliefMap.at(state));
308 for (auto const& entry : cutOffInformationForBelief) {
309 if (isReachProb || isRewBndReachProb) {
310 if (!storm::utility::isZero(entry.second)) {
311 transitionBuilder.addNextValue(choice, targetState, entry.second);
312 }
313 BeliefMdpValueType const probabilityToBottom = storm::utility::one<BeliefMdpValueType>() - entry.second;
314 if (!storm::utility::isZero(probabilityToBottom)) {
315 transitionBuilder.addNextValue(choice, bottomState, probabilityToBottom);
316 }
317 } else {
318 transitionBuilder.addNextValue(choice, targetState, storm::utility::one<BeliefMdpValueType>());
319 if (isTotRew) {
320 actionRewards[choice] += entry.second;
321 }
322 }
323 if (optionalChoiceLabeling.has_value()) {
324 if (!optionalChoiceLabeling.value().containsLabel(entry.first)) {
325 optionalChoiceLabeling.value().addLabel(entry.first);
326 }
327 optionalChoiceLabeling.value().addLabelToChoice(entry.first, choice);
328 }
329 ++choice;
330 }
331 }
332 if (initialTerminalState.has_value()) {
333 transitionBuilder.newRowGroup(choice);
334 BeliefMdpValueType const terminalValue = explorationInformation.terminalBeliefValues.at(explorationInformation.initialBeliefId);
335 if (isReachProb) {
336 if (!storm::utility::isZero(terminalValue)) {
337 transitionBuilder.addNextValue(choice, targetState, terminalValue);
338 }
339 BeliefMdpValueType const probabilityToBottom = storm::utility::one<BeliefMdpValueType>() - terminalValue;
340 if (!storm::utility::isZero(probabilityToBottom)) {
341 transitionBuilder.addNextValue(choice, bottomState, probabilityToBottom);
342 }
343 } else {
344 STORM_LOG_ASSERT(isTotRew, "Unexpected terminal initial belief for this property type.");
345 transitionBuilder.addNextValue(choice, targetState, storm::utility::one<BeliefMdpValueType>());
346 actionRewards[choice] += terminalValue;
347 }
348 ++choice;
349 }
350 STORM_LOG_ASSERT(choice == numChoices - numBottomTargetStates, "Unexpected choice layout.");
351
352 // Treat extra states
353 transitionBuilder.newRowGroup(numChoices - numBottomTargetStates);
354 if (optionalChoiceLabeling.has_value()) {
355 if (!optionalChoiceLabeling.value().containsLabel("__loop__")) {
356 optionalChoiceLabeling.value().addLabel("__loop__");
357 }
358 optionalChoiceLabeling.value().addLabelToChoice("__loop__", numChoices - numBottomTargetStates);
359 }
360 transitionBuilder.addNextValue(numChoices - numBottomTargetStates, targetState, storm::utility::one<BeliefMdpValueType>());
361 for (uint64_t i = 0; i < transitionRewardBuilderVector.size(); ++i) {
362 auto& transitionRewardBuilder = transitionRewardBuilderVector[i];
363 transitionRewardBuilder.newRowGroup(numChoices - numBottomTargetStates);
364 // Optimistic Pmin cut-offs must eventually satisfy every lower bound without consuming upper-only budgets.
365 if (propertyInformation.dir == storm::OptimizationDirection::Minimize && propertyInformation.rewardBounds[i].lowerBound.has_value()) {
366 transitionRewardBuilder.addNextValue(numChoices - numBottomTargetStates, targetState, storm::utility::one<BeliefMdpValueType>());
367 }
368 }
369 if (isReachProb || isRewBndReachProb || clippingUsed) {
370 transitionBuilder.newRowGroup(numChoices - 1);
371 transitionBuilder.addNextValue(numChoices - 1, bottomState, storm::utility::one<BeliefMdpValueType>());
372 for (auto& transitionRewardBuilder : transitionRewardBuilderVector) {
373 transitionRewardBuilder.newRowGroup(numChoices - 1);
374 }
375 if (optionalChoiceLabeling.has_value()) {
376 if (!optionalChoiceLabeling.value().containsLabel("__loop__")) {
377 optionalChoiceLabeling.value().addLabel("__loop__");
378 }
379 optionalChoiceLabeling.value().addLabelToChoice("__loop__", numChoices - 1);
380 }
381 }
382
383 storm::models::sparse::StateLabeling stateLabeling(numStates);
384 stateLabeling.addLabel("target");
385 if (isRewBndReachProb) {
386 stateLabeling.addLabelToState("target", targetState);
387 // A belief observation may encode an action observation as actionObservation * nrObservationsInPomdp + pomdpObservation.
388 // The modulo recovers the current POMDP observation ID, which is also the ID stored in targetObservations.
389 // After reward-aware transformation, that ID identifies a (target observation, reward vector) pair.
390 for (auto const& [belId, state] : explorationInformation.exploredBeliefs) {
391 if (propertyInformation.targetObservations.contains(explorationInformation.discoveredBeliefs.getBeliefFromId(belId).observation() %
392 explorationInformation.nrObservationsInPomdp)) {
393 stateLabeling.addLabelToState("target", state);
394 }
395 }
396 for (auto const& belId : frontierBeliefs) {
397 if (propertyInformation.targetObservations.contains(explorationInformation.discoveredBeliefs.getBeliefFromId(belId).observation() %
398 explorationInformation.nrObservationsInPomdp)) {
399 stateLabeling.addLabelToState("target", frontierBeliefToStateMap.at(belId));
400 }
401 }
402 } else {
403 stateLabeling.addLabelToState("target", targetState);
404 }
405 stateLabeling.addLabel("init");
406 if (auto const initialExploredIt = explorationInformation.exploredBeliefs.find(explorationInformation.initialBeliefId);
407 initialExploredIt != explorationInformation.exploredBeliefs.end()) {
408 stateLabeling.addLabelToState("init", initialExploredIt->second);
409 } else if (initialTerminalState.has_value()) {
410 stateLabeling.addLabelToState("init", initialTerminalState.value());
411 } else {
412 stateLabeling.addLabelToState("init", frontierBeliefToStateMap.at(explorationInformation.initialBeliefId));
413 }
414 stateLabeling.addLabel("truncated");
415 for (uint64_t state = firstFrontierState; state < numStates - numBottomTargetStates; ++state) {
416 stateLabeling.addLabelToState("truncated", state);
417 }
418
419 if (isReachProb || isRewBndReachProb || clippingUsed) {
420 stateLabeling.addLabel("bottom");
421 stateLabeling.addLabelToState("bottom", bottomState);
422 }
423 storm::storage::sparse::ModelComponents<BeliefMdpValueType> components(transitionBuilder.build(), std::move(stateLabeling));
424
425 if (isTotRew) {
426 storm::models::sparse::StandardRewardModel<BeliefMdpValueType> rewardModel(std::nullopt, std::move(actionRewards));
427 components.rewardModels.emplace(propertyInformation.rewardModelName.value(), std::move(rewardModel));
428 } else if (isRewBndReachProb) {
429 uint64_t i = 0ul;
430 for (auto& transitionRewardBuilder : transitionRewardBuilderVector) {
431 storm::models::sparse::StandardRewardModel<BeliefMdpValueType> rewardModel(std::nullopt, std::nullopt, transitionRewardBuilder.build());
432 components.rewardModels.emplace(propertyInformation.rewardBounds.at(i).rewardModelName, std::move(rewardModel));
433 ++i;
434 }
435 }
436 if (optionalChoiceLabeling.has_value()) {
437 components.choiceLabeling = optionalChoiceLabeling.value();
438 }
439
440 // If requested, populate the stateToBeliefMap for the generic buildBeliefMdp variant
441 std::unordered_map<uint64_t, BeliefId> stateToBeliefMap;
442 // Explored beliefs
443 for (auto const& [beliefId, stateIndex] : explorationInformation.exploredBeliefs) {
444 stateToBeliefMap[stateIndex] = beliefId;
445 }
446 // Frontier beliefs: mapping was built as stateToFrontierBeliefMap
447 for (auto const& [stateIndex, beliefId] : stateToFrontierBeliefMap) {
448 stateToBeliefMap[stateIndex] = beliefId;
449 }
450 if (initialTerminalState.has_value()) {
451 stateToBeliefMap[initialTerminalState.value()] = explorationInformation.initialBeliefId;
452 }
453
454 return std::make_pair(std::make_shared<storm::models::sparse::Mdp<BeliefMdpValueType>>(std::move(components)), std::move(stateToBeliefMap));
455}
456
457template std::pair<std::shared_ptr<models::sparse::Mdp<double>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
458 ExplorationInformation<double, Belief<double>> const& explorationInformation, PropertyInformation const& propertyInformation,
459 std::function<std::unordered_map<std::string, double>(Belief<double> const&)> const& computeCutOffValueMap);
460
461template std::pair<std::shared_ptr<models::sparse::Mdp<storm::RationalNumber>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
462 ExplorationInformation<storm::RationalNumber, Belief<double>> const& explorationInformation, PropertyInformation const& propertyInformation,
463 std::function<std::unordered_map<std::string, storm::RationalNumber>(Belief<double> const&)> const& computeCutOffValueMap);
464
465template std::pair<std::shared_ptr<models::sparse::Mdp<double>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
466 ExplorationInformation<double, Belief<storm::RationalNumber>> const& explorationInformation, PropertyInformation const& propertyInformation,
467 std::function<std::unordered_map<std::string, double>(Belief<storm::RationalNumber> const&)> const& computeCutOffValueMap);
468
469template std::pair<std::shared_ptr<models::sparse::Mdp<storm::RationalNumber>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
470 ExplorationInformation<storm::RationalNumber, Belief<storm::RationalNumber>> const& explorationInformation, PropertyInformation const& propertyInformation,
471 std::function<std::unordered_map<std::string, storm::RationalNumber>(Belief<storm::RationalNumber> const&)> const& computeCutOffValueMap);
472
473template std::pair<std::shared_ptr<models::sparse::Mdp<double>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
474 ClippingExplorationInformation<double, Belief<double>> const& explorationInformation, PropertyInformation const& propertyInformation,
475 std::function<std::unordered_map<std::string, double>(Belief<double> const&)> const& computeCutOffValueMap);
476
477template std::pair<std::shared_ptr<models::sparse::Mdp<storm::RationalNumber>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
478 ClippingExplorationInformation<storm::RationalNumber, Belief<double>> const& explorationInformation, PropertyInformation const& propertyInformation,
479 std::function<std::unordered_map<std::string, storm::RationalNumber>(Belief<double> const&)> const& computeCutOffValueMap);
480
481template std::pair<std::shared_ptr<models::sparse::Mdp<double>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
482 ClippingExplorationInformation<double, Belief<storm::RationalNumber>> const& explorationInformation, PropertyInformation const& propertyInformation,
483 std::function<std::unordered_map<std::string, double>(Belief<storm::RationalNumber> const&)> const& computeCutOffValueMap);
484
485template std::pair<std::shared_ptr<models::sparse::Mdp<storm::RationalNumber>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
486 ClippingExplorationInformation<storm::RationalNumber, Belief<storm::RationalNumber>> const& explorationInformation,
487 PropertyInformation const& propertyInformation,
488 std::function<std::unordered_map<std::string, storm::RationalNumber>(Belief<storm::RationalNumber> const&)> const& computeCutOffValueMap);
489
490template std::pair<std::shared_ptr<models::sparse::Mdp<double>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
491 RewardAwareExplorationInformation<double, Belief<double>> const& explorationInformation, PropertyInformation const& propertyInformation,
492 std::function<std::unordered_map<std::string, double>(Belief<double> const&)> const& computeCutOffValueMap);
493
494template std::pair<std::shared_ptr<models::sparse::Mdp<storm::RationalNumber>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
495 RewardAwareExplorationInformation<storm::RationalNumber, Belief<double>> const& explorationInformation, PropertyInformation const& propertyInformation,
496 std::function<std::unordered_map<std::string, storm::RationalNumber>(Belief<double> const&)> const& computeCutOffValueMap);
497
498template std::pair<std::shared_ptr<models::sparse::Mdp<double>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
499 RewardAwareExplorationInformation<double, Belief<storm::RationalNumber>> const& explorationInformation, PropertyInformation const& propertyInformation,
500 std::function<std::unordered_map<std::string, double>(Belief<storm::RationalNumber> const&)> const& computeCutOffValueMap);
501
502template std::pair<std::shared_ptr<models::sparse::Mdp<storm::RationalNumber>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdp(
503 RewardAwareExplorationInformation<storm::RationalNumber, Belief<storm::RationalNumber>> const& explorationInformation,
504 PropertyInformation const& propertyInformation,
505 std::function<std::unordered_map<std::string, storm::RationalNumber>(Belief<storm::RationalNumber> const&)> const& computeCutOffValueMap);
506} // namespace storm::pomdp::beliefs
This class manages the labeling of the choice space with a number of (atomic) labels.
void addLabel(std::string const &label)
Adds a new label to the labelings.
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:16
This class manages the labeling of the state space with a number of (atomic) labels.
void addLabelToState(std::string const &label, storm::storage::sparse::state_type state)
Adds a label to a given state.
std::vector< uint64_t > rowIndications
Start indices of action rows in transitions.
std::vector< BeliefExplorationTransition< ValueType, ExtraTransitionData... > > transitions
Successor entries, grouped by rowIndications.
std::vector< uint64_t > rowGroupIndices
Start indices of belief row groups in the action rows.
std::vector< std::set< std::string > > choiceLabels
Optional labels for the action rows.
Represents a belief of a Pomdp, i.e.
Definition Belief.h:21
A class that can be used to build a sparse matrix by adding value by value.
void addNextValue(index_type row, index_type column, value_type const &value)
Sets the matrix entry at the given row and column to the given value.
void newRowGroup(index_type startingRow)
Starts a new row group in the matrix.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
bool hasUniqueTransitionRewardsInChoice(MatrixType const &matrix, uint64_t choice, uint64_t numRewardModels)
std::shared_ptr< storm::logic::Formula const > createFormulaForBeliefMdp(PropertyInformation const &propertyInformation)
ExplorationInformation< BeliefMdpValueType, BeliefType, std::optional< BeliefMdpValueType >, std::optional< BeliefMdpValueType > > ClippingExplorationInformation
Exploration information that stores optional clipping probability and reward-adjustment metadata.
std::pair< std::shared_ptr< models::sparse::Mdp< BeliefMdpValueType > >, std::unordered_map< uint64_t, BeliefId > > buildBeliefMdp(ExplorationInformation< BeliefMdpValueType, BeliefType, ExtraTransitionData... > const &explorationInformation, PropertyInformation const &propertyInformation, std::function< std::unordered_map< std::string, BeliefMdpValueType >(BeliefType const &)> const &computeCutOffValueMap)
Builds a belief MDP from the given exploration information and property information.
ExplorationInformation< BeliefMdpValueType, BeliefType, std::vector< BeliefMdpValueType > > RewardAwareExplorationInformation
Exploration information that stores a reward vector on each transition.
bool constexpr minimize(OptimizationDirection d)
bool isZero(ValueType const &a)
Definition constants.cpp:44
ValueType zero()
Definition constants.cpp:26
ValueType one()
Definition constants.cpp:21
bool isInfinity(ValueType const &a)
Mutable state of one belief-MDP exploration.
storm::pomdp::beliefs::BeliefCollector< BeliefType > discoveredBeliefs
std::vector< BeliefMdpValueType > actionRewards
BeliefExplorationMatrix< BeliefMdpValueType, ExtraTransitionData... > matrix
std::unordered_set< BeliefId > getFrontierBeliefs() const
std::unordered_map< BeliefId, BeliefStateType > exploredBeliefs
std::unordered_map< BeliefId, BeliefMdpValueType > terminalBeliefValues
Property data consumed by the belief MDP construction.
std::set< BeliefObservationType > targetObservations
One reward dimension of a reward-bounded reachability property.
std::unordered_map< std::string, RewardModelType > rewardModels
std::optional< storm::models::sparse::ChoiceLabeling > choiceLabeling