9#include <boost/algorithm/string.hpp>
48template<
typename ValueType>
51template<
typename ValueType>
53 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
58 modelParameters.insert(rewParameters.begin(), rewParameters.end());
60 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
62 return modelParameters;
65template<
typename ValueType>
66std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType>
parseVariableList(
68 if (inputString ==
"") {
71 std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType> variables;
72 std::vector<std::string> variableStrings;
73 boost::split(variableStrings, inputString, boost::is_any_of(
","));
74 for (
auto& var : variableStrings) {
78 for (
auto const& param : consideredVariables) {
79 if (var == param.name()) {
80 variables.push_back(param);
92template<
typename ValueType>
93std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType>
parseVariableList(std::string
const& inputString,
95 return parseVariableList<ValueType>(inputString, getModelParameters<ValueType>(model));
98template<
typename ValueType>
99std::vector<storm::storage::ParameterRegion<ValueType>>
parseRegions(
110template<
typename ValueType>
112 return parseRegions<ValueType>(inputString, getModelParameters<ValueType>(model));
115template<
typename ValueType>
121template<
typename ValueType>
123 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
128 modelParameters.insert(rewParameters.begin(), rewParameters.end());
130 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
132 return std::vector<storm::storage::ParameterRegion<ValueType>>({createRegion<ValueType>(inputString, modelParameters)});
135template<
typename ValueType>
139 if (inputString ==
"" && consideredVariables.empty()) {
143 auto res = parseRegions<ValueType>(inputString, consideredVariables);
144 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
148template<
typename ValueType>
155 auto res = parseRegions<ValueType>(inputString, model);
156 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
160template<
typename ValueType>
161std::pair<std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>,
162 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>>
164 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
167 modelParameters.insert(rewParameters.begin(), rewParameters.end());
169 fileName, modelParameters));
172template<
typename ParametricType>
176 bool preconditionsValidatedManually =
false) {
178 "Could not validate whether parameter lifting is applicable. Please validate manually...");
179 std::shared_ptr<storm::models::sparse::Model<ParametricType>> consideredModel = model;
183 STORM_LOG_WARN(
"Parameter lifting not supported for continuous time models. Transforming continuous model to discrete model...");
184 std::vector<std::shared_ptr<storm::logic::Formula const>> taskFormulaAsVector{task.
getFormula().asSharedPointer()};
187 storm::exceptions::UnexpectedException,
"Transformation to discrete time model has failed.");
189 return consideredModel;
192template<
typename ParametricType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
196 "Unable to create a region checker for the provided model type.");
201 return std::make_unique<
204 return std::make_unique<
209 return std::make_unique<
212 return std::make_unique<storm::modelchecker::SparseMdpParameterLiftingModelChecker<storm::models::sparse::Mdp<ParametricType>, PreciseType>>();
215 return std::make_unique<
219 return std::make_unique<storm::modelchecker::ValidatingSparseParameterLiftingModelChecker<storm::models::sparse::Dtmc<ParametricType>,
220 ImpreciseType, PreciseType>>();
222 return std::make_unique<storm::modelchecker::ValidatingSparseParameterLiftingModelChecker<storm::models::sparse::Mdp<ParametricType>,
223 ImpreciseType, PreciseType>>();
226 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unexpected region model checker type.");
231template<
typename ParametricType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
237 monotoneParameters = std::nullopt) {
239 auto monotonicityBackend = std::make_unique<storm::modelchecker::MonotonicityBackend<ParametricType>>();
243 std::unique_ptr<storm::modelchecker::MonotonicityBackend<ParametricType>> orderBasedBackend;
245 orderBasedBackend = std::make_unique<storm::modelchecker::OrderBasedMonotonicityBackend<ParametricType, PreciseType>>(
248 orderBasedBackend = std::make_unique<storm::modelchecker::OrderBasedMonotonicityBackend<ParametricType, ImpreciseType>>(
252 monotonicityBackend = std::move(orderBasedBackend);
254 STORM_LOG_WARN(
"Order-based Monotonicity enabled for region checking engine " << engine <<
" but not supported in this configuration.");
259 if (monotoneParameters) {
260 for (
auto const& incrPar : monotoneParameters->first) {
263 for (
auto const& decrPar : monotoneParameters->second) {
267 return monotonicityBackend;
270template<
typename ValueType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
274 bool allowModelSimplification =
true,
bool graphPreserving =
true,
bool preconditionsValidated =
false,
278 monotoneParameters = std::nullopt) {
280 auto regionChecker = createRegionModelChecker<ValueType, ImpreciseType, PreciseType>(engine, model->getType());
281 auto monotonicityBackend =
282 initializeMonotonicityBackend<ValueType, ImpreciseType, PreciseType>(*regionChecker, engine, task, monotonicitySetting, monotoneParameters);
283 if (allowModelSimplification) {
284 allowModelSimplification = monotonicityBackend->recommendModelSimplifications();
285 STORM_LOG_WARN_COND(allowModelSimplification,
"Model simplification is disabled because the monotonicity algorithm does not recommend it.");
287 regionChecker->specify(env, consideredModel, task, std::nullopt, std::move(monotonicityBackend), allowModelSimplification, graphPreserving);
288 return regionChecker;
291template<
typename ValueType>
299template<
typename ValueType>
303 std::vector<storm::modelchecker::RegionResultHypothesis>
const& hypotheses,
bool sampleVerticesOfRegions) {
306 return regionChecker->analyzeRegions(env, regions, hypotheses, sampleVerticesOfRegions);
309template<
typename ValueType>
314 bool sampleVerticesOfRegions =
false) {
315 std::vector<storm::modelchecker::RegionResultHypothesis> hypotheses(regions.size(), hypothesis);
319template<
typename ValueType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
323 auto regionChecker = createRegionModelChecker<ValueType, ImpreciseType, PreciseType>(settings.
engine, settings.
model->getType());
324 auto monotonicityBackend = initializeMonotonicityBackend<ValueType, ImpreciseType, PreciseType>(*regionChecker, settings.
engine, settings.
task,
327 auto refinementChecker = std::make_unique<storm::modelchecker::RegionRefinementChecker<ValueType>>(std::move(regionChecker));
330 return refinementChecker;
344template<
typename ValueType>
347 std::optional<uint64_t>
const& refinementDepthThreshold = std::nullopt,
351 return regionRefinementChecker->performRegionPartitioning(env, region, coverageThreshold, refinementDepthThreshold, hypothesis, monThresh);
365template<
typename ValueType>
366std::pair<storm::RationalNumber, typename storm::storage::ParameterRegion<ValueType>::Valuation>
computeExtremalValue(
368 std::optional<ValueType>
const& precision,
bool absolutePrecision, std::optional<storm::logic::Bound>
const& boundInvariant) {
372 refinementChecker->computeExtremalValue(env, region, dir, precision.value_or(storm::utility::zero<ValueType>()), absolutePrecision, boundInvariant);
373 return {storm::utility::convertNumber<storm::RationalNumber>(res.first), std::move(res.second)};
382template<
typename ValueType>
386 storm::exceptions::NotSupportedException,
"Only probability and reward operators supported");
388 "Verification requires a bounded operator formula.");
392 return refinementChecker->verifyRegion(env, region, bound);
395template<
typename ValueType>
397 bool onlyConclusiveResults =
false) {
399 STORM_LOG_THROW(regionCheckResult !=
nullptr, storm::exceptions::UnexpectedException,
400 "Can not export region check result: The given checkresult does not have the expected type.");
402 std::ofstream filestream;
404 for (
auto const& res : regionCheckResult->getRegionResults()) {
407 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)
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.
@ ParameterLifting
Parameter lifting approach.
@ ValidatingParameterLifting
Parameter lifting approach with a) inexact (and fast) computation first and b) exact validation of ob...
@ RobustParameterLifting
Parameter lifting approach based on robust markov models instead of generating nondeterminism.
@ 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...
bool useOnlyGlobalMonotonicity
std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > const & discreteVariables
storm::modelchecker::RegionCheckEngine engine
std::shared_ptr< storm::models::sparse::Model< ValueType > > model
storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > task
bool preconditionsValidated
MonotonicityOptions monotonicitySetting
storm::modelchecker::RegionSplittingStrategy regionSplittingStrategy
std::optional< std::pair< std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType >, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > > > monotoneParameters
bool allowModelSimplification