Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseParametricModelSimplifier.cpp
Go to the documentation of this file.
2
4
11
15
16namespace storm {
17namespace transformer {
18
19template<typename SparseModelType>
21 // intentionally left empty
22}
23
24template<typename SparseModelType>
26 // Make sure that there is no old result from a previous call
27 simplifiedModel = nullptr;
28 simplifiedFormula = nullptr;
29 if (formula.isProbabilityOperatorFormula()) {
31 if (probOpForm.getSubformula().isUntilFormula()) {
32 return simplifyForUntilProbabilities(probOpForm);
33 } else if (probOpForm.getSubformula().isReachabilityProbabilityFormula()) {
34 return simplifyForReachabilityProbabilities(probOpForm);
35 } else if (probOpForm.getSubformula().isBoundedUntilFormula()) {
36 return simplifyForBoundedUntilProbabilities(probOpForm);
37 }
38 } else if (formula.isRewardOperatorFormula()) {
40 STORM_LOG_THROW((rewOpForm.hasRewardModelName() && originalModel.hasRewardModel(rewOpForm.getRewardModelName())) ||
41 (!rewOpForm.hasRewardModelName() && originalModel.hasUniqueRewardModel()),
42 storm::exceptions::InvalidPropertyException,
43 "The reward model specified by formula " << formula << " is not available in the given model.");
45 return simplifyForReachabilityRewards(rewOpForm);
46 } else if (rewOpForm.getSubformula().isCumulativeRewardFormula()) {
47 return simplifyForCumulativeRewards(rewOpForm);
48 }
49 }
50 // reaching this point means that the provided formula is not supported. Thus, no simplification is possible.
51 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
52 return false;
53}
54
55template<typename SparseModelType>
57 STORM_LOG_THROW(simplifiedModel, storm::exceptions::InvalidStateException, "Tried to get the simplified model but simplification was not invoked before.");
58 return simplifiedModel;
59}
60
61template<typename SparseModelType>
62std::shared_ptr<storm::logic::Formula const> SparseParametricModelSimplifier<SparseModelType>::getSimplifiedFormula() const {
63 STORM_LOG_THROW(simplifiedFormula, storm::exceptions::InvalidStateException,
64 "Tried to get the simplified formula but simplification was not invoked before.");
65 return simplifiedFormula;
66}
67
68template<typename SparseModelType>
70 // If this method was not overridden by any subclass, simplification is not possible
71 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
72 return false;
73}
74
75template<typename SparseModelType>
77 // transform to until formula
78 auto untilFormula = std::make_shared<storm::logic::UntilFormula const>(storm::logic::Formula::getTrueFormula(),
80 return simplifyForUntilProbabilities(storm::logic::ProbabilityOperatorFormula(untilFormula, formula.getOperatorInformation()));
81}
82
83template<typename SparseModelType>
85 // If this method was not overridden by any subclass, simplification is not possible
86 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
87 return false;
88}
89
90template<typename SparseModelType>
92 // If this method was not overridden by any subclass, simplification is not possible
93 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
94 return false;
95}
96
97template<typename SparseModelType>
99 // If this method was not overridden by any subclass, simplification is not possible
100 STORM_LOG_DEBUG("Simplification not possible because the formula is not supported. Formula: " << formula);
101 return false;
102}
103
104template<typename SparseModelType>
106 SparseModelType const& model, storm::storage::BitVector const& consideredStates, boost::optional<std::string> const& rewardModelName) {
107 storm::storage::SparseMatrix<typename SparseModelType::ValueType> const& sparseMatrix = model.getTransitionMatrix();
108
109 // get the action-based reward values
110 std::vector<typename SparseModelType::ValueType> actionRewards;
111 if (rewardModelName) {
112 actionRewards = model.getRewardModel(*rewardModelName).getTotalRewardVector(sparseMatrix);
113 } else {
114 actionRewards = std::vector<typename SparseModelType::ValueType>(model.getTransitionMatrix().getRowCount(),
115 storm::utility::zero<typename SparseModelType::ValueType>());
116 }
117
118 // Find the states that are to be eliminated
119 storm::storage::BitVector selectedStates = consideredStates;
120 for (auto state : consideredStates) {
121 if (sparseMatrix.getRowGroupSize(state) == 1 &&
122 (!rewardModelName.is_initialized() || storm::utility::isConstant(actionRewards[sparseMatrix.getRowGroupIndices()[state]]))) {
123 for (auto const& entry : sparseMatrix.getRowGroup(state)) {
124 if (!storm::utility::isConstant(entry.getValue())) {
125 selectedStates.set(state, false);
126 break;
127 }
128 }
129 } else {
130 selectedStates.set(state, false);
131 }
132 }
133
134 // invoke elimination and obtain resulting transition matrix
136 storm::storage::FlexibleSparseMatrix<typename SparseModelType::ValueType> flexibleBackwardTransitions(sparseMatrix.transpose(), true);
138 flexibleMatrix, flexibleBackwardTransitions, actionRewards);
139 for (auto state : selectedStates) {
140 stateEliminator.eliminateState(state, true);
141 }
142 selectedStates.complement();
143 auto keptRows = sparseMatrix.getRowFilter(selectedStates);
144 storm::storage::SparseMatrix<typename SparseModelType::ValueType> newTransitionMatrix = flexibleMatrix.createSparseMatrix(keptRows, selectedStates);
145
146 // obtain the reward model for the resulting system
147 std::unordered_map<std::string, typename SparseModelType::RewardModelType> rewardModels;
148 if (rewardModelName) {
149 storm::utility::vector::filterVectorInPlace(actionRewards, keptRows);
150 rewardModels.insert(std::make_pair(*rewardModelName, typename SparseModelType::RewardModelType(std::nullopt, std::move(actionRewards))));
151 }
152
153 return std::make_shared<SparseModelType>(std::move(newTransitionMatrix), model.getStateLabeling().getSubLabeling(selectedStates), std::move(rewardModels));
154}
155
158} // namespace transformer
159} // namespace storm
RewardOperatorFormula & asRewardOperatorFormula()
Definition Formula.cpp:461
virtual bool isReachabilityRewardFormula() const
Definition Formula.cpp:152
static std::shared_ptr< Formula const > getTrueFormula()
Definition Formula.cpp:205
virtual bool isReachabilityProbabilityFormula() const
Definition Formula.cpp:92
virtual bool isProbabilityOperatorFormula() const
Definition Formula.cpp:172
virtual bool isCumulativeRewardFormula() const
Definition Formula.cpp:144
ProbabilityOperatorFormula & asProbabilityOperatorFormula()
Definition Formula.cpp:453
virtual bool isUntilFormula() const
Definition Formula.cpp:80
virtual bool isRewardOperatorFormula() const
Definition Formula.cpp:176
EventuallyFormula & asEventuallyFormula()
Definition Formula.cpp:333
virtual bool isBoundedUntilFormula() const
Definition Formula.cpp:84
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:548
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:18
void complement()
Negates all bits in the bit vector.
void set(uint_fast64_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.
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
static 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.
virtual bool simplifyForUntilProbabilities(storm::logic::ProbabilityOperatorFormula const &formula)
virtual bool simplifyForCumulativeRewards(storm::logic::RewardOperatorFormula const &formula)
#define STORM_LOG_DEBUG(message)
Definition logging.h:23
#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:1224
bool isConstant(ValueType const &)
Definition constants.cpp:66
LabParser.cpp.
Definition cli.cpp:18