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
5
12
16
17namespace storm {
18namespace transformer {
19
20template<typename SparseModelType>
22 // intentionally left empty
23}
24
25template<typename SparseModelType>
27 // Make sure that there is no old result from a previous call
28 simplifiedModel = nullptr;
29 simplifiedFormula = nullptr;
30 if (formula.isProbabilityOperatorFormula()) {
32 if (probOpForm.getSubformula().isUntilFormula()) {
33 return simplifyForUntilProbabilities(probOpForm);
34 } else if (probOpForm.getSubformula().isReachabilityProbabilityFormula()) {
35 return simplifyForReachabilityProbabilities(probOpForm);
36 } else if (probOpForm.getSubformula().isBoundedUntilFormula()) {
37 return simplifyForBoundedUntilProbabilities(probOpForm);
38 }
39 } else if (formula.isRewardOperatorFormula()) {
41 STORM_LOG_THROW((rewOpForm.hasRewardModelName() && originalModel.hasRewardModel(rewOpForm.getRewardModelName())) ||
42 (!rewOpForm.hasRewardModelName() && originalModel.hasUniqueRewardModel()),
43 storm::exceptions::InvalidPropertyException,
44 "The reward model specified by formula " << formula << " is not available in the given model.");
46 return simplifyForReachabilityRewards(rewOpForm);
47 } else if (rewOpForm.getSubformula().isCumulativeRewardFormula()) {
48 return simplifyForCumulativeRewards(rewOpForm);
49 }
50 }
51 // reaching this point means that the provided formula is not supported. Thus, no simplification is possible.
52 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
53 return false;
54}
55
56template<typename SparseModelType>
58 STORM_LOG_THROW(simplifiedModel, storm::exceptions::InvalidStateException, "Tried to get the simplified model but simplification was not invoked before.");
59 return simplifiedModel;
60}
61
62template<typename SparseModelType>
63std::shared_ptr<storm::logic::Formula const> SparseParametricModelSimplifier<SparseModelType>::getSimplifiedFormula() const {
64 STORM_LOG_THROW(simplifiedFormula, storm::exceptions::InvalidStateException,
65 "Tried to get the simplified formula but simplification was not invoked before.");
66 return simplifiedFormula;
67}
68
69template<typename SparseModelType>
71 // If this method was not overridden by any subclass, simplification is not possible
72 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
73 return false;
74}
75
76template<typename SparseModelType>
78 // transform to until formula
79 auto untilFormula = std::make_shared<storm::logic::UntilFormula const>(storm::logic::Formula::getTrueFormula(),
81 return simplifyForUntilProbabilities(storm::logic::ProbabilityOperatorFormula(untilFormula, formula.getOperatorInformation()));
82}
83
84template<typename SparseModelType>
86 // If this method was not overridden by any subclass, simplification is not possible
87 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
88 return false;
89}
90
91template<typename SparseModelType>
93 // If this method was not overridden by any subclass, simplification is not possible
94 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
95 return false;
96}
97
98template<typename SparseModelType>
100 // If this method was not overridden by any subclass, simplification is not possible
101 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
102 return false;
103}
104
105template<typename SparseModelType>
107 SparseModelType const& model, storm::storage::BitVector const& consideredStates, boost::optional<std::string> const& rewardModelName) {
108 storm::storage::SparseMatrix<typename SparseModelType::ValueType> const& sparseMatrix = model.getTransitionMatrix();
109 auto backwardsSparseMatrix = sparseMatrix.transpose();
110
111 // get the action-based reward values
112 std::vector<typename SparseModelType::ValueType> actionRewards;
113 if (rewardModelName) {
114 actionRewards = model.getRewardModel(*rewardModelName).getTotalRewardVector(sparseMatrix);
115 } else {
116 actionRewards = std::vector<typename SparseModelType::ValueType>(model.getTransitionMatrix().getRowCount(),
117 storm::utility::zero<typename SparseModelType::ValueType>());
118 }
119
120 // Find the states that are to be eliminated
121 storm::storage::BitVector selectedStates = consideredStates;
122 for (auto state : consideredStates) {
123 if (sparseMatrix.getRowGroupSize(state) == 1 &&
124 (!rewardModelName.is_initialized() || storm::utility::isConstant(actionRewards[sparseMatrix.getRowGroupIndices()[state]]))) {
125 for (auto const& entry : sparseMatrix.getRowGroup(state)) {
126 if (!storm::utility::isConstant(entry.getValue())) {
127 selectedStates.set(state, false);
128 break;
129 }
130 }
131 if (state && this->preserveParametricTransitions) {
132 for (auto const& entry : backwardsSparseMatrix.getRowGroup(state)) {
133 if (!storm::utility::isConstant(entry.getValue())) {
134 selectedStates.set(state, false);
135 break;
136 }
137 }
138 }
139 } else {
140 selectedStates.set(state, false);
141 }
142 }
143
144 // invoke elimination and obtain resulting transition matrix
146 storm::storage::FlexibleSparseMatrix<typename SparseModelType::ValueType> flexibleBackwardTransitions(backwardsSparseMatrix, true);
148 flexibleMatrix, flexibleBackwardTransitions, actionRewards);
149 for (auto state : selectedStates) {
150 stateEliminator.eliminateState(state, true);
151 }
152 selectedStates.complement();
153 auto keptRows = sparseMatrix.getRowFilter(selectedStates);
154 storm::storage::SparseMatrix<typename SparseModelType::ValueType> newTransitionMatrix = flexibleMatrix.createSparseMatrix(keptRows, selectedStates);
155
156 // obtain the reward model for the resulting system
157 std::unordered_map<std::string, typename SparseModelType::RewardModelType> rewardModels;
158 if (rewardModelName) {
159 storm::utility::vector::filterVectorInPlace(actionRewards, keptRows);
160 rewardModels.insert(std::make_pair(*rewardModelName, typename SparseModelType::RewardModelType(std::nullopt, std::move(actionRewards))));
161 }
162
163 return std::make_shared<SparseModelType>(std::move(newTransitionMatrix), model.getStateLabeling().getSubLabeling(selectedStates), std::move(rewardModels));
164}
165
166template<typename SparseModelType>
168 this->preserveParametricTransitions = preserveParametricTransitions;
169}
170
171template<typename SparseModelType>
173 return this->preserveParametricTransitions;
174}
175
178} // namespace transformer
179} // 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:1075
bool isConstant(ValueType const &)
Definition constants.cpp:67
LabParser.cpp.