3#include <boost/optional.hpp>
47template<
typename ValueType>
48std::vector<storm::storage::ParameterRegion<ValueType>>
parseRegions(
59template<
typename ValueType>
65template<
typename ValueType>
67 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
72 modelParameters.insert(rewParameters.begin(), rewParameters.end());
74 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
76 return parseRegions<ValueType>(inputString, modelParameters);
79template<
typename ValueType>
81 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
86 modelParameters.insert(rewParameters.begin(), rewParameters.end());
88 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Retrieving model parameters is not supported for the given model type.");
90 return std::vector<storm::storage::ParameterRegion<ValueType>>({createRegion<ValueType>(inputString, modelParameters)});
93template<
typename ValueType>
97 if (inputString ==
"" && consideredVariables.empty()) {
101 auto res = parseRegions<ValueType>(inputString, consideredVariables);
102 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
106template<
typename ValueType>
113 auto res = parseRegions<ValueType>(inputString, model);
114 STORM_LOG_THROW(res.size() == 1, storm::exceptions::InvalidOperationException,
"Parsed " << res.size() <<
" regions but exactly one was expected.");
118template<
typename ValueType>
119std::pair<std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>,
120 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType>>
122 std::set<typename storm::storage::ParameterRegion<ValueType>::VariableType> modelParameters;
125 modelParameters.insert(rewParameters.begin(), rewParameters.end());
127 fileName, modelParameters));
130template<
typename ParametricType,
typename ConstantType>
137 monotoneParameters = boost::none) {
139 "Could not validate whether parameter lifting is applicable. Please validate manually...");
141 !(allowModelSimplification && monotonicitySetting.useMonotonicity),
142 "Allowing model simplification when using monotonicity is not useful, as for monotonicity checking model simplification is done as preprocessing");
144 "Setting monotone parameters without setting monotonicity usage doesn't work");
146 std::shared_ptr<storm::models::sparse::Model<ParametricType>> consideredModel = model;
151 "Usage of monotonicity not supported for this type of model, continuing without montonicity checking");
152 STORM_LOG_WARN(
"Parameter lifting not supported for continuous time models. Transforming continuous model to discrete model...");
153 std::vector<std::shared_ptr<storm::logic::Formula const>> taskFormulaAsVector{task.
getFormula().asSharedPointer()};
156 storm::exceptions::UnexpectedException,
"Transformation to discrete time model has failed.");
160 std::shared_ptr<storm::modelchecker::RegionModelChecker<ParametricType>> checker;
162 checker = std::make_shared<storm::modelchecker::SparseDtmcParameterLiftingModelChecker<storm::models::sparse::Dtmc<ParametricType>, ConstantType>>();
163 checker->setUseMonotonicity(monotonicitySetting.useMonotonicity);
164 checker->setUseOnlyGlobal(monotonicitySetting.useOnlyGlobalMonotonicity);
165 checker->setUseBounds(monotonicitySetting.useBoundsFromPLA);
166 if (monotonicitySetting.useMonotonicity && monotoneParameters) {
167 checker->setMonotoneParameters(monotoneParameters.get());
171 "Usage of monotonicity not supported for this type of model, continuing without montonicity checking");
172 checker = std::make_shared<storm::modelchecker::SparseMdpParameterLiftingModelChecker<storm::models::sparse::Mdp<ParametricType>, ConstantType>>();
174 STORM_LOG_THROW(
false, storm::exceptions::InvalidOperationException,
"Unable to perform parameterLifting on the provided model type.");
177 checker->specify(env, consideredModel, task, generateSplitEstimates, allowModelSimplification);
182template<
typename ParametricType,
typename ImpreciseType,
typename PreciseType>
186 bool allowModelSimplification =
true) {
188 "Could not validate whether parameter lifting is applicable. Please validate manually...");
190 std::shared_ptr<storm::models::sparse::Model<ParametricType>> consideredModel = model;
194 STORM_LOG_WARN(
"Parameter lifting not supported for continuous time models. Transforming continuous model to discrete model...");
195 std::vector<std::shared_ptr<storm::logic::Formula const>> taskFormulaAsVector{task.
getFormula().asSharedPointer()};
198 storm::exceptions::UnexpectedException,
"Transformation to discrete time model has failed.");
202 std::shared_ptr<storm::modelchecker::RegionModelChecker<ParametricType>> checker;
204 checker = std::make_shared<
207 checker = std::make_shared<
210 STORM_LOG_THROW(
false, storm::exceptions::InvalidOperationException,
"Unable to perform parameterLifting on the provided model type.");
213 checker->specify(env, consideredModel, task, generateSplitEstimates, allowModelSimplification);
217template<
typename ValueType>
221 bool generateSplitEstimates =
false,
bool allowModelSimplification =
true,
bool preconditionsValidated =
false,
225 monotoneParameters = boost::none) {
229 return initializeParameterLiftingRegionModelChecker<ValueType, double>(env, model, task, generateSplitEstimates, allowModelSimplification,
230 preconditionsValidated, monotonicitySetting, monotoneParameters);
232 return initializeParameterLiftingRegionModelChecker<ValueType, storm::RationalNumber>(
233 env, model, task, generateSplitEstimates, allowModelSimplification, preconditionsValidated, monotonicitySetting, monotoneParameters);
236 STORM_LOG_WARN_COND(preconditionsValidated,
"Preconditions are checked anyway by a valicating model checker...");
237 return initializeValidatingRegionModelChecker<ValueType, double, storm::RationalNumber>(env, model, task, generateSplitEstimates,
238 allowModelSimplification);
240 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unexpected region model checker type.");
245template<
typename ValueType>
253template<
typename ValueType>
257 std::vector<storm::modelchecker::RegionResultHypothesis>
const& hypotheses,
bool sampleVerticesOfRegions) {
260 return regionChecker->analyzeRegions(env, regions, hypotheses, sampleVerticesOfRegions);
263template<
typename ValueType>
268 bool sampleVerticesOfRegions =
false) {
269 std::vector<storm::modelchecker::RegionResultHypothesis> hypotheses(regions.size(), hypothesis);
284template<
typename ValueType>
288 boost::optional<ValueType>
const& coverageThreshold, boost::optional<uint64_t>
const& refinementDepthThreshold = boost::none,
292 bool preconditionsValidated =
false;
293 auto regionChecker =
initializeRegionModelChecker(env, model, task, engine,
true, allowModelSimplification, preconditionsValidated, monotonicitySetting);
294 return regionChecker->performRegionRefinement(env, region, coverageThreshold, refinementDepthThreshold, hypothesis, monThresh);
301template<
typename ValueType>
302std::pair<storm::RationalNumber, typename storm::storage::ParameterRegion<ValueType>::Valuation>
computeExtremalValue(
305 boost::optional<ValueType>
const& precision,
bool absolutePrecision,
MonotonicitySetting const& monotonicitySetting,
306 std::optional<storm::logic::Bound>
const& boundInvariant,
bool generateSplitEstimates =
false,
307 std::optional<uint64_t> maxSplitsPerStepThreshold = std::numeric_limits<uint64_t>::max()) {
309 bool preconditionsValidated =
false;
312 initializeRegionModelChecker(env, model, task, engine, generateSplitEstimates, allowModelSimplification, preconditionsValidated, monotonicitySetting);
313 if (maxSplitsPerStepThreshold && maxSplitsPerStepThreshold < std::numeric_limits<uint64_t>::max()) {
314 regionChecker->setMaxSplitDimensions(maxSplitsPerStepThreshold.value());
316 auto res = regionChecker->computeExtremalValue(env, region, dir, precision.is_initialized() ? precision.get() : storm::utility::zero<ValueType>(),
317 absolutePrecision, boundInvariant);
319 return {storm::utility::convertNumber<storm::RationalNumber>(res.first.constantPart()), std::move(res.second)};
325template<
typename ValueType>
329 std::optional<uint64_t> maxSplitsPerStepThreshold = std::numeric_limits<uint64_t>::max()) {
332 "Only probability and reward operators supported");
336 std::shared_ptr<storm::logic::Formula> formulaWithoutBounds = formula.
clone();
337 formulaWithoutBounds->asOperatorFormula().removeBound();
338 bool preconditionsValidated =
false;
341 engine, generateSplitEstimates, allowModelSimplification, preconditionsValidated, monotonicitySetting);
342 if (maxSplitsPerStepThreshold && maxSplitsPerStepThreshold < std::numeric_limits<uint64_t>::max()) {
343 regionChecker->setMaxSplitDimensions(maxSplitsPerStepThreshold.value());
345 return regionChecker->verifyRegion(env, region, bound);
348template<
typename ValueType>
350 bool onlyConclusiveResults =
false) {
352 STORM_LOG_THROW(regionCheckResult !=
nullptr, storm::exceptions::UnexpectedException,
353 "Can not export region check result: The given checkresult does not have the expected type.");
355 std::ofstream filestream;
357 for (
auto const& res : regionCheckResult->getRegionResults()) {
359 filestream << res.second <<
": " << res.first <<
'\n';
FormulaType const & getFormula() const
Retrieves the formula from this task.
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_ASSERT(cond, message)
#define STORM_LOG_WARN_COND(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
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(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, storm::storage::ParameterRegion< ValueType > const ®ion, storm::modelchecker::RegionCheckEngine engine, boost::optional< ValueType > const &coverageThreshold, boost::optional< uint64_t > const &refinementDepthThreshold=boost::none, storm::modelchecker::RegionResultHypothesis hypothesis=storm::modelchecker::RegionResultHypothesis::Unknown, bool allowModelSimplification=true, MonotonicitySetting monotonicitySetting=MonotonicitySetting(), uint64_t monThresh=0)
Checks and iteratively refines the given region with the sparse engine.
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::pair< storm::RationalNumber, typename storm::storage::ParameterRegion< ValueType >::Valuation > computeExtremalValue(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, storm::storage::ParameterRegion< ValueType > const ®ion, storm::modelchecker::RegionCheckEngine engine, storm::solver::OptimizationDirection const &dir, boost::optional< ValueType > const &precision, bool absolutePrecision, MonotonicitySetting const &monotonicitySetting, std::optional< storm::logic::Bound > const &boundInvariant, bool generateSplitEstimates=false, std::optional< uint64_t > maxSplitsPerStepThreshold=std::numeric_limits< uint64_t >::max())
Finds the extremal value in the given region.
std::shared_ptr< storm::modelchecker::RegionModelChecker< ParametricType > > initializeValidatingRegionModelChecker(Environment const &env, std::shared_ptr< storm::models::sparse::Model< ParametricType > > const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ParametricType > const &task, bool generateSplitEstimates=false, bool allowModelSimplification=true)
std::shared_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 generateSplitEstimates=false, bool allowModelSimplification=true, bool preconditionsValidated=false, MonotonicitySetting monotonicitySetting=MonotonicitySetting(), boost::optional< std::pair< std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType >, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > > > monotoneParameters=boost::none)
storm::storage::ParameterRegion< ValueType > createRegion(std::string const &inputString, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > const &consideredVariables)
bool verifyRegion(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, storm::logic::Formula const &formula, storm::storage::ParameterRegion< ValueType > const ®ion, storm::modelchecker::RegionCheckEngine engine, MonotonicitySetting const &monotonicitySetting, bool generateSplitEstimates=false, std::optional< uint64_t > maxSplitsPerStepThreshold=std::numeric_limits< uint64_t >::max())
Verifies whether a region satisfies a property.
std::shared_ptr< storm::modelchecker::RegionModelChecker< ParametricType > > initializeParameterLiftingRegionModelChecker(Environment const &env, std::shared_ptr< storm::models::sparse::Model< ParametricType > > const &model, storm::modelchecker::CheckTask< storm::logic::Formula, ParametricType > const &task, bool generateSplitEstimates=false, bool allowModelSimplification=true, bool preconditionsValidatedManually=false, MonotonicitySetting monotonicitySetting=MonotonicitySetting(), boost::optional< std::pair< std::set< typename storm::storage::ParameterRegion< ParametricType >::VariableType >, std::set< typename storm::storage::ParameterRegion< ParametricType >::VariableType > > > monotoneParameters=boost::none)
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 parameters in the given region
@ AllViolated
the formula is violated 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...
@ 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)
Checks whether the parameter lifting approach is sound on the given model with respect to the provide...
bool useOnlyGlobalMonotonicity
MonotonicitySetting(bool useMonotonicity=false, bool useOnlyGlobalMonotonicity=false, bool useBoundsFromPLA=false)