29 std::vector<uint32_t> modifiedObservations = observations;
33 modifiedObservations[0] = model.getNrObservations();
37 for (uint64_t state : initialStates) {
38 if (model.getObservation(state) != observations[0]) {
39 actualInitialStates.
set(state,
false);
43 "Must have unique initial state matching the observation.");
45#ifdef _VERBOSE_OBSERVATION_UNFOLDING
46 std::cout <<
"build valution builder..\n";
51 svBuilder.
addIntegerVariable(svvar, -1,
static_cast<int64_t
>(model.getNumberOfStates()) - 1);
57 auto addStateValuation = [
this, &stateValuations](int64_t s, int64_t t) {
58 stateValuations.
emplaceBack<
false, int64_t>([
this, s, t](
auto,
auto const& var,
auto& value) { value = var == svvar ? s : t; });
61 std::unordered_map<uint64_t, uint64_t> unfoldedToOld;
62 std::unordered_map<uint64_t, uint64_t> unfoldedToOldNextStep;
63 std::unordered_map<uint64_t, uint64_t> oldToUnfolded;
65#ifdef _VERBOSE_OBSERVATION_UNFOLDING
66 std::cout <<
"start buildiing matrix...\n";
69 uint64_t newStateIndex = 0;
70 uint64_t
const violatedState = newStateIndex;
71 if (!options.useRestartSemantics) {
76 uint64_t
const initialState = newStateIndex;
79 unfoldedToOldNextStep[initialState] = actualInitialStates.
getNextSetIndex(0);
81 uint64_t
const resetDestination = options.useRestartSemantics ? initialState : violatedState;
84 if (!options.useRestartSemantics) {
88 addStateValuation(-1, -1);
92 uint64_t newRowGroupStart = initialState;
93 uint64_t newRowCount = initialState;
96 for (uint64_t step = 0; step < observations.size() - 1; ++step) {
97 oldToUnfolded.clear();
98 unfoldedToOld = unfoldedToOldNextStep;
99 unfoldedToOldNextStep.clear();
101 for (
auto const& unfoldedToOldEntry : unfoldedToOld) {
102 transitionMatrixBuilder.
newRowGroup(newRowGroupStart);
103#ifdef _VERBOSE_OBSERVATION_UNFOLDING
104 std::cout <<
"\tconsider new state " << unfoldedToOldEntry.first <<
'\n';
107 "Step " << step <<
" newRowCount " << newRowCount <<
" lastRow " << transitionMatrixBuilder.
getLastRow());
108 addStateValuation(unfoldedToOldEntry.second, step);
109 uint64_t oldRowIndexStart = model.getNondeterministicChoiceIndices()[unfoldedToOldEntry.second];
110 uint64_t oldRowIndexEnd = model.getNondeterministicChoiceIndices()[unfoldedToOldEntry.second + 1];
112 for (uint64_t oldRowIndex = oldRowIndexStart; oldRowIndex != oldRowIndexEnd; oldRowIndex++) {
113#ifdef _VERBOSE_OBSERVATION_UNFOLDING
114 std::cout <<
"\t\tconsider old action " << oldRowIndex <<
'\n';
115 std::cout <<
"\t\tconsider new row nr " << newRowCount <<
'\n';
120 for (
auto const& oldRowEntry : model.getTransitionMatrix().getRow(oldRowIndex)) {
121 if (model.getObservation(oldRowEntry.getColumn()) != observations[step + 1]) {
122 resetProb += oldRowEntry.getValue();
123 if constexpr (std::is_same_v<ValueType, storm::Interval>) {
124 resetProb.setUpper(std::min(resetProb.upper(), 1.0));
125 resetProb.setLower(std::max(resetProb.lower(), 0.0));
126 }
else if constexpr (std::is_same_v<ValueType, storm::RationalInterval>) {
132#ifdef _VERBOSE_OBSERVATION_UNFOLDING
133 std::cout <<
"\t\t\t add reset with probability " << resetProb <<
'\n';
138 transitionMatrixBuilder.
addNextValue(newRowCount, resetDestination, resetProb);
140#ifdef _VERBOSE_OBSERVATION_UNFOLDING
141 std::cout <<
"\t\t\t add other transitions...\n";
145 for (
auto const& oldRowEntry : model.getTransitionMatrix().getRow(oldRowIndex)) {
146 if (model.getObservation(oldRowEntry.getColumn()) != observations[step + 1]) {
151 auto entryIt = oldToUnfolded.find(oldRowEntry.getColumn());
152 if (entryIt == oldToUnfolded.end()) {
153 column = newStateIndex;
154 oldToUnfolded[oldRowEntry.getColumn()] = column;
155 unfoldedToOldNextStep[column] = oldRowEntry.getColumn();
158 column = entryIt->second;
160#ifdef _VERBOSE_OBSERVATION_UNFOLDING
161 std::cout <<
"\t\t\t\t transition to " << column <<
"with probability " << oldRowEntry.getValue() <<
'\n';
163 transitionMatrixBuilder.
addNextValue(newRowCount, column, oldRowEntry.getValue());
167 newRowGroupStart = transitionMatrixBuilder.
getLastRow() + 1;
171 uint64_t sinkState = newStateIndex;
172 uint64_t targetState = newStateIndex + 1;
173 for (
auto const& unfoldedToOldEntry : unfoldedToOldNextStep) {
174 addStateValuation(unfoldedToOldEntry.second, observations.size() - 1);
175 transitionMatrixBuilder.
newRowGroup(newRowGroupStart);
176 STORM_LOG_ASSERT(risk.size() > unfoldedToOldEntry.second,
"Must be a state.");
178 "Risk must be a probability");
184 transitionMatrixBuilder.
addNextValue(newRowGroupStart, targetState, risk[unfoldedToOldEntry.second]);
189 transitionMatrixBuilder.
newRowGroup(newRowGroupStart);
191 addStateValuation(-1, -1);
194 transitionMatrixBuilder.
newRowGroup(newRowGroupStart);
197 addStateValuation(-1, -1);
199#ifdef _VERBOSE_OBSERVATION_UNFOLDING
200 std::cout <<
"build matrix...\n";
205#ifdef _VERBOSE_OBSERVATION_UNFOLDING
212 if (!options.useRestartSemantics) {
223 return std::make_shared<storm::models::sparse::Mdp<ValueType>>(std::move(components));