Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
graphPreservation.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <optional>
5#include <sstream>
6#include <string>
7#include <type_traits>
8#include <vector>
9
22
23namespace storm::pars {
24
28template<typename ValueType>
29std::optional<storm::analysis::ConstraintCollector> collectConstraints(std::shared_ptr<storm::models::ModelBase> const& model) {
30 if constexpr (std::is_same_v<ValueType, storm::RationalFunction>) {
31 if (model && model->isSparseModel()) {
32 try {
34 } catch (storm::exceptions::BaseException const& exception) {
35 STORM_LOG_WARN("Could not collect the constraints of the model; they will be treated as undecided: " << exception.what());
36 }
37 }
38 }
39 return std::nullopt;
40}
41
47template<typename ValueType>
48std::optional<storm::pars::analysis::RegionCheckResult> checkRegionConstraints(std::optional<storm::analysis::ConstraintCollector> const& collector,
49 storm::storage::ParameterRegion<ValueType> const& region, bool wellformedness) {
50 if constexpr (std::is_same_v<ValueType, storm::RationalFunction>) {
51 if (collector) {
53 try {
54 return wellformedness ? checker.checkWellformedness(region) : checker.checkGraphPreservation(region);
55 } catch (storm::exceptions::BaseException const& exception) {
56 STORM_LOG_WARN("Could not check the constraints for region " << region << "; treating them as undecided: " << exception.what());
57 }
58 }
59 }
60 return std::nullopt;
61}
62
67 std::stringstream message;
68 message << "the constraint '" << result.violatedConstraint->toString() << "' is violated";
69 if (result.witness) {
70 message << " at the point " << *result.witness;
71 }
72 return message.str();
73}
74
84template<typename ValueType>
85storm::pars::analysis::GraphPreservationStatus establishGraphPreservation(std::shared_ptr<storm::models::ModelBase> const& model,
86 std::vector<storm::storage::ParameterRegion<ValueType>> const& regions,
87 bool graphPreservationRequired) {
88 bool const assumed = storm::settings::getModule<storm::settings::modules::RegionSettings>().isAssumeGraphPreservingSet();
89 bool const needsGraphPreservation = assumed || graphPreservationRequired;
90 auto const collector = collectConstraints<ValueType>(model);
91
94 for (auto const& region : regions) {
95 auto const result = checkRegionConstraints<ValueType>(collector, region, !needsGraphPreservation);
96 if (result && result->verdict == storm::pars::analysis::ConstraintVerdict::Sat) {
97 continue;
98 }
99 bool const violated = result && result->verdict == storm::pars::analysis::ConstraintVerdict::Unsat;
100
101 if (!needsGraphPreservation) {
102 // Ill-defined regions are handled by the engine itself, so we do not warn.
103 if (violated) {
107 }
108 } else if (assumed) {
109 STORM_LOG_WARN_COND(!violated, "Region " << region << " does not preserve the graph structure of the parametric model: "
110 << describeViolation(*result) << ". Set --assume-graph-preserving false.");
111 } else {
112 STORM_LOG_THROW(!violated, storm::exceptions::InvalidSettingsException,
113 "Region " << region << " is provably not graph-preserving: " << describeViolation(*result)
114 << ". Pass --assume-graph-preserving true to proceed nevertheless.");
115 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException,
116 "Cannot prove that region " << region
117 << " preserves the graph structure of the parametric model. This is only possible for sparse "
118 "parametric models with decidable (e.g. linear) constraints. Pass --assume-graph-preserving "
119 "true to skip this check.");
120 }
121 }
122 return status;
123}
124
125} // namespace storm::pars
Class to collect constraints on parametric Markov chains.
This class represents the base class of all exception classes.
virtual const char * what() const noexcept override
Retrieves the message associated with this exception.
Base class for all sparse models.
Definition Model.h:34
Checks whether the constraints collected for a parametric model hold over an entire rectangular regio...
RegionCheckResult checkGraphPreservation(RationalFunctionRegion const &region) const
Checks the graph-preserving constraints together with the well-formedness constraints,...
RegionCheckResult checkWellformedness(RationalFunctionRegion const &region) const
#define STORM_LOG_WARN(message)
Definition logging.h:35
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:54
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
GraphPreservationStatus
Describes to what extent a set of regions is known to be well-defined and to preserve the graph struc...
@ WellDefined
The regions are known to be well-defined, i.e.
@ Unknown
It could not be established whether the regions are well-defined or preserve the graph structure of t...
@ GraphPreserving
The regions are known (or assumed) to preserve the graph structure of the model.
std::optional< storm::pars::analysis::RegionCheckResult > checkRegionConstraints(std::optional< storm::analysis::ConstraintCollector > const &collector, storm::storage::ParameterRegion< ValueType > const &region, bool wellformedness)
Checks the well-formedness constraints or the graph-preservation constraints over the region.
std::optional< storm::analysis::ConstraintCollector > collectConstraints(std::shared_ptr< storm::models::ModelBase > const &model)
Collects the constraints of the model.
storm::pars::analysis::GraphPreservationStatus establishGraphPreservation(std::shared_ptr< storm::models::ModelBase > const &model, std::vector< storm::storage::ParameterRegion< ValueType > > const &regions, bool graphPreservationRequired)
Determines to what extent the regions are known to be well-defined and graph-preserving.
std::string describeViolation(storm::pars::analysis::RegionCheckResult const &result)
Describes a violated constraint, including the point at which it fails.
SettingsType const & getModule()
Get module.
std::optional< RegionWitness > witness
A point at which a constraint is violated.
std::optional< storm::expressions::Expression > violatedConstraint
The constraint violated at the witness.