51 rewardModels.push_back(rewardModel);
55 for (
auto const& rewardModelName : this->options.getRewardModelNames()) {
57 rewardModels.push_back(this->program.
getRewardModel(rewardModelName));
59 STORM_LOG_THROW(rewardModelName.empty(), storm::exceptions::InvalidArgumentException,
60 "Cannot build unknown reward model '" << rewardModelName <<
"'.");
62 "Reference to standard reward model is ambiguous.");
68 if (rewardModels.empty() && !this->options.getRewardModelNames().empty()) {
74 for (
auto const& rewardModel : rewardModels) {
75 hasStateActionRewards |= rewardModel.get().hasStateActionRewards();
80 for (
auto const& expressionOrLabelAndBool : this->options.getTerminalStates()) {
81 if (expressionOrLabelAndBool.first.isExpression()) {
82 this->terminalStates.push_back(std::make_pair(expressionOrLabelAndBool.first.getExpression(), expressionOrLabelAndBool.second));
84 if (program.
hasLabel(expressionOrLabelAndBool.first.getLabel())) {
85 this->terminalStates.push_back(
86 std::make_pair(this->program.
getLabelExpression(expressionOrLabelAndBool.first.getLabel()), expressionOrLabelAndBool.second));
89 STORM_LOG_THROW(this->isSpecialLabel(expressionOrLabelAndBool.first.getLabel()), storm::exceptions::InvalidArgumentException,
90 "Terminal states refer to illegal label '" << expressionOrLabelAndBool.first.getLabel() <<
"'.");
102template<
typename ValueType,
typename StateType>
108template<
typename ValueType,
typename StateType>
112 std::vector<std::reference_wrapper<storm::prism::Constant const>> undefinedConstants = program.
getUndefinedConstants();
113 std::stringstream stream;
114 bool printComma =
false;
115 for (
auto const& constant : undefinedConstants) {
121 stream << constant.get().getName() <<
" (" << constant.get().getType() <<
")";
124 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Program still contains these undefined constants: " + stream.str());
128 "The program contains undefined constants that appear in some places other than update probabilities and reward value expressions, "
129 "which is not admitted. Undefined constants are: "
134template<
typename ValueType,
typename StateType>
150 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Invalid model type.");
154template<
typename ValueType,
typename StateType>
159template<
typename ValueType,
typename StateType>
164template<
typename ValueType,
typename StateType>
169template<
typename ValueType,
typename StateType>
171 std::vector<StateType> initialStateIndices;
176 std::vector<std::vector<uint64_t>> allValues;
177 for (
auto const& intVar : this->variableInformation.integerVariables) {
178 STORM_LOG_ASSERT(intVar.lowerBound <= intVar.upperBound,
"Expecting variable with non-empty set of possible values.");
180 allValues.push_back(storm::utility::vector::buildVectorForRange<uint64_t>(
static_cast<uint64_t
>(0), intVar.upperBound + 1 - intVar.lowerBound));
182 uint64_t intEndIndex = allValues.size();
184 allValues.resize(allValues.size() + this->variableInformation.booleanVariables.size(),
185 std::vector<uint64_t>({static_cast<uint64_t>(0), static_cast<uint64_t>(1)}));
187 std::vector<std::vector<uint64_t>::const_iterator> its;
188 std::vector<std::vector<uint64_t>::const_iterator> ites;
189 for (
auto const& valVec : allValues) {
190 its.push_back(valVec.cbegin());
191 ites.push_back(valVec.cend());
195 CompressedState initialState(this->variableInformation.getTotalBitOffset(
true));
198 [
this, &initialState, &intEndIndex](uint64_t index, uint64_t value) {
200 if (index < intEndIndex) {
202 auto const& intVar = this->variableInformation.integerVariables[index];
203 initialState.
setFromInt(intVar.bitOffset, intVar.bitWidth, value);
206 STORM_LOG_ASSERT(index - intEndIndex < this->variableInformation.booleanVariables.size(),
"Unexpected index");
207 auto const& boolVar = this->variableInformation.booleanVariables[index - intEndIndex];
209 initialState.
set(boolVar.bitOffset,
static_cast<bool>(value));
212 [&stateToIdCallback, &initialStateIndices, &initialState]() {
214 StateType
id = stateToIdCallback(initialState);
215 initialStateIndices.push_back(
id);
218 STORM_LOG_DEBUG(
"Enumerated " << initialStateIndices.size() <<
" initial states using brute force enumeration.");
222 std::unique_ptr<storm::solver::SmtSolver> solver = factory.
create(program.
getManager());
225 for (
auto const& expression : rangeExpressions) {
226 solver->add(expression);
233 CompressedState initialState(this->variableInformation.getTotalBitOffset(
true));
238 std::shared_ptr<storm::solver::SmtSolver::ModelReference> model = solver->getModel();
239 for (
auto const& booleanVariable : this->variableInformation.booleanVariables) {
240 bool variableValue = model->getBooleanValue(booleanVariable.variable);
242 blockingExpression = blockingExpression.
isInitialized() ? blockingExpression || localBlockingExpression : localBlockingExpression;
243 initialState.
set(booleanVariable.bitOffset, variableValue);
245 for (
auto const& integerVariable : this->variableInformation.integerVariables) {
246 int_fast64_t variableValue = model->getIntegerValue(integerVariable.variable);
248 blockingExpression = blockingExpression.
isInitialized() ? blockingExpression || localBlockingExpression : localBlockingExpression;
249 initialState.
setFromInt(integerVariable.bitOffset, integerVariable.bitWidth,
250 static_cast<uint_fast64_t
>(variableValue - integerVariable.lowerBound));
254 StateType
id = stateToIdCallback(initialState);
255 initialStateIndices.push_back(
id);
261 solver->add(blockingExpression);
264 STORM_LOG_DEBUG(
"Enumerated " << initialStateIndices.size() <<
" initial states using SMT solving.");
267 return initialStateIndices;
270template<
typename ValueType,
typename StateType>
277 for (
auto const& rewardModel : rewardModels) {
278 ValueType stateRewardValue = storm::utility::zero<ValueType>();
279 if (rewardModel.get().hasStateRewards()) {
280 for (
auto const& stateReward : rewardModel.get().getStateRewards()) {
281 if (this->evaluator->asBool(stateReward.getStatePredicateExpression())) {
282 stateRewardValue += ValueType(this->evaluator->asRational(stateReward.getRewardValueExpression()));
290 if (!this->terminalStates.empty()) {
291 for (
auto const& expressionBool : this->terminalStates) {
292 if (this->evaluator->asBool(expressionBool.first) == expressionBool.second) {
293 if (!isPartiallyObservable()) {
299 std::vector<Choice<ValueType>> allChoices = getSelfLoopsForAllActions(*this->state, stateToIdCallback);
300 if (allChoices.size() != 0) {
301 for (
auto& choice : allChoices) {
305 this->postprocess(result);
316 std::vector<Choice<ValueType>> allChoices;
317 if (this->getOptions().isApplyMaximalProgressAssumptionSet()) {
319 allChoices = getAsynchronousChoices(*this->state, stateToIdCallback, CommandFilter::Probabilistic);
320 addSynchronousChoices(allChoices, *this->state, stateToIdCallback, CommandFilter::Probabilistic);
321 if (allChoices.empty()) {
323 allChoices = getAsynchronousChoices(*this->state, stateToIdCallback, CommandFilter::Markovian);
324 addSynchronousChoices(allChoices, *this->state, stateToIdCallback, CommandFilter::Markovian);
327 allChoices = getAsynchronousChoices(*this->state, stateToIdCallback);
328 addSynchronousChoices(allChoices, *this->state, stateToIdCallback);
333 if (allChoices.empty()) {
338 if (this->isDeterministicModel() && allChoices.size() > 1) {
342 this->overlappingGuardStates->push_back(stateToIdCallback(*this->state));
347 ValueType
const totalNumberOfChoices = storm::utility::convertNumber<ValueType, uint64_t>(allChoices.size());
348 ValueType totalExitRate = this->isDiscreteTimeModel() ? totalNumberOfChoices : storm::utility::zero<ValueType>();
351 for (
auto const& choice : allChoices) {
352 for (
auto const& stateProbabilityPair : choice) {
353 if (this->isDiscreteTimeModel()) {
354 globalChoice.
addProbability(stateProbabilityPair.first, stateProbabilityPair.second / totalNumberOfChoices);
356 globalChoice.
addProbability(stateProbabilityPair.first, stateProbabilityPair.second);
360 if (hasStateActionRewards && !this->isDiscreteTimeModel()) {
361 totalExitRate += choice.getTotalMass();
365 globalChoice.
addLabels(choice.getLabels());
374 for (
auto const& rewardModel : rewardModels) {
375 ValueType stateActionRewardValue = storm::utility::zero<ValueType>();
376 if (rewardModel.get().hasStateActionRewards()) {
377 for (
auto const& stateActionReward : rewardModel.get().getStateActionRewards()) {
378 for (
auto const& choice : allChoices) {
379 if (stateActionReward.getActionIndex() == choice.getActionIndex() &&
380 this->evaluator->asBool(stateActionReward.getStatePredicateExpression())) {
381 stateActionRewardValue +=
382 ValueType(this->evaluator->asRational(stateActionReward.getRewardValueExpression())) * choice.getTotalMass();
387 if (hasStateActionRewards) {
388 globalChoice.
addReward(stateActionRewardValue / totalExitRate);
394 allChoices.push_back(std::move(globalChoice));
399 auto choiceIt = allChoices.begin();
401 "State '" << this->stateToString(*this->state)
402 <<
"' features a choice without player index.");
405 "State '" << this->stateToString(*this->state)
406 <<
"' features a choice with invalid player index.");
407 for (++choiceIt; choiceIt != allChoices.end(); ++choiceIt) {
409 "State '" << this->stateToString(*this->state)
410 <<
"' features a choice without player index.");
412 "State '" << this->stateToString(*this->state)
413 <<
"' features a choice with invalid player index.");
414 STORM_LOG_THROW(statePlayerIndex == choiceIt->getPlayerIndex(), storm::exceptions::WrongFormatException,
415 "The player for state '" << this->stateToString(*this->state) <<
"' is not unique. At least one choice is owned by player '"
416 << statePlayerIndex <<
"' while another is owned by player '" << choiceIt->getPlayerIndex() <<
"'.");
421 for (
auto& choice : allChoices) {
425 this->postprocess(result);
430template<
typename ValueType,
typename StateType>
432 return this->evaluator->asBool(expr);
435template<
typename ValueType,
typename StateType>
448 auto boolIt = this->variableInformation.booleanVariables.begin();
449 for (; assignmentIt != assignmentIte && assignmentIt->getExpression().hasBooleanType(); ++assignmentIt) {
450 while (assignmentIt->getVariable() != boolIt->variable) {
453 newState.set(boolIt->bitOffset, this->evaluator->asBool(assignmentIt->getExpression()));
457 auto integerIt = this->variableInformation.integerVariables.begin();
458 for (; assignmentIt != assignmentIte && assignmentIt->getExpression().hasIntegerType(); ++assignmentIt) {
459 while (assignmentIt->getVariable() != integerIt->variable) {
462 int_fast64_t assignedValue = this->evaluator->asInt(assignmentIt->getExpression());
464 if (assignedValue < integerIt->lowerBound || assignedValue > integerIt->upperBound) {
465 return this->outOfBoundsState;
467 }
else if (integerIt->forceOutOfBoundsCheck || this->options.isExplorationChecksSet()) {
468 STORM_LOG_THROW(assignedValue >= integerIt->lowerBound, storm::exceptions::WrongFormatException,
469 "The update " << update <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
470 << assignmentIt->getVariableName() <<
"'.");
471 STORM_LOG_THROW(assignedValue <= integerIt->upperBound, storm::exceptions::WrongFormatException,
472 "The update " << update <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
473 << assignmentIt->getVariableName() <<
"'.");
475 newState.setFromInt(integerIt->bitOffset, integerIt->bitWidth, assignedValue - integerIt->lowerBound);
476 STORM_LOG_ASSERT(
static_cast<int_fast64_t
>(newState.getAsInt(integerIt->bitOffset, integerIt->bitWidth)) + integerIt->lowerBound == assignedValue,
477 "Writing to the bit vector bucket failed (read " << newState.getAsInt(integerIt->bitOffset, integerIt->bitWidth) <<
" but wrote "
478 << assignedValue <<
").");
482 STORM_LOG_ASSERT(assignmentIt == assignmentIte,
"Not all assignments were consumed.");
498template<
typename ValueType,
typename StateType>
499boost::optional<std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>>>
507 std::vector<ActiveCommandData> activeCommands;
512 if (!module.hasActionIndex(actionIndex)) {
516 std::set<uint_fast64_t>
const& commandIndices =
module.getCommandIndicesByActionIndex(actionIndex);
520 if (commandIndices.empty()) {
525 bool hasOneEnabledCommand =
false;
526 for (
auto commandIndexIt = commandIndices.begin(), commandIndexIte = commandIndices.end(); commandIndexIt != commandIndexIte; ++commandIndexIt) {
528 if (!isCommandPotentiallySynchronizing(command)) {
531 if (commandFilter != CommandFilter::All) {
532 STORM_LOG_ASSERT(commandFilter == CommandFilter::Markovian || commandFilter == CommandFilter::Probabilistic,
"Unexpected command filter.");
533 if ((commandFilter == CommandFilter::Markovian) != command.
isMarkovian()) {
539 hasOneEnabledCommand =
true;
540 activeCommands.emplace_back(&module, &commandIndices, commandIndexIt);
545 if (!hasOneEnabledCommand) {
551 std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>> result;
554 for (
auto const& activeCommand : activeCommands) {
555 std::vector<std::reference_wrapper<storm::prism::Command const>> commands;
557 auto commandIndexIt = activeCommand.currentCommandIndexIt;
559 commands.push_back(activeCommand.modulePtr->getCommand(*commandIndexIt));
562 auto commandIndexIte = activeCommand.commandIndicesPtr->end();
563 for (++commandIndexIt; commandIndexIt != commandIndexIte; ++commandIndexIt) {
565 if (commandFilter != CommandFilter::All) {
566 STORM_LOG_ASSERT(commandFilter == CommandFilter::Markovian || commandFilter == CommandFilter::Probabilistic,
"Unexpected command filter.");
567 if ((commandFilter == CommandFilter::Markovian) != command.
isMarkovian()) {
572 commands.push_back(command);
576 result.push_back(std::move(commands));
583template<
typename ValueType,
typename BaseValueType>
585 if constexpr (storm::IsIntervalType<ValueType>) {
589 return ValueType(lower, carl::BoundType::WEAK, upper, carl::BoundType::WEAK);
600template<
typename ValueType,
typename StateType>
601std::vector<Choice<ValueType>> PrismNextStateGenerator<ValueType, StateType>::getAsynchronousChoices(
CompressedState const& state,
602 StateToIdCallback stateToIdCallback,
603 CommandFilter
const& commandFilter) {
604 std::vector<Choice<ValueType>> result;
611 for (uint_fast64_t j = 0; j <
module.getNumberOfCommands(); ++j) {
615 if (isCommandPotentiallySynchronizing(command))
618 if (commandFilter != CommandFilter::All) {
619 STORM_LOG_ASSERT(commandFilter == CommandFilter::Markovian || commandFilter == CommandFilter::Probabilistic,
"Unexpected command filter.");
620 if ((commandFilter == CommandFilter::Markovian) != command.
isMarkovian()) {
624 if (this->actionMask !=
nullptr) {
636 Choice<ValueType>& choice = result.back();
641 choice.addOriginData(boost::any(std::move(commandIndex)));
645 ValueType probabilitySum = storm::utility::zero<ValueType>();
649 ValueType probability = evaluateLikelihoodExpression<ValueType>(update, *this->evaluator);
650 if (probability != storm::utility::zero<ValueType>()) {
653 StateType stateIndex = stateToIdCallback(applyUpdate(state, update));
656 choice.addProbability(stateIndex, probability);
658 if constexpr (!std::is_same_v<ValueType, storm::RationalFunction>) {
659 STORM_LOG_THROW(probability > storm::utility::zero<ValueType>(), storm::exceptions::WrongFormatException,
660 "Probability expression in update '" << update <<
" evaluates to negative value " << probability <<
".");
662 storm::exceptions::WrongFormatException,
663 "Probability expression in update '" << update <<
" evaluates to value " << probability <<
" >1.");
665 probabilitySum += probability;
671 for (
auto const& rewardModel : rewardModels) {
672 ValueType stateActionRewardValue = storm::utility::zero<ValueType>();
673 if (rewardModel.get().hasStateActionRewards()) {
674 for (
auto const& stateActionReward : rewardModel.get().getStateActionRewards()) {
675 if (stateActionReward.getActionIndex() == choice.getActionIndex() &&
676 this->evaluator->asBool(stateActionReward.getStatePredicateExpression())) {
677 stateActionRewardValue +=
ValueType(this->evaluator->asRational(stateActionReward.getRewardValueExpression()));
681 choice.addReward(stateActionRewardValue);
691 auto const playerOfModule = moduleIndexToPlayerIndexMap.at(i);
693 "Module " << module.getName() <<
" is not owned by any player but has at least one enabled, unlabeled command.");
694 choice.setPlayerIndex(playerOfModule);
697 auto const playerOfAction = actionIndexToPlayerIndexMap.at(command.
getActionIndex());
700 choice.setPlayerIndex(playerOfAction);
707 storm::exceptions::WrongFormatException,
708 "Probabilities do not sum to one for command '" << command <<
"' (actually sum to " << probabilitySum <<
").");
716template<
typename ValueType,
typename StateType>
717std::vector<Choice<ValueType>> PrismNextStateGenerator<ValueType, StateType>::getSelfLoopsForAllActions(
CompressedState const& state,
718 StateToIdCallback stateToIdCallback,
719 CommandFilter
const& commandFilter) {
720 std::vector<Choice<ValueType>> result;
728 for (uint_fast64_t j = 0; j <
module.getNumberOfCommands(); ++j) {
732 if (isCommandPotentiallySynchronizing(command))
735 if (this->actionMask !=
nullptr) {
747 Choice<ValueType>& choice = result.back();
752 choice.addOriginData(boost::any(std::move(commandIndex)));
754 choice.addProbability(stateToIdCallback(*this->state), storm::utility::one<ValueType>());
757 for (
auto const& rewardModel : rewardModels) {
758 ValueType stateActionRewardValue = storm::utility::zero<ValueType>();
759 if (rewardModel.get().hasStateActionRewards()) {
760 for (
auto const& stateActionReward : rewardModel.get().getStateActionRewards()) {
761 if (stateActionReward.getActionIndex() == choice.getActionIndex() &&
762 this->evaluator->asBool(stateActionReward.getStatePredicateExpression())) {
763 stateActionRewardValue +=
ValueType(this->evaluator->asRational(stateActionReward.getRewardValueExpression()));
767 choice.addReward(stateActionRewardValue);
777 for (uint_fast64_t actionIndex : program.getSynchronizingActionIndices()) {
778 if (this->actionMask !=
nullptr) {
779 if (!this->actionMask->query(*
this, actionIndex)) {
783 boost::optional<std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>>> optionalActiveCommandLists =
784 getActiveCommandsByActionIndex(actionIndex, commandFilter);
787 if (optionalActiveCommandLists) {
788 std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>>
const& activeCommandList = optionalActiveCommandLists.get();
789 std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>::const_iterator> iteratorList(activeCommandList.size());
792 for (
size_t i = 0;
i < activeCommandList.size(); ++
i) {
793 iteratorList[
i] = activeCommandList[
i].cbegin();
802 result.push_back(Choice<ValueType>(actionIndex));
805 Choice<ValueType>& choice = result.back();
812 CommandSet commandIndices;
813 for (uint_fast64_t i = 0;
i < iteratorList.size(); ++
i) {
814 commandIndices.insert(iteratorList[i]->get().getGlobalIndex());
816 choice.addOriginData(boost::any(std::move(commandIndices)));
818 choice.addProbability(stateToIdCallback(*this->state), storm::utility::one<ValueType>());
821 for (
auto const& rewardModel : rewardModels) {
822 ValueType stateActionRewardValue = storm::utility::zero<ValueType>();
823 if (rewardModel.get().hasStateActionRewards()) {
824 for (
auto const& stateActionReward : rewardModel.get().getStateActionRewards()) {
825 if (stateActionReward.getActionIndex() == choice.getActionIndex() &&
826 this->evaluator->asBool(stateActionReward.getStatePredicateExpression())) {
827 stateActionRewardValue +=
ValueType(this->evaluator->asRational(stateActionReward.getRewardValueExpression()));
831 choice.addReward(stateActionRewardValue);
835 bool movedIterator =
false;
836 for (int_fast64_t j = iteratorList.size() - 1; !movedIterator && j >= 0; --j) {
838 if (iteratorList[j] != activeCommandList[j].end()) {
839 movedIterator =
true;
842 iteratorList[j] = activeCommandList[j].begin();
846 done = !movedIterator;
854template<
typename ValueType,
typename StateType>
855void PrismNextStateGenerator<ValueType, StateType>::generateSynchronizedDistribution(
857 std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>::const_iterator>
const& iteratorList,
859 if (storm::utility::isZero<ValueType>(probability)) {
863 if (position >= iteratorList.size()) {
864 StateType
id = stateToIdCallback(state);
865 distribution.
add(
id, std::move(probability));
870 ValueType updateProbability = evaluateLikelihoodExpression<ValueType>(update, *this->evaluator);
871 if constexpr (!std::is_same_v<ValueType, storm::RationalFunction>) {
873 STORM_LOG_THROW(updateProbability >= storm::utility::zero<ValueType>(), storm::exceptions::WrongFormatException,
874 "Probability expression in update '" << update <<
" evaluates to negative value " << updateProbability <<
".");
876 storm::exceptions::WrongFormatException,
877 "Probability expression in update '" << update <<
" evaluates to value " << updateProbability <<
" >1.");
880 updateProbability *= probability;
881 generateSynchronizedDistribution(applyUpdate(state, update), updateProbability, position + 1, iteratorList, distribution, stateToIdCallback);
886template<
typename ValueType,
typename StateType>
887void PrismNextStateGenerator<ValueType, StateType>::addSynchronousChoices(std::vector<Choice<ValueType>>& choices,
CompressedState const& state,
888 StateToIdCallback stateToIdCallback, CommandFilter
const& commandFilter) {
889 for (uint_fast64_t actionIndex : program.getSynchronizingActionIndices()) {
890 if (this->actionMask !=
nullptr) {
891 if (!this->actionMask->query(*
this, actionIndex)) {
895 boost::optional<std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>>> optionalActiveCommandLists =
896 getActiveCommandsByActionIndex(actionIndex, commandFilter);
899 if (optionalActiveCommandLists) {
900 std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>>
const& activeCommandList = optionalActiveCommandLists.get();
901 std::vector<std::vector<std::reference_wrapper<storm::prism::Command const>>::const_iterator> iteratorList(activeCommandList.size());
904 for (
size_t i = 0;
i < activeCommandList.size(); ++
i) {
905 iteratorList[
i] = activeCommandList[
i].cbegin();
913 distribution.
clear();
914 generateSynchronizedDistribution(state, storm::utility::one<ValueType>(), 0, iteratorList, distribution, stateToIdCallback);
920 choices.push_back(Choice<ValueType>(actionIndex));
923 Choice<ValueType>& choice = choices.back();
929 <<
" is not owned by any player but has at least one enabled, unlabeled (synchronized) command.");
930 choice.setPlayerIndex(playerOfAction);
938 CommandSet commandIndices;
939 for (uint_fast64_t i = 0;
i < iteratorList.size(); ++
i) {
940 commandIndices.insert(iteratorList[i]->get().getGlobalIndex());
942 choice.addOriginData(boost::any(std::move(commandIndices)));
946 ValueType probabilitySum = storm::utility::zero<ValueType>();
947 choice.reserve(std::distance(distribution.
begin(), distribution.
end()));
948 for (
auto const& stateProbability : distribution) {
949 choice.addProbability(stateProbability.getState(), stateProbability.getValue());
951 probabilitySum += stateProbability.getValue();
958 storm::exceptions::WrongFormatException,
959 "Sum of update probabilities do not some to one for some command (actually sum to " << probabilitySum <<
").");
963 for (
auto const& rewardModel : rewardModels) {
964 ValueType stateActionRewardValue = storm::utility::zero<ValueType>();
965 if (rewardModel.get().hasStateActionRewards()) {
966 for (
auto const& stateActionReward : rewardModel.get().getStateActionRewards()) {
967 if (stateActionReward.getActionIndex() == choice.getActionIndex() &&
968 this->evaluator->asBool(stateActionReward.getStatePredicateExpression())) {
969 stateActionRewardValue +=
ValueType(this->evaluator->asRational(stateActionReward.getRewardValueExpression()));
973 choice.addReward(stateActionRewardValue);
977 bool movedIterator =
false;
978 for (int_fast64_t j = iteratorList.size() - 1; !movedIterator && j >= 0; --j) {
980 if (iteratorList[j] != activeCommandList[j].end()) {
981 movedIterator =
true;
984 iteratorList[j] = activeCommandList[j].begin();
988 done = !movedIterator;
994template<
typename ValueType,
typename StateType>
999template<
typename ValueType,
typename StateType>
1001 std::vector<StateType>
const& initialStateIndices,
1002 std::vector<StateType>
const& deadlockStateIndices,
1003 std::vector<StateType>
const& unexploredStateIndices) {
1005 std::vector<std::pair<std::string, storm::expressions::Expression>> labels;
1007 for (
auto const& label : program.
getLabels()) {
1008 labels.push_back(std::make_pair(label.getName(), label.getStatePredicateExpression()));
1011 for (
auto const& labelName : this->options.
getLabelNames()) {
1015 STORM_LOG_THROW(this->isSpecialLabel(labelName), storm::exceptions::InvalidArgumentException,
1016 "Cannot build labeling for unknown label '" << labelName <<
"'.");
1024template<
typename ValueType,
typename StateType>
1034 result.setFromInt(64 * i, 64, this->evaluator->asInt(program.
getObservationLabels()[i].getStatePredicateExpression()));
1039template<
typename ValueType,
typename StateType>
1046template<
typename ValueType,
typename StateType>
1048 return rewardModels.size();
1051template<
typename ValueType,
typename StateType>
1058template<
typename ValueType,
typename StateType>
1060 std::vector<boost::any>& dataForChoiceOrigins)
const {
1061 if (!this->getOptions().isBuildChoiceOriginsSet()) {
1065 std::vector<uint_fast64_t> identifiers;
1066 identifiers.reserve(dataForChoiceOrigins.size());
1068 std::map<CommandSet, uint_fast64_t> commandSetToIdentifierMap;
1071 commandSetToIdentifierMap.insert(std::make_pair(
CommandSet(), 0));
1072 uint_fast64_t currentIdentifier = 1;
1073 for (boost::any& originData : dataForChoiceOrigins) {
1074 STORM_LOG_ASSERT(originData.empty() || boost::any_cast<CommandSet>(&originData) !=
nullptr,
1075 "Origin data has unexpected type: " << originData.type().name() <<
".");
1077 CommandSet currentCommandSet = originData.empty() ?
CommandSet() : boost::any_cast<CommandSet>(std::move(originData));
1078 auto insertionRes = commandSetToIdentifierMap.insert(std::make_pair(std::move(currentCommandSet), currentIdentifier));
1079 identifiers.push_back(insertionRes.first->second);
1080 if (insertionRes.second) {
1081 ++currentIdentifier;
1085 std::vector<CommandSet> identifierToCommandSetMapping(currentIdentifier);
1086 for (
auto const& setIdPair : commandSetToIdentifierMap) {
1087 identifierToCommandSetMapping[setIdPair.second] = setIdPair.first;
1090 return std::make_shared<storm::storage::sparse::PrismChoiceOrigins>(std::make_shared<storm::prism::Program>(program), std::move(identifiers),
1091 std::move(identifierToCommandSetMapping));