136 auto rewardModels =
pomdp.getRewardModels();
137 std::unordered_map<std::string, storm::models::sparse::StandardRewardModel<ValueType>> newRewardModels;
138 for (
auto& rewardModelNameAndModel : rewardModels) {
139 newRewardModels.emplace(rewardModelNameAndModel.first, rewardModelNameAndModel.second.permuteActions(permutation));
142 newRewardModels,
false, boost::none);
148 return std::make_shared<storm::models::sparse::Pomdp<ValueType>>(modelcomponents,
true);
171 std::map<uint32_t, std::vector<detail::ActionIdentifier>> observationActionIdentifiers;
172 std::map<uint32_t, uint64_t> actionIdentifierDefinition;
173 auto const& choiceLabeling =
pomdp.getChoiceLabeling();
176 std::vector<uint64_t> permutation;
177 uint64_t nrObservations =
pomdp.getNrObservations();
180 uint64_t freshChoiceOriginId = 0;
182 for (uint64_t state = 0; state <
pomdp.getNumberOfStates(); ++state) {
183 uint64_t rowIndexFrom =
pomdp.getTransitionMatrix().getRowGroupIndices()[state];
184 uint64_t rowIndexTo =
pomdp.getTransitionMatrix().getRowGroupIndices()[state + 1];
186 uint64_t observation =
pomdp.getObservation(state);
187 if (rowIndexFrom + 1 == rowIndexTo) {
188 permutation.push_back(rowIndexFrom);
189 if (moreActionObservations.
get(observation)) {
192 std::string actionval =
"";
193 if (
pomdp.hasChoiceLabeling()) {
194 auto labelsOfChoice =
pomdp.getChoiceLabeling().getLabelsOfChoice(rowIndexFrom);
195 if (labelsOfChoice.empty()) {
196 actionval =
"[[no-label]]";
198 actionval = *
pomdp.getChoiceLabeling().getLabelsOfChoice(rowIndexFrom).begin();
205 oneActionObservations.
set(observation);
215 STORM_LOG_THROW(!oneActionObservations.
get(observation), storm::exceptions::AmbiguousModelException,
217 <<
getStateInformation(state) <<
" provides " << rowIndexTo - rowIndexFrom <<
" actions.");
218 moreActionObservations.
set(observation);
221 std::map<detail::ActionIdentifier, uint64_t> actionIdentifiers;
222 std::set<uint64_t> actionLabels;
223 for (uint64_t actionIndex = rowIndexFrom; actionIndex < rowIndexTo; ++actionIndex) {
226 std::set<std::string> labels = choiceLabeling.getLabelsOfChoice(actionIndex);
227 STORM_LOG_ASSERT(labels.size() <= 1,
"We expect choice labels to be single sets.");
229 uint64_t labelId = -1;
230 if (labels.size() == 1) {
232 STORM_LOG_THROW(actionLabels.count(labelId) == 0, storm::exceptions::AmbiguousModelException,
233 "Multiple actions with label '" << *labels.begin() <<
"' exist in state id " << state <<
".");
234 actionLabels.emplace(labelId);
241 if (
pomdp.hasChoiceOrigins()) {
246 STORM_LOG_ASSERT(actionIdentifiers.count(ai) == 0,
"Action with this identifier already exists for this state.");
247 actionIdentifiers.emplace(ai, actionIndex);
249 STORM_LOG_ASSERT(actionIdentifiers.size() == rowIndexTo - rowIndexFrom,
"Number of action identifiers should match number of actions.");
251 if (observationActionIdentifiers.count(observation) == 0) {
254 std::vector<detail::ActionIdentifier> ais;
255 for (
auto const& als : actionIdentifiers) {
256 ais.push_back(als.first);
259 observationActionIdentifiers.emplace(observation, ais);
260 actionIdentifierDefinition.emplace(observation, state);
262 auto referenceStart = observationActionIdentifiers[observation].begin();
263 auto referenceEnd = observationActionIdentifiers[observation].end();
264 STORM_LOG_ASSERT(observationActionIdentifiers[observation].size() ==
pomdp.getNumberOfChoices(actionIdentifierDefinition[observation]),
265 "Number of actions recorded for state does not coincide with number of actions.");
266 STORM_LOG_THROW(observationActionIdentifiers[observation].size() == actionIdentifiers.size(), storm::exceptions::AmbiguousModelException,
267 "Number of actions in state '" <<
getStateInformation(state) <<
"' (nr actions:" << actionIdentifiers.size() <<
") and state '"
269 <<
"' (actions: " << observationActionIdentifiers[observation].size()
271 if (!
detail::compatibleWith(referenceStart, referenceEnd, actionIdentifiers.begin(), actionIdentifiers.end())) {
274 std::cout <<
" according to state " << actionIdentifierDefinition[observation] <<
".\n";
276 std::cout <<
" according to state " << state <<
".\n";
277 std::cout <<
"(Actions are given as [id (label), originId])\n";
279 for (
auto const& ai : actionIdentifiers) {
280 if (labelStorage.
getLabel(ai.first.choiceLabelId) ==
"") {
281 for (
auto const& ai2 : observationActionIdentifiers[observation]) {
283 "Actions with empty label are only considered the same action if they originate from the same command.");
289 "Actions identifiers do not align between states \n\t"
291 <<
"\nboth having observation " <<
getObservationInformation(observation) <<
". See output above for more information.");
295 for (
auto const& al : actionIdentifiers) {
296 permutation.push_back(al.second);