#include "src/generator/DftNextStateGenerator.h" #include "src/utility/constants.h" #include "src/utility/macros.h" #include "src/exceptions/NotImplementedException.h" namespace storm { namespace generator { template DftNextStateGenerator::DftNextStateGenerator(storm::storage::DFT const& dft, storm::storage::DFTStateGenerationInfo const& stateGenerationInfo) : mDft(dft), mStateGenerationInfo(stateGenerationInfo), state(nullptr), comparator() { // Intentionally left empty. } template bool DftNextStateGenerator::isDeterministicModel() const { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "This functionality is not yet implemented."); } template std::vector DftNextStateGenerator::getInitialStates(StateToIdCallback const& stateToIdCallback) { DFTStatePointer initialState = std::make_shared>(mDft, mStateGenerationInfo, 0); // Register initial state StateType id = stateToIdCallback(initialState); initialState->setId(id); return {id}; } template void DftNextStateGenerator::load(std::shared_ptr> const& state) { /*// Since almost all subsequent operations are based on the evaluator, we load the state into it now. unpackStateIntoEvaluator(state, variableInformation, evaluator); // Also, we need to store a pointer to the state itself, because we need to be able to access it when expanding it. this->state = &state;*/ STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "This functionality is not yet implemented."); } template bool DftNextStateGenerator::satisfies(storm::expressions::Expression const& expression) const { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "This functionality is not yet implemented."); } template StateBehavior DftNextStateGenerator::expand(StateToIdCallback const& stateToIdCallback) { /*// Prepare the result, in case we return early. StateBehavior result; // First, construct the state rewards, as we may return early if there are no choices later and we already // need the state rewards then. for (auto const& rewardModel : selectedRewardModels) { ValueType stateRewardValue = storm::utility::zero(); if (rewardModel.get().hasStateRewards()) { for (auto const& stateReward : rewardModel.get().getStateRewards()) { if (evaluator.asBool(stateReward.getStatePredicateExpression())) { stateRewardValue += ValueType(evaluator.asRational(stateReward.getRewardValueExpression())); } } } result.addStateReward(stateRewardValue); } // If a terminal expression was set and we must not expand this state, return now. if (terminalExpression && evaluator.asBool(terminalExpression.get())) { return result; } // Get all choices for the state. std::vector> allChoices = getUnlabeledChoices(*this->state, stateToIdCallback); std::vector> allLabeledChoices = getLabeledChoices(*this->state, stateToIdCallback); for (auto& choice : allLabeledChoices) { allChoices.push_back(std::move(choice)); } std::size_t totalNumberOfChoices = allChoices.size(); // If there is not a single choice, we return immediately, because the state has no behavior (other than // the state reward). if (totalNumberOfChoices == 0) { return result; } // If the model is a deterministic model, we need to fuse the choices into one. if (program.isDeterministicModel() && totalNumberOfChoices > 1) { Choice globalChoice; // For CTMCs, we need to keep track of the total exit rate to scale the action rewards later. For DTMCs // this is equal to the number of choices, which is why we initialize it like this here. ValueType totalExitRate = program.isDiscreteTimeModel() ? static_cast(totalNumberOfChoices) : storm::utility::zero(); // Iterate over all choices and combine the probabilities/rates into one choice. for (auto const& choice : allChoices) { for (auto const& stateProbabilityPair : choice) { if (program.isDiscreteTimeModel()) { globalChoice.addProbability(stateProbabilityPair.first, stateProbabilityPair.second / totalNumberOfChoices); } else { globalChoice.addProbability(stateProbabilityPair.first, stateProbabilityPair.second); } } if (hasStateActionRewards && !program.isDiscreteTimeModel()) { totalExitRate += choice.getTotalMass(); } if (buildChoiceLabeling) { globalChoice.addChoiceLabels(choice.getChoiceLabels()); } } // Now construct the state-action reward for all selected reward models. for (auto const& rewardModel : selectedRewardModels) { ValueType stateActionRewardValue = storm::utility::zero(); if (rewardModel.get().hasStateActionRewards()) { for (auto const& stateActionReward : rewardModel.get().getStateActionRewards()) { for (auto const& choice : allChoices) { if (stateActionReward.getActionIndex() == choice.getActionIndex() && evaluator.asBool(stateActionReward.getStatePredicateExpression())) { stateActionRewardValue += ValueType(evaluator.asRational(stateActionReward.getRewardValueExpression())) * choice.getTotalMass() / totalExitRate; } } } } globalChoice.addChoiceReward(stateActionRewardValue); } // Move the newly fused choice in place. allChoices.clear(); allChoices.push_back(std::move(globalChoice)); } // Move all remaining choices in place. for (auto& choice : allChoices) { result.addChoice(std::move(choice)); } result.setExpanded(); return result;*/ STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "This functionality is not yet implemented."); } template class DftNextStateGenerator; template class DftNextStateGenerator; } }