Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseModelToUmb.cpp
Go to the documentation of this file.
2
6
22
23namespace storm::umb {
24
25namespace detail {
26
27template<typename ValueType, typename TargetValueType>
29 if (!matrix.hasTrivialRowGrouping()) {
30 umb.stateToChoices = matrix.getRowGroupIndices();
31 }
32 umb.choiceToBranches = matrix.getRowIndices();
33 umb.branchToTarget.emplace().reserve(matrix.getEntryCount());
34 std::vector<TargetValueType> branchProbabilities;
35 branchProbabilities.reserve(matrix.getEntryCount());
36 for (uint64_t rowIndex = 0; rowIndex < matrix.getRowCount(); ++rowIndex) {
37 auto const& row = matrix.getRow(rowIndex);
38 for (auto const& entry : row) {
39 umb.branchToTarget->push_back(entry.getColumn());
40 branchProbabilities.push_back(storm::utility::convertNumber<TargetValueType>(entry.getValue()));
41 }
42 if (normalize) {
43 auto rowProbs = std::span<TargetValueType>(branchProbabilities.end() - row.getNumberOfEntries(), branchProbabilities.end());
44 TargetValueType const rowSum = std::accumulate(rowProbs.begin(), rowProbs.end(), storm::utility::zero<TargetValueType>());
45 if (!storm::utility::isOne(rowSum)) {
46 std::for_each(rowProbs.begin(), rowProbs.end(), [&rowSum](TargetValueType& entry) { entry /= rowSum; });
47 }
48 }
49 }
50 umb.branchToProbability.template set<TargetValueType>(std::move(branchProbabilities));
51}
52
54 for (auto const& labelName : labeling.getLabels()) {
55 if (labelName == "init") {
56 continue; // skip initial state labeling. Initial states are handled separately.
57 }
58 STORM_LOG_ASSERT(umb.index.aps(), "Model index must have annotations to store state labels.");
59 auto const name = umb.index.findAPName(labelName);
60 STORM_LOG_ASSERT(name.has_value(), "Label '" << labelName << "' not found in the model index.");
61 auto& aps = umb.aps(true).value();
62 STORM_LOG_ASSERT(!aps.contains(*name), "Annotation for label '" << labelName << "' already exists.");
63 auto& annotation = aps[*name];
64 annotation.states.emplace().values.template set<bool>(labeling.getStates(labelName));
65 }
66}
67
69 // choice to action
70 auto& choiceToAction = umb.choiceActions.emplace().values.emplace();
71 choiceToAction.reserve(choiceOrigins.getNumberOfChoices());
72 for (uint64_t c = 0; c < choiceOrigins.getNumberOfChoices(); ++c) {
73 choiceToAction.push_back(choiceOrigins.getIdentifier(c));
74 }
75
76 // action strings
77 // We always set a csr, even in cases where it could be omitted.
78 auto actionStrings = StringsBuilder(umb.choiceActions->strings.emplace(), umb.choiceActions->stringMapping.emplace());
79 // We use the empty action string for choices with no origin, which we want to be the first index.
80 [[maybe_unused]] auto const emptyStringIndex = actionStrings.push_back("");
81 STORM_LOG_ASSERT(emptyStringIndex == 0, "Action index for empty action string must be 0.");
82 // add to the action strings by initializing the csr with {0,0}
83 STORM_LOG_ASSERT(choiceOrigins.getIdentifierForChoicesWithNoOrigin() == 0, "Identifier for choices with no origin expected to be 0.");
84
85 for (uint64_t id = 1; id < choiceOrigins.getNumberOfIdentifiers(); ++id) { // intentionally start at 1, since we already added the empty action string
86 actionStrings.push_back(choiceOrigins.getIdentifierInfo(id));
87 }
88 actionStrings.finalize();
89 return actionStrings.size();
90}
91
93 // initialize umb data
94 // Action 0 must be the default action and is used for choices without any label (if present).
95 auto& choiceToAction = umb.choiceActions.emplace().values.emplace(labeling.getNumberOfItems(), 0);
96 auto actionStrings = StringsBuilder(umb.choiceActions->strings.emplace(), umb.choiceActions->stringMapping.emplace());
97
98 // Find out which choices have zero, at least one, or multiple labels. The former two cases can be handled more efficiently
99 auto const labels = labeling.getLabels();
100 storm::storage::BitVector choicesWithAtLeastOneLabel, choicesWithMultipleLabels;
101 for (auto const& labelName : labels) {
102 auto const& currentChoices = labeling.getChoices(labelName);
103 if (choicesWithAtLeastOneLabel.size() == 0) {
104 // first processed label
105 choicesWithAtLeastOneLabel = currentChoices;
106 } else if (choicesWithMultipleLabels.size() == 0) {
107 // second processed label
108 choicesWithMultipleLabels = choicesWithAtLeastOneLabel & currentChoices;
109 choicesWithAtLeastOneLabel |= currentChoices;
110 } else {
111 // third or later processed label
112 choicesWithMultipleLabels |= choicesWithAtLeastOneLabel & currentChoices;
113 choicesWithAtLeastOneLabel |= currentChoices;
114 }
115 }
116
117 // Handle choices without any labels.
118 if (choicesWithAtLeastOneLabel.size() == 0 || !choicesWithAtLeastOneLabel.full()) {
119 // For consistency, unlabelled choices shall always have action index 0. So we add the empty action string.
120 [[maybe_unused]] auto const emptyStringIndex = actionStrings.push_back("");
121 STORM_LOG_ASSERT(emptyStringIndex == 0, "Action index for empty action string must be 0.");
122 // nothing else to do for unlabeled choices: we already initialized the choiceToAction mapping with 0s
123 }
124
125 // Handle choices with exactly one label.
126 auto setChoices = [&choiceToAction, &actionStrings](storm::storage::BitVector const& choices, std::string_view actionName) {
127 auto choiceIt = choices.begin();
128 auto const choiceItEnd = choices.end();
129 if (choiceIt != choiceItEnd) {
130 // there is at least one choice with this label
131 auto const actionIndex = actionStrings.findOrPushBack(actionName);
132 for (; choiceIt != choiceItEnd; ++choiceIt) {
133 choiceToAction[*choiceIt] = actionIndex; // set action index for this choice
134 }
135 }
136 };
137 if (choicesWithMultipleLabels.empty()) {
138 for (auto const& labelName : labels) {
139 setChoices(labeling.getChoices(labelName), labelName);
140 }
141 } else {
142 choicesWithMultipleLabels.complement(); // now contains the choices with at most one label
143 for (auto const& labelName : labels) {
144 setChoices(labeling.getChoices(labelName) & choicesWithMultipleLabels, labelName);
145 }
146 choicesWithMultipleLabels.complement(); // revert above complement operation
147 }
148
149 // Handle choices with multiple labels.
150 for (uint64_t choice : choicesWithMultipleLabels) {
151 std::string action;
152 for (auto const& label : labeling.getLabelsOfChoice(choice)) {
153 if (!action.empty()) {
154 action += ","; // separate multiple labels with a comma
155 }
156 action += label;
157 }
158 choiceToAction[choice] = actionStrings.findOrPushBack(action);
159 }
160 return actionStrings.size();
161}
162
163template<typename TargetValueType>
164void setGenericVector(storm::umb::GenericVector& target, std::ranges::input_range auto&& values) {
165 using ValueType = std::ranges::range_value_t<decltype(values)>;
166 if constexpr (std::is_same_v<ValueType, TargetValueType>) {
167 target.template set<TargetValueType>(std::forward<decltype(values)>(values));
168 } else {
169 target.template set<TargetValueType>(storm::utility::vector::convertNumericVector<TargetValueType>(std::forward<decltype(values)>(values)));
170 }
171}
172
173template<typename ValueType, typename TargetValueType>
174void rewardToUmb(std::string const& rewardModelName, storm::models::sparse::StandardRewardModel<ValueType> const& rewardModel,
176 STORM_LOG_ASSERT(umb.index.rewards(), "Model index must have rewards to store state labels.");
177 auto const rewardIdentifier = umb.index.findRewardName(rewardModelName);
178 STORM_LOG_ASSERT(rewardIdentifier.has_value(), "Reward '" << rewardModelName << "' not found in the model index.");
179 auto& umbRewards = umb.rewards(true).value();
180 STORM_LOG_ASSERT(!umbRewards.contains(*rewardIdentifier), "Reward '" << *rewardIdentifier << "' already exists in the umb model.");
181 auto& rewardAnnotation = umbRewards[*rewardIdentifier];
182 if (rewardModel.hasStateRewards()) {
183 setGenericVector<TargetValueType>(rewardAnnotation.states.emplace().values, rewardModel.getStateRewardVector());
184 }
185 if (rewardModel.hasStateActionRewards()) {
186 setGenericVector<TargetValueType>(rewardAnnotation.choices.emplace().values, rewardModel.getStateActionRewardVector());
187 }
188 if (rewardModel.hasTransitionRewards()) {
189 std::vector<TargetValueType> branchRewards;
190 branchRewards.reserve(transitionMatrix.getEntryCount());
191 STORM_LOG_ASSERT(transitionMatrix.getRowCount() == rewardModel.getTransitionRewardMatrix().getRowCount(),
192 "The number of rows in the transition matrix and the reward model do not match.");
193 for (uint64_t rowIndex = 0; rowIndex < transitionMatrix.getRowCount(); ++rowIndex) {
194 auto const& transitionRow = transitionMatrix.getRow(rowIndex);
195 auto const& rewardRow = rewardModel.getTransitionRewardMatrix().getRow(rowIndex);
196 auto rewIt = rewardRow.begin();
197 // Match transition branch entries with entries in the transition reward matrix (which might not have the same entries at the same columns)
198 for (auto const& entry : transitionRow) {
199 while (rewIt != rewardRow.end() && rewIt->getColumn() < entry.getColumn()) {
200 ++rewIt;
201 }
202 if (rewIt == rewardRow.end() || rewIt->getColumn() > entry.getColumn()) {
203 branchRewards.push_back(storm::utility::zero<TargetValueType>());
204 } else {
205 STORM_LOG_ASSERT(rewIt->getColumn() == entry.getColumn(), "Unexpected column in reward model.");
206 branchRewards.push_back(storm::utility::convertNumber<TargetValueType>(rewIt->getValue()));
207 }
208 }
209 }
210 rewardAnnotation.branches.emplace().values.template set<TargetValueType>(std::move(branchRewards));
211 }
212}
213
214template<typename ValueType, typename TargetValueType>
215void playerIndicesToUmb(storm::models::sparse::Smg<ValueType> const& smg, auto& playerNames, auto& stateToPlayerIndices) {
216 STORM_LOG_ASSERT(playerNames.empty() && stateToPlayerIndices.empty(), "Expected initially empty player names and indices.");
217 auto const& origPlayerNamesToIndex = smg.getPlayerNamesToIndex();
218 playerNames.resize(smg.getNumberOfPlayers());
219 // We might have to insert names for unnamed players
220 storm::storage::BitVector unnamedIndices(playerNames.size(), true);
221 for (auto const& [name, index] : origPlayerNamesToIndex) {
222 playerNames[index] = name;
223 unnamedIndices.set(index, false);
224 }
225 auto freshPlayerName = [&origPlayerNamesToIndex](uint64_t i) {
226 std::string name = "unnamed_player" + std::to_string(i);
227 while (origPlayerNamesToIndex.contains(name)) {
228 name += "_";
229 }
230 return name;
231 };
232 for (uint64_t unnamedIndex : unnamedIndices) {
233 playerNames[unnamedIndex] = freshPlayerName(unnamedIndex);
234 }
235 stateToPlayerIndices.reserve(smg.getNumberOfStates());
236 // Some states might not have a player. For example, states that were not explored during model construction.
237 // These states are indicated by INVALID_PLAYER_INDEX. We assign these states to a fresh player at the end.
238 auto const invalPlayerIndex = smg.getNumberOfPlayers();
239 bool hasInvalidIndices = false;
240 for (auto const& index : smg.getStatePlayerIndications()) {
242 stateToPlayerIndices.push_back(invalPlayerIndex);
243 hasInvalidIndices = true;
244 } else {
245 STORM_LOG_ASSERT(index < smg.getNumberOfPlayers(), "Unexpected player index.");
246 stateToPlayerIndices.push_back(index);
247 }
248 }
249 if (hasInvalidIndices) {
250 playerNames.push_back(freshPlayerName(invalPlayerIndex));
251 }
252}
253
254template<typename ValueType>
256 using OptionType = ExportOptions::ValueType;
257 using ExportType = storm::umb::Type;
258 switch (options.valueType) {
259 case OptionType::Default:
260 if constexpr (std::is_same_v<ValueType, double>) {
261 return ExportType::Double;
262 } else if constexpr (std::is_same_v<ValueType, storm::RationalNumber>) {
263 return ExportType::Rational;
264 } else if constexpr (std::is_same_v<ValueType, storm::Interval>) {
265 return ExportType::DoubleInterval;
266 } else {
267 static_assert(std::is_same_v<ValueType, storm::RationalInterval>, "Unhandled value type");
268 return ExportType::RationalInterval;
269 }
270 case OptionType::Double:
271 return ExportType::Double;
272 case OptionType::Rational:
273 return ExportType::Rational;
274 case OptionType::DoubleInterval:
275 return ExportType::DoubleInterval;
276 case OptionType::RationalInterval:
277 return ExportType::RationalInterval;
278 }
279 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Unexpected value type.");
280}
281
282template<typename ValueType>
284 // No model (meta-)data to set at this point.
285 // file-data:
286 index.fileData.emplace();
287 index.fileData->setCreationDateToNow();
288 index.fileData->tool = "Storm";
289 // Note: it's difficult to get the version of the tool because the storm library is not linked against storm-version-info
290
291 // transition-system:
292 auto& ts = index.transitionSystem;
293 switch (model.getType()) {
294 using enum storm::models::ModelType;
296 case Dtmc:
297 ts.time = Discrete;
298 ts.numPlayers = 0;
299 break;
300 case Ctmc:
301 ts.time = Stochastic;
302 ts.numPlayers = 0;
303 break;
304 case Mdp:
305 case Pomdp:
306 ts.time = Discrete;
307 ts.numPlayers = 1;
308 break;
309 case MarkovAutomaton:
310 ts.time = UrgentStochastic;
311 ts.numPlayers = 1;
312 break;
313 case Smg:
314 ts.time = Discrete;
316 break;
317 default:
318 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Unexpected model type.");
319 }
320 ts.numStates = model.getNumberOfStates();
321 ts.numInitialStates = model.getInitialStates().getNumberOfSetBits();
322 ts.numChoices = model.getNumberOfChoices();
323 ts.numChoiceActions = (model.hasChoiceLabeling() || model.hasChoiceOrigins()) ? ModelIndex::TransitionSystem::InvalidNumber
324 : 0; // action count is only known after processing choice labeling/origins.
325 ts.numBranches = model.getNumberOfTransitions();
326 ts.numBranchActions = 0;
327 ts.numObservations = model.isPartiallyObservable() ? ModelIndex::TransitionSystem::InvalidNumber : 0; // observation count set later
328
329 auto const exportType = getExportType<ValueType>(options);
330 ts.branchProbabilityType = {exportType, defaultBitSize(exportType)};
332 ts.exitRateType = ts.branchProbabilityType;
333 }
334
335 // annotations:
336 bool const hasRewards = model.hasRewardModel();
337 bool const hasAps = model.getStateLabeling().getNumberOfLabels() >= 2 ||
338 (model.getStateLabeling().getNumberOfLabels() == 1 && !model.getStateLabeling().containsLabel("init"));
339 if (hasRewards || hasAps) {
340 index.annotations.emplace();
341 }
342
343 // rewards:
344 if (hasRewards) {
345 auto& rewards = index.rewards(true).value();
346 for (auto const& [rewardModelName, rewardModel] : model.getRewardModels()) {
347 auto identifier = umb::ModelIndex::Annotation::getValidIdentifierFromAlias(rewardModelName);
348 STORM_LOG_THROW(!rewards.contains(identifier), storm::exceptions::WrongFormatException, "Reward id '" << identifier << "' already exists.");
349 auto& rewardIndex = rewards[identifier];
350 if (!rewardModelName.empty()) {
351 rewardIndex.alias = rewardModelName; // Don't introduce an alias for unnamed rewards. They don't have a nice name.
352 }
353 if (rewardModel.hasNegativeRewards()) {
354 if (!rewardModel.hasPositiveRewards()) {
355 rewardIndex.upper = 0;
356 }
357 } else {
358 rewardIndex.lower = 0;
359 }
361 if (rewardModel.hasStateRewards()) {
362 rewardIndex.appliesTo.push_back(States);
363 }
364 if (rewardModel.hasStateActionRewards()) {
365 rewardIndex.appliesTo.push_back(Choices);
366 }
367 if (rewardModel.hasTransitionRewards()) {
368 rewardIndex.appliesTo.push_back(Branches);
369 }
370 rewardIndex.type = {exportType, defaultBitSize(exportType)};
371 }
372 }
373
374 // aps:
375 if (hasAps) {
376 auto& aps = index.aps(true).value();
377 for (auto const& label : model.getStateLabeling().getLabels()) {
378 if (label == "init") {
379 continue;
380 }
382 STORM_LOG_THROW(!aps.contains(identifier), storm::exceptions::WrongFormatException, "AP with identifier '" << identifier << "' already exists.");
383 auto& apIndex = aps[identifier];
384 apIndex.alias = label;
387 }
388 }
389
390 // valuations:
391 auto createDescription = [](storm::storage::sparse::ValuationsStorage const& valuations) {
393 for (uint64_t classIndex = 0; classIndex < valuations.numClasses(); ++classIndex) {
394 descr.classes.push_back(valuations.getClassDescription(classIndex));
395 }
396 if (valuations.hasStrings()) {
397 descr.numStrings = valuations.numStrings();
398 }
399 return descr;
400 };
401 if (model.hasStateValuations()) {
402 index.valuations.emplace().states = createDescription(model.getStateValuations().getStorage());
403 }
404 if (model.isPartiallyObservable()) {
405 STORM_LOG_ASSERT(model.isOfType(storm::models::ModelType::Pomdp), "Only POMDPs are supported as partially observable models.");
406 auto pomdp = model.template as<storm::models::sparse::Pomdp<ValueType>>();
407 if (pomdp->hasObservationValuations()) {
408 if (!index.valuations.has_value()) {
409 index.valuations.emplace();
410 }
411 index.valuations->observations = createDescription(pomdp->getObservationValuations().getStorage());
412 }
413 }
414}
415
416template<typename ValueType, typename TargetValueType>
418 // Possibly canonicize POMDP
419 if (options.canonicizePomdp && model.isPartiallyObservable()) {
420 STORM_LOG_ASSERT(model.isOfType(storm::models::ModelType::Pomdp), "Only POMDPs are supported as partially observable models.");
421 auto pomdp = model.template as<storm::models::sparse::Pomdp<ValueType>>();
422 if (!pomdp->isCanonic()) {
423 STORM_LOG_INFO("Canonicizing POMDP before UMB export.");
425 auto newOptions = options;
426 newOptions.canonicizePomdp = false; // avoid infinite recursion
427 sparseModelToUmb<ValueType, TargetValueType>(*makeCanonic.transform(), umbModel, newOptions);
428 return;
429 }
430 }
431
432 // index
433 setIndexInformation<ValueType>(model, umbModel.index, options);
434
435 // initial states and APs
436 umbModel.stateIsInitial = model.getInitialStates();
437 stateLabelingToUmb(model.getStateLabeling(), umbModel);
438
439 // Choice Actions
440 if (options.allowChoiceOriginsAsActions && model.hasChoiceOrigins()) {
442 "Choice origins and choice labeling are both present but only choice origins will be used as actions for UMB export.");
443 uint64_t const numActions = choiceOriginsToUmb(*model.getChoiceOrigins(), umbModel);
444 umbModel.index.transitionSystem.numChoiceActions = numActions;
445 } else if (options.allowChoiceLabelingAsActions && model.hasChoiceLabeling()) {
446 uint64_t const numActions = choiceLabelingToUmb(model.getChoiceLabeling(), umbModel);
447 umbModel.index.transitionSystem.numChoiceActions = numActions;
448 }
449
450 // Valuations
451 if (model.hasStateValuations()) {
453 }
454 if (model.isPartiallyObservable()) {
455 STORM_LOG_ASSERT(model.isOfType(storm::models::ModelType::Pomdp), "Only POMDPs are supported as partially observable models.");
456 auto pomdp = model.template as<storm::models::sparse::Pomdp<ValueType>>();
457 if (pomdp->hasObservationValuations()) {
458 umbModel.valuations.observations = pomdp->getObservationValuations().getStorage().getRawUmbData();
459 }
460 }
461
462 // Transition matrix
463 using enum storm::models::ModelType;
464 bool normalize = model.isOfType(Ctmc);
466 STORM_LOG_WARN("Translating from non-exact to exact model representation. This may lead to rounding errors.");
467 normalize = true;
468 }
470
471 // rewards
472 for (auto const& [name, rewardModel] : model.getRewardModels()) {
473 rewardToUmb<ValueType, TargetValueType>(name, rewardModel, model.getTransitionMatrix(), umbModel);
474 }
475
476 // Model type specific components
477 if (model.isOfType(Ctmc)) {
478 auto const& ctmc = *model.template as<storm::models::sparse::Ctmc<ValueType>>();
479 setGenericVector<TargetValueType>(umbModel.stateToExitRate, ctmc.getExitRateVector());
480 } else if (model.isOfType(MarkovAutomaton)) {
481 auto const& ma = *model.template as<storm::models::sparse::MarkovAutomaton<ValueType>>();
482 umbModel.stateIsMarkovian = ma.getMarkovianStates();
483 setGenericVector<TargetValueType>(umbModel.stateToExitRate, ma.getExitRates());
484 } else if (model.isOfType(Pomdp)) {
485 auto const& pomdp = *model.template as<storm::models::sparse::Pomdp<ValueType>>();
486 umbModel.index.transitionSystem.numObservations = pomdp.getNrObservations();
488 umbModel.stateObservations.emplace().values.emplace(pomdp.getObservations().begin(), pomdp.getObservations().end());
489 } else if (model.isOfType(Smg)) {
490 auto const& smg = *model.template as<storm::models::sparse::Smg<ValueType>>();
494 "Exporting SMG to UMB with zero or one players. The model will be recognized as MDP or DTMC on import.");
495 } else {
496 STORM_LOG_THROW(model.isOfType(Dtmc) || model.isOfType(Mdp), storm::exceptions::NotSupportedException,
497 "Unexpected model type for UMB export: " << model.getType() << ".");
498 }
499}
500
501} // namespace detail
502
503template<typename ValueType>
505 storm::umb::UmbModel umbModel;
506 using enum ExportOptions::ValueType;
507 switch (options.valueType) {
508 case Default:
509 detail::sparseModelToUmb<ValueType, ValueType>(model, umbModel, options);
510 break;
511 case Double:
512 detail::sparseModelToUmb<ValueType, double>(model, umbModel, options);
513 break;
514 case Rational:
516 break;
517 case DoubleInterval:
519 break;
520 case RationalInterval:
522 break;
523 default:
524 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Unexpected value type.");
525 }
526 STORM_LOG_ASSERT(umbModel.validate(std::cout), "Created umb model is not valid.");
527 return umbModel;
528}
529
532 ExportOptions const& options);
535 ExportOptions const& options);
536} // namespace storm::umb
storm::models::sparse::Dtmc< double > Dtmc
storm::models::sparse::Mdp< double > Mdp
virtual ModelType getType() const
Return the actual type of the model.
Definition ModelBase.cpp:7
bool isOfType(storm::models::ModelType const &modelType) const
Checks whether the model is of the given type.
Definition ModelBase.cpp:27
virtual bool isPartiallyObservable() const
Definition ModelBase.cpp:50
This class manages the labeling of the choice space with a number of (atomic) labels.
storm::storage::BitVector const & getChoices(std::string const &label) const
Returns the labeling of choices associated with the given label.
std::set< std::string > getLabelsOfChoice(uint64_t choice) const
Retrieves the set of labels attached to the given choice.
std::set< std::string > getLabels() const
Retrieves the set of labels contained in this labeling.
bool containsLabel(std::string const &label) const
Checks whether a label is registered within this labeling.
std::size_t getNumberOfItems() const
Returns the number of items managed by this object.
std::size_t getNumberOfLabels() const
Returns the number of labels managed by this object.
Base class for all sparse models.
Definition Model.h:30
storm::models::sparse::ChoiceLabeling const & getChoiceLabeling() const
Retrieves the labels for the choices of the model.
Definition Model.cpp:335
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:198
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
Definition Model.cpp:690
bool hasStateValuations() const
Retrieves whether this model was build with state valuations.
Definition Model.cpp:350
storm::storage::sparse::Valuations const & getStateValuations() const
Retrieves the valuations of the states of the model.
Definition Model.cpp:355
virtual uint_fast64_t getNumberOfChoices() const override
Returns the number of choices ine the model.
Definition Model.cpp:173
std::shared_ptr< storm::storage::sparse::ChoiceOrigins > const & getChoiceOrigins() const
Retrieves the origins of the choices of the model.
Definition Model.cpp:375
bool hasChoiceLabeling() const
Retrieves whether this model has a labeling of the choices.
Definition Model.cpp:330
virtual bool hasRewardModel(std::string const &rewardModelName) const override
Retrieves whether the model has a reward model with the given name.
Definition Model.cpp:208
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
Definition Model.cpp:320
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
Definition Model.cpp:168
bool hasChoiceOrigins() const
Retrieves whether this model was build with choice origins.
Definition Model.cpp:370
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:163
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:178
This class represents a stochastic multiplayer game.
Definition Smg.h:16
std::vector< storm::storage::PlayerIndex > const & getStatePlayerIndications() const
Definition Smg.cpp:36
std::map< std::string, storm::storage::PlayerIndex > const & getPlayerNamesToIndex() const
Definition Smg.cpp:54
uint64_t getNumberOfPlayers() const
Definition Smg.cpp:59
storm::storage::SparseMatrix< ValueType > const & getTransitionRewardMatrix() const
Retrieves the transition rewards of the reward model.
bool hasTransitionRewards() const
Retrieves whether the reward model has transition rewards.
std::vector< ValueType > const & getStateActionRewardVector() const
Retrieves the state-action rewards of the reward model.
std::vector< ValueType > const & getStateRewardVector() const
Retrieves the state rewards of the reward model.
bool hasStateRewards() const
Retrieves whether the reward model has state rewards.
bool hasStateActionRewards() const
Retrieves whether the reward model has state-action rewards.
This class manages the labeling of the state space with a number of (atomic) labels.
storm::storage::BitVector const & getStates(std::string const &label) const
Returns the labeling of states associated with the given label.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void complement()
Negates all bits in the bit vector.
bool full() const
Retrieves whether all bits are set in this bit vector.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
size_t size() const
Retrieves the number of bits this bit vector can store.
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
index_type getEntryCount() const
Returns the number of entries in the matrix.
std::vector< index_type > const & getRowIndices() const
Returns the entry indices within the given row.
bool hasTrivialRowGrouping() const
Retrieves whether the matrix has a trivial row grouping.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
This class represents the origin of the choices of a model in terms of the input model specification ...
virtual uint_fast64_t getNumberOfIdentifiers() const =0
uint_fast64_t getIdentifier(uint_fast64_t choiceIndex) const
static uint_fast64_t getIdentifierForChoicesWithNoOrigin()
std::string const & getIdentifierInfo(uint_fast64_t identifier) const
ValuationsStorage const & getStorage() const
Stores valuations of variables for a set of entities (e.g.
storm::umb::UmbModel::Valuation getRawUmbData() const
Exports a snapshot of the raw UMB model valuation data (packed bytes, optional class mapping,...
std::shared_ptr< storm::models::sparse::Pomdp< ValueType > > transform() const
Represents a model in the UMB format.
Definition UmbModel.h:21
TO1< bool > stateIsMarkovian
Definition UmbModel.h:29
bool validate(std::ostream &errors) const
Validates the given UMB model and writes potential errors to the given output stream.
Definition UmbModel.cpp:96
TO1< bool > stateIsInitial
Definition UmbModel.h:28
TO1< AnyValueType > stateToExitRate
Definition UmbModel.h:30
ModelIndex index
Definition UmbModel.h:24
TO1< uint32_t > stateToPlayer
Definition UmbModel.h:27
Valuations valuations
Definition UmbModel.h:77
std::optional< Observations > stateObservations
Definition UmbModel.h:51
#define STORM_LOG_INFO(message)
Definition logging.h:27
#define STORM_LOG_WARN(message)
Definition logging.h:28
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:36
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
PlayerIndex const INVALID_PLAYER_INDEX
Definition PlayerIndex.h:8
void rewardToUmb(std::string const &rewardModelName, storm::models::sparse::StandardRewardModel< ValueType > const &rewardModel, storm::storage::SparseMatrix< ValueType > const &transitionMatrix, storm::umb::UmbModel &umb)
storm::umb::Type getExportType(ExportOptions const &options)
void setIndexInformation(storm::models::sparse::Model< ValueType > const &model, storm::umb::ModelIndex &index, ExportOptions const &options)
uint64_t choiceLabelingToUmb(storm::models::sparse::ChoiceLabeling const &labeling, storm::umb::UmbModel &umb)
void setGenericVector(storm::umb::GenericVector &target, std::ranges::input_range auto &&values)
uint64_t choiceOriginsToUmb(storm::storage::sparse::ChoiceOrigins const &choiceOrigins, storm::umb::UmbModel &umb)
void playerIndicesToUmb(storm::models::sparse::Smg< ValueType > const &smg, auto &playerNames, auto &stateToPlayerIndices)
void transitionMatrixToUmb(storm::storage::SparseMatrix< ValueType > const &matrix, storm::umb::UmbModel &umb, bool const normalize)
void stateLabelingToUmb(storm::models::sparse::StateLabeling const &labeling, storm::umb::UmbModel &umb)
void sparseModelToUmb(storm::models::sparse::Model< ValueType > const &model, UmbModel &umbModel, ExportOptions const &options)
Import and export of umb files.
storm::umb::UmbModel sparseModelToUmb(storm::models::sparse::Model< ValueType > const &model, ExportOptions const &options)
template storm::umb::UmbModel sparseModelToUmb< storm::RationalInterval >(storm::models::sparse::Model< storm::RationalInterval > const &model, ExportOptions const &options)
uint64_t defaultBitSize(Type const type)
Returns the default size (in bits) of a type, if available.
Definition Type.cpp:59
template storm::umb::UmbModel sparseModelToUmb< double >(storm::models::sparse::Model< double > const &model, ExportOptions const &options)
template storm::umb::UmbModel sparseModelToUmb< storm::Interval >(storm::models::sparse::Model< storm::Interval > const &model, ExportOptions const &options)
template storm::umb::UmbModel sparseModelToUmb< storm::RationalNumber >(storm::models::sparse::Model< storm::RationalNumber > const &model, ExportOptions const &options)
std::vector< TargetType > convertNumericVector(std::vector< SourceType > const &oldVector)
Converts the given vector to the given ValueType Assumes that both, TargetType and SourceType are num...
Definition vector.h:966
bool isOne(ValueType const &a)
Definition constants.cpp:37
ValueType zero()
Definition constants.cpp:24
TargetType convertNumber(SourceType const &number)
carl::Interval< storm::RationalNumber > RationalInterval
static const bool IsExact
Describes all valuation classes for a set of entities (e.g.
std::vector< ValuationClassDescription > classes
bool allowChoiceLabelingAsActions
Whether export of choice origins is enabled.
bool allowChoiceOriginsAsActions
Whether export of choice origins is enabled.
ValueType
The type that is used for all kinds of values.
bool canonicizePomdp
Whether to canonicize POMDPs before export.
static std::string getValidIdentifierFromAlias(std::string const &alias)
Takes an alias (which can be an arbitrary string) and converts it to a valid identifier in [0-9a-z_-]...
std::optional< storm::SerializedEnum< ObservationsApplyToDeclaration > > observationsApplyTo
Definition ModelIndex.h:56
std::optional< std::vector< std::string > > playerNames
Definition ModelIndex.h:60
storm::OptionalRef< AnnotationMap > rewards(bool createIfMissing=false)
struct storm::umb::ModelIndex::TransitionSystem transitionSystem
std::optional< std::map< std::string, AnnotationMap > > annotations
Definition ModelIndex.h:109
std::optional< Valuations > valuations
Definition ModelIndex.h:116
storm::OptionalRef< AnnotationMap > aps(bool createIfMissing=false)
std::optional< FileData > fileData
Definition ModelIndex.h:37
std::optional< Values > observations
Definition UmbModel.h:55
std::optional< Values > states
Definition UmbModel.h:55