78 bool allowModelSimplifications,
bool graphPreserving) {
79 STORM_LOG_THROW(this->canHandle(parametricModel, checkTask), storm::exceptions::NotSupportedException,
80 "Combination of model " << parametricModel->getType() <<
" and formula '" << checkTask.
getFormula() <<
"' is not supported.");
81 this->specifySplitEstimates(generateRegionSplitEstimates, checkTask);
82 this->specifyMonotonicity(monotonicityBackend, checkTask);
83 this->graphPreserving = graphPreserving;
84 auto dtmc = parametricModel->template as<SparseModelType>();
85 if (isOrderBasedMonotonicityBackend()) {
87 "Allowing model simplification when using order-based monotonicity is not useful, as for order-based monotonicity checking model "
88 "simplification is done as preprocessing");
89 getOrderBasedMonotonicityBackend().initializeMonotonicityChecker(dtmc->getTransitionMatrix());
94 if (allowModelSimplifications && graphPreserving) {
96 simplifier.setPreserveParametricTransitions(
true);
97 if (!simplifier.simplify(checkTask.
getFormula())) {
98 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Simplifying the model was not successfull.");
100 this->parametricModel = simplifier.getSimplifiedModel();
101 this->specifyFormula(env, checkTask.
substituteFormula(*simplifier.getSimplifiedFormula()));
103 this->parametricModel = dtmc;
104 this->specifyFormula(env, checkTask);
106 if constexpr (!Robust) {
107 if (isOrderBasedMonotonicityBackend()) {
108 getOrderBasedMonotonicityBackend().registerParameterLifterReference(*parameterLifter);
109 getOrderBasedMonotonicityBackend().registerPLABoundFunction(
111 return this->computeQuantitativeValues(env, region, dir);
115 std::shared_ptr<storm::logic::Formula> formulaWithoutBounds = this->currentCheckTask->getFormula().clone();
116 formulaWithoutBounds->asOperatorFormula().removeBound();
117 this->currentFormulaNoBound = formulaWithoutBounds->asSharedPointer();
118 this->currentCheckTaskNoBound = std::make_unique<storm::modelchecker::CheckTask<storm::logic::Formula, ParametricType>>(*this->currentFormulaNoBound);
120 this->derivativeChecker =
121 std::make_unique<storm::derivative::SparseDerivativeInstantiationModelChecker<ParametricType, ConstantType>>(*this->parametricModel);
122 this->derivativeChecker->specifyFormula(env, *this->currentCheckTaskNoBound);
131 STORM_LOG_THROW(!checkTask.
getFormula().hasLowerBound(), storm::exceptions::NotSupportedException,
"Lower step bounds are not supported.");
132 STORM_LOG_THROW(checkTask.
getFormula().hasUpperBound(), storm::exceptions::NotSupportedException,
"Expected a bounded until formula with an upper bound.");
134 "Expected a bounded until formula with step bounds.");
135 stepBound = checkTask.
getFormula().getUpperBound().evaluateAsInt();
136 STORM_LOG_THROW(*stepBound > 0, storm::exceptions::NotSupportedException,
137 "Can not apply parameter lifting on step bounded formula: The step bound has to be positive.");
138 if (checkTask.
getFormula().isUpperBoundStrict()) {
139 STORM_LOG_THROW(*stepBound > 0, storm::exceptions::NotSupportedException,
"Expected a strict upper step bound that is greater than zero.");
142 STORM_LOG_THROW(*stepBound > 0, storm::exceptions::NotSupportedException,
143 "Can not apply parameter lifting on step bounded formula: The step bound has to be positive.");
149 storm::exceptions::NotSupportedException,
"Parameter lifting with non-propositional subformulas is not supported");
151 std::move(propositionalChecker.
check(checkTask.
getFormula().getLeftSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
153 std::move(propositionalChecker.
check(checkTask.
getFormula().getRightSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
157 maybeStates &= ~psiStates;
160 resultsForNonMaybeStates = std::vector<ConstantType>(this->parametricModel->getNumberOfStates(), storm::utility::zero<ConstantType>());
164 if (Robust || !maybeStates.empty()) {
166 std::vector<ParametricType> b = this->parametricModel->getTransitionMatrix().getConstrainedRowSumVector(
168 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
169 this->parametricModel->getTransitionMatrix(), b, maybeStates, maybeStates,
false, isOrderBasedMonotonicityBackend());
173 lowerResultBound = storm::utility::zero<ConstantType>();
174 upperResultBound = storm::utility::one<ConstantType>();
176 solverFactory->setRequirementsChecked(
true);
178 if (isOrderBasedMonotonicityBackend()) {
180 getOrderBasedMonotonicityBackend().initializeOrderExtender(prob1, prob0, this->parametricModel->getTransitionMatrix());
191 storm::exceptions::NotSupportedException,
"Parameter lifting with non-propositional subformulas is not supported");
193 std::move(propositionalChecker.
check(checkTask.
getFormula().getLeftSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
195 std::move(propositionalChecker.
check(checkTask.
getFormula().getRightSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
198 std::pair<storm::storage::BitVector, storm::storage::BitVector> statesWithProbability01 =
200 maybeStates = ~(statesWithProbability01.first | statesWithProbability01.second);
203 resultsForNonMaybeStates = std::vector<ConstantType>(this->parametricModel->getNumberOfStates(), storm::utility::zero<ConstantType>());
207 if (Robust || !maybeStates.empty()) {
208 if constexpr (Robust) {
211 std::vector<ParametricType> target(this->parametricModel->getNumberOfStates(), storm::utility::zero<ParametricType>());
214 if (!graphPreserving) {
216 maybeStates = ~statesWithProbability01.first & ~psiStates;
222 auto rowFilter = this->parametricModel->getTransitionMatrix().getRowFilter(maybeStates);
223 auto filteredMatrix = this->parametricModel->getTransitionMatrix().filterEntries(rowFilter);
225 maybeStates = allTrue;
227 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
228 filteredMatrix, target, allTrue, allTrue, isValueDeltaRegionSplitEstimates(), isOrderBasedMonotonicityBackend());
231 std::vector<ParametricType> b = this->parametricModel->getTransitionMatrix().getConstrainedRowSumVector(
232 storm::storage::BitVector(this->parametricModel->getTransitionMatrix().getRowCount(),
true), statesWithProbability01.second);
233 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
234 this->parametricModel->getTransitionMatrix(), b, maybeStates, maybeStates, isValueDeltaRegionSplitEstimates(),
235 isOrderBasedMonotonicityBackend());
240 lowerResultBound = storm::utility::zero<ConstantType>();
241 upperResultBound = storm::utility::one<ConstantType>();
245 auto req = solverFactory->getRequirements(env,
true,
true, boost::none, !Robust);
247 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UncheckedRequirementException,
248 "Solver requirements " + req.getEnabledRequirementsAsString() +
" not checked.");
249 solverFactory->setRequirementsChecked(
true);
251 if (isOrderBasedMonotonicityBackend()) {
252 getOrderBasedMonotonicityBackend().initializeOrderExtender(statesWithProbability01.second, statesWithProbability01.first,
253 this->parametricModel->getTransitionMatrix());
263 "Parameter lifting with non-propositional subformulas is not supported");
265 std::move(propositionalChecker.
check(checkTask.
getFormula().getSubformula())->asExplicitQualitativeCheckResult().getTruthValuesVector());
268 this->parametricModel->getBackwardTransitions(),
storm::storage::BitVector(this->parametricModel->getNumberOfStates(),
true), targetStates);
270 maybeStates = ~(targetStates | infinityStates);
273 resultsForNonMaybeStates = std::vector<ConstantType>(this->parametricModel->getNumberOfStates(), storm::utility::zero<ConstantType>());
277 if (Robust || !maybeStates.empty()) {
280 (!checkTask.
isRewardModelSet() && this->parametricModel->hasUniqueRewardModel()),
281 storm::exceptions::InvalidPropertyException,
"The reward model specified by the CheckTask is not available in the given model.");
283 typename SparseModelType::RewardModelType
const& rewardModel =
286 std::vector<ParametricType> b = rewardModel.getTotalRewardVector(this->parametricModel->getTransitionMatrix());
288 if constexpr (Robust) {
290 if (!graphPreserving) {
291 maybeStates = ~targetStates;
293 auto rowFilter = this->parametricModel->getTransitionMatrix().getRowFilter(maybeStates);
294 auto filteredMatrix = this->parametricModel->getTransitionMatrix().filterEntries(rowFilter);
295 maybeStates = allTrue;
297 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
298 filteredMatrix, b, allTrue, allTrue, isValueDeltaRegionSplitEstimates(), isOrderBasedMonotonicityBackend());
300 parameterLifter = std::make_unique<ParameterLifterType<ParametricType, ConstantType, Robust>>(
301 this->parametricModel->getTransitionMatrix(), b, maybeStates, maybeStates, isValueDeltaRegionSplitEstimates(),
302 isOrderBasedMonotonicityBackend());
307 lowerResultBound = storm::utility::zero<ConstantType>();
311 auto req = solverFactory->getRequirements(env,
true,
true, boost::none, !Robust);
312 req.clearLowerBounds();
313 if (req.upperBounds()) {
314 solvingRequiresUpperRewardBounds =
true;
315 req.clearUpperBounds();
317 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UncheckedRequirementException,
318 "Solver requirements " + req.getEnabledRequirementsAsString() +
" not checked.");
319 solverFactory->setRequirementsChecked(
true);
320 STORM_LOG_WARN_COND(!isOrderBasedMonotonicityBackend(),
"Order-based monotonicity not used for reachability reward formula.");
401 if (maybeStates.empty()) {
402 this->updateKnownValueBoundInRegion(region, dirForParameters, resultsForNonMaybeStates);
403 return resultsForNonMaybeStates;
405 parameterLifter->specifyRegion(region.
region, dirForParameters);
406 auto liftedMatrix = parameterLifter->getMatrix();
407 auto liftedVector = parameterLifter->getVector();
408 bool nonTrivialEndComponents =
false;
409 if constexpr (Robust) {
410 if (parameterLifter->isCurrentRegionAllIllDefined()) {
411 return std::vector<ConstantType>();
413 if (!graphPreserving) {
415 auto const& result = endComponentPreserver.
eliminateMECs(liftedMatrix, liftedVector);
419 liftedMatrix = *result;
420 nonTrivialEndComponents =
true;
424 const uint64_t resultVectorSize = liftedMatrix.getColumnCount();
427 if constexpr (!Robust) {
428 assert(*stepBound > 0);
429 x = std::vector<ConstantType>(resultVectorSize, storm::utility::zero<ConstantType>());
431 multiplier->repeatedMultiplyAndReduce(env, dirForParameters, x, &liftedVector, *stepBound);
436 auto solver = solverFactory->create(env, liftedMatrix);
437 solver->setHasUniqueSolution();
438 solver->setHasNoEndComponents();
440 solver->setUncertaintyIsRobust(
false);
441 if (lowerResultBound)
442 solver->setLowerBound(lowerResultBound.value());
443 if (upperResultBound) {
444 solver->setUpperBound(upperResultBound.value());
445 }
else if (solvingRequiresUpperRewardBounds) {
446 if constexpr (!Robust) {
448 std::vector<ConstantType> oneStepProbs;
449 oneStepProbs.reserve(liftedMatrix.getRowCount());
450 for (uint64_t row = 0; row < liftedMatrix.getRowCount(); ++row) {
451 oneStepProbs.push_back(storm::utility::one<ConstantType>() - liftedMatrix.getRowSum(row));
453 if (dirForParameters == storm::OptimizationDirection::Minimize) {
464 solver->setTrackScheduler(
true);
470 if constexpr (!Robust) {
472 if (isOrderBasedMonotonicityBackend()) {
474 if (!choices.has_value()) {
475 choices.emplace(parameterLifter->getRowGroupCount(), 0u);
477 statesWithFixedChoice = getOrderBasedMonotonicityBackend().getChoicesToFixForPLASolver(region, dirForParameters, *choices);
481 if (choices.has_value()) {
482 solver->setInitialScheduler(std::move(choices.value()));
483 if (statesWithFixedChoice.
size() != 0) {
485 solver->setSchedulerFixedForRowGroup(std::move(statesWithFixedChoice));
490 if (!nonTrivialEndComponents && choices.has_value()) {
491 solver->setInitialScheduler(std::move(choices.value()));
495 if (this->currentCheckTask->isBoundSet() && solver->hasInitialScheduler()) {
498 std::unique_ptr<storm::solver::TerminationCondition<ConstantType>> termCond;
500 ? this->parametricModel->getInitialStates() % maybeStates
504 termCond = std::make_unique<storm::solver::TerminateIfFilteredExtremumBelowThreshold<ConstantType>>(
505 relevantStatesInSubsystem,
true, this->currentCheckTask->getBoundThreshold(),
false);
508 termCond = std::make_unique<storm::solver::TerminateIfFilteredExtremumExceedsThreshold<ConstantType>>(
509 relevantStatesInSubsystem,
true, this->currentCheckTask->getBoundThreshold(),
true);
511 solver->setTerminationCondition(std::move(termCond));
515 x.resize(resultVectorSize, storm::utility::zero<ConstantType>());
516 solver->solveEquations(env, dirForParameters, x, liftedVector);
517 if (isValueDeltaRegionSplitEstimates()) {
518 computeStateValueDeltaRegionSplitEstimates(env, x, solver->getSchedulerChoices(), region.
region, dirForParameters);
521 if (!nonTrivialEndComponents) {
522 choices = solver->getSchedulerChoices();
527 std::vector<ConstantType> result = resultsForNonMaybeStates;
528 auto maybeStateResIt = x.begin();
529 for (
auto const& maybeState : maybeStates) {
530 result[maybeState] = *maybeStateResIt;
534 STORM_LOG_INFO(dirForParameters <<
" " << region.
region <<
": " << result[this->getUniqueInitialState()] << std::endl);
536 this->updateKnownValueBoundInRegion(region, dirForParameters, result);
542 Environment const& env, std::vector<ConstantType>
const& quantitativeResult, std::vector<uint64_t>
const& schedulerChoices,
544 auto const& matrix = parameterLifter->getMatrix();
545 auto const& vector = parameterLifter->getVector();
547 std::vector<ConstantType> weighting = std::vector<ConstantType>(vector.size(), utility::one<ConstantType>());
555 uint64_t rowIndex = 0;
556 for (
auto const& state : maybeStates) {
557 weighting[rowIndex++] = visitingTimes[state];
561 switch (*this->specifiedRegionSplitEstimateKind) {
564 std::map<VariableType, ConstantType> deltaLower, deltaUpper;
566 deltaLower.emplace(p, storm::utility::zero<ConstantType>());
567 deltaUpper.emplace(p, storm::utility::zero<ConstantType>());
569 if constexpr (Robust) {
571 static std::map<RationalFunction, RationalFunction> functionDerivatives;
572 static std::vector<std::pair<bool, double>> constantDerivatives;
573 if (constantDerivatives.empty()) {
574 for (uint64_t state : maybeStates) {
575 auto variables = parameterLifter->getOccurringVariablesAtState().at(state);
576 if (variables.size() == 0) {
580 "Cannot compute state-value-delta split estimates in robust mode if there are states with multiple parameters.");
581 auto const p = *variables.begin();
582 for (
auto const& entry : this->parametricModel->getTransitionMatrix().getRow(state)) {
583 auto const& function = entry.getValue();
584 if (functionDerivatives.count(function)) {
585 constantDerivatives.emplace_back(
false, 0);
588 auto const derivative = function.derivative(p);
589 if (derivative.isConstant()) {
590 constantDerivatives.emplace_back(
true, utility::convertNumber<double>(derivative.constantPart()));
592 functionDerivatives.emplace(function, derivative);
593 constantDerivatives.emplace_back(
false, 0);
595 constantDerivatives.emplace_back(
false, 0);
601 cachedRegionSplitEstimates.clear();
603 cachedRegionSplitEstimates.emplace(p, utility::zero<ConstantType>());
606 uint64_t entryCount = 0;
608 for (uint64_t state : maybeStates) {
609 auto variables = parameterLifter->getOccurringVariablesAtState().at(state);
610 if (variables.size() == 0) {
614 "Cannot compute state-value-delta split estimates in robust mode if there are states with multiple parameters.");
616 auto const p = *variables.begin();
618 const uint64_t rowIndex = maybeStates.getNumberOfSetBitsBeforeIndex(state);
620 std::vector<ConstantType> derivatives;
621 for (
auto const& entry : this->parametricModel->getTransitionMatrix().getRow(state)) {
624 ConstantType derivative =
625 annotation.derivative()->template evaluate<ConstantType>(utility::convertNumber<ConstantType>(region.
getCenter(p)));
626 derivatives.push_back(derivative);
628 auto const& cDer = constantDerivatives.at(entryCount);
630 derivatives.push_back(cDer.second);
633 derivatives.push_back(utility::convertNumber<ConstantType>(derivative));
639 std::vector<ConstantType> results(0);
641 ConstantType distrToNegativeDerivative = storm::utility::zero<ConstantType>();
642 ConstantType distrToPositiveDerivative = storm::utility::zero<ConstantType>();
644 for (
auto const& direction : {OptimizationDirection::Maximize, OptimizationDirection::Minimize}) {
649 ConstantType remainingValue = utility::one<ConstantType>();
650 ConstantType result = utility::zero<ConstantType>();
653 "Non-constant vector indices not supported (this includes parametric rewards).");
655 std::vector<std::pair<ConstantType, std::pair<ConstantType, uint64_t>>> robustOrder;
658 for (
auto const& entry : matrix.getRow(rowIndex)) {
659 auto const lower = entry.getValue().lower();
660 result += quantitativeResult[entry.getColumn()] * lower;
661 remainingValue -= lower;
662 auto const diameter = entry.getValue().upper() - lower;
664 robustOrder.emplace_back(quantitativeResult[entry.getColumn()], std::make_pair(diameter, index));
669 std::sort(robustOrder.begin(), robustOrder.end(),
670 [direction](
const std::pair<ConstantType, std::pair<ConstantType, uint64_t>>& a,
671 const std::pair<ConstantType, std::pair<ConstantType, uint64_t>>& b) {
672 if (direction == OptimizationDirection::Maximize) {
673 return a.first > b.first;
675 return a.first < b.first;
679 for (
auto const& pair : robustOrder) {
680 auto availableMass = std::min(pair.second.first, remainingValue);
681 result += availableMass * pair.first;
683 if (direction == this->currentCheckTask->getOptimizationDirection()) {
684 if (derivatives[pair.second.second] > 1e-6) {
685 distrToPositiveDerivative += availableMass;
686 }
else if (derivatives[pair.second.second] < 1e-6) {
687 distrToNegativeDerivative += availableMass;
690 remainingValue -= availableMass;
693 results.push_back(result);
696 ConstantType diff = std::abs(results[0] - results[1]);
697 if (distrToPositiveDerivative > distrToNegativeDerivative) {
698 deltaUpper[p] += diff * weighting[rowIndex];
700 deltaLower[p] += diff * weighting[rowIndex];
704 auto const& choiceValuations = parameterLifter->getRowLabels();
706 std::vector<ConstantType> stateResults;
707 for (uint64_t state = 0; state < schedulerChoices.size(); ++state) {
708 uint64_t rowOffset = matrix.getRowGroupIndices()[state];
709 uint64_t optimalChoice = schedulerChoices[state];
710 auto const& optimalChoiceVal = choiceValuations[rowOffset + optimalChoice];
711 assert(optimalChoiceVal.getUnspecifiedParameters().empty());
712 stateResults.clear();
713 for (uint64_t row = rowOffset; row < matrix.getRowGroupIndices()[state + 1]; ++row) {
714 stateResults.push_back(matrix.multiplyRowWithVector(row, quantitativeResult) + vector[row]);
717 bool checkUpperParameters =
false;
719 auto const& consideredParameters = checkUpperParameters ? optimalChoiceVal.getUpperParameters() : optimalChoiceVal.getLowerParameters();
720 for (
auto const& p : consideredParameters) {
722 ConstantType bestValue = 0;
723 bool foundBestValue =
false;
724 for (uint64_t choice = 0; choice < stateResults.size(); ++choice) {
725 if (choice != optimalChoice) {
726 auto const& otherBoundParsOfChoice = checkUpperParameters ? choiceValuations[rowOffset + choice].getLowerParameters()
727 : choiceValuations[rowOffset + choice].getUpperParameters();
728 if (otherBoundParsOfChoice.find(p) != otherBoundParsOfChoice.end()) {
729 ConstantType
const& choiceValue = stateResults[choice];
730 if (!foundBestValue ||
732 foundBestValue =
true;
733 bestValue = choiceValue;
738 auto const& optimal = stateResults[optimalChoice];
739 auto diff = storm::utility::abs<ConstantType>(optimal - storm::utility::convertNumber<ConstantType>(bestValue));
740 if (foundBestValue) {
741 if (checkUpperParameters) {
742 deltaLower[p] += diff * weighting[state];
744 deltaUpper[p] += diff * weighting[state];
748 checkUpperParameters = !checkUpperParameters;
749 }
while (checkUpperParameters);
753 cachedRegionSplitEstimates.clear();
756 auto minDelta = std::min(deltaLower[p], deltaUpper[p]);
757 cachedRegionSplitEstimates.emplace(p, minDelta);
765 *this->parametricModel);
766 instantiationModelChecker.
specifyFormula(*this->currentCheckTaskNoBound);
770 std::unique_ptr<storm::modelchecker::CheckResult> result = instantiationModelChecker.
check(env, center);
771 auto const reachabilityProbabilities = result->asExplicitQuantitativeCheckResult<ConstantType>().getValueVector();
773 STORM_LOG_ASSERT(this->derivativeChecker,
"Derivative checker not intialized");
776 auto result = this->derivativeChecker->check(env, center, param, reachabilityProbabilities);
777 ConstantType derivative =
778 result->template asExplicitQuantitativeCheckResult<ConstantType>().getValueVector()[this->derivativeChecker->getInitialState()];
779 cachedRegionSplitEstimates[param] =
utility::abs(derivative) * utility::convertNumber<ConstantType>(region.
getDifference(param));
784 STORM_LOG_ERROR(
"Region split estimate kind not handled by SparseDtmcParameterLiftingModelChecker.");