Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseParametricDtmcSimplifier.cpp
Go to the documentation of this file.
2
3#include <optional>
4
13#include "storm/utility/graph.h"
14
15namespace storm {
16namespace transformer {
17
18template<typename SparseModelType>
20 : SparseParametricModelSimplifier<SparseModelType>(model) {
21 // intentionally left empty
22}
23
24template<typename SparseModelType>
26 // Get the prob0, prob1 and the maybeStates
28 if (!propositionalChecker.canHandle(formula.getSubformula().asUntilFormula().getLeftSubformula()) ||
29 !propositionalChecker.canHandle(formula.getSubformula().asUntilFormula().getRightSubformula())) {
30 STORM_LOG_DEBUG("Can not simplify when Until-formula has non-propositional subformula(s). Formula: " << formula);
31 return false;
32 }
33 storm::storage::BitVector phiStates = std::move(propositionalChecker.check(formula.getSubformula().asUntilFormula().getLeftSubformula())
34 ->template asExplicitQualitativeCheckResult<typename SparseModelType::ValueType>()
35 .getTruthValuesVector());
36 storm::storage::BitVector psiStates = std::move(propositionalChecker.check(formula.getSubformula().asUntilFormula().getRightSubformula())
37 ->template asExplicitQualitativeCheckResult<typename SparseModelType::ValueType>()
38 .getTruthValuesVector());
39 std::pair<storm::storage::BitVector, storm::storage::BitVector> statesWithProbability01 =
40 storm::utility::graph::performProb01(this->originalModel, phiStates, psiStates);
41 // Only consider the maybestates that are reachable from one initial state without hopping over a target (i.e., prob1) state
43 this->originalModel.getTransitionMatrix(), this->originalModel.getInitialStates() & ~statesWithProbability01.first, ~statesWithProbability01.first,
44 statesWithProbability01.second);
45 storm::storage::BitVector maybeStates = reachableGreater0States & ~statesWithProbability01.second;
46
47 // obtain the resulting subsystem
50 goalStateMerger.mergeTargetAndSinkStates(maybeStates, statesWithProbability01.second, statesWithProbability01.first);
51 this->simplifiedModel = mergerResult.model;
52 statesWithProbability01.second = storm::storage::BitVector(this->simplifiedModel->getNumberOfStates(), false);
53 if (mergerResult.targetState) {
54 statesWithProbability01.second.set(mergerResult.targetState.get(), true);
55 }
56 std::string targetLabel = "target";
57 while (this->simplifiedModel->hasLabel(targetLabel)) {
58 targetLabel = "_" + targetLabel;
59 }
60 this->simplifiedModel->getStateLabeling().addLabel(targetLabel, std::move(statesWithProbability01.second));
61
62 // obtain the simplified formula for the simplified model
63 auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula const>(targetLabel);
64 auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula const>(labelFormula, storm::logic::FormulaContext::Probability);
65 this->simplifiedFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula const>(eventuallyFormula, formula.getOperatorInformation());
66
67 // Eliminate all states for which all outgoing transitions are constant
68 storm::storage::BitVector considerForElimination = ~this->simplifiedModel->getInitialStates();
69 if (mergerResult.targetState) {
70 considerForElimination.set(*mergerResult.targetState, false);
71 }
72 if (mergerResult.sinkState) {
73 considerForElimination.set(*mergerResult.sinkState, false);
74 }
75 this->simplifiedModel = this->eliminateConstantDeterministicStates(*this->simplifiedModel, considerForElimination);
76
77 return true;
78}
79
80template<typename SparseModelType>
82 STORM_LOG_THROW(!formula.getSubformula().asBoundedUntilFormula().hasLowerBound(), storm::exceptions::NotSupportedException,
83 "Lower step bounds are not supported.");
84 STORM_LOG_THROW(formula.getSubformula().asBoundedUntilFormula().hasUpperBound(), storm::exceptions::UnexpectedException,
85 "Expected a bounded until formula with an upper bound.");
87 storm::exceptions::UnexpectedException, "Expected a bounded until formula with integral bounds.");
88
89 uint_fast64_t upperStepBound = formula.getSubformula().asBoundedUntilFormula().getUpperBound().evaluateAsInt();
91 STORM_LOG_THROW(upperStepBound > 0, storm::exceptions::UnexpectedException, "Expected a strict upper bound that is greater than zero.");
92 --upperStepBound;
93 }
94
95 // Get the prob0, target, and the maybeStates
97 if (!propositionalChecker.canHandle(formula.getSubformula().asBoundedUntilFormula().getLeftSubformula()) ||
98 !propositionalChecker.canHandle(formula.getSubformula().asBoundedUntilFormula().getRightSubformula())) {
99 STORM_LOG_DEBUG("Can not simplify when Until-formula has non-propositional subformula(s). Formula: " << formula);
100 return false;
101 }
102 storm::storage::BitVector phiStates = std::move(propositionalChecker.check(formula.getSubformula().asBoundedUntilFormula().getLeftSubformula())
103 ->template asExplicitQualitativeCheckResult<typename SparseModelType::ValueType>()
104 .getTruthValuesVector());
105 storm::storage::BitVector psiStates = std::move(propositionalChecker.check(formula.getSubformula().asBoundedUntilFormula().getRightSubformula())
106 ->template asExplicitQualitativeCheckResult<typename SparseModelType::ValueType>()
107 .getTruthValuesVector());
108 storm::storage::BitVector probGreater0States =
109 storm::utility::graph::performProbGreater0(this->originalModel.getBackwardTransitions(), phiStates, psiStates, true, upperStepBound);
110
111 // Only consider the maybestates that are reachable from one initial probGreater0 state within the given amount of steps and without hopping over a target
112 // state
113 storm::storage::BitVector reachableGreater0States =
114 storm::utility::graph::getReachableStates(this->originalModel.getTransitionMatrix(), this->originalModel.getInitialStates() & probGreater0States,
115 probGreater0States, psiStates, true, upperStepBound);
116 storm::storage::BitVector maybeStates = reachableGreater0States & ~psiStates;
117 storm::storage::BitVector prob0States = ~reachableGreater0States & ~psiStates;
118
119 // obtain the resulting subsystem
122 goalStateMerger.mergeTargetAndSinkStates(maybeStates, psiStates, prob0States);
123 this->simplifiedModel = mergerResult.model;
124 psiStates = storm::storage::BitVector(this->simplifiedModel->getNumberOfStates(), false);
125 if (mergerResult.targetState) {
126 psiStates.set(mergerResult.targetState.get(), true);
127 }
128 std::string targetLabel = "target";
129 while (this->simplifiedModel->hasLabel(targetLabel)) {
130 targetLabel = "_" + targetLabel;
131 }
132 this->simplifiedModel->getStateLabeling().addLabel(targetLabel, std::move(psiStates));
133
134 // obtain the simplified formula for the simplified model
135 auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula const>(targetLabel);
136 auto boundedUntilFormula =
137 std::make_shared<storm::logic::BoundedUntilFormula const>(storm::logic::Formula::getTrueFormula(), labelFormula, std::nullopt,
141 this->simplifiedFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula const>(boundedUntilFormula, formula.getOperatorInformation());
142
143 return true;
144}
145
146template<typename SparseModelType>
148 typename SparseModelType::RewardModelType const& originalRewardModel =
149 formula.hasRewardModelName() ? this->originalModel.getRewardModel(formula.getRewardModelName()) : this->originalModel.getUniqueRewardModel();
150
151 // Get the prob1 and the maybeStates
153 if (!propositionalChecker.canHandle(formula.getSubformula().asEventuallyFormula().getSubformula())) {
154 STORM_LOG_DEBUG("Can not simplify when reachability reward formula has non-propositional subformula(s). Formula: " << formula);
155 return false;
156 }
157 storm::storage::BitVector targetStates = std::move(propositionalChecker.check(formula.getSubformula().asEventuallyFormula().getSubformula())
158 ->template asExplicitQualitativeCheckResult<typename SparseModelType::ValueType>()
159 .getTruthValuesVector());
160 // The set of target states can be extended by the states that reach target with probability 1 without collecting any reward
161 targetStates = storm::utility::graph::performProb1(this->originalModel.getBackwardTransitions(),
162 originalRewardModel.getStatesWithZeroReward(this->originalModel.getTransitionMatrix()), targetStates);
164 this->originalModel.getBackwardTransitions(), storm::storage::BitVector(this->originalModel.getNumberOfStates(), true), targetStates);
165 storm::storage::BitVector infinityStates = ~statesWithProb1;
166 // Only consider the states that are reachable from an initial state without hopping over a target state
168 this->originalModel.getTransitionMatrix(), this->originalModel.getInitialStates() & statesWithProb1, statesWithProb1, targetStates);
169 storm::storage::BitVector maybeStates = reachableStates & ~targetStates;
170
171 // obtain the resulting subsystem
172 std::vector<std::string> rewardModelNameAsVector(
173 1, formula.hasRewardModelName() ? formula.getRewardModelName() : this->originalModel.getRewardModels().begin()->first);
176 goalStateMerger.mergeTargetAndSinkStates(maybeStates, targetStates, infinityStates, rewardModelNameAsVector);
177 this->simplifiedModel = mergerResult.model;
178 targetStates = storm::storage::BitVector(this->simplifiedModel->getNumberOfStates(), false);
179 if (mergerResult.targetState) {
180 targetStates.set(mergerResult.targetState.get(), true);
181 }
182 std::string targetLabel = "target";
183 while (this->simplifiedModel->hasLabel(targetLabel)) {
184 targetLabel = "_" + targetLabel;
185 }
186 this->simplifiedModel->getStateLabeling().addLabel(targetLabel, std::move(targetStates));
187
188 // obtain the simplified formula for the simplified model
189 auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula const>(targetLabel);
190 auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula const>(labelFormula, storm::logic::FormulaContext::Reward);
191 this->simplifiedFormula =
192 std::make_shared<storm::logic::RewardOperatorFormula const>(eventuallyFormula, rewardModelNameAsVector.front(), formula.getOperatorInformation());
193
194 // Eliminate all states for which all outgoing transitions are constant
195 storm::storage::BitVector considerForElimination = ~this->simplifiedModel->getInitialStates();
196 if (mergerResult.targetState) {
197 considerForElimination.set(*mergerResult.targetState, false);
198 }
199 if (mergerResult.sinkState) {
200 considerForElimination.set(*mergerResult.sinkState, false);
201 }
202 this->simplifiedModel = this->eliminateConstantDeterministicStates(*this->simplifiedModel, considerForElimination, rewardModelNameAsVector.front());
203
204 return true;
205}
206
207template<typename SparseModelType>
210 storm::exceptions::UnexpectedException, "Expected a cumulative reward formula with integral bound.");
211
212 typename SparseModelType::RewardModelType const& originalRewardModel =
213 formula.hasRewardModelName() ? this->originalModel.getRewardModel(formula.getRewardModelName()) : this->originalModel.getUniqueRewardModel();
214
215 uint_fast64_t stepBound = formula.getSubformula().asCumulativeRewardFormula().getBound().evaluateAsInt();
217 STORM_LOG_THROW(stepBound > 0, storm::exceptions::UnexpectedException, "Expected a strict upper bound that is greater than zero.");
218 --stepBound;
219 }
220
221 // Get the states with non-zero reward
223 this->originalModel.getBackwardTransitions(), storm::storage::BitVector(this->originalModel.getNumberOfStates(), true),
224 ~originalRewardModel.getStatesWithZeroReward(this->originalModel.getTransitionMatrix()), true, stepBound);
225 storm::storage::BitVector zeroRewardStates = ~maybeStates;
226 storm::storage::BitVector noStates(this->originalModel.getNumberOfStates(), false);
227
228 // obtain the resulting subsystem
229 std::vector<std::string> rewardModelNameAsVector(
230 1, formula.hasRewardModelName() ? formula.getRewardModelName() : this->originalModel.getRewardModels().begin()->first);
233 goalStateMerger.mergeTargetAndSinkStates(maybeStates, noStates, zeroRewardStates, rewardModelNameAsVector);
234 this->simplifiedModel = mergerResult.model;
235
236 // obtain the simplified formula for the simplified model
238
239 return true;
240}
241
243} // namespace transformer
244} // namespace storm
virtual bool isIntegerLiteralExpression() const
int_fast64_t evaluateAsInt(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of variables given by the valuation and returns the resu...
BaseExpression const & getBaseExpression() const
Retrieves the base expression underlying this expression object.
Formula const & getRightSubformula() const
Formula const & getLeftSubformula() const
storm::expressions::Expression const & getUpperBound(unsigned i=0) const
bool isUpperBoundStrict(unsigned i=0) const
std::shared_ptr< Formula > clone(Formula const &f) const
storm::expressions::Expression const & getBound() const
UntilFormula & asUntilFormula()
Definition Formula.cpp:325
BoundedUntilFormula & asBoundedUntilFormula()
Definition Formula.cpp:333
static std::shared_ptr< Formula const > getTrueFormula()
Definition Formula.cpp:213
EventuallyFormula & asEventuallyFormula()
Definition Formula.cpp:341
CumulativeRewardFormula & asCumulativeRewardFormula()
Definition Formula.cpp:429
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
virtual std::unique_ptr< CheckResult > check(Environment const &env, CheckTask< storm::logic::Formula, SolutionType > const &checkTask)
Checks the provided formula.
virtual bool canHandle(CheckTask< storm::logic::Formula, SolutionType > const &checkTask) const override
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
ReturnType mergeTargetAndSinkStates(storm::storage::BitVector const &maybeStates, storm::storage::BitVector const &targetStates, storm::storage::BitVector const &sinkStates, std::vector< std::string > const &selectedRewardModels=std::vector< std::string >(), boost::optional< storm::storage::BitVector > const &choiceFilter=boost::none) const
This class performs different steps to simplify the given (parametric) model.
virtual bool simplifyForReachabilityRewards(storm::logic::RewardOperatorFormula const &formula) override
virtual bool simplifyForCumulativeRewards(storm::logic::RewardOperatorFormula const &formula) override
virtual bool simplifyForUntilProbabilities(storm::logic::ProbabilityOperatorFormula const &formula) override
virtual bool simplifyForBoundedUntilProbabilities(storm::logic::ProbabilityOperatorFormula const &formula) override
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.
std::shared_ptr< storm::logic::Formula const > simplifiedFormula
#define STORM_LOG_DEBUG(message)
Definition logging.h:21
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
std::pair< storm::storage::BitVector, storm::storage::BitVector > performProb01(storm::models::sparse::DeterministicModel< T > const &model, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates)
Computes the sets of states that have probability 0 or 1, respectively, of satisfying phi until psi i...
Definition graph.cpp:393
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...
Definition graph.cpp:41
storm::storage::BitVector performProbGreater0(storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates, bool useStepBound, uint_fast64_t maximalSteps)
Performs a backward depth-first search trough the underlying graph structure of the given model to de...
Definition graph.cpp:315
storm::storage::BitVector performProb1(storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &, storm::storage::BitVector const &psiStates, storm::storage::BitVector const &statesWithProbabilityGreater0)
Computes the set of states of the given model for which all paths lead to the given set of target sta...
Definition graph.cpp:376
boost::optional< uint_fast64_t > sinkState
std::shared_ptr< SparseModelType > model
boost::optional< uint_fast64_t > targetState