Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ReachabilityCertificateComputer.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <cfenv>
5#include <vector>
6
38
39namespace storm::modelchecker {
40
41namespace {
45class ScopedRoundingMode {
46 public:
47 explicit ScopedRoundingMode(int mode) : previousMode(std::fegetround()) {
48 std::fesetround(mode);
49 }
50 ~ScopedRoundingMode() {
51 std::fesetround(previousMode);
52 }
53 ScopedRoundingMode(ScopedRoundingMode const&) = delete;
54 ScopedRoundingMode& operator=(ScopedRoundingMode const&) = delete;
55
56 private:
57 int const previousMode;
58};
59} // namespace
60
61template<typename ValueType>
63 std::vector<ValueType> lowerValues;
64 std::vector<ValueType> upperValues; // Upper values for each state
65};
66
67template<typename ValueType, bool Nondeterministic, storm::OptimizationDirection Dir>
69 public:
71 struct Algorithm {
73 ValueType gamma;
74 ValueType delta;
75 };
76
78 storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix,
79 TotalRewardSpecification<ValueType> const& totalRewardSpecification)
80 : certificateEnv(certificateEnv), transitionProbabilityMatrix(transitionProbabilityMatrix), totalRewardSpecification(totalRewardSpecification) {}
81
83 if (certificateEnv.getAlgorithm() == AlgorithmType::FpSmoothII || certificateEnv.getAlgorithm() == AlgorithmType::FpRoundII) {
84 // For gamma = 1, the bounds are never updated, so the iteration would not terminate.
85 STORM_LOG_THROW(certificateEnv.getGamma() < 1.0, storm::exceptions::InvalidEnvironmentException,
86 "The parameter gamma for smooth and rounding interval iteration must be smaller than 1.");
87 }
88 return {certificateEnv.getAlgorithm(), storm::utility::convertNumber<ValueType>(certificateEnv.getGamma()),
89 storm::utility::convertNumber<ValueType>(certificateEnv.getDelta())};
90 }
91
92 LowerUpperValueCertificateComputerReturnType<ValueType> compute(bool relative, ValueType const& precision) {
93 auto alg = getAlgorithm();
94 initializeValueVectors(alg);
95 if (!totalRewardSpecification.terminalStates.full()) {
96 if (certificateEnv.isUseTopological()) {
97 computeTopological(alg, relative, precision, ~totalRewardSpecification.terminalStates);
98 } else {
99 computeForSubsystem(alg, relative, precision, ~totalRewardSpecification.terminalStates);
100 }
101 }
102 if (globalUpperValues.empty()) {
103 // Exact methods do not populate the upper values.
104 globalUpperValues = globalLowerValues; // copy lower values
105 }
106 return {std::move(globalLowerValues), std::move(globalUpperValues)};
107 }
108
109 private:
110 template<typename VT, bool SingleValue>
111 struct SubsystemData {
113 storm::storage::BitVector exitChoices;
114 using ValueVectorType = std::conditional_t<SingleValue, std::vector<VT>, std::pair<std::vector<VT>, std::vector<VT>>>;
115 ValueVectorType offsets;
116 ValueVectorType operands;
117 std::optional<std::vector<VT>> exitProbabilities; // for each row the probability to exit the subsystem
118 // if originalToReducedStateMapping is given, this subsystem has been reduced and the ith entry is the index in the reduced system corresponding to
119 // the ith subsystem state
120 std::optional<std::vector<uint64_t>> originalToReducedStateMapping;
121 };
122
123 void initializeValueVectors(Algorithm const& alg) {
124 // Initialize value vector and set values for terminal states.
125 uint64_t const numberOfStates = totalRewardSpecification.terminalStates.size();
126 globalLowerValues.assign(numberOfStates, storm::utility::zero<ValueType>());
127 for (auto const& [value, stateSet] : totalRewardSpecification.terminalStateValues) {
128 if (storm::utility::isFinite(value)) {
129 storm::utility::vector::setVectorValues(globalLowerValues, stateSet, storm::utility::getFinite(value));
130 } else {
131 STORM_LOG_ASSERT(storm::utility::isInfinity(value), "Unexpected terminal state value.");
132 // Infinity is not representable in ValueType (in particular not for rational numbers).
133 // The values of these states are never used in any computation, because choices leading to such states are either cut away or do not exist.
134 // The actual infinite values are set by the caller.
135 }
136 }
137 // We assume that 0 is a valid lower bound for all states.
138 STORM_LOG_THROW(!totalRewardSpecification.actionRewards.has_value() ||
139 std::all_of(totalRewardSpecification.actionRewards->begin(), totalRewardSpecification.actionRewards->end(),
140 [](auto const& v) { return v >= storm::utility::zero<ValueType>(); }),
141 storm::exceptions::NotSupportedException, "Certificates for negative rewards are not supported.");
142
143 // Initialize second vector for upper bounds (if needed by the selected algorithm)
144 if (alg.type == AlgorithmType::FpII || alg.type == AlgorithmType::FpSmoothII || alg.type == AlgorithmType::FpRoundII) {
145 globalUpperValues = globalLowerValues;
146 } else {
147 STORM_LOG_ASSERT(alg.type == AlgorithmType::ExPI, "Unsupported algorithm.");
148 globalUpperValues.clear(); // Do not use upper values for this.
149 }
150 }
151
152 storm::storage::BitVector getSubsystemExitChoices(storm::storage::BitVector const& subsystem, uint64_t numSubystemRows,
153 std::optional<storm::storage::BitVector> const& optionalSubsystemChoices) const {
154 storm::storage::BitVector result(numSubystemRows, false);
155 uint64_t currSubsystemRow = 0;
156 for (auto const state : subsystem) {
157 for (auto const rowIndex : transitionProbabilityMatrix.getRowGroupIndices(state)) {
158 if (optionalSubsystemChoices.has_value() && !optionalSubsystemChoices->get(rowIndex)) {
159 continue;
160 }
161 auto row = transitionProbabilityMatrix.getRow(rowIndex);
162 if (std::any_of(row.begin(), row.end(), [&subsystem](auto const& entry) { return !subsystem.get(entry.getColumn()); })) {
163 result.set(currSubsystemRow);
164 }
165 ++currSubsystemRow;
166 }
167 }
168 return result;
169 }
170
171 template<typename VT>
172 std::vector<VT> getSubsystemOffsets(storm::storage::BitVector const& subsystem, std::optional<storm::storage::BitVector> const& optionalSubsystemChoices,
173 storm::storage::BitVector const& subsystemExitChoices, std::vector<ValueType> const& globalValues) const {
174 std::vector<VT> result;
175 result.reserve(subsystemExitChoices.size());
176 for (auto const state : subsystem) {
177 for (auto const rowIndex : transitionProbabilityMatrix.getRowGroupIndices(state)) {
178 if (optionalSubsystemChoices.has_value() && !optionalSubsystemChoices->get(rowIndex)) {
179 continue;
180 }
181 auto rowValue = totalRewardSpecification.actionRewards.has_value()
182 ? storm::utility::convertNumber<VT>(totalRewardSpecification.actionRewards.value()[rowIndex])
183 : storm::utility::zero<VT>();
184 if (subsystemExitChoices.get(result.size())) {
185 for (auto const& entry : transitionProbabilityMatrix.getRow(rowIndex)) {
186 if (!subsystem.get(entry.getColumn())) {
187 rowValue += storm::utility::convertNumber<VT, ValueType>(entry.getValue() * globalValues[entry.getColumn()]);
188 }
189 }
190 }
191 result.push_back(std::move(rowValue));
192 }
193 }
194 result.shrink_to_fit();
195 STORM_LOG_ASSERT(result.size() == subsystemExitChoices.size(), "Unexpected number of rows in subsystem.");
196 return result;
197 }
198
199 template<typename VT>
200 std::vector<VT> getSubsystemExitProbabilities(storm::storage::BitVector const& subsystem,
201 std::optional<storm::storage::BitVector> const& optionalSubsystemChoices,
202 storm::storage::BitVector const& subsystemExitChoices) const {
203 std::vector<VT> result;
204 result.reserve(subsystemExitChoices.size());
205 for (auto const state : subsystem) {
206 for (auto const rowIndex : transitionProbabilityMatrix.getRowGroupIndices(state)) {
207 if (optionalSubsystemChoices.has_value() && !optionalSubsystemChoices->get(rowIndex)) {
208 continue;
209 }
210 auto rowValue = storm::utility::zero<VT>();
211 if (subsystemExitChoices.get(result.size())) {
212 for (auto const& entry : transitionProbabilityMatrix.getRow(rowIndex)) {
213 if (!subsystem.get(entry.getColumn())) {
214 rowValue += storm::utility::convertNumber<VT, ValueType>(entry.getValue());
215 }
216 }
217 }
218 result.push_back(std::move(rowValue));
219 }
220 }
221 result.shrink_to_fit();
222 STORM_LOG_ASSERT(result.size() == subsystemExitChoices.size(), "Unexpected number of rows in subsystem.");
223 return result;
224 }
225
226 std::optional<storm::storage::BitVector> getSubsystemChoicesIfNonTrivial(storm::storage::BitVector const& subsystem) const {
227 STORM_LOG_ASSERT(totalRewardSpecification.terminalStateValues.size() == 1, "Unexpected number of terminal state values.");
228 STORM_LOG_ASSERT(subsystem.isDisjointFrom(totalRewardSpecification.terminalStates), "subsystem contains terminal state.");
229 auto const& [value, stateSet] = totalRewardSpecification.terminalStateValues.front();
230 STORM_LOG_ASSERT(storm::utility::isFinite(value) || storm::utility::isInfinity(value), "Unexpected terminal state value.");
232 // We have an infinite terminal state value, so we need to cut away all choices leading to those states.
233 return transitionProbabilityMatrix.getRowFilter(subsystem, ~stateSet);
234 }
235 return std::nullopt;
236 }
237
238 template<typename VT>
239 storm::storage::SparseMatrix<VT> getSubsystemMatrix(storm::storage::BitVector const& subsystemStates,
240 std::optional<storm::storage::BitVector> const& subsystemChoices) const {
241 storm::storage::SparseMatrix<ValueType> subMatrix = subsystemChoices.has_value()
242 ? transitionProbabilityMatrix.getSubmatrix(false, *subsystemChoices, subsystemStates)
243 : transitionProbabilityMatrix.getSubmatrix(true, subsystemStates, subsystemStates);
244 // Convert to desired value type
245 if constexpr (std::is_same_v<VT, ValueType>) {
246 return subMatrix;
247 } else {
248 return subMatrix.template toValueType<VT>();
249 }
250 }
251
252 template<typename VT, bool SingleValue>
253 SubsystemData<VT, SingleValue> initializeSubsystemData(storm::storage::BitVector const& subsystem, AlgorithmType const algorithmType) const {
254 auto optionalSubsystemChoices = getSubsystemChoicesIfNonTrivial(subsystem);
255 auto result = SubsystemData<VT, SingleValue>{getSubsystemMatrix<VT>(subsystem, optionalSubsystemChoices), {}, {}, {}, {}, {}};
256 result.exitChoices = getSubsystemExitChoices(subsystem, result.transitions.getRowCount(), optionalSubsystemChoices);
257 if constexpr (SingleValue) {
258 STORM_LOG_ASSERT(globalUpperValues.empty(), "Expected upper values not to be initialized.");
259 result.offsets = getSubsystemOffsets<VT>(subsystem, optionalSubsystemChoices, result.exitChoices, globalLowerValues);
260 } else {
261 STORM_LOG_ASSERT(!globalUpperValues.empty(), "Expected upper values to be initialized.");
262 result.offsets = {getSubsystemOffsets<VT>(subsystem, optionalSubsystemChoices, result.exitChoices, globalLowerValues),
263 getSubsystemOffsets<VT>(subsystem, optionalSubsystemChoices, result.exitChoices, globalUpperValues)};
264 }
265 bool const computeInitialBounds =
266 algorithmType == AlgorithmType::FpII || algorithmType == AlgorithmType::FpSmoothII || algorithmType == AlgorithmType::FpRoundII;
267 if (computeInitialBounds) {
268 result.exitProbabilities = getSubsystemExitProbabilities<VT>(subsystem, optionalSubsystemChoices, result.exitChoices);
269 }
270 if (!totalRewardSpecification.terminalStatesUniversallyAlmostSurelyReached) {
271 result = eliminateECs(std::move(result));
272 }
273 if (computeInitialBounds) {
274 std::optional<storm::OptimizationDirection> constexpr optionalDir =
275 Nondeterministic ? std::optional<storm::OptimizationDirection>(Dir) : std::nullopt;
276 storm::OptionalRef<std::vector<VT>> lowerBounds, upperBounds;
277 if constexpr (SingleValue) {
278 result.operands = computeLowerOrUpperBoundsTotalReward<VT, true>(result.transitions, result.offsets, result.exitChoices,
279 result.exitProbabilities.value(), optionalDir);
280 } else {
281 result.operands.first = computeLowerOrUpperBoundsTotalReward<VT, true>(result.transitions, result.offsets.first, result.exitChoices,
282 result.exitProbabilities.value(), optionalDir);
283 result.operands.second = computeLowerOrUpperBoundsTotalReward<VT, false>(result.transitions, result.offsets.second, result.exitChoices,
284 result.exitProbabilities.value(), optionalDir);
285 }
286 } else {
287 if constexpr (SingleValue) {
288 result.operands = std::vector<VT>(result.transitions.getRowGroupCount(), storm::utility::zero<VT>());
289 } else {
290 result.operands = {std::vector<VT>(result.transitions.getRowGroupCount(), storm::utility::zero<VT>()),
291 std::vector<VT>(result.transitions.getRowGroupCount(), storm::utility::zero<VT>())};
292 }
293 }
294
295 return result;
296 }
297
298 template<typename VT, bool SingleValue>
299 SubsystemData<VT, SingleValue> eliminateECs(SubsystemData<VT, SingleValue>&& original) const {
300 storm::storage::BitVector allStates(original.transitions.getRowGroupCount(), true);
301 auto possibleECChoices = ~original.exitChoices;
302 if (totalRewardSpecification.actionRewards) {
303 // Do not consider choices with rewards
304 auto const candidateChoices = possibleECChoices;
305 for (auto const choice : candidateChoices) {
306 if constexpr (SingleValue) {
307 if (!storm::utility::isZero(original.offsets[choice])) {
308 possibleECChoices.set(choice, false);
309 }
310 } else {
311 STORM_LOG_ASSERT(storm::utility::isZero(original.offsets.first[choice]) == storm::utility::isZero(original.offsets.second[choice]),
312 "Unexpected offsets in non-exiting choice.");
313 if (!storm::utility::isZero(original.offsets.first[choice])) {
314 possibleECChoices.set(choice, false);
315 }
316 }
317 }
318 }
319 storm::storage::MaximalEndComponentDecomposition<VT> ecs(original.transitions, original.transitions.transpose(true), allStates, possibleECChoices);
320 if (ecs.empty()) {
321 // No ECs to eliminate
322 return std::move(original);
323 }
324 auto reductionRes = storm::transformer::EndComponentEliminator<VT>::transform(original.transitions, ecs, allStates, ~allStates, false);
325 SubsystemData<VT, SingleValue> reduced{
326 std::move(reductionRes.matrix), std::move(reductionRes.sinkRows), {}, {}, {}, std::move(reductionRes.oldToNewStateMapping)};
327 if constexpr (SingleValue) {
328 reduced.offsets.reserve(reduced.exitChoices.size());
329 } else {
330 reduced.offsets.first.reserve(reduced.exitChoices.size());
331 reduced.offsets.second.reserve(reduced.exitChoices.size());
332 }
333 if (original.exitProbabilities.has_value()) {
334 reduced.exitProbabilities.emplace();
335 reduced.exitProbabilities->reserve(reduced.exitChoices.size());
336 }
337 for (uint64_t newRow = 0; newRow < reduced.exitChoices.size(); ++newRow) {
338 auto const oldRow = reductionRes.newToOldRowMapping[newRow];
339 if (original.exitProbabilities.has_value()) {
340 // Set exit probability to '1' for all sinkRows, i.e., those that correspond to staying in the EC forever
341 reduced.exitProbabilities->push_back(reduced.exitChoices.get(newRow) ? storm::utility::one<VT>() : original.exitProbabilities->at(oldRow));
342 }
343 if (original.exitChoices.get(oldRow)) {
344 reduced.exitChoices.set(newRow, true);
345 }
346 if constexpr (SingleValue) {
347 reduced.offsets.push_back(original.offsets[oldRow]);
348 } else {
349 reduced.offsets.first.push_back(original.offsets.first[oldRow]);
350 reduced.offsets.second.push_back(original.offsets.second[oldRow]);
351 }
352 }
353 STORM_LOG_ASSERT(std::all_of(reduced.originalToReducedStateMapping->begin(), reduced.originalToReducedStateMapping->end(),
354 [&reduced](auto const& i) { return i < reduced.transitions.getRowGroupCount(); }),
355 "No representative for some state found in the reduced subsystem.");
356 return reduced;
357 }
358
359 template<typename VT>
360 void setGlobalValuesFromSubsystemVector(storm::storage::BitVector const& subsystemStates, std::vector<VT> const& localValues,
361 std::vector<ValueType>& globalValues, std::optional<std::vector<uint64_t>> const& reducedStateMapping,
362 bool invert) {
363 STORM_LOG_ASSERT(subsystemStates.size() == globalValues.size(), "Unexpected number of values.");
364 if (reducedStateMapping) {
365 STORM_LOG_ASSERT(subsystemStates.getNumberOfSetBits() == reducedStateMapping->size(), "Unexpected number of states in unreduced subsystem.");
366 uint64_t unreducedSubsystemState = 0;
367 for (auto globalState : subsystemStates) {
368 auto const reducedSubsystemState = reducedStateMapping->at(unreducedSubsystemState);
369 STORM_LOG_ASSERT(reducedSubsystemState < localValues.size(), "unexpeced index in reduced subsystem.");
370 globalValues[globalState] = storm::utility::convertNumber<ValueType>(localValues[reducedSubsystemState]);
371 if (invert) {
372 globalValues[globalState] = -globalValues[globalState];
373 }
374 ++unreducedSubsystemState;
375 }
376 } else {
377 STORM_LOG_ASSERT(subsystemStates.getNumberOfSetBits() == localValues.size(), "Unexpected number of values in subsystem.");
378 auto localValuesIt = localValues.cbegin();
379 for (auto i : subsystemStates) {
380 globalValues[i] = storm::utility::convertNumber<ValueType>(*localValuesIt);
381 if (invert) {
382 globalValues[i] = -globalValues[i];
383 }
384 ++localValuesIt;
385 }
386 }
387 }
388
389 template<typename VT, bool SingleValue>
390 void setGlobalValuesFromSubsystem(storm::storage::BitVector const& subsystemStates, SubsystemData<VT, SingleValue> const& subsystemData,
391 bool invertLowerValues) {
392 if constexpr (SingleValue) {
393 setGlobalValuesFromSubsystemVector<VT>(subsystemStates, subsystemData.operands, globalLowerValues, subsystemData.originalToReducedStateMapping,
394 invertLowerValues);
395 STORM_LOG_ASSERT(globalUpperValues.empty(), "Expected upper values not to be initialized.");
396 } else {
397 setGlobalValuesFromSubsystemVector<VT>(subsystemStates, subsystemData.operands.first, globalLowerValues,
398 subsystemData.originalToReducedStateMapping, invertLowerValues);
399 setGlobalValuesFromSubsystemVector<VT>(subsystemStates, subsystemData.operands.second, globalUpperValues,
400 subsystemData.originalToReducedStateMapping, false);
401 }
402 }
403
404 void computeForSingleStateSubsystem(uint64_t state) {
405 storm::utility::Extremum<Dir, ValueType> lowerValue, upperValue;
406 bool const computeUpperValues = !globalUpperValues.empty();
407 // If we minimize, choices that lead to states with infinite value can be ignored
408 // (If we maximize, there are no such choices since the optimal value would be infinite as well.)
409 auto const& infinityStates = totalRewardSpecification.terminalStateValues.front().second;
410 bool const ignoreChoicesToInfinity =
411 storm::solver::minimize(Dir) && storm::utility::isInfinity(totalRewardSpecification.terminalStateValues.front().first);
412 for (auto const rowIndex : transitionProbabilityMatrix.getRowGroupIndices(state)) {
413 if (ignoreChoicesToInfinity) {
414 auto const row = transitionProbabilityMatrix.getRow(rowIndex);
415 if (std::any_of(row.begin(), row.end(), [&infinityStates](auto const& entry) { return infinityStates.get(entry.getColumn()); })) {
416 continue;
417 }
418 }
419 auto const reward = totalRewardSpecification.actionRewards.has_value() ? totalRewardSpecification.actionRewards.value()[rowIndex]
421 auto lowerRowValue = reward;
422 auto upperRowValue = reward;
423 std::optional<ValueType> diagonalEntry;
424 for (auto const& entry : transitionProbabilityMatrix.getRow(rowIndex)) {
425 if (state == entry.getColumn()) {
426 STORM_LOG_ASSERT(!diagonalEntry, "Already have diag entry.");
427 diagonalEntry = entry.getValue();
428 } else {
429 lowerRowValue += entry.getValue() * globalLowerValues[entry.getColumn()];
430 if (computeUpperValues) {
431 upperRowValue += entry.getValue() * globalUpperValues[entry.getColumn()];
432 }
433 }
434 }
435 if (diagonalEntry.has_value()) {
436 if (diagonalEntry.value() == storm::utility::one<ValueType>()) {
437 // This choice is a self-loop and can therefore never be optimal
438 continue;
439 }
440 lowerRowValue /= storm::utility::one<ValueType>() - diagonalEntry.value();
441 if (computeUpperValues) {
442 upperRowValue /= storm::utility::one<ValueType>() - diagonalEntry.value();
443 }
444 }
445 lowerValue &= lowerRowValue;
446 if (computeUpperValues) {
447 upperValue &= upperRowValue;
448 }
449 }
450 STORM_LOG_ASSERT(!lowerValue.empty() && !(computeUpperValues && upperValue.empty()),
451 "Failed to compute lower and/or upper value for state " << state << ".");
452 globalLowerValues[state] = *lowerValue;
453 if (computeUpperValues) {
454 globalUpperValues[state] = *upperValue;
455 }
456 }
457
458 void computeForSubsystemFpII(Algorithm const& alg, bool relative, ValueType const& precision, storm::storage::BitVector const& subsystemStates) {
459 using VT = std::conditional_t<storm::NumberTraits<ValueType>::IsExact, double, ValueType>; // VT is imprecise
460 std::optional<storm::OptimizationDirection> constexpr optionalDir = Nondeterministic ? std::optional<storm::OptimizationDirection>(Dir) : std::nullopt;
461 auto subsystemData = initializeSubsystemData<VT, false>(subsystemStates, alg.type);
462 if (alg.type == AlgorithmType::FpRoundII) {
463 auto invertVector = [](auto& vector) {
464 for (auto& value : vector) {
465 value = -value;
466 }
467 };
468 invertVector(subsystemData.operands.first);
469 invertVector(subsystemData.offsets.first);
470 }
471
472 auto viOp = std::make_shared<storm::solver::helper::ValueIterationOperator<VT, !Nondeterministic>>();
473 viOp->setMatrixBackwards(subsystemData.transitions);
474 storm::solver::helper::IntervalIterationHelper<VT, !Nondeterministic> iiHelper(viOp);
475 uint64_t numIterations = 0;
476 if (alg.type == AlgorithmType::FpII) {
477 iiHelper.II(subsystemData.operands, subsystemData.offsets, numIterations, relative, storm::utility::convertNumber<VT>(precision), optionalDir);
478 } else if (alg.type == AlgorithmType::FpRoundII) {
479 ScopedRoundingMode const roundUpwards(FE_UPWARD);
480 iiHelper.roundII(subsystemData.operands, subsystemData.offsets, numIterations, relative, storm::utility::convertNumber<VT>(precision),
481 storm::utility::convertNumber<VT>(alg.gamma), storm::utility::convertNumber<VT>(alg.delta), optionalDir);
482 } else {
483 STORM_LOG_ASSERT(alg.type == AlgorithmType::FpSmoothII, "Unsupported algorithm.");
484 iiHelper.smoothII(subsystemData.operands, subsystemData.offsets, numIterations, relative, storm::utility::convertNumber<VT>(precision),
485 storm::utility::convertNumber<VT>(alg.gamma), storm::utility::convertNumber<VT>(alg.delta), optionalDir);
486 }
487 setGlobalValuesFromSubsystem<VT>(subsystemStates, subsystemData, alg.type == AlgorithmType::FpRoundII);
488 }
489
490 void computeForSubsystemExPI(storm::storage::BitVector const& subsystemStates) {
491 using VT = std::conditional_t<storm::NumberTraits<ValueType>::IsExact, ValueType, storm::RationalNumber>; // VT is exact
492
493 auto subsystemData = initializeSubsystemData<VT, true>(subsystemStates, AlgorithmType::ExPI);
494
495 storm::Environment env;
496 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ViToPi);
497 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Eigen);
498 env.solver().eigen().setMethod(solver::EigenLinearEquationSolverMethod::SparseLU);
499 env.solver().setForceExact(true);
500
501 if constexpr (Nondeterministic) {
502 auto solverFactory = storm::solver::GeneralMinMaxLinearEquationSolverFactory<VT>();
503 auto req = solverFactory.getRequirements(env, true, false, Dir, false, false);
504 std::vector<uint64_t> initSched;
505 if (req.validInitialScheduler()) {
506 storm::storage::SparseMatrix<VT> const& submatrix = subsystemData.transitions;
507 auto exitStates = submatrix.getRowGroupFilter(subsystemData.exitChoices, false);
508 storm::storage::Scheduler<VT> validScheduler(exitStates.size());
509 storm::utility::graph::computeSchedulerProb1E(storm::storage::BitVector(exitStates.size(), true), submatrix, submatrix.transpose(true),
510 ~exitStates, exitStates, validScheduler);
511
512 // Extract the relevant parts of the scheduler for the solver.
513 initSched.reserve(exitStates.size());
514 for (uint64_t i = 0; i < exitStates.size(); ++i) {
515 if (exitStates.get(i)) {
516 initSched.push_back(validScheduler.getChoice(i).getDeterministicChoice());
517 } else {
518 auto const groupStart = submatrix.getRowGroupIndices()[i];
519 auto globalChoice = subsystemData.exitChoices.getNextSetIndex(groupStart);
520 STORM_LOG_ASSERT(globalChoice < submatrix.getRowGroupIndices()[i + 1], "No valid choice for exit state " << i << ".");
521 initSched.push_back(globalChoice - groupStart);
522 }
523 }
524 req.clearValidInitialScheduler();
525 }
526 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UnmetRequirementException,
527 "Unmet requirements for MinMax linear equation solver: " << req.getEnabledRequirementsAsString() << ".");
528 auto solver = solverFactory.create(env, std::move(subsystemData.transitions));
529 solver->setHasUniqueSolution(true); // TODO: Has no end components?
530 if (!initSched.empty()) {
531 solver->setInitialScheduler(std::move(initSched));
532 }
533 solver->setRequirementsChecked(true);
534 solver->solveEquations(env, Dir, subsystemData.operands, subsystemData.offsets);
535 } else {
536 auto solverFactory = storm::solver::GeneralLinearEquationSolverFactory<VT>();
537 if (solverFactory.getEquationProblemFormat(env) == storm::solver::LinearEquationSolverProblemFormat::EquationSystem) {
538 subsystemData.transitions = storm::storage::SparseMatrix<VT>(subsystemData.transitions, true); // insert diag entries
539 subsystemData.transitions.convertToEquationSystem(); // Note: Invalidates uses of this matrix as 'transitions'
540 }
541 auto req = solverFactory.getRequirements(env);
542 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UnmetRequirementException,
543 "Unmet requirements for linear equation solver: " << req.getEnabledRequirementsAsString() << ".");
544 auto solver = solverFactory.create(env, std::move(subsystemData.transitions));
545 solver->solveEquations(env, subsystemData.operands, subsystemData.offsets);
546 }
547 setGlobalValuesFromSubsystem<VT>(subsystemStates, subsystemData, false);
548 }
549
550 void computeForSubsystem(Algorithm const& alg, bool relative, ValueType const& precision, storm::storage::BitVector const& subsystemStates) {
551 switch (alg.type) {
552 case AlgorithmType::FpII:
553 case AlgorithmType::FpSmoothII:
554 case AlgorithmType::FpRoundII:
555 computeForSubsystemFpII(alg, relative, precision, subsystemStates);
556 break;
557 case AlgorithmType::ExPI:
558 computeForSubsystemExPI(subsystemStates);
559 break;
560 default:
561 STORM_LOG_ASSERT(false, "Unsupported algorithm.");
562 }
563 }
564
565 void computeTopological(Algorithm const& alg, bool relative, ValueType const& precision, storm::storage::BitVector const& nonTerminalStates) {
566 STORM_LOG_TRACE("Creating SCC decomposition.");
567 storm::utility::Stopwatch sccSw(true);
568 storm::storage::StronglyConnectedComponentDecomposition<ValueType> const sccDecomposition(
569 transitionProbabilityMatrix,
570 storm::storage::StronglyConnectedComponentDecompositionOptions().forceTopologicalSort().computeSccDepths().subsystem(nonTerminalStates));
571 uint64_t const longestSccChainSize = sccDecomposition.getMaxSccDepth() + 1;
572 sccSw.stop();
573 STORM_LOG_INFO("SCC decomposition computed in "
574 << sccSw << ". Found " << sccDecomposition.size() << " SCC(s) containing a total of " << nonTerminalStates.getNumberOfSetBits()
575 << " states. Average SCC size is "
576 << static_cast<double>(transitionProbabilityMatrix.getRowGroupCount()) / static_cast<double>(sccDecomposition.size())
577 << ". Longest SCC chain size is " << longestSccChainSize << ".");
578 if (sccDecomposition.size() == 1) {
579 // Handle the case where there is just one large scc
580 computeForSubsystem(alg, relative, precision, nonTerminalStates);
581 return;
582 }
583 // At this point, solve each SCC individually
584 storm::storage::BitVector sccAsBitvector(transitionProbabilityMatrix.getRowGroupCount(), false); // allocate memory outside of loop
585 for (uint64_t sccIndex = 0; sccIndex < sccDecomposition.size(); ++sccIndex) {
586 auto const& scc = sccDecomposition.getBlock(sccIndex);
587 if (scc.size() == 1) {
588 // Directly solve single-state SCCs
589 computeForSingleStateSubsystem(*scc.begin());
590 continue;
591 }
592 sccAsBitvector.set(scc.begin(), scc.end());
593 ValueType const sccPrecision =
594 precision / storm::utility::convertNumber<ValueType, uint64_t>(longestSccChainSize - sccDecomposition.getSccDepth(sccIndex));
595 computeForSubsystem(alg, relative, sccPrecision, sccAsBitvector);
596 sccAsBitvector.clear();
597 }
598 }
599
600 storm::CertificateModelCheckerEnvironment const& certificateEnv;
601 storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix;
602 TotalRewardSpecification<ValueType> const& totalRewardSpecification;
603 // lower/upper values for each state. If the computation is exact, upper values are not used and remain empty.
604 std::vector<ValueType> globalLowerValues, globalUpperValues;
605}; // namespace storm::modelchecker
606
607template<storm::OptimizationDirection Dir, typename ValueType, typename VectorValueType>
609 std::vector<VectorValueType> const& valueVector, storm::storage::BitVector const& relevantStates,
610 storm::OptionalRef<std::vector<ValueType> const> rewardVector = {}) {
611 storm::storage::BitVector inductiveChoices(transitionProbabilityMatrix.getRowCount(), false);
612 bool warnIfEmpty = true;
613 for (auto state : relevantStates) {
614 bool stateHasInductiveChoice = false;
615 for (auto choice : transitionProbabilityMatrix.getRowGroupIndices(state)) {
616 VectorValueType const choiceValue = transitionProbabilityMatrix.multiplyRowWithVector(
617 choice, valueVector, rewardVector.has_value() ? rewardVector->at(choice) : storm::utility::zero<ValueType>());
618 if (storm::solver::maximize(Dir) ? valueVector[state] <= choiceValue : choiceValue <= valueVector[state]) {
619 inductiveChoices.set(choice);
620 stateHasInductiveChoice = true;
621 }
622 }
623 if (!stateHasInductiveChoice) {
624 STORM_LOG_WARN_COND(!warnIfEmpty, "State " << state << " has no inductive choice. The certificate might not be valid");
625 warnIfEmpty = false;
626 }
627 }
628 return inductiveChoices;
629}
630
631template<typename ValueType, storm::OptimizationDirection Dir>
632std::vector<RankingType> computeDistanceRanking(storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix,
633 storm::storage::SparseMatrix<ValueType> const& backwardTransitions,
634 storm::storage::BitVector const& targetStates,
636 std::optional<storm::storage::BitVector> const& choiceConstraint = std::nullopt) {
637 auto const& rowGroupIndices = transitionProbabilityMatrix.getRowGroupIndices();
638
639 std::vector<RankingType> ranks(targetStates.size(), InfRank);
641 std::vector<uint64_t> stateQueue(targetStates.begin(), targetStates.end());
642 while (!stateQueue.empty()) {
643 auto const state = stateQueue.back();
644 stateQueue.pop_back();
645 for (auto const& preEntry : backwardTransitions.getRow(state)) {
646 auto const preState = preEntry.getColumn();
647 if (ranks[preState] != InfRank) {
648 continue;
649 }
650 if (constraintStates.has_value() && !constraintStates->get(preState)) {
651 continue;
652 }
654 // Iterate over all (selected) choices of the pre-state
655 uint64_t currentChoice = rowGroupIndices[preState];
656 if (choiceConstraint.has_value()) {
657 currentChoice = choiceConstraint->getNextSetIndex(currentChoice);
658 }
659 auto nextChoice = [&choiceConstraint](auto c) { return choiceConstraint.has_value() ? choiceConstraint->getNextSetIndex(c + 1) : c + 1; };
660 for (auto const endChoice = rowGroupIndices[preState + 1]; currentChoice < endChoice; currentChoice = nextChoice(currentChoice)) {
661 // Compute current rank for this choice
663 for (auto const& entry : transitionProbabilityMatrix.getRow(currentChoice)) {
664 if (storm::utility::isZero(entry.getValue())) {
665 continue;
666 }
667 choiceRank &= ranks[entry.getColumn()];
668 }
669 STORM_LOG_ASSERT(!choiceRank.empty(),
670 "Ranking operator failed to compute rank for state " << state << " since the row " << currentChoice << " is empty.");
671 newRankMinusOne &= *choiceRank;
672 }
673 if (!newRankMinusOne.empty() && *newRankMinusOne != InfRank) {
674 ranks[preState] = *newRankMinusOne + 1;
675 stateQueue.push_back(preState);
676 }
677 }
678 }
679 return ranks;
680}
681
682template<typename ValueType, storm::OptimizationDirection Dir>
683std::vector<RankingType> computeModifiedDistanceRanking(storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix,
684 storm::storage::SparseMatrix<ValueType> const& backwardTransitions,
685 storm::storage::BitVector const& probLess1States) {
686 std::vector<RankingType> ranks(probLess1States.size(), InfRank);
688
689 // Apply the modified ranking operator until no more states are updated
690 while (true) {
691 bool updated = false;
692 for (auto state : probLess1States) {
694 for (auto const currentChoice : transitionProbabilityMatrix.getRowGroupIndices(state)) {
696 bool allSuccessorsEqual = true;
697 for (auto const& entry : transitionProbabilityMatrix.getRow(currentChoice)) {
698 if (storm::utility::isZero(entry.getValue())) {
699 continue;
700 }
701 if (!minSuccessorRank.empty() && ranks[entry.getColumn()] != *minSuccessorRank) {
702 allSuccessorsEqual = false;
703 }
704 minSuccessorRank &= ranks[entry.getColumn()];
705 }
706 STORM_LOG_ASSERT(!minSuccessorRank.empty(),
707 "Ranking operator failed to compute rank for state " << state << " since the row " << currentChoice << " is empty.");
708 auto choiceRank = *minSuccessorRank;
709 if (choiceRank != InfRank && !allSuccessorsEqual) {
710 ++choiceRank;
711 }
712 newStateRank &= choiceRank;
713 }
714 STORM_LOG_ASSERT(!newStateRank.empty(), "Failed to compute rank for state " << state << ".");
715 if (ranks[state] != *newStateRank) {
716 STORM_LOG_ASSERT(ranks[state] <= *newStateRank, "Ranking operator did not generate an increasing sequence for state " << state << ".");
717 ranks[state] = *newStateRank;
718 updated = true;
719 }
720 }
721 if (!updated) {
722 return ranks;
723 }
724 }
725}
726
727template<typename ValueType>
729 std::vector<ValueType> lowerValues, upperValues;
730 std::vector<RankingType> ranks;
731};
732
733template<typename ValueType, bool Nondeterministic, storm::OptimizationDirection Dir = storm::OptimizationDirection::Minimize>
735 storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix,
736 storm::storage::BitVector const& targetStates,
738 std::optional<storm::OptimizationDirection> constexpr optionalDir = Nondeterministic ? std::optional<storm::OptimizationDirection>(Dir) : std::nullopt;
739 storm::storage::BackwardTransitionCache<ValueType> backwardTransitionCache(transitionProbabilityMatrix);
740 auto toRewardData = ReachabilityProbabilityToRewardTransformer<ValueType>(transitionProbabilityMatrix, backwardTransitionCache)
741 .transform(optionalDir, targetStates, constraintStates);
742 STORM_LOG_ASSERT(toRewardData.terminalStateValues.size() == 1 &&
743 toRewardData.terminalStateValues.front().first == storm::utility::ExtendedValueType<ValueType>(storm::utility::one<ValueType>()),
744 "Expected exactly one terminal state value with value 1.");
745 LowerUpperValueCertificateComputer<ValueType, Nondeterministic, Dir> computer(env.modelchecker().certificate(), transitionProbabilityMatrix, toRewardData);
746
747 auto [lowerValues, upperValues] = computer.compute(env.solver().minMax().getRelativeTerminationCriterion(),
749 std::optional<storm::storage::BitVector> inductiveChoices;
750 if (optionalDir.has_value() && optionalDir.value() == storm::OptimizationDirection::Maximize) {
751 auto relevantStates = ~targetStates;
752 if (constraintStates.has_value()) {
753 relevantStates &= *constraintStates;
754 }
755 inductiveChoices = computeInductiveChoices<storm::OptimizationDirection::Maximize, ValueType>(transitionProbabilityMatrix, lowerValues, relevantStates);
756 }
757 auto ranks = computeDistanceRanking<ValueType, storm::solver::invert(Dir)>(transitionProbabilityMatrix, backwardTransitionCache.get(), targetStates,
758 constraintStates, inductiveChoices);
759 return {std::move(lowerValues), std::move(upperValues), std::move(ranks)};
760}
761
762template<typename ValueType>
764 std::optional<storm::OptimizationDirection> dir,
765 storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix,
766 storm::storage::BitVector const& targetStates,
769 if (dir.has_value()) {
770 if (storm::solver::maximize(*dir)) {
772 targetStates, constraintStates);
773 } else {
775 targetStates, constraintStates);
776 }
777 } else {
778 data = computeReachabilityProbabilityCertificateData<ValueType, false>(env, transitionProbabilityMatrix, targetStates, constraintStates);
779 }
780 return data;
781}
782
783template<typename ValueType>
784std::unique_ptr<ReachabilityProbabilityCertificate<ValueType>> computeReachabilityProbabilityCertificate(
785 storm::Environment const& env, std::optional<storm::OptimizationDirection> dir, storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix,
786 storm::storage::BitVector targetStates, std::optional<storm::storage::BitVector> constraintStates, std::string targetLabel,
787 std::optional<std::string> constraintLabel) {
789 std::unique_ptr<ReachabilityProbabilityCertificate<ValueType>> result;
790 if (constraintStates.has_value()) {
791 data = computeReachabilityProbabilityCertificateData<ValueType>(env, dir, transitionProbabilityMatrix, targetStates, constraintStates.value());
792 result = std::make_unique<ReachabilityProbabilityCertificate<ValueType>>(dir, std::move(targetStates), std::move(constraintStates.value()),
793 std::move(targetLabel), constraintLabel.value_or("constraint"));
794 } else {
795 data = computeReachabilityProbabilityCertificateData<ValueType>(env, dir, transitionProbabilityMatrix, targetStates, storm::NullRef);
796 result = std::make_unique<ReachabilityProbabilityCertificate<ValueType>>(dir, std::move(targetStates), std::move(targetLabel));
797 }
798 result->setLowerBoundsCertificate(std::move(data.lowerValues), std::move(data.ranks));
799 result->setUpperBoundsCertificate(std::move(data.upperValues));
800 return result;
801}
802
803template<typename ValueType>
805 std::vector<storm::utility::ExtendedValueType<ValueType>> lowerValues, upperValues;
806 std::vector<RankingType> lowerRanks, upperRanks;
807};
808
809template<typename ValueType, bool Nondeterministic, storm::OptimizationDirection Dir = storm::OptimizationDirection::Minimize>
811 storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix,
812 storm::storage::BitVector const& targetStates,
813 std::vector<ValueType> const& stateActionRewardVector) {
814 std::optional<storm::OptimizationDirection> constexpr optionalDir = Nondeterministic ? std::optional<storm::OptimizationDirection>(Dir) : std::nullopt;
815 storm::storage::BackwardTransitionCache<ValueType> backwardTransitionCache(transitionProbabilityMatrix);
816 auto toRewardData = ReachabilityRewardTransformer<ValueType>(transitionProbabilityMatrix, backwardTransitionCache)
817 .transform(optionalDir, targetStates, stateActionRewardVector);
818 STORM_LOG_ASSERT(toRewardData.terminalStateValues.size() == 1 && storm::utility::isInfinity(toRewardData.terminalStateValues.front().first),
819 "Expected exactly one terminal state value with value +infinity.");
820 auto const& infinityStates = toRewardData.terminalStateValues.front().second;
821 LowerUpperValueCertificateComputer<ValueType, Nondeterministic, Dir> computer(env.modelchecker().certificate(), transitionProbabilityMatrix, toRewardData);
822
823 std::vector<storm::utility::ExtendedValueType<ValueType>> extendedLowerValues, extendedUpperValues;
824 {
825 auto [lowerValues, upperValues] = computer.compute(env.solver().minMax().getRelativeTerminationCriterion(),
827 extendedLowerValues.reserve(lowerValues.size());
828 extendedUpperValues.reserve(upperValues.size());
829 for (uint64_t i = 0; i < lowerValues.size(); ++i) {
830 if (infinityStates.get(i)) {
831 extendedLowerValues.push_back(storm::utility::positiveInfinity<ValueType>());
832 extendedUpperValues.push_back(storm::utility::positiveInfinity<ValueType>());
833 } else {
834 extendedLowerValues.emplace_back(std::move(lowerValues[i]));
835 extendedUpperValues.emplace_back(std::move(upperValues[i]));
836 }
837 }
838 }
839
840 std::optional<storm::storage::BitVector> inductiveChoices;
841 if (optionalDir.has_value() && optionalDir.value() == storm::OptimizationDirection::Minimize) {
842 inductiveChoices = computeInductiveChoices<storm::OptimizationDirection::Minimize, ValueType>(transitionProbabilityMatrix, extendedUpperValues,
843 ~targetStates, stateActionRewardVector);
844 }
845 auto upperRanks =
846 computeDistanceRanking<ValueType, Dir>(transitionProbabilityMatrix, backwardTransitionCache.get(), targetStates, storm::NullRef, inductiveChoices);
847 // The lower bound ranks consider all choices (not only the inductive ones), see Proposition 7 of https://doi.org/10.1007/978-3-031-90653-4_7.
848 auto lowerRanks =
849 computeModifiedDistanceRanking<ValueType, storm::solver::invert(Dir)>(transitionProbabilityMatrix, backwardTransitionCache.get(), infinityStates);
850
851 return {std::move(extendedLowerValues), std::move(extendedUpperValues), std::move(lowerRanks), std::move(upperRanks)};
852}
853
854template<typename ValueType>
855std::unique_ptr<ReachabilityRewardCertificate<ValueType>> computeReachabilityRewardCertificate(
856 storm::Environment const& env, std::optional<storm::OptimizationDirection> dir, storm::storage::SparseMatrix<ValueType> const& transitionProbabilityMatrix,
857 storm::storage::BitVector targetStates, std::vector<ValueType> stateActionRewardVector, std::string targetLabel, std::string rewardModelName) {
859 if (dir.has_value()) {
860 if (storm::solver::maximize(*dir)) {
862 targetStates, stateActionRewardVector);
863 } else {
865 targetStates, stateActionRewardVector);
866 }
867 } else {
868 data = computeReachabilityRewardCertificateData<ValueType, false>(env, transitionProbabilityMatrix, targetStates, stateActionRewardVector);
869 }
870 auto result = std::make_unique<ReachabilityRewardCertificate<ValueType>>(dir, std::move(targetStates), std::move(stateActionRewardVector),
871 std::move(targetLabel), std::move(rewardModelName));
872 result->setLowerBoundsCertificate(std::move(data.lowerValues), std::move(data.lowerRanks));
873 result->setUpperBoundsCertificate(std::move(data.upperValues), std::move(data.upperRanks));
874 return result;
875}
876
877template std::unique_ptr<ReachabilityProbabilityCertificate<double>> computeReachabilityProbabilityCertificate<double>(
878 storm::Environment const& env, std::optional<storm::OptimizationDirection> dir, storm::storage::SparseMatrix<double> const& transitionProbabilityMatrix,
879 storm::storage::BitVector targetStates, std::optional<storm::storage::BitVector> constraintStates, std::string targetLabel,
880 std::optional<std::string> constraintLabel);
881template std::unique_ptr<ReachabilityProbabilityCertificate<storm::RationalNumber>> computeReachabilityProbabilityCertificate<storm::RationalNumber>(
882 storm::Environment const& env, std::optional<storm::OptimizationDirection> dir,
883 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionProbabilityMatrix, storm::storage::BitVector targetStates,
884 std::optional<storm::storage::BitVector> constraintStates, std::string targetLabel, std::optional<std::string> constraintLabel);
885
886template std::unique_ptr<ReachabilityRewardCertificate<double>> computeReachabilityRewardCertificate<double>(
887 storm::Environment const& env, std::optional<storm::OptimizationDirection> dir, storm::storage::SparseMatrix<double> const& transitionProbabilityMatrix,
888 storm::storage::BitVector targetStates, std::vector<double> stateActionRewardVector, std::string targetLabel, std::string rewardModelName);
889
890template std::unique_ptr<ReachabilityRewardCertificate<storm::RationalNumber>> computeReachabilityRewardCertificate<storm::RationalNumber>(
891 storm::Environment const& env, std::optional<storm::OptimizationDirection> dir,
892 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionProbabilityMatrix, storm::storage::BitVector targetStates,
893 std::vector<storm::RationalNumber> stateActionRewardVector, std::string targetLabel, std::string rewardModelName);
894
895} // namespace storm::modelchecker
Options for the computation of certificates for reachability probabilities and expected rewards.
void setMethod(storm::solver::EigenLinearEquationSolverMethod value, bool isSetFromDefault=false)
SolverEnvironment & solver()
ModelCheckerEnvironment & modelchecker()
storm::RationalNumber const & getPrecision() const
void setMethod(storm::solver::MinMaxMethod value, bool isSetFromDefault=false)
bool const & getRelativeTerminationCriterion() const
CertificateModelCheckerEnvironment & certificate()
Helper class that optionally holds a reference to an object of type T.
Definition OptionalRef.h:48
bool has_value() const
Yields true iff this contains a reference.
void setLinearEquationSolverType(storm::solver::EquationSolverType const &value, bool isSetFromDefault=false)
EigenSolverEnvironment & eigen()
MinMaxSolverEnvironment & minMax()
LowerUpperValueCertificateComputerReturnType< ValueType > compute(bool relative, ValueType const &precision)
LowerUpperValueCertificateComputer(storm::CertificateModelCheckerEnvironment const &certificateEnv, storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, TotalRewardSpecification< ValueType > const &totalRewardSpecification)
TotalRewardSpecification< ValueType > transform(StateSet const &targetStates, storm::OptionalRef< StateSet const > constraintStates=storm::NullRef)
TotalRewardSpecification< ValueType > transform(StateSet const &targetStates, std::vector< ValueType > const &actionRewards)
This class caches the backward transitions of a given forward transition matrix.
SparseMatrix< ValueType > const & get() const
Retrieves the backward transitions.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
bool isDisjointFrom(BitVector const &other) const
Checks whether none of the bits that are set in the current bit vector are also set in the given bit ...
const_iterator end() const
Returns an iterator pointing at the element past the back of the bit vector.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
const_iterator begin() const
Returns an iterator to the indices of the set bits in the 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.
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.
ValueType multiplyRowWithVector(index_type row, std::vector< ValueType > const &vector, ValueType offset=storm::utility::zero< ValueType >()) const
Multiplies a single row of the matrix with the given vector and adds the given offset to the result.
storm::storage::BitVector getRowGroupFilter(storm::storage::BitVector const &rowConstraint, bool setIfForAllRowsInGroup) const
Returns the indices of all row groups selected by the row constraints.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
storm::storage::SparseMatrix< value_type > transpose(bool joinGroups=false, bool keepZeros=false) const
Transposes the matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
static EndComponentEliminatorReturnType transform(storm::storage::SparseMatrix< ValueType > const &originalMatrix, storm::storage::MaximalEndComponentDecomposition< ValueType > ecs, storm::storage::BitVector const &subsystemStates, storm::storage::BitVector const &addSinkRowStates, bool addSelfLoopAtSinkStates=false)
Stores and manages an extremal (maximal or minimal) value.
Definition Extremum.h:17
#define STORM_LOG_INFO(message)
Definition logging.h:34
#define STORM_LOG_TRACE(message)
Definition logging.h:22
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:54
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
SFTBDDChecker::ValueType ValueType
std::vector< ValueType > computeLowerOrUpperBoundsTotalReward(storm::storage::SparseMatrix< ValueType > const &matrix, std::vector< ValueType > const &offsets, storm::storage::BitVector const &exitRows, std::vector< ValueType > const &exitProbabilities, std::optional< storm::OptimizationDirection > dir)
Computes for each state a lower (if Lower is true) or an upper (otherwise) bound on the optimal total...
ProbabilityCertificateData< ValueType > computeReachabilityProbabilityCertificateData(storm::Environment const &env, storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, storm::storage::BitVector const &targetStates, storm::OptionalRef< storm::storage::BitVector const > constraintStates)
std::unique_ptr< ReachabilityRewardCertificate< ValueType > > computeReachabilityRewardCertificate(storm::Environment const &env, std::optional< storm::OptimizationDirection > dir, storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, storm::storage::BitVector targetStates, std::vector< ValueType > stateActionRewardVector, std::string targetLabel, std::string rewardModelName)
Computes a certificate for expected rewards accumulated until reaching the target states.
static RankingType const InfRank
Definition RankingType.h:8
storm::storage::BitVector computeInductiveChoices(storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, std::vector< VectorValueType > const &valueVector, storm::storage::BitVector const &relevantStates, storm::OptionalRef< std::vector< ValueType > const > rewardVector={})
std::vector< RankingType > computeDistanceRanking(storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, storm::storage::SparseMatrix< ValueType > const &backwardTransitions, storm::storage::BitVector const &targetStates, storm::OptionalRef< storm::storage::BitVector const > constraintStates, std::optional< storm::storage::BitVector > const &choiceConstraint=std::nullopt)
std::vector< RankingType > computeModifiedDistanceRanking(storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, storm::storage::SparseMatrix< ValueType > const &backwardTransitions, storm::storage::BitVector const &probLess1States)
std::unique_ptr< ReachabilityProbabilityCertificate< ValueType > > computeReachabilityProbabilityCertificate(storm::Environment const &env, std::optional< storm::OptimizationDirection > dir, storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, storm::storage::BitVector targetStates, std::optional< storm::storage::BitVector > constraintStates, std::string targetLabel, std::optional< std::string > constraintLabel)
Computes a certificate for reachability probabilities (or constrained reachability probabilities if c...
RewardCertificateData< ValueType > computeReachabilityRewardCertificateData(storm::Environment const &env, storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, storm::storage::BitVector const &targetStates, std::vector< ValueType > const &stateActionRewardVector)
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
void computeSchedulerProb1E(storm::storage::BitVector const &prob1EStates, storm::storage::SparseMatrix< T > const &transitionMatrix, storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates, storm::storage::Scheduler< SchedulerValueType > &scheduler, boost::optional< storm::storage::BitVector > const &rowFilter)
Computes a scheduler for the given prob1EStates such that in the induced system the given psiStates a...
Definition graph.cpp:609
void setVectorValues(std::vector< T > &vector, storm::storage::BitVector const &positions, std::vector< S > const &values)
Sets the provided values at the provided positions in the given vector.
Definition vector.h:79
ExtendedValueType< ValueType > positiveInfinity()
Extremum< storm::OptimizationDirection::Minimize, ValueType > Minimum
Definition Extremum.h:168
bool isFinite(ExtendedNumber< ValueType > const &value)
bool isZero(ValueType const &a)
Definition constants.cpp:44
ValueType zero()
Definition constants.cpp:26
std::conditional_t< storm::NumberTraits< ValueType >::HasInfinity, ValueType, ExtendedNumber< ValueType > > ExtendedValueType
The type to use for values that may be infinite.
ValueType one()
Definition constants.cpp:21
bool isInfinity(ValueType const &a)
ValueType const & getFinite(ExtendedNumber< ValueType > const &value)
TargetType convertNumber(SourceType const &number)
CertificateAlgorithm
The algorithms that can be used to compute the values underlying a certificate.
OptionalRef(T &) -> OptionalRef< T >
deduction guides
constexpr NullRefType NullRef
Definition OptionalRef.h:31
std::vector< storm::utility::ExtendedValueType< ValueType > > lowerValues
std::vector< storm::utility::ExtendedValueType< ValueType > > upperValues
Specifies a total reward query: The goal is to compute (bounds on) the optimal total reward that is c...