9#include <boost/algorithm/string.hpp>
45template<
typename ValueType>
48template<
typename ValueType>
50 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
55 modelParameters.insert(rewParameters.begin(), rewParameters.end());
57 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
59 return modelParameters;
62template<
typename ValueType>
63std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType>
parseVariableList(
65 if (inputString ==
"") {
68 std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType> variables;
69 std::vector<std::string> variableStrings;
70 boost::split(variableStrings, inputString, boost::is_any_of(
","));
71 for (
auto& var : variableStrings) {
75 for (
auto const& param : consideredVariables) {
76 if (var == param.name()) {
77 variables.push_back(param);
89template<
typename ValueType>
90std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType>
parseVariableList(std::string
const& inputString,
95template<
typename ValueType>
96std::vector<storm::storage::ParameterRegion<ValueType>>
parseRegions(
107template<
typename ValueType>
112template<
typename ValueType>
118template<
typename ValueType>
120 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
125 modelParameters.insert(rewParameters.begin(), rewParameters.end());
127 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
129 return std::vector<storm::storage::ParameterRegion<ValueType>>({
createRegion<ValueType>(inputString, modelParameters)});
132template<
typename ValueType>
136 if (inputString ==
"" && consideredVariables.empty()) {
141 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
145template<
typename ValueType>
153 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
157template<
typename ValueType>
158std::pair<std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>,
159 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>>
161 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
164 modelParameters.insert(rewParameters.begin(), rewParameters.end());
166 fileName, modelParameters));
169template<
typename ParametricType>
173 bool preconditionsValidatedManually =
false) {
175 "Could not validate whether parameter lifting is applicable. Please validate manually...");
176 std::shared_ptr<storm::models::sparse::Model<ParametricType>> consideredModel = model;
180 STORM_LOG_WARN(
"Parameter lifting not supported for continuous time models. Transforming continuous model to discrete model...");
181 std::vector<std::shared_ptr<storm::logic::Formula const>> taskFormulaAsVector{task.
getFormula().asSharedPointer()};
184 storm::exceptions::UnexpectedException,
"Transformation to discrete time model has failed.");
186 return consideredModel;
189template<
typename ParametricType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
193extern template std::unique_ptr<storm::modelchecker::RegionModelChecker<storm::RationalFunction>>
197template<
typename ParametricType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
203 monotoneParameters = std::nullopt) {
205 auto monotonicityBackend = std::make_unique<storm::modelchecker::MonotonicityBackend<ParametricType>>();
209 std::unique_ptr<storm::modelchecker::MonotonicityBackend<ParametricType>> orderBasedBackend;
211 orderBasedBackend = std::make_unique<storm::modelchecker::OrderBasedMonotonicityBackend<ParametricType, PreciseType>>(
214 orderBasedBackend = std::make_unique<storm::modelchecker::OrderBasedMonotonicityBackend<ParametricType, ImpreciseType>>(
218 monotonicityBackend = std::move(orderBasedBackend);
220 STORM_LOG_WARN(
"Order-based Monotonicity enabled for region checking engine " << engine <<
" but not supported in this configuration.");
225 if (monotoneParameters) {
226 for (
auto const& incrPar : monotoneParameters->first) {
229 for (
auto const& decrPar : monotoneParameters->second) {
233 return monotonicityBackend;
236template<
typename ValueType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
240 bool allowModelSimplification =
true,
bool graphPreserving =
true,
bool preconditionsValidated =
false,
244 monotoneParameters = std::nullopt) {
247 auto monotonicityBackend =
249 if (allowModelSimplification) {
250 allowModelSimplification = monotonicityBackend->recommendModelSimplifications();
251 STORM_LOG_WARN_COND(allowModelSimplification,
"Model simplification is disabled because the monotonicity algorithm does not recommend it.");
253 regionChecker->specify(env, consideredModel, task, std::nullopt, std::move(monotonicityBackend), allowModelSimplification, graphPreserving);
254 return regionChecker;
257template<
typename ValueType>
265template<
typename ValueType>
269 std::vector<storm::modelchecker::RegionResultHypothesis>
const& hypotheses,
bool sampleVerticesOfRegions) {
272 return regionChecker->analyzeRegions(env, regions, hypotheses, sampleVerticesOfRegions);
275template<
typename ValueType>
280 bool sampleVerticesOfRegions =
false) {
281 std::vector<storm::modelchecker::RegionResultHypothesis> hypotheses(regions.size(), hypothesis);
285template<
typename ValueType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
292 settings.allowModelSimplification =
settings.allowModelSimplification && monotonicityBackend->recommendModelSimplifications();
293 auto refinementChecker = std::make_unique<storm::modelchecker::RegionRefinementChecker<ValueType>>(std::move(regionChecker));
294 refinementChecker->specify(env, consideredModel,
settings.task, std::move(
settings.regionSplittingStrategy), std::move(
settings.discreteVariables),
295 std::move(monotonicityBackend),
settings.allowModelSimplification,
settings.graphPreserving);
296 return refinementChecker;
310template<
typename ValueType>
313 std::optional<uint64_t>
const& refinementDepthThreshold = std::nullopt,
317 return regionRefinementChecker->performRegionPartitioning(env, region, coverageThreshold, refinementDepthThreshold, hypothesis, monThresh);
331template<
typename ValueType>
332std::pair<storm::RationalNumber, typename storm::storage::ParameterRegion<ValueType>::Valuation>
computeExtremalValue(
334 std::optional<ValueType>
const& precision,
bool absolutePrecision, std::optional<storm::logic::Bound>
const& boundInvariant) {
348template<
typename ValueType>
352 storm::exceptions::NotSupportedException,
"Only probability and reward operators supported.");
353 STORM_LOG_THROW(
settings.task.getFormula().asOperatorFormula().hasBound(), storm::exceptions::NotSupportedException,
354 "Verification requires a bounded operator formula.");
358 return refinementChecker->verifyRegion(env, region, bound);
361template<
typename ValueType>
363 bool onlyConclusiveResults =
false) {
365 STORM_LOG_THROW(regionCheckResult !=
nullptr, storm::exceptions::UnexpectedException,
366 "Can not export region check result: The given checkresult does not have the expected type.");
368 std::ofstream filestream;
370 for (
auto const& res : regionCheckResult->getRegionResults()) {
373 filestream << res.second <<
": " << res.first <<
'\n';
FormulaType const & getFormula() const
Retrieves the formula from this task.
virtual bool isMonotonicitySupported(MonotonicityBackend< ParametricType > const &backend, CheckTask< storm::logic::Formula, ParametricType > const &checkTask) const =0
Returns whether this region model checker can work together with the given monotonicity backend.
virtual bool hasParameters() const
Checks whether the model has parameters.
virtual bool isSparseModel() const
Checks whether the model is a sparse model.
Base class for all sparse models.
static storm::storage::ParameterRegion< ParametricType > createRegion(std::string const ®ionBound, std::set< VariableType > const &consideredVariables)
static std::vector< storm::storage::ParameterRegion< ParametricType > > parseMultipleRegions(std::string const ®ionsString, std::set< VariableType > const &consideredVariables)
static std::vector< storm::storage::ParameterRegion< ParametricType > > parseMultipleRegionsFromFile(std::string const &fileName, std::set< VariableType > const &consideredVariables)
storm::utility::parametric::VariableType< ParametricType >::type VariableType
#define STORM_LOG_WARN(message)
#define STORM_LOG_ERROR(message)
#define STORM_LOG_WARN_COND(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
@ Incr
the result is monotonically increasing
@ Decr
the result is monotonically decreasing
void exportRegionCheckResultToFile(std::unique_ptr< storm::modelchecker::CheckResult > const &checkResult, std::string const &filename, bool onlyConclusiveResults=false)
std::vector< storm::storage::ParameterRegion< ValueType > > parseRegions(std::string const &inputString, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > const &consideredVariables)
std::shared_ptr< storm::models::sparse::Model< ParametricType > > preprocessSparseModelForParameterLifting(std::shared_ptr< storm::models::sparse::Model< ParametricType > > const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ParametricType > const &task, storm::modelchecker::RegionCheckEngine engine, bool preconditionsValidatedManually=false)
std::unique_ptr< storm::modelchecker::MonotonicityBackend< ParametricType > > initializeMonotonicityBackend(storm::modelchecker::RegionModelChecker< ParametricType > const ®ionChecker, storm::modelchecker::RegionCheckEngine engine, storm::modelchecker::CheckTask< storm::logic::Formula, ParametricType > const &task, MonotonicitySetting const &monotonicitySetting, std::optional< std::pair< std::set< typename storm::storage::ParameterRegion< ParametricType >::VariableType >, std::set< typename storm::storage::ParameterRegion< ParametricType >::VariableType > > > monotoneParameters=std::nullopt)
storm::storage::ParameterRegion< ValueType > parseRegion(std::string const &inputString, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > const &consideredVariables)
std::unique_ptr< storm::modelchecker::RegionCheckResult< ValueType > > checkRegionsWithSparseEngine(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, std::vector< storm::storage::ParameterRegion< ValueType > > const ®ions, storm::modelchecker::RegionCheckEngine engine, std::vector< storm::modelchecker::RegionResultHypothesis > const &hypotheses, bool sampleVerticesOfRegions)
std::pair< std::shared_ptr< storm::models::sparse::Model< ValueType > >, std::vector< std::shared_ptr< storm::logic::Formula const > > > transformContinuousToDiscreteTimeSparseModel(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas)
Transforms the given continuous model to a discrete time model.
std::unique_ptr< storm::modelchecker::RegionRefinementCheckResult< ValueType > > checkAndRefineRegionWithSparseEngine(RefinementOptions< ValueType > settings, storm::storage::ParameterRegion< ValueType > const ®ion, std::optional< ValueType > const &coverageThreshold, std::optional< uint64_t > const &refinementDepthThreshold=std::nullopt, storm::modelchecker::RegionResultHypothesis hypothesis=storm::modelchecker::RegionResultHypothesis::Unknown, uint64_t monThresh=0)
Checks and iteratively refines the given region with the sparse engine.
std::unique_ptr< storm::modelchecker::RegionModelChecker< ParametricType > > createRegionModelChecker(storm::modelchecker::RegionCheckEngine engine, storm::models::ModelType modelType)
std::unique_ptr< storm::modelchecker::RegionModelChecker< ValueType > > initializeRegionModelChecker(Environment const &env, std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, storm::modelchecker::RegionCheckEngine engine, bool allowModelSimplification=true, bool graphPreserving=true, bool preconditionsValidated=false, MonotonicitySetting monotonicitySetting=MonotonicitySetting(), std::optional< std::pair< std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType >, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > > > monotoneParameters=std::nullopt)
std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > getModelParameters(storm::models::ModelBase const &model)
std::pair< storm::RationalNumber, typename storm::storage::ParameterRegion< ValueType >::Valuation > computeExtremalValue(RefinementOptions< ValueType > settings, storm::storage::ParameterRegion< ValueType > const ®ion, storm::solver::OptimizationDirection const &dir, std::optional< ValueType > const &precision, bool absolutePrecision, std::optional< storm::logic::Bound > const &boundInvariant)
Finds the extremal value in the given region.
storm::pars::modelchecker::MonotonicityOptions MonotonicitySetting
std::unique_ptr< storm::modelchecker::RegionRefinementChecker< ValueType > > initializeRegionRefinementChecker(Environment const &env, RefinementOptions< ValueType > settings)
std::vector< typename storm::storage::ParameterRegion< ValueType >::VariableType > parseVariableList(std::string const &inputString, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > const &consideredVariables)
bool verifyRegion(RefinementOptions< ValueType > settings, storm::storage::ParameterRegion< ValueType > const ®ion)
Verifies whether a region satisfies a property.
storm::storage::ParameterRegion< ValueType > createRegion(std::string const &inputString, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > const &consideredVariables)
template std::unique_ptr< storm::modelchecker::RegionModelChecker< storm::RationalFunction > > createRegionModelChecker< storm::RationalFunction, double, storm::RationalNumber >(storm::modelchecker::RegionCheckEngine engine, storm::models::ModelType modelType)
storm::pars::modelchecker::RegionRefinementOptions< ValueType > RefinementOptions
std::pair< std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType >, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > > parseMonotoneParameters(std::string const &fileName, std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model)
void closeFile(std::ofstream &stream)
Close the given file after writing.
bool fileExistsAndIsReadable(std::string const &filename)
Tests whether the given file exists and is readable.
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
@ 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
@ AllIllDefined
the formula is ill-defined for all parameters in the given region
RegionResultHypothesis
hypothesis for the result for a single Parameter Region
RegionCheckEngine
The considered engine for region checking.
@ ExactParameterLifting
Parameter lifting approach with exact arithmethics.
std::set< storm::RationalFunctionVariable > getRewardParameters(Model< storm::RationalFunction > const &model)
Get all parameters occurring in rewards.
std::set< storm::RationalFunctionVariable > getProbabilityParameters(Model< storm::RationalFunction > const &model)
Get all probability parameters occurring on transitions.
static bool validateParameterLiftingSound(storm::models::sparse::Model< ValueType > const &model, storm::logic::Formula const &formula, storm::modelchecker::RegionCheckEngine engine)
Checks whether the parameter lifting approach is sound on the given model with respect to the provide...
TargetType convertNumber(SourceType const &number)
bool useOnlyGlobalMonotonicity