12#include <unordered_map>
31namespace transformer {
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()) {
63 uint64_t newIndex = container.second.size();
64 container.first[f] = newIndex;
65 container.second.push_back(f);
72 auto key = std::make_pair(factorization, p);
73 if (localCache.count(key)) {
74 return localCache.at(key);
77 polynomial = polynomial.one();
78 for (uint64_t i = 0; i < factorization.size(); i++) {
79 for (uint64_t j = 0; j < factorization[i]; j++) {
80 polynomial *= this->at(p).second[i];
83 localCache.emplace(key, polynomial);
88 : parameter(parameter), polynomialCache(polynomialCache) {
93 STORM_LOG_ASSERT(other.parameter == this->parameter,
"Can only add annotations with equal parameters.");
94 for (
auto const& [factors, number] : other) {
95 if (this->count(factors)) {
96 this->at(factors) += number;
98 this->emplace(factors, number);
104 for (
auto& [factors, number] : *
this) {
112 return annotationCopy;
116 for (
auto const& [info, constant] : other) {
117 if (!this->count(info)) {
120 this->at(info) += constant * timesConstant;
125 for (
auto const& [info, constant] : other) {
127 auto newCounter = info;
130 auto const cacheNum = this->polynomialCache->lookUpInCache(polynomial, parameter);
131 while (newCounter.size() <= cacheNum) {
132 newCounter.push_back(0);
134 newCounter[cacheNum]++;
136 if (!this->count(newCounter)) {
137 this->emplace(newCounter, constant);
139 this->at(newCounter) += constant;
145 for (
auto const& [info1, constant1] : anno1) {
146 for (
auto const& [info2, constant2] : anno2) {
147 std::vector<uint64_t> newCounter(std::max(info1.size(), info2.size()), 0);
149 for (uint64_t i = 0; i < newCounter.size(); i++) {
150 if (i < info1.size()) {
151 newCounter[i] += info1[i];
153 if (i < info2.size()) {
154 newCounter[i] += info2[i];
158 if (!this->count(newCounter)) {
159 this->emplace(newCounter, constant1 * constant2);
161 this->at(newCounter) += constant1 * constant2;
169 for (
auto const& [info, constant] : *
this) {
170 prob += polynomialCache->polynomialFromFactorization(info, parameter) * constant;
176 std::vector<UniPoly> terms;
177 for (
auto const& [info, constant] : *
this) {
178 terms.push_back(polynomialCache->polynomialFromFactorization(info, parameter) * constant);
184 if (!derivativeOfThis) {
187 Interval boundDerivative = derivativeOfThis->evaluateOnIntervalMidpointTheorem(input, higherOrderBounds);
190 double fMin = fMid - (input.diameter() / 2) * maxSlope;
191 double fMax = fMid + (input.diameter() / 2) * maxSlope;
192 if (higherOrderBounds) {
206 if (nth == 0 || derivativeOfThis) {
209 derivativeOfThis = std::make_shared<Annotation>(this->parameter, this->polynomialCache);
210 for (
auto const& [info, constant] : *
this) {
212 for (uint64_t i = 0; i < info.size(); i++) {
219 std::vector<uint64_t> insert(info);
222 while (!insert.empty() && insert.back() == 0) {
226 auto polynomial = polynomialCache->at(parameter).second.at(i);
231 uint64_t derivativeIndex = this->polynomialCache->lookUpInCache(
derivative, parameter);
232 while (insert.size() < derivativeIndex) {
235 insert[derivativeIndex]++;
237 if (derivativeOfThis->count(insert)) {
238 derivativeOfThis->at(insert) += newConstant;
240 derivativeOfThis->emplace(insert, newConstant);
244 derivativeOfThis->computeDerivative(nth - 1);
249 for (
auto const& [info, constant] : *
this) {
259 return derivativeOfThis;
264 auto iterator = annotation.begin();
265 while (iterator != annotation.end()) {
266 auto const& factors = iterator->first;
267 auto const& constant = iterator->second;
268 os << constant <<
" * (";
269 bool alreadyPrintedFactor =
false;
270 for (uint64_t i = 0; i < factors.size(); i++) {
271 if (factors[i] > 0) {
272 if (alreadyPrintedFactor) {
275 alreadyPrintedFactor =
true;
277 os <<
"(" << annotation.polynomialCache->at(annotation.parameter).second[i] <<
")"
278 <<
"^" << 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 &&
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();
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;
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) {
552 uint64_t oldMatrixSize = flexibleMatrix.getRowCount();
554 std::vector<std::pair<uint64_t, Annotation>> transitions = findBigStep(bottomAnnotations, parameter, flexibleMatrix, backwardsTransitions,
555 alreadyTimeTravelledToThis, treeStatesNeedUpdate, state, originalNumStates);
558 auto newStoredAnnotations =
559 replaceWithNewTransitions(state, transitions, flexibleMatrix, backwardsTransitions, reachableStates, treeStatesNeedUpdate);
560 for (
auto const& entry : newStoredAnnotations) {
561 storedAnnotations.emplace(entry);
565 updateUnreachableStates(reachableStates, visitedStates, backwardsTransitions, initialState);
567 uint64_t newMatrixSize = flexibleMatrix.getRowCount();
568 if (newMatrixSize > oldMatrixSize) {
570 runningLabeling = extendStateLabeling(runningLabeling, oldMatrixSize, newMatrixSize, state, labelsInFormula);
571 runningLabelingTreeStates = extendStateLabeling(runningLabelingTreeStates, oldMatrixSize, newMatrixSize, state, labelsInFormula);
574 reachableStates.
resize(newMatrixSize,
true);
576 for (uint64_t i = oldMatrixSize; i < newMatrixSize; i++) {
577 topologicalOrderingStack.push(i);
578 for (
auto& [_parameter, updateStates] : treeStatesNeedUpdate) {
579 updateStates.emplace(i);
582 if (stateRewardVector) {
586 updateTreeStates(treeStates, treeStatesNeedUpdate, flexibleMatrix, backwardsTransitions, allParameters, stateRewardVector,
587 runningLabelingTreeStates);
596 if (stateRewardVector) {
601 storm::io::openFile(
"dots/travel_" + std::to_string(flexibleMatrix.getRowCount()) +
".dot", file2);
607 transitionMatrix = flexibleMatrix.createSparseMatrix();
614 initialStates.
set(initialState,
true);
617 transitionMatrix = transitionMatrix.
getSubmatrix(
false, reachableStates, reachableStates);
618 runningLabeling = runningLabeling.
getSubLabeling(reachableStates);
619 uint_fast64_t newInitialState = 0;
620 for (uint_fast64_t i = 0; i < initialState; i++) {
621 if (reachableStates.
get(i)) {
625 initialState = newInitialState;
626 if (stateRewardVector) {
627 std::vector<RationalFunction> newStateRewardVector;
628 for (uint_fast64_t i = 0; i < stateRewardVector->size(); i++) {
629 if (reachableStates.
get(i)) {
630 newStateRewardVector.push_back(stateRewardVector->at(i));
635 stateRewardVector = newStateRewardVector;
642 newInitialStates.
set(initialState,
true);
645 if (stateRewardVector) {
651 "Internal error: resulting matrix not probabilistic!");
654 for (
auto const& entry : storedAnnotations) {
658 return std::make_pair(newDTMC, storedAnnotations);
661std::pair<std::map<uint64_t, Annotation>, std::pair<std::vector<uint64_t>, std::map<uint64_t, std::set<uint64_t>>>> BigStep::bigStepBFS(
665 const boost::optional<std::vector<RationalFunction>>& stateRewardVector,
const std::map<UniPoly, Annotation>& storedAnnotations) {
667 auto const [subtree, bottomStates] =
findSubgraph(flexibleMatrix, start, treeStates, stateRewardVector, parameter);
670 std::vector<uint64_t> visitedStatesInBFSOrder;
672 std::set<std::pair<uint64_t, uint64_t>> visitedEdges;
675 std::map<uint64_t, Annotation> annotations;
678 std::queue<uint64_t> activeStates;
679 activeStates.push(start);
681 annotations.emplace(start,
Annotation(parameter, polynomialCache));
685 while (!activeStates.empty()) {
686 auto state = activeStates.front();
688 visitedStatesInBFSOrder.push_back(state);
689 for (
auto const& entry : flexibleMatrix.
getRow(state)) {
690 auto const goToState = entry.getColumn();
691 if (!subtree.count(goToState) || !subtree.at(state).count(goToState)) {
694 visitedEdges.emplace(std::make_pair(state, goToState));
696 bool allBackwardsStatesVisited =
true;
697 for (
auto const& backwardsEntry : backwardsFlexibleMatrix.
getRow(goToState)) {
698 if (!subtree.count(backwardsEntry.getColumn()) || !subtree.at(backwardsEntry.getColumn()).count(goToState)) {
704 if (!visitedEdges.count(std::make_pair(backwardsEntry.getColumn(), goToState))) {
705 allBackwardsStatesVisited =
false;
709 if (!allBackwardsStatesVisited) {
714 annotations.emplace(goToState, Annotation(parameter, polynomialCache));
717 for (
auto const& backwardsEntry : backwardsFlexibleMatrix.
getRow(goToState)) {
718 if (!subtree.count(backwardsEntry.getColumn()) || !subtree.at(backwardsEntry.getColumn()).count(goToState)) {
724 auto const transition = backwardsEntry.getValue();
727 auto& targetAnnotation = annotations.at(goToState);
730 if (transition.isConstant()) {
731 targetAnnotation.addAnnotationTimesConstant(annotations.at(backwardsEntry.getColumn()), transition.constantPart());
734 STORM_LOG_ERROR_COND(transition.denominator().isConstant(),
"Only transitions with constant denominator supported but this has "
735 << transition.denominator() <<
" in transition " << transition);
736 auto nominator = transition.nominator();
737 UniPoly nominatorAsUnivariate = transition.nominator().toUnivariatePolynomial();
739 nominatorAsUnivariate /= transition.denominator().coefficient();
740 if (storedAnnotations.count(nominatorAsUnivariate)) {
741 targetAnnotation.addAnnotationTimesAnnotation(annotations.at(backwardsEntry.getColumn()), storedAnnotations.at(nominatorAsUnivariate));
743 targetAnnotation.addAnnotationTimesPolynomial(annotations.at(backwardsEntry.getColumn()), std::move(nominatorAsUnivariate));
748 bool allForwardEdgesVisited =
true;
749 for (
auto const& entry : flexibleMatrix.
getRow(backwardsEntry.getColumn())) {
750 if (!subtree.at(backwardsEntry.getColumn()).count(entry.getColumn())) {
756 if (!annotations.count(entry.getColumn())) {
757 allForwardEdgesVisited =
false;
761 if (allForwardEdgesVisited) {
762 annotations.erase(backwardsEntry.getColumn());
765 activeStates.push(goToState);
769 for (
auto const& [state, _successors] : subtree) {
770 if (!bottomStates.count(state)) {
771 annotations.erase(state);
774 return std::make_pair(annotations, std::make_pair(visitedStatesInBFSOrder, subtree));
777std::vector<std::pair<uint64_t, Annotation>> BigStep::findBigStep(
const std::map<uint64_t, Annotation> bigStepAnnotations,
779 storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
780 storage::FlexibleSparseMatrix<RationalFunction>& backwardsFlexibleMatrix,
783 uint64_t originalNumStates) {
784 STORM_LOG_INFO(
"Find time travelling called with root " << root <<
" and parameter " << parameter);
787 std::map<std::vector<uint64_t>, std::map<uint64_t, RationalFunctionCoefficient>> parametricTransitions;
789 for (
auto const& [state, annotation] : bigStepAnnotations) {
790 for (
auto const& [info, constant] : annotation) {
791 if (!parametricTransitions.count(info)) {
792 parametricTransitions[info] = std::map<uint64_t, RationalFunctionCoefficient>();
794 STORM_LOG_ASSERT(!parametricTransitions.at(info).count(state),
"State already exists.");
795 parametricTransitions.at(info)[state] = constant;
800 std::vector<std::pair<uint64_t, Annotation>> insertTransitions;
803 std::unordered_set<uint64_t> affectedStates;
805 std::set<std::set<uint64_t>> targetSetStates;
807 for (
auto const& [factors, transitions] : parametricTransitions) {
808 if (transitions.size() > 1) {
812 std::set<uint64_t> targetStates;
815 for (
auto const& [state, info] : transitions) {
816 affectedStates.emplace(state);
817 if (state < originalNumStates) {
818 targetStates.emplace(state);
822 if (alreadyTimeTravelledToThis[parameter].
count(targetStates)) {
823 for (
auto const& [state, probability] : transitions) {
824 Annotation newAnnotation(parameter, polynomialCache);
825 newAnnotation[factors] = probability;
827 insertTransitions.emplace_back(state, newAnnotation);
831 targetSetStates.emplace(targetStates);
833 Annotation newAnnotation(parameter, polynomialCache);
836 for (
auto const& [state, transition] : transitions) {
837 constantPart += transition;
839 newAnnotation[factors] = constantPart;
841 STORM_LOG_INFO(
"Time travellable transitions with " << newAnnotation);
844 uint64_t newRow = flexibleMatrix.insertNewRowsAtEnd(1);
845 [[maybe_unused]] uint64_t newRowBackwards = backwardsFlexibleMatrix.insertNewRowsAtEnd(1);
846 STORM_LOG_ASSERT(newRow == newRowBackwards,
"Internal error: Drifting matrix and backwardsTransitions.");
849 insertTransitions.emplace_back(newRow, newAnnotation);
852 for (
auto const& [state, thisProb] : transitions) {
855 flexibleMatrix.getRow(newRow).push_back(storage::MatrixEntry<uint_fast64_t, RationalFunction>(state, probAsFunction));
857 backwardsFlexibleMatrix.getRow(state).push_back(storage::MatrixEntry<uint_fast64_t, RationalFunction>(newRow, probAsFunction));
859 for (
auto& entry : treeStatesNeedUpdate) {
860 entry.second.emplace(state);
864 backwardsFlexibleMatrix.getRow(state) = joinDuplicateTransitions(backwardsFlexibleMatrix.getRow(state));
867 flexibleMatrix.getRow(newRow) = joinDuplicateTransitions(flexibleMatrix.getRow(newRow));
869 auto const [state, probability] = *transitions.begin();
871 Annotation newAnnotation(parameter, polynomialCache);
872 newAnnotation[factors] = probability;
874 insertTransitions.emplace_back(state, newAnnotation);
879 for (
auto const& targetSet : targetSetStates) {
880 alreadyTimeTravelledToThis[parameter].emplace(targetSet);
883 return insertTransitions;
886std::map<UniPoly, Annotation> BigStep::replaceWithNewTransitions(uint64_t state,
const std::vector<std::pair<uint64_t, Annotation>> transitions,
887 storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
888 storage::FlexibleSparseMatrix<RationalFunction>& backwardsFlexibleMatrix,
889 storage::BitVector& reachableStates,
891 std::map<UniPoly, Annotation> storedAnnotations;
895 for (
auto const& deletingTransition : flexibleMatrix.getRow(state)) {
896 auto& row = backwardsFlexibleMatrix.getRow(deletingTransition.getColumn());
897 auto it = row.begin();
898 while (it != row.end()) {
899 if (it->getColumn() == state) {
907 flexibleMatrix.getRow(state) = std::vector<storage::MatrixEntry<uint_fast64_t, RationalFunction>>();
911 std::map<uint64_t, Annotation> insertThese;
912 for (
auto const& [target, probability] : transitions) {
913 for (
auto& entry : treeStatesNeedUpdate) {
914 entry.second.emplace(target);
916 if (insertThese.count(target)) {
917 insertThese.at(target) += probability;
919 insertThese.emplace(target, probability);
922 for (
auto const& [state2, annotation] : insertThese) {
923 auto uniProbability = annotation.getProbability();
924 storedAnnotations.emplace(uniProbability, std::move(annotation));
928 flexibleMatrix.getRow(state).push_back(storm::storage::MatrixEntry<uint_fast64_t, RationalFunction>(state2, probability));
929 backwardsFlexibleMatrix.getRow(state2).push_back(storm::storage::MatrixEntry<uint_fast64_t, RationalFunction>(state, probability));
932 return storedAnnotations;
935void BigStep::updateUnreachableStates(storage::BitVector& reachableStates, std::vector<uint64_t>
const& statesMaybeUnreachable,
936 storage::FlexibleSparseMatrix<RationalFunction>
const& backwardsFlexibleMatrix, uint64_t initialState) {
937 if (backwardsFlexibleMatrix.getRowCount() > reachableStates.size()) {
938 reachableStates.resize(backwardsFlexibleMatrix.getRowCount(),
true);
942 for (
auto const& visitedState : statesMaybeUnreachable) {
943 if (visitedState == initialState) {
946 bool isUnreachable =
true;
947 for (
auto const& entry : backwardsFlexibleMatrix.getRow(visitedState)) {
948 if (reachableStates.get(entry.getColumn())) {
949 isUnreachable =
false;
954 reachableStates.set(visitedState,
false);
959std::vector<storm::storage::MatrixEntry<uint64_t, RationalFunction>> BigStep::joinDuplicateTransitions(
960 std::vector<storm::storage::MatrixEntry<uint64_t, RationalFunction>>
const& entries) {
961 std::vector<uint64_t> keyOrder;
962 std::map<uint64_t, storm::storage::MatrixEntry<uint64_t, RationalFunction>> existingEntries;
963 for (
auto const& entry : entries) {
964 if (existingEntries.count(entry.getColumn())) {
965 existingEntries.at(entry.getColumn()).setValue(existingEntries.at(entry.getColumn()).getValue() + entry.getValue());
967 existingEntries[entry.getColumn()] = entry;
968 keyOrder.push_back(entry.getColumn());
971 std::vector<storm::storage::MatrixEntry<uint64_t, RationalFunction>> newEntries;
972 for (uint64_t key : keyOrder) {
973 newEntries.push_back(existingEntries.at(key));
978models::sparse::StateLabeling BigStep::extendStateLabeling(models::sparse::StateLabeling
const& oldLabeling, uint64_t oldSize, uint64_t newSize,
979 uint64_t stateWithLabels,
const std::set<std::string>& labelsInFormula) {
980 models::sparse::StateLabeling newLabels(newSize);
981 for (
auto const& label : oldLabeling.getLabels()) {
982 newLabels.addLabel(label);
984 for (uint64_t state = 0; state < oldSize; state++) {
985 for (
auto const& label : oldLabeling.getLabelsOfState(state)) {
986 newLabels.addLabelToState(label, state);
989 for (uint64_t i = oldSize;
i < newSize;
i++) {
991 for (
auto const& label : oldLabeling.getLabelsOfState(stateWithLabels)) {
992 if (labelsInFormula.count(label)) {
993 newLabels.addLabelToState(label, i);
1000void BigStep::updateTreeStates(std::map<
RationalFunctionVariable, std::map<uint64_t, std::set<uint64_t>>>& treeStates,
1002 const storage::FlexibleSparseMatrix<RationalFunction>& flexibleMatrix,
1003 const storage::FlexibleSparseMatrix<RationalFunction>& backwardsTransitions,
1004 const std::set<RationalFunctionVariable>& allParameters,
const boost::optional<std::vector<RationalFunction>>& stateRewardVector,
1005 const models::sparse::StateLabeling stateLabeling) {
1006 for (
auto const& parameter : allParameters) {
1007 std::set<uint64_t>& workingSet = workingSets[parameter];
1008 while (!workingSet.empty()) {
1009 std::set<uint64_t> newWorkingSet;
1010 for (uint64_t row : workingSet) {
1011 if (stateRewardVector && !stateRewardVector->at(row).isZero()) {
1014 for (
auto const& entry : backwardsTransitions.getRow(row)) {
1015 if (entry.getValue().isConstant()) {
1018 bool isSubset =
true;
1019 for (
auto const& state : treeStates.at(parameter)[row]) {
1020 if (!treeStates.at(parameter)[entry.getColumn()].count(state)) {
1028 for (
auto const& state : treeStates.at(parameter).at(row)) {
1029 treeStates.at(parameter).at(entry.getColumn()).emplace(state);
1031 if (stateLabeling.getLabelsOfState(entry.getColumn()) == stateLabeling.getLabelsOfState(row)) {
1032 newWorkingSet.emplace(entry.getColumn());
1037 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, storm::OptionalRef< std::string > reason={}) const
Checks for each row whether (i) each entry is between zero and one and (ii) all entries sum 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)
std::vector< uint_fast64_t > getTopologicalSort(storm::storage::SparseMatrix< T > const &matrix, std::vector< uint64_t > const &firstStates)
Performs a topological sort of the states of the system according to the given transitions.
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)
TargetType convertNumber(SourceType const &number)
carl::Interval< double > Interval
Interval type.
carl::Variable RationalFunctionVariable
carl::RationalFunction< Polynomial, true > RationalFunction
carl::MultivariatePolynomial< RationalFunctionCoefficient > RawPolynomial