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