|
|
@ -62,39 +62,24 @@ namespace storm { |
|
|
|
// The state-action reward vector.
|
|
|
|
std::vector<ValueType> stateActionRewardVector; |
|
|
|
}; |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::StateInformation::StateInformation(uint_fast64_t numberOfStates) : valuations(numberOfStates) { |
|
|
|
// Intentionally left empty.
|
|
|
|
} |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::InternalStateInformation::InternalStateInformation() : stateStorage(64, 10), initialStateIndices(), bitsPerState(64), numberOfStates() { |
|
|
|
// Intentionally left empty.
|
|
|
|
} |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::InternalStateInformation::InternalStateInformation(uint64_t bitsPerState) : stateStorage(bitsPerState, 10000000), initialStateIndices(), bitsPerState(bitsPerState), numberOfStates() { |
|
|
|
// Intentionally left empty.
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::ModelComponents::ModelComponents() : transitionMatrix(), stateLabeling(), rewardModels(), choiceLabeling() { |
|
|
|
// Intentionally left empty.
|
|
|
|
} |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::Options::Options() : explorationOrder(storm::settings::generalSettings().getExplorationOrder()), buildCommandLabels(false), buildAllRewardModels(true), buildStateInformation(false), rewardModelsToBuild(), constantDefinitions(), buildAllLabels(true), labelsToBuild(), expressionLabels(), terminalStates(), negatedTerminalStates() { |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::Options::Options() : explorationOrder(storm::settings::generalSettings().getExplorationOrder()), buildCommandLabels(false), buildAllRewardModels(true), buildStateValuations(false), rewardModelsToBuild(), constantDefinitions(), buildAllLabels(true), labelsToBuild(), expressionLabels(), terminalStates(), negatedTerminalStates() { |
|
|
|
// Intentionally left empty.
|
|
|
|
} |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::Options::Options(storm::logic::Formula const& formula) : explorationOrder(storm::settings::generalSettings().getExplorationOrder()), buildCommandLabels(false), buildAllRewardModels(false), buildStateInformation(false), rewardModelsToBuild(), constantDefinitions(), buildAllLabels(false), labelsToBuild(std::set<std::string>()), expressionLabels(std::vector<storm::expressions::Expression>()), terminalStates(), negatedTerminalStates() { |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::Options::Options(storm::logic::Formula const& formula) : explorationOrder(storm::settings::generalSettings().getExplorationOrder()), buildCommandLabels(false), buildAllRewardModels(false), buildStateValuations(false), rewardModelsToBuild(), constantDefinitions(), buildAllLabels(false), labelsToBuild(std::set<std::string>()), expressionLabels(std::vector<storm::expressions::Expression>()), terminalStates(), negatedTerminalStates() { |
|
|
|
this->preserveFormula(formula); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::Options::Options(std::vector<std::shared_ptr<const storm::logic::Formula>> const& formulas) : explorationOrder(storm::settings::generalSettings().getExplorationOrder()), buildCommandLabels(false), buildAllRewardModels(false), buildStateInformation(false), rewardModelsToBuild(), constantDefinitions(), buildAllLabels(false), labelsToBuild(), expressionLabels(), terminalStates(), negatedTerminalStates() { |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::Options::Options(std::vector<std::shared_ptr<const storm::logic::Formula>> const& formulas) : explorationOrder(storm::settings::generalSettings().getExplorationOrder()), buildCommandLabels(false), buildAllRewardModels(false), buildStateValuations(false), rewardModelsToBuild(), constantDefinitions(), buildAllLabels(false), labelsToBuild(), expressionLabels(), terminalStates(), negatedTerminalStates() { |
|
|
|
if (formulas.empty()) { |
|
|
|
this->buildAllRewardModels = true; |
|
|
|
this->buildAllLabels = true; |
|
|
@ -182,19 +167,14 @@ namespace storm { |
|
|
|
} |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::ExplicitPrismModelBuilder(storm::prism::Program const& program, Options const& options) : program(storm::utility::prism::preprocessProgram<ValueType>(program, options.constantDefinitions, !options.buildAllLabels ? options.labelsToBuild : boost::none, options.expressionLabels)), options(options) { |
|
|
|
|
|
|
|
// Create the variable information for the transformed program.
|
|
|
|
this->variableInformation = VariableInformation(this->program); |
|
|
|
|
|
|
|
// Create the internal state storage.
|
|
|
|
this->internalStateInformation = InternalStateInformation(variableInformation.getTotalBitOffset(true)); |
|
|
|
ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::ExplicitPrismModelBuilder(storm::prism::Program const& program, Options const& options) : program(storm::utility::prism::preprocessProgram<ValueType>(program, options.constantDefinitions, !options.buildAllLabels ? options.labelsToBuild : boost::none, options.expressionLabels)), options(options), variableInformation(this->program), stateStorage(variableInformation.getTotalBitOffset(true)) { |
|
|
|
// Intentionally left empty.
|
|
|
|
} |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
typename ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::StateInformation const& ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::getStateInformation() const { |
|
|
|
STORM_LOG_THROW(static_cast<bool>(stateInformation), storm::exceptions::InvalidOperationException, "The state information was not properly build."); |
|
|
|
return stateInformation.get(); |
|
|
|
storm::storage::sparse::StateValuations const& ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::getStateValuations() const { |
|
|
|
STORM_LOG_THROW(static_cast<bool>(stateValuations), storm::exceptions::InvalidOperationException, "The state information was not properly build."); |
|
|
|
return stateValuations.get(); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
@ -261,10 +241,10 @@ namespace storm { |
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
StateType ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::getOrAddStateIndex(CompressedState const& state) { |
|
|
|
uint32_t newIndex = internalStateInformation.numberOfStates; |
|
|
|
uint32_t newIndex = stateStorage.numberOfStates; |
|
|
|
|
|
|
|
// Check, if the state was already registered.
|
|
|
|
std::pair<uint32_t, std::size_t> actualIndexBucketPair = internalStateInformation.stateStorage.findOrAddAndGetBucket(state, newIndex); |
|
|
|
std::pair<uint32_t, std::size_t> actualIndexBucketPair = stateStorage.stateToId.findOrAddAndGetBucket(state, newIndex); |
|
|
|
|
|
|
|
if (actualIndexBucketPair.first == newIndex) { |
|
|
|
if (options.explorationOrder == ExplorationOrder::Dfs) { |
|
|
@ -277,7 +257,7 @@ namespace storm { |
|
|
|
} else { |
|
|
|
STORM_LOG_ASSERT(false, "Invalid exploration order."); |
|
|
|
} |
|
|
|
++internalStateInformation.numberOfStates; |
|
|
|
++stateStorage.numberOfStates; |
|
|
|
} |
|
|
|
|
|
|
|
return actualIndexBucketPair.first; |
|
|
@ -311,7 +291,7 @@ namespace storm { |
|
|
|
} |
|
|
|
|
|
|
|
// Let the generator create all initial states.
|
|
|
|
this->internalStateInformation.initialStateIndices = generator.getInitialStates(stateToIdCallback); |
|
|
|
this->stateStorage.initialStateIndices = generator.getInitialStates(stateToIdCallback); |
|
|
|
|
|
|
|
// Now explore the current state until there is no more reachable state.
|
|
|
|
uint_fast64_t currentRowGroup = 0; |
|
|
@ -321,7 +301,7 @@ namespace storm { |
|
|
|
while (!statesToExplore.empty()) { |
|
|
|
// Get the first state in the queue.
|
|
|
|
CompressedState currentState = statesToExplore.front(); |
|
|
|
StateType currentIndex = internalStateInformation.stateStorage.getValue(currentState); |
|
|
|
StateType currentIndex = stateStorage.stateToId.getValue(currentState); |
|
|
|
statesToExplore.pop_front(); |
|
|
|
|
|
|
|
// If the exploration order differs from breadth-first, we remember that this row group was actually
|
|
|
@ -426,13 +406,13 @@ namespace storm { |
|
|
|
transitionMatrixBuilder.replaceColumns(remapping, 0); |
|
|
|
|
|
|
|
// Fix (b).
|
|
|
|
std::vector<StateType> newInitialStateIndices(this->internalStateInformation.initialStateIndices.size()); |
|
|
|
std::transform(this->internalStateInformation.initialStateIndices.begin(), this->internalStateInformation.initialStateIndices.end(), newInitialStateIndices.begin(), [&remapping] (StateType const& state) { return remapping[state]; } ); |
|
|
|
std::vector<StateType> newInitialStateIndices(this->stateStorage.initialStateIndices.size()); |
|
|
|
std::transform(this->stateStorage.initialStateIndices.begin(), this->stateStorage.initialStateIndices.end(), newInitialStateIndices.begin(), [&remapping] (StateType const& state) { return remapping[state]; } ); |
|
|
|
std::sort(newInitialStateIndices.begin(), newInitialStateIndices.end()); |
|
|
|
this->internalStateInformation.initialStateIndices = std::move(newInitialStateIndices); |
|
|
|
this->stateStorage.initialStateIndices = std::move(newInitialStateIndices); |
|
|
|
|
|
|
|
// Fix (c).
|
|
|
|
this->internalStateInformation.stateStorage.remap([&remapping] (StateType const& state) { return remapping[state]; } ); |
|
|
|
this->stateStorage.stateToId.remap([&remapping] (StateType const& state) { return remapping[state]; } ); |
|
|
|
} |
|
|
|
|
|
|
|
return choiceLabels; |
|
|
@ -497,10 +477,10 @@ namespace storm { |
|
|
|
modelComponents.stateLabeling = buildStateLabeling(); |
|
|
|
|
|
|
|
// Finally -- if requested -- build the state information that can be retrieved from the outside.
|
|
|
|
if (options.buildStateInformation) { |
|
|
|
stateInformation = StateInformation(internalStateInformation.numberOfStates); |
|
|
|
for (auto const& bitVectorIndexPair : internalStateInformation.stateStorage) { |
|
|
|
stateInformation.get().valuations[bitVectorIndexPair.second] = unpackStateIntoValuation(bitVectorIndexPair.first); |
|
|
|
if (options.buildStateValuations) { |
|
|
|
stateValuations = storm::storage::sparse::StateValuations(stateStorage.numberOfStates); |
|
|
|
for (auto const& bitVectorIndexPair : stateStorage.stateToId) { |
|
|
|
stateValuations.get().valuations[bitVectorIndexPair.second] = unpackStateIntoValuation(bitVectorIndexPair.first); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -510,7 +490,7 @@ namespace storm { |
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
|
storm::models::sparse::StateLabeling ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::buildStateLabeling() { |
|
|
|
storm::generator::PrismStateLabelingGenerator<ValueType, StateType> generator(program, variableInformation); |
|
|
|
return generator.generate(internalStateInformation.stateStorage, internalStateInformation.initialStateIndices); |
|
|
|
return generator.generate(stateStorage.stateToId, stateStorage.initialStateIndices); |
|
|
|
} |
|
|
|
|
|
|
|
// Explicitly instantiate the class.
|
|
|
|
xxxxxxxxxx