Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
model-handling-main-cli.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <optional>
5#include <sstream>
6
22
23namespace storm {
24namespace cli {
25
26inline void exportSymbolicInput(SymbolicInput const& input) {
28 if (input.model && input.model.get().isJaniModel()) {
29 storm::languages::SymbolicModelDescription const& model = input.model.get();
30 if (ioSettings.isExportJaniDotSet()) {
31 storm::api::exportJaniModelAsDot(model.asJaniModel(), ioSettings.getExportJaniDotFilename());
32 }
33 }
34}
35
37 STORM_PRINT("Computing counterexample for property " << *property.getRawFormula() << " ...\n");
38}
39
40inline void printCounterexample(std::shared_ptr<storm::counterexamples::Counterexample> const& counterexample, storm::utility::Stopwatch* watch = nullptr) {
41 if (counterexample) {
42 STORM_PRINT(*counterexample << '\n');
43 if (watch) {
44 STORM_PRINT("Time for computation: " << *watch << ".\n");
45 }
46 } else {
47 STORM_PRINT(" failed.\n");
48 }
49}
50
51template<typename ModelType>
52 requires(!std::derived_from<ModelType, storm::models::sparse::Model<double>>)
53inline void generateCounterexamples(std::shared_ptr<ModelType> const&, SymbolicInput const&, ModelProcessingInformation const&) {
54 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Counterexample generation is not supported for this data-type.");
55}
56
57template<typename ModelType>
58 requires(std::derived_from<ModelType, storm::models::sparse::Model<double>>)
59inline void generateCounterexamples(std::shared_ptr<ModelType> const& sparseModel, SymbolicInput const& input, ModelProcessingInformation const& mpi) {
60 using ValueType = typename ModelType::ValueType;
61
62 for (auto& rewModel : sparseModel->getRewardModels()) {
63 rewModel.second.reduceToStateBasedRewards(sparseModel->getTransitionMatrix(), true);
64 }
65
66 STORM_LOG_THROW(sparseModel->isOfType(storm::models::ModelType::Dtmc) || sparseModel->isOfType(storm::models::ModelType::Mdp),
67 storm::exceptions::NotSupportedException, "Counterexample is currently only supported for discrete-time models.");
68
70 if (counterexampleSettings.isMinimalCommandSetGenerationSet()) {
71 bool useMilp = counterexampleSettings.isUseMilpBasedMinimalCommandSetGenerationSet();
73 maxSmtOptions.encodeReachability = counterexampleSettings.isEncodeReachabilitySet();
74 maxSmtOptions.useDynamicConstraints = counterexampleSettings.isUseDynamicConstraintsSet();
75 for (auto const& property : input.properties) {
76 std::shared_ptr<storm::counterexamples::Counterexample> counterexample;
78 storm::utility::Stopwatch watch(true);
79 if (useMilp) {
80 STORM_LOG_THROW(sparseModel->isOfType(storm::models::ModelType::Mdp), storm::exceptions::NotSupportedException,
81 "Counterexample generation using MILP is currently only supported for MDPs.");
82 counterexample = storm::api::computeHighLevelCounterexampleMilp(mpi.env, input.model.get(),
83 sparseModel->template as<storm::models::sparse::Mdp<ValueType>>(),
84 property.getRawFormula(), counterexampleSettings.isUseSchedulerCutsSet());
85 } else {
86 STORM_LOG_THROW(sparseModel->isOfType(storm::models::ModelType::Dtmc) || sparseModel->isOfType(storm::models::ModelType::Mdp),
87 storm::exceptions::NotSupportedException,
88 "Counterexample generation using MaxSAT is currently only supported for discrete-time models.");
89
90 if (sparseModel->isOfType(storm::models::ModelType::Dtmc)) {
91 counterexample = storm::api::computeHighLevelCounterexampleMaxSmt(mpi.env, input.model.get(),
92 sparseModel->template as<storm::models::sparse::Dtmc<ValueType>>(),
93 property.getRawFormula(), maxSmtOptions);
94 } else {
96 mpi.env, input.model.get(), sparseModel->template as<storm::models::sparse::Mdp<ValueType>>(), property.getRawFormula(), maxSmtOptions);
97 }
98 }
99 watch.stop();
100 printCounterexample(counterexample, &watch);
101 }
102 } else if (counterexampleSettings.isShortestPathGenerationSet()) {
103 for (auto const& property : input.properties) {
104 std::shared_ptr<storm::counterexamples::Counterexample> counterexample;
106 storm::utility::Stopwatch watch(true);
107 STORM_LOG_THROW(sparseModel->isOfType(storm::models::ModelType::Dtmc), storm::exceptions::NotSupportedException,
108 "Counterexample generation using shortest paths is currently only supported for DTMCs.");
110 property.getRawFormula(), counterexampleSettings.getShortestPathMaxK());
111 watch.stop();
112 printCounterexample(counterexample, &watch);
113 }
114 } else {
115 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "The selected counterexample formalism is unsupported.");
116 }
117}
118
119template<typename ValueType>
121void printFilteredResult(std::unique_ptr<storm::modelchecker::CheckResult> const& result, storm::modelchecker::FilterType ft) {
122 if (result->isQuantitative()) {
124 STORM_PRINT(*result);
125 } else {
126 switch (ft) {
131 break;
134 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Outputting states is not supported.");
135 break;
139 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Filter type only defined for qualitative results.");
140 break;
141 default:
142 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Unhandled filter type.");
143 }
144 auto const aggregate = result->asQuantitativeCheckResult<ValueType>().aggregate(ft);
145 auto const printSide = [](std::optional<storm::utility::ExtendedValueType<ValueType>> const& value, bool approximate) {
146 if (!value) {
147 STORM_PRINT("?");
148 } else if (storm::utility::isInfinity(*value)) {
149 STORM_PRINT("inf");
150 } else if (approximate) {
152 } else {
153 STORM_PRINT(*value);
154 }
155 };
156 // Only an exact value type has a decimal approximation to add, and a rational function has none to give.
157 bool const approximates =
159 printSide(aggregate.value, false);
160 if (approximates) {
161 STORM_PRINT(" (approx. ");
162 printSide(aggregate.value, true);
163 STORM_PRINT(")");
164 }
165 // An aggregate of an enclosure encloses the aggregate, so report it in the same shape as the values do.
166 if (aggregate.hasLower() && aggregate.hasUpper() && *aggregate.lower == *aggregate.upper) {
167 STORM_PRINT(". Exact solution.");
168 } else if (aggregate.hasLower() || aggregate.hasUpper()) {
169 STORM_PRINT(". Solution bounds: [");
170 printSide(aggregate.lower, false);
171 STORM_PRINT(", ");
172 printSide(aggregate.upper, false);
173 STORM_PRINT("]");
174 if (approximates) {
175 STORM_PRINT(" (approx. [");
176 printSide(aggregate.lower, true);
177 STORM_PRINT(", ");
178 printSide(aggregate.upper, true);
179 STORM_PRINT("])");
180 }
181 STORM_PRINT(".");
182 }
183 }
184 } else if (result->isExplicitCertificateCheckResult()) {
185 STORM_PRINT(*result);
187 "\nIgnored non-default property filter " << storm::modelchecker::toString(ft) << " for certificate result.");
188 } else {
189 switch (ft) {
191 STORM_PRINT(*result << '\n');
192 break;
194 STORM_PRINT(result->asQualitativeCheckResult().existsTrue());
195 break;
197 STORM_PRINT(result->asQualitativeCheckResult().forallTrue());
198 break;
200 STORM_PRINT(result->asQualitativeCheckResult().count());
201 break;
204 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Outputting states is not supported.");
205 break;
210 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Filter type only defined for quantitative results.");
211 }
212 }
213 STORM_PRINT('\n');
214}
215
216template<typename ValueType>
218void printResult(std::unique_ptr<storm::modelchecker::CheckResult> const& result, storm::logic::Formula const& filterStatesFormula,
219 storm::modelchecker::FilterType const& filterType, storm::utility::Stopwatch* watch = nullptr) {
220 if (result) {
221 std::stringstream ss;
222 ss << "'" << filterStatesFormula << "'";
223 STORM_PRINT((storm::utility::resources::isTerminate() ? "Result till abort" : "Result")
224 << " (for " << (filterStatesFormula.isInitialFormula() ? "initial" : ss.str()) << " states): ");
225 printFilteredResult<ValueType>(result, filterType);
226 if (watch) {
227 STORM_PRINT("Time for model checking: " << *watch << ".\n");
228 }
229 } else {
230 STORM_LOG_ERROR("Property is unsupported by selected engine/settings.\n");
231 }
232}
233
234template<typename ValueType>
235void printResult(std::unique_ptr<storm::modelchecker::CheckResult> const& result, storm::jani::Property const& property,
236 storm::utility::Stopwatch* watch = nullptr) {
237 printResult<ValueType>(result, *property.getFilter().getStatesFormula(), property.getFilter().getFilterType(), watch);
238}
239
240using VerificationCallbackType = std::function<std::unique_ptr<storm::modelchecker::CheckResult>(std::shared_ptr<storm::logic::Formula const> const& formula,
241 std::shared_ptr<storm::logic::Formula const> const& states)>;
242using PostprocessingCallbackType = std::function<void(std::unique_ptr<storm::modelchecker::CheckResult> const&)>;
243
245 void operator()(std::unique_ptr<storm::modelchecker::CheckResult> const&) {
246 // Intentionally left empty.
247 }
248};
249
256template<typename ValueType>
257std::unique_ptr<storm::modelchecker::CheckResult> verifyProperty(std::shared_ptr<storm::logic::Formula const> const& formula,
258 std::shared_ptr<storm::logic::Formula const> const& statesFilter,
259 VerificationCallbackType const& verificationCallback) {
261
262 try {
263 if constexpr (storm::IsIntervalType<ValueType>) {
264 STORM_LOG_ASSERT(!transformationSettings.isChainEliminationSet() && !transformationSettings.isToNondeterministicModelSet(),
265 "Unsupported transformation has been invoked.");
266 return verificationCallback(formula, statesFilter);
267 }
268 if (transformationSettings.isChainEliminationSet() && !storm::transformer::NonMarkovianChainTransformer<ValueType>::preservesFormula(*formula)) {
269 STORM_LOG_WARN("Property is not preserved by elimination of non-markovian states.");
270 } else if (transformationSettings.isToDiscreteTimeModelSet()) {
272 auto transformedStatesFilter = storm::api::checkAndTransformContinuousToDiscreteTimeFormula<ValueType>(*statesFilter);
273 if (transformedFormula && transformedStatesFilter) {
274 // invoke verification algorithm on transformed formulas
275 return verificationCallback(transformedFormula, transformedStatesFilter);
276 } else {
277 STORM_LOG_WARN("Property is not preserved by transformation to discrete time model.");
278 }
279 } else {
280 // invoke verification algorithm on given formulas
281 return verificationCallback(formula, statesFilter);
282 }
283 } catch (storm::exceptions::BaseException const& ex) {
284 STORM_LOG_WARN("Cannot handle property: " << ex.what());
285 }
286 return nullptr;
287}
288
295template<typename ValueType>
296void verifyProperties(SymbolicInput const& input, VerificationCallbackType const& verificationCallback,
297 PostprocessingCallbackType const& postprocessingCallback = PostprocessingIdentity()) {
298 auto const& properties = input.preprocessedProperties ? input.preprocessedProperties.get() : input.properties;
299 for (auto const& property : properties) {
301 storm::utility::Stopwatch watch(true);
302 auto result = verifyProperty<ValueType>(property.getRawFormula(), property.getFilter().getStatesFormula(), verificationCallback);
303 watch.stop();
304 if (result) {
305 postprocessingCallback(result);
306 }
307 printResult<storm::IntervalBaseType<ValueType>>(result, property, &watch);
308 }
309}
310
320template<typename ValueType>
321void computeStateValues(std::string const& description, std::function<std::unique_ptr<storm::modelchecker::CheckResult>()> const& computationCallback,
322 SymbolicInput const& input, VerificationCallbackType const& verificationCallback,
323 PostprocessingCallbackType const& postprocessingCallback = PostprocessingIdentity()) {
324 // First compute the state values for all the states by invoking the computationCallback
325 storm::utility::Stopwatch watch(true);
326 STORM_PRINT("\nComputing " << description << " ...\n");
327 std::unique_ptr<storm::modelchecker::CheckResult> result;
328 try {
329 result = computationCallback();
330 } catch (storm::exceptions::BaseException const& ex) {
331 STORM_LOG_ERROR("Cannot compute " << description << ": " << ex.what());
332 }
333 if (!result) {
334 STORM_LOG_ERROR("Computation had no result.");
335 return;
336 }
337 // Now process the (potentially filtered) result
338 if (input.properties.empty()) {
339 // Do not apply any filtering, consider result for *all* states
340 postprocessingCallback(result);
342 } else {
343 // Each property identifies a subset of states to which we restrict (aka filter) the state-value result to
344 auto const& properties = input.preprocessedProperties ? input.preprocessedProperties.get() : input.properties;
345 for (uint64_t propertyIndex = 0; propertyIndex < properties.size(); ++propertyIndex) {
346 auto const& property = properties[propertyIndex];
347 // As the property serves as filter, it should (a) be qualitative and should (b) not consider a filter itself.
348 if (!property.getRawFormula()->hasQualitativeResult()) {
349 STORM_LOG_ERROR("Property '" << *property.getRawFormula()
350 << "' can not be used for filtering states as it does not have a qualitative result.");
351 continue;
352 }
353
354 // Invoke verification algorithm on filtering property
355 auto propertyFilter = verifyProperty<ValueType>(property.getRawFormula(), storm::logic::Formula::getTrueFormula(), verificationCallback);
356
357 if (propertyFilter) {
358 // Filter and process result
359 std::unique_ptr<storm::modelchecker::CheckResult> filteredResult = result->clone();
360 filteredResult->filter(propertyFilter->asQualitativeCheckResult());
361 postprocessingCallback(filteredResult);
362 printResult<ValueType>(filteredResult, *property.getRawFormula(), property.getFilter().getFilterType(),
363 propertyIndex == properties.size() - 1 ? &watch : nullptr);
364 }
365 }
366 }
367}
368
369inline std::vector<storm::expressions::Expression> parseConstraints(storm::expressions::ExpressionManager const& expressionManager,
370 std::string const& constraintsString) {
371 std::vector<storm::expressions::Expression> constraints;
372
373 std::vector<std::string> constraintsAsStrings;
374 boost::split(constraintsAsStrings, constraintsString, boost::is_any_of(","));
375
376 storm::parser::ExpressionParser expressionParser(expressionManager);
377 std::unordered_map<std::string, storm::expressions::Expression> variableMapping;
378 for (auto const& variableTypePair : expressionManager) {
379 variableMapping[variableTypePair.first.getName()] = variableTypePair.first;
380 }
381 expressionParser.setIdentifierMapping(variableMapping);
382
383 for (auto const& constraintString : constraintsAsStrings) {
384 if (constraintString.empty()) {
385 continue;
386 }
387
388 storm::expressions::Expression constraint = expressionParser.parseFromString(constraintString);
389 STORM_LOG_TRACE("Adding special (user-provided) constraint " << constraint << ".");
390 constraints.emplace_back(constraint);
391 }
392
393 return constraints;
394}
395
396inline std::vector<std::vector<storm::expressions::Expression>> parseInjectedRefinementPredicates(
397 storm::expressions::ExpressionManager const& expressionManager, std::string const& refinementPredicatesString) {
398 std::vector<std::vector<storm::expressions::Expression>> injectedRefinementPredicates;
399
400 storm::parser::ExpressionParser expressionParser(expressionManager);
401 std::unordered_map<std::string, storm::expressions::Expression> variableMapping;
402 for (auto const& variableTypePair : expressionManager) {
403 variableMapping[variableTypePair.first.getName()] = variableTypePair.first;
404 }
405 expressionParser.setIdentifierMapping(variableMapping);
406
407 std::vector<std::string> predicateGroupsAsStrings;
408 boost::split(predicateGroupsAsStrings, refinementPredicatesString, boost::is_any_of(";"));
409
410 if (!predicateGroupsAsStrings.empty()) {
411 for (auto const& predicateGroupString : predicateGroupsAsStrings) {
412 if (predicateGroupString.empty()) {
413 continue;
414 }
415
416 std::vector<std::string> predicatesAsStrings;
417 boost::split(predicatesAsStrings, predicateGroupString, boost::is_any_of(":"));
418
419 if (!predicatesAsStrings.empty()) {
420 injectedRefinementPredicates.emplace_back();
421 for (auto const& predicateString : predicatesAsStrings) {
422 storm::expressions::Expression predicate = expressionParser.parseFromString(predicateString);
423 STORM_LOG_TRACE("Adding special (user-provided) refinement predicate " << predicateString << ".");
424 injectedRefinementPredicates.back().emplace_back(predicate);
425 }
426
427 STORM_LOG_THROW(!injectedRefinementPredicates.back().empty(), storm::exceptions::InvalidArgumentException,
428 "Expecting non-empty list of predicates to inject for each (mentioned) refinement step.");
429
430 // Finally reverse the list, because we take the predicates from the back.
431 std::reverse(injectedRefinementPredicates.back().begin(), injectedRefinementPredicates.back().end());
432 }
433 }
434
435 // Finally reverse the list, because we take the predicates from the back.
436 std::reverse(injectedRefinementPredicates.begin(), injectedRefinementPredicates.end());
437 }
438
439 return injectedRefinementPredicates;
440}
441
443 storm::expressions::ExpressionManager const* expressionManager = nullptr) {
446 if (expressionManager != nullptr) {
447 options.constraints = parseConstraints(*expressionManager, settings.getConstraintString());
448 options.injectedRefinementPredicates = parseInjectedRefinementPredicates(*expressionManager, settings.getInjectedRefinementPredicates());
449 }
450 options.restrictToRelevantStates = settings.isRestrictToRelevantStatesSet();
451 options.restrictToValidBlocks = settings.getValidBlockMode() == storm::settings::modules::AbstractionSettings::ValidBlockMode::BlockEnumeration;
452 options.useDecomposition = settings.isUseDecompositionSet();
453 options.useInterpolation = settings.isUseInterpolationSet();
454 options.splitMode = settings.getSplitMode();
455 options.pivotSelectionHeuristic = settings.getPivotSelectionHeuristic();
456 options.rankRefinementPredicates = settings.isRankRefinementPredicatesSet();
457 options.useEagerRefinement = settings.isUseEagerRefinementSet();
458 options.addAllGuards = settings.isAddAllGuardsSet();
459 options.addAllInitialExpressions = settings.isAddAllInitialExpressionsSet();
460 options.precision = settings.getPrecision();
461 options.relativeTerminationCriterion = settings.getRelativeTerminationCriterion();
462 options.solveMode = settings.getSolveMode();
463 options.reuseMode = settings.getReuseMode();
464 options.maximalNumberOfAbstractions = settings.getMaximalAbstractionCount();
465 options.fixPlayer1Strategy = settings.isFixPlayer1StrategySet();
466 options.fixPlayer2Strategy = settings.isFixPlayer2StrategySet();
467 options.debug = settings.isDebugSet();
468 return options;
469}
470
471template<storm::dd::DdType DdType, typename ValueType>
473 STORM_LOG_ASSERT(input.model, "Expected symbolic model description.");
475
476 verifyProperties<ValueType>(input, [&input, &options, &mpi](std::shared_ptr<storm::logic::Formula const> const& formula,
477 std::shared_ptr<storm::logic::Formula const> const& states) {
478 STORM_LOG_THROW(states->isInitialFormula(), storm::exceptions::NotSupportedException, "Abstraction-refinement can only filter initial states.");
480 storm::api::createTask<ValueType>(formula, true), options);
481 });
482}
483
484template<typename ValueType>
486 STORM_LOG_ASSERT(input.model, "Expected symbolic model description.");
487 STORM_LOG_THROW((std::is_same<ValueType, double>::value), storm::exceptions::NotSupportedException,
488 "Exploration does not support other data-types than floating points.");
490 input, [&input, &mpi](std::shared_ptr<storm::logic::Formula const> const& formula, std::shared_ptr<storm::logic::Formula const> const& states) {
491 STORM_LOG_THROW(states->isInitialFormula(), storm::exceptions::NotSupportedException, "Exploration can only filter initial states.");
493 });
494}
495
496template<typename ValueType>
497void verifyModel(std::shared_ptr<storm::models::sparse::Model<ValueType>> const& sparseModel, SymbolicInput const& input,
498 ModelProcessingInformation const& mpi) {
500 bool const produceCertificate = storm::settings::getModule<storm::settings::modules::CertificationSettings>().isProduceCertificateSet();
502 auto verificationCallback = [&sparseModel, &ioSettings, &mpi, preferEliminationChecker, produceCertificate](
503 std::shared_ptr<storm::logic::Formula const> const& formula, std::shared_ptr<storm::logic::Formula const> const& states) {
504 auto createTask = [&ioSettings](auto const& f, bool onlyInitialStates) {
505 if constexpr (storm::IsIntervalType<ValueType>) {
506 STORM_LOG_THROW(ioSettings.isUncertaintyResolutionModeSet(), storm::exceptions::InvalidSettingsException,
507 "Uncertainty resolution mode required for uncertain (interval) models.");
508 return storm::api::createTask<ValueType>(f, storm::solver::convert(ioSettings.getUncertaintyResolutionMode()), onlyInitialStates);
509 } else {
510 (void)ioSettings; // suppress unused lambda capture warning. [[maybe_unused]] doesn't work for lambda captures.
511 return storm::api::createTask<ValueType>(f, onlyInitialStates);
512 }
513 };
514 bool const filterForInitialStates = states->isInitialFormula();
515 auto task = createTask(formula, filterForInitialStates);
516 if (ioSettings.isExportSchedulerSet()) {
517 task.setProduceSchedulers(true);
518 }
519 if (produceCertificate) {
520 task.setProduceCertificate(true);
521 }
522 std::unique_ptr<storm::modelchecker::CheckResult> result =
524
525 std::unique_ptr<storm::modelchecker::CheckResult> filter;
526 if (filterForInitialStates) {
527 using SolutionType = storm::IntervalBaseType<ValueType>;
528 filter = std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<SolutionType>>(sparseModel->getInitialStates());
529 } else if (!states->isTrueFormula()) { // No need to apply filter if it is the formula 'true'
530 filter = storm::api::verifyWithSparseEngine<ValueType>(mpi.env, sparseModel, createTask(states, false), preferEliminationChecker);
531 }
532 if (result && filter) {
533 result->filter(filter->asQualitativeCheckResult());
534 }
535 return result;
536 };
537 uint64_t exportCount = 0; // this number will be prepended to the export file name of schedulers and/or check results in case of multiple properties.
538 auto postprocessingCallback = [&sparseModel, &ioSettings, &input, &exportCount](std::unique_ptr<storm::modelchecker::CheckResult> const& result) {
539 // Certificate validity check
540 if (result->isExplicitCertificateCheckResult()) {
542 STORM_PRINT_AND_LOG("Certificate validity check ... ");
543 storm::utility::Stopwatch chkValid(true);
544 bool const valid = result->template asExplicitCertificateCheckResult<ValueType>().checkValidity(*sparseModel);
545 chkValid.stop();
546 STORM_PRINT_AND_LOG((valid ? "valid" : "invalid") << " (time: " << chkValid << ")\n");
547 }
548 }
549
550 // Scheduler export
551 STORM_LOG_WARN_COND(!ioSettings.isExportSchedulerSet() || result->hasScheduler(), "Scheduler requested but could not be generated.");
552 if (ioSettings.isExportSchedulerSet() && result->hasScheduler()) {
553 std::filesystem::path schedulerExportPath = ioSettings.getExportSchedulerFilename();
554 if (exportCount > 0) {
555 STORM_LOG_WARN("Prepending " << exportCount << " to scheduler file name for this property because there are multiple properties.");
556 schedulerExportPath.replace_filename(std::to_string(exportCount) + schedulerExportPath.filename().string());
557 }
558 STORM_PRINT_AND_LOG("Exporting scheduler ... ");
559 if (input.model) {
560 STORM_LOG_WARN_COND(sparseModel->hasStateValuations(),
561 "No information of state valuations available. The scheduler output will use internal state ids. You might be "
562 "interested in building the model with state valuations using --buildstateval.");
564 sparseModel->hasChoiceLabeling() || sparseModel->hasChoiceOrigins(),
565 "No symbolic choice information is available. The scheduler output will use internal choice ids. You might be interested in "
566 "building the model with choice labels or choice origins using --buildchoicelab or --buildchoiceorig.");
567 STORM_LOG_WARN_COND(sparseModel->hasChoiceLabeling() && !sparseModel->hasChoiceOrigins(),
568 "Only partial choice information is available. You might want to build the model with choice origins using "
569 "--buildchoicelab or --buildchoiceorig.");
570 }
571 if (result->isExplicitQuantitativeCheckResult()) {
572 if constexpr (storm::IsIntervalType<ValueType>) {
573 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Scheduler export for interval models is not supported.");
574 } else {
575 storm::api::exportScheduler(sparseModel, result->template asExplicitQuantitativeCheckResult<ValueType>().getScheduler(),
576 schedulerExportPath.string());
577 }
578 } else if (result->isExplicitParetoCurveCheckResult()) {
579 if constexpr (std::is_same_v<ValueType, storm::RationalFunction> || storm::IsIntervalType<ValueType>) {
580 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Scheduler export for models of this value type is not supported.");
581 } else {
582 auto const& paretoRes = result->template asExplicitParetoCurveCheckResult<ValueType>();
583 storm::api::exportParetoScheduler(sparseModel, paretoRes.getPoints(), paretoRes.getSchedulers(), schedulerExportPath.string());
584 }
585 } else if (result->isExplicitQualitativeCheckResult()) {
586 if constexpr (storm::IsIntervalType<ValueType>) {
587 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Scheduler export for interval models is not supported.");
588 } else {
589 storm::api::exportScheduler(sparseModel, result->template asExplicitQualitativeCheckResult<ValueType>().getScheduler(),
590 schedulerExportPath.string());
591 }
592 } else {
593 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Scheduler export not supported for this value type.");
594 }
595 }
596
597 // Result export
598 if (ioSettings.isExportCheckResultSet()) {
599 if constexpr (storm::IsIntervalType<ValueType>) {
600 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Result export for interval models is not supported.");
601 } else {
602 std::filesystem::path resultExportPath = ioSettings.getExportCheckResultFilename();
603 if (exportCount > 0) {
604 STORM_LOG_WARN("Prepending " << exportCount << " to result file name for this property because there are multiple properties.");
605 resultExportPath.replace_filename(std::to_string(exportCount) + resultExportPath.filename().string());
606 }
607 STORM_LOG_WARN_COND(sparseModel->hasStateValuations(),
608 "No information of state valuations available. The result output will use internal state ids. You might be interested in "
609 "building the model with state valuations using --buildstateval.");
610 storm::api::exportCheckResultToJson(sparseModel, result, resultExportPath);
611 }
612 }
613 ++exportCount;
614 };
615 if (!(ioSettings.isComputeSteadyStateDistributionSet() || ioSettings.isComputeExpectedVisitingTimesSet())) {
616 verifyProperties<ValueType>(input, verificationCallback, postprocessingCallback);
617 }
618 if (ioSettings.isComputeSteadyStateDistributionSet()) {
619 if constexpr (storm::IsIntervalType<ValueType>) {
620 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Computing steady state distribution is not supported for interval models.");
621 } else {
623 "steady-state probabilities",
624 [&mpi, &sparseModel]() { return storm::api::computeSteadyStateDistributionWithSparseEngine<ValueType>(mpi.env, sparseModel); }, input,
625 verificationCallback, postprocessingCallback);
626 }
627 }
628 if (ioSettings.isComputeExpectedVisitingTimesSet()) {
629 if constexpr (storm::IsIntervalType<ValueType>) {
630 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Computing expected visiting times is not supported for interval models.");
631 } else {
633 "expected visiting times",
634 [&mpi, &sparseModel]() { return storm::api::computeExpectedVisitingTimesWithSparseEngine<ValueType>(mpi.env, sparseModel); }, input,
635 verificationCallback, postprocessingCallback);
636 }
637 }
638}
639
640template<storm::dd::DdType DdType, typename ValueType>
641void verifyWithHybridEngine(std::shared_ptr<storm::models::symbolic::Model<DdType, ValueType>> const& symbolicModel, SymbolicInput const& input,
642 ModelProcessingInformation const& mpi) {
644 input, [&symbolicModel, &mpi](std::shared_ptr<storm::logic::Formula const> const& formula, std::shared_ptr<storm::logic::Formula const> const& states) {
645 bool filterForInitialStates = states->isInitialFormula();
646 auto task = storm::api::createTask<ValueType>(formula, filterForInitialStates);
647
648 std::unique_ptr<storm::modelchecker::CheckResult> result = storm::api::verifyWithHybridEngine<DdType, ValueType>(mpi.env, symbolicModel, task);
649
650 std::unique_ptr<storm::modelchecker::CheckResult> filter;
651 if (filterForInitialStates) {
652 filter = std::make_unique<storm::modelchecker::SymbolicQualitativeCheckResult<DdType>>(symbolicModel->getReachableStates(),
653 symbolicModel->getInitialStates());
654 } else if (!states->isTrueFormula()) { // No need to apply filter if it is the formula 'true'
656 }
657 if (result && filter) {
658 result->filter(filter->asQualitativeCheckResult());
659 }
660 return result;
661 });
662}
663
664template<storm::dd::DdType DdType, typename ValueType>
665void verifyWithDdEngine(std::shared_ptr<storm::models::symbolic::Model<DdType, ValueType>> const& symbolicModel, SymbolicInput const& input,
666 ModelProcessingInformation const& mpi) {
668 input, [&symbolicModel, &mpi](std::shared_ptr<storm::logic::Formula const> const& formula, std::shared_ptr<storm::logic::Formula const> const& states) {
669 bool filterForInitialStates = states->isInitialFormula();
670 auto task = storm::api::createTask<ValueType>(formula, filterForInitialStates);
671
672 std::unique_ptr<storm::modelchecker::CheckResult> result =
674
675 std::unique_ptr<storm::modelchecker::CheckResult> filter;
676 if (filterForInitialStates) {
677 filter = std::make_unique<storm::modelchecker::SymbolicQualitativeCheckResult<DdType>>(symbolicModel->getReachableStates(),
678 symbolicModel->getInitialStates());
679 } else if (!states->isTrueFormula()) { // No need to apply filter if it is the formula 'true'
681 }
682 if (result && filter) {
683 result->filter(filter->asQualitativeCheckResult());
684 }
685 return result;
686 });
687}
688
689template<storm::dd::DdType DdType, typename ValueType>
691 ModelProcessingInformation const& mpi) {
693 verifyProperties<ValueType>(input, [&symbolicModel, &mpi, &options](std::shared_ptr<storm::logic::Formula const> const& formula,
694 std::shared_ptr<storm::logic::Formula const> const& states) {
695 STORM_LOG_THROW(states->isInitialFormula(), storm::exceptions::NotSupportedException, "Abstraction-refinement can only filter initial states.");
697 storm::api::createTask<ValueType>(formula, true), options);
698 });
699}
700
701template<storm::dd::DdType DdType, typename ValueType>
702typename std::enable_if<storm::dd::BackendTraits<DdType>::template supportsValueType<ValueType>, void>::type verifyModel(
703 std::shared_ptr<storm::models::symbolic::Model<DdType, ValueType>> const& symbolicModel, SymbolicInput const& input,
704 ModelProcessingInformation const& mpi) {
706 verifyWithHybridEngine<DdType, ValueType>(symbolicModel, input, mpi);
707 } else if (mpi.engine == storm::utility::Engine::Dd) {
708 verifyWithDdEngine<DdType, ValueType>(symbolicModel, input, mpi);
709 } else {
711 }
712}
713
714template<storm::dd::DdType DdType, typename ValueType>
715typename std::enable_if<!storm::dd::BackendTraits<DdType>::template supportsValueType<ValueType>, void>::type verifySymbolicModel(
716 std::shared_ptr<storm::models::ModelBase> const&, SymbolicInput const&, ModelProcessingInformation const&) {
717 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, storm::dd::BackendTraits<DdType>::name << " does not support the selected data-type.");
718}
719
720inline void processInput(SymbolicInput const& input, ModelProcessingInformation const& mpi) {
723
724 // For several engines, no model building step is performed, but the verification is started right away.
726 abstractionSettings.getAbstractionRefinementMethod() == storm::settings::modules::AbstractionSettings::Method::Games) {
728 [&input, &mpi]<storm::dd::DdType DD, typename VT>() { verifyWithAbstractionRefinementEngine<DD, VT>(input, mpi); });
730 applyValueType(mpi.verificationValueType, [&input, &mpi]<typename VT>() { verifyWithExplorationEngine<VT>(input, mpi); });
731 } else {
732 std::shared_ptr<storm::models::ModelBase> model = buildPreprocessExportModel(input, mpi);
733 if (model) {
734 if (counterexampleSettings.isCounterexampleSet()) {
735 castAndApply(model, [&input, &mpi](auto const& m) { generateCounterexamples(m, input, mpi); });
736 } else {
737 castAndApply(model, [&input, &mpi](auto const& m) { verifyModel(m, input, mpi); });
738 }
739 }
740 }
741}
742} // namespace cli
743} // namespace storm
This class represents the base class of all exception classes.
virtual const char * what() const noexcept override
Retrieves the message associated with this exception.
This class is responsible for managing a set of typed variables and all expressions using these varia...
std::shared_ptr< storm::logic::Formula const > const & getStatesFormula() const
Definition Property.h:52
storm::modelchecker::FilterType getFilterType() const
Definition Property.h:56
std::shared_ptr< storm::logic::Formula const > getRawFormula() const
Definition Property.cpp:91
FilterExpression const & getFilter() const
Definition Property.cpp:87
static std::shared_ptr< Formula const > getTrueFormula()
Definition Formula.cpp:227
This class represents a discrete-time Markov chain.
Definition Dtmc.h:16
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:16
Base class for all sparse models.
Definition Model.h:34
Base class for all symbolic models.
Definition Model.h:42
storm::expressions::Expression parseFromString(std::string const &expressionString, bool ignoreError=false) const
Parses an expression from the given string.
void setIdentifierMapping(qi::symbols< char, storm::expressions::Expression > const *identifiers_)
Sets an identifier mapping that is used to determine valid variables in the expression.
This class represents the settings for the abstraction procedures.
static bool preservesFormula(storm::logic::Formula const &formula)
Check if the property specified by the given formula is preserved by the transformation.
A class that provides convenience operations to display run times.
Definition Stopwatch.h:13
void stop()
Stop stopwatch and add measured time to total time.
Definition Stopwatch.cpp:42
#define STORM_LOG_WARN(message)
Definition logging.h:35
#define STORM_LOG_TRACE(message)
Definition logging.h:22
#define STORM_LOG_ERROR(message)
Definition logging.h:36
#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
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithHybridEngine(storm::Environment const &env, std::shared_ptr< storm::models::symbolic::Dtmc< DdType, ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task)
void exportScheduler(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, storm::storage::Scheduler< ValueType > const &scheduler, std::string const &filename)
Definition export.h:82
storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > createTask(std::shared_ptr< const storm::logic::Formula > const &formula, bool onlyInitialStatesRelevant=false)
std::shared_ptr< storm::counterexamples::Counterexample > computeHighLevelCounterexampleMaxSmt(storm::Environment const &env, storm::languages::SymbolicModelDescription const &symbolicModel, std::shared_ptr< storm::models::sparse::Model< double > > model, std::shared_ptr< storm::logic::Formula const > const &formula, storm::counterexamples::SMTMinimalLabelSetGenerator< double >::Options const &options)
void exportJaniModelAsDot(storm::jani::Model const &model, std::string const &filename)
Definition export.cpp:7
std::unique_ptr< storm::modelchecker::CheckResult > computeExpectedVisitingTimesWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc)
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithDdEngine(storm::Environment const &env, std::shared_ptr< storm::models::symbolic::Dtmc< DdType, ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task)
std::shared_ptr< storm::logic::Formula const > checkAndTransformContinuousToDiscreteTimeFormula(storm::logic::Formula const &formula, std::string const &timeRewardName="_time")
std::shared_ptr< storm::counterexamples::Counterexample > computeHighLevelCounterexampleMilp(storm::Environment const &env, storm::languages::SymbolicModelDescription const &symbolicModel, std::shared_ptr< storm::models::sparse::Mdp< double > > mdp, std::shared_ptr< storm::logic::Formula const > const &formula, bool includeSchedulerCuts)
void exportCheckResultToJson(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::unique_ptr< storm::modelchecker::CheckResult > const &checkResult, std::string const &filename)
Definition export.h:129
std::shared_ptr< storm::counterexamples::Counterexample > computeKShortestPathCounterexample(std::shared_ptr< storm::models::sparse::Model< double > > model, std::shared_ptr< storm::logic::Formula const > const &formula, size_t maxK)
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithExplorationEngine(storm::Environment const &env, storm::languages::SymbolicModelDescription const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task)
void exportParetoScheduler(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::vector< PointType > const &points, std::vector< storm::storage::Scheduler< ValueType > > const &schedulers, std::string const &baseFilenameStr)
Definition export.h:96
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, bool preferEliminationChecker=false)
std::unique_ptr< storm::modelchecker::CheckResult > computeSteadyStateDistributionWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc)
void exportSymbolicInput(SymbolicInput const &input)
void verifyWithAbstractionRefinementEngine(SymbolicInput const &input, ModelProcessingInformation const &mpi)
void verifyModel(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &sparseModel, SymbolicInput const &input, ModelProcessingInformation const &mpi)
auto castAndApply(std::shared_ptr< storm::models::ModelBase > const &model, auto const &callback)
void verifyWithExplorationEngine(SymbolicInput const &input, ModelProcessingInformation const &mpi)
std::enable_if<!storm::dd::BackendTraits< DdType >::templatesupportsValueType< ValueType >, void >::type verifySymbolicModel(std::shared_ptr< storm::models::ModelBase > const &, SymbolicInput const &, ModelProcessingInformation const &)
void printResult(std::unique_ptr< storm::modelchecker::CheckResult > const &result, storm::logic::Formula const &filterStatesFormula, storm::modelchecker::FilterType const &filterType, storm::utility::Stopwatch *watch=nullptr)
auto applyValueType(ModelProcessingInformation::ValueType vt, auto const &callback)
std::shared_ptr< storm::models::ModelBase > buildPreprocessExportModel(SymbolicInput const &input, ModelProcessingInformation const &mpi)
void verifyProperties(SymbolicInput const &input, VerificationCallbackType const &verificationCallback, PostprocessingCallbackType const &postprocessingCallback=PostprocessingIdentity())
Verifies all (potentially preprocessed) properties given in input.
std::vector< storm::expressions::Expression > parseConstraints(storm::expressions::ExpressionManager const &expressionManager, std::string const &constraintsString)
std::vector< std::vector< storm::expressions::Expression > > parseInjectedRefinementPredicates(storm::expressions::ExpressionManager const &expressionManager, std::string const &refinementPredicatesString)
void generateCounterexamples(std::shared_ptr< ModelType > const &, SymbolicInput const &, ModelProcessingInformation const &)
void verifyWithDdEngine(std::shared_ptr< storm::models::symbolic::Model< DdType, ValueType > > const &symbolicModel, SymbolicInput const &input, ModelProcessingInformation const &mpi)
std::function< std::unique_ptr< storm::modelchecker::CheckResult >(std::shared_ptr< storm::logic::Formula const > const &formula, std::shared_ptr< storm::logic::Formula const > const &states)> VerificationCallbackType
void printFilteredResult(std::unique_ptr< storm::modelchecker::CheckResult > const &result, storm::modelchecker::FilterType ft)
void computeStateValues(std::string const &description, std::function< std::unique_ptr< storm::modelchecker::CheckResult >()> const &computationCallback, SymbolicInput const &input, VerificationCallbackType const &verificationCallback, PostprocessingCallbackType const &postprocessingCallback=PostprocessingIdentity())
Computes values for each state (such as the steady-state probability distribution).
std::function< void(std::unique_ptr< storm::modelchecker::CheckResult > const &)> PostprocessingCallbackType
void printCounterexample(std::shared_ptr< storm::counterexamples::Counterexample > const &counterexample, storm::utility::Stopwatch *watch=nullptr)
void printModelCheckingProperty(storm::jani::Property const &property)
void verifyWithHybridEngine(std::shared_ptr< storm::models::symbolic::Model< DdType, ValueType > > const &symbolicModel, SymbolicInput const &input, ModelProcessingInformation const &mpi)
void printComputingCounterexample(storm::jani::Property const &property)
auto applyDdLibValueType(storm::dd::DdType dd, ModelProcessingInformation::ValueType vt, auto const &callback)
bool preferEliminationChecker()
Returns whether the settings request to prefer the dedicated elimination model checker.
void processInput(SymbolicInput const &input, ModelProcessingInformation const &mpi)
storm::gbar::api::AbstractionRefinementOptions getAbstractionRefinementOptions(storm::expressions::ExpressionManager const *expressionManager=nullptr)
std::unique_ptr< storm::modelchecker::CheckResult > verifyProperty(std::shared_ptr< storm::logic::Formula const > const &formula, std::shared_ptr< storm::logic::Formula const > const &statesFilter, VerificationCallbackType const &verificationCallback)
Verifies the given formula plus a filter formula to identify relevant states and warns the user in ca...
std::enable_if<!std::is_same< ValueType, storm::RationalFunction >::value, std::unique_ptr< storm::modelchecker::CheckResult > >::type verifyWithAbstractionRefinementEngine(storm::Environment const &env, storm::languages::SymbolicModelDescription const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, AbstractionRefinementOptions const &options=AbstractionRefinementOptions())
storm::gbar::abstraction::AbstractionOptions AbstractionRefinementOptions
constexpr bool SupportsCertificates
Certificates can be computed for models with these value types.
Definition Certificate.h:27
std::string toString(FilterType ft)
Definition FilterType.cpp:9
SettingsType const & getModule()
Get module.
OptimizationDirection convert(OptimizationDirectionSetting s)
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
bool isConstant(ValueType const &)
bool isInfinity(ValueType const &a)
TargetType convertNumber(SourceType const &number)
The contract of a DD backend.
constexpr bool IsIntervalType
Helper to check if a type is an interval.
typename detail::IntervalMetaProgrammingHelper< ValueType >::BaseType IntervalBaseType
Helper to access the type in which interval boundaries are stored.
#define STORM_PRINT_AND_LOG(message)
Definition print.h:20
#define STORM_PRINT(message)
Define the macros that print information to stdout and optionally also log it.
Definition print.h:14
static const bool IsExact
void operator()(std::unique_ptr< storm::modelchecker::CheckResult > const &)
std::vector< storm::jani::Property > properties
boost::optional< storm::languages::SymbolicModelDescription > model
boost::optional< std::vector< storm::jani::Property > > preprocessedProperties
bool useDecomposition
A flag indicating whether decomposition is to be used during the abstraction.
bool relativeTerminationCriterion
A flag indicating whether to use a relative termination criterion.
SolveMode solveMode
The mode with which to solve the abstractions.
bool restrictToValidBlocks
A flag indicating whether the abstractor restricts the initial states to valid blocks.
bool useInterpolation
A flag indicating whether interpolation is to be used to eliminate spurious pivot blocks.
ReuseMode reuseMode
The mode determining which results are reused.
bool fixPlayer1Strategy
A flag indicating whether player 1 strategies are to be fixed.
bool debug
A flag indicating whether debug mode is enabled.
std::vector< std::vector< storm::expressions::Expression > > injectedRefinementPredicates
Predicates that are injected (starting with the last one in this list) instead of the derived ones.
bool fixPlayer2Strategy
A flag indicating whether player 2 strategies are to be fixed.
bool addAllInitialExpressions
A flag indicating whether all initial expressions are added as initial predicates.
bool useEagerRefinement
A flag indicating whether to refine eagerly.
SplitMode splitMode
The mode that determines which predicates are split into atoms for the refinement.
bool rankRefinementPredicates
A flag indicating whether refinement predicates are to be ranked.
std::vector< storm::expressions::Expression > constraints
Additional constraints used by the abstraction.
bool addAllGuards
A flag indicating whether all guards are added as initial predicates.
bool restrictToRelevantStates
A flag indicating whether the abstractor restricts the abstraction to relevant states.
uint_fast64_t maximalNumberOfAbstractions
The maximal number of abstractions to perform until giving up on converging.
double precision
The precision used for detecting convergence.
PivotSelectionHeuristic pivotSelectionHeuristic
The heuristic to use for pivot block selection.