3#include <boost/optional.hpp>
22namespace transformer {
24template<
typename ValueType,
typename RewardModelType>
28 auto const& ma = *originalModel.template as<storm::models::sparse::MarkovAutomaton<ValueType, RewardModelType>>();
33 auto const& ctmc = *originalModel.template as<storm::models::sparse::Ctmc<ValueType, RewardModelType>>();
38 storm::exceptions::UnexpectedException,
"Unexpected model type.");
43template<
typename RewardModelType>
46 std::optional<std::vector<typename RewardModelType::ValueType>> stateRewardVector;
47 std::optional<std::vector<typename RewardModelType::ValueType>> stateActionRewardVector;
48 std::optional<storm::storage::SparseMatrix<typename RewardModelType::ValueType>> transitionRewardMatrix;
49 if (originalRewardModel.hasStateRewards()) {
52 if (originalRewardModel.hasStateActionRewards()) {
55 if (originalRewardModel.hasTransitionRewards()) {
56 transitionRewardMatrix = originalRewardModel.getTransitionRewardMatrix().getSubmatrix(
false, subsystemActions, subsystem);
57 if (makeRowGroupingTrivial) {
58 STORM_LOG_ASSERT(transitionRewardMatrix.value().getColumnCount() == transitionRewardMatrix.value().getRowCount(),
"Matrix should be square");
59 transitionRewardMatrix.value().makeRowGroupingTrivial();
62 return RewardModelType(std::move(stateRewardVector), std::move(stateActionRewardVector), std::move(transitionRewardMatrix));
65template<
typename ValueType,
typename RewardModelType>
81 deadlockStates.
resize(subsystemStates.
size(),
false);
86 for (
auto subsysState : subsystemStates) {
90 bool hasDeadlock =
true;
91 for (uint_fast64_t row = subsystemActions.
getNextSetIndex(groupIndices[subsysState]); row < groupIndices[subsysState + 1];
93 bool allRowEntriesStayInSubsys =
true;
96 if (!subsystemStates.
get(entry.getColumn())) {
97 allRowEntriesStayInSubsys =
false;
102 if (allRowEntriesStayInSubsys) {
106 keptActions.
set(row,
true);
112 "Expected that in each state, at least one action is selected. Got a deadlock state instead. (violated at " << subsysState <<
")");
116 deadlockStates.
set(subsysState);
120 bool hasDeadlockStates = !deadlockStates.
empty();
125 for (
auto deadlockState : deadlockStates) {
126 keptActions.
set(groupIndices[deadlockState],
true);
131 if (hasDeadlockStates) {
160 if (hasDeadlockStates) {
161 auto subDeadlockStates = deadlockStates % subsystemStates;
162 assert(deadlockStates.
getNumberOfSetBits() == subDeadlockStates.getNumberOfSetBits());
165 for (
auto state : subDeadlockStates) {
171 for (
auto state : subDeadlockStates) {
172 auto const& choice = components.
transitionMatrix.getRowGroupIndices()[state];
173 nonDeadlockChoices.
set(choice,
false);
175 for (
auto const& label : components.
choiceLabeling.value().getLabels()) {
180 for (
auto state : subDeadlockStates) {
181 auto const& choice = components.
transitionMatrix.getRowGroupIndices()[state];
182 components.
choiceOrigins.value()->clearOriginOfChoice(choice);
193 transformModelSpecificComponents<ValueType, RewardModelType>(originalModel, subsystemStates, components);
199 STORM_LOG_DEBUG(
"Subsystem Builder is done. Resulting model has " << result.
model->getNumberOfStates() <<
" states.");
203template<
typename ValueType,
typename RewardModelType>
210 STORM_LOG_THROW(!initialStates.
empty(), storm::exceptions::InvalidArgumentException,
"The subsystem would not contain any initial states");
212 STORM_LOG_THROW(!subsystemStates.
empty(), storm::exceptions::InvalidArgumentException,
"Invoked SubsystemBuilder for an empty subsystem.");
213 if (keepUnreachableStates) {
236 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.
uint64_t getNextSetIndex(uint64_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.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
void set(uint64_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.
void resize(uint64_t newLength, bool init=false)
Resizes the bit vector to hold the given new number of bits.
bool get(uint64_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