81 bool allowModelSimplifications,
bool graphPreserving) {
82 STORM_LOG_THROW(this->canHandle(parametricModel, checkTask), storm::exceptions::NotSupportedException,
83 "Combination of model " << parametricModel->getType() <<
" and formula '" << checkTask.
getFormula() <<
"' is not supported.");
84 this->specifySplitEstimates(generateRegionSplitEstimates, checkTask);
85 this->specifyMonotonicity(monotonicityBackend, checkTask);
86 this->graphPreserving = graphPreserving;
87 auto dtmc = parametricModel->template as<SparseModelType>();
88 if (isOrderBasedMonotonicityBackend()) {
90 "Allowing model simplification when using order-based monotonicity is not useful, as for order-based monotonicity checking model "
91 "simplification is done as preprocessing");
92 getOrderBasedMonotonicityBackend().initializeMonotonicityChecker(dtmc->getTransitionMatrix());
97 if (allowModelSimplifications && graphPreserving) {
99 simplifier.setPreserveParametricTransitions(
true);
100 if (!simplifier.simplify(checkTask.
getFormula())) {
101 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Simplifying the model was not successfull.");
103 this->parametricModel = simplifier.getSimplifiedModel();
104 this->specifyFormula(env, checkTask.
substituteFormula(*simplifier.getSimplifiedFormula()));
106 this->parametricModel = dtmc;
107 this->specifyFormula(env, checkTask);
109 if constexpr (!Robust) {
110 if (isOrderBasedMonotonicityBackend()) {
111 getOrderBasedMonotonicityBackend().registerParameterLifterReference(*parameterLifter);
112 getOrderBasedMonotonicityBackend().registerPLABoundFunction(
114 return this->computeQuantitativeValues(env, region, dir);
118 std::shared_ptr<storm::logic::Formula> formulaWithoutBounds = this->currentCheckTask->getFormula().clone();
119 formulaWithoutBounds->asOperatorFormula().removeBound();
120 this->currentFormulaNoBound = formulaWithoutBounds->asSharedPointer();
121 this->currentCheckTaskNoBound = std::make_unique<storm::modelchecker::CheckTask<storm::logic::Formula, ParametricType>>(*this->currentFormulaNoBound);
123 this->derivativeChecker =
124 std::make_unique<storm::derivative::SparseDerivativeInstantiationModelChecker<ParametricType, ConstantType>>(*this->parametricModel);
125 this->derivativeChecker->specifyFormula(env, *this->currentCheckTaskNoBound);
134 STORM_LOG_THROW(!checkTask.
getFormula().hasLowerBound(), storm::exceptions::NotSupportedException,
"Lower step bounds are not supported.");
135 STORM_LOG_THROW(checkTask.
getFormula().hasUpperBound(), storm::exceptions::NotSupportedException,
"Expected a bounded until formula with an upper bound.");
137 "Expected a bounded until formula with step bounds.");
138 stepBound = checkTask.
getFormula().getUpperBound().evaluateAsInt();
139 STORM_LOG_THROW(*stepBound > 0, storm::exceptions::NotSupportedException,
140 "Can not apply parameter lifting on step bounded formula: The step bound has to be positive.");
141 if (checkTask.
getFormula().isUpperBoundStrict()) {
142 STORM_LOG_THROW(*stepBound > 0, storm::exceptions::NotSupportedException,
"Expected a strict upper step bound that is greater than zero.");
145 STORM_LOG_THROW(*stepBound > 0, storm::exceptions::NotSupportedException,
146 "Can not apply parameter lifting on step bounded formula: The step bound has to be positive.");
152 storm::exceptions::NotSupportedException,
"Parameter lifting with non-propositional subformulas is not supported");
154 std::move(propositionalChecker.
check(checkTask.
getFormula().getLeftSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
156 std::move(propositionalChecker.
check(checkTask.
getFormula().getRightSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
160 maybeStates &= ~psiStates;
163 resultsForNonMaybeStates = std::vector<ConstantType>(this->parametricModel->getNumberOfStates(), storm::utility::zero<ConstantType>());
167 if (Robust || !maybeStates.empty()) {
169 std::vector<ParametricType> b = this->parametricModel->getTransitionMatrix().getConstrainedRowSumVector(
171 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
172 this->parametricModel->getTransitionMatrix(), b, maybeStates, maybeStates,
false, isOrderBasedMonotonicityBackend());
176 lowerResultBound = storm::utility::zero<ConstantType>();
177 upperResultBound = storm::utility::one<ConstantType>();
179 solverFactory->setRequirementsChecked(
true);
181 if (isOrderBasedMonotonicityBackend()) {
183 getOrderBasedMonotonicityBackend().initializeOrderExtender(prob1, prob0, this->parametricModel->getTransitionMatrix());
194 storm::exceptions::NotSupportedException,
"Parameter lifting with non-propositional subformulas is not supported");
196 std::move(propositionalChecker.
check(checkTask.
getFormula().getLeftSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
198 std::move(propositionalChecker.
check(checkTask.
getFormula().getRightSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
201 std::pair<storm::storage::BitVector, storm::storage::BitVector> statesWithProbability01 =
203 maybeStates = ~(statesWithProbability01.first | statesWithProbability01.second);
206 resultsForNonMaybeStates = std::vector<ConstantType>(this->parametricModel->getNumberOfStates(), storm::utility::zero<ConstantType>());
210 if (Robust || !maybeStates.empty()) {
211 if constexpr (Robust) {
214 std::vector<ParametricType> target(this->parametricModel->getNumberOfStates(), storm::utility::zero<ParametricType>());
217 if (!graphPreserving) {
219 maybeStates = ~statesWithProbability01.first & ~psiStates;
225 auto rowFilter = this->parametricModel->getTransitionMatrix().getRowFilter(maybeStates);
226 auto filteredMatrix = this->parametricModel->getTransitionMatrix().filterEntries(rowFilter);
228 maybeStates = allTrue;
230 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
231 filteredMatrix, target, allTrue, allTrue, isValueDeltaRegionSplitEstimates(), isOrderBasedMonotonicityBackend());
234 std::vector<ParametricType> b = this->parametricModel->getTransitionMatrix().getConstrainedRowSumVector(
235 storm::storage::BitVector(this->parametricModel->getTransitionMatrix().getRowCount(),
true), statesWithProbability01.second);
236 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
237 this->parametricModel->getTransitionMatrix(), b, maybeStates, maybeStates, isValueDeltaRegionSplitEstimates(),
238 isOrderBasedMonotonicityBackend());
243 lowerResultBound = storm::utility::zero<ConstantType>();
244 upperResultBound = storm::utility::one<ConstantType>();
248 auto req = solverFactory->getRequirements(env,
true,
true, boost::none, !Robust);
250 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UncheckedRequirementException,
251 "Solver requirements " + req.getEnabledRequirementsAsString() +
" not checked.");
252 solverFactory->setRequirementsChecked(
true);
254 if (isOrderBasedMonotonicityBackend()) {
255 getOrderBasedMonotonicityBackend().initializeOrderExtender(statesWithProbability01.second, statesWithProbability01.first,
256 this->parametricModel->getTransitionMatrix());
266 "Parameter lifting with non-propositional subformulas is not supported");
268 std::move(propositionalChecker.
check(checkTask.
getFormula().getSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
271 this->parametricModel->getBackwardTransitions(),
storm::storage::BitVector(this->parametricModel->getNumberOfStates(),
true), targetStates);
273 maybeStates = ~(targetStates | infinityStates);
276 resultsForNonMaybeStates = std::vector<ConstantType>(this->parametricModel->getNumberOfStates(), storm::utility::zero<ConstantType>());
280 if (Robust || !maybeStates.empty()) {
283 (!checkTask.
isRewardModelSet() && this->parametricModel->hasUniqueRewardModel()),
284 storm::exceptions::InvalidPropertyException,
"The reward model specified by the CheckTask is not available in the given model.");
286 typename SparseModelType::RewardModelType
const& rewardModel =
289 std::vector<ParametricType> b = rewardModel.getTotalRewardVector(this->parametricModel->getTransitionMatrix());
291 if constexpr (Robust) {
293 if (!graphPreserving) {
294 maybeStates = ~targetStates;
296 auto rowFilter = this->parametricModel->getTransitionMatrix().getRowFilter(maybeStates);
297 auto filteredMatrix = this->parametricModel->getTransitionMatrix().filterEntries(rowFilter);
298 maybeStates = allTrue;
300 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
301 filteredMatrix, b, allTrue, allTrue, isValueDeltaRegionSplitEstimates(), isOrderBasedMonotonicityBackend());
303 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
304 this->parametricModel->getTransitionMatrix(), b, maybeStates, maybeStates, isValueDeltaRegionSplitEstimates(),
305 isOrderBasedMonotonicityBackend());
310 lowerResultBound = storm::utility::zero<ConstantType>();
314 auto req = solverFactory->getRequirements(env,
true,
true, boost::none, !Robust);
315 req.clearLowerBounds();
316 if (req.upperBounds()) {
317 solvingRequiresUpperRewardBounds =
true;
318 req.clearUpperBounds();
320 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UncheckedRequirementException,
321 "Solver requirements " + req.getEnabledRequirementsAsString() +
" not checked.");
322 solverFactory->setRequirementsChecked(
true);
323 STORM_LOG_WARN_COND(!isOrderBasedMonotonicityBackend(),
"Order-based monotonicity not used for reachability reward formula.");
404 if (maybeStates.empty()) {
405 this->updateKnownValueBoundInRegion(region, dirForParameters, resultsForNonMaybeStates);
406 return resultsForNonMaybeStates;
408 parameterLifter->specifyRegion(region.
region, dirForParameters);
409 auto liftedMatrix = parameterLifter->getMatrix();
410 auto liftedVector = parameterLifter->getVector();
411 bool nonTrivialEndComponents =
false;
412 if constexpr (Robust) {
413 if (parameterLifter->isCurrentRegionAllIllDefined()) {
414 return std::vector<ConstantType>();
416 if (!graphPreserving) {
418 auto const& result = endComponentPreserver.
eliminateMECs(liftedMatrix, liftedVector);
422 liftedMatrix = *result;
423 nonTrivialEndComponents =
true;
427 const uint64_t resultVectorSize = liftedMatrix.getColumnCount();
430 if constexpr (!Robust) {
431 assert(*stepBound > 0);
432 x = std::vector<ConstantType>(resultVectorSize, storm::utility::zero<ConstantType>());
434 multiplier->repeatedMultiplyAndReduce(env, dirForParameters, x, &liftedVector, *stepBound);
439 auto solver = solverFactory->create(env, liftedMatrix);
440 solver->setHasUniqueSolution();
441 solver->setHasNoEndComponents();
443 solver->setUncertaintyIsRobust(
false);
444 if (lowerResultBound)
445 solver->setLowerBound(lowerResultBound.value());
446 if (upperResultBound) {
447 solver->setUpperBound(upperResultBound.value());
448 }
else if (solvingRequiresUpperRewardBounds) {
449 if constexpr (!Robust) {
451 std::vector<ConstantType> oneStepProbs;
452 oneStepProbs.reserve(liftedMatrix.getRowCount());
453 for (uint64_t row = 0; row < liftedMatrix.getRowCount(); ++row) {
454 oneStepProbs.push_back(storm::utility::one<ConstantType>() - liftedMatrix.getRowSum(row));
456 if (dirForParameters == storm::OptimizationDirection::Minimize) {
467 solver->setTrackScheduler(
true);
473 if constexpr (!Robust) {
475 if (isOrderBasedMonotonicityBackend()) {
477 if (!choices.has_value()) {
478 choices.emplace(parameterLifter->getRowGroupCount(), 0u);
480 statesWithFixedChoice = getOrderBasedMonotonicityBackend().getChoicesToFixForPLASolver(region, dirForParameters, *choices);
484 if (choices.has_value()) {
485 solver->setInitialScheduler(std::move(choices.value()));
486 if (statesWithFixedChoice.
size() != 0) {
488 solver->setSchedulerFixedForRowGroup(std::move(statesWithFixedChoice));
493 if (!nonTrivialEndComponents && choices.has_value()) {
494 solver->setInitialScheduler(std::move(choices.value()));
498 if (this->currentCheckTask->isBoundSet() && solver->hasInitialScheduler()) {
501 std::unique_ptr<storm::solver::TerminationCondition<ConstantType>> termCond;
503 ? this->parametricModel->getInitialStates() % maybeStates
507 termCond = std::make_unique<storm::solver::TerminateIfFilteredExtremumBelowThreshold<ConstantType>>(
508 relevantStatesInSubsystem,
true, this->currentCheckTask->getBoundThreshold(),
false);
511 termCond = std::make_unique<storm::solver::TerminateIfFilteredExtremumExceedsThreshold<ConstantType>>(
512 relevantStatesInSubsystem,
true, this->currentCheckTask->getBoundThreshold(),
true);
514 solver->setTerminationCondition(std::move(termCond));
518 x.resize(resultVectorSize, storm::utility::zero<ConstantType>());
519 solver->solveEquations(env, dirForParameters, x, liftedVector);
520 if (isValueDeltaRegionSplitEstimates()) {
521 computeStateValueDeltaRegionSplitEstimates(env, x, solver->getSchedulerChoices(), region.
region, dirForParameters);
524 if (!nonTrivialEndComponents) {
525 choices = solver->getSchedulerChoices();
530 std::vector<ConstantType> result = resultsForNonMaybeStates;
531 auto maybeStateResIt = x.begin();
532 for (
auto const& maybeState : maybeStates) {
533 result[maybeState] = *maybeStateResIt;
537 STORM_LOG_INFO(dirForParameters <<
" " << region.
region <<
": " << result[this->getUniqueInitialState()] << std::endl);
539 this->updateKnownValueBoundInRegion(region, dirForParameters, result);
545 Environment const& env, std::vector<ConstantType>
const& quantitativeResult, std::vector<uint64_t>
const& schedulerChoices,
547 auto const& matrix = parameterLifter->getMatrix();
548 auto const& vector = parameterLifter->getVector();
550 std::vector<ConstantType> weighting = std::vector<ConstantType>(vector.size(), utility::one<ConstantType>());
558 uint64_t rowIndex = 0;
559 for (
auto const& state : maybeStates) {
560 weighting[rowIndex++] = visitingTimes[state];
564 switch (*this->specifiedRegionSplitEstimateKind) {
567 std::map<VariableType, ConstantType> deltaLower, deltaUpper;
569 deltaLower.emplace(p, storm::utility::zero<ConstantType>());
570 deltaUpper.emplace(p, storm::utility::zero<ConstantType>());
572 if constexpr (Robust) {
574 static std::map<RationalFunction, RationalFunction> functionDerivatives;
575 static std::vector<std::pair<bool, double>> constantDerivatives;
576 if (constantDerivatives.empty()) {
577 for (uint64_t state : maybeStates) {
578 auto variables = parameterLifter->getOccurringVariablesAtState().at(state);
579 if (variables.size() == 0) {
583 "Cannot compute state-value-delta split estimates in robust mode if there are states with multiple parameters.");
584 auto const p = *variables.begin();
585 for (
auto const& entry : this->parametricModel->getTransitionMatrix().getRow(state)) {
586 auto const& function = entry.getValue();
587 if (functionDerivatives.count(function)) {
588 constantDerivatives.emplace_back(
false, 0);
591 auto const derivative = function.derivative(p);
592 if (derivative.isConstant()) {
593 constantDerivatives.emplace_back(
true, utility::convertNumber<double>(derivative.constantPart()));
595 functionDerivatives.emplace(function, derivative);
596 constantDerivatives.emplace_back(
false, 0);
598 constantDerivatives.emplace_back(
false, 0);
604 cachedRegionSplitEstimates.clear();
606 cachedRegionSplitEstimates.emplace(p, utility::zero<ConstantType>());
609 uint64_t entryCount = 0;
611 for (uint64_t state : maybeStates) {
612 auto variables = parameterLifter->getOccurringVariablesAtState().at(state);
613 if (variables.size() == 0) {
617 "Cannot compute state-value-delta split estimates in robust mode if there are states with multiple parameters.");
619 auto const p = *variables.begin();
621 const uint64_t rowIndex = maybeStates.getNumberOfSetBitsBeforeIndex(state);
623 std::vector<ConstantType> derivatives;
624 for (
auto const& entry : this->parametricModel->getTransitionMatrix().getRow(state)) {
627 ConstantType derivative =
628 annotation.derivative()->template evaluate<ConstantType>(utility::convertNumber<ConstantType>(region.
getCenter(p)));
629 derivatives.push_back(derivative);
631 auto const& cDer = constantDerivatives.at(entryCount);
633 derivatives.push_back(cDer.second);
636 derivatives.push_back(utility::convertNumber<ConstantType>(derivative));
642 std::vector<ConstantType> results(0);
644 ConstantType distrToNegativeDerivative = storm::utility::zero<ConstantType>();
645 ConstantType distrToPositiveDerivative = storm::utility::zero<ConstantType>();
647 for (
auto const& direction : {OptimizationDirection::Maximize, OptimizationDirection::Minimize}) {
652 ConstantType remainingValue = utility::one<ConstantType>();
653 ConstantType result = utility::zero<ConstantType>();
656 "Non-constant vector indices not supported (this includes parametric rewards).");
658 std::vector<std::pair<ConstantType, std::pair<ConstantType, uint64_t>>> robustOrder;
661 for (
auto const& entry : matrix.getRow(rowIndex)) {
662 auto const lower = entry.getValue().lower();
663 result += quantitativeResult[entry.getColumn()] * lower;
664 remainingValue -= lower;
665 auto const diameter = entry.getValue().upper() - lower;
667 robustOrder.emplace_back(quantitativeResult[entry.getColumn()], std::make_pair(diameter, index));
672 std::sort(robustOrder.begin(), robustOrder.end(),
673 [direction](
const std::pair<ConstantType, std::pair<ConstantType, uint64_t>>& a,
674 const std::pair<ConstantType, std::pair<ConstantType, uint64_t>>& b) {
675 if (direction == OptimizationDirection::Maximize) {
676 return a.first > b.first;
678 return a.first < b.first;
682 for (
auto const& pair : robustOrder) {
683 auto availableMass = std::min(pair.second.first, remainingValue);
684 result += availableMass * pair.first;
686 if (direction == this->currentCheckTask->getOptimizationDirection()) {
687 if (derivatives[pair.second.second] > 1e-6) {
688 distrToPositiveDerivative += availableMass;
689 }
else if (derivatives[pair.second.second] < 1e-6) {
690 distrToNegativeDerivative += availableMass;
693 remainingValue -= availableMass;
696 results.push_back(result);
699 ConstantType diff = std::abs(results[0] - results[1]);
700 if (distrToPositiveDerivative > distrToNegativeDerivative) {
701 deltaUpper[p] += diff * weighting[rowIndex];
703 deltaLower[p] += diff * weighting[rowIndex];
707 auto const& choiceValuations = parameterLifter->getRowLabels();
709 std::vector<ConstantType> stateResults;
710 for (uint64_t state = 0; state < schedulerChoices.size(); ++state) {
711 uint64_t rowOffset = matrix.getRowGroupIndices()[state];
712 uint64_t optimalChoice = schedulerChoices[state];
713 auto const& optimalChoiceVal = choiceValuations[rowOffset + optimalChoice];
714 assert(optimalChoiceVal.getUnspecifiedParameters().empty());
715 stateResults.clear();
716 for (uint64_t row = rowOffset; row < matrix.getRowGroupIndices()[state + 1]; ++row) {
717 stateResults.push_back(matrix.multiplyRowWithVector(row, quantitativeResult) + vector[row]);
720 bool checkUpperParameters =
false;
722 auto const& consideredParameters = checkUpperParameters ? optimalChoiceVal.getUpperParameters() : optimalChoiceVal.getLowerParameters();
723 for (
auto const& p : consideredParameters) {
725 ConstantType bestValue = 0;
726 bool foundBestValue =
false;
727 for (uint64_t choice = 0; choice < stateResults.size(); ++choice) {
728 if (choice != optimalChoice) {
729 auto const& otherBoundParsOfChoice = checkUpperParameters ? choiceValuations[rowOffset + choice].getLowerParameters()
730 : choiceValuations[rowOffset + choice].getUpperParameters();
731 if (otherBoundParsOfChoice.find(p) != otherBoundParsOfChoice.end()) {
732 ConstantType
const& choiceValue = stateResults[choice];
733 if (!foundBestValue ||
735 foundBestValue =
true;
736 bestValue = choiceValue;
741 auto const& optimal = stateResults[optimalChoice];
742 auto diff = storm::utility::abs<ConstantType>(optimal - storm::utility::convertNumber<ConstantType>(bestValue));
743 if (foundBestValue) {
744 if (checkUpperParameters) {
745 deltaLower[p] += diff * weighting[state];
747 deltaUpper[p] += diff * weighting[state];
751 checkUpperParameters = !checkUpperParameters;
752 }
while (checkUpperParameters);
756 cachedRegionSplitEstimates.clear();
759 auto minDelta = std::min(deltaLower[p], deltaUpper[p]);
760 cachedRegionSplitEstimates.emplace(p, minDelta);
768 *this->parametricModel);
769 instantiationModelChecker.
specifyFormula(*this->currentCheckTaskNoBound);
773 std::unique_ptr<storm::modelchecker::CheckResult> result = instantiationModelChecker.
check(env, center);
774 auto const reachabilityProbabilities = result->asExplicitQuantitativeCheckResult<ConstantType>().getValueVector();
776 STORM_LOG_ASSERT(this->derivativeChecker,
"Derivative checker not intialized");
779 auto result = this->derivativeChecker->check(env, center, param, reachabilityProbabilities);
780 ConstantType derivative =
781 result->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector()[this->derivativeChecker->getInitialState()];
782 cachedRegionSplitEstimates[param] =
utility::abs(derivative) * utility::convertNumber<ConstantType>(region.
getDifference(param));
787 STORM_LOG_ERROR(
"Region split estimate kind not handled by SparseDtmcParameterLiftingModelChecker.");