Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparsePcaaAchievabilityQuery.cpp
Go to the documentation of this file.
2
12
13namespace storm {
14namespace modelchecker {
15namespace multiobjective {
16
17template<class SparseModelType, typename GeometryValueType>
20 : SparsePcaaQuery<SparseModelType, GeometryValueType>(preprocessorResult) {
22 "Invalid query Type");
23 initializeThresholdData();
24
25 // Set the precision of the weight vector checker. Will be refined during the computation
26 this->weightVectorChecker->setWeightedPrecision(storm::utility::convertNumber<typename SparseModelType::ValueType>(0.1));
27}
28
29template<class SparseModelType, typename GeometryValueType>
31 thresholds.reserve(this->objectives.size());
32 strictThresholds = storm::storage::BitVector(this->objectives.size(), false);
33 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
34 auto const& formula = *this->objectives[objIndex].formula;
35 STORM_LOG_ASSERT(formula.hasBound(), "Achievability query invoked but there is an objective without bound.");
36 thresholds.push_back(formula.template getThresholdAs<GeometryValueType>());
37 if (storm::solver::minimize(formula.getOptimalityType())) {
38 STORM_LOG_ASSERT(!storm::logic::isLowerBound(formula.getBound().comparisonType), "Minimizing objective should not specify an upper bound.");
39 // Values for minimizing objectives will be negated in order to convert them to maximizing objectives.
40 // Hence, we also negate the threshold
41 thresholds.back() *= -storm::utility::one<GeometryValueType>();
42 }
43 strictThresholds.set(objIndex, storm::logic::isStrict(formula.getBound().comparisonType));
44 }
45}
46
47template<class SparseModelType, typename GeometryValueType>
48std::unique_ptr<CheckResult> SparsePcaaAchievabilityQuery<SparseModelType, GeometryValueType>::check(Environment const& env, bool produceScheduler) {
49 STORM_LOG_THROW(!produceScheduler, storm::exceptions::NotImplementedException, "Scheduler computation is not implement for achievability queries.");
50
51 bool result = this->checkAchievability(env);
52
53 return std::unique_ptr<CheckResult>(new ExplicitQualitativeCheckResult(this->originalModel.getInitialStates().getNextSetIndex(0), result));
54}
55
56template<class SparseModelType, typename GeometryValueType>
58 // repeatedly refine the over/ under approximation until the threshold point is either in the under approx. or not in the over approx.
59 while (!this->maxStepsPerformed(env) && !storm::utility::resources::isTerminate()) {
60 WeightVector separatingVector = this->findSeparatingVector(thresholds);
61 this->updateWeightedPrecision(separatingVector);
62 this->performRefinementStep(env, std::move(separatingVector), false); // scheduler computation currently not supported
63 if (!checkIfThresholdsAreSatisfied(this->overApproximation)) {
64 return false;
65 }
66 if (checkIfThresholdsAreSatisfied(this->underApproximation)) {
67 return true;
68 }
69 }
70 STORM_LOG_ERROR("Could not check whether thresholds are achievable: Termination requested or maximum number of refinement steps exceeded.");
71 return false;
72}
73
74template<class SparseModelType, typename GeometryValueType>
75void SparsePcaaAchievabilityQuery<SparseModelType, GeometryValueType>::updateWeightedPrecision(WeightVector const& weights) {
76 // Our heuristic considers the distance between the under- and the over approximation w.r.t. the given direction
77 std::pair<Point, bool> optimizationResOverApprox = this->overApproximation->optimize(weights);
78 if (optimizationResOverApprox.second) {
79 std::pair<Point, bool> optimizationResUnderApprox = this->underApproximation->optimize(weights);
80 if (optimizationResUnderApprox.second) {
81 GeometryValueType distance = storm::utility::vector::dotProduct(optimizationResOverApprox.first, weights) -
82 storm::utility::vector::dotProduct(optimizationResUnderApprox.first, weights);
83 STORM_LOG_ASSERT(distance >= storm::utility::zero<GeometryValueType>(), "Negative distance between under- and over approximation was not expected");
84 // Normalize the distance by dividing it with the Euclidean Norm of the weight-vector
85 distance /= storm::utility::sqrt(storm::utility::vector::dotProduct(weights, weights));
86 distance /= GeometryValueType(2);
87 this->weightVectorChecker->setWeightedPrecision(storm::utility::convertNumber<typename SparseModelType::ValueType>(distance));
88 }
89 }
90 // do not update the precision if one of the approximations is unbounded in the provided direction
91}
92
93template<class SparseModelType, typename GeometryValueType>
94bool SparsePcaaAchievabilityQuery<SparseModelType, GeometryValueType>::checkIfThresholdsAreSatisfied(
95 std::shared_ptr<storm::storage::geometry::Polytope<GeometryValueType>> const& polytope) {
96 std::vector<storm::storage::geometry::Halfspace<GeometryValueType>> halfspaces = polytope->getHalfspaces();
97 for (auto const& h : halfspaces) {
98 if (storm::utility::isZero(h.distance(thresholds))) {
99 // Check if the threshold point is on the boundary of the halfspace and whether this is violates strict thresholds
100 if (h.isPointOnBoundary(thresholds)) {
101 for (auto strictThreshold : strictThresholds) {
102 if (h.normalVector()[strictThreshold] > storm::utility::zero<GeometryValueType>()) {
103 return false;
104 }
105 }
106 }
107 } else {
108 return false;
109 }
110 }
111 return true;
112}
113
114template class SparsePcaaAchievabilityQuery<storm::models::sparse::Mdp<double>, storm::RationalNumber>;
115template class SparsePcaaAchievabilityQuery<storm::models::sparse::MarkovAutomaton<double>, storm::RationalNumber>;
116
117template class SparsePcaaAchievabilityQuery<storm::models::sparse::Mdp<storm::RationalNumber>, storm::RationalNumber>;
118template class SparsePcaaAchievabilityQuery<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>, storm::RationalNumber>;
119} // namespace multiobjective
120} // namespace modelchecker
121} // namespace storm
SparsePcaaAchievabilityQuery(preprocessing::SparseMultiObjectivePreprocessorResult< SparseModelType > &preprocessorResult)
virtual std::unique_ptr< CheckResult > check(Environment const &env, bool produceScheduler) override
std::unique_ptr< PcaaWeightVectorChecker< SparseModelType > > weightVectorChecker
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
#define STORM_LOG_ERROR(message)
Definition logging.h:26
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
bool isLowerBound(ComparisonType t)
bool isStrict(ComparisonType t)
bool constexpr minimize(OptimizationDirection d)
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
T dotProduct(std::vector< T > const &firstOperand, std::vector< T > const &secondOperand)
Computes the dot product (aka scalar product) and returns the result.
Definition vector.h:473
bool isZero(ValueType const &a)
Definition constants.cpp:39
ValueType sqrt(ValueType const &number)