26 std::vector<uint32_t> modifiedObservations = observations;
30 modifiedObservations[0] = model.getNrObservations();
34 for (uint64_t state : initialStates) {
35 if (model.getObservation(state) != observations[0]) {
36 actualInitialStates.
set(state,
false);
40 "Must have unique initial state matching the observation");
42#ifdef _VERBOSE_OBSERVATION_UNFOLDING
43 std::cout <<
"build valution builder..\n";
49 std::unordered_map<uint64_t, uint64_t> unfoldedToOld;
50 std::unordered_map<uint64_t, uint64_t> unfoldedToOldNextStep;
51 std::unordered_map<uint64_t, uint64_t> oldToUnfolded;
53#ifdef _VERBOSE_OBSERVATION_UNFOLDING
54 std::cout <<
"start buildiing matrix...\n";
57 uint64_t newStateIndex = 0;
58 uint64_t
const violatedState = newStateIndex;
59 if (!options.useRestartSemantics) {
64 uint64_t
const initialState = newStateIndex;
67 unfoldedToOldNextStep[initialState] = actualInitialStates.
getNextSetIndex(0);
69 uint64_t
const resetDestination = options.useRestartSemantics ? initialState : violatedState;
72 if (!options.useRestartSemantics) {
76 svbuilder.
addState(violatedState, {}, {-1, -1});
80 uint64_t newRowGroupStart = initialState;
81 uint64_t newRowCount = initialState;
84 for (uint64_t step = 0; step < observations.size() - 1; ++step) {
85 oldToUnfolded.clear();
86 unfoldedToOld = unfoldedToOldNextStep;
87 unfoldedToOldNextStep.clear();
89 for (
auto const& unfoldedToOldEntry : unfoldedToOld) {
90 transitionMatrixBuilder.
newRowGroup(newRowGroupStart);
91#ifdef _VERBOSE_OBSERVATION_UNFOLDING
92 std::cout <<
"\tconsider new state " << unfoldedToOldEntry.first <<
'\n';
95 "step " << step <<
" newRowCount " << newRowCount <<
" lastRow " << transitionMatrixBuilder.
getLastRow());
96 svbuilder.
addState(unfoldedToOldEntry.first, {}, {static_cast<int64_t>(unfoldedToOldEntry.second), static_cast<int64_t>(step)});
97 uint64_t oldRowIndexStart = model.getNondeterministicChoiceIndices()[unfoldedToOldEntry.second];
98 uint64_t oldRowIndexEnd = model.getNondeterministicChoiceIndices()[unfoldedToOldEntry.second + 1];
100 for (uint64_t oldRowIndex = oldRowIndexStart; oldRowIndex != oldRowIndexEnd; oldRowIndex++) {
101#ifdef _VERBOSE_OBSERVATION_UNFOLDING
102 std::cout <<
"\t\tconsider old action " << oldRowIndex <<
'\n';
103 std::cout <<
"\t\tconsider new row nr " << newRowCount <<
'\n';
108 for (
auto const& oldRowEntry : model.getTransitionMatrix().getRow(oldRowIndex)) {
109 if (model.getObservation(oldRowEntry.getColumn()) != observations[step + 1]) {
110 resetProb += oldRowEntry.getValue();
111 if constexpr (std::is_same_v<ValueType, storm::Interval>) {
112 resetProb.setUpper(std::min(resetProb.upper(), 1.0));
113 resetProb.setLower(std::max(resetProb.lower(), 0.0));
114 }
else if constexpr (std::is_same_v<ValueType, storm::RationalInterval>) {
120#ifdef _VERBOSE_OBSERVATION_UNFOLDING
121 std::cout <<
"\t\t\t add reset with probability " << resetProb <<
'\n';
126 transitionMatrixBuilder.
addNextValue(newRowCount, resetDestination, resetProb);
128#ifdef _VERBOSE_OBSERVATION_UNFOLDING
129 std::cout <<
"\t\t\t add other transitions...\n";
133 for (
auto const& oldRowEntry : model.getTransitionMatrix().getRow(oldRowIndex)) {
134 if (model.getObservation(oldRowEntry.getColumn()) != observations[step + 1]) {
139 auto entryIt = oldToUnfolded.find(oldRowEntry.getColumn());
140 if (entryIt == oldToUnfolded.end()) {
141 column = newStateIndex;
142 oldToUnfolded[oldRowEntry.getColumn()] = column;
143 unfoldedToOldNextStep[column] = oldRowEntry.getColumn();
146 column = entryIt->second;
148#ifdef _VERBOSE_OBSERVATION_UNFOLDING
149 std::cout <<
"\t\t\t\t transition to " << column <<
"with probability " << oldRowEntry.getValue() <<
'\n';
151 transitionMatrixBuilder.
addNextValue(newRowCount, column, oldRowEntry.getValue());
155 newRowGroupStart = transitionMatrixBuilder.
getLastRow() + 1;
159 uint64_t sinkState = newStateIndex;
160 uint64_t targetState = newStateIndex + 1;
161 for (
auto const& unfoldedToOldEntry : unfoldedToOldNextStep) {
162 svbuilder.
addState(unfoldedToOldEntry.first, {}, {static_cast<int64_t>(unfoldedToOldEntry.second), static_cast<int64_t>(observations.size() - 1)});
164 transitionMatrixBuilder.
newRowGroup(newRowGroupStart);
165 STORM_LOG_ASSERT(risk.size() > unfoldedToOldEntry.second,
"Must be a state");
167 "Risk must be a probability");
173 transitionMatrixBuilder.
addNextValue(newRowGroupStart, targetState, risk[unfoldedToOldEntry.second]);
178 transitionMatrixBuilder.
newRowGroup(newRowGroupStart);
180 svbuilder.
addState(sinkState, {}, {-1, -1});
183 transitionMatrixBuilder.
newRowGroup(newRowGroupStart);
186 svbuilder.
addState(targetState, {}, {-1, -1});
187#ifdef _VERBOSE_OBSERVATION_UNFOLDING
188 std::cout <<
"build matrix...\n";
193#ifdef _VERBOSE_OBSERVATION_UNFOLDING
200 if (!options.useRestartSemantics) {
211 return std::make_shared<storm::models::sparse::Mdp<ValueType>>(std::move(components));