Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
RobustParameterLifter.cpp
Go to the documentation of this file.
2
3#include <carl/core/rootfinder/RootFinder.h>
4#include <algorithm>
5#include <cmath>
6#include <map>
7#include <memory>
8#include <optional>
9#include <set>
10#include <vector>
11
25
26std::unordered_map<storm::RationalFunction, storm::transformer::Annotation> storm::transformer::BigStep::lastSavedAnnotations;
27
28namespace storm {
29namespace transformer {
30
32
33template<typename ParametricType, typename ConstantType>
35 std::vector<ParametricType> const& pVector,
36 storm::storage::BitVector const& selectedRows,
37 storm::storage::BitVector const& selectedColumns, bool generateRowLabels,
38 bool useMonotonicity) {
39 oldToNewColumnIndexMapping = std::vector<uint64_t>(selectedColumns.size(), selectedColumns.size());
40 uint64_t newIndexColumns = 0;
41 for (auto const& oldColumn : selectedColumns) {
42 oldToNewColumnIndexMapping[oldColumn] = newIndexColumns++;
43 }
44
45 oldToNewRowIndexMapping = std::vector<uint64_t>(selectedRows.size(), selectedRows.size());
46 uint64_t newIndexRows = 0;
47 for (auto const& oldRow : selectedRows) {
48 oldToNewRowIndexMapping[oldRow] = newIndexRows++;
49 }
50
51 // Stores which entries of the original matrix/vector are non-constant. Entries for non-selected rows/columns are omitted
52 auto nonConstMatrixEntries = storm::storage::BitVector(pMatrix.getEntryCount(), false); // this vector has to be resized later
53 auto nonConstVectorEntries = storm::storage::BitVector(selectedRows.getNumberOfSetBits(), false);
54 // Counters for selected entries in the pMatrix and the pVector
55 uint64_t pMatrixEntryCount = 0;
56 uint64_t pVectorEntryCount = 0;
57
58 // The matrix builder for the new matrix. The correct number of rows and entries is not known yet.
59 storm::storage::SparseMatrixBuilder<Interval> builder(newIndexRows, newIndexColumns, 0, true, false);
60
61 this->occurringVariablesAtState.resize(pMatrix.getRowCount());
62
63 for (uint64_t row = 0; row < pMatrix.getRowCount(); row++) {
64 if (!selectedRows.get(row)) {
65 continue;
66 }
67 std::set<VariableType> occurringVariables;
68 for (auto const& entry : pMatrix.getRow(row)) {
69 auto column = entry.getColumn();
70 if (!selectedColumns.get(column)) {
71 continue;
72 }
73
74 auto transition = entry.getValue();
75
76 auto variables = transition.gatherVariables();
77 occurringVariables.insert(variables.begin(), variables.end());
78
79 if (storm::utility::isConstant(transition)) {
80 builder.addNextValue(oldToNewColumnIndexMapping[row], oldToNewColumnIndexMapping[column], utility::convertNumber<double>(transition));
81 } else {
82 nonConstMatrixEntries.set(pMatrixEntryCount, true);
83 auto valuation = RobustAbstractValuation(transition);
84 builder.addNextValue(oldToNewColumnIndexMapping[row], oldToNewColumnIndexMapping[column], Interval());
85 Interval& placeholder = functionValuationCollector.add(valuation);
86 matrixAssignment.push_back(std::pair<typename storm::storage::SparseMatrix<Interval>::iterator, Interval&>(
88 }
89 pMatrixEntryCount++;
90 }
91
92 // Save the occuringVariables of a state, needed if we want to use monotonicity
93 for (auto& var : occurringVariables) {
94 occuringStatesAtVariable[var].insert(row);
95 }
96 occurringVariablesAtState[row] = std::move(occurringVariables);
97 }
98
99 for (uint64_t i = 0; i < pVector.size(); i++) {
100 auto const transition = pVector[i];
101 if (!selectedRows.get(i)) {
102 continue;
103 }
104 if (storm::utility::isConstant(transition)) {
105 vector.push_back(utility::convertNumber<double>(transition));
106 } else {
107 nonConstVectorEntries.set(pVectorEntryCount, true);
108 auto valuation = RobustAbstractValuation(transition);
109 vector.push_back(Interval());
110 Interval& placeholder = functionValuationCollector.add(valuation);
111 vectorAssignment.push_back(std::pair<typename std::vector<Interval>::iterator, Interval&>(typename std::vector<Interval>::iterator(), placeholder));
112 for (auto const& var : valuation.getParameters()) {
113 occuringStatesAtVariable[var].insert(i);
114 occurringVariablesAtState[i].emplace(var);
115 }
116 }
117 pVectorEntryCount++;
118 }
119
120 matrix = builder.build();
121 vector.shrink_to_fit();
122 matrixAssignment.shrink_to_fit();
123 vectorAssignment.shrink_to_fit();
124 nonConstMatrixEntries.resize(pMatrixEntryCount);
125
126 // Now insert the correct iterators for the matrix and vector assignment
127 auto matrixAssignmentIt = matrixAssignment.begin();
128 uint64_t startEntryOfRow = 0;
129 for (uint64_t group = 0; group < matrix.getRowGroupCount(); ++group) {
130 uint64_t startEntryOfNextRow = startEntryOfRow + matrix.getRow(group, 0).getNumberOfEntries();
131 for (uint64_t matrixRow = matrix.getRowGroupIndices()[group]; matrixRow < matrix.getRowGroupIndices()[group + 1]; ++matrixRow) {
132 auto matrixEntryIt = matrix.getRow(matrixRow).begin();
133 for (uint64_t nonConstEntryIndex = nonConstMatrixEntries.getNextSetIndex(startEntryOfRow); nonConstEntryIndex < startEntryOfNextRow;
134 nonConstEntryIndex = nonConstMatrixEntries.getNextSetIndex(nonConstEntryIndex + 1)) {
135 matrixAssignmentIt->first = matrixEntryIt + (nonConstEntryIndex - startEntryOfRow);
136 ++matrixAssignmentIt;
137 }
138 }
139 startEntryOfRow = startEntryOfNextRow;
140 }
141 STORM_LOG_ASSERT(matrixAssignmentIt == matrixAssignment.end(), "Unexpected number of entries in the matrix assignment.");
142
143 auto vectorAssignmentIt = vectorAssignment.begin();
144 for (auto const& nonConstVectorEntry : nonConstVectorEntries) {
145 for (uint64_t vectorIndex = matrix.getRowGroupIndices()[nonConstVectorEntry]; vectorIndex != matrix.getRowGroupIndices()[nonConstVectorEntry + 1];
146 ++vectorIndex) {
147 vectorAssignmentIt->first = vector.begin() + vectorIndex;
148 ++vectorAssignmentIt;
149 }
150 }
151 STORM_LOG_ASSERT(vectorAssignmentIt == vectorAssignment.end(), "Unexpected number of entries in the vector assignment.");
152}
153
154template<typename ParametricType, typename ConstantType>
156 storm::solver::OptimizationDirection const& dirForParameters) {
157 // write the evaluation result of each function,evaluation pair into the placeholders
158 this->currentRegionAllIllDefined = functionValuationCollector.evaluateCollectedFunctions(region, dirForParameters);
159
160 // TODO Return if currentRegionAllIllDefined? Or write to matrix?
161
162 // apply the matrix and vector assignments to write the contents of the placeholder into the matrix/vector
163 for (auto& assignment : matrixAssignment) {
164 assignment.first->setValue(assignment.second);
165 }
166
167 for (auto& assignment : vectorAssignment) {
168 *assignment.first = assignment.second;
169 }
170}
171
172template<typename ParametricType, typename ConstantType>
173const std::vector<std::set<typename RobustParameterLifter<ParametricType, ConstantType>::VariableType>>&
177
178template<typename ParametricType, typename ConstantType>
179std::map<typename RobustParameterLifter<ParametricType, ConstantType>::VariableType, std::set<uint_fast64_t>> const&
183
184template<typename ParametricType, typename ConstantType>
185std::optional<std::set<typename storm::utility::parametric::CoefficientType<ParametricType>::type>>
188 std::shared_ptr<storm::expressions::ExpressionManager> expressionManager = std::make_shared<storm::expressions::ExpressionManager>();
189
191 auto smtSolver = factory.create(*expressionManager);
192
194
195 auto expression = rfte.toExpression(function) == expressionManager->rational(0);
196
197 auto variables = expressionManager->getVariables();
198 // Sum the summands together directly in the expression so we pass this info to the solver
199 expressions::Expression exprBounds = expressionManager->boolean(true);
200 for (auto const& var : variables) {
201 exprBounds = exprBounds && expressionManager->rational(0) <= var && var <= expressionManager->rational(1);
202 }
203
204 smtSolver->setTimeout(50);
205
206 smtSolver->add(exprBounds);
207 smtSolver->add(expression);
208
209 std::set<CoefficientType> zeroes = {};
210
211 while (true) {
212 auto checkResult = smtSolver->check();
213
214 if (checkResult == solver::SmtSolver::CheckResult::Sat) {
215 auto model = smtSolver->getModel();
216
217 STORM_LOG_ERROR_COND(variables.size() == 1, "Should be one variable.");
218 if (variables.size() != 1) {
219 return {};
220 }
221 auto const var = *variables.begin();
222
223 double value = model->getRationalValue(var);
224
225 zeroes.emplace(utility::convertNumber<CoefficientType>(value));
226
227 // Add new constraint so we search for the next zero in the polynomial
228 // Get another model (or unsat)
229 // For some reason, this only really works when we then make a new
230 smtSolver->addNotCurrentModel();
231 } else if (checkResult == solver::SmtSolver::CheckResult::Unknown) {
232 return std::nullopt;
233 break;
234 } else {
235 // Unsat => found all zeroes :)
236 break;
237 }
238 }
239 return zeroes;
240}
241
242template<typename ParametricType, typename ConstantType>
243std::optional<std::set<typename storm::utility::parametric::CoefficientType<ParametricType>::type>>
244RobustParameterLifter<ParametricType, ConstantType>::RobustAbstractValuation::zeroesCarl(
247 auto const& carlRoots = carl::rootfinder::realRoots<CoefficientType, CoefficientType>(
248 polynomial, carl::Interval<CoefficientType>(utility::zero<CoefficientType>(), utility::one<CoefficientType>()),
249 carl::rootfinder::SplittingStrategy::ABERTH);
250 std::set<CoefficientType> zeroes = {};
251 for (carl::RealAlgebraicNumber<CoefficientType> const& root : carlRoots) {
252 CoefficientType rootCoefficient;
253 if (root.isNumeric()) {
254 rootCoefficient = CoefficientType(root.value());
255 } else {
256 rootCoefficient = CoefficientType((root.upper() + root.lower()) / 2);
257 }
258 zeroes.emplace(rootCoefficient);
259 }
260 return zeroes;
261}
262
263template<typename ParametricType, typename ConstantType>
264std::set<typename storm::utility::parametric::CoefficientType<ParametricType>::type>
265RobustParameterLifter<ParametricType, ConstantType>::RobustAbstractValuation::cubicEquationZeroes(
267 if (polynomial.isConstant()) {
268 return {};
269 }
270 STORM_LOG_ERROR_COND(polynomial.gatherVariables().size() == 1, "Multi-variate polynomials currently not supported");
271 // Polynomial is a*p^3 + b*p^2 + c*p + d
272
273 // Recover factors from polynomial
274 CoefficientType a = utility::zero<CoefficientType>(), b = a, c = a, d = a;
275 utility::convertNumber<ConstantType>(a);
276 for (auto const& term : polynomial.getTerms()) {
277 STORM_LOG_ASSERT(term.getNrVariables() <= 1, "No terms with more than one variable allowed but " << term << " has " << term.getNrVariables());
278 if (!term.isConstant() && term.getSingleVariable() != parameter) {
279 continue;
280 }
281 CoefficientType coefficient = term.coeff();
282 STORM_LOG_ASSERT(term.tdeg() < 4, "Transitions are only allowed to have a maximum degree of four.");
283 switch (term.tdeg()) {
284 case 0:
285 d = coefficient;
286 break;
287 case 1:
288 c = coefficient;
289 break;
290 case 2:
291 b = coefficient;
292 break;
293 case 3:
294 a = coefficient;
295 break;
296 }
297 }
298 // Translated from https://stackoverflow.com/questions/27176423/function-to-solve-cubic-equation-analytically
299
300 // Quadratic case
301 if (utility::isZero(a)) {
302 a = b;
303 b = c;
304 c = d;
305 // Linear case
306 if (utility::isZero(a)) {
307 a = b;
308 b = c;
309 // Constant case
310 if (utility::isZero(a)) {
311 return {};
312 }
313 return {-b / a};
314 }
315
316 CoefficientType D = b * b - 4 * a * c;
317 if (utility::isZero(D)) {
318 return {-b / (2 * a)};
319 } else if (D > 0) {
320 return {(-b + utility::sqrt(D)) / (2 * a), (-b - utility::sqrt(D)) / (2 * a)};
321 }
322 return {};
323 }
324 std::set<CoefficientType> roots;
325
326 // Convert to depressed cubic t^3+pt+q = 0 (subst x = t - b/3a)
327 CoefficientType p = (3 * a * c - b * b) / (3 * a * a);
328 CoefficientType q = (2 * b * b * b - 9 * a * b * c + 27 * a * a * d) / (27 * a * a * a);
329 double pDouble = utility::convertNumber<ConstantType>(p);
330 double qDouble = utility::convertNumber<ConstantType>(q);
331
332 if (utility::isZero(p)) { // p = 0 -> t^3 = -q -> t = -q^1/3
333 roots = {utility::convertNumber<CoefficientType>(std::cbrt(-qDouble))};
334 } else if (utility::isZero(q)) { // q = 0 -> t^3 + pt = 0 -> t(t^2+p)=0
335 roots = {0};
336 if (p < 0) {
337 roots.emplace(utility::convertNumber<CoefficientType>(utility::sqrt(-pDouble)));
338 roots.emplace(utility::convertNumber<CoefficientType>(-utility::sqrt(-pDouble)));
339 }
340 } else {
341 // These are all coefficients (we also plug the values into RationalFunctions later), i.e., they are rational numbers,
342 // but some of these operations are strictly real, so we convert to double and back (i.e., approximate).
343 CoefficientType D = q * q / 4 + p * p * p / 27;
344 if (utility::isZero(D)) { // D = 0 -> two roots
345 roots = {-3 * q / (p * 2), 3 * q / p};
346 } else if (D > 0) { // Only one real root
347 double Ddouble = utility::convertNumber<ConstantType>(D);
348 CoefficientType u = utility::convertNumber<CoefficientType>(std::cbrt(-qDouble / 2 - utility::sqrt(Ddouble)));
349 roots = {u - p / (3 * u)};
350 } else { // D < 0, three roots, but needs to use complex numbers/trigonometric solution
351 double u = 2 * utility::sqrt(-pDouble / 3);
352 double t = std::acos(3 * qDouble / pDouble / u) / 3; // D < 0 implies p < 0 and acos argument in [-1..1]
353 double k = 2 * M_PI / 3;
354
355 roots = {utility::convertNumber<CoefficientType>(u * std::cos(t)), utility::convertNumber<CoefficientType>(u * std::cos(t - k)),
356 utility::convertNumber<CoefficientType>(u * std::cos(t - 2 * k))};
357 }
358 }
359
360 return roots;
361}
362
363template<typename ParametricType, typename ConstantType>
365 : transition(transition) {
366 STORM_LOG_ERROR_COND(transition.denominator().isConstant(), "Robust PLA only supports transitions with constant denominators.");
367 transition.simplify();
368 std::set<VariableType> occurringVariables;
369 storm::utility::parametric::gatherOccurringVariables(transition, occurringVariables);
370 for (auto const& var : occurringVariables) {
371 parameters.emplace(var);
372 }
373}
374
375template<typename ParametricType, typename ConstantType>
379
380template<typename ParametricType, typename ConstantType>
382 return vector;
383}
384
385template<typename ParametricType, typename ConstantType>
387 return currentRegionAllIllDefined;
388}
389
390template<typename ParametricType, typename ConstantType>
392 return this->transition == other.transition;
393}
394
395template<typename ParametricType, typename ConstantType>
396std::set<typename RobustParameterLifter<ParametricType, ConstantType>::VariableType> const&
400
401template<typename ParametricType, typename ConstantType>
405
406template<typename ParametricType, typename ConstantType>
408 // TODO This function is a mess
409 if (this->extrema || this->annotation) {
410 // Extrema already initialized
411 return;
412 }
413
414 if (BigStep::lastSavedAnnotations.count(transition)) {
415 auto& annotation = BigStep::lastSavedAnnotations.at(transition);
416
417 auto const& terms = annotation.getTerms();
418
419 // Try to find all zeroes of all derivatives with the SMT solver.
420 // TODO: Are we even using that this is a sum of terms?
421
422 std::optional<std::set<CoefficientType>> carlResult;
423
424 if (terms.size() < 5) {
425 carlResult = zeroesCarl(annotation.getProbability().derivative(), annotation.getParameter());
426 }
427
428 if (carlResult) {
429 // Hooray, we found the zeroes with the SMT solver / CARL
430 this->extrema = std::map<VariableType, std::set<CoefficientType>>();
431 (*this->extrema)[annotation.getParameter()];
432 for (auto const& root : *carlResult) {
433 (*this->extrema).at(annotation.getParameter()).emplace(utility::convertNumber<CoefficientType>(root));
434 }
435 } else {
436 // TODO make evaluation depth configurable
437 annotation.computeDerivative(4);
438 }
439 this->annotation.emplace(annotation);
440 } else {
441 this->extrema = std::map<VariableType, std::set<CoefficientType>>();
442
443 for (auto const& p : transition.gatherVariables()) {
444 (*this->extrema)[p] = {};
445
446 auto const& derivative = transition.derivative(p);
447
448 if (derivative.isConstant()) {
449 continue;
450 }
451
452 // There is no annotation for this transition:
453 auto nominatorAsUnivariate = derivative.nominator().toUnivariatePolynomial();
454 // Constant denominator is now distributed in the factors, not in the denominator of the rational function
455 nominatorAsUnivariate /= derivative.denominator().coefficient();
456
457 // Compute zeros of derivative (= maxima/minima of function) and emplace those between 0 and 1 into the maxima set
458 std::optional<std::set<CoefficientType>> zeroes;
459 // Find zeroes with straight-forward method for degrees <4, find them with SMT for degrees above that
460 if (derivative.nominator().totalDegree() < 4) {
461 zeroes = cubicEquationZeroes(RawPolynomial(derivative.nominator()), p);
462 } else {
463 zeroes = zeroesSMT(derivative, p);
464 }
465 STORM_LOG_ERROR_COND(zeroes, "Zeroes of " << derivative << " could not be found.");
466 for (auto const& zero : *zeroes) {
467 if (zero >= utility::zero<CoefficientType>() && zero <= utility::one<CoefficientType>()) {
468 this->extrema->at(p).emplace(zero);
469 }
470 }
471 }
472 }
473}
474
475template<typename ParametricType, typename ConstantType>
476std::optional<std::map<typename RobustParameterLifter<ParametricType, ConstantType>::VariableType,
477 std::set<typename storm::utility::parametric::CoefficientType<ParametricType>::type>>> const&
481
482template<typename ParametricType, typename ConstantType>
484 return this->annotation;
485}
486
487template<typename ParametricType, typename ConstantType>
489 std::size_t seed = 0;
490 carl::hash_add(seed, transition);
491 return seed;
492}
493
494template<typename ParametricType, typename ConstantType>
496 // If no valuation like this is present in the collectedValuations, initialize the extrema
497 if (!collectedValuations.count(valuation)) {
498 valuation.initialize();
499 this->regionsAndBounds.emplace(valuation, std::vector<std::pair<Interval, Interval>>());
500 }
501 // insert the function and the valuation
502 // Note that references to elements of an unordered map remain valid after calling unordered_map::insert.
503 auto insertionRes = collectedValuations.insert(std::pair<RobustAbstractValuation, Interval>(std::move(valuation), storm::Interval(0, 1)));
504 return insertionRes.first->second;
505}
506
507Interval evaluateExtremaAnnotations(std::map<UniPoly, std::set<double>> extremaAnnotations, Interval input) {
508 Interval sumOfTerms(0.0, 0.0);
509 for (auto const& [poly, roots] : extremaAnnotations) {
510 std::set<double> potentialExtrema = {input.lower(), input.upper()};
511 for (auto const& root : roots) {
512 if (root >= input.lower() && root <= input.upper()) {
513 potentialExtrema.emplace(root);
514 }
515 }
516
517 double minValue = utility::infinity<double>();
518 double maxValue = -utility::infinity<double>();
519
520 for (auto const& potentialExtremum : potentialExtrema) {
521 auto value = utility::convertNumber<double>(poly.evaluate(utility::convertNumber<RationalFunctionCoefficient>(potentialExtremum)));
522 if (value > maxValue) {
523 maxValue = value;
524 }
525 if (value < minValue) {
526 minValue = value;
527 }
528 }
529 sumOfTerms += Interval(minValue, maxValue);
530 }
531 return sumOfTerms;
532}
533
534template<typename ParametricType, typename ConstantType>
535bool RobustParameterLifter<ParametricType, ConstantType>::FunctionValuationCollector::evaluateCollectedFunctions(
536 storm::storage::ParameterRegion<ParametricType> const& region, storm::solver::OptimizationDirection const& dirForUnspecifiedParameters) {
537 std::unordered_map<RobustAbstractValuation, Interval, RobustAbstractValuationHash> insertThese;
538 for (auto& [abstrValuation, placeholder] : collectedValuations) {
539 // Results of our computations go here, we use different methods
540 ConstantType lowerBound = utility::infinity<ConstantType>();
541 ConstantType upperBound = -utility::infinity<ConstantType>();
542
543 if (abstrValuation.getExtrema()) {
544 // We know the extrema of this abstract valuation => we can get the exact bounds easily
545
546 // If an annotation exists:
547 // Evaluating the annotation is cheaper than evaluating the RationalFunction, which isn't prime-factorized
548 // If no annotation exists:
549 // The RationalFunction is hopefully prime-factorized
550 auto const& maybeAnnotation = abstrValuation.getAnnotation();
551
552 if (maybeAnnotation) {
553 // We only have one parameter and can evaluate the annotation directly
554 auto p = maybeAnnotation->getParameter();
555
556 CoefficientType lowerP = region.getLowerBoundary(p);
557 CoefficientType upperP = region.getUpperBoundary(p);
558 std::set<CoefficientType> potentialExtrema = {lowerP, upperP};
559 for (auto const& maximum : abstrValuation.getExtrema()->at(p)) {
560 if (maximum >= lowerP && maximum <= upperP) {
561 potentialExtrema.emplace(maximum);
562 }
563 }
564
565 for (auto const& potentialExtremum : potentialExtrema) {
566 // Possible optimization: evaluate all transitions together, keeping track of intermediate results
567 auto value = maybeAnnotation->evaluate(utility::convertNumber<double>(potentialExtremum));
568 if (value > upperBound) {
569 upperBound = value;
570 }
571 if (value < lowerBound) {
572 lowerBound = value;
573 }
574 }
575 } else {
576 // We may have multiple parameters, but the derivatives w.r.t. each parameter only contain that parameter
577 // We first figure out the positions of the lower and upper bounds per parameter
578 // Lower/upper bound of every parameter is independent because the transitions are sums of terms with one parameter each
579 // At the end, we compute the value
580 std::map<VariableType, CoefficientType> lowerPositions;
581 std::map<VariableType, CoefficientType> upperPositions;
582
583 for (auto const& p : abstrValuation.getParameters()) {
584 CoefficientType lowerP = region.getLowerBoundary(p);
585 CoefficientType upperP = region.getUpperBoundary(p);
586
587 std::set<CoefficientType> potentialExtrema = {lowerP, upperP};
588 for (auto const& maximum : abstrValuation.getExtrema()->at(p)) {
589 if (maximum >= lowerP && maximum <= upperP) {
590 potentialExtrema.emplace(maximum);
591 }
592 }
593
594 CoefficientType minPosP;
595 CoefficientType maxPosP;
596 CoefficientType minValue = utility::infinity<CoefficientType>();
597 CoefficientType maxValue = -utility::infinity<CoefficientType>();
598
599 auto instantiation = std::map<VariableType, CoefficientType>(region.getLowerBoundaries());
600
601 for (auto const& potentialExtremum : potentialExtrema) {
602 // We modify the instantiation to have value potentialExtremum at p, keeping other parameters the same
603 instantiation[p] = potentialExtremum;
604 auto value = abstrValuation.getTransition().evaluate(instantiation);
605 if (value > maxValue) {
606 maxValue = value;
607 maxPosP = potentialExtremum;
608 }
609 if (value < minValue) {
610 minValue = value;
611 minPosP = potentialExtremum;
612 }
613 }
614
615 lowerPositions[p] = minPosP;
616 upperPositions[p] = maxPosP;
617 }
618
619 // Compute function values at left and right ends
620 lowerBound = utility::convertNumber<ConstantType>(abstrValuation.getTransition().evaluate(lowerPositions));
621 upperBound = utility::convertNumber<ConstantType>(abstrValuation.getTransition().evaluate(upperPositions));
622 }
623
624 if (upperBound < utility::zero<ConstantType>() || lowerBound > utility::one<ConstantType>()) {
625 // Current region is entirely ill-defined (partially ill-defined is fine:)
626 return true;
627 }
628 } else {
629 STORM_LOG_ASSERT(abstrValuation.getAnnotation(), "Needs to have annotation if no zeroes");
630 auto& regionsAndBounds = this->regionsAndBounds.at(abstrValuation);
631 auto const& annotation = *abstrValuation.getAnnotation();
632
633 auto plaRegion = Interval(region.getLowerBoundary(annotation.getParameter()), region.getUpperBoundary(annotation.getParameter()));
634
635 bool refine = false;
636 do {
637 lowerBound = 1.0;
638 upperBound = 0.0;
639 std::vector<uint64_t> regionsInPLARegion;
640 for (uint64_t i = 0; i < regionsAndBounds.size(); i++) {
641 auto const& [region, bound] = regionsAndBounds[i];
643 i == 0 ? true : (!(region.upper() < regionsAndBounds[i - 1].first.lower() || region.lower() > regionsAndBounds[i - 1].first.upper())),
644 "regions next to each other need to intersect");
645 if (region.upper() <= plaRegion.lower() || region.lower() >= plaRegion.upper()) {
646 if (regionsInPLARegion.empty()) {
647 continue;
648 } else {
649 // Regions are sorted => we've walked past the interesting part
650 break;
651 }
652 }
653 lowerBound = utility::min(lowerBound, bound.lower());
654 upperBound = utility::max(upperBound, bound.upper());
655 regionsInPLARegion.push_back(i);
656 }
657
658 // TODO make this configurable
659 uint64_t regionsRefine = std::max((uint64_t)10, annotation.maxDegree());
660 refine = regionsInPLARegion.size() < regionsRefine;
661
662 if (refine) {
663 std::vector<Interval> newIntervals;
664 auto diameter = plaRegion.diameter();
665 // If we have no regions at all, initialize with the entire region
666 if (regionsAndBounds.empty()) {
667 regionsAndBounds.emplace_back(plaRegion, Interval(0, 1));
668 regionsInPLARegion.push_back(0);
669 }
670 // Add start (old regions might be larger than currently considered region)
671 if (regionsAndBounds[regionsInPLARegion.front()].first.lower() < plaRegion.lower()) {
672 newIntervals.push_back(Interval(regionsAndBounds[regionsInPLARegion.front()].first.lower(), plaRegion.lower()));
673 }
674 // Split up considered region
675 for (uint64_t i = 0; i < regionsRefine; i++) {
676 newIntervals.push_back(Interval(plaRegion.lower() + ((double)i / (double)regionsRefine) * diameter,
677 plaRegion.lower() + ((double)(i + 1) / (double)regionsRefine) * diameter));
678 }
679 // Add end
680 if (regionsAndBounds[regionsInPLARegion.back()].first.upper() > plaRegion.upper()) {
681 newIntervals.push_back(Interval(plaRegion.upper(), regionsAndBounds[regionsInPLARegion.back()].first.upper()));
682 }
683 // Remember everything that comes after what we changed
684 std::vector<std::pair<Interval, Interval>> regionsAndBoundsAfter;
685 for (uint64_t i = regionsInPLARegion.back() + 1; i < regionsAndBounds.size(); i++) {
686 regionsAndBoundsAfter.push_back(regionsAndBounds[i]);
687 }
688 // Remove previous results
689 regionsAndBounds.erase(regionsAndBounds.begin() + *regionsInPLARegion.begin(), regionsAndBounds.end());
690
691 // Compute region results using interval arithmetic
692 for (auto const& region : newIntervals) {
693 regionsAndBounds.emplace_back(region, annotation.evaluateOnIntervalMidpointTheorem(region));
694 }
695 // Emplace back remembered stuff
696 for (auto const& item : regionsAndBoundsAfter) {
697 regionsAndBounds.emplace_back(item);
698 }
699 }
700 } while (refine);
701 }
702
703 // bool graphPreserving = true;
704 // // const ConstantType epsilon =
705 // // graphPreserving ? utility::convertNumber<ConstantType>(storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision())
706 // // : utility::zero<ConstantType>();
707 const ConstantType epsilon = 0;
708 // We want to check in the realm of feasible instantiations, even if our not our entire parameter space is feasible
709 lowerBound = utility::max(utility::min(lowerBound, utility::one<ConstantType>() - epsilon), epsilon);
710 upperBound = utility::max(utility::min(upperBound, utility::one<ConstantType>() - epsilon), epsilon);
711
712 STORM_LOG_ASSERT(lowerBound <= upperBound, "Whoops");
713
714 placeholder = Interval(lowerBound, upperBound);
715 }
716 for (auto& key : insertThese) {
717 this->collectedValuations.insert(std::move(insertThese.extract(key.first)));
718 }
719 return false;
720}
721
722template class RobustParameterLifter<storm::RationalFunction, double>;
723} // namespace transformer
724} // namespace storm
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
size_t size() const
Retrieves the number of bits this bit vector can store.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
Valuation const & getLowerBoundaries() const
CoefficientType const & getLowerBoundary(VariableType const &variable) const
CoefficientType const & getUpperBoundary(VariableType const &variable) const
A class that can be used to build a sparse matrix by adding value by value.
void addNextValue(index_type row, index_type column, value_type const &value)
Sets the matrix entry at the given row and column to the given value.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
index_type getEntryCount() const
Returns the number of entries in the matrix.
std::vector< MatrixEntry< index_type, value_type > >::iterator iterator
index_type getRowCount() const
Returns the number of rows of the matrix.
static std::unordered_map< RationalFunction, Annotation > lastSavedAnnotations
Definition BigStep.h:198
std::optional< std::map< VariableType, std::set< CoefficientType > > > const & getExtrema() const
This class lifts parameter choices to nondeterminism: For each row in the given matrix that considerd...
storm::storage::SparseMatrix< Interval > const & getMatrix() const
std::map< VariableType, std::set< uint_fast64_t > > const & getOccuringStatesAtVariable() const
std::vector< Interval > const & getVector() const
storm::utility::parametric::CoefficientType< ParametricType >::type CoefficientType
std::vector< std::set< VariableType > > const & getOccurringVariablesAtState() const
void specifyRegion(storm::storage::ParameterRegion< ParametricType > const &region, storm::solver::OptimizationDirection const &dirForParameters)
storm::utility::parametric::VariableType< ParametricType >::type VariableType
RobustParameterLifter(storm::storage::SparseMatrix< ParametricType > const &pMatrix, std::vector< ParametricType > const &pVector, storm::storage::BitVector const &selectedRows, storm::storage::BitVector const &selectedColumns, bool generateRowLabels=false, bool useMonotonicity=false)
Lifts the parameter choices to nondeterminisim.
virtual std::unique_ptr< storm::solver::SmtSolver > create(storm::expressions::ExpressionManager &manager) const
Creates a new SMT solver instance.
Definition solver.cpp:146
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_ERROR_COND(cond, message)
Definition macros.h:52
std::set< storm::RationalFunctionVariable > getParameters(DFT< storm::RationalFunction > const &dft)
Get all rate/probability parameters occurring in the DFT.
Definition DFT.cpp:825
storm::utility::parametric::CoefficientType< storm::RationalFunction >::type CoefficientType
carl::UnivariatePolynomial< RationalFunctionCoefficient > UniPoly
Definition BigStep.cpp:33
Interval evaluateExtremaAnnotations(std::map< UniPoly, std::set< double > > extremaAnnotations, Interval input)
void gatherOccurringVariables(FunctionType const &function, std::set< typename VariableType< FunctionType >::type > &variableSet)
Add all variables that occur in the given function to the the given set.
ValueType max(ValueType const &first, ValueType const &second)
bool isConstant(ValueType const &)
ValueType min(ValueType const &first, ValueType const &second)
bool isZero(ValueType const &a)
Definition constants.cpp:39
ValueType sqrt(ValueType const &number)
carl::Interval< double > Interval
Interval type.
carl::MultivariatePolynomial< RationalFunctionCoefficient > RawPolynomial