9#include <boost/algorithm/string.hpp>
46template<
typename ValueType>
49template<
typename ValueType>
51 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
56 modelParameters.insert(rewParameters.begin(), rewParameters.end());
58 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
60 return modelParameters;
63template<
typename ValueType>
64std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType>
parseVariableList(
66 if (inputString ==
"") {
69 std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType> variables;
70 std::vector<std::string> variableStrings;
71 boost::split(variableStrings, inputString, boost::is_any_of(
","));
72 for (
auto& var : variableStrings) {
76 for (
auto const& param : consideredVariables) {
77 if (var == param.name()) {
78 variables.push_back(param);
90template<
typename ValueType>
91std::vector<typename storm::storage::ParameterRegion<ValueType>::VariableType>
parseVariableList(std::string
const& inputString,
96template<
typename ValueType>
97std::vector<storm::storage::ParameterRegion<ValueType>>
parseRegions(
108template<
typename ValueType>
113template<
typename ValueType>
119template<
typename ValueType>
121 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
126 modelParameters.insert(rewParameters.begin(), rewParameters.end());
128 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
130 return std::vector<storm::storage::ParameterRegion<ValueType>>({
createRegion<ValueType>(inputString, modelParameters)});
133template<
typename ValueType>
137 if (inputString ==
"" && consideredVariables.empty()) {
142 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
146template<
typename ValueType>
154 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
158template<
typename ValueType>
159std::pair<std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>,
160 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>>
162 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
165 modelParameters.insert(rewParameters.begin(), rewParameters.end());
167 fileName, modelParameters));
170template<
typename ParametricType>
174 bool preconditionsValidatedManually =
false) {
176 "Could not validate whether parameter lifting is applicable. Please validate manually...");
177 std::shared_ptr<storm::models::sparse::Model<ParametricType>> consideredModel = model;
181 STORM_LOG_WARN(
"Parameter lifting not supported for continuous time models. Transforming continuous model to discrete model...");
182 std::vector<std::shared_ptr<storm::logic::Formula const>> taskFormulaAsVector{task.
getFormula().asSharedPointer()};
185 storm::exceptions::UnexpectedException,
"Transformation to discrete time model has failed.");
187 return consideredModel;
190template<
typename ParametricType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
194extern template std::unique_ptr<storm::modelchecker::RegionModelChecker<storm::RationalFunction>>
198template<
typename ParametricType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
204 monotoneParameters = std::nullopt) {
206 auto monotonicityBackend = std::make_unique<storm::modelchecker::MonotonicityBackend<ParametricType>>();
210 std::unique_ptr<storm::modelchecker::MonotonicityBackend<ParametricType>> orderBasedBackend;
212 orderBasedBackend = std::make_unique<storm::modelchecker::OrderBasedMonotonicityBackend<ParametricType, PreciseType>>(
215 orderBasedBackend = std::make_unique<storm::modelchecker::OrderBasedMonotonicityBackend<ParametricType, ImpreciseType>>(
219 monotonicityBackend = std::move(orderBasedBackend);
221 STORM_LOG_WARN(
"Order-based Monotonicity enabled for region checking engine " << engine <<
" but not supported in this configuration.");
226 if (monotoneParameters) {
227 for (
auto const& incrPar : monotoneParameters->first) {
230 for (
auto const& decrPar : monotoneParameters->second) {
234 return monotonicityBackend;
237template<
typename ValueType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
241 bool allowModelSimplification =
true,
246 monotoneParameters = std::nullopt) {
249 auto monotonicityBackend =
251 if (allowModelSimplification) {
252 allowModelSimplification = monotonicityBackend->recommendModelSimplifications();
253 STORM_LOG_WARN_COND(allowModelSimplification,
"Model simplification is disabled because the monotonicity algorithm does not recommend it.");
255 regionChecker->specify(env, consideredModel, task, std::nullopt, std::move(monotonicityBackend), allowModelSimplification, graphPreservationStatus);
256 return regionChecker;
259template<
typename ValueType>
267template<
typename ValueType>
273 return regionChecker->analyzeRegions(env, regions, hypotheses, sampleVerticesOfRegions);
276template<
typename ValueType>
282 bool sampleVerticesOfRegions =
false) {
283 std::vector<storm::modelchecker::RegionResultHypothesis> hypotheses(regions.size(), hypothesis);
287template<
typename ValueType,
typename ImpreciseType =
double,
typename PreciseType = storm::RationalNumber>
294 settings.allowModelSimplification =
settings.allowModelSimplification && monotonicityBackend->recommendModelSimplifications();
295 auto refinementChecker = std::make_unique<storm::modelchecker::RegionRefinementChecker<ValueType>>(std::move(regionChecker));
296 refinementChecker->specify(env, consideredModel,
settings.task, std::move(
settings.regionSplittingStrategy), std::move(
settings.discreteVariables),
297 std::move(monotonicityBackend),
settings.allowModelSimplification,
settings.graphPreservationStatus);
298 return refinementChecker;
312template<
typename ValueType>
315 std::optional<ValueType>
const& coverageThreshold, std::optional<uint64_t>
const& refinementDepthThreshold = std::nullopt,
318 return regionRefinementChecker->performRegionPartitioning(env, region, coverageThreshold, refinementDepthThreshold, hypothesis, monThresh);
332template<
typename ValueType>
333std::pair<storm::ExtendedRationalNumber, typename storm::storage::ParameterRegion<ValueType>::Valuation>
computeExtremalValue(
336 std::optional<storm::logic::Bound>
const& boundInvariant) {
349template<
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::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< storm::ExtendedRationalNumber, typename storm::storage::ParameterRegion< ValueType >::Valuation > 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.
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::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)
bool useOnlyGlobalMonotonicity