2#include <carl/core/FactorizedPolynomial.h>
3#include <carl/core/MultivariatePolynomial.h>
4#include <carl/core/RationalFunction.h>
5#include <carl/core/Variable.h>
6#include <carl/core/VariablePool.h>
7#include <carl/core/polynomialfunctions/Factorization.h>
8#include <carl/core/rootfinder/RootFinder.h>
20#include <unordered_map>
43namespace transformer {
48 auto multivariatePol = carl::MultivariatePolynomial<RationalFunctionCoefficient>(uniPoly);
54 if (lhs.degree() != rhs.degree()) {
55 return lhs.degree() < rhs.degree();
58 for (uint64_t i = 0; i < lhs.coefficients().size(); i++) {
59 if (lhs.coefficients()[i] != rhs.coefficients()[i]) {
60 return lhs.coefficients()[i] < rhs.coefficients()[i];
68 auto& container = (*this)[p];
70 auto it = container.first.find(f);
71 if (it != container.first.end()) {
76 uint64_t newIndex = container.second.size();
77 container.first[f] = newIndex;
78 container.second.push_back(f);
85 auto key = std::make_pair(factorization, p);
86 if (localCache.count(key)) {
87 return localCache.at(key);
90 polynomial = polynomial.one();
91 for (uint64_t i = 0; i < factorization.size(); i++) {
92 for (uint64_t j = 0; j < factorization[i]; j++) {
93 polynomial *= this->at(p).second[i];
96 localCache.emplace(key, polynomial);
101 : parameter(parameter), polynomialCache(polynomialCache) {
106 STORM_LOG_ASSERT(other.parameter == this->parameter,
"Can only add annotations with equal parameters.");
107 for (
auto const& [factors, number] : other) {
108 if (this->count(factors)) {
109 this->at(factors) += number;
111 this->emplace(factors, number);
117 for (
auto& [factors, number] : *
this) {
125 return annotationCopy;
129 for (
auto const& [info, constant] : other) {
130 if (!this->count(info)) {
131 this->emplace(info, utility::zero<RationalFunctionCoefficient>());
133 this->at(info) += constant * timesConstant;
138 for (
auto const& [info, constant] : other) {
140 auto newCounter = info;
143 auto const cacheNum = this->polynomialCache->lookUpInCache(polynomial, parameter);
144 while (newCounter.size() <= cacheNum) {
145 newCounter.push_back(0);
147 newCounter[cacheNum]++;
149 if (!this->count(newCounter)) {
150 this->emplace(newCounter, constant);
152 this->at(newCounter) += constant;
158 for (
auto const& [info1, constant1] : anno1) {
159 for (
auto const& [info2, constant2] : anno2) {
160 std::vector<uint64_t> newCounter(std::max(info1.size(), info2.size()), 0);
162 for (uint64_t i = 0; i < newCounter.size(); i++) {
163 if (i < info1.size()) {
164 newCounter[i] += info1[i];
166 if (i < info2.size()) {
167 newCounter[i] += info2[i];
171 if (!this->count(newCounter)) {
172 this->emplace(newCounter, constant1 * constant2);
174 this->at(newCounter) += constant1 * constant2;
182 for (
auto const& [info, constant] : *
this) {
183 prob += polynomialCache->polynomialFromFactorization(info, parameter) * constant;
189 std::vector<UniPoly> terms;
190 for (
auto const& [info, constant] : *
this) {
191 terms.push_back(polynomialCache->polynomialFromFactorization(info, parameter) * constant);
197 if (!derivativeOfThis) {
198 return evaluate<Interval>(input);
200 Interval boundDerivative = derivativeOfThis->evaluateOnIntervalMidpointTheorem(input, higherOrderBounds);
202 double fMid = evaluate<double>(input.center());
203 double fMin = fMid - (input.diameter() / 2) * maxSlope;
204 double fMax = fMid + (input.diameter() / 2) * maxSlope;
205 if (higherOrderBounds) {
206 Interval boundsHere = evaluate<Interval>(input);
219 if (nth == 0 || derivativeOfThis) {
222 derivativeOfThis = std::make_shared<Annotation>(this->parameter, this->polynomialCache);
223 for (
auto const& [info, constant] : *
this) {
225 for (uint64_t i = 0; i < info.size(); i++) {
230 RationalFunctionCoefficient newConstant = constant * utility::convertNumber<RationalFunctionCoefficient>(info[i]);
232 std::vector<uint64_t> insert(info);
235 while (!insert.empty() && insert.back() == 0) {
239 auto polynomial = polynomialCache->at(parameter).second.at(i);
244 uint64_t derivativeIndex = this->polynomialCache->lookUpInCache(
derivative, parameter);
245 while (insert.size() < derivativeIndex) {
248 insert[derivativeIndex]++;
250 if (derivativeOfThis->count(insert)) {
251 derivativeOfThis->at(insert) += newConstant;
253 derivativeOfThis->emplace(insert, newConstant);
257 derivativeOfThis->computeDerivative(nth - 1);
262 for (
auto const& [info, constant] : *
this) {
272 return derivativeOfThis;
276std::ostream& operator<<(std::ostream& os,
const Annotation& annotation) {
277 auto iterator = annotation.begin();
278 while (iterator != annotation.end()) {
279 auto const& factors = iterator->first;
280 auto const& constant = iterator->second;
281 os << constant <<
" * (";
282 bool alreadyPrintedFactor =
false;
283 for (uint64_t i = 0; i < factors.size(); i++) {
284 if (factors[i] > 0) {
285 if (alreadyPrintedFactor) {
288 alreadyPrintedFactor =
true;
290 os <<
"(" << annotation.polynomialCache->at(annotation.parameter).second[i] <<
")" <<
"^" << factors[i];
293 if (factors.empty()) {
298 if (iterator != annotation.end()) {
305std::pair<std::map<uint64_t, std::set<uint64_t>>, std::set<uint64_t>>
findSubgraph(
308 const boost::optional<std::vector<RationalFunction>>& stateRewardVector,
const RationalFunctionVariable parameter) {
309 std::map<uint64_t, std::set<uint64_t>> subgraph;
310 std::set<uint64_t> bottomStates;
312 std::set<uint64_t> acyclicStates;
314 std::vector<uint64_t> dfsStack = {root};
315 while (!dfsStack.empty()) {
316 uint64_t state = dfsStack.back();
318 if (!subgraph.count(state)) {
319 subgraph[state] = {};
321 std::vector<uint64_t> tmpStack;
322 bool isAcyclic =
true;
325 for (
auto const& entry : transitionMatrix.
getRow(state)) {
327 if (subgraph.count(entry.getColumn()) && !acyclicStates.count(entry.getColumn()) && !bottomStates.count(entry.getColumn())) {
336 bottomStates.emplace(state);
340 for (
auto const& entry : transitionMatrix.
getRow(state)) {
343 (entry.getValue().gatherVariables().size() == 1 && *entry.getValue().gatherVariables().begin() == parameter),
344 "Called findSubgraph with incorrect parameter.");
346 subgraph.at(state).emplace(entry.getColumn());
348 if (!subgraph.count(entry.getColumn())) {
349 bool continueSearching = treeStates.at(parameter).count(entry.getColumn()) && !treeStates.at(parameter).at(entry.getColumn()).empty();
351 if (!entry.getValue().isConstant()) {
354 continueSearching &= entry.getValue().gatherVariables().size() == 1 && *entry.getValue().gatherVariables().begin() == parameter;
359 bool onlyHasOne = transitionMatrix.
getRow(entry.getColumn()).size() == 1 &&
360 transitionMatrix.
getRow(entry.getColumn()).begin()->getValue() == utility::one<RationalFunction>();
361 continueSearching |= onlyHasOne;
364 continueSearching &= !(stateRewardVector && !stateRewardVector->at(entry.getColumn()).isZero());
366 if (continueSearching) {
369 tmpStack.push_back(entry.getColumn());
372 subgraph[entry.getColumn()] = {};
373 bottomStates.emplace(entry.getColumn());
375 acyclicStates.emplace(entry.getColumn());
381 for (
auto const& entry : tmpStack) {
382 dfsStack.push_back(entry);
386 acyclicStates.emplace(state);
390 return std::make_pair(subgraph, bottomStates);
393std::pair<models::sparse::Dtmc<RationalFunction>, std::map<UniPoly, Annotation>>
BigStep::bigStep(
406 std::set<std::string> labelsInFormula;
407 for (
auto const& atomicLabelFormula : checkTask.
getFormula().getAtomicLabelFormulas()) {
408 labelsInFormula.emplace(atomicLabelFormula->getLabel());
413 for (
auto const& label : labelsInFormula) {
418 boost::optional<std::vector<RationalFunction>> stateRewardVector;
419 boost::optional<std::string> stateRewardName;
420 if (checkTask.
getFormula().isRewardOperatorFormula()) {
427 stateRewardVector = dtmc.
getRewardModel(
"").getStateRewardVector();
432 auto topologicalOrdering = utility::graph::getTopologicalSort<RationalFunction>(transitionMatrix, {initialState});
439 std::map<RationalFunctionVariable, std::map<uint64_t, std::set<uint64_t>>> treeStates;
441 std::map<RationalFunctionVariable, std::set<uint64_t>> treeStatesNeedUpdate;
444 for (uint64_t row = 0; row < flexibleMatrix.getRowCount(); row++) {
445 for (
auto const& entry : flexibleMatrix.getRow(row)) {
446 if (!entry.getValue().isConstant()) {
447 if (!this->rawPolynomialCache) {
449 this->rawPolynomialCache = entry.getValue().nominator().pCache();
451 for (
auto const& parameter : entry.getValue().gatherVariables()) {
452 treeStatesNeedUpdate[parameter].emplace(row);
453 treeStates[parameter][row].emplace(row);
458 updateTreeStates(treeStates, treeStatesNeedUpdate, flexibleMatrix, backwardsTransitions, allParameters, stateRewardVector, runningLabelingTreeStates);
462 std::map<RationalFunctionVariable, std::set<std::set<uint64_t>>> alreadyTimeTravelledToThis;
465 std::stack<uint64_t> topologicalOrderingStack;
466 topologicalOrdering = utility::graph::getTopologicalSort<RationalFunction>(transitionMatrix, {initialState});
467 for (
auto rit = topologicalOrdering.begin(); rit != topologicalOrdering.end(); ++rit) {
468 topologicalOrderingStack.push(*rit);
475 initialStates.
set(initialState,
true);
481 std::map<UniPoly, Annotation> storedAnnotations;
483 std::map<RationalFunctionVariable, std::set<uint64_t>> bottomStatesSeen;
486 uint64_t writeDtmcCounter = 0;
489 while (!topologicalOrderingStack.empty()) {
490 auto state = topologicalOrderingStack.top();
491 topologicalOrderingStack.pop();
493 if (!reachableStates.
get(state)) {
497 std::set<RationalFunctionVariable> parametersInState;
498 for (
auto const& entry : flexibleMatrix.getRow(state)) {
499 for (
auto const& parameter : entry.getValue().gatherVariables()) {
500 parametersInState.emplace(parameter);
504 std::set<RationalFunctionVariable> bigStepParameters;
505 for (
auto const& parameter : allParameters) {
506 if (treeStates[parameter].count(state)) {
508 if (treeStates.at(parameter).at(state).size() > 1) {
509 bigStepParameters.emplace(parameter);
513 if (parametersInState.count(parameter)) {
514 for (
auto const& treeState : treeStates[parameter][state]) {
515 for (
auto const& successor : flexibleMatrix.getRow(treeState)) {
516 if (treeStates[parameter].count(successor.getColumn())) {
517 bigStepParameters.emplace(parameter);
528 for (
auto const& parameter : bigStepParameters) {
530 auto const [bottomAnnotations, visitedStatesAndSubtree] =
531 bigStepBFS(state, parameter, flexibleMatrix, backwardsTransitions, treeStates, stateRewardVector, storedAnnotations);
532 auto const [visitedStates, subtree] = visitedStatesAndSubtree;
537 bool existsEliminableState =
false;
538 for (
auto const& s : visitedStates) {
539 bool allPredecessorsInVisitedStates =
true;
540 for (
auto const& predecessor : backwardsTransitions.getRow(s)) {
541 if (predecessor.getValue().isZero()) {
544 if (!reachableStates.
get(predecessor.getColumn())) {
549 if (!subtree.count(predecessor.getColumn()) || !subtree.at(predecessor.getColumn()).count(s)) {
550 allPredecessorsInVisitedStates =
false;
554 if (allPredecessorsInVisitedStates) {
555 existsEliminableState =
true;
560 if (!existsEliminableState) {
568 uint64_t oldMatrixSize = flexibleMatrix.getRowCount();
570 std::vector<std::pair<uint64_t, Annotation>> transitions = findBigStep(bottomAnnotations, parameter, flexibleMatrix, backwardsTransitions,
571 alreadyTimeTravelledToThis, treeStatesNeedUpdate, state, originalNumStates);
574 auto newStoredAnnotations =
575 replaceWithNewTransitions(state, transitions, flexibleMatrix, backwardsTransitions, reachableStates, treeStatesNeedUpdate);
576 for (
auto const& entry : newStoredAnnotations) {
577 storedAnnotations.emplace(entry);
581 updateUnreachableStates(reachableStates, visitedStates, backwardsTransitions, initialState);
583 uint64_t newMatrixSize = flexibleMatrix.getRowCount();
584 if (newMatrixSize > oldMatrixSize) {
586 runningLabeling = extendStateLabeling(runningLabeling, oldMatrixSize, newMatrixSize, state, labelsInFormula);
587 runningLabelingTreeStates = extendStateLabeling(runningLabelingTreeStates, oldMatrixSize, newMatrixSize, state, labelsInFormula);
590 reachableStates.
resize(newMatrixSize,
true);
592 for (uint64_t i = oldMatrixSize; i < newMatrixSize; i++) {
593 topologicalOrderingStack.push(i);
594 for (
auto& [_parameter, updateStates] : treeStatesNeedUpdate) {
595 updateStates.emplace(i);
598 if (stateRewardVector) {
599 stateRewardVector->push_back(storm::utility::zero<RationalFunction>());
602 updateTreeStates(treeStates, treeStatesNeedUpdate, flexibleMatrix, backwardsTransitions, allParameters, stateRewardVector,
603 runningLabelingTreeStates);
614 if (stateRewardVector) {
619 storm::io::openFile(
"dots/travel_" + std::to_string(flexibleMatrix.getRowCount()) +
".dot", file2);
626 transitionMatrix = flexibleMatrix.createSparseMatrix();
633 initialStates.
set(initialState,
true);
636 transitionMatrix = transitionMatrix.
getSubmatrix(
false, reachableStates, reachableStates);
637 runningLabeling = runningLabeling.
getSubLabeling(reachableStates);
638 uint_fast64_t newInitialState = 0;
639 for (uint_fast64_t i = 0; i < initialState; i++) {
640 if (reachableStates.
get(i)) {
644 initialState = newInitialState;
645 if (stateRewardVector) {
646 std::vector<RationalFunction> newStateRewardVector;
647 for (uint_fast64_t i = 0; i < stateRewardVector->size(); i++) {
648 if (reachableStates.
get(i)) {
649 newStateRewardVector.push_back(stateRewardVector->at(i));
654 stateRewardVector = newStateRewardVector;
661 newInitialStates.
set(initialState,
true);
664 if (stateRewardVector) {
672 for (
auto const& entry : storedAnnotations) {
676 return std::make_pair(newDTMC, storedAnnotations);
679std::pair<std::map<uint64_t, Annotation>, std::pair<std::vector<uint64_t>, std::map<uint64_t, std::set<uint64_t>>>> BigStep::bigStepBFS(
683 const boost::optional<std::vector<RationalFunction>>& stateRewardVector,
const std::map<UniPoly, Annotation>& storedAnnotations) {
685 auto const [subtree, bottomStates] =
findSubgraph(flexibleMatrix, start, treeStates, stateRewardVector, parameter);
688 std::vector<uint64_t> visitedStatesInBFSOrder;
690 std::set<std::pair<uint64_t, uint64_t>> visitedEdges;
693 std::map<uint64_t, Annotation> annotations;
696 std::queue<uint64_t> activeStates;
697 activeStates.push(start);
699 annotations.emplace(start,
Annotation(parameter, polynomialCache));
701 annotations.at(start)[std::vector<uint64_t>()] = utility::one<RationalFunctionCoefficient>();
703 while (!activeStates.empty()) {
704 auto const& state = activeStates.front();
706 visitedStatesInBFSOrder.push_back(state);
707 for (
auto const& entry : flexibleMatrix.getRow(state)) {
708 auto const goToState = entry.getColumn();
709 if (!subtree.count(goToState) || !subtree.at(state).count(goToState)) {
712 visitedEdges.emplace(std::make_pair(state, goToState));
714 bool allBackwardsStatesVisited =
true;
715 for (
auto const& backwardsEntry : backwardsFlexibleMatrix.getRow(goToState)) {
716 if (!subtree.count(backwardsEntry.getColumn()) || !subtree.at(backwardsEntry.getColumn()).count(goToState)) {
722 if (!visitedEdges.count(std::make_pair(backwardsEntry.getColumn(), goToState))) {
723 allBackwardsStatesVisited =
false;
727 if (!allBackwardsStatesVisited) {
732 annotations.emplace(goToState, std::move(Annotation(parameter, polynomialCache)));
735 for (
auto const& backwardsEntry : backwardsFlexibleMatrix.getRow(goToState)) {
736 if (!subtree.count(backwardsEntry.getColumn()) || !subtree.at(backwardsEntry.getColumn()).count(goToState)) {
742 auto const transition = backwardsEntry.getValue();
747 auto& targetAnnotation = annotations.at(goToState);
753 if (transition.isConstant()) {
755 targetAnnotation.addAnnotationTimesConstant(annotations.at(backwardsEntry.getColumn()), transition.constantPart());
759 STORM_LOG_ERROR_COND(transition.denominator().isConstant(),
"Only transitions with constant denominator supported but this has "
760 << transition.denominator() <<
" in transition " << transition);
761 auto nominator = transition.nominator();
762 UniPoly nominatorAsUnivariate = transition.nominator().toUnivariatePolynomial();
764 nominatorAsUnivariate /= transition.denominator().coefficient();
765 if (storedAnnotations.count(nominatorAsUnivariate)) {
766 targetAnnotation.addAnnotationTimesAnnotation(annotations.at(backwardsEntry.getColumn()), storedAnnotations.at(nominatorAsUnivariate));
768 targetAnnotation.addAnnotationTimesPolynomial(annotations.at(backwardsEntry.getColumn()), std::move(nominatorAsUnivariate));
773 bool allForwardEdgesVisited =
true;
774 for (
auto const& entry : flexibleMatrix.getRow(backwardsEntry.getColumn())) {
775 if (!subtree.at(backwardsEntry.getColumn()).count(entry.getColumn())) {
781 if (!annotations.count(entry.getColumn())) {
782 allForwardEdgesVisited =
false;
786 if (allForwardEdgesVisited) {
787 annotations.erase(backwardsEntry.getColumn());
790 activeStates.push(goToState);
794 for (
auto const& [state, _successors] : subtree) {
799 if (!bottomStates.count(state)) {
800 annotations.erase(state);
803 return std::make_pair(annotations, std::make_pair(visitedStatesInBFSOrder, subtree));
806std::vector<std::pair<uint64_t, Annotation>> BigStep::findBigStep(
const std::map<uint64_t, Annotation> bigStepAnnotations,
808 storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
809 storage::FlexibleSparseMatrix<RationalFunction>& backwardsFlexibleMatrix,
812 uint64_t originalNumStates) {
813 STORM_LOG_INFO(
"Find time travelling called with root " << root <<
" and parameter " << parameter);
814 bool doneBigStep =
false;
817 std::map<std::vector<uint64_t>, std::map<uint64_t, RationalFunctionCoefficient>> parametricTransitions;
819 for (
auto const& [state, annotation] : bigStepAnnotations) {
820 for (
auto const& [info, constant] : annotation) {
821 if (!parametricTransitions.count(info)) {
822 parametricTransitions[info] = std::map<uint64_t, RationalFunctionCoefficient>();
824 STORM_LOG_ASSERT(!parametricTransitions.at(info).count(state),
"State already exists");
825 parametricTransitions.at(info)[state] = constant;
830 std::vector<std::pair<uint64_t, Annotation>> insertTransitions;
833 std::unordered_set<uint64_t> affectedStates;
846 std::set<std::set<uint64_t>> targetSetStates;
848 for (
auto const& [factors, transitions] : parametricTransitions) {
849 if (transitions.size() > 1) {
853 std::set<uint64_t> targetStates;
856 for (
auto const& [state, info] : transitions) {
857 affectedStates.emplace(state);
858 if (state < originalNumStates) {
859 targetStates.emplace(state);
863 if (alreadyTimeTravelledToThis[parameter].
count(targetStates)) {
864 for (
auto const& [state, probability] : transitions) {
865 Annotation newAnnotation(parameter, polynomialCache);
866 newAnnotation[factors] = probability;
868 insertTransitions.emplace_back(state, newAnnotation);
872 targetSetStates.emplace(targetStates);
874 Annotation newAnnotation(parameter, polynomialCache);
876 RationalFunctionCoefficient constantPart = utility::zero<RationalFunctionCoefficient>();
877 for (
auto const& [state, transition] : transitions) {
878 constantPart += transition;
880 newAnnotation[factors] = constantPart;
882 STORM_LOG_INFO(
"Time travellable transitions with " << newAnnotation);
887 uint64_t newRow = flexibleMatrix.insertNewRowsAtEnd(1);
888 uint64_t newRowBackwards = backwardsFlexibleMatrix.insertNewRowsAtEnd(1);
889 STORM_LOG_ASSERT(newRow == newRowBackwards,
"Internal error: Drifting matrix and backwardsTransitions.");
892 insertTransitions.emplace_back(newRow, newAnnotation);
895 for (
auto const& [state, thisProb] : transitions) {
898 flexibleMatrix.getRow(newRow).push_back(storage::MatrixEntry<uint_fast64_t, RationalFunction>(state, probAsFunction));
900 backwardsFlexibleMatrix.getRow(state).push_back(storage::MatrixEntry<uint_fast64_t, RationalFunction>(newRow, probAsFunction));
902 for (
auto& entry : treeStatesNeedUpdate) {
903 entry.second.emplace(state);
907 backwardsFlexibleMatrix.getRow(state) = joinDuplicateTransitions(backwardsFlexibleMatrix.getRow(state));
910 flexibleMatrix.getRow(newRow) = joinDuplicateTransitions(flexibleMatrix.getRow(newRow));
912 auto const [state, probability] = *transitions.begin();
914 Annotation newAnnotation(parameter, polynomialCache);
915 newAnnotation[factors] = probability;
917 insertTransitions.emplace_back(state, newAnnotation);
922 for (
auto const& targetSet : targetSetStates) {
923 alreadyTimeTravelledToThis[parameter].emplace(targetSet);
926 return insertTransitions;
929std::map<UniPoly, Annotation> BigStep::replaceWithNewTransitions(uint64_t state,
const std::vector<std::pair<uint64_t, Annotation>> transitions,
930 storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
931 storage::FlexibleSparseMatrix<RationalFunction>& backwardsFlexibleMatrix,
932 storage::BitVector& reachableStates,
934 std::map<UniPoly, Annotation> storedAnnotations;
938 for (
auto const& deletingTransition : flexibleMatrix.getRow(state)) {
939 auto& row = backwardsFlexibleMatrix.getRow(deletingTransition.getColumn());
940 auto it = row.begin();
941 while (it != row.end()) {
942 if (it->getColumn() == state) {
950 flexibleMatrix.getRow(state) = std::vector<storage::MatrixEntry<uint_fast64_t, RationalFunction>>();
954 std::map<uint64_t, Annotation> insertThese;
955 for (
auto const& [target, probability] : transitions) {
956 for (
auto& entry : treeStatesNeedUpdate) {
957 entry.second.emplace(target);
959 if (insertThese.count(target)) {
960 insertThese.at(target) += probability;
962 insertThese.emplace(target, probability);
965 for (
auto const& [state2, annotation] : insertThese) {
966 auto uniProbability = annotation.getProbability();
967 storedAnnotations.emplace(uniProbability, std::move(annotation));
975 return storedAnnotations;
978void BigStep::updateUnreachableStates(storage::BitVector& reachableStates, std::vector<uint64_t>
const& statesMaybeUnreachable,
979 storage::FlexibleSparseMatrix<RationalFunction>
const& backwardsFlexibleMatrix, uint64_t initialState) {
980 if (backwardsFlexibleMatrix.getRowCount() > reachableStates.size()) {
981 reachableStates.resize(backwardsFlexibleMatrix.getRowCount(),
true);
985 for (
auto const& visitedState : statesMaybeUnreachable) {
986 if (visitedState == initialState) {
989 bool isUnreachable =
true;
990 for (
auto const& entry : backwardsFlexibleMatrix.getRow(visitedState)) {
991 if (reachableStates.get(entry.getColumn())) {
992 isUnreachable =
false;
997 reachableStates.set(visitedState,
false);
1002std::vector<storm::storage::MatrixEntry<uint64_t, RationalFunction>> BigStep::joinDuplicateTransitions(
1004 std::vector<uint64_t> keyOrder;
1005 std::map<uint64_t, storm::storage::MatrixEntry<uint64_t, RationalFunction>> existingEntries;
1006 for (
auto const& entry : entries) {
1007 if (existingEntries.count(entry.getColumn())) {
1008 existingEntries.at(entry.getColumn()).setValue(existingEntries.at(entry.getColumn()).getValue() + entry.getValue());
1010 existingEntries[entry.getColumn()] = entry;
1011 keyOrder.push_back(entry.getColumn());
1014 std::vector<storm::storage::MatrixEntry<uint64_t, RationalFunction>> newEntries;
1015 for (uint64_t key : keyOrder) {
1016 newEntries.push_back(existingEntries.at(key));
1021models::sparse::StateLabeling BigStep::extendStateLabeling(models::sparse::StateLabeling
const& oldLabeling, uint64_t oldSize, uint64_t newSize,
1022 uint64_t stateWithLabels,
const std::set<std::string>& labelsInFormula) {
1023 models::sparse::StateLabeling newLabels(newSize);
1024 for (
auto const& label : oldLabeling.getLabels()) {
1025 newLabels.addLabel(label);
1027 for (uint64_t state = 0; state < oldSize; state++) {
1028 for (
auto const& label : oldLabeling.getLabelsOfState(state)) {
1029 newLabels.addLabelToState(label, state);
1032 for (uint64_t i = oldSize;
i < newSize;
i++) {
1034 for (
auto const& label : oldLabeling.getLabelsOfState(stateWithLabels)) {
1035 if (labelsInFormula.count(label)) {
1036 newLabels.addLabelToState(label, i);
1043void BigStep::updateTreeStates(std::map<
RationalFunctionVariable, std::map<uint64_t, std::set<uint64_t>>>& treeStates,
1045 const storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
1046 const storage::FlexibleSparseMatrix<RationalFunction>& backwardsTransitions,
1047 const std::set<RationalFunctionVariable>& allParameters,
const boost::optional<std::vector<RationalFunction>>& stateRewardVector,
1048 const models::sparse::StateLabeling stateLabeling) {
1049 for (
auto const& parameter : allParameters) {
1050 std::set<uint64_t>& workingSet = workingSets[parameter];
1051 while (!workingSet.empty()) {
1052 std::set<uint64_t> newWorkingSet;
1053 for (uint64_t row : workingSet) {
1054 if (stateRewardVector && !stateRewardVector->at(row).isZero()) {
1057 for (
auto const& entry : backwardsTransitions.getRow(row)) {
1058 if (entry.getValue().isConstant()) {
1061 bool isSubset =
true;
1062 for (
auto const& state : treeStates.at(parameter)[row]) {
1063 if (!treeStates.at(parameter)[entry.getColumn()].count(state)) {
1071 for (
auto const& state : treeStates.at(parameter).at(row)) {
1072 treeStates.at(parameter).at(entry.getColumn()).emplace(state);
1074 if (stateLabeling.getLabelsOfState(entry.getColumn()) == stateLabeling.getLabelsOfState(row)) {
1075 newWorkingSet.emplace(entry.getColumn());
1080 workingSet = newWorkingSet;
bool isRewardModelSet() const
Retrieves whether a reward model was set.
std::string const & getRewardModel() const
Retrieves the reward model over which to perform the checking (if set).
FormulaType const & getFormula() const
Retrieves the formula from this task.
virtual void writeDotToStream(std::ostream &outStream, size_t maxWidthLabel=30, bool includeLabeling=true, storm::storage::BitVector const *subsystem=nullptr, std::vector< ValueType > const *firstValue=nullptr, std::vector< ValueType > const *secondValue=nullptr, std::vector< uint_fast64_t > const *stateColoring=nullptr, std::vector< std::string > const *colors=nullptr, std::vector< uint_fast64_t > *scheduler=nullptr, bool finalizeOutput=true) const override
This class represents a discrete-time Markov chain.
virtual void reduceToStateBasedRewards() override
Converts the transition rewards of all reward models to state-based rewards.
void removeLabel(std::string const &label)
Removes a label from the labelings.
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
void setInitialStates(storm::storage::BitVector const &states)
Overwrites the initial states of the model.
void addRewardModel(std::string const &rewardModelName, RewardModelType const &rewModel)
Adds a reward model to the model.
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
virtual std::string const & getUniqueRewardModelName() const override
Retrieves the name of the unique reward model, if there exists exactly one.
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
This class manages the labeling of the state space with a number of (atomic) labels.
StateLabeling getSubLabeling(storm::storage::BitVector const &states) const
Retrieves the sub labeling that represents the same labeling as the current one for all selected stat...
A bit vector that is internally represented as a vector of 64-bit values.
uint64_t getNextSetIndex(uint64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to true in the bit vector.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
void resize(uint64_t newLength, bool init=false)
Resizes the bit vector to hold the given new number of bits.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
The flexible sparse matrix is used during state elimination.
row_type & getRow(index_type)
Returns an object representing the given row.
A class that holds a possibly non-square matrix in the compressed row storage format.
bool isProbabilistic() const
Checks for each row whether it sums to one.
SparseMatrix getSubmatrix(bool useGroups, storm::storage::BitVector const &rowConstraint, storm::storage::BitVector const &columnConstraint, bool insertDiagonalEntries=false, storm::storage::BitVector const &makeZeroColumns=storm::storage::BitVector()) const
Creates a submatrix of the current matrix by dropping all rows and columns whose bits are not set to ...
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.
#define STORM_LOG_INFO(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_ERROR_COND(cond, message)
void closeFile(std::ofstream &stream)
Close the given file after writing.
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
std::set< storm::RationalFunctionVariable > getAllParameters(Model< storm::RationalFunction > const &model)
Get all parameters (probability, rewards, and rates) occurring in the model.
std::pair< storm::RationalNumber, storm::RationalNumber > count(std::vector< storm::storage::BitVector > const &origSets, std::vector< storm::storage::BitVector > const &intersects, std::vector< storm::storage::BitVector > const &intersectsInfo, storm::RationalNumber val, bool plus, uint64_t remdepth)
storm::storage::BitVector getReachableStates(storm::storage::SparseMatrix< T > const &transitionMatrix, storm::storage::BitVector const &initialStates, storm::storage::BitVector const &constraintStates, storm::storage::BitVector const &targetStates, bool useStepBound, uint_fast64_t maximalSteps, boost::optional< storm::storage::BitVector > const &choiceFilter)
Performs a forward depth-first search through the underlying graph structure to identify the states t...
ValueType max(ValueType const &first, ValueType const &second)
ValueType min(ValueType const &first, ValueType const &second)
bool isZero(ValueType const &a)
ValueType abs(ValueType const &number)
carl::Interval< double > Interval
Interval type.
carl::Variable RationalFunctionVariable
carl::RationalFunction< Polynomial, true > RationalFunction