Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseParametricModelSimplifier.cpp
Go to the documentation of this file.
2#include <memory>
3
12
13namespace storm {
14namespace transformer {
15
16template<typename SparseModelType>
18 // intentionally left empty
19}
20
21template<typename SparseModelType>
23 // Make sure that there is no old result from a previous call
24 simplifiedModel = nullptr;
25 simplifiedFormula = nullptr;
26 if (formula.isProbabilityOperatorFormula()) {
28 if (probOpForm.getSubformula().isUntilFormula()) {
29 return simplifyForUntilProbabilities(probOpForm);
30 } else if (probOpForm.getSubformula().isReachabilityProbabilityFormula()) {
31 return simplifyForReachabilityProbabilities(probOpForm);
32 } else if (probOpForm.getSubformula().isBoundedUntilFormula()) {
33 return simplifyForBoundedUntilProbabilities(probOpForm);
34 }
35 } else if (formula.isRewardOperatorFormula()) {
37 STORM_LOG_THROW((rewOpForm.hasRewardModelName() && originalModel.hasRewardModel(rewOpForm.getRewardModelName())) ||
38 (!rewOpForm.hasRewardModelName() && originalModel.hasUniqueRewardModel()),
39 storm::exceptions::InvalidPropertyException,
40 "The reward model specified by formula " << formula << " is not available in the given model.");
42 return simplifyForReachabilityRewards(rewOpForm);
43 } else if (rewOpForm.getSubformula().isCumulativeRewardFormula()) {
44 return simplifyForCumulativeRewards(rewOpForm);
45 }
46 }
47 // reaching this point means that the provided formula is not supported. Thus, no simplification is possible.
48 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
49 return false;
50}
51
52template<typename SparseModelType>
54 STORM_LOG_THROW(simplifiedModel, storm::exceptions::InvalidStateException, "Tried to get the simplified model but simplification was not invoked before.");
55 return simplifiedModel;
56}
57
58template<typename SparseModelType>
59std::shared_ptr<storm::logic::Formula const> SparseParametricModelSimplifier<SparseModelType>::getSimplifiedFormula() const {
60 STORM_LOG_THROW(simplifiedFormula, storm::exceptions::InvalidStateException,
61 "Tried to get the simplified formula but simplification was not invoked before.");
62 return simplifiedFormula;
63}
64
65template<typename SparseModelType>
67 // If this method was not overridden by any subclass, simplification is not possible
68 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
69 return false;
70}
71
72template<typename SparseModelType>
74 // transform to until formula
75 auto untilFormula = std::make_shared<storm::logic::UntilFormula const>(storm::logic::Formula::getTrueFormula(),
77 return simplifyForUntilProbabilities(storm::logic::ProbabilityOperatorFormula(untilFormula, formula.getOperatorInformation()));
78}
79
80template<typename SparseModelType>
82 // If this method was not overridden by any subclass, simplification is not possible
83 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
84 return false;
85}
86
87template<typename SparseModelType>
89 // If this method was not overridden by any subclass, simplification is not possible
90 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
91 return false;
92}
93
94template<typename SparseModelType>
96 // If this method was not overridden by any subclass, simplification is not possible
97 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
98 return false;
99}
100
101template<typename SparseModelType>
103 SparseModelType const& model, storm::storage::BitVector const& consideredStates, boost::optional<std::string> const& rewardModelName) {
104 storm::storage::SparseMatrix<typename SparseModelType::ValueType> const& sparseMatrix = model.getTransitionMatrix();
105 auto backwardsSparseMatrix = sparseMatrix.transpose();
106
107 // get the action-based reward values
108 std::vector<typename SparseModelType::ValueType> actionRewards;
109 if (rewardModelName) {
110 actionRewards = model.getRewardModel(*rewardModelName).getTotalRewardVector(sparseMatrix);
111 } else {
112 actionRewards = std::vector<typename SparseModelType::ValueType>(model.getTransitionMatrix().getRowCount(),
113 storm::utility::zero<typename SparseModelType::ValueType>());
114 }
115
116 // Find the states that are to be eliminated
117 storm::storage::BitVector selectedStates = consideredStates;
118 for (auto state : consideredStates) {
119 if (sparseMatrix.getRowGroupSize(state) == 1 &&
120 (!rewardModelName.is_initialized() || storm::utility::isConstant(actionRewards[sparseMatrix.getRowGroupIndices()[state]]))) {
121 for (auto const& entry : sparseMatrix.getRowGroup(state)) {
122 if (!storm::utility::isConstant(entry.getValue())) {
123 selectedStates.set(state, false);
124 break;
125 }
126 }
127 if (state && this->preserveParametricTransitions) {
128 for (auto const& entry : backwardsSparseMatrix.getRowGroup(state)) {
129 if (!storm::utility::isConstant(entry.getValue())) {
130 selectedStates.set(state, false);
131 break;
132 }
133 }
134 }
135 } else {
136 selectedStates.set(state, false);
137 }
138 }
139
140 // invoke elimination and obtain resulting transition matrix
142 storm::storage::FlexibleSparseMatrix<typename SparseModelType::ValueType> flexibleBackwardTransitions(backwardsSparseMatrix, true);
144 flexibleMatrix, flexibleBackwardTransitions, actionRewards);
145 for (auto state : selectedStates) {
146 stateEliminator.eliminateState(state, true);
147 }
148 selectedStates.complement();
149 auto keptRows = sparseMatrix.getRowFilter(selectedStates);
150 storm::storage::SparseMatrix<typename SparseModelType::ValueType> newTransitionMatrix = flexibleMatrix.createSparseMatrix(keptRows, selectedStates);
151
152 // obtain the reward model for the resulting system
153 std::unordered_map<std::string, typename SparseModelType::RewardModelType> rewardModels;
154 if (rewardModelName) {
155 storm::utility::vector::filterVectorInPlace(actionRewards, keptRows);
156 rewardModels.insert(std::make_pair(*rewardModelName, typename SparseModelType::RewardModelType(std::nullopt, std::move(actionRewards))));
157 }
158
159 return std::make_shared<SparseModelType>(std::move(newTransitionMatrix), model.getStateLabeling().getSubLabeling(selectedStates), std::move(rewardModels));
160}
161
162template<typename SparseModelType>
164 this->preserveParametricTransitions = preserveParametricTransitions;
165}
166
167template<typename SparseModelType>
169 return this->preserveParametricTransitions;
170}
171
174} // namespace transformer
175} // namespace storm
RewardOperatorFormula & asRewardOperatorFormula()
Definition Formula.cpp:484
virtual bool isReachabilityRewardFormula() const
Definition Formula.cpp:156
static std::shared_ptr< Formula const > getTrueFormula()
Definition Formula.cpp:213
virtual bool isReachabilityProbabilityFormula() const
Definition Formula.cpp:92
virtual bool isProbabilityOperatorFormula() const
Definition Formula.cpp:180
virtual bool isCumulativeRewardFormula() const
Definition Formula.cpp:144
ProbabilityOperatorFormula & asProbabilityOperatorFormula()
Definition Formula.cpp:476
virtual bool isUntilFormula() const
Definition Formula.cpp:80
virtual bool isRewardOperatorFormula() const
Definition Formula.cpp:184
EventuallyFormula & asEventuallyFormula()
Definition Formula.cpp:341
virtual bool isBoundedUntilFormula() const
Definition Formula.cpp:84
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:571
OperatorInformation const & getOperatorInformation() const
std::string const & getRewardModelName() const
Retrieves the name of the reward model this property refers to (if any).
bool hasRewardModelName() const
Retrieves whether the reward model refers to a specific reward model.
Formula const & getSubformula() const
Formula const & getSubformula() const
void eliminateState(storm::storage::sparse::state_type state, bool removeForwardTransitions)
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void complement()
Negates all bits in the bit vector.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
The flexible sparse matrix is used during state elimination.
storm::storage::SparseMatrix< ValueType > createSparseMatrix()
Creates a sparse matrix from the flexible sparse matrix.
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRowGroup(index_type rowGroup) const
Returns an object representing the given row group.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
index_type getRowGroupSize(index_type group) const
Returns the size of the given row group.
storm::storage::SparseMatrix< value_type > transpose(bool joinGroups=false, bool keepZeros=false) const
Transposes the matrix.
storm::storage::BitVector getRowFilter(storm::storage::BitVector const &groupConstraint) const
Returns a bitvector representing the set of rows, with all indices set that correspond to one of the ...
This class performs different steps to simplify the given (parametric) model.
void setPreserveParametricTransitions(bool preserveParametricTransitions)
Set whether to preserve parametric transions (i.e.
virtual bool simplifyForBoundedUntilProbabilities(storm::logic::ProbabilityOperatorFormula const &formula)
virtual bool simplifyForReachabilityProbabilities(storm::logic::ProbabilityOperatorFormula const &formula)
virtual bool simplifyForReachabilityRewards(storm::logic::RewardOperatorFormula const &formula)
std::shared_ptr< storm::logic::Formula const > getSimplifiedFormula() const
std::shared_ptr< SparseModelType > eliminateConstantDeterministicStates(SparseModelType const &model, storm::storage::BitVector const &consideredStates, boost::optional< std::string > const &rewardModelName=boost::none)
Eliminates all states that satisfy.
bool isPreserveParametricTransitionsSet() const
Whether this SparseParametricDtmcSimplifier preserves parametric transitions.
virtual bool simplifyForUntilProbabilities(storm::logic::ProbabilityOperatorFormula const &formula)
virtual bool simplifyForCumulativeRewards(storm::logic::RewardOperatorFormula const &formula)
#define STORM_LOG_DEBUG(message)
Definition logging.h:18
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
void filterVectorInPlace(std::vector< Type > &v, storm::storage::BitVector const &filter)
Definition vector.h:1071
bool isConstant(ValueType const &)