Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseParameterLiftingModelChecker.cpp
Go to the documentation of this file.
2
18
19namespace storm {
20namespace modelchecker {
21
22template<typename SparseModelType, typename ConstantType>
26
27template<typename SparseModelType, typename ConstantType>
30 currentFormula = checkTask.getFormula().asSharedPointer();
31 currentCheckTask = std::make_unique<storm::modelchecker::CheckTask<storm::logic::Formula, ConstantType>>(
32 checkTask.substituteFormula(*currentFormula).template convertValueType<ConstantType>());
33
34 if (currentCheckTask->getFormula().isProbabilityOperatorFormula()) {
35 auto const& probOpFormula = currentCheckTask->getFormula().asProbabilityOperatorFormula();
36 if (probOpFormula.getSubformula().isBoundedUntilFormula()) {
37 specifyBoundedUntilFormula(currentCheckTask->substituteFormula(probOpFormula.getSubformula().asBoundedUntilFormula()));
38 } else if (probOpFormula.getSubformula().isUntilFormula()) {
39 specifyUntilFormula(env, currentCheckTask->substituteFormula(probOpFormula.getSubformula().asUntilFormula()));
40 } else if (probOpFormula.getSubformula().isEventuallyFormula()) {
41 specifyReachabilityProbabilityFormula(env, currentCheckTask->substituteFormula(probOpFormula.getSubformula().asEventuallyFormula()));
42 } else {
43 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Parameter lifting is not supported for the given property.");
44 }
45 } else if (currentCheckTask->getFormula().isRewardOperatorFormula()) {
46 auto const& rewOpFormula = currentCheckTask->getFormula().asRewardOperatorFormula();
47 if (rewOpFormula.getSubformula().isEventuallyFormula()) {
48 specifyReachabilityRewardFormula(env, currentCheckTask->substituteFormula(rewOpFormula.getSubformula().asEventuallyFormula()));
49 } else if (rewOpFormula.getSubformula().isCumulativeRewardFormula()) {
50 specifyCumulativeRewardFormula(currentCheckTask->substituteFormula(rewOpFormula.getSubformula().asCumulativeRewardFormula()));
51 }
52 }
53}
54
55template<typename SparseModelType, typename ConstantType>
57 return this->parametricModel->getInitialStates().getNumberOfSetBits() == 1;
58}
59
60template<typename SparseModelType, typename ConstantType>
62 STORM_LOG_ASSERT(hasUniqueInitialState(), "Model does not have a unique initial state.");
63 return *this->parametricModel->getInitialStates().begin();
64}
65
66template<typename RegionType>
68 std::map<typename RegionType::VariableType, storm::analysis::MonotonicityKind> const& monotonicityResult,
70 typename RegionType::Valuation result;
71 for (auto const& [var, mon] : monotonicityResult) {
73 result.emplace(var, region.getLowerBoundary(var));
75 result.emplace(var, storm::solver::maximize(dir) ? region.getUpperBoundary(var) : region.getLowerBoundary(var));
77 result.emplace(var, storm::solver::minimize(dir) ? region.getUpperBoundary(var) : region.getLowerBoundary(var));
78 }
79 }
80 return result;
81}
82
83template<typename SparseModelType, typename ConstantType>
85 RegionResultHypothesis const& hypothesis,
86 bool sampleVerticesOfRegion) {
87 STORM_LOG_THROW(this->currentCheckTask->isOnlyInitialStatesRelevantSet(), storm::exceptions::NotSupportedException,
88 "Analyzing regions with parameter lifting requires a property where only the value in the initial states is relevant.");
89 STORM_LOG_THROW(this->currentCheckTask->isBoundSet(), storm::exceptions::NotSupportedException,
90 "Analyzing regions with parameter lifting requires a bounded property.");
91 STORM_LOG_THROW(hasUniqueInitialState(), storm::exceptions::NotSupportedException,
92 "Analyzing regions with parameter lifting requires a model with a single initial state.");
93
94 RegionResult result = region.result;
95 if (result == RegionResult::AllSat || result == RegionResult::AllViolated || result == RegionResult::ExistsBoth) {
96 return result; // Result is already known, nothing to do.
97 }
98
99 // Check if we need to check the formula on one point to decide whether to show AllSat or AllViolated
100 if (hypothesis == RegionResultHypothesis::Unknown &&
102 auto const center = region.region.getCenterPoint();
103 if (getInstantiationChecker(env, false).isWellDefined(center)) {
104 result = getInstantiationChecker(env, false).check(env, center)->template asExplicitQualitativeCheckResult<ConstantType>()[getUniqueInitialState()]
107 } else {
108 auto const lowerCorner = region.region.getLowerBoundaries();
109 if (getInstantiationChecker(env, false).isWellDefined(lowerCorner)) {
110 result = getInstantiationChecker(env, false)
111 .check(env, lowerCorner)
112 ->template asExplicitQualitativeCheckResult<ConstantType>()[getUniqueInitialState()]
115 } else {
117 }
118 }
119 }
120
121 bool const existsSat = (hypothesis == RegionResultHypothesis::AllSat || result == RegionResult::ExistsSat || result == RegionResult::CenterSat);
122 bool const existsIllDefined = (result == RegionResult::ExistsIllDefined || result == RegionResult::CenterIllDefined);
123 {
124 [[maybe_unused]] bool const existsViolated =
126 STORM_LOG_ASSERT(existsSat + existsViolated + existsIllDefined == 1,
127 "Invalid state of region analysis."); // At this point, exactly one of the three cases must be true
128 }
129 auto const dirForSat =
130 isLowerBound(this->currentCheckTask->getBound().comparisonType) ? storm::OptimizationDirection::Minimize : storm::OptimizationDirection::Maximize;
131
132 std::vector<storm::OptimizationDirection> dirsToCheck;
133 if (existsSat) {
134 dirsToCheck = {dirForSat};
135 } else if (existsIllDefined) {
136 dirsToCheck = {dirForSat, storm::solver::invert(dirForSat)};
137 } else {
138 dirsToCheck = {storm::solver::invert(dirForSat)};
139 }
140
141 for (auto const& dirToCheck : dirsToCheck) {
142 // Try solving through global monotonicity
143 if (auto globalMonotonicity = region.monotonicityAnnotation.getGlobalMonotonicityResult();
144 globalMonotonicity.has_value() && globalMonotonicity->isDone() && globalMonotonicity->isAllMonotonicity()) {
145 auto const valuation = getOptimalValuationForMonotonicity(region.region, globalMonotonicity->getMonotonicityResult(), dirToCheck);
146 STORM_LOG_ASSERT(valuation.size() == region.region.getVariables().size(), "Not all parameters seem to be monotonic.");
147 auto& checker = existsSat ? getInstantiationCheckerSAT(env, false) : getInstantiationCheckerVIO(env, false);
148 bool const monCheckResult = checker.check(env, valuation)->template asExplicitQualitativeCheckResult<ConstantType>()[getUniqueInitialState()];
149 if (existsSat == monCheckResult) {
150 result = existsSat ? RegionResult::AllSat : RegionResult::AllViolated;
151 STORM_LOG_INFO("Region " << region.region << " is " << result << ", discovered with instantiation checker on " << valuation
152 << " and help of monotonicity\n");
153 region.resultKnownThroughMonotonicity = true;
154 } else if (result == RegionResult::ExistsSat || result == RegionResult::CenterSat || result == RegionResult::ExistsViolated ||
156 // We found a satisfying and a violating point
158 } else {
160 "This case should only be reached if the initial region result is unknown, but it is " << result << ".");
161 result = monCheckResult ? RegionResult::ExistsSat : RegionResult::ExistsViolated;
162 if (sampleVerticesOfRegion) {
163 result = sampleVertices(env, region.region, result);
164 }
165 }
166 } else {
167 // Try to prove AllSat or AllViolated through parameterLifting
168 auto const checkResult = this->check(env, region, dirToCheck);
169 if (checkResult) {
170 bool const value = checkResult->template asExplicitQualitativeCheckResult<ConstantType>()[getUniqueInitialState()];
171 if ((dirToCheck == dirForSat) == value) {
172 result = (dirToCheck == dirForSat) ? RegionResult::AllSat : RegionResult::AllViolated;
173 } else if (sampleVerticesOfRegion) {
174 result = sampleVertices(env, region.region, result);
175 }
176 } else {
178 }
179 }
180 }
181 return result;
182}
183
184template<typename SparseModelType, typename ConstantType>
187 RegionResult const& initialResult) {
188 RegionResult result = initialResult;
189
190 if (result == RegionResult::AllSat || result == RegionResult::AllViolated) {
191 return result;
192 }
193
194 bool hasSatPoint = result == RegionResult::ExistsSat || result == RegionResult::CenterSat;
195 bool hasViolatedPoint = result == RegionResult::ExistsViolated || result == RegionResult::CenterViolated;
196
197 // Check if there is a point in the region for which the property is satisfied
198 auto vertices = region.getVerticesOfRegion(region.getVariables());
199 auto vertexIt = vertices.begin();
200 while (vertexIt != vertices.end() && !(hasSatPoint && hasViolatedPoint)) {
201 if (getInstantiationChecker(env, false).check(env, *vertexIt)->template asExplicitQualitativeCheckResult<ConstantType>()[getUniqueInitialState()]) {
202 hasSatPoint = true;
203 } else {
204 hasViolatedPoint = true;
205 }
206 ++vertexIt;
207 }
208
209 if (hasSatPoint) {
210 if (hasViolatedPoint) {
212 } else if (result != RegionResult::CenterSat) {
214 }
215 } else if (hasViolatedPoint && result != RegionResult::CenterViolated) {
217 }
218
219 return result;
220}
221
222template<typename SparseModelType, typename ConstantType>
225 auto quantitativeResult = computeQuantitativeValues(env, region, dirForParameters);
226 if (quantitativeResult.size() == 0) {
227 return nullptr;
228 }
229 auto quantitativeCheckResult = std::make_unique<storm::modelchecker::ExplicitQuantitativeCheckResult<ConstantType>>(std::move(quantitativeResult));
230 if (currentCheckTask->getFormula().hasQuantitativeResult()) {
231 return quantitativeCheckResult;
232 } else {
233 return quantitativeCheckResult->compareAgainstBound(this->currentCheckTask->getFormula().asOperatorFormula().getComparisonType(),
234 this->currentCheckTask->getFormula().asOperatorFormula().template getThresholdAs<ConstantType>());
235 }
236}
237
238template<typename SparseModelType, typename ConstantType>
239std::unique_ptr<QuantitativeCheckResult<ConstantType>> SparseParameterLiftingModelChecker<SparseModelType, ConstantType>::getBound(
241 STORM_LOG_WARN_COND(this->currentCheckTask->getFormula().hasQuantitativeResult(), "Computing quantitative bounds for a qualitative formula...");
242 return std::make_unique<ExplicitQuantitativeCheckResult<ConstantType>>(computeQuantitativeValues(env, region, dirForParameters));
243}
244
245template<typename SparseModelType, typename ConstantType>
248 storm::solver::OptimizationDirection const& dirForParameters) {
249 STORM_LOG_THROW(hasUniqueInitialState(), storm::exceptions::NotSupportedException,
250 "Getting a bound at the initial state requires a model with a single initial state.");
252}
253
254template<typename SparseModelType, typename ConstantType>
259
260template<typename SparseModelType, typename ConstantType>
265
266template<typename SparseModelType, typename ConstantType>
270
271template<typename SparseModelType, typename ConstantType>
275
276template<typename SparseModelType, typename ConstantType>
279 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Parameter lifting is not supported for the given property.");
280}
281
282template<typename SparseModelType, typename ConstantType>
285 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Parameter lifting is not supported for the given property.");
286}
287
288template<typename SparseModelType, typename ConstantType>
291 // transform to until formula
292 auto untilFormula =
293 std::make_shared<storm::logic::UntilFormula const>(storm::logic::Formula::getTrueFormula(), checkTask.getFormula().getSubformula().asSharedPointer());
294 specifyUntilFormula(env, currentCheckTask->substituteFormula(*untilFormula));
295}
296
297template<typename SparseModelType, typename ConstantType>
300 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Parameter lifting is not supported for the given property.");
301}
302
303template<typename SparseModelType, typename ConstantType>
306 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Parameter lifting is not supported for the given property.");
307}
308
309template<typename SparseModelType, typename ConstantType>
310std::pair<typename SparseParameterLiftingModelChecker<SparseModelType, ConstantType>::ExtendedCoefficientType,
313 OptimizationDirection const& dirForParameters) {
314 // Take region boundaries for parameters that are known to be monotonic or where there is hope for monotonicity
315 auto point = getOptimalValuationForMonotonicity(region.region, this->monotonicityBackend->getOptimisticMonotonicityApproximation(region), dirForParameters);
316 // Fill in missing parameters with the center point
317 for (auto const& var : region.region.getVariables()) {
318 point.emplace(var, region.region.getCenter(var)); // does not overwrite existing values
319 }
320 auto value = getInstantiationChecker(env, true).check(env, point)->template asExplicitQuantitativeCheckResult<ConstantType>()[getUniqueInitialState()];
321
322 return std::make_pair(storm::utility::convertNumber<ExtendedCoefficientType>(value), std::move(point));
323}
324
325template<typename SparseModelType, typename ConstantType>
333
338} // namespace modelchecker
339} // namespace storm
static std::shared_ptr< Formula const > getTrueFormula()
Definition Formula.cpp:227
CheckTask< NewFormulaType, ValueType > substituteFormula(NewFormulaType const &newFormula) const
Copies the check task from the source while replacing the formula with the new one.
Definition CheckTask.h:53
FormulaType const & getFormula() const
Retrieves the formula from this task.
Definition CheckTask.h:141
Class to efficiently check a formula on a parametric model with different parameter instantiations.
Class to approximately check a formula on a parametric model for all parameter valuations within a re...
virtual RegionResult analyzeRegion(Environment const &env, AnnotatedRegion< ParametricType > &region, RegionResultHypothesis const &hypothesis=RegionResultHypothesis::Unknown, bool sampleVerticesOfRegion=false) override
Analyzes the given region by means of Parameter Lifting.
void updateKnownValueBoundInRegion(AnnotatedRegion< ParametricType > &region, storm::solver::OptimizationDirection dir, std::vector< ExtendedConstantType > const &newValues)
virtual std::vector< ExtendedConstantType > computeQuantitativeValues(Environment const &env, AnnotatedRegion< ParametricType > &region, storm::solver::OptimizationDirection const &dirForParameters)=0
std::unique_ptr< CheckTask< storm::logic::Formula, ConstantType > > currentCheckTask
virtual void specifyUntilFormula(Environment const &env, CheckTask< storm::logic::UntilFormula, ConstantType > const &checkTask)
virtual void specifyReachabilityRewardFormula(Environment const &env, CheckTask< storm::logic::EventuallyFormula, ConstantType > const &checkTask)
virtual storm::modelchecker::SparseInstantiationModelChecker< SparseModelType, ConstantType > & getInstantiationCheckerVIO(Environment const &env, bool quantitative)
std::unique_ptr< QuantitativeCheckResult< ConstantType > > getBound(Environment const &env, AnnotatedRegion< ParametricType > &region, storm::solver::OptimizationDirection const &dirForParameters)
Over-approximates the values within the given region for each state of the considered parametric mode...
virtual void specifyCumulativeRewardFormula(const CheckTask< storm::logic::CumulativeRewardFormula, ConstantType > &checkTask)
virtual std::pair< ExtendedCoefficientType, Valuation > getAndEvaluateGoodPoint(Environment const &env, AnnotatedRegion< ParametricType > &region, storm::solver::OptimizationDirection const &dirForParameters) override
Heuristically finds a point within the region and computes the value at the initial state for that po...
virtual storm::modelchecker::SparseInstantiationModelChecker< SparseModelType, ConstantType > & getInstantiationCheckerSAT(Environment const &env, bool quantitative)
typename RegionModelChecker< ParametricType >::ExtendedCoefficientType ExtendedCoefficientType
std::unique_ptr< CheckResult > check(Environment const &env, AnnotatedRegion< ParametricType > &region, storm::solver::OptimizationDirection const &dirForParameters)
Checks the specified formula on the given region by applying parameter lifting (Parameter choices are...
RegionResult sampleVertices(Environment const &env, storm::storage::ParameterRegion< ParametricType > const &region, RegionResult const &initialResult=RegionResult::Unknown)
Analyzes the 2^parameters corner points of the given region.
void specifyFormula(Environment const &env, CheckTask< storm::logic::Formula, ParametricType > const &checkTask)
virtual storm::modelchecker::SparseInstantiationModelChecker< SparseModelType, ConstantType > & getInstantiationChecker(Environment const &env, bool quantitative)=0
virtual ExtendedCoefficientType getBoundAtInitState(Environment const &env, AnnotatedRegion< ParametricType > &region, storm::solver::OptimizationDirection const &dirForParameters) override
Over-approximates the value within the given region.
virtual void specifyReachabilityProbabilityFormula(Environment const &env, CheckTask< storm::logic::EventuallyFormula, ConstantType > const &checkTask)
typename RegionModelChecker< ParametricType >::Valuation Valuation
CheckTask< storm::logic::Formula, ConstantType > const & getCurrentCheckTask() const
virtual void specifyBoundedUntilFormula(const CheckTask< storm::logic::BoundedUntilFormula, ConstantType > &checkTask)
#define STORM_LOG_INFO(message)
Definition logging.h:34
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:54
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
@ Incr
the result is monotonically increasing
@ Decr
the result is monotonically decreasing
@ Constant
the result is constant
RegionResult
The results for a single Parameter Region.
@ CenterSat
the formula is satisfied for the parameter Valuation that corresponds to the center point of the regi...
@ CenterIllDefined
the formula is ill-defined for the parameter Valuation that corresponds to the center point of the re...
@ AllSat
the formula is satisfied for all well-defined parameters in the given region
@ AllViolated
the formula is violated for all well-defined parameters in the given region
@ Unknown
the result is unknown
@ ExistsBoth
the formula is satisfied for some parameters but also violated for others
@ AllIllDefined
the formula is ill-defined for all parameters in the given region
@ CenterViolated
the formula is violated for the parameter Valuation that corresponds to the center point of the regio...
@ ExistsSat
the formula is satisfied for at least one parameter evaluation that lies in the given region
@ ExistsViolated
the formula is violated for at least one parameter evaluation that lies in the given region
@ ExistsIllDefined
the formula is ill-defined for at least one parameter evaluation that lies in the given region
RegionResultHypothesis
hypothesis for the result for a single Parameter Region
auto getOptimalValuationForMonotonicity(RegionType const &region, std::map< typename RegionType::VariableType, storm::analysis::MonotonicityKind > const &monotonicityResult, storm::OptimizationDirection dir)
bool constexpr maximize(OptimizationDirection d)
OptimizationDirection constexpr invert(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
TargetType convertNumber(SourceType const &number)
solver::OptimizationDirection OptimizationDirection