26template<
typename ParametricType>
28 STORM_LOG_ASSERT(regionChecker !=
nullptr,
"The region model checker must not be null.");
29 this->regionChecker = std::move(regionChecker);
32template<
typename ParametricType>
35 return regionChecker->canHandle(parametricModel, checkTask);
38template<
typename ParametricType>
44 this->monotonicityBackend = monotonicityBackend ? monotonicityBackend : std::make_shared<MonotonicityBackend<ParametricType>>();
45 this->regionSplittingStrategy = std::move(splittingStrategy);
46 this->discreteVariables = std::move(discreteVariables);
47 this->graphPreservationStatus = graphPreservationStatus;
53 if (regionSplittingStrategy.estimateKind.has_value()) {
54 STORM_LOG_THROW(regionChecker->isRegionSplitEstimateKindSupported(regionSplittingStrategy.estimateKind.value(), checkTask),
55 storm::exceptions::NotSupportedException,
"The specified region split estimate kind is not supported by the region model checker.");
57 regionSplittingStrategy.estimateKind = regionChecker->getDefaultRegionSplitEstimateKind(checkTask);
58 STORM_LOG_ASSERT(regionChecker->isRegionSplitEstimateKindSupported(regionSplittingStrategy.estimateKind.value(), checkTask),
59 "The region model checker does not support its default region split estimate kind.");
62 regionSplittingStrategy.estimateKind = std::nullopt;
65 regionChecker->specify(env, parametricModel, checkTask, regionSplittingStrategy.estimateKind, monotonicityBackend, allowModelSimplifications,
66 graphPreservationStatus);
73 : totalArea(totalArea),
74 coverageThreshold(coverageThreshold),
78 progress(
"% covered area", delay) {
79 progress.setMaxCount(100 - asPercentage(coverageThreshold));
80 progress.startNewMeasurement(0u);
84 return asPercentage(fractionOfUndiscoveredArea);
88 return fractionOfUndiscoveredArea <= coverageThreshold;
92 auto addedFraction = area / totalArea;
93 fractionOfUndiscoveredArea -= addedFraction;
111 static uint64_t asPercentage(T
const& value) {
116 T
const coverageThreshold;
117 T fractionOfUndiscoveredArea;
118 T fractionOfAllSatArea;
119 T fractionOfAllViolatedArea;
120 T fractionOfAllIllDefinedArea;
124template<
typename ParametricType>
139 std::queue<std::reference_wrapper<AnnotatedRegion<ParametricType>>> unprocessedRegions;
140 unprocessedRegions.emplace(rootRegion);
142 uint64_t numOfAnalyzedRegions{0u};
143 bool monotonicityInitialized{
false};
146 while (!progress.isCoverageThresholdReached() && !unprocessedRegions.empty()) {
147 auto& currentRegion = unprocessedRegions.front().get();
148 STORM_LOG_TRACE(
"Analyzing region #" << numOfAnalyzedRegions <<
" (Refinement depth " << currentRegion.refinementDepth <<
"; "
149 << progress.getUndiscoveredPercentage() <<
"% still unknown; " << unprocessedRegions.size()
150 <<
" regions unprocessed).");
151 unprocessedRegions.pop();
152 ++numOfAnalyzedRegions;
154 if (!monotonicityInitialized && currentRegion.refinementDepth >= monThresh) {
155 monotonicityInitialized =
true;
156 monotonicityBackend->initializeMonotonicity(env, rootRegion);
158 if (currentRegion.refinementDepth > 0) {
162 if (monotonicityInitialized) {
163 monotonicityBackend->updateMonotonicity(env, currentRegion);
166 currentRegion.result = regionChecker->analyzeRegion(env, currentRegion, hypothesis);
169 progress.addAllSatArea(currentRegion.region.area());
171 progress.addAllViolatedArea(currentRegion.region.area());
175 "The region is not graph-preserving, but the selected region verification engine requires this assumption. Please use "
176 "--assume-graph-preserving false.");
177 progress.addAllIllDefinedArea(currentRegion.region.area());
180 if (!depthThreshold || currentRegion.refinementDepth < depthThreshold.value()) {
181 monotonicityBackend->updateMonotonicityBeforeSplitting(env, currentRegion);
182 auto splittingVariables = getSplittingVariables(currentRegion, Context::Partitioning);
184 currentRegion.splitLeafNodeAtCenter(splittingVariables, this->discreteVariables,
true);
185 for (
auto& child : currentRegion.subRegions) {
186 unprocessedRegions.emplace(child);
193 uint64_t numberOfRegionsKnownThroughMonotonicity{0};
194 std::vector<std::pair<storm::storage::ParameterRegion<ParametricType>,
RegionResult>> result;
196 if (node.subRegions.empty()) {
197 if (node.resultKnownThroughMonotonicity) {
198 ++numberOfRegionsKnownThroughMonotonicity;
200 result.emplace_back(node.region, node.result);
204 STORM_LOG_INFO(
"Region partitioning terminated after analyzing " << numOfAnalyzedRegions <<
" regions.\n\t" << numberOfRegionsKnownThroughMonotonicity
205 <<
" regions known through monotonicity.\n\tMaximum refinement depth: " << maxDepth
206 <<
".\n\t" << progress.getUndiscoveredPercentage()
207 <<
"% of the parameter space are not covered.");
209 auto regionCopyForResult =
region;
210 return std::make_unique<storm::modelchecker::RegionRefinementCheckResult<ParametricType>>(std::move(result), std::move(regionCopyForResult));
213template<
typename ParametricType>
227 rhs) {
return lhs.
knownLowerValueBound.getExtendedValue() > rhs.knownLowerValueBound.getExtendedValue(); }
229 return lhs.
knownUpperValueBound.getExtendedValue() < rhs.knownUpperValueBound.getExtendedValue();
231 std::priority_queue<std::reference_wrapper<AnnotatedRegion<ParametricType>>, std::vector<std::reference_wrapper<AnnotatedRegion<ParametricType>>>,
233 unprocessedRegions(cmp);
234 unprocessedRegions.push(rootRegion);
237 monotonicityBackend->initializeMonotonicity(env, rootRegion);
240 auto valueValuation = regionChecker->getAndEvaluateGoodPoint(env, rootRegion, dir);
241 auto& value = valueValuation.first;
242 if (rejectInstance(value)) {
243 return valueValuation;
246 if (std::all_of(
region.getVariables().begin(),
region.getVariables().end(),
247 [&](
auto const& variable) { return storm::utility::isZero(region.getDifference(variable)); })) {
248 return valueValuation;
252 auto isBetterThanValue = [&value, &dir](
auto const& newValue) {
return storm::solver::minimize(dir) ? newValue < value : newValue > value; };
256 uint64_t numOfAnalyzedRegions{0u};
257 while (!unprocessedRegions.empty()) {
258 auto& currentRegion = unprocessedRegions.top().get();
260 storm::solver::minimize(dir) ? currentRegion.knownLowerValueBound.getExtendedValue() : currentRegion.knownUpperValueBound.getExtendedValue();
261 STORM_LOG_TRACE(
"Analyzing region #" << numOfAnalyzedRegions <<
" (Refinement depth " << currentRegion.refinementDepth <<
"; "
262 << progress.getUndiscoveredPercentage() <<
"% still unknown; " << unprocessedRegions.size()
263 <<
" regions unprocessed). Best known value: " << value <<
".");
264 unprocessedRegions.pop();
265 ++numOfAnalyzedRegions;
267 monotonicityBackend->updateMonotonicity(env, currentRegion);
270 if (!acceptGlobalBound(value, currentBound)) {
272 currentBound = regionChecker->getBoundAtInitState(env, currentRegion, dir);
274 currentRegion.knownLowerValueBound &= currentBound;
276 currentRegion.knownUpperValueBound &= currentBound;
281 if (!acceptGlobalBound(value, currentBound)) {
284 auto [currValue, currValuation] = regionChecker->getAndEvaluateGoodPoint(env, currentRegion, dir);
285 if (isBetterThanValue(currValue)) {
286 valueValuation = {currValue, currValuation};
287 if (rejectInstance(currValue)) {
288 STORM_LOG_INFO(
"Found rejecting instance " << currValuation <<
" with value " << currValue);
289 return valueValuation;
295 if (!acceptGlobalBound(value, currentBound)) {
296 monotonicityBackend->updateMonotonicityBeforeSplitting(env, currentRegion);
297 auto splittingVariables = getSplittingVariables(currentRegion, Context::ExtremalValue);
298 for (
auto it = splittingVariables.begin(); it != splittingVariables.end();) {
300 it = splittingVariables.erase(it);
306 !splittingVariables.empty(), storm::exceptions::NotSupportedException,
307 "getSplittingVariables returned no parameter with non-zero width for region " << currentRegion.region <<
"; refinement cannot proceed.");
309 currentRegion.splitLeafNodeAtCenter(splittingVariables, this->discreteVariables,
true);
310 for (
auto& child : currentRegion.subRegions) {
311 unprocessedRegions.emplace(child);
314 progress.addDiscoveredArea(currentRegion.region.area());
318 STORM_LOG_INFO(
"Region partitioning for extremal value terminated after analyzing "
319 << numOfAnalyzedRegions <<
" regions.\n\t" << progress.getUndiscoveredPercentage() <<
"% of the parameter space are not covered.");
320 return valueValuation;
323template<
typename ParametricType>
327 bool absolutePrecision, std::optional<storm::logic::Bound>
const& boundInvariant) {
330 "Precision must be a constant value. Got " << precision <<
" instead.");
335 return newValue == value;
341 auto rejectInstance = [&](
ExtendedCoefficientType const& currentValue) {
return boundInvariant && !boundInvariant->isSatisfied(currentValue); };
346template<
typename ParametricType>
352 isLowerBound(bound.
comparisonType) ? storm::solver::OptimizationDirection::Minimize : storm::solver::OptimizationDirection::Maximize;
363template<
typename ParametricType>
364std::set<typename RegionRefinementChecker<ParametricType>::VariableType> RegionRefinementChecker<ParametricType>::getSplittingVariablesEstimateBased(
367 if (this->regionSplittingStrategy.maxSplitDimensions >=
region.region.getVariables().size()) {
368 return region.region.getVariables();
371 auto const& estimates = regionChecker->obtainRegionSplitEstimates(region.
region.
getVariables());
372 std::vector<std::pair<VariableType, CoefficientType>> estimatesToSort;
375 auto estimatesIter = estimates.begin();
377 estimatesToSort.push_back(std::make_pair(param, *estimatesIter++));
381 std::sort(estimatesToSort.begin(), estimatesToSort.end(), [](
const auto& a,
const auto& b) { return a.second > b.second; });
383 std::set<VariableType> splittingVars;
384 for (
auto const& estimate : estimatesToSort) {
394 splittingVars.emplace(estimate.first);
395 if (splittingVars.size() == regionSplittingStrategy.maxSplitDimensions) {
399 return splittingVars;
402template<
typename ParametricType>
403std::set<typename RegionRefinementChecker<ParametricType>::VariableType> RegionRefinementChecker<ParametricType>::getSplittingVariablesRoundRobin(
406 auto const& vars =
region.region.getVariables();
407 auto varsIter = vars.begin();
409 std::advance(varsIter, (
region.refinementDepth * this->regionSplittingStrategy.maxSplitDimensions) % vars.size());
411 auto loopPoint = varsIter;
413 std::set<VariableType> splittingVars;
416 if (context == Context::ExtremalValue &&
region.monotonicityAnnotation.getGlobalMonotonicityResult() &&
417 region.monotonicityAnnotation.getGlobalMonotonicityResult()->isMonotone(*varsIter)) {
420 splittingVars.emplace(*varsIter);
421 std::advance(varsIter, 1);
422 if (varsIter == vars.end()) {
423 varsIter = vars.begin();
425 }
while (loopPoint != varsIter && splittingVars.size() < this->regionSplittingStrategy.maxSplitDimensions);
427 return splittingVars;
430template<
typename ParametricType>
431std::set<typename RegionRefinementChecker<ParametricType>::VariableType> RegionRefinementChecker<ParametricType>::getSplittingVariables(
433 switch (regionSplittingStrategy.heuristic) {
435 return getSplittingVariablesEstimateBased(
region, context);
437 return getSplittingVariablesRoundRobin(
region, context);
SolverEnvironment & solver()
uint64_t getShowProgressDelay() const
void addAllIllDefinedArea(T const &area)
void addAllViolatedArea(T const &area)
bool isCoverageThresholdReached() const
T addDiscoveredArea(T const &area)
void addAllSatArea(T const &area)
uint64_t getUndiscoveredPercentage() const
PartitioningProgress(T const totalArea, uint64_t delay, T const coverageThreshold=storm::utility::zero< T >())
bool canHandle(std::shared_ptr< storm::models::ModelBase > parametricModel, CheckTask< storm::logic::Formula, ParametricType > const &checkTask) const
typename storm::storage::ParameterRegion< ParametricType >::CoefficientType CoefficientType
bool verifyRegion(Environment const &env, storm::storage::ParameterRegion< ParametricType > const ®ion, storm::logic::Bound const &bound)
Checks whether the bound is satisfied on the complete region.
storm::utility::ExtendedValueType< CoefficientType > ExtendedCoefficientType
RegionRefinementChecker(std::unique_ptr< RegionModelChecker< ParametricType > > &®ionChecker)
std::unique_ptr< storm::modelchecker::RegionRefinementCheckResult< ParametricType > > performRegionPartitioning(Environment const &env, storm::storage::ParameterRegion< ParametricType > const ®ion, std::optional< ParametricType > coverageThreshold, std::optional< uint64_t > depthThreshold=std::nullopt, RegionResultHypothesis const &hypothesis=RegionResultHypothesis::Unknown, uint64_t monThresh=0)
Iteratively refines the region until the region analysis yields a conclusive result (AllSat or AllVio...
std::pair< ExtendedCoefficientType, Valuation > computeExtremalValue(Environment const &env, storm::storage::ParameterRegion< ParametricType > const ®ion, storm::solver::OptimizationDirection const &dir, ParametricType const &precision, bool absolutePrecision, std::optional< storm::logic::Bound > const &boundInvariant)
Finds the extremal value within the given region and with the given precision.
void specify(Environment const &env, std::shared_ptr< storm::models::ModelBase > parametricModel, CheckTask< storm::logic::Formula, ParametricType > const &checkTask, RegionSplittingStrategy splittingStrategy=RegionSplittingStrategy(), std::set< VariableType > const &discreteVariables={}, std::shared_ptr< MonotonicityBackend< ParametricType > > monotonicityBackend={}, bool allowModelSimplifications=true, storm::pars::analysis::GraphPreservationStatus graphPreservationStatus=storm::pars::analysis::GraphPreservationStatus::GraphPreserving)
std::pair< ExtendedCoefficientType, Valuation > computeExtremalValueHelper(Environment const &env, storm::storage::ParameterRegion< ParametricType > const ®ion, storm::solver::OptimizationDirection const &dir, std::function< bool(ExtendedCoefficientType const &, ExtendedCoefficientType const &)> acceptGlobalBound, std::function< bool(ExtendedCoefficientType const &)> rejectInstance)
Finds the extremal value within the given region and with the given precision.
std::set< VariableType > const & getVariables() const
storm::utility::parametric::Valuation< ParametricType > Valuation
A class that provides convenience operations to display run times.
#define STORM_LOG_INFO(message)
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ERROR(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
RegionResult
The results for a single Parameter Region.
@ 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
GraphPreservationStatus
Describes to what extent a set of regions is known to be well-defined and to preserve the graph struc...
bool isGraphPreserving(GraphPreservationStatus status)
Returns whether the given status guarantees that the graph structure of the model is preserved.
bool constexpr minimize(OptimizationDirection d)
bool isFinite(ExtendedNumber< ValueType > const &value)
bool isConstant(ValueType const &)
bool isZero(ValueType const &a)
ValueType round(ValueType const &number)
TargetType convertNumber(SourceType const &number)
The contract of a DD backend.
ComparisonType comparisonType
bool isSatisfied(ValueType const &compareValue) const
void propagateAnnotationsToSubregions(bool allowDeleteAnnotationsOfThis)
storm::modelchecker::MonotonicityAnnotation< ParametricType > monotonicityAnnotation
Whether the result is known through monotonicity.
void postOrderTraverseSubRegions(std::function< void(AnnotatedRegion< ParametricType > &)> const &visitor)
storm::utility::Maximum< CoefficientType > knownLowerValueBound
storm::utility::Minimum< CoefficientType > knownUpperValueBound
uint64_t getMaxDepthOfSubRegions() const
Region const region
The subregions of this region.