Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseDtmcInstantiationModelChecker.cpp
Go to the documentation of this file.
2
12
13namespace storm {
14namespace modelchecker {
15
16template<typename SparseModelType, typename ConstantType>
22
23template<typename SparseModelType, typename ConstantType>
26 STORM_LOG_THROW(this->currentCheckTask, storm::exceptions::InvalidStateException, "Checking has been invoked but no property has been specified before.");
27 auto const& instantiatedModel = modelInstantiator.instantiate(valuation);
28 if (instantiatedModel.isExact()) {
29 STORM_LOG_THROW(instantiatedModel.getTransitionMatrix().isProbabilistic(storm::utility::zero<ConstantType>()),
30 storm::exceptions::InvalidArgumentException, "Instantiation point is invalid as the transition matrix becomes non-stochastic.");
31 } else {
32 STORM_LOG_THROW(instantiatedModel.getTransitionMatrix().isProbabilistic(storm::utility::convertNumber<ConstantType>(env.modelTolerance())),
33 storm::exceptions::InvalidArgumentException, "Instantiation point is invalid as the transition matrix becomes non-stochastic.");
34 }
35
37
38 // Check if there are some optimizations implemented for the specified property
39 if (this->currentCheckTask->getFormula().isInFragment(storm::logic::reachability())) {
40 return checkReachabilityProbabilityFormula(env, modelChecker);
41 } else if (this->currentCheckTask->getFormula().isInFragment(storm::logic::propositional()
42 .setRewardOperatorsAllowed(true)
43 .setReachabilityRewardFormulasAllowed(true)
44 .setOperatorAtTopLevelRequired(true)
45 .setNestedOperatorsAllowed(false))) {
46 return checkReachabilityRewardFormula(env, modelChecker);
47 } else if (this->currentCheckTask->getFormula().isInFragment(storm::logic::propositional()
48 .setProbabilityOperatorsAllowed(true)
49 .setBoundedUntilFormulasAllowed(true)
50 .setStepBoundedUntilFormulasAllowed(true)
51 .setTimeBoundedUntilFormulasAllowed(true)
52 .setOperatorAtTopLevelRequired(true)
53 .setNestedOperatorsAllowed(false))) {
54 return checkBoundedUntilFormula(env, modelChecker);
55 } else {
56 return modelChecker.check(env, *this->currentCheckTask);
57 }
58}
59
60template<typename SparseModelType, typename ConstantType>
63 if (!this->currentCheckTask->getHint().isExplicitModelCheckerHint()) {
64 this->currentCheckTask->setHint(std::make_shared<ExplicitModelCheckerHint<ConstantType>>());
65 }
66 ExplicitModelCheckerHint<ConstantType>& hint = this->currentCheckTask->getHint().template asExplicitModelCheckerHint<ConstantType>();
67
69 // Perform purely qualitative analysis once
70 std::vector<ExtendedConstantType> qualitativeResult;
71 if (this->currentCheckTask->getFormula().asOperatorFormula().hasQuantitativeResult()) {
72 auto newCheckTask = *this->currentCheckTask;
73 newCheckTask.setQualitative(true);
74 newCheckTask.setOnlyInitialStatesRelevant(false);
75 qualitativeResult = std::move(modelChecker.check(env, newCheckTask)->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector());
76 } else {
77 auto newCheckTask = this->currentCheckTask->substituteFormula(this->currentCheckTask->getFormula().asOperatorFormula().getSubformula());
78 newCheckTask.setQualitative(true);
79 newCheckTask.setOnlyInitialStatesRelevant(false);
80 qualitativeResult =
81 std::move(modelChecker.computeProbabilities(env, newCheckTask)->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector());
82 }
84 qualitativeResult, [](ExtendedConstantType const& value) -> bool { return !(storm::utility::isZero(value) || storm::utility::isOne(value)); });
85 hint.setMaybeStates(std::move(maybeStates));
86 hint.setResultHint(std::move(qualitativeResult));
88 }
89
90 std::unique_ptr<CheckResult> result;
91 // Check the formula and store the result as a hint for the next call.
92 // For qualitative properties, we still want a quantitative result hint. Hence we perform the check on the subformula
93 if (this->currentCheckTask->getFormula().asOperatorFormula().hasQuantitativeResult()) {
94 result = modelChecker.check(env, *this->currentCheckTask);
95 hint.setResultHint(result->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector());
96 } else {
97 auto newCheckTask = this->currentCheckTask->substituteFormula(this->currentCheckTask->getFormula().asOperatorFormula().getSubformula())
98 .setOnlyInitialStatesRelevant(false);
99 std::unique_ptr<CheckResult> quantitativeResult = modelChecker.computeProbabilities(env, newCheckTask);
100 result = quantitativeResult->template asExplicitQuantitativeCheckResult<ConstantType>().compareAgainstBound(
101 this->currentCheckTask->getFormula().asOperatorFormula().getComparisonType(),
102 this->currentCheckTask->getFormula().asOperatorFormula().template getThresholdAs<ConstantType>());
103 hint.setResultHint(std::move(quantitativeResult->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector()));
104 }
105
106 return result;
107}
108
109template<typename SparseModelType, typename ConstantType>
112 if (!this->currentCheckTask->getHint().isExplicitModelCheckerHint()) {
113 this->currentCheckTask->setHint(std::make_shared<ExplicitModelCheckerHint<ConstantType>>());
114 }
115 ExplicitModelCheckerHint<ConstantType>& hint = this->currentCheckTask->getHint().template asExplicitModelCheckerHint<ConstantType>();
116
118 // Perform purely qualitative analysis once
119 std::vector<ExtendedConstantType> qualitativeResult;
120 if (this->currentCheckTask->getFormula().asOperatorFormula().hasQuantitativeResult()) {
121 auto newCheckTask = *this->currentCheckTask;
122 newCheckTask.setQualitative(true);
123 newCheckTask.setOnlyInitialStatesRelevant(false);
124 qualitativeResult = std::move(modelChecker.check(env, newCheckTask)->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector());
125 } else {
126 auto newCheckTask = this->currentCheckTask->substituteFormula(this->currentCheckTask->getFormula().asOperatorFormula().getSubformula());
127 newCheckTask.setQualitative(true);
128 newCheckTask.setOnlyInitialStatesRelevant(false);
129 qualitativeResult =
130 std::move(modelChecker.computeRewards(env, newCheckTask)->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector());
131 }
133 qualitativeResult, [](ExtendedConstantType const& value) -> bool { return !(storm::utility::isZero(value) || storm::utility::isInfinity(value)); });
134 hint.setMaybeStates(std::move(maybeStates));
135 hint.setResultHint(std::move(qualitativeResult));
136 hint.setComputeOnlyMaybeStates(true);
137 }
138
139 std::unique_ptr<CheckResult> result;
140
141 // Check the formula and store the result as a hint for the next call.
142 // For qualitative properties, we still want a quantitative result hint. Hence we perform the check on the subformula
143 if (this->currentCheckTask->getFormula().asOperatorFormula().hasQuantitativeResult()) {
144 result = modelChecker.check(env, *this->currentCheckTask);
145 this->currentCheckTask->getHint().template asExplicitModelCheckerHint<ConstantType>().setResultHint(
146 result->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector());
147 } else {
148 auto newCheckTask = this->currentCheckTask->substituteFormula(this->currentCheckTask->getFormula().asOperatorFormula().getSubformula())
149 .setOnlyInitialStatesRelevant(false);
150 std::unique_ptr<CheckResult> quantitativeResult = modelChecker.computeRewards(env, newCheckTask);
151 result = quantitativeResult->template asExplicitQuantitativeCheckResult<ConstantType>().compareAgainstBound(
152 this->currentCheckTask->getFormula().asOperatorFormula().getComparisonType(),
153 this->currentCheckTask->getFormula().asOperatorFormula().template getThresholdAs<ConstantType>());
154 this->currentCheckTask->getHint().template asExplicitModelCheckerHint<ConstantType>().setResultHint(
155 std::move(quantitativeResult->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector()));
156 }
157
158 return result;
159}
160
161template<typename SparseModelType, typename ConstantType>
164 if (!this->currentCheckTask->getHint().isExplicitModelCheckerHint()) {
165 this->currentCheckTask->setHint(std::make_shared<ExplicitModelCheckerHint<ConstantType>>());
166 }
167 std::unique_ptr<CheckResult> result;
168 ExplicitModelCheckerHint<ConstantType>& hint = this->currentCheckTask->getHint().template asExplicitModelCheckerHint<ConstantType>();
169
171 // We extract the maybestates from the quantitative result
172 // For qualitative properties, we still need a quantitative result. Hence we perform the check on the subformula
173 if (this->currentCheckTask->getFormula().asOperatorFormula().hasQuantitativeResult()) {
174 result = modelChecker.check(env, *this->currentCheckTask);
175 hint.setResultHint(result->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector());
176 } else {
177 auto newCheckTask = this->currentCheckTask->substituteFormula(this->currentCheckTask->getFormula().asOperatorFormula().getSubformula())
178 .setOnlyInitialStatesRelevant(false);
179 std::unique_ptr<CheckResult> quantitativeResult = modelChecker.computeProbabilities(env, newCheckTask);
180 result = quantitativeResult->template asExplicitQuantitativeCheckResult<ConstantType>().compareAgainstBound(
181 this->currentCheckTask->getFormula().asOperatorFormula().getComparisonType(),
182 this->currentCheckTask->getFormula().asOperatorFormula().template getThresholdAs<ConstantType>());
183 hint.setResultHint(std::move(quantitativeResult->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector()));
184 }
185
187 // We need to exclude the target states from the maybe states.
188 // Note that we can not consider the states with probability one since a state might reach a target state with prob 1 within >0 steps
189 std::unique_ptr<CheckResult> subFormulaResult =
190 modelChecker.check(env, this->currentCheckTask->getFormula().asOperatorFormula().getSubformula().asBoundedUntilFormula().getRightSubformula());
191 maybeStates = maybeStates & ~(subFormulaResult->template asExplicitQualitativeCheckResult<ConstantType>().getTruthValuesVector());
192 hint.setMaybeStates(std::move(maybeStates));
193 hint.setComputeOnlyMaybeStates(true);
194 } else {
195 result = modelChecker.check(env, *this->currentCheckTask);
196 }
197
198 return result;
199}
200
201template<typename SparseModelType, typename ConstantType>
204 auto const& instantiatedModel = modelInstantiator.instantiate(valuation);
205 // Should be moved further outside.
206 if (instantiatedModel.isExact()) {
207 return instantiatedModel.getTransitionMatrix().isProbabilistic(storm::utility::zero<ConstantType>());
208 } else {
209 return instantiatedModel.getTransitionMatrix().isProbabilistic(storm::utility::convertNumber<ConstantType>(this->env.modelTolerance()));
210 }
211}
212
215
216} // namespace modelchecker
217} // namespace storm
virtual std::unique_ptr< CheckResult > check(Environment const &env, CheckTask< storm::logic::Formula, SolutionType > const &checkTask)
Checks the provided formula.
This class contains information that might accelerate the model checking process.
void setResultHint(boost::optional< std::vector< ExtendedValueType > > const &resultHint)
void setMaybeStates(storm::storage::BitVector const &maybeStates)
std::vector< ExtendedValueType > const & getResultHint() const
Class to efficiently check a formula on a parametric model with different parameter instantiations.
std::unique_ptr< CheckResult > checkReachabilityRewardFormula(Environment const &env, storm::modelchecker::SparseDtmcPrctlModelChecker< storm::models::sparse::Dtmc< ConstantType > > &modelChecker)
virtual std::unique_ptr< CheckResult > check(Environment const &env, storm::utility::parametric::Valuation< typename SparseModelType::ValueType > const &valuation) override
virtual bool isWellDefined(storm::utility::parametric::Valuation< typename SparseModelType::ValueType > const &valuation) override
Checks if the given valuation is valid for the current model.
storm::utility::ExtendedValueType< ConstantType > ExtendedConstantType
SparseDtmcInstantiationModelChecker(Environment const &env, SparseModelType const &parametricModel)
storm::utility::ModelInstantiator< SparseModelType, storm::models::sparse::Dtmc< ConstantType > > modelInstantiator
std::unique_ptr< CheckResult > checkBoundedUntilFormula(Environment const &env, storm::modelchecker::SparseDtmcPrctlModelChecker< storm::models::sparse::Dtmc< ConstantType > > &modelChecker)
std::unique_ptr< CheckResult > checkReachabilityProbabilityFormula(Environment const &env, storm::modelchecker::SparseDtmcPrctlModelChecker< storm::models::sparse::Dtmc< ConstantType > > &modelChecker)
SparseInstantiationModelChecker(Environment const &env, SparseModelType const &parametricModel)
std::unique_ptr< CheckTask< storm::logic::Formula, ConstantType > > currentCheckTask
This class represents a discrete-time Markov chain.
Definition Dtmc.h:16
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
FragmentSpecification propositional()
FragmentSpecification reachability()
std::map< typename VariableType< FunctionType >::type, typename CoefficientType< FunctionType >::type > Valuation
Definition parametric.h:43
storm::storage::BitVector filter(std::vector< T > const &values, std::function< bool(T const &value)> const &function)
Retrieves a bit vector containing all the indices for which the value at this position makes the give...
Definition vector.h:487
storm::storage::BitVector filterGreaterZero(std::vector< T > const &values)
Retrieves a bit vector containing all the indices for which the value at this position is greater tha...
Definition vector.h:509
bool isOne(ValueType const &a)
Definition constants.cpp:39
bool isZero(ValueType const &a)
Definition constants.cpp:44
ValueType zero()
Definition constants.cpp:26
bool isInfinity(ValueType const &a)
TargetType convertNumber(SourceType const &number)