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