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);
210 if (oneActionObservations.
get(observation)) {
218 <<
getStateInformation(state) <<
" provides " << rowIndexTo - rowIndexFrom <<
" actions.");
220 moreActionObservations.
set(observation);
223 std::map<detail::ActionIdentifier, uint64_t> actionIdentifiers;
224 std::set<uint64_t> actionLabels;
225 for (uint64_t actionIndex = rowIndexFrom; actionIndex < rowIndexTo; ++actionIndex) {
228 std::set<std::string> labels = choiceLabeling.getLabelsOfChoice(actionIndex);
229 STORM_LOG_ASSERT(labels.size() <= 1,
"We expect choice labels to be single sets");
231 uint64_t labelId = -1;
232 if (labels.size() == 1) {
234 STORM_LOG_THROW(actionLabels.count(labelId) == 0, storm::exceptions::AmbiguousModelException,
235 "Multiple actions with label '" << *labels.begin() <<
"' exist in state id " << state <<
".");
236 actionLabels.emplace(labelId);
243 if (
pomdp.hasChoiceOrigins()) {
248 STORM_LOG_ASSERT(actionIdentifiers.count(ai) == 0,
"Action with this identifier already exists for this state");
249 actionIdentifiers.emplace(ai, actionIndex);
251 STORM_LOG_ASSERT(actionIdentifiers.size() == rowIndexTo - rowIndexFrom,
"Number of action identifiers should match number of actions");
253 if (observationActionIdentifiers.count(observation) == 0) {
256 std::vector<detail::ActionIdentifier> ais;
257 for (
auto const& als : actionIdentifiers) {
258 ais.push_back(als.first);
261 observationActionIdentifiers.emplace(observation, ais);
262 actionIdentifierDefinition.emplace(observation, state);
264 auto referenceStart = observationActionIdentifiers[observation].begin();
265 auto referenceEnd = observationActionIdentifiers[observation].end();
266 STORM_LOG_ASSERT(observationActionIdentifiers[observation].size() ==
pomdp.getNumberOfChoices(actionIdentifierDefinition[observation]),
267 "Number of actions recorded for state does not coincide with number of actions.");
268 if (observationActionIdentifiers[observation].size() != actionIdentifiers.size()) {
270 "Number of actions in state '" <<
getStateInformation(state) <<
"' (nr actions:" << actionIdentifiers.size() <<
") and state '"
272 <<
"' (actions: " << observationActionIdentifiers[observation].size()
275 if (!
detail::compatibleWith(referenceStart, referenceEnd, actionIdentifiers.begin(), actionIdentifiers.end())) {
278 std::cout <<
" according to state " << actionIdentifierDefinition[observation] <<
".\n";
280 std::cout <<
" according to state " << state <<
".\n";
281 std::cout <<
"(Actions are given as [id (label), originId])\n";
283 for (
auto const& ai : actionIdentifiers) {
284 if (labelStorage.
getLabel(ai.first.choiceLabelId) ==
"") {
285 for (
auto const& ai2 : observationActionIdentifiers[observation]) {
287 "Actions with empty label are only considered the same action if they originate from the same command.");
293 "Actions identifiers do not align between states \n\t"
295 <<
"\nboth having observation " <<
getObservationInformation(observation) <<
". See output above for more information.");
299 for (
auto const& al : actionIdentifiers) {
300 permutation.push_back(al.second);