14template<
typename BeliefType>
17template<
typename BeliefMdpValueType,
typename PomdpType,
typename BeliefType>
20template<
typename BeliefMdpValueType,
typename PomdpType,
typename BeliefType>
28 void operator()(BeliefType&& bel,
typename BeliefType::ValueType&& val) {
29 auto const belId =
info.discoveredBeliefs.getIdOrAddBelief(std::move(bel));
30 if (
info.exploredBeliefs.count(belId) == 0u &&
info.terminalBeliefValues.count(belId) == 0u) {
31 info.queue.push(belId);
37template<
typename BeliefMdpValueType,
typename PomdpType,
typename BeliefType>
45 void operator()(BeliefType&& bel,
typename BeliefType::ValueType&& val, std::optional<typename BeliefType::ValueType> optionalWeightedClippingValue,
46 std::optional<typename BeliefType::ValueType> optionalRewardAdjustment) {
47 auto const belId =
info.discoveredBeliefs.getIdOrAddBelief(std::move(bel));
48 if (
info.exploredBeliefs.count(belId) == 0u &&
info.terminalBeliefValues.count(belId) == 0u) {
49 info.queue.push(belId);
51 if (optionalWeightedClippingValue) {
52 if (optionalRewardAdjustment) {
53 STORM_LOG_TRACE(
"Add transition to belief " << belId <<
" with val " << val <<
", weighted clipping value " << *optionalWeightedClippingValue
54 <<
" and reward adjustment " << *optionalRewardAdjustment <<
".");
68 void operator()(BeliefType&& bel,
typename BeliefType::ValueType&& val) {
69 auto const belId =
info.discoveredBeliefs.getIdOrAddBelief(std::move(bel));
70 if (
info.exploredBeliefs.count(belId) == 0u &&
info.terminalBeliefValues.count(belId) == 0u) {
71 info.queue.push(belId);
77template<
typename BeliefMdpValueType,
typename PomdpType,
typename BeliefType>
85 void operator()(BeliefType&& bel,
typename BeliefType::ValueType&& val, std::vector<BeliefMdpValueType>
const& rewards) {
86 auto const belId =
info.discoveredBeliefs.getIdOrAddBelief(std::move(bel));
87 if (
info.exploredBeliefs.count(belId) == 0u &&
info.terminalBeliefValues.count(belId) == 0u) {
88 info.queue.push(belId);
101template<
typename BeliefMdpValueType,
typename PomdpType,
typename BeliefType>
115 template<
typename InfoType>
118 info.queue.changeOrder(explorationQueueOrder);
119 info.initialBeliefId = info.discoveredBeliefs.addBelief(firstStateNextStateGenerator.computeInitialBelief());
120 info.queue.push(info.initialBeliefId);
121 info.nrObservationsInPomdp = nrObservationsInPomdp;
130 template<
typename AbstractionType>
135 firstStateNextStateGenerator.setRewardModel(rewardModelName.
value());
137 firstStateNextStateGenerator.unsetRewardModel();
141 performExploration(info, firstStateNextStateGenerator.getPostAbstractionHandle(abstraction.
value(), discoverCallback), terminalBeliefCallback,
142 terminationCallback);
144 performExploration(info, firstStateNextStateGenerator.getHandle(discoverCallback), terminalBeliefCallback, terminationCallback);
152 template<
typename AbstractionType>
157 firstStateNextStateGenerator.unsetRewardModel();
160 performExploration(info, firstStateNextStateGenerator.getPrePostAbstractionHandle(rewardSplitter, abstraction.
value(), discoverCallback),
161 terminalBeliefCallback, terminationCallback);
163 performExploration(info, firstStateNextStateGenerator.getPreAbstractionHandle(rewardSplitter, discoverCallback), terminalBeliefCallback,
164 terminationCallback);
171 template<
typename AbstractionType>
176 firstStateNextStateGenerator.setRewardModel(rewardModelName.
value());
178 firstStateNextStateGenerator.unsetRewardModel();
182 performExploration(info, firstStateNextStateGenerator.getPostAbstractionHandle(abstraction.
value(), discoverCallback), terminalBeliefCallback,
183 terminationCallback);
185 performExploration(info, firstStateNextStateGenerator.getHandle(discoverCallback), terminalBeliefCallback, terminationCallback);
190 template<
typename InfoType,
typename NextStateHandleType>
191 bool performExploration(InfoType& info, NextStateHandleType&& exploreNextStates,
TerminalBeliefCallback const& terminalBeliefCallback,
193 while (info.queue.hasNext()) {
197 "Frontier beliefs inconsistent.");
202 auto const currentBeliefId = info.queue.popNext();
203 STORM_LOG_ASSERT(info.discoveredBeliefs.containsId(currentBeliefId),
"Unknown belief id");
204 STORM_LOG_ASSERT(info.exploredBeliefs.count(currentBeliefId) == 0,
"Belief #" << currentBeliefId <<
" already explored.");
205 STORM_LOG_ASSERT(info.terminalBeliefValues.count(currentBeliefId) == 0,
"Belief #" << currentBeliefId <<
" already found to be terminal.");
207 auto const currentBelief = info.discoveredBeliefs.getBeliefFromId(currentBeliefId);
208 STORM_LOG_TRACE(
"Explore belief " << currentBeliefId <<
" : " << currentBelief.toString());
210 if (terminalBeliefCallback) {
211 if (
auto terminal = terminalBeliefCallback(currentBelief); terminal.has_value()) {
212 info.terminalBeliefValues.emplace(currentBeliefId, std::move(terminal.value()));
218 info.exploredBeliefs.emplace(currentBeliefId, info.matrix.groups());
219 auto const numActions = firstStateNextStateGenerator.getBeliefNumberOfActions(currentBelief);
220 for (uint64_t localActionIndex = 0; localActionIndex < numActions; ++localActionIndex) {
221 exploreNextStates(currentBelief, localActionIndex);
222 info.matrix.endCurrentRow();
223 if (firstStateNextStateGenerator.hasRewardModel()) {
224 info.actionRewards.emplace_back(
227 if (info.generateChoiceLabeling) {
228 info.matrix.choiceLabels.push_back(firstStateNextStateGenerator.getBeliefActionChoiceLabels(currentBelief, localActionIndex));
231 info.matrix.endCurrentRowGroup();
236 FirstStateNextStateGenerator<PomdpType, BeliefType> firstStateNextStateGenerator;
Helper class that optionally holds a reference to an object of type T.
T & value()
Accesses the contained reference (if any).
bool has_value() const
Yields true iff this contains a reference.
BeliefExploration(PomdpType const &pomdp)
Creates an explorer for pomdp.
InfoType initializeExploration(uint64_t nrObservationsInPomdp, ExplorationQueueOrder const explorationQueueOrder=ExplorationQueueOrder::Unordered)
Initializes an exploration with the initial belief as its only queued frontier belief.
void resumeRewardAwareExploration(RewardAwareExplorationInformation< BeliefMdpValueType, BeliefType > &info, TerminalBeliefCallback const &terminalBeliefCallback, TerminationCallback const &terminationCallback, RewardBoundedBeliefSplitter< BeliefMdpValueType, PomdpType, BeliefType > &rewardSplitter, storm::OptionalRef< AbstractionType > abstraction)
Continues reward-aware exploration, splitting a belief by reward vector before generating successors.
void resumeClippingExploration(ClippingExplorationInformation< BeliefMdpValueType, BeliefType > &info, TerminalBeliefCallback const &terminalBeliefCallback, TerminationCallback const &terminationCallback, storm::OptionalRef< std::string const > rewardModelName, storm::OptionalRef< AbstractionType > abstraction)
Continues exploration with clipping metadata on the generated transitions.
void resumeExploration(StandardExplorationInformation< BeliefMdpValueType, BeliefType > &info, TerminalBeliefCallback const &terminalBeliefCallback, TerminationCallback const &terminationCallback, storm::OptionalRef< std::string const > rewardModelName, storm::OptionalRef< AbstractionType > abstraction)
Continues an ordinary exploration until the queue is empty, a terminal callback applies,...
std::function< bool()> TerminationCallback
std::function< std::optional< BeliefMdpValueType >(BeliefType const &)> TerminalBeliefCallback
Abstracts a belief by triangulating it using the Freudenthal triangulation.
Abstracts a given belief by splitting it into sub-beliefs based on the (state-action) reward of the P...
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ASSERT(cond, message)
ExplorationInformation< BeliefMdpValueType, BeliefType, std::optional< BeliefMdpValueType >, std::optional< BeliefMdpValueType > > ClippingExplorationInformation
Exploration information that stores optional clipping probability and reward-adjustment metadata.
ExplorationInformation< BeliefMdpValueType, BeliefType > StandardExplorationInformation
Exploration information without transition metadata.
ExplorationQueueOrder
Order used to select the next discovered belief for exploration.
ExplorationInformation< BeliefMdpValueType, BeliefType, std::vector< BeliefMdpValueType > > RewardAwareExplorationInformation
Exploration information that stores a reward vector on each transition.
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
TargetType convertNumber(SourceType const &number)
Stores successor transitions together with clipping metadata.
void operator()(BeliefType &&bel, typename BeliefType::ValueType &&val)
ClippingDiscoverCallback(ClippingExplorationInformation< BeliefMdpValueType, BeliefType > &info)
void operator()(BeliefType &&bel, typename BeliefType::ValueType &&val, std::optional< typename BeliefType::ValueType > optionalWeightedClippingValue, std::optional< typename BeliefType::ValueType > optionalRewardAdjustment)
ClippingExplorationInformation< BeliefMdpValueType, BeliefType > & info
Stores reward-aware successor transitions and their reward vectors.
RewardAwareExplorationInformation< BeliefMdpValueType, BeliefType > & info
RewardAwareDiscoverCallback(RewardAwareExplorationInformation< BeliefMdpValueType, BeliefType > &info)
void operator()(BeliefType &&bel, typename BeliefType::ValueType &&val, std::vector< BeliefMdpValueType > const &rewards)
Stores ordinary successor transitions in exploration information.
void operator()(BeliefType &&bel, typename BeliefType::ValueType &&val)
StandardDiscoverCallback(StandardExplorationInformation< BeliefMdpValueType, BeliefType > &info)
StandardExplorationInformation< BeliefMdpValueType, BeliefType > & info