12#include <unordered_map>
31namespace transformer {
36 auto multivariatePol = carl::MultivariatePolynomial<RationalFunctionCoefficient>(uniPoly);
42 if (lhs.degree() != rhs.degree()) {
43 return lhs.degree() < rhs.degree();
46 for (uint64_t i = 0; i < lhs.coefficients().size(); i++) {
47 if (lhs.coefficients()[i] != rhs.coefficients()[i]) {
48 return lhs.coefficients()[i] < rhs.coefficients()[i];
56 auto& container = (*this)[p];
58 auto it = container.first.find(f);
59 if (it != container.first.end()) {
64 uint64_t newIndex = container.second.size();
65 container.first[f] = newIndex;
66 container.second.push_back(f);
73 auto key = std::make_pair(factorization, p);
74 if (localCache.count(key)) {
75 return localCache.at(key);
78 polynomial = polynomial.one();
79 for (uint64_t i = 0; i < factorization.size(); i++) {
80 for (uint64_t j = 0; j < factorization[i]; j++) {
81 polynomial *= this->at(p).second[i];
84 localCache.emplace(key, polynomial);
89 : parameter(parameter), polynomialCache(polynomialCache) {
94 STORM_LOG_ASSERT(other.parameter == this->parameter,
"Can only add annotations with equal parameters.");
95 for (
auto const& [factors, number] : other) {
96 if (this->count(factors)) {
97 this->at(factors) += number;
99 this->emplace(factors, number);
105 for (
auto& [factors, number] : *
this) {
113 return annotationCopy;
117 for (
auto const& [info, constant] : other) {
118 if (!this->count(info)) {
119 this->emplace(info, utility::zero<RationalFunctionCoefficient>());
121 this->at(info) += constant * timesConstant;
126 for (
auto const& [info, constant] : other) {
128 auto newCounter = info;
131 auto const cacheNum = this->polynomialCache->lookUpInCache(polynomial, parameter);
132 while (newCounter.size() <= cacheNum) {
133 newCounter.push_back(0);
135 newCounter[cacheNum]++;
137 if (!this->count(newCounter)) {
138 this->emplace(newCounter, constant);
140 this->at(newCounter) += constant;
146 for (
auto const& [info1, constant1] : anno1) {
147 for (
auto const& [info2, constant2] : anno2) {
148 std::vector<uint64_t> newCounter(std::max(info1.size(), info2.size()), 0);
150 for (uint64_t i = 0; i < newCounter.size(); i++) {
151 if (i < info1.size()) {
152 newCounter[i] += info1[i];
154 if (i < info2.size()) {
155 newCounter[i] += info2[i];
159 if (!this->count(newCounter)) {
160 this->emplace(newCounter, constant1 * constant2);
162 this->at(newCounter) += constant1 * constant2;
170 for (
auto const& [info, constant] : *
this) {
171 prob += polynomialCache->polynomialFromFactorization(info, parameter) * constant;
177 std::vector<UniPoly> terms;
178 for (
auto const& [info, constant] : *
this) {
179 terms.push_back(polynomialCache->polynomialFromFactorization(info, parameter) * constant);
185 if (!derivativeOfThis) {
186 return evaluate<Interval>(input);
188 Interval boundDerivative = derivativeOfThis->evaluateOnIntervalMidpointTheorem(input, higherOrderBounds);
190 double fMid = evaluate<double>(input.center());
191 double fMin = fMid - (input.diameter() / 2) * maxSlope;
192 double fMax = fMid + (input.diameter() / 2) * maxSlope;
193 if (higherOrderBounds) {
194 Interval boundsHere = evaluate<Interval>(input);
207 if (nth == 0 || derivativeOfThis) {
210 derivativeOfThis = std::make_shared<Annotation>(this->parameter, this->polynomialCache);
211 for (
auto const& [info, constant] : *
this) {
213 for (uint64_t i = 0; i < info.size(); i++) {
218 RationalFunctionCoefficient newConstant = constant * utility::convertNumber<RationalFunctionCoefficient>(info[i]);
220 std::vector<uint64_t> insert(info);
223 while (!insert.empty() && insert.back() == 0) {
227 auto polynomial = polynomialCache->at(parameter).second.at(i);
232 uint64_t derivativeIndex = this->polynomialCache->lookUpInCache(
derivative, parameter);
233 while (insert.size() < derivativeIndex) {
236 insert[derivativeIndex]++;
238 if (derivativeOfThis->count(insert)) {
239 derivativeOfThis->at(insert) += newConstant;
241 derivativeOfThis->emplace(insert, newConstant);
245 derivativeOfThis->computeDerivative(nth - 1);
250 for (
auto const& [info, constant] : *
this) {
260 return derivativeOfThis;
264std::ostream& operator<<(std::ostream& os,
const Annotation& annotation) {
265 auto iterator = annotation.begin();
266 while (iterator != annotation.end()) {
267 auto const& factors = iterator->first;
268 auto const& constant = iterator->second;
269 os << constant <<
" * (";
270 bool alreadyPrintedFactor =
false;
271 for (uint64_t i = 0; i < factors.size(); i++) {
272 if (factors[i] > 0) {
273 if (alreadyPrintedFactor) {
276 alreadyPrintedFactor =
true;
278 os <<
"(" << annotation.polynomialCache->at(annotation.parameter).second[i] <<
")" <<
"^" << factors[i];
281 if (factors.empty()) {
286 if (iterator != annotation.end()) {
293std::pair<std::map<uint64_t, std::set<uint64_t>>, std::set<uint64_t>>
findSubgraph(
296 const boost::optional<std::vector<RationalFunction>>& stateRewardVector,
const RationalFunctionVariable parameter) {
297 std::map<uint64_t, std::set<uint64_t>> subgraph;
298 std::set<uint64_t> bottomStates;
300 std::set<uint64_t> acyclicStates;
302 std::vector<uint64_t> dfsStack = {root};
303 while (!dfsStack.empty()) {
304 uint64_t state = dfsStack.back();
306 if (!subgraph.count(state)) {
307 subgraph[state] = {};
309 std::vector<uint64_t> tmpStack;
310 bool isAcyclic =
true;
313 for (
auto const& entry : transitionMatrix.
getRow(state)) {
315 if (subgraph.count(entry.getColumn()) && !acyclicStates.count(entry.getColumn()) && !bottomStates.count(entry.getColumn())) {
324 bottomStates.emplace(state);
328 for (
auto const& entry : transitionMatrix.
getRow(state)) {
331 (entry.getValue().gatherVariables().size() == 1 && *entry.getValue().gatherVariables().begin() == parameter),
332 "Called findSubgraph with incorrect parameter.");
334 subgraph.at(state).emplace(entry.getColumn());
336 if (!subgraph.count(entry.getColumn())) {
337 bool continueSearching = treeStates.at(parameter).count(entry.getColumn()) && !treeStates.at(parameter).at(entry.getColumn()).empty();
339 if (!entry.getValue().isConstant()) {
342 continueSearching &= entry.getValue().gatherVariables().size() == 1 && *entry.getValue().gatherVariables().begin() == parameter;
347 bool onlyHasOne = transitionMatrix.
getRow(entry.getColumn()).size() == 1 &&
348 transitionMatrix.
getRow(entry.getColumn()).begin()->getValue() == utility::one<RationalFunction>();
349 continueSearching |= onlyHasOne;
352 continueSearching &= !(stateRewardVector && !stateRewardVector->at(entry.getColumn()).isZero());
354 if (continueSearching) {
357 tmpStack.push_back(entry.getColumn());
360 subgraph[entry.getColumn()] = {};
361 bottomStates.emplace(entry.getColumn());
363 acyclicStates.emplace(entry.getColumn());
369 for (
auto const& entry : tmpStack) {
370 dfsStack.push_back(entry);
374 acyclicStates.emplace(state);
378 return std::make_pair(subgraph, bottomStates);
381std::pair<models::sparse::Dtmc<RationalFunction>, std::map<UniPoly, Annotation>>
BigStep::bigStep(
394 std::set<std::string> labelsInFormula;
395 for (
auto const& atomicLabelFormula : checkTask.
getFormula().getAtomicLabelFormulas()) {
396 labelsInFormula.emplace(atomicLabelFormula->getLabel());
401 for (
auto const& label : labelsInFormula) {
406 boost::optional<std::vector<RationalFunction>> stateRewardVector;
407 boost::optional<std::string> stateRewardName;
408 if (checkTask.
getFormula().isRewardOperatorFormula()) {
415 stateRewardVector = dtmc.
getRewardModel(
"").getStateRewardVector();
420 auto topologicalOrdering = utility::graph::getTopologicalSort<RationalFunction>(transitionMatrix, {initialState});
427 std::map<RationalFunctionVariable, std::map<uint64_t, std::set<uint64_t>>> treeStates;
429 std::map<RationalFunctionVariable, std::set<uint64_t>> treeStatesNeedUpdate;
432 for (uint64_t row = 0; row < flexibleMatrix.getRowCount(); row++) {
433 for (
auto const& entry : flexibleMatrix.getRow(row)) {
434 if (!entry.getValue().isConstant()) {
435 if (!this->rawPolynomialCache) {
437 this->rawPolynomialCache = entry.getValue().nominator().pCache();
439 for (
auto const& parameter : entry.getValue().gatherVariables()) {
440 treeStatesNeedUpdate[parameter].emplace(row);
441 treeStates[parameter][row].emplace(row);
446 updateTreeStates(treeStates, treeStatesNeedUpdate, flexibleMatrix, backwardsTransitions, allParameters, stateRewardVector, runningLabelingTreeStates);
450 std::map<RationalFunctionVariable, std::set<std::set<uint64_t>>> alreadyTimeTravelledToThis;
453 std::stack<uint64_t> topologicalOrderingStack;
454 topologicalOrdering = utility::graph::getTopologicalSort<RationalFunction>(transitionMatrix, {initialState});
455 for (
auto rit = topologicalOrdering.begin(); rit != topologicalOrdering.end(); ++rit) {
456 topologicalOrderingStack.push(*rit);
463 initialStates.
set(initialState,
true);
469 std::map<UniPoly, Annotation> storedAnnotations;
471 std::map<RationalFunctionVariable, std::set<uint64_t>> bottomStatesSeen;
474 uint64_t writeDtmcCounter = 0;
477 while (!topologicalOrderingStack.empty()) {
478 auto state = topologicalOrderingStack.top();
479 topologicalOrderingStack.pop();
481 if (!reachableStates.
get(state)) {
485 std::set<RationalFunctionVariable> parametersInState;
486 for (
auto const& entry : flexibleMatrix.getRow(state)) {
487 for (
auto const& parameter : entry.getValue().gatherVariables()) {
488 parametersInState.emplace(parameter);
492 std::set<RationalFunctionVariable> bigStepParameters;
493 for (
auto const& parameter : allParameters) {
494 if (treeStates[parameter].count(state)) {
496 if (treeStates.at(parameter).at(state).size() > 1) {
497 bigStepParameters.emplace(parameter);
501 if (parametersInState.count(parameter)) {
502 for (
auto const& treeState : treeStates[parameter][state]) {
503 for (
auto const& successor : flexibleMatrix.getRow(treeState)) {
504 if (treeStates[parameter].count(successor.getColumn())) {
505 bigStepParameters.emplace(parameter);
516 for (
auto const& parameter : bigStepParameters) {
518 auto const [bottomAnnotations, visitedStatesAndSubtree] =
519 bigStepBFS(state, parameter, flexibleMatrix, backwardsTransitions, treeStates, stateRewardVector, storedAnnotations);
520 auto const [visitedStates, subtree] = visitedStatesAndSubtree;
525 bool existsEliminableState =
false;
526 for (
auto const& s : visitedStates) {
527 bool allPredecessorsInVisitedStates =
true;
528 for (
auto const& predecessor : backwardsTransitions.getRow(s)) {
529 if (predecessor.getValue().isZero()) {
532 if (!reachableStates.
get(predecessor.getColumn())) {
537 if (!subtree.count(predecessor.getColumn()) || !subtree.at(predecessor.getColumn()).count(s)) {
538 allPredecessorsInVisitedStates =
false;
542 if (allPredecessorsInVisitedStates) {
543 existsEliminableState =
true;
548 if (!existsEliminableState) {
556 uint64_t oldMatrixSize = flexibleMatrix.getRowCount();
558 std::vector<std::pair<uint64_t, Annotation>> transitions = findBigStep(bottomAnnotations, parameter, flexibleMatrix, backwardsTransitions,
559 alreadyTimeTravelledToThis, treeStatesNeedUpdate, state, originalNumStates);
562 auto newStoredAnnotations =
563 replaceWithNewTransitions(state, transitions, flexibleMatrix, backwardsTransitions, reachableStates, treeStatesNeedUpdate);
564 for (
auto const& entry : newStoredAnnotations) {
565 storedAnnotations.emplace(entry);
569 updateUnreachableStates(reachableStates, visitedStates, backwardsTransitions, initialState);
571 uint64_t newMatrixSize = flexibleMatrix.getRowCount();
572 if (newMatrixSize > oldMatrixSize) {
574 runningLabeling = extendStateLabeling(runningLabeling, oldMatrixSize, newMatrixSize, state, labelsInFormula);
575 runningLabelingTreeStates = extendStateLabeling(runningLabelingTreeStates, oldMatrixSize, newMatrixSize, state, labelsInFormula);
578 reachableStates.
resize(newMatrixSize,
true);
580 for (uint64_t i = oldMatrixSize; i < newMatrixSize; i++) {
581 topologicalOrderingStack.push(i);
582 for (
auto& [_parameter, updateStates] : treeStatesNeedUpdate) {
583 updateStates.emplace(i);
586 if (stateRewardVector) {
587 stateRewardVector->push_back(storm::utility::zero<RationalFunction>());
590 updateTreeStates(treeStates, treeStatesNeedUpdate, flexibleMatrix, backwardsTransitions, allParameters, stateRewardVector,
591 runningLabelingTreeStates);
600 if (stateRewardVector) {
605 storm::io::openFile(
"dots/travel_" + std::to_string(flexibleMatrix.getRowCount()) +
".dot", file2);
611 transitionMatrix = flexibleMatrix.createSparseMatrix();
618 initialStates.
set(initialState,
true);
621 transitionMatrix = transitionMatrix.
getSubmatrix(
false, reachableStates, reachableStates);
622 runningLabeling = runningLabeling.
getSubLabeling(reachableStates);
623 uint_fast64_t newInitialState = 0;
624 for (uint_fast64_t i = 0; i < initialState; i++) {
625 if (reachableStates.
get(i)) {
629 initialState = newInitialState;
630 if (stateRewardVector) {
631 std::vector<RationalFunction> newStateRewardVector;
632 for (uint_fast64_t i = 0; i < stateRewardVector->size(); i++) {
633 if (reachableStates.
get(i)) {
634 newStateRewardVector.push_back(stateRewardVector->at(i));
639 stateRewardVector = newStateRewardVector;
646 newInitialStates.
set(initialState,
true);
649 if (stateRewardVector) {
655 "Internal error: resulting matrix not probabilistic!");
658 for (
auto const& entry : storedAnnotations) {
662 return std::make_pair(newDTMC, storedAnnotations);
665std::pair<std::map<uint64_t, Annotation>, std::pair<std::vector<uint64_t>, std::map<uint64_t, std::set<uint64_t>>>> BigStep::bigStepBFS(
669 const boost::optional<std::vector<RationalFunction>>& stateRewardVector,
const std::map<UniPoly, Annotation>& storedAnnotations) {
671 auto const [subtree, bottomStates] =
findSubgraph(flexibleMatrix, start, treeStates, stateRewardVector, parameter);
674 std::vector<uint64_t> visitedStatesInBFSOrder;
676 std::set<std::pair<uint64_t, uint64_t>> visitedEdges;
679 std::map<uint64_t, Annotation> annotations;
682 std::queue<uint64_t> activeStates;
683 activeStates.push(start);
685 annotations.emplace(start,
Annotation(parameter, polynomialCache));
687 annotations.at(start)[std::vector<uint64_t>()] = utility::one<RationalFunctionCoefficient>();
689 while (!activeStates.empty()) {
690 auto state = activeStates.front();
692 visitedStatesInBFSOrder.push_back(state);
693 for (
auto const& entry : flexibleMatrix.getRow(state)) {
694 auto const goToState = entry.getColumn();
695 if (!subtree.count(goToState) || !subtree.at(state).count(goToState)) {
698 visitedEdges.emplace(std::make_pair(state, goToState));
700 bool allBackwardsStatesVisited =
true;
701 for (
auto const& backwardsEntry : backwardsFlexibleMatrix.getRow(goToState)) {
702 if (!subtree.count(backwardsEntry.getColumn()) || !subtree.at(backwardsEntry.getColumn()).count(goToState)) {
708 if (!visitedEdges.count(std::make_pair(backwardsEntry.getColumn(), goToState))) {
709 allBackwardsStatesVisited =
false;
713 if (!allBackwardsStatesVisited) {
718 annotations.emplace(goToState, Annotation(parameter, polynomialCache));
721 for (
auto const& backwardsEntry : backwardsFlexibleMatrix.getRow(goToState)) {
722 if (!subtree.count(backwardsEntry.getColumn()) || !subtree.at(backwardsEntry.getColumn()).count(goToState)) {
728 auto const transition = backwardsEntry.getValue();
733 auto& targetAnnotation = annotations.at(goToState);
739 if (transition.isConstant()) {
741 targetAnnotation.addAnnotationTimesConstant(annotations.at(backwardsEntry.getColumn()), transition.constantPart());
745 STORM_LOG_ERROR_COND(transition.denominator().isConstant(),
"Only transitions with constant denominator supported but this has "
746 << transition.denominator() <<
" in transition " << transition);
747 auto nominator = transition.nominator();
748 UniPoly nominatorAsUnivariate = transition.nominator().toUnivariatePolynomial();
750 nominatorAsUnivariate /= transition.denominator().coefficient();
751 if (storedAnnotations.count(nominatorAsUnivariate)) {
752 targetAnnotation.addAnnotationTimesAnnotation(annotations.at(backwardsEntry.getColumn()), storedAnnotations.at(nominatorAsUnivariate));
754 targetAnnotation.addAnnotationTimesPolynomial(annotations.at(backwardsEntry.getColumn()), std::move(nominatorAsUnivariate));
759 bool allForwardEdgesVisited =
true;
760 for (
auto const& entry : flexibleMatrix.getRow(backwardsEntry.getColumn())) {
761 if (!subtree.at(backwardsEntry.getColumn()).count(entry.getColumn())) {
767 if (!annotations.count(entry.getColumn())) {
768 allForwardEdgesVisited =
false;
772 if (allForwardEdgesVisited) {
773 annotations.erase(backwardsEntry.getColumn());
776 activeStates.push(goToState);
780 for (
auto const& [state, _successors] : subtree) {
785 if (!bottomStates.count(state)) {
786 annotations.erase(state);
789 return std::make_pair(annotations, std::make_pair(visitedStatesInBFSOrder, subtree));
792std::vector<std::pair<uint64_t, Annotation>> BigStep::findBigStep(
const std::map<uint64_t, Annotation> bigStepAnnotations,
794 storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
795 storage::FlexibleSparseMatrix<RationalFunction>& backwardsFlexibleMatrix,
798 uint64_t originalNumStates) {
799 STORM_LOG_INFO(
"Find time travelling called with root " << root <<
" and parameter " << parameter);
802 std::map<std::vector<uint64_t>, std::map<uint64_t, RationalFunctionCoefficient>> parametricTransitions;
804 for (
auto const& [state, annotation] : bigStepAnnotations) {
805 for (
auto const& [info, constant] : annotation) {
806 if (!parametricTransitions.count(info)) {
807 parametricTransitions[info] = std::map<uint64_t, RationalFunctionCoefficient>();
809 STORM_LOG_ASSERT(!parametricTransitions.at(info).count(state),
"State already exists");
810 parametricTransitions.at(info)[state] = constant;
815 std::vector<std::pair<uint64_t, Annotation>> insertTransitions;
818 std::unordered_set<uint64_t> affectedStates;
831 std::set<std::set<uint64_t>> targetSetStates;
833 for (
auto const& [factors, transitions] : parametricTransitions) {
834 if (transitions.size() > 1) {
838 std::set<uint64_t> targetStates;
841 for (
auto const& [state, info] : transitions) {
842 affectedStates.emplace(state);
843 if (state < originalNumStates) {
844 targetStates.emplace(state);
848 if (alreadyTimeTravelledToThis[parameter].
count(targetStates)) {
849 for (
auto const& [state, probability] : transitions) {
850 Annotation newAnnotation(parameter, polynomialCache);
851 newAnnotation[factors] = probability;
853 insertTransitions.emplace_back(state, newAnnotation);
857 targetSetStates.emplace(targetStates);
859 Annotation newAnnotation(parameter, polynomialCache);
861 RationalFunctionCoefficient constantPart = utility::zero<RationalFunctionCoefficient>();
862 for (
auto const& [state, transition] : transitions) {
863 constantPart += transition;
865 newAnnotation[factors] = constantPart;
867 STORM_LOG_INFO(
"Time travellable transitions with " << newAnnotation);
870 uint64_t newRow = flexibleMatrix.insertNewRowsAtEnd(1);
871 uint64_t newRowBackwards = backwardsFlexibleMatrix.insertNewRowsAtEnd(1);
872 STORM_LOG_ASSERT(newRow == newRowBackwards,
"Internal error: Drifting matrix and backwardsTransitions.");
875 insertTransitions.emplace_back(newRow, newAnnotation);
878 for (
auto const& [state, thisProb] : transitions) {
881 flexibleMatrix.getRow(newRow).push_back(storage::MatrixEntry<uint_fast64_t, RationalFunction>(state, probAsFunction));
883 backwardsFlexibleMatrix.getRow(state).push_back(storage::MatrixEntry<uint_fast64_t, RationalFunction>(newRow, probAsFunction));
885 for (
auto& entry : treeStatesNeedUpdate) {
886 entry.second.emplace(state);
890 backwardsFlexibleMatrix.getRow(state) = joinDuplicateTransitions(backwardsFlexibleMatrix.getRow(state));
893 flexibleMatrix.getRow(newRow) = joinDuplicateTransitions(flexibleMatrix.getRow(newRow));
895 auto const [state, probability] = *transitions.begin();
897 Annotation newAnnotation(parameter, polynomialCache);
898 newAnnotation[factors] = probability;
900 insertTransitions.emplace_back(state, newAnnotation);
905 for (
auto const& targetSet : targetSetStates) {
906 alreadyTimeTravelledToThis[parameter].emplace(targetSet);
909 return insertTransitions;
912std::map<UniPoly, Annotation> BigStep::replaceWithNewTransitions(uint64_t state,
const std::vector<std::pair<uint64_t, Annotation>> transitions,
913 storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
914 storage::FlexibleSparseMatrix<RationalFunction>& backwardsFlexibleMatrix,
915 storage::BitVector& reachableStates,
917 std::map<UniPoly, Annotation> storedAnnotations;
921 for (
auto const& deletingTransition : flexibleMatrix.getRow(state)) {
922 auto& row = backwardsFlexibleMatrix.getRow(deletingTransition.getColumn());
923 auto it = row.begin();
924 while (it != row.end()) {
925 if (it->getColumn() == state) {
933 flexibleMatrix.getRow(state) = std::vector<storage::MatrixEntry<uint_fast64_t, RationalFunction>>();
937 std::map<uint64_t, Annotation> insertThese;
938 for (
auto const& [target, probability] : transitions) {
939 for (
auto& entry : treeStatesNeedUpdate) {
940 entry.second.emplace(target);
942 if (insertThese.count(target)) {
943 insertThese.at(target) += probability;
945 insertThese.emplace(target, probability);
948 for (
auto const& [state2, annotation] : insertThese) {
949 auto uniProbability = annotation.getProbability();
950 storedAnnotations.emplace(uniProbability, std::move(annotation));
958 return storedAnnotations;
961void BigStep::updateUnreachableStates(storage::BitVector& reachableStates, std::vector<uint64_t>
const& statesMaybeUnreachable,
962 storage::FlexibleSparseMatrix<RationalFunction>
const& backwardsFlexibleMatrix, uint64_t initialState) {
963 if (backwardsFlexibleMatrix.getRowCount() > reachableStates.size()) {
964 reachableStates.resize(backwardsFlexibleMatrix.getRowCount(),
true);
968 for (
auto const& visitedState : statesMaybeUnreachable) {
969 if (visitedState == initialState) {
972 bool isUnreachable =
true;
973 for (
auto const& entry : backwardsFlexibleMatrix.getRow(visitedState)) {
974 if (reachableStates.get(entry.getColumn())) {
975 isUnreachable =
false;
980 reachableStates.set(visitedState,
false);
985std::vector<storm::storage::MatrixEntry<uint64_t, RationalFunction>> BigStep::joinDuplicateTransitions(
987 std::vector<uint64_t> keyOrder;
988 std::map<uint64_t, storm::storage::MatrixEntry<uint64_t, RationalFunction>> existingEntries;
989 for (
auto const& entry : entries) {
990 if (existingEntries.count(entry.getColumn())) {
991 existingEntries.at(entry.getColumn()).setValue(existingEntries.at(entry.getColumn()).getValue() + entry.getValue());
993 existingEntries[entry.getColumn()] = entry;
994 keyOrder.push_back(entry.getColumn());
997 std::vector<storm::storage::MatrixEntry<uint64_t, RationalFunction>> newEntries;
998 for (uint64_t key : keyOrder) {
999 newEntries.push_back(existingEntries.at(key));
1004models::sparse::StateLabeling BigStep::extendStateLabeling(models::sparse::StateLabeling
const& oldLabeling, uint64_t oldSize, uint64_t newSize,
1005 uint64_t stateWithLabels,
const std::set<std::string>& labelsInFormula) {
1006 models::sparse::StateLabeling newLabels(newSize);
1007 for (
auto const& label : oldLabeling.getLabels()) {
1008 newLabels.addLabel(label);
1010 for (uint64_t state = 0; state < oldSize; state++) {
1011 for (
auto const& label : oldLabeling.getLabelsOfState(state)) {
1012 newLabels.addLabelToState(label, state);
1015 for (uint64_t i = oldSize;
i < newSize;
i++) {
1017 for (
auto const& label : oldLabeling.getLabelsOfState(stateWithLabels)) {
1018 if (labelsInFormula.count(label)) {
1019 newLabels.addLabelToState(label, i);
1026void BigStep::updateTreeStates(std::map<
RationalFunctionVariable, std::map<uint64_t, std::set<uint64_t>>>& treeStates,
1028 const storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
1029 const storage::FlexibleSparseMatrix<RationalFunction>& backwardsTransitions,
1030 const std::set<RationalFunctionVariable>& allParameters,
const boost::optional<std::vector<RationalFunction>>& stateRewardVector,
1031 const models::sparse::StateLabeling stateLabeling) {
1032 for (
auto const& parameter : allParameters) {
1033 std::set<uint64_t>& workingSet = workingSets[parameter];
1034 while (!workingSet.empty()) {
1035 std::set<uint64_t> newWorkingSet;
1036 for (uint64_t row : workingSet) {
1037 if (stateRewardVector && !stateRewardVector->at(row).isZero()) {
1040 for (
auto const& entry : backwardsTransitions.getRow(row)) {
1041 if (entry.getValue().isConstant()) {
1044 bool isSubset =
true;
1045 for (
auto const& state : treeStates.at(parameter)[row]) {
1046 if (!treeStates.at(parameter)[entry.getColumn()].count(state)) {
1054 for (
auto const& state : treeStates.at(parameter).at(row)) {
1055 treeStates.at(parameter).at(entry.getColumn()).emplace(state);
1057 if (stateLabeling.getLabelsOfState(entry.getColumn()) == stateLabeling.getLabelsOfState(row)) {
1058 newWorkingSet.emplace(entry.getColumn());
1063 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(ValueType const &tolerance) 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