Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseParametricDtmcSimplifier.cpp
Go to the documentation of this file.
2
12#include "storm/utility/graph.h"
13
14namespace storm {
15namespace transformer {
16
17template<typename SparseModelType>
19 : SparseParametricModelSimplifier<SparseModelType>(model) {
20 // intentionally left empty
21}
22
23template<typename SparseModelType>
25 // Get the prob0, prob1 and the maybeStates
26 storm::modelchecker::SparsePropositionalModelChecker<SparseModelType> propositionalChecker(this->originalModel);
27 if (!propositionalChecker.canHandle(formula.getSubformula().asUntilFormula().getLeftSubformula()) ||
28 !propositionalChecker.canHandle(formula.getSubformula().asUntilFormula().getRightSubformula())) {
29 STORM_LOG_DEBUG("Can not simplify when Until-formula has non-propositional subformula(s). Formula: " << formula);
30 return false;
31 }
32 storm::storage::BitVector phiStates = std::move(
33 propositionalChecker.check(formula.getSubformula().asUntilFormula().getLeftSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
34 storm::storage::BitVector psiStates = std::move(
35 propositionalChecker.check(formula.getSubformula().asUntilFormula().getRightSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
36 std::pair<storm::storage::BitVector, storm::storage::BitVector> statesWithProbability01 =
37 storm::utility::graph::performProb01(this->originalModel, phiStates, psiStates);
38 // Only consider the maybestates that are reachable from one initial state without hopping over a target (i.e., prob1) state
40 this->originalModel.getTransitionMatrix(), this->originalModel.getInitialStates() & ~statesWithProbability01.first, ~statesWithProbability01.first,
41 statesWithProbability01.second);
42 storm::storage::BitVector maybeStates = reachableGreater0States & ~statesWithProbability01.second;
43
44 // obtain the resulting subsystem
45 storm::transformer::GoalStateMerger<SparseModelType> goalStateMerger(this->originalModel);
47 goalStateMerger.mergeTargetAndSinkStates(maybeStates, statesWithProbability01.second, statesWithProbability01.first);
48 this->simplifiedModel = mergerResult.model;
49 statesWithProbability01.second = storm::storage::BitVector(this->simplifiedModel->getNumberOfStates(), false);
50 if (mergerResult.targetState) {
51 statesWithProbability01.second.set(mergerResult.targetState.get(), true);
52 }
53 std::string targetLabel = "target";
54 while (this->simplifiedModel->hasLabel(targetLabel)) {
55 targetLabel = "_" + targetLabel;
56 }
57 this->simplifiedModel->getStateLabeling().addLabel(targetLabel, std::move(statesWithProbability01.second));
58
59 // obtain the simplified formula for the simplified model
60 auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula const>(targetLabel);
61 auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula const>(labelFormula, storm::logic::FormulaContext::Probability);
62 this->simplifiedFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula const>(eventuallyFormula, formula.getOperatorInformation());
63
64 // Eliminate all states for which all outgoing transitions are constant
65 storm::storage::BitVector considerForElimination = ~this->simplifiedModel->getInitialStates();
66 if (mergerResult.targetState) {
67 considerForElimination.set(*mergerResult.targetState, false);
68 }
69 if (mergerResult.sinkState) {
70 considerForElimination.set(*mergerResult.sinkState, false);
71 }
72 this->simplifiedModel = this->eliminateConstantDeterministicStates(*this->simplifiedModel, considerForElimination);
73
74 return true;
75}
76
77template<typename SparseModelType>
79 STORM_LOG_THROW(!formula.getSubformula().asBoundedUntilFormula().hasLowerBound(), storm::exceptions::NotSupportedException,
80 "Lower step bounds are not supported.");
81 STORM_LOG_THROW(formula.getSubformula().asBoundedUntilFormula().hasUpperBound(), storm::exceptions::UnexpectedException,
82 "Expected a bounded until formula with an upper bound.");
84 storm::exceptions::UnexpectedException, "Expected a bounded until formula with integral bounds.");
85
86 uint_fast64_t upperStepBound = formula.getSubformula().asBoundedUntilFormula().getUpperBound().evaluateAsInt();
88 STORM_LOG_THROW(upperStepBound > 0, storm::exceptions::UnexpectedException, "Expected a strict upper bound that is greater than zero.");
89 --upperStepBound;
90 }
91
92 // Get the prob0, target, and the maybeStates
93 storm::modelchecker::SparsePropositionalModelChecker<SparseModelType> propositionalChecker(this->originalModel);
94 if (!propositionalChecker.canHandle(formula.getSubformula().asBoundedUntilFormula().getLeftSubformula()) ||
95 !propositionalChecker.canHandle(formula.getSubformula().asBoundedUntilFormula().getRightSubformula())) {
96 STORM_LOG_DEBUG("Can not simplify when Until-formula has non-propositional subformula(s). Formula: " << formula);
97 return false;
98 }
99 storm::storage::BitVector phiStates = std::move(propositionalChecker.check(formula.getSubformula().asBoundedUntilFormula().getLeftSubformula())
100 ->asExplicitQualitativeCheckResult()
101 .getTruthValuesVector());
102 storm::storage::BitVector psiStates = std::move(propositionalChecker.check(formula.getSubformula().asBoundedUntilFormula().getRightSubformula())
103 ->asExplicitQualitativeCheckResult()
104 .getTruthValuesVector());
105 storm::storage::BitVector probGreater0States =
106 storm::utility::graph::performProbGreater0(this->originalModel.getBackwardTransitions(), phiStates, psiStates, true, upperStepBound);
107
108 // Only consider the maybestates that are reachable from one initial probGreater0 state within the given amount of steps and without hopping over a target
109 // state
110 storm::storage::BitVector reachableGreater0States =
111 storm::utility::graph::getReachableStates(this->originalModel.getTransitionMatrix(), this->originalModel.getInitialStates() & probGreater0States,
112 probGreater0States, psiStates, true, upperStepBound);
113 storm::storage::BitVector maybeStates = reachableGreater0States & ~psiStates;
114 storm::storage::BitVector prob0States = ~reachableGreater0States & ~psiStates;
115
116 // obtain the resulting subsystem
117 storm::transformer::GoalStateMerger<SparseModelType> goalStateMerger(this->originalModel);
119 goalStateMerger.mergeTargetAndSinkStates(maybeStates, psiStates, prob0States);
120 this->simplifiedModel = mergerResult.model;
121 psiStates = storm::storage::BitVector(this->simplifiedModel->getNumberOfStates(), false);
122 if (mergerResult.targetState) {
123 psiStates.set(mergerResult.targetState.get(), true);
124 }
125 std::string targetLabel = "target";
126 while (this->simplifiedModel->hasLabel(targetLabel)) {
127 targetLabel = "_" + targetLabel;
128 }
129 this->simplifiedModel->getStateLabeling().addLabel(targetLabel, std::move(psiStates));
130
131 // obtain the simplified formula for the simplified model
132 auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula const>(targetLabel);
133 auto boundedUntilFormula =
134 std::make_shared<storm::logic::BoundedUntilFormula const>(storm::logic::Formula::getTrueFormula(), labelFormula, boost::none,
138 this->simplifiedFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula const>(boundedUntilFormula, formula.getOperatorInformation());
139
140 return true;
141}
142
143template<typename SparseModelType>
145 typename SparseModelType::RewardModelType const& originalRewardModel =
146 formula.hasRewardModelName() ? this->originalModel.getRewardModel(formula.getRewardModelName()) : this->originalModel.getUniqueRewardModel();
147
148 // Get the prob1 and the maybeStates
149 storm::modelchecker::SparsePropositionalModelChecker<SparseModelType> propositionalChecker(this->originalModel);
150 if (!propositionalChecker.canHandle(formula.getSubformula().asEventuallyFormula().getSubformula())) {
151 STORM_LOG_DEBUG("Can not simplify when reachability reward formula has non-propositional subformula(s). Formula: " << formula);
152 return false;
153 }
154 storm::storage::BitVector targetStates = std::move(
155 propositionalChecker.check(formula.getSubformula().asEventuallyFormula().getSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
156 // The set of target states can be extended by the states that reach target with probability 1 without collecting any reward
157 targetStates = storm::utility::graph::performProb1(this->originalModel.getBackwardTransitions(),
158 originalRewardModel.getStatesWithZeroReward(this->originalModel.getTransitionMatrix()), targetStates);
160 this->originalModel.getBackwardTransitions(), storm::storage::BitVector(this->originalModel.getNumberOfStates(), true), targetStates);
161 storm::storage::BitVector infinityStates = ~statesWithProb1;
162 // Only consider the states that are reachable from an initial state without hopping over a target state
164 this->originalModel.getTransitionMatrix(), this->originalModel.getInitialStates() & statesWithProb1, statesWithProb1, targetStates);
165 storm::storage::BitVector maybeStates = reachableStates & ~targetStates;
166
167 // obtain the resulting subsystem
168 std::vector<std::string> rewardModelNameAsVector(
169 1, formula.hasRewardModelName() ? formula.getRewardModelName() : this->originalModel.getRewardModels().begin()->first);
170 storm::transformer::GoalStateMerger<SparseModelType> goalStateMerger(this->originalModel);
172 goalStateMerger.mergeTargetAndSinkStates(maybeStates, targetStates, infinityStates, rewardModelNameAsVector);
173 this->simplifiedModel = mergerResult.model;
174 targetStates = storm::storage::BitVector(this->simplifiedModel->getNumberOfStates(), false);
175 if (mergerResult.targetState) {
176 targetStates.set(mergerResult.targetState.get(), true);
177 }
178 std::string targetLabel = "target";
179 while (this->simplifiedModel->hasLabel(targetLabel)) {
180 targetLabel = "_" + targetLabel;
181 }
182 this->simplifiedModel->getStateLabeling().addLabel(targetLabel, std::move(targetStates));
183
184 // obtain the simplified formula for the simplified model
185 auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula const>(targetLabel);
186 auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula const>(labelFormula, storm::logic::FormulaContext::Reward);
187 this->simplifiedFormula =
188 std::make_shared<storm::logic::RewardOperatorFormula const>(eventuallyFormula, rewardModelNameAsVector.front(), formula.getOperatorInformation());
189
190 // Eliminate all states for which all outgoing transitions are constant
191 storm::storage::BitVector considerForElimination = ~this->simplifiedModel->getInitialStates();
192 if (mergerResult.targetState) {
193 considerForElimination.set(*mergerResult.targetState, false);
194 }
195 if (mergerResult.sinkState) {
196 considerForElimination.set(*mergerResult.sinkState, false);
197 }
198 this->simplifiedModel = this->eliminateConstantDeterministicStates(*this->simplifiedModel, considerForElimination, rewardModelNameAsVector.front());
199
200 return true;
201}
202
203template<typename SparseModelType>
206 storm::exceptions::UnexpectedException, "Expected a cumulative reward formula with integral bound.");
207
208 typename SparseModelType::RewardModelType const& originalRewardModel =
209 formula.hasRewardModelName() ? this->originalModel.getRewardModel(formula.getRewardModelName()) : this->originalModel.getUniqueRewardModel();
210
211 uint_fast64_t stepBound = formula.getSubformula().asCumulativeRewardFormula().getBound().evaluateAsInt();
213 STORM_LOG_THROW(stepBound > 0, storm::exceptions::UnexpectedException, "Expected a strict upper bound that is greater than zero.");
214 --stepBound;
215 }
216
217 // Get the states with non-zero reward
219 this->originalModel.getBackwardTransitions(), storm::storage::BitVector(this->originalModel.getNumberOfStates(), true),
220 ~originalRewardModel.getStatesWithZeroReward(this->originalModel.getTransitionMatrix()), true, stepBound);
221 storm::storage::BitVector zeroRewardStates = ~maybeStates;
222 storm::storage::BitVector noStates(this->originalModel.getNumberOfStates(), false);
223
224 // obtain the resulting subsystem
225 std::vector<std::string> rewardModelNameAsVector(
226 1, formula.hasRewardModelName() ? formula.getRewardModelName() : this->originalModel.getRewardModels().begin()->first);
227 storm::transformer::GoalStateMerger<SparseModelType> goalStateMerger(this->originalModel);
229 goalStateMerger.mergeTargetAndSinkStates(maybeStates, noStates, zeroRewardStates, rewardModelNameAsVector);
230 this->simplifiedModel = mergerResult.model;
231
232 // obtain the simplified formula for the simplified model
233 this->simplifiedFormula = storm::logic::CloneVisitor().clone(formula);
234
235 return true;
236}
237
239} // namespace transformer
240} // 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:317
BoundedUntilFormula & asBoundedUntilFormula()
Definition Formula.cpp:325
static std::shared_ptr< Formula const > getTrueFormula()
Definition Formula.cpp:205
EventuallyFormula & asEventuallyFormula()
Definition Formula.cpp:333
CumulativeRewardFormula & asCumulativeRewardFormula()
Definition Formula.cpp:421
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
Determines whether the model checker can handle the given verification task.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
void set(uint_fast64_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
This class performs different steps to simplify the given (parametric) model.
#define STORM_LOG_DEBUG(message)
Definition logging.h:23
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
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:400
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:48
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:322
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:383
LabParser.cpp.
Definition cli.cpp:18
boost::optional< uint_fast64_t > sinkState
std::shared_ptr< SparseModelType > model
boost::optional< uint_fast64_t > targetState