3#include <boost/optional.hpp>
25namespace transformer {
27template<
typename ValueType,
typename RewardModelType>
31 auto const& ma = *originalModel.template as<storm::models::sparse::MarkovAutomaton<ValueType, RewardModelType>>();
36 auto const& ctmc = *originalModel.template as<storm::models::sparse::Ctmc<ValueType, RewardModelType>>();
41 storm::exceptions::UnexpectedException,
"Unexpected model type.");
46template<
typename RewardModelType>
49 std::optional<std::vector<typename RewardModelType::ValueType>> stateRewardVector;
50 std::optional<std::vector<typename RewardModelType::ValueType>> stateActionRewardVector;
51 std::optional<storm::storage::SparseMatrix<typename RewardModelType::ValueType>> transitionRewardMatrix;
52 if (originalRewardModel.hasStateRewards()) {
55 if (originalRewardModel.hasStateActionRewards()) {
58 if (originalRewardModel.hasTransitionRewards()) {
59 transitionRewardMatrix = originalRewardModel.getTransitionRewardMatrix().getSubmatrix(
false, subsystemActions, subsystem);
60 if (makeRowGroupingTrivial) {
61 STORM_LOG_ASSERT(transitionRewardMatrix.value().getColumnCount() == transitionRewardMatrix.value().getRowCount(),
"Matrix should be square");
62 transitionRewardMatrix.value().makeRowGroupingTrivial();
65 return RewardModelType(std::move(stateRewardVector), std::move(stateActionRewardVector), std::move(transitionRewardMatrix));
68template<
typename ValueType,
typename RewardModelType>
84 deadlockStates.
resize(subsystemStates.
size(),
false);
89 for (
auto subsysState : subsystemStates) {
93 bool hasDeadlock =
true;
94 for (uint_fast64_t row = subsystemActions.
getNextSetIndex(groupIndices[subsysState]); row < groupIndices[subsysState + 1];
96 bool allRowEntriesStayInSubsys =
true;
99 if (!subsystemStates.
get(entry.getColumn())) {
100 allRowEntriesStayInSubsys =
false;
105 if (allRowEntriesStayInSubsys) {
109 keptActions.
set(row,
true);
115 "Expected that in each state, at least one action is selected. Got a deadlock state instead. (violated at " << subsysState <<
")");
119 deadlockStates.
set(subsysState);
123 bool hasDeadlockStates = !deadlockStates.
empty();
128 for (
auto deadlockState : deadlockStates) {
129 keptActions.
set(groupIndices[deadlockState],
true);
134 if (hasDeadlockStates) {
163 if (hasDeadlockStates) {
164 auto subDeadlockStates = deadlockStates % subsystemStates;
165 assert(deadlockStates.
getNumberOfSetBits() == subDeadlockStates.getNumberOfSetBits());
168 for (
auto state : subDeadlockStates) {
174 for (
auto state : subDeadlockStates) {
175 auto const& choice = components.
transitionMatrix.getRowGroupIndices()[state];
176 nonDeadlockChoices.
set(choice,
false);
178 for (
auto const& label : components.
choiceLabeling.value().getLabels()) {
183 for (
auto state : subDeadlockStates) {
184 auto const& choice = components.
transitionMatrix.getRowGroupIndices()[state];
185 components.
choiceOrigins.value()->clearOriginOfChoice(choice);
196 transformModelSpecificComponents<ValueType, RewardModelType>(originalModel, subsystemStates, components);
202 STORM_LOG_DEBUG(
"Subsystem Builder is done. Resulting model has " << result.
model->getNumberOfStates() <<
" states.");
206template<
typename ValueType,
typename RewardModelType>
213 STORM_LOG_THROW(!initialStates.
empty(), storm::exceptions::InvalidArgumentException,
"The subsystem would not contain any initial states");
215 STORM_LOG_THROW(!subsystemStates.
empty(), storm::exceptions::InvalidArgumentException,
"Invoked SubsystemBuilder for an empty subsystem.");
216 if (keepUnreachableStates) {
239 bool keepUnreachableStates =
true,
virtual ModelType getType() const
Return the actual type of the model.
bool isOfType(storm::models::ModelType const &modelType) const
Checks whether the model is of the given type.
ChoiceLabeling getSubLabeling(storm::storage::BitVector const &choices) const
Retrieves the sub labeling that represents the same labeling as the current one for all selected choi...
void addLabel(std::string const &label)
Adds a new label to the labelings.
bool containsLabel(std::string const &label) const
Checks whether a label is registered within this labeling.
Base class for all sparse models.
storm::models::sparse::ChoiceLabeling const & getChoiceLabeling() const
Retrieves the labels for the choices of the model.
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
bool hasStateValuations() const
Retrieves whether this model was build with state valuations.
storm::storage::sparse::StateValuations const & getStateValuations() const
Retrieves the valuations of the states of the model.
std::shared_ptr< storm::storage::sparse::ChoiceOrigins > const & getChoiceOrigins() const
Retrieves the origins of the choices of the model.
bool hasChoiceLabeling() const
Retrieves whether this model has a labeling of the choices.
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
bool hasChoiceOrigins() const
Retrieves whether this model was build with choice origins.
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
StateLabeling getSubLabeling(storm::storage::BitVector const &states) const
Retrieves the sub labeling that represents the same labeling as the current one for all selected stat...
A bit vector that is internally represented as a vector of 64-bit values.
uint_fast64_t getNextSetIndex(uint_fast64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to true in the bit vector.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
void resize(uint_fast64_t newLength, bool init=false)
Resizes the bit vector to hold the given new number of bits.
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
size_t size() const
Retrieves the number of bits this bit vector can store.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
StateValuations selectStates(storm::storage::BitVector const &selectedStates) const
#define STORM_LOG_DEBUG(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > buildModelFromComponents(storm::models::ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > &&components)
storm::storage::BitVector getReachableStates(storm::storage::SparseMatrix< T > const &transitionMatrix, storm::storage::BitVector const &initialStates, storm::storage::BitVector const &constraintStates, storm::storage::BitVector const &targetStates, bool useStepBound, uint_fast64_t maximalSteps, boost::optional< storm::storage::BitVector > const &choiceFilter)
Performs a forward depth-first search through the underlying graph structure to identify the states t...
std::vector< Type > filterVector(std::vector< Type > const &in, storm::storage::BitVector const &filter)
std::optional< storm::storage::sparse::StateValuations > stateValuations
std::unordered_map< std::string, RewardModelType > rewardModels
storm::storage::SparseMatrix< ValueType > transitionMatrix
boost::optional< storm::storage::BitVector > markovianStates
std::optional< std::shared_ptr< storm::storage::sparse::ChoiceOrigins > > choiceOrigins
std::optional< storm::models::sparse::ChoiceLabeling > choiceLabeling
storm::models::sparse::StateLabeling stateLabeling
boost::optional< std::vector< ValueType > > exitRates