9#include <boost/algorithm/string.hpp>
47template<
typename ValueType>
50template<
typename ValueType>
52 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
57 modelParameters.insert(rewParameters.begin(), rewParameters.end());
59 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
61 return modelParameters;
64template<
typename ValueType>
65std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType>
parseVariableList(
67 if (inputString ==
"") {
70 std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType> variables;
71 std::vector<std::string> variableStrings;
72 boost::split(variableStrings, inputString, boost::is_any_of(
","));
73 for (
auto& var : variableStrings) {
77 for (
auto const& param : consideredVariables) {
78 if (var == param.name()) {
79 variables.push_back(param);
91template<
typename ValueType>
92std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType>
parseVariableList(std::string
const& inputString,
97template<
typename ValueType>
98std::vector<storm::storage::ParameterRegion<ValueType>>
parseRegions(
109template<
typename ValueType>
114template<
typename ValueType>
120template<
typename ValueType>
122 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
127 modelParameters.insert(rewParameters.begin(), rewParameters.end());
129 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
131 return std::vector<storm::storage::ParameterRegion<ValueType>>({
createRegion<ValueType>(inputString, modelParameters)});
134template<
typename ValueType>
138 if (inputString ==
"" && consideredVariables.empty()) {
143 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
147template<
typename ValueType>
155 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
159template<
typename ValueType>
160std::pair<std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>,
161 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>>
163 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
166 modelParameters.insert(rewParameters.begin(), rewParameters.end());
168 fileName, modelParameters));
171template<
typename ParametricType>
175 bool preconditionsValidatedManually =
false) {
177 "Could not validate whether parameter lifting is applicable. Please validate manually...");
178 std::shared_ptr<storm::models::sparse::Model<ParametricType>> consideredModel = model;
182 STORM_LOG_WARN(
"Parameter lifting not supported for continuous time models. Transforming continuous model to discrete model...");
183 std::vector<std::shared_ptr<storm::logic::Formula const>> taskFormulaAsVector{task.
getFormula().asSharedPointer()};
186 storm::exceptions::UnexpectedException,
"Transformation to discrete time model has failed.");
188 return consideredModel;
191template<
typename ParametricType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
195extern template std::unique_ptr<storm::modelchecker::RegionModelChecker<storm::RationalFunction>>
199template<
typename ParametricType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
205 monotoneParameters = std::nullopt) {
207 auto monotonicityBackend = std::make_unique<storm::modelchecker::MonotonicityBackend<ParametricType>>();
211 std::unique_ptr<storm::modelchecker::MonotonicityBackend<ParametricType>> orderBasedBackend;
213 orderBasedBackend = std::make_unique<storm::modelchecker::OrderBasedMonotonicityBackend<ParametricType, PreciseType>>(
216 orderBasedBackend = std::make_unique<storm::modelchecker::OrderBasedMonotonicityBackend<ParametricType, ImpreciseType>>(
220 monotonicityBackend = std::move(orderBasedBackend);
222 STORM_LOG_WARN(
"Order-based Monotonicity enabled for region checking engine " << engine <<
" but not supported in this configuration.");
227 if (monotoneParameters) {
228 for (
auto const& incrPar : monotoneParameters->first) {
231 for (
auto const& decrPar : monotoneParameters->second) {
235 return monotonicityBackend;
238template<
typename ValueType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
242 bool allowModelSimplification =
true,
247 monotoneParameters = std::nullopt) {
250 auto monotonicityBackend =
252 if (allowModelSimplification) {
253 allowModelSimplification = monotonicityBackend->recommendModelSimplifications();
254 STORM_LOG_WARN_COND(allowModelSimplification,
"Model simplification is disabled because the monotonicity algorithm does not recommend it.");
256 regionChecker->specify(env, consideredModel, task, std::nullopt, std::move(monotonicityBackend), allowModelSimplification, graphPreservationStatus);
257 return regionChecker;
260template<
typename ValueType>
268template<
typename ValueType>
274 return regionChecker->analyzeRegions(env, regions, hypotheses, sampleVerticesOfRegions);
277template<
typename ValueType>
283 bool sampleVerticesOfRegions =
false) {
284 std::vector<storm::modelchecker::RegionResultHypothesis> hypotheses(regions.size(), hypothesis);
288template<
typename ValueType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
295 settings.allowModelSimplification =
settings.allowModelSimplification && monotonicityBackend->recommendModelSimplifications();
296 auto refinementChecker = std::make_unique<storm::modelchecker::RegionRefinementChecker<ValueType>>(std::move(regionChecker));
297 refinementChecker->specify(env, consideredModel,
settings.task, std::move(
settings.regionSplittingStrategy), std::move(
settings.discreteVariables),
298 std::move(monotonicityBackend),
settings.allowModelSimplification,
settings.graphPreservationStatus);
299 return refinementChecker;
313template<
typename ValueType>
316 std::optional<ValueType>
const& coverageThreshold, std::optional<uint64_t>
const& refinementDepthThreshold = std::nullopt,
319 return regionRefinementChecker->performRegionPartitioning(env, region, coverageThreshold, refinementDepthThreshold, hypothesis, monThresh);
333template<
typename ValueType>
337 std::optional<ValueType>
const& precision,
bool absolutePrecision,
338 std::optional<storm::logic::Bound>
const& boundInvariant) {
351template<
typename ValueType>
354 storm::exceptions::NotSupportedException,
"Only probability and reward operators supported.");
355 STORM_LOG_THROW(
settings.task.getFormula().asOperatorFormula().hasBound(), storm::exceptions::NotSupportedException,
356 "Verification requires a bounded operator formula.");
360 return refinementChecker->verifyRegion(env, region, bound);
363template<
typename ValueType>
365 bool onlyConclusiveResults =
false) {
367 STORM_LOG_THROW(regionCheckResult !=
nullptr, storm::exceptions::UnexpectedException,
368 "Can not export region check result: The given checkresult does not have the expected type.");
370 std::ofstream filestream;
372 for (
auto const& res : regionCheckResult->getRegionResults()) {
375 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::unique_ptr< storm::modelchecker::RegionRefinementCheckResult< ValueType > > checkAndRefineRegionWithSparseEngine(Environment const &env, 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::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::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.
bool verifyRegion(Environment const &env, RefinementOptions< ValueType > settings, storm::storage::ParameterRegion< ValueType > const ®ion)
Verifies whether a region satisfies a property.
std::unique_ptr< storm::modelchecker::RegionModelChecker< ParametricType > > createRegionModelChecker(storm::modelchecker::RegionCheckEngine engine, storm::models::ModelType modelType)
std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > getModelParameters(storm::models::ModelBase const &model)
storm::pars::FeasibilityResult< storm::RationalNumber > computeExtremalValue(Environment const &env, 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)
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)
std::unique_ptr< storm::modelchecker::RegionCheckResult< ValueType > > checkRegionsWithSparseEngine(Environment const &env, 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::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, storm::pars::analysis::GraphPreservationStatus graphPreservationStatus=storm::pars::analysis::GraphPreservationStatus::GraphPreserving, 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)
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.
GraphPreservationStatus
Describes to what extent a set of regions is known to be well-defined and to preserve the graph struc...
@ GraphPreserving
The regions are known (or assumed) to preserve the graph structure of the model.
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)
The contract of a DD backend.
The result of a feasibility synthesis: a parameter valuation and the value at the initial state under...
bool useOnlyGlobalMonotonicity